1
1
cmake_minimum_required (VERSION 3.18 )
2
-
3
- project (dxdispatch VERSION 0.4.0 LANGUAGES CXX )
4
-
5
- # Statically link runtime library to avoid runtime dependency on Visual C++ redistributable
6
- set (CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug> )
2
+ project (dxdispatch VERSION 0.5.0 LANGUAGES CXX )
7
3
8
4
# ==============================================================================
9
- # External Libraries
5
+ # External Libraries/Helpers
10
6
# ==============================================================================
7
+
11
8
include (FetchContent )
9
+ include (cmake/helper_platform.cmake )
10
+
11
+ if (NOT TARGET_XBOX )
12
+ # Statically link runtime library to avoid runtime dependency on Visual C++ redistributable.
13
+ # On Xbox we deploy these dependencies for now.
14
+ set (CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug> )
15
+ endif ()
16
+
17
+ if (TARGET_WSL )
18
+ set (CMAKE_SKIP_BUILD_RPATH FALSE )
19
+ set (CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
20
+ set (CMAKE_INSTALL_RPATH "$\{ ORIGIN\} " )
21
+ endif ()
22
+
12
23
include (cmake/gsl.cmake )
13
24
include (cmake/rapidjson.cmake )
14
25
include (cmake/fmt.cmake )
15
26
include (cmake/wil.cmake )
16
- include (cmake/directml.cmake )
17
- include (cmake/directmlx.cmake )
18
- include (cmake/direct3d.cmake )
19
- include (cmake/dxheaders.cmake )
20
- include (cmake/pix.cmake )
21
- include (cmake/gtest.cmake )
22
- include (cmake/dxc.cmake )
23
27
include (cmake/half.cmake )
24
28
include (cmake/cxxopts.cmake )
25
29
30
+ if (NOT TARGET_XBOX )
31
+ include (cmake/gtest.cmake )
32
+ endif ()
33
+
34
+ include (cmake/wil.cmake )
35
+ add_wil_target (wil CACHE_PREFIX DXD )
36
+
37
+ include (cmake/gdk.cmake )
38
+ add_gdk_target (gdk CACHE_PREFIX DXD )
39
+ get_target_property (gdk_dxcompiler_path gdk DX_COMPILER_PATH )
40
+
41
+ include (cmake/pix.cmake )
42
+ add_pix_target (pix CACHE_PREFIX DXD )
43
+
44
+ include (cmake/dxcompiler.cmake )
45
+ add_dxcompiler_target (dxcompiler CACHE_PREFIX DXD GDK_DXCOMPILER_PATH ${gdk_dxcompiler_path} )
46
+ get_target_property (dxcompiler_type dxcompiler DX_COMPONENT_CONFIG )
47
+
48
+ include (cmake/d3d12.cmake )
49
+ add_d3d12_target (d3d12 CACHE_PREFIX DXD )
50
+
51
+ include (cmake/directml.cmake )
52
+ add_directml_target (directml CACHE_PREFIX DXD )
53
+
26
54
# ==============================================================================
27
55
# Model Library
28
56
# ==============================================================================
@@ -36,13 +64,13 @@ target_link_libraries(
36
64
model
37
65
PRIVATE
38
66
fmt::fmt-header-only
39
- Microsoft::DirectMLX
40
67
PUBLIC
41
68
Microsoft.GSL::GSL
42
- rapidjson::rapidjson
43
- Microsoft::DirectML
44
- Microsoft::WIL
45
69
Half::Half
70
+ rapidjson::rapidjson
71
+ wil
72
+ d3d12
73
+ directml
46
74
)
47
75
48
76
target_compile_features (model PRIVATE cxx_std_17 )
@@ -52,59 +80,58 @@ target_include_directories(model INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/model
52
80
# ==============================================================================
53
81
# Main Executable
54
82
# ==============================================================================
83
+ get_target_property (directml_config directml DX_COMPONENT_CONFIG )
84
+ get_target_property (d3d12_config d3d12 DX_COMPONENT_CONFIG )
85
+ get_target_property (dxcompiler_config dxcompiler DX_COMPONENT_CONFIG )
86
+ get_target_property (pix_config pix DX_COMPONENT_CONFIG )
87
+ get_target_property (gdk_config gdk DX_COMPONENT_CONFIG )
55
88
configure_file (${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch/config.h.in config.h )
56
- configure_file (${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch/dxdispatch.rc.in dxdispatch.rc )
57
89
58
90
add_executable (
59
91
dxdispatch
60
92
src/dxdispatch/Adapter.cpp
61
93
src/dxdispatch/Device.cpp
62
94
src/dxdispatch/main.cpp
63
95
src/dxdispatch/DmlDispatchable.cpp
64
- src/dxdispatch/HlslDispatchable.cpp
65
96
src/dxdispatch/Executor.cpp
66
97
src/dxdispatch/CommandLineArgs.cpp
98
+ src/dxdispatch/Logging.cpp
67
99
${CMAKE_CURRENT_BINARY_DIR} /config.h
68
- ${CMAKE_CURRENT_BINARY_DIR} /dxdispatch.rc
69
100
)
70
101
102
+ if (NOT dxcompiler_type STREQUAL None )
103
+ target_sources (dxdispatch PRIVATE src/dxdispatch/HlslDispatchable.cpp )
104
+ endif ()
105
+
106
+ set_property (DIRECTORY PROPERTY VS_STARTUP_PROJECT dxdispatch )
107
+
108
+ if (WIN32 )
109
+ target_sources (dxdispatch PRIVATE ${CMAKE_CURRENT_BINARY_DIR} /dxdispatch.rc )
110
+ configure_file (${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch/dxdispatch.rc.in dxdispatch.rc )
111
+ endif ()
112
+
71
113
target_include_directories (dxdispatch PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
72
114
73
115
target_link_libraries (
74
116
dxdispatch
75
117
PRIVATE
76
118
Microsoft.GSL::GSL
77
119
fmt::fmt-header-only
78
- Microsoft::WIL
79
- Microsoft::DirectML
80
- Microsoft::Direct3D12
81
- Microsoft::PIX
82
- Microsoft::DirectMLX
83
- Microsoft::DirectX-Headers
84
- Microsoft::DirectX-Guids
85
- Microsoft::DXC
86
- dxcore
87
120
model
88
121
cxxopts
122
+ directml
123
+ d3d12
124
+ dxcompiler
125
+ pix
126
+ gdk
127
+ wil
89
128
)
90
129
91
130
target_compile_features (dxdispatch PRIVATE cxx_std_17 )
92
131
target_precompile_headers (dxdispatch PRIVATE src/dxdispatch/pch.h )
132
+ target_copy_redist_dependencies (dxdispatch )
93
133
94
- # Copy DLLs into executable's build output directory for debugging purposes.
95
- add_custom_command (
96
- TARGET dxdispatch
97
- POST_BUILD
98
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_FILE:Microsoft::DirectML> $< TARGET_FILE_DIR:dxdispatch>
99
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_PROPERTY:Microsoft::DirectML,DEBUG_DLL_PATH> $< TARGET_FILE_DIR:dxdispatch>
100
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_FILE:Microsoft::PIX> $< TARGET_FILE_DIR:dxdispatch>
101
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_FILE:Microsoft::DXC> $< TARGET_FILE_DIR:dxdispatch>
102
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_PROPERTY:Microsoft::DXC,DXIL_PATH> $< TARGET_FILE_DIR:dxdispatch>
103
- COMMAND ${CMAKE_COMMAND} -E make_directory $< TARGET_FILE_DIR:dxdispatch> /$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
104
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_PROPERTY:Microsoft::Direct3D12,CORE_DLL_PATH> $< TARGET_FILE_DIR:dxdispatch> /$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
105
- COMMAND ${CMAKE_COMMAND} -E copy_if_different $< TARGET_PROPERTY:Microsoft::Direct3D12,DEBUG_DLL_PATH> $< TARGET_FILE_DIR:dxdispatch> /$<TARGET_PROPERTY:Microsoft::Direct3D12,SUBDIR_PATH>
106
- )
107
-
134
+ install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /models DESTINATION bin )
108
135
install (
109
136
FILES
110
137
$< TARGET_FILE:dxdispatch>
@@ -113,70 +140,109 @@ install(
113
140
DESTINATION bin
114
141
)
115
142
116
- install (
117
- DIRECTORY
118
- ${CMAKE_CURRENT_SOURCE_DIR} /models
119
- DESTINATION bin
120
- )
143
+ if (TARGET_XBOX )
144
+ # Deploy to the console instead of running on local machine.
145
+ set_property (TARGET dxdispatch PROPERTY VS_SOLUTION_DEPLOY ON )
146
+
147
+ # No need for logos/assets; this is a developer-only app.
148
+ target_sources (dxdispatch PRIVATE ${CMAKE_BINARY_DIR} /MicrosoftGame.config )
149
+ configure_file (${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch/dxdispatch.config.in MicrosoftGame.config )
150
+ set_source_files_properties (${CMAKE_BINARY_DIR} /MicrosoftGame.config PROPERTIES VS_TOOL_OVERRIDE "MGCCompile" )
151
+
152
+ # Copy MSVC/UCRT redist files matching the current toolset to the build output directory. Not all of the DLLs
153
+ # are necessary but this approach is simple and should avoid missing dependencies.
154
+ set (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE )
155
+ set (CMAKE_INSTALL_DEBUG_LIBRARIES TRUE )
156
+ set (CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY TRUE )
157
+ set (CMAKE_INSTALL_UCRT_LIBRARIES TRUE )
158
+ include (InstallRequiredSystemLibraries )
159
+ add_custom_command (
160
+ TARGET dxdispatch
161
+ POST_BUILD
162
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} $< TARGET_FILE_DIR:dxdispatch>
163
+ )
164
+
165
+ # For Copy models to the deployment directory even if other targets don't need to be built.
166
+ add_custom_target (
167
+ copy_models ALL
168
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR} /models" "${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_VS_PLATFORM_NAME} /Layout/Image/Loose/models"
169
+ )
170
+ endif ()
121
171
122
172
# ==============================================================================
123
173
# Tests
124
174
# ==============================================================================
125
- enable_testing ()
126
- include (GoogleTest )
127
-
128
- add_executable (
129
- jsontests
130
- src/test/JsonParserTests.cpp
131
- )
132
-
133
- target_compile_features (jsontests PRIVATE cxx_std_17 )
134
- target_link_libraries (
135
- jsontests
136
- PRIVATE
137
- gtest_main
138
- fmt::fmt-header-only
139
- Microsoft::DirectMLX
140
- model
141
- )
142
- target_include_directories (jsontests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch )
143
- gtest_discover_tests (jsontests )
144
-
145
- add_test (test_dml_convolution dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_convolution.json )
146
- set_tests_properties (test_dml_convolution PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 6, 8, 12, 14" )
147
-
148
- add_test (test_dml_cumulative_product dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_cumulative_product.json )
149
- set_tests_properties (test_dml_cumulative_product PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 2, 8, 64, 192" )
150
-
151
- add_test (test_dml_element_wise_add dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_add.json )
152
- set_tests_properties (test_dml_element_wise_add PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -2" )
153
-
154
- add_test (test_dml_element_wise_add1 dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_add1.json )
155
- set_tests_properties (test_dml_element_wise_add1 PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -0.432332" )
156
-
157
- add_test (test_dml_element_wise_clip dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_clip.json )
158
- set_tests_properties (test_dml_element_wise_clip PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'A': -2.5, -2.5, -2, -1, 0, 1, 2, 2.5, 2.5" )
159
-
160
- add_test (test_dml_element_wise_identity dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_identity.json )
161
- set_tests_properties (test_dml_element_wise_identity PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 12, 14, 16" )
162
-
163
- add_test (test_dml_fill_value_sequence dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_fill_value_sequence.json )
164
- set_tests_properties (test_dml_fill_value_sequence PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 3.2, 4.7, 6.2, 7.7, 9.2" )
165
-
166
- add_test (test_dml_join dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_join.json )
167
- set_tests_properties (test_dml_join PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 1, 2, 3, 100, 115, 5, 6, 7, 8, 9" )
168
-
169
- add_test (test_dml_reduce dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_reduce.json )
170
- set_tests_properties (test_dml_reduce PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 6, 15, 24" )
171
-
172
- add_test (test_dml_slice dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_slice.json )
173
- set_tests_properties (test_dml_slice PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 7, 9, 12, 14, 17, 19" )
174
-
175
- add_test (test_dml_split dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_split.json )
176
- set_tests_properties (test_dml_split PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out1': 1, 2\n Resource 'Out2': 3, 4\n Resource 'Out3': 5, 6" )
177
-
178
- add_test (test_dml_upsample_2d dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_upsample_2d.json )
179
- set_tests_properties (test_dml_upsample_2d PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 1, 1.25, 1.75, 2, 1.5, 1.75, 2.25, 2.5, 2.5, 2.75, 3.25, 3.5, 3, 3.25, 3.75, 4" )
180
-
181
- add_test (test_owned_by_dml dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/owned_by_dml.json )
182
- set_tests_properties (test_owned_by_dml PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -2" )
175
+ if (TARGET_WINDOWS OR TARGET_WSL )
176
+ option (DXD_TESTS "Build DxDispatch tests" ON )
177
+ else ()
178
+ option (DXD_TESTS "Build DxDispatch tests" OFF )
179
+ endif ()
180
+
181
+ if (DXD_TESTS )
182
+ enable_testing ()
183
+ include (GoogleTest )
184
+
185
+ add_executable (
186
+ jsontests
187
+ src/test/JsonParserTests.cpp
188
+ )
189
+
190
+ target_compile_features (jsontests PRIVATE cxx_std_17 )
191
+ target_link_libraries (
192
+ jsontests
193
+ PRIVATE
194
+ gtest_main
195
+ fmt::fmt-header-only
196
+ directml
197
+ d3d12
198
+ wil
199
+ model
200
+ )
201
+ target_include_directories (jsontests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /src/dxdispatch )
202
+ gtest_discover_tests (jsontests )
203
+
204
+ # Hacky. Needed for silly reasons related to defining GUIDs in winadapter. This should
205
+ # ideally be cleaned up at some point.
206
+ if (NOT WIN32 )
207
+ add_dependencies (jsontests dxdispatch )
208
+ endif ()
209
+
210
+ add_test (test_dml_convolution dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_convolution.json )
211
+ set_tests_properties (test_dml_convolution PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 6, 8, 12, 14" )
212
+
213
+ add_test (test_dml_cumulative_product dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_cumulative_product.json )
214
+ set_tests_properties (test_dml_cumulative_product PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 2, 8, 64, 192" )
215
+
216
+ add_test (test_dml_element_wise_add dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_add.json )
217
+ set_tests_properties (test_dml_element_wise_add PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -2" )
218
+
219
+ add_test (test_dml_element_wise_add1 dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_add1.json )
220
+ set_tests_properties (test_dml_element_wise_add1 PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -0.432332" )
221
+
222
+ add_test (test_dml_element_wise_clip dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_clip.json )
223
+ set_tests_properties (test_dml_element_wise_clip PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'A': -2.5, -2.5, -2, -1, 0, 1, 2, 2.5, 2.5" )
224
+
225
+ add_test (test_dml_element_wise_identity dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_element_wise_identity.json )
226
+ set_tests_properties (test_dml_element_wise_identity PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 12, 14, 16" )
227
+
228
+ add_test (test_dml_fill_value_sequence dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_fill_value_sequence.json )
229
+ set_tests_properties (test_dml_fill_value_sequence PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 3.2, 4.7, 6.2, 7.7, 9.2" )
230
+
231
+ add_test (test_dml_join dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_join.json )
232
+ set_tests_properties (test_dml_join PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 1, 2, 3, 100, 115, 5, 6, 7, 8, 9" )
233
+
234
+ add_test (test_dml_reduce dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_reduce.json )
235
+ set_tests_properties (test_dml_reduce PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 6, 15, 24" )
236
+
237
+ add_test (test_dml_slice dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_slice.json )
238
+ set_tests_properties (test_dml_slice PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 7, 9, 12, 14, 17, 19" )
239
+
240
+ add_test (test_dml_split dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_split.json )
241
+ set_tests_properties (test_dml_split PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out1': 1, 2\n Resource 'Out2': 3, 4\n Resource 'Out3': 5, 6" )
242
+
243
+ add_test (test_dml_upsample_2d dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/dml_upsample_2d.json )
244
+ set_tests_properties (test_dml_upsample_2d PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'output': 1, 1.25, 1.75, 2, 1.5, 1.75, 2.25, 2.5, 2.5, 2.75, 3.25, 3.5, 3, 3.25, 3.75, 4" )
245
+
246
+ add_test (test_owned_by_dml dxdispatch ${CMAKE_CURRENT_SOURCE_DIR} /models/owned_by_dml.json )
247
+ set_tests_properties (test_owned_by_dml PROPERTIES PASS_REGULAR_EXPRESSION "Resource 'Out': 6, 10, -2" )
248
+ endif ()
0 commit comments