Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoecker committed Jun 21, 2021
0 parents commit 13be76c
Show file tree
Hide file tree
Showing 65 changed files with 13,579 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/packages
/x64
/Debug
/Release
/ShaderTest/x64
/ShaderTest/Debug
/ShaderTest/Release
*.vcxproj.user
/build
.vscode/*
CMakeUserPresets.json
141 changes: 141 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
cmake_minimum_required(VERSION 3.18)

project(dxdispatch VERSION 0.1.0 LANGUAGES CXX)

# ==============================================================================
# External Libraries
# ==============================================================================
include(FetchContent)
include(cmake/gsl.cmake)
include(cmake/rapidjson.cmake)
include(cmake/fmt.cmake)
include(cmake/wil.cmake)
include(cmake/directml.cmake)
include(cmake/directmlx.cmake)
include(cmake/direct3d.cmake)
include(cmake/dxheaders.cmake)
include(cmake/pix.cmake)
include(cmake/gtest.cmake)
include(cmake/dxc.cmake)
include(cmake/half.cmake)
include(cmake/cxxopts.cmake)

# ==============================================================================
# Model Library
# ==============================================================================
add_library(
model STATIC
src/model/JsonParsers.cpp
src/model/Model.cpp
)

target_link_libraries(
model
PRIVATE
fmt::fmt-header-only
Microsoft::DirectMLX
PUBLIC
Microsoft.GSL::GSL
rapidjson::rapidjson
Microsoft::DirectML
Microsoft::WIL
Half::Half
)

target_compile_features(model PRIVATE cxx_std_17)
target_precompile_headers(model PRIVATE src/model/pch.h)
target_include_directories(model INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/model)

# ==============================================================================
# Main Executable
# ==============================================================================
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/dxdispatch/config.h.in config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/dxdispatch/dxdispatch.rc.in dxdispatch.rc)

add_executable(
dxdispatch
src/dxdispatch/Adapter.cpp
src/dxdispatch/Device.cpp
src/dxdispatch/main.cpp
src/dxdispatch/DmlDispatchable.cpp
src/dxdispatch/HlslDispatchable.cpp
src/dxdispatch/Executor.cpp
src/dxdispatch/CommandLineArgs.cpp
${CMAKE_CURRENT_BINARY_DIR}/config.h
${CMAKE_CURRENT_BINARY_DIR}/dxdispatch.rc
)

target_include_directories(dxdispatch PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(
dxdispatch
PRIVATE
Microsoft.GSL::GSL
fmt::fmt-header-only
Microsoft::WIL
Microsoft::DirectML
Microsoft::Direct3D12
Microsoft::PIX
Microsoft::DirectMLX
Microsoft::DirectX-Headers
Microsoft::DirectX-Guids
Microsoft::DXC
dxcore
model
cxxopts
)

target_compile_features(dxdispatch PRIVATE cxx_std_17)
target_precompile_headers(dxdispatch PRIVATE src/dxdispatch/pch.h)

# Copy DLLs into executable's build output directory for debugging purposes.
add_custom_command(
TARGET dxdispatch
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Microsoft::DirectML> $<TARGET_FILE_DIR:dxdispatch>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Microsoft::DirectML,DEBUG_DLL_PATH> $<TARGET_FILE_DIR:dxdispatch>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Microsoft::PIX> $<TARGET_FILE_DIR:dxdispatch>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Microsoft::DXC> $<TARGET_FILE_DIR:dxdispatch>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Microsoft::DXC,DXIL_PATH> $<TARGET_FILE_DIR:dxdispatch>
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:dxdispatch>/$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Microsoft::Direct3D12,CORE_DLL_PATH> $<TARGET_FILE_DIR:dxdispatch>/$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_PROPERTY:Microsoft::Direct3D12,DEBUG_DLL_PATH> $<TARGET_FILE_DIR:dxdispatch>/$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
)

# TODO: improve this installation
install(
FILES
$<TARGET_FILE:dxdispatch>
${CMAKE_CURRENT_SOURCE_DIR}/ThirdPartyNotices.txt
${CMAKE_CURRENT_SOURCE_DIR}/doc/Guide.md
DESTINATION bin
)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/models
DESTINATION bin
)

# ==============================================================================
# Tests
# ==============================================================================
enable_testing()
include(GoogleTest)

add_executable(
jsontests
src/test/JsonParserTests.cpp
)

target_compile_features(jsontests PRIVATE cxx_std_17)
target_link_libraries(
jsontests
PRIVATE
gtest_main
fmt::fmt-header-only
Microsoft::DirectMLX
model
)
target_include_directories(jsontests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/dxdispatch)
gtest_discover_tests(jsontests)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Justin Stoecker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# DxDispatch

**This is a hobby project and a work in progress! Releases will use [semantic versioning](https://semver.org/), starting with 0.1.0, to reflect the beta nature of this tool.**

DxDispatch is simple command-line executable for launching DirectX 12 compute programs without writing all the C++ boilerplate. The input to the tool is a JSON model that defines resources, dispatchables (compute shaders or DirectML operators), and commands to execute. The model abstraction makes it easy to experiment, but it also preserves low-level control and flexibility.

Some of the things you can do with this tool:
- Launch [DirectML](https://github.com/Microsoft/directml) operators to understand how they work with different inputs.
- Run custom HLSL compute shaders that are compiled at runtime using the [DirectX Shader Compiler](https://github.com/Microsoft/DirectXShaderCompiler).
- Debug binding and API usage issues. DxDispatch hooks into the Direct3D and DirectML debug layers and prints errors and warnings directly to the console; no need to attach a debugger.
- Experiment with performance by benchmarking dispatches.
- Take GPU or timing captures using [PIX on Windows](https://devblogs.microsoft.com/pix/download/). Labeled events and resources make it easy to correlate model objects to D3D objects.

This tool is *not* designed to be a general-purpose framework for building large computational models or running in production scenarios. The focus is on experimentation and learning!

# DirectX Component Versions

DxDispatch currently targets the following versions of DirectX components:

| Component | Version |
| ----------------------- | --------------------------------------------------------------------------------------------------- |
| DirectML | [1.5.1](https://www.nuget.org/packages/Microsoft.AI.DirectML/1.5.1) |
| Direct3D 12 | [1.4.9 (Agility SDK)](https://www.nuget.org/packages/Microsoft.Direct3D.D3D12/1.4.9) |
| DirectX Shader Compiler | [April 2021 (v1.6.2104)](https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.6.2104) |

# System Requirements

DxDispatch is currently only available for Windows 10, but support for WSL is planned. DxDispatch depends on the [DirectX 12 Agility SDK](https://devblogs.microsoft.com/directx/announcing-dx12agility/), which is only available on Version 1909+.

- A DirectX 12 capable hardware device.
- Windows 10 November 2019 Update (Version 1909; Build 18363) or newer.
- If testing shaders that use Shader Model 6.6:
- AMD: [Adrenalin 21.4.1 preview driver](https://www.amd.com/en/support/kb/release-notes/rn-rad-win-21-4-1-dx12-agility-sdk)
- NVIDIA: drivers with version 466.11 or higher

Each Windows release of DxDispatch bundles a recent redistributable copy of DirectML (plus debug layers), Direct3D 12 (plus debug layers), and the DX Shader Compiler. You do not need to install any additional software to run the dxdispatch executable, but a recent driver for your DX12 device is recommended.

# Getting Started

See the [guide](doc/Guide.md) for detailed usage instructions. The [models](./models) directory contains some simple examples to get started. For example, here's an example that invokes DML's reduction operator:

```
> dxdispatch.exe models/dml_reduce.json
Running on 'NVIDIA GeForce RTX 2070 SUPER'
Resource 'input': 1, 2, 3, 4, 5, 6, 7, 8, 9
Resource 'output': 6, 15, 24
```

# Building, Testing, and Installing

DxDispatch relies on several external dependencies that are downloaded when the project is configured. See [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) for relevant license info.

This project uses CMake so you may generate a build system of your choosing. However, some of the CMake scripts to fetch external dependencies currently assume a Visual Studio generator. Until this is resolved you'll want to stick with VS. Tested with the following configuration:
- Microsoft Visual Studio 2019
- Windows SDK 10.0.19041.0

Example from a terminal in the clone directory (change install location as desired):

```
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=c:/dxdispatch ..
cmake --build . --target INSTALL
ctest .
```
Loading

0 comments on commit 13be76c

Please sign in to comment.