summaryrefslogtreecommitdiffstats
path: root/Graphics
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
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')
-rw-r--r--Graphics/GLSLTools/include/SPIRVShaderResources.h3
-rw-r--r--Graphics/GLSLTools/src/SPIRVShaderResources.cpp42
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp5
4 files changed, 46 insertions, 6 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();
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
index adcc6a31..d42973c2 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
@@ -96,7 +96,7 @@ private:
ShaderResourceCacheVk m_StaticResCache;
ShaderVariableManagerVk m_StaticVarsMgr;
- const std::string m_EntryPoint;
+ std::string m_EntryPoint;
std::vector<uint32_t> m_SPIRV;
};
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index 56e32ed1..54ce0030 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -38,8 +38,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl*
TShaderBase (pRefCounters, pRenderDeviceVk, CreationAttribs.Desc),
m_StaticResLayout (*this, pRenderDeviceVk->GetLogicalDevice()),
m_StaticResCache (ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources),
- m_StaticVarsMgr (*this),
- m_EntryPoint (CreationAttribs.EntryPoint)
+ m_StaticVarsMgr (*this)
{
if (CreationAttribs.Source != nullptr || CreationAttribs.FilePath != nullptr)
{
@@ -80,7 +79,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl*
auto& Allocator = GetRawAllocator();
auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources));
bool IsHLSLVertexShader = CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL && m_Desc.ShaderType == SHADER_TYPE_VERTEX;
- auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr, IsHLSLVertexShader);
+ auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr, IsHLSLVertexShader, m_EntryPoint);
m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator));
if (IsHLSLVertexShader)