@@ -630,14 +630,41 @@ if(_NBL_ENABLE_DXC_COMPILE_TESTS_)
630
630
# MSVC and other generators have "SetEnv" task - we need to make sure our enviroment is clean while invoking DXC compilation
631
631
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 " )
632
632
633
- # Include dependency chain for considered compile file
633
+ # include- dependency input file chain
634
634
set (_NBL_DXC_CT_CURRENT_DEPENDS_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /depends.txt" )
635
635
set (_NBL_DXC_CT_CURRENT_IDC_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /depends.cmd" )
636
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
637
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
639
638
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
641
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_} \" " )
642
669
set (_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} /compile.cmd" )
643
670
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_)
649
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" )
650
677
endif ()
651
678
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
-
680
679
list (APPEND _NBL_DXC_CT_BIN_OUTPUTS_ "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} " )
681
680
681
+ # create custom command per input file with it's all dependencies listed as DEPENDS
682
682
add_custom_command (
683
683
OUTPUT "${_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_} "
684
684
COMMAND "${_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_} "
685
- DEPENDS ${_TMP_CURRENT_DEPS_LIST_ }
685
+ DEPENDS ${_NBL_DXC_CT_CURRENT_DEPS_LIST_ }
686
686
WORKING_DIRECTORY "${_NBL_DXC_CT_CURRENT_OUTPUT_BIN_DIR_} "
687
687
USES_TERMINAL
688
688
VERBATIM
689
689
)
690
690
691
691
unset (_NBL_DXC_CT_CURRENT_OUTPUT_FILEPATH_ )
692
692
unset (_NBL_DXC_CT_CURRENT_SHADER_COMPILE_FILEPATH_ )
693
- unset (_TMP_CURRENT_DEPS_LIST_ )
693
+ unset (_NBL_DXC_CT_CURRENT_DEPS_LIST_ )
694
694
endforeach ()
695
-
695
+
696
+ # create custom targets for which DEPENDS are all of input files for DXC compile test
696
697
add_custom_target (HLSL_NABLA_COMPILE_TEST DEPENDS ${_NBL_DXC_CT_BIN_OUTPUTS_}
697
698
COMMENT "${CMAKE_COMMAND} " -E echo "Launching Nabla HLSL compile test..."
698
699
)
0 commit comments