From 1313de1ab167fe67d14fa2a848946f442491ca11 Mon Sep 17 00:00:00 2001 From: azhirnov Date: Tue, 25 Aug 2020 04:56:42 +0300 Subject: added HLSLTools, HLSL shader compiler refactoring added ShaderCompiler field to ShaderCreateInfo, fixed tests that doesn't compile on DXC, added dxc/WinAdapter.h to fix compilation on linux --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 1 + Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 48 ++++++++++++---------- 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 647cf48f..4d4e495b 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -179,6 +179,7 @@ set(PRIVATE_DEPENDENCIES Diligent-TargetPlatform Diligent-GraphicsEngineNextGenBase Diligent-GLSLTools + Diligent-HLSLTools ) if (${DILIGENT_NO_HLSL}) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 65e9f274..554d9b73 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -64,32 +64,38 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, "# define VULKAN 1\n" "#endif\n"; - if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL && - (CreationAttribs.HLSLVersion.Major == 0 || CreationAttribs.HLSLVersion.Major > 5) && - HasDXILCompilerForVulkan()) - { - m_SPIRV = HLSLtoSPIRVusingDXIL(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput); - } - else + switch (CreationAttribs.ShaderCompiler) { + case SHADER_COMPILER_DXC: + m_SPIRV = DXILtoSPIRV(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput); + break; + + case SHADER_COMPILER_DEFAULT: + case SHADER_COMPILER_GLSLANG: + { #if DILIGENT_NO_GLSLANG - LOG_ERROR_AND_THROW("Diligent engine was not linked with glslang and can only consume compiled SPIRV bytecode."); + LOG_ERROR_AND_THROW("Diligent engine was not linked with glslang, use DXIL compiler or precompiled SPIRV bytecode."); #else - if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL) - { - m_SPIRV = HLSLtoSPIRV(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput); + if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL) + { + m_SPIRV = HLSLtoSPIRV(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput); + } + else + { + auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), + TargetGLSLCompiler::glslang, + VulkanDefine); + + m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), + static_cast(GLSLSource.length()), + CreationAttribs.ppCompilerOutput); + } +#endif + break; } - else - { - auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), - TargetGLSLCompiler::glslang, - VulkanDefine); - m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), - static_cast(GLSLSource.length()), - CreationAttribs.ppCompilerOutput); - } -#endif + default: + LOG_ERROR_AND_THROW("Unsupported shader compiler"); } if (m_SPIRV.empty()) -- cgit v1.2.3