summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-08-19 20:56:45 +0000
committerazhirnov <zh1dron@gmail.com>2020-08-19 20:57:55 +0000
commit58e5c53f4bcb29139dace9576d35da16c492ba89 (patch)
tree5a8a4c34719eff4c99439607a56dfd691b6e3d04 /Graphics/GraphicsEngineVulkan
parentRemoved macros HAS_D12_DXIL_COMPILER (diff)
downloadDiligentCore-58e5c53f4bcb29139dace9576d35da16c492ba89.tar.gz
DiligentCore-58e5c53f4bcb29139dace9576d35da16c492ba89.zip
Move DXIL compiler for SPIRV to separate file, allow to compile HLSL without glslang.
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/CMakeLists.txt2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp37
2 files changed, 26 insertions, 13 deletions
diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt
index 51bb9dc5..edb18711 100644
--- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt
+++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt
@@ -230,6 +230,8 @@ if(EXISTS ${Vulkan_BINARY})
set(DXC_VK_COMPILER_PATH "${Vulkan_BINARY}" CACHE INTERNAL "" FORCE)
target_compile_definitions(Diligent-GraphicsEngineVk-static PRIVATE HAS_VK_DXIL_COMPILER)
message(STATUS "Found DXIL compiler for Vulkan")
+else()
+ set(HAS_VK_DXIL_COMPILER FALSE CACHE INTERNAL "" FORCE)
endif()
if(PLATFORM_WIN32)
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index a2f6ddc6..65e9f274 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -37,6 +37,7 @@
#if !DILIGENT_NO_GLSLANG
# include "SPIRVUtils.hpp"
#endif
+#include "DXILUtils.hpp"
namespace Diligent
{
@@ -55,9 +56,6 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters,
{
if (CreationAttribs.Source != nullptr || CreationAttribs.FilePath != nullptr)
{
-#if DILIGENT_NO_GLSLANG
- LOG_ERROR_AND_THROW("Diligent engine was not linked with glslang and can only consume compiled SPIRV bytecode.");
-#else
DEV_CHECK_ERR(CreationAttribs.ByteCode == nullptr, "'ByteCode' must be null when shader is created from source code or a file");
DEV_CHECK_ERR(CreationAttribs.ByteCodeSize == 0, "'ByteCodeSize' must be 0 when shader is created from source code or a file");
@@ -65,26 +63,39 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters,
"#ifndef VULKAN\n"
"# define VULKAN 1\n"
"#endif\n";
- if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL)
+
+ if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL &&
+ (CreationAttribs.HLSLVersion.Major == 0 || CreationAttribs.HLSLVersion.Major > 5) &&
+ HasDXILCompilerForVulkan())
{
- m_SPIRV = HLSLtoSPIRV(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput);
+ m_SPIRV = HLSLtoSPIRVusingDXIL(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<int>(GLSLSource.length()),
- CreationAttribs.ppCompilerOutput);
+#if DILIGENT_NO_GLSLANG
+ LOG_ERROR_AND_THROW("Diligent engine was not linked with glslang and can only consume compiled SPIRV bytecode.");
+#else
+ 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<int>(GLSLSource.length()),
+ CreationAttribs.ppCompilerOutput);
+ }
+#endif
}
if (m_SPIRV.empty())
{
LOG_ERROR_AND_THROW("Failed to compile shader");
}
-#endif
}
else if (CreationAttribs.ByteCode != nullptr)
{