Skip to content

Commit ecb189c

Browse files
AnastaZIukdeprilula28
authored andcommitted
move CT target creation to 3rdparty/dxc/CT/CMakeLists.txt, add HLSL_NABLA_COMPILE_TEST as Nabla's dependency on _NBL_ENABLE_DXC_COMPILE_TESTS_ condition
1 parent 92aaef1 commit ecb189c

File tree

3 files changed

+119
-114
lines changed

3 files changed

+119
-114
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ ExternalProject_Add(dxc
5757
)
5858

5959
unset(DXC_CMAKE_ARGS)
60-
unset(_DXC_CURRENT_CONFIG_)
60+
unset(_DXC_CURRENT_CONFIG_)
61+
62+
if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
63+
add_subdirectory(CT CT)
64+
endif()

3rdparty/dxc/CT/CMakeLists.txt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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
9+
set(_NBL_DXC_CT_BINARY_BIN_ "${CMAKE_CURRENT_BINARY_DIR}") # compile-test directory
10+
11+
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
12+
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_INCLUDE_ROOT_ = '${_NBL_DXC_CT_INCLUDE_ROOT_}'")
13+
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_BINARY_BIN_ = '${_NBL_DXC_CT_BINARY_BIN_}'")
14+
endif()
15+
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+
)
20+
21+
foreach(_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_)
22+
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
23+
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} adding _SHADER_FILE_PATH_ = '${_SHADER_FILE_PATH_}' as INPUT of DXC CT target")
24+
endif()
25+
26+
cmake_path(RELATIVE_PATH _SHADER_FILE_PATH_ BASE_DIRECTORY "${_NBL_DXC_CT_INCLUDE_ROOT_}" OUTPUT_VARIABLE _SHADER_NEW_RELATIVE_FILE_PATH_)
27+
cmake_path(GET _SHADER_NEW_RELATIVE_FILE_PATH_ STEM LAST_ONLY _SHADER_NEW_STEAM_)
28+
cmake_path(REMOVE_EXTENSION _SHADER_NEW_RELATIVE_FILE_PATH_ LAST_ONLY OUTPUT_VARIABLE _SHADER_NEW_RELATIVE_OUTPUT_DIR_)
29+
30+
set(_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_ "${_NBL_DXC_CT_BINARY_BIN_}/${_SHADER_NEW_RELATIVE_OUTPUT_DIR_}/bin")
31+
set(_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/${_SHADER_NEW_STEAM_}.bin")
32+
33+
# MSVC and other generators have "SetEnv" task - we need to make sure our enviroment is clean while invoking DXC compilation
34+
string(APPEND _TMP_CLEAN_ENV_ "set PATH=$ENV{PATH}\nset CAExcludePath=\nset LIB=\nset LIBPATH=\nset INCLUDE=\nset EXTERNAL_INCLUDE=\n")
35+
36+
# include-dependency input file chain
37+
set(_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/depends.txt")
38+
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_}\"")
40+
file(WRITE "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_IDC_COMMAND_}")
41+
42+
# create a file contating paths to all input file's dependencies scanned recursively
43+
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
44+
execute_process(COMMAND "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}")
45+
else()
46+
execute_process(COMMAND "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}"
47+
OUTPUT_QUIET
48+
ERROR_QUIET
49+
)
50+
endif()
51+
52+
file(READ "${_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_}" _NBL_DXC_CT_DEPENDENCIES_)
53+
unset(_NBL_DXC_CT_WRAPPER_IDC_COMMAND_)
54+
55+
# filter DXC output MF's file dependencies and put them into CMake list
56+
string(REPLACE ": " ";" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_}")
57+
string(REPLACE " \\" ";" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
58+
string(REPLACE "\r" "" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
59+
string(REPLACE "\n" "" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
60+
string(STRIP "${_NBL_DXC_CT_DEPENDENCIES_S_}" _NBL_DXC_CT_DEPENDENCIES_S_)
61+
list(APPEND _NBL_DXC_CT_DEPENDENCIES_L_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
62+
list(TRANSFORM _NBL_DXC_CT_DEPENDENCIES_L_ STRIP)
63+
list(REMOVE_DUPLICATES _NBL_DXC_CT_DEPENDENCIES_L_)
64+
65+
set(_NBL_DXC_CT_CURRENT_DEPS_LIST_ ${_NBL_DXC_CT_DEPENDENCIES_L_})
66+
unset(_NBL_DXC_CT_DEPENDENCIES_)
67+
unset(_NBL_DXC_CT_DEPENDENCIES_S_)
68+
unset(_NBL_DXC_CT_DEPENDENCIES_L_)
69+
70+
# 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_}\"")
72+
set(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/compile.cmd")
73+
file(WRITE "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_}")
74+
75+
unset(_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_)
76+
unset(_TMP_CLEAN_ENV_)
77+
78+
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
79+
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+
endif()
81+
82+
list(APPEND _NBL_DXC_CT_BIN_OUTPUTS_ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}")
83+
84+
# create custom command per input file with it's all dependencies listed as DEPENDS
85+
add_custom_command(
86+
OUTPUT "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}"
87+
COMMAND "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}"
88+
DEPENDS ${_NBL_DXC_CT_CURRENT_DEPS_LIST_}
89+
WORKING_DIRECTORY "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}"
90+
USES_TERMINAL
91+
VERBATIM
92+
)
93+
94+
unset(_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_)
95+
unset(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_)
96+
unset(_NBL_DXC_CT_CURRENT_DEPS_LIST_)
97+
endforeach()
98+
99+
# create custom targets for which DEPENDS are all of input files for DXC compile test
100+
add_custom_target(HLSL_NABLA_COMPILE_TEST DEPENDS ${_NBL_DXC_CT_BIN_OUTPUTS_}
101+
COMMENT "${CMAKE_COMMAND}" -E echo "Launching Nabla HLSL compile test..."
102+
)
103+
104+
add_dependencies(HLSL_NABLA_COMPILE_TEST dxc)
105+
106+
unset(_NBL_DXC_CT_BIN_OUTPUTS_)
107+
unset(_NBL_DXC_CT_BINARY_BIN_)
108+
unset(_NBL_DXC_CT_SHADER_FILES_)
109+
unset(_NBL_DXC_CT_INCLUDE_ROOT_)

src/nbl/CMakeLists.txt

Lines changed: 5 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ if(_NBL_COMPILE_WITH_GLI_)
580580
endif()
581581

582582
# DXC
583-
add_dependencies(Nabla dxc)
583+
if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
584+
add_dependencies(Nabla HLSL_NABLA_COMPILE_TEST)
585+
else()
586+
add_dependencies(Nabla dxc)
587+
endif()
584588
target_include_directories(Nabla PRIVATE
585589
"${DXC_BINARY_DIR_GE}/tools/clang/tools/dxcompiler"
586590
"${DXC_SOURCE_DIR}/tools/clang/tools/dxcompiler"
@@ -594,118 +598,6 @@ target_include_directories(Nabla PRIVATE
594598
)
595599
target_link_libraries(Nabla INTERFACE "${DXC_DXCOMPILER_LIB}")
596600

597-
############################################################################
598-
# list files you want to compile with DXC in _NBL_ENABLE_DXC_COMPILE_TESTS_
599-
# once we have guarantee all of shaders in Nabla can be compiled with DXC,
600-
# we can simply grep all of those files/use existing vars holding paths to
601-
# shaders and remove manual adding the files bellow
602-
###################################################
603-
604-
if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
605-
set(_NBL_DXC_CT_INCLUDE_ROOT_ "${NBL_ROOT_PATH}/include") # Nabla include root path for shaders
606-
set(_NBL_DXC_CT_BINARY_BIN_ "${CMAKE_CURRENT_BINARY_DIR}/DXC/CT") # compile-test directory
607-
608-
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
609-
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_INCLUDE_ROOT_ = '${_NBL_DXC_CT_INCLUDE_ROOT_}'")
610-
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} _NBL_DXC_CT_BINARY_BIN_ = '${_NBL_DXC_CT_BINARY_BIN_}'")
611-
endif()
612-
613-
# this is how you add file for compilation test
614-
set(_NBL_DXC_CT_SHADER_FILES_
615-
"${_NBL_DXC_CT_INCLUDE_ROOT_}/nbl/builtin/hlsl/barycentric/utils.hlsl"
616-
)
617-
618-
foreach(_SHADER_FILE_PATH_ IN LISTS _NBL_DXC_CT_SHADER_FILES_)
619-
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
620-
message("${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} adding _SHADER_FILE_PATH_ = '${_SHADER_FILE_PATH_}' as INPUT of DXC CT target")
621-
endif()
622-
623-
cmake_path(RELATIVE_PATH _SHADER_FILE_PATH_ BASE_DIRECTORY "${_NBL_DXC_CT_INCLUDE_ROOT_}" OUTPUT_VARIABLE _SHADER_NEW_RELATIVE_FILE_PATH_)
624-
cmake_path(GET _SHADER_NEW_RELATIVE_FILE_PATH_ STEM LAST_ONLY _SHADER_NEW_STEAM_)
625-
cmake_path(REMOVE_EXTENSION _SHADER_NEW_RELATIVE_FILE_PATH_ LAST_ONLY OUTPUT_VARIABLE _SHADER_NEW_RELATIVE_OUTPUT_DIR_)
626-
627-
set(_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_ "${_NBL_DXC_CT_BINARY_BIN_}/${_SHADER_NEW_RELATIVE_OUTPUT_DIR_}/bin")
628-
set(_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/${_SHADER_NEW_STEAM_}.bin")
629-
630-
# MSVC and other generators have "SetEnv" task - we need to make sure our enviroment is clean while invoking DXC compilation
631-
string(APPEND _TMP_CLEAN_ENV_ "set PATH=$ENV{PATH}\nset CAExcludePath=\nset LIB=\nset LIBPATH=\nset INCLUDE=\nset EXTERNAL_INCLUDE=\n")
632-
633-
# include-dependency input file chain
634-
set(_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/depends.txt")
635-
set(_NBL_DXC_CT_CURRENT_IDC_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/depends.cmd")
636-
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_}\"")
637-
file(WRITE "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_IDC_COMMAND_}")
638-
639-
# create a file contating paths to all input file's dependencies scanned recursively
640-
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
641-
execute_process(COMMAND "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}")
642-
else()
643-
execute_process(COMMAND "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}"
644-
OUTPUT_QUIET
645-
ERROR_QUIET
646-
)
647-
endif()
648-
649-
file(READ "${_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_}" _NBL_DXC_CT_DEPENDENCIES_)
650-
unset(_NBL_DXC_CT_WRAPPER_IDC_COMMAND_)
651-
652-
# filter DXC output MF's file dependencies and put them into CMake list
653-
string(REPLACE ": " ";" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_}")
654-
string(REPLACE " \\" ";" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
655-
string(REPLACE "\r" "" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
656-
string(REPLACE "\n" "" _NBL_DXC_CT_DEPENDENCIES_S_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
657-
string(STRIP "${_NBL_DXC_CT_DEPENDENCIES_S_}" _NBL_DXC_CT_DEPENDENCIES_S_)
658-
list(APPEND _NBL_DXC_CT_DEPENDENCIES_L_ "${_NBL_DXC_CT_DEPENDENCIES_S_}")
659-
list(TRANSFORM _NBL_DXC_CT_DEPENDENCIES_L_ STRIP)
660-
list(REMOVE_DUPLICATES _NBL_DXC_CT_DEPENDENCIES_L_)
661-
662-
set(_NBL_DXC_CT_CURRENT_DEPS_LIST_ ${_NBL_DXC_CT_DEPENDENCIES_L_})
663-
unset(_NBL_DXC_CT_DEPENDENCIES_)
664-
unset(_NBL_DXC_CT_DEPENDENCIES_S_)
665-
unset(_NBL_DXC_CT_DEPENDENCIES_L_)
666-
667-
# compile command
668-
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_}\"")
669-
set(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/compile.cmd")
670-
file(WRITE "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_}")
671-
672-
unset(_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_)
673-
unset(_TMP_CLEAN_ENV_)
674-
675-
if(_NBL_DXC_COMPILE_TESTS_ENABLE_CMAKE_LOG_)
676-
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")
677-
endif()
678-
679-
list(APPEND _NBL_DXC_CT_BIN_OUTPUTS_ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}")
680-
681-
# create custom command per input file with it's all dependencies listed as DEPENDS
682-
add_custom_command(
683-
OUTPUT "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}"
684-
COMMAND "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}"
685-
DEPENDS ${_NBL_DXC_CT_CURRENT_DEPS_LIST_}
686-
WORKING_DIRECTORY "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}"
687-
USES_TERMINAL
688-
VERBATIM
689-
)
690-
691-
unset(_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_)
692-
unset(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_)
693-
unset(_NBL_DXC_CT_CURRENT_DEPS_LIST_)
694-
endforeach()
695-
696-
# create custom targets for which DEPENDS are all of input files for DXC compile test
697-
add_custom_target(HLSL_NABLA_COMPILE_TEST DEPENDS ${_NBL_DXC_CT_BIN_OUTPUTS_}
698-
COMMENT "${CMAKE_COMMAND}" -E echo "Launching Nabla HLSL compile test..."
699-
)
700-
701-
add_dependencies(HLSL_NABLA_COMPILE_TEST dxc)
702-
703-
unset(_NBL_DXC_CT_BIN_OUTPUTS_)
704-
unset(_NBL_DXC_CT_BINARY_BIN_)
705-
unset(_NBL_DXC_CT_SHADER_FILES_)
706-
unset(_NBL_DXC_CT_INCLUDE_ROOT_)
707-
endif()
708-
709601
# Linux Display Systems
710602
if (UNIX AND NOT ANDROID AND NOT APPLE)
711603
target_include_directories(Nabla PUBLIC

0 commit comments

Comments
 (0)