summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-26 15:03:40 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-26 15:03:40 +0000
commit0717c9e7eb0d3fb5595b018c8bd97d66e81f2128 (patch)
tree65354a54901203411125e13dda4bb23cd8826f19 /Graphics/GraphicsEngineVulkan
parentFixed build warning + few minor updates to build script & readme (diff)
downloadDiligentCore-0717c9e7eb0d3fb5595b018c8bd97d66e81f2128.tar.gz
DiligentCore-0717c9e7eb0d3fb5595b018c8bd97d66e81f2128.zip
Enabled Vulkan backend to take compiled SPIRV byte code
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index e27445f9..137727ff 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -39,19 +39,36 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl*
m_StaticResCache (ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources),
m_StaticVarsMgr (*this)
{
- if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL)
+ if (CreationAttribs.Source != nullptr || CreationAttribs.FilePath != nullptr)
{
- m_SPIRV = HLSLtoSPIRV(CreationAttribs, CreationAttribs.ppCompilerOutput);
+ 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");
+
+ if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL)
+ {
+ m_SPIRV = HLSLtoSPIRV(CreationAttribs, CreationAttribs.ppCompilerOutput);
+ }
+ else
+ {
+ auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n");
+ m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast<int>(GLSLSource.length()), CreationAttribs.ppCompilerOutput);
+ }
+
+ if (m_SPIRV.empty())
+ {
+ LOG_ERROR_AND_THROW("Failed to compile shader");
+ }
}
- else
+ else if (CreationAttribs.ByteCode != nullptr)
{
- auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n");
- m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast<int>(GLSLSource.length()), CreationAttribs.ppCompilerOutput);
+ DEV_CHECK_ERR(CreationAttribs.ByteCodeSize != 0, "ByteCodeSize must not be 0");
+ DEV_CHECK_ERR(CreationAttribs.ByteCodeSize % 4 == 0, "Byte code size (", CreationAttribs.ByteCodeSize, ") is not multiple of 4");
+ m_SPIRV.resize(CreationAttribs.ByteCodeSize/4);
+ memcpy(m_SPIRV.data(), CreationAttribs.ByteCode, CreationAttribs.ByteCodeSize);
}
-
- if (m_SPIRV.empty())
+ else
{
- LOG_ERROR_AND_THROW("Failed to compile shader");
+ LOG_ERROR_AND_THROW("Shader source must be provided through one of the 'Source', 'FilePath' or 'ByteCode' members");
}
// We cannot create shader module here because resource bindings are assigned when