summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-11-09 17:01:53 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-11-09 17:01:53 +0000
commit5874e6b071ffbb9cc73f96bb7bf6afff5a532ff9 (patch)
tree9ad0d6c4146948b1add3bc1c7762d452e340088c /Graphics/GLSLTools
parentFixed cmake 3.13 policy CMP0077 warnings (diff)
downloadDiligentCore-5874e6b071ffbb9cc73f96bb7bf6afff5a532ff9.tar.gz
DiligentCore-5874e6b071ffbb9cc73f96bb7bf6afff5a532ff9.zip
Using entry point name from SPIRV bytecode (fixed https://github.com/DiligentGraphics/DiligentCore/issues/39)
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/include/SPIRVShaderResources.h3
-rw-r--r--Graphics/GLSLTools/src/SPIRVShaderResources.cpp42
2 files changed, 43 insertions, 2 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h
index 0a798495..28fb147e 100644
--- a/Graphics/GLSLTools/include/SPIRVShaderResources.h
+++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h
@@ -211,7 +211,8 @@ public:
std::vector<uint32_t> spirv_binary,
const ShaderDesc& shaderDesc,
const char* CombinedSamplerSuffix,
- bool LoadShaderStageInputs);
+ bool LoadShaderStageInputs,
+ std::string& EntryPoint);
SPIRVShaderResources (const SPIRVShaderResources&) = delete;
SPIRVShaderResources ( SPIRVShaderResources&&) = delete;
diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
index 5fe9a460..853d0174 100644
--- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
+++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
@@ -91,17 +91,57 @@ static Int32 FindImmutableSampler(const ShaderDesc& shaderDesc, const std::strin
return -1;
}
+static spv::ExecutionModel ShaderTypeToExecutionModel(SHADER_TYPE ShaderType)
+{
+ switch(ShaderType)
+ {
+ case SHADER_TYPE_VERTEX: return spv::ExecutionModelVertex;
+ case SHADER_TYPE_HULL: return spv::ExecutionModelTessellationControl;
+ case SHADER_TYPE_DOMAIN: return spv::ExecutionModelTessellationEvaluation;
+ case SHADER_TYPE_GEOMETRY: return spv::ExecutionModelGeometry;
+ case SHADER_TYPE_PIXEL: return spv::ExecutionModelFragment;
+ case SHADER_TYPE_COMPUTE: return spv::ExecutionModelGLCompute;
+
+ default:
+ UNEXPECTED("Unexpected shader type");
+ return spv::ExecutionModelVertex;
+ }
+}
+
SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
IRenderDevice* pRenderDevice,
std::vector<uint32_t> spirv_binary,
const ShaderDesc& shaderDesc,
const char* CombinedSamplerSuffix,
- bool LoadShaderStageInputs) :
+ bool LoadShaderStageInputs,
+ std::string& EntryPoint) :
m_ShaderType(shaderDesc.ShaderType)
{
// https://github.com/KhronosGroup/SPIRV-Cross/wiki/Reflection-API-user-guide
spirv_cross::Compiler Compiler(std::move(spirv_binary));
+ spv::ExecutionModel ExecutionModel = ShaderTypeToExecutionModel(shaderDesc.ShaderType);
+ auto EntryPoints = Compiler.get_entry_points_and_stages();
+ for (const auto& CurrEntryPoint : EntryPoints)
+ {
+ if (CurrEntryPoint.execution_model == ExecutionModel)
+ {
+ if (!EntryPoint.empty())
+ {
+ LOG_WARNING_MESSAGE("More than one entry point of type ", GetShaderTypeLiteralName(shaderDesc.ShaderType), " found in SPIRV binary for shader '", shaderDesc.Name, "'. The first one ('", EntryPoint, "') will be used.");
+ }
+ else
+ {
+ EntryPoint = CurrEntryPoint.name;
+ }
+ }
+ }
+ if (EntryPoint.empty())
+ {
+ LOG_ERROR_AND_THROW("Unable to find entry point of type ", GetShaderTypeLiteralName(shaderDesc.ShaderType), " in SPIRV binary for shader '", shaderDesc.Name, "'");
+ }
+ Compiler.set_entry_point(EntryPoint, ExecutionModel);
+
// The SPIR-V is now parsed, and we can perform reflection on it.
spirv_cross::ShaderResources resources = Compiler.get_shader_resources();