Skip to content

Commit 92aaef1

Browse files
AnastaZIukdeprilula28
authored andcommitted
remove old algorithm for scanning input file dependencies and make the DXC CT target scan each input file dependencies recursively with new filtering approach, create proper dependency chain that works for each created custom command and perform tests on previous DXC config-dependent compilation
1 parent 34249ce commit 92aaef1

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ list(APPEND DXC_CMAKE_ARGS "-DDXC_BUILD_ARCH=x64")
3333
set(_DXC_CURRENT_CONFIG_ "$<IF:$<CONFIG:Debug>,Debug,Release>")
3434
set(DXC_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dxc" CACHE INTERNAL "")
3535
set(DXC_BINARY_DIR_EP "${CMAKE_CURRENT_BINARY_DIR}/external/dxc" CACHE INTERNAL "")
36-
set(DXC_BINARY_DIR_GE "${DXC_BINARY_DIR_EP}/${_DXC_CURRENT_CONFIG_}" CACHE INTERNAL "")
37-
set(DXC_BIN_DIR "${DXC_BINARY_DIR_GE}/${_DXC_CURRENT_CONFIG_}/bin" CACHE INTERNAL "")
38-
set(DXC_LIB_DIR "${DXC_BINARY_DIR_GE}/${_DXC_CURRENT_CONFIG_}/lib" CACHE INTERNAL "")
36+
set(DXC_BINARY_DIR_GE "${DXC_BINARY_DIR_EP}/build" CACHE INTERNAL "")
37+
set(DXC_BIN_DIR "${DXC_BINARY_DIR_GE}/Release/bin" CACHE INTERNAL "") # hardcoded
38+
set(DXC_LIB_DIR "${DXC_BINARY_DIR_GE}/${_DXC_CURRENT_CONFIG_}/lib" CACHE INTERNAL "") # library path depends on the configuration
3939
set(DXC_EXECUTABLE "${DXC_BIN_DIR}/dxc.exe" CACHE INTERNAL "")
40-
set(DXC_DXCOMPILER_LIB "${DXC_LIB_DIR}/dxcompiler.lib" CACHE INTERNAL "") # TODO: check if there is any debug postfix/suffix!
40+
set(DXC_DXCOMPILER_LIB "${DXC_LIB_DIR}/dxcompiler.lib" CACHE INTERNAL "")
4141

4242
# DXC External Project
4343
# builds DXC executable target and dxcompiler library target

src/nbl/CMakeLists.txt

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,41 @@ if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
630630
# MSVC and other generators have "SetEnv" task - we need to make sure our enviroment is clean while invoking DXC compilation
631631
string(APPEND _TMP_CLEAN_ENV_ "set PATH=$ENV{PATH}\nset CAExcludePath=\nset LIB=\nset LIBPATH=\nset INCLUDE=\nset EXTERNAL_INCLUDE=\n")
632632

633-
# Include dependency chain for considered compile file
633+
# include-dependency input file chain
634634
set(_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/depends.txt")
635635
set(_NBL_DXC_CT_CURRENT_IDC_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/depends.cmd")
636636
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_}\"")
637637
file(WRITE "${_NBL_DXC_CT_CURRENT_IDC_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_IDC_COMMAND_}")
638-
# TODO execute_process for _NBL_DXC_CT_CURRENT_IDC_FILEPATH_ and hanlding _NBL_DXC_CT_CURRENT_IDC_FILEPATH_'s deps by custom command
639638

640-
# Compile command
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
641668
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_}\"")
642669
set(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}/compile.cmd")
643670
file(WRITE "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}" "${_NBL_DXC_CT_WRAPPER_COMPILE_COMMAND_}")
@@ -649,50 +676,24 @@ if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
649676
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")
650677
endif()
651678

652-
###############################################################
653-
# scans include files of particular hlsl file to compile by DXC
654-
# performs validation of include files and adds them as DEPENDS
655-
# of custom command to keep track of modifications of any
656-
# dependency file
657-
#
658-
# TODO: add recursive scanning of ALL includes, right now it
659-
# doesn't scan recursivly but sinks only with include depth = 1
660-
###############################################################
661-
662-
set(_NBL_DXC_CT_CURRENT_ROOT_COMPILE_FILE_ISSUER_ "${_SHADER_FILE_PATH_}")
663-
list(APPEND _TMP_CURRENT_DEPS_LIST_ "${_NBL_DXC_CT_CURRENT_ROOT_COMPILE_FILE_ISSUER_}")
664-
file(STRINGS "${_NBL_DXC_CT_CURRENT_ROOT_COMPILE_FILE_ISSUER_}" _NBL_DXC_CT_INPUT_SCAN_INCLUDE_LINES_ REGEX "#include <|#include \"")
665-
666-
foreach(_NBL_DXC_CT_CURRENT_INPUT_SCAN_LINE_ IN LISTS _NBL_DXC_CT_INPUT_SCAN_INCLUDE_LINES_)
667-
string(REGEX MATCH "<.*>|\".*\"" _TMP_INCLUDE_WITH_SHEATH_CHARS_ "${_NBL_DXC_CT_CURRENT_INPUT_SCAN_LINE_}")
668-
string(REGEX REPLACE <|>|\" "" _TMP_INCLUDE_WITHOUT_SHEATH_CHARS_ "${_TMP_INCLUDE_WITH_SHEATH_CHARS_}")
669-
670-
set(_NBL_DXC_CT_CURRENT_HANDLED_INCLUDE_PATH_ "${_NBL_DXC_CT_INCLUDE_ROOT_}/${_TMP_INCLUDE_WITHOUT_SHEATH_CHARS_}")
671-
672-
if(NOT EXISTS "${_NBL_DXC_CT_CURRENT_HANDLED_INCLUDE_PATH_}")
673-
# NOTE: this won't work for shaders included that are registered on fly by asset manager, but let's assume we won't test shaders including another files stored in virtual file system
674-
message(FATAL_ERROR "${_NBL_DXC_CT_PREFIX_CMAKE_LOG_DEBUG_} File '${_NBL_DXC_CT_CURRENT_HANDLED_INCLUDE_PATH_}' included by '${_NBL_DXC_CT_CURRENT_ROOT_COMPILE_FILE_ISSUER_}' doesn't exist!")
675-
endif()
676-
677-
list(APPEND _TMP_CURRENT_DEPS_LIST_ "${_NBL_DXC_CT_CURRENT_HANDLED_INCLUDE_PATH_}") # add scanned include files as DEPENDS of a add_custom_command
678-
endforeach()
679-
680679
list(APPEND _NBL_DXC_CT_BIN_OUTPUTS_ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}")
681680

681+
# create custom command per input file with it's all dependencies listed as DEPENDS
682682
add_custom_command(
683683
OUTPUT "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_}"
684684
COMMAND "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_}"
685-
DEPENDS ${_TMP_CURRENT_DEPS_LIST_}
685+
DEPENDS ${_NBL_DXC_CT_CURRENT_DEPS_LIST_}
686686
WORKING_DIRECTORY "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_}"
687687
USES_TERMINAL
688688
VERBATIM
689689
)
690690

691691
unset(_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_)
692692
unset(_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_)
693-
unset(_TMP_CURRENT_DEPS_LIST_)
693+
unset(_NBL_DXC_CT_CURRENT_DEPS_LIST_)
694694
endforeach()
695-
695+
696+
# create custom targets for which DEPENDS are all of input files for DXC compile test
696697
add_custom_target(HLSL_NABLA_COMPILE_TEST DEPENDS ${_NBL_DXC_CT_BIN_OUTPUTS_}
697698
COMMENT "${CMAKE_COMMAND}" -E echo "Launching Nabla HLSL compile test..."
698699
)

0 commit comments

Comments
 (0)