summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-07-24 01:07:02 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-07-24 01:07:02 +0000
commit57c5b28cefe726a2c332ba226f28bee580ba82a2 (patch)
tree80588b059f0dfb26e2ded46f62d7f5c760c62ae3 /Graphics/GLSLTools
parentAnother attempt to fix windows build issues with python (diff)
downloadDiligentCore-57c5b28cefe726a2c332ba226f28bee580ba82a2.tar.gz
DiligentCore-57c5b28cefe726a2c332ba226f28bee580ba82a2.zip
Vulkan backend: added SPIRV legalization when compiling from HLSL
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/src/SPIRVUtils.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/Graphics/GLSLTools/src/SPIRVUtils.cpp b/Graphics/GLSLTools/src/SPIRVUtils.cpp
index 46e26470..3bdada38 100644
--- a/Graphics/GLSLTools/src/SPIRVUtils.cpp
+++ b/Graphics/GLSLTools/src/SPIRVUtils.cpp
@@ -37,6 +37,8 @@
#include "DataBlobImpl.h"
#include "RefCntAutoPtr.h"
+#include "spirv-tools/optimizer.hpp"
+
static const char g_HLSLDefinitions[] =
{
#include "../../GraphicsEngineD3DBase/include/HLSLDefinitions_inc.fxh"
@@ -461,7 +463,22 @@ std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, IDataBlob
Shader.setStringsWithLengthsAndNames(ShaderStrings, ShaderStringLenghts, Names, 1);
IncluderImpl Includer(Attribs.pShaderSourceStreamFactory);
- return CompileShaderInternal(Shader, messages, &Includer, SourceCode, SourceCodeLen, ppCompilerOutput);
+ auto SPIRV = CompileShaderInternal(Shader, messages, &Includer, SourceCode, SourceCodeLen, ppCompilerOutput);
+
+ // SPIR-V bytecode generated from HLSL must be legalized to
+ // turn it into a valid vulkan SPIR-V shader
+ spvtools::Optimizer SpirvOptimizer(SPV_ENV_VULKAN_1_0);
+ SpirvOptimizer.RegisterLegalizationPasses();
+ std::vector<uint32_t> LegalizedSPIRV;
+ if (SpirvOptimizer.Run(SPIRV.data(), SPIRV.size(), &LegalizedSPIRV))
+ {
+ return std::move(LegalizedSPIRV);
+ }
+ else
+ {
+ LOG_ERROR("Failed to legalize SPIR-V shader generated by HLSL front-end. This may result in undefined behavior.");
+ return std::move(SPIRV);
+ }
}
std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char* ShaderSource, int SourceCodeLen, IDataBlob** ppCompilerOutput)