1
- ############################################################################
2
- # list files you want to compile with DXC in _NBL_ENABLE_DXC_COMPILE_TESTS_
3
- # once we have guarantee all of shaders in Nabla can be compiled with DXC,
4
- # we can simply grep all of those files/use existing vars holding paths to
5
- # shaders and remove manual adding the files bellow
6
- ###################################################
7
-
8
- set (_NBL_DXC_CT_INCLUDE_ROOT_ "${NBL_ROOT_PATH} /include" ) # Nabla include root path for shaders
1
+ set (_NBL_DXC_CT_INCLUDE_ROOT_ "${NBL_ROOT_PATH} /include" ) # Nabla include root path
9
2
set (_NBL_DXC_CT_BINARY_BIN_ "${CMAKE_CURRENT_BINARY_DIR} " ) # compile-test directory
10
3
11
4
if (_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_ )
12
5
message ("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_INCLUDE_ROOT_ = '${_NBL_DXC_CT_INCLUDE_ROOT_} '" )
13
6
message ("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_BINARY_BIN_ = '${_NBL_DXC_CT_BINARY_BIN_} '" )
14
7
endif ()
15
8
16
- # this is how you add file for compilation test
17
- set (_NBL_DXC_CT_SHADER_FILES_
18
- "${_NBL_DXC_CT_INCLUDE_ROOT_} /nbl/builtin/hlsl/barycentric/utils.hlsl"
19
- )
9
+ ####################################
10
+ # NBL_DXC_CT_ADD_INPUT_FILE function
11
+ # @_NBL_INPUT_REL_FILEPATH_@ is path relative to _NBL_DXC_CT_INCLUDE_ROOT_, the file must be nested in _NBL_DXC_CT_INCLUDE_ROOT_ as well to follow Nabla include rules
12
+ # @_NBL_PROFILE_@ is DXC target profile, e.g "lib_6_7"
13
+ # @_NBL_ENTRY_POINT_@ is entry point name for both HLSL and SPIRV if enabled. Leave it as empty "" string to not specify the entry point explicitly
14
+ # @_NBL_GENERATE_SPIRV_@ is a bool option for enabling SPIRV code generation
15
+ #############################################################################
20
16
21
- foreach (_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_ )
17
+ function (NBL_DXC_CT_ADD_INPUT_FILE _NBL_INPUT_REL_FILEPATH_ _NBL_PROFILE_ _NBL_ENTRY_POINT_ _NBL_GENERATE_SPIRV_ )
18
+ set (_SHADER_FILE_PATH_ "${_NBL_DXC_CT_INCLUDE_ROOT_} /${_NBL_INPUT_REL_FILEPATH_} " )
19
+
22
20
if (_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_ )
23
21
message ("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} adding _SHADER_FILE_PATH_ = '${_SHADER_FILE_PATH_} ' as INPUT of DXC CT target" )
24
22
endif ()
@@ -30,13 +28,31 @@ foreach(_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_)
30
28
set (_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_ "${_NBL_DXC_CT_BINARY_BIN_} /${_SHADER_NEW_RELATIVE_OUTPUT_DIR_} /bin" )
31
29
set (_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /${_SHADER_NEW_STEAM_} .bin" )
32
30
31
+ string (FIND "${_NBL_PROFILE_} " "lib" _TMP_FOUND_LIB_PROFILE_ )
32
+ if ("${_TMP_FOUND_LIB_PROFILE_} " STREQUAL "-1" )
33
+ if (_NBL_GENERATE_SPIRV_ )
34
+ cmake_path (REPLACE_EXTENSION _NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ "spv" )
35
+ endif ()
36
+ else ()
37
+ cmake_path (REPLACE_EXTENSION _NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ "dxil" )
38
+ endif ()
39
+ unset (_TMP_FOUND_LIB_PROFILE_ )
40
+
33
41
# MSVC and other generators have "SetEnv" task - we need to make sure our enviroment is clean while invoking DXC compilation
34
42
string (APPEND _TMP_CLEAN_ENV_ "set PATH=$ENV{PATH} \n set CAExcludePath=\n set LIB=\n set LIBPATH=\n set INCLUDE=\n set EXTERNAL_INCLUDE=\n " )
35
43
44
+ if (NOT "${_NBL_ENTRY_POINT_} " STREQUAL "" )
45
+ string (APPEND _TMP_ENTRY_POINT_ARG_ "-E ${_NBL_ENTRY_POINT_} " )
46
+ endif ()
47
+
48
+ if (_NBL_GENERATE_SPIRV_ )
49
+ string (APPEND _TMP_ENABLE_SPIRV_GEN_ARG_ "-spirv" )
50
+ endif ()
51
+
36
52
# include-dependency input file chain
37
53
set (_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /depends.txt" )
38
54
set (_NBL_DXC_CT_CURRENT_IDC_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /depends.cmd" )
39
- string (APPEND _NBL_DXC_CT_WRAPPER_IDC_COMMAND_ "${_TMP_CLEAN_ENV_} \" ${DXC_EXECUTABLE} \" -HV 2021 -T lib_6_7 -I\" ${_NBL_DXC_CT_INCLUDE_ROOT_} \" -Zi -MF \" ${_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_} \" \" ${_SHADER_FILE_PATH_} \" " )
55
+ string (APPEND _NBL_DXC_CT_WRAPPER_IDC_COMMAND_ "${_TMP_CLEAN_ENV_} \" ${DXC_EXECUTABLE} \" -HV 2021 -T ${_NBL_PROFILE_} ${_TMP_ENTRY_POINT_ARG_} ${_TMP_ENABLE_SPIRV_GEN_ARG_} -I\" ${_NBL_DXC_CT_INCLUDE_ROOT_} \" -Zi -MF \" ${_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_} \" \" ${_SHADER_FILE_PATH_} \" " )
40
56
file (WRITE "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_} " "${_NBL_DXC_CT_WRAPPER_IDC_COMMAND_} " )
41
57
42
58
# create a file contating paths to all input file's dependencies scanned recursively
@@ -68,18 +84,23 @@ foreach(_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_)
68
84
unset (_NBL_DXC_CT_DEPENDENCIES_L_ )
69
85
70
86
# compile command
71
- string (APPEND _NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_ "${_TMP_CLEAN_ENV_} \" ${DXC_EXECUTABLE} \" -HV 2021 -T lib_6_7 -I\" ${_NBL_DXC_CT_INCLUDE_ROOT_} \" -Zi -Fo \" ${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} \" \" ${_SHADER_FILE_PATH_} \" " )
87
+ string (APPEND _NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_ "${_TMP_CLEAN_ENV_} \" ${DXC_EXECUTABLE} \" -HV 2021 -T ${_NBL_PROFILE_} ${_TMP_ENTRY_POINT_ARG_} ${_TMP_ENABLE_SPIRV_GEN_ARG_} -I\" ${_NBL_DXC_CT_INCLUDE_ROOT_} \" -Zi -Fo \" ${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} \" \" ${_SHADER_FILE_PATH_} \" " )
72
88
set (_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /compile.cmd" )
73
89
file (WRITE "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_} " "${_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_} " )
74
90
75
91
unset (_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_ )
76
92
unset (_TMP_CLEAN_ENV_ )
93
+ unset (_TMP_ENTRY_POINT_ARG_ )
94
+ unset (_TMP_ENABLE_SPIRV_GEN_ARG_ )
77
95
78
96
if (_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_ )
79
97
message ("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} adding _NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ = '${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} ' as OUTPUT of DXC CT target" )
80
98
endif ()
81
99
82
- list (APPEND _NBL_DXC_CT_BIN_OUTPUTS_ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} " )
100
+ set (_NBL_DXC_CT_BIN_OUTPUTS_
101
+ ${_NBL_DXC_CT_BIN_OUTPUTS_}
102
+ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} "
103
+ PARENT_SCOPE )
83
104
84
105
# create custom command per input file with it's all dependencies listed as DEPENDS
85
106
add_custom_command (
@@ -91,10 +112,17 @@ foreach(_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_)
91
112
VERBATIM
92
113
)
93
114
115
+ unset (_SHADER_FILE_PATH_ )
94
116
unset (_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ )
95
117
unset (_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ )
96
118
unset (_NBL_DXC_CT_CURRENT_DEPS_LIST_ )
97
- endforeach ()
119
+ endfunction ()
120
+
121
+ ###############################################################################
122
+ # list files you would like to compile with DXC using NBL_DXC_CT_ADD_INPUT_FILE
123
+ ###############################################################################
124
+
125
+ NBL_DXC_CT_ADD_INPUT_FILE ("nbl/builtin/hlsl/barycentric/utils.hlsl" "lib_6_7" "" OFF )
98
126
99
127
# create custom targets for which DEPENDS are all of input files for DXC compile test
100
128
add_custom_target (HLSL_NABLA_COMPILE_TEST DEPENDS ${_NBL_DXC_CT_BIN_OUTPUTS_}
@@ -105,5 +133,4 @@ add_dependencies(HLSL_NABLA_COMPILE_TEST dxc)
105
133
106
134
unset (_NBL_DXC_CT_BIN_OUTPUTS_ )
107
135
unset (_NBL_DXC_CT_BINARY_BIN_ )
108
- unset (_NBL_DXC_CT_SHADER_FILES_ )
109
136
unset (_NBL_DXC_CT_INCLUDE_ROOT_ )
0 commit comments