diff options
-rw-r--r-- | Help/release/dev/FindVulkan-dxc.rst | 5 | ||||
-rw-r--r-- | Modules/FindVulkan.cmake | 75 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/Run-dxc_exe.cmake | 20 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/main-dxc_lib.cxx | 23 |
5 files changed, 138 insertions, 0 deletions
diff --git a/Help/release/dev/FindVulkan-dxc.rst b/Help/release/dev/FindVulkan-dxc.rst new file mode 100644 index 0000000000..e22f016f37 --- /dev/null +++ b/Help/release/dev/FindVulkan-dxc.rst @@ -0,0 +1,5 @@ +FindVulkan-dxc +-------------- + +* The :module:`FindVulkan` module gained support for a DirectX Shader Compiler + component, ``dxc``. diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 78b07c41d7..0dcdb31005 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -20,6 +20,10 @@ This module respects several optional COMPONENTS: ``glslc``, On macOS, an additional component ``MoltenVK`` is available. There are corresponding import targets for each of these flags. +.. versionadded:: 3.25 + +Added optional COMPONENT ``dxc`` with corresponding targets. + IMPORTED Targets ^^^^^^^^^^^^^^^^ @@ -75,6 +79,16 @@ This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found: Defined if SDK has the Vulkan meta-loader (volk). +``Vulkan::dxc_lib`` + .. versionadded:: 3.25 + + Defined if SDK has the DirectX shader compiler library. + +``Vulkan::dxc_exe`` + .. versionadded:: 3.25 + + Defined if SDK has the DirectX shader compiler CLI tool. + Result Variables ^^^^^^^^^^^^^^^^ @@ -119,6 +133,17 @@ This module defines the following variables: True, if the SDK has the volk library. +``Vulkan_dxc_lib_FOUND`` + .. versionadded:: 3.25 + + True, if the SDK has the DirectX shader compiler library. + +``Vulkan_dxc_exe_FOUND`` + .. versionadded:: 3.25 + + True, if the SDK has the DirectX shader compiler CLI tool. + + The module will also defines these cache variables: ``Vulkan_INCLUDE_DIR`` @@ -151,6 +176,16 @@ The module will also defines these cache variables: Path to the volk library. +``Vulkan_dxc_LIBRARY`` + .. versionadded:: 3.25 + + Path to the DirectX shader compiler library. + +``Vulkan_dxc_EXECUTABLE`` + .. versionadded:: 3.25 + + Path to the DirectX shader compiler CLI tool. + Hints ^^^^^ @@ -396,6 +431,20 @@ if(volk IN_LIST Vulkan_FIND_COMPONENTS) mark_as_advanced(Vulkan_Volk_LIBRARY) endif() +if (dxc IN_LIST Vulkan_FIND_COMPONENTS) + find_library(Vulkan_dxc_LIBRARY + NAMES dxcompiler + HINTS + ${_Vulkan_hint_library_search_paths}) + mark_as_advanced(Vulkan_dxc_LIBRARY) + + find_program(Vulkan_dxc_EXECUTABLE + NAMES dxc + HINTS + ${_Vulkan_hint_executable_search_paths}) + mark_as_advanced(Vulkan_dxc_EXECUTABLE) +endif() + if(Vulkan_GLSLC_EXECUTABLE) set(Vulkan_glslc_FOUND TRUE) else() @@ -408,6 +457,12 @@ else() set(Vulkan_glslangValidator_FOUND FALSE) endif() +if (Vulkan_dxc_EXECUTABLE) + set(Vulkan_dxc_exe_FOUND TRUE) +else() + set(Vulkan_dxc_exe_FOUND FALSE) +endif() + function(_Vulkan_set_library_component_found component) cmake_parse_arguments(PARSE_ARGV 1 _ARG "NO_WARNING" @@ -459,6 +514,7 @@ _Vulkan_set_library_component_found(glslang _Vulkan_set_library_component_found(shaderc_combined) _Vulkan_set_library_component_found(SPIRV-Tools) _Vulkan_set_library_component_found(volk) +_Vulkan_set_library_component_found(dxc) if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY) set(Vulkan_MoltenVK_FOUND TRUE) @@ -764,6 +820,25 @@ if(Vulkan_FOUND) IMPORTED_LINK_INTERFACE_LIBRARIES dl) endif() endif() + + if (Vulkan_dxc_LIBRARY AND NOT TARGET Vulkan::dxc_lib) + add_library(Vulkan::dxc_lib STATIC IMPORTED) + set_property(TARGET Vulkan::dxc_lib + PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}") + set_property(TARGET Vulkan::dxc_lib APPEND + PROPERTY + IMPORTED_CONFIGURATIONS Release) + set_property(TARGET Vulkan::dxc_lib APPEND + PROPERTY + IMPORTED_LOCATION_RELEASE "${Vulkan_dxc_LIBRARY}") + endif() + + if(Vulkan_dxc_EXECUTABLE AND NOT TARGET Vulkan::dxc_exe) + add_executable(Vulkan::dxc_exe IMPORTED) + set_property(TARGET Vulkan::dxc_exe PROPERTY IMPORTED_LOCATION "${Vulkan_dxc_EXECUTABLE}") + endif() + endif() if(Vulkan_MoltenVK_FOUND) diff --git a/Tests/FindVulkan/Test/CMakeLists.txt b/Tests/FindVulkan/Test/CMakeLists.txt index 727e1ce838..dfcfc156a7 100644 --- a/Tests/FindVulkan/Test/CMakeLists.txt +++ b/Tests/FindVulkan/Test/CMakeLists.txt @@ -8,7 +8,9 @@ set(components shaderc_combined SPIRV-Tools volk + dxc ) + if(APPLE) list(APPEND components MoltenVK) endif() @@ -80,6 +82,10 @@ add_executable(test_tgt_volk main-volk.cxx) target_link_libraries(test_tgt_volk Vulkan::volk) add_test(NAME test_tgt_volk COMMAND test_tgt_volk) +add_executable(test_tgt_dxc_lib main-dxc_lib.cxx) +target_link_libraries(test_tgt_dxc_lib Vulkan::dxc_lib) +add_test(NAME test_tgt_dxc_lib COMMAND test_tgt_dxc_lib) + if(Vulkan_GLSLC_EXECUTABLE) add_test(NAME test_glslc COMMAND ${CMAKE_COMMAND} @@ -97,3 +103,12 @@ if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE) -P "${CMAKE_CURRENT_LIST_DIR}/Run-glslangValidator.cmake" ) endif() + +if(Vulkan_dxc_EXECUTABLE) + add_test(NAME test_dxc_exe + COMMAND ${CMAKE_COMMAND} + "-DVULKAN_DXC_EXECUTABLE=${Vulkan_dxc_EXECUTABLE}" + "-DVULKAN_DXC_EXECUTABLE_TARGET=$<TARGET_FILE:Vulkan::dxc_exe>" + -P "${CMAKE_CURRENT_LIST_DIR}/Run-dxc_exe.cmake" + ) +endif() diff --git a/Tests/FindVulkan/Test/Run-dxc_exe.cmake b/Tests/FindVulkan/Test/Run-dxc_exe.cmake new file mode 100644 index 0000000000..0d38855eea --- /dev/null +++ b/Tests/FindVulkan/Test/Run-dxc_exe.cmake @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.12) + +function(run_dxc_exe exe exe_display) + execute_process(COMMAND ${exe} --help + OUTPUT_VARIABLE output + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result + ) + + if(NOT result EQUAL 0) + message(SEND_ERROR "Result of ${exe_display} --help is ${result}, should be 0") + endif() + + if(NOT output MATCHES "^OVERVIEW: HLSL Compiler for ") + message(SEND_ERROR "Output of ${exe_display} --help is \"${output}\", should begin with \"OVERVIEW: HLSL Compiler for \"") + endif() +endfunction() + +run_dxc_exe("${VULKAN_DXC_EXECUTABLE}" "\${VULKAN_DXC_EXECUTABLE}") +run_dxc_exe("${VULKAN_DXC_EXECUTABLE_TARGET}" "Vulkan::dxc_exe") diff --git a/Tests/FindVulkan/Test/main-dxc_lib.cxx b/Tests/FindVulkan/Test/main-dxc_lib.cxx new file mode 100644 index 0000000000..6ccb0dea00 --- /dev/null +++ b/Tests/FindVulkan/Test/main-dxc_lib.cxx @@ -0,0 +1,23 @@ +#include <cstdio> + +#include "dxc/dxcapi.h" +#include "printf.h" + +int main() +{ + IDxcCompiler3* compiler; + DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&compiler)); + + assert(compiler); + + IDxcVersionInfo* version; + compiler->QueryInterface(&version); + + uint32_t major, minor; + version->GetVersion(&major, &minor); + printf("DirectX Shader Compiler: %u.%u\n", major, minor); + version->Release(); + compiler->Release(); + + return 0; +} |