Skip to content

Commit

Permalink
[DebugLayer] Report error in debug validation when PSO uses uniforms …
Browse files Browse the repository at this point in the history
…but shader reflection failed (#144).
  • Loading branch information
LukasBanana committed Jan 11, 2025
1 parent 3b7aef0 commit aaedbdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions sources/Renderer/DebugLayer/DbgRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,20 +2003,16 @@ void DbgRenderSystem::ValidateGraphicsPipelineDesc(const GraphicsPipelineDescrip

if (const DbgPipelineLayout* pipelineLayoutDbg = DbgGetWrapper<DbgPipelineLayout>(pipelineStateDesc.pipelineLayout))
{
ValidatePipelineStateUniforms(*pipelineLayoutDbg, shadersDbg);
ValidatePipelineStateUniforms(*pipelineLayoutDbg, shadersDbg, pipelineStateDesc.debugName);

/* If shader reflection failed, report error if PSO layout requires it (Vulkan specific) */
if (hasShadersWithFailedReflection && IsVulkan())
{
if (!pipelineLayoutDbg->desc.bindings.empty() &&
!pipelineLayoutDbg->desc.heapBindings.empty())
{
const std::string psoLabel =
(
pipelineStateDesc.debugName != nullptr && *pipelineStateDesc.debugName != '\0'
? " '" + std::string(pipelineStateDesc.debugName) + '\''
: ""
);
const char* psoDebugName = pipelineStateDesc.debugName;
const std::string psoLabel = (psoDebugName != nullptr && *psoDebugName != '\0' ? " '" + std::string(psoDebugName) + '\'' : "");
LLGL_DBG_ERROR(
ErrorType::UndefinedBehavior,
"failed to reflect shader code in PSO%s with mix of heap- and individual bindings; "
Expand Down Expand Up @@ -2209,7 +2205,7 @@ static ShaderType StageFlagsToShaderType(long stageFlags)
}
}

void DbgRenderSystem::ValidatePipelineStateUniforms(const DbgPipelineLayout& pipelineLayout, const ArrayView<DbgShader*>& shaders)
void DbgRenderSystem::ValidatePipelineStateUniforms(const DbgPipelineLayout& pipelineLayout, const ArrayView<DbgShader*>& shaders, const char* psoDebugName)
{
/*
Warn if any uniform is in a cbuffer that has different binding slots across multiple shader stages,
Expand Down Expand Up @@ -2240,7 +2236,17 @@ void DbgRenderSystem::ValidatePipelineStateUniforms(const DbgPipelineLayout& pip
{
/* Reflect shader code */
ShaderReflection reflection;
shader->instance.Reflect(reflection);
if (!shader->instance.Reflect(reflection))
{
const std::string psoLabel = (psoDebugName != nullptr && *psoDebugName != '\0' ? " '" + std::string(psoDebugName) + '\'' : "");
LLGL_DBG_ERROR(
ErrorType::InvalidState,
"failed to reflect shader code in PSO%s with uniform descriptors%s",
psoLabel.c_str(),
(IsVulkan() ? "; perhaps LLGL was built without LLGL_VK_ENABLE_SPIRV_REFLECT" : "")
);
continue;
}

/* Check mismatch between shader resources */
if (!reflections.empty())
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/DebugLayer/DbgRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DbgRenderSystem final : public RenderSystem
void ValidateFragmentShaderOutput(DbgShader& fragmentShaderDbg, const RenderPass* renderPass, bool hasDualSourceBlend);
void ValidateFragmentShaderOutputWithRenderPass(DbgShader& fragmentShaderDbg, const FragmentShaderAttributes& fragmentAttribs, const DbgRenderPass& renderPass, bool hasDualSourceBlend);
void ValidateFragmentShaderOutputWithoutRenderPass(DbgShader& fragmentShaderDbg, const FragmentShaderAttributes& fragmentAttribs);
void ValidatePipelineStateUniforms(const DbgPipelineLayout& pipelineLayout, const ArrayView<DbgShader*>& shaders);
void ValidatePipelineStateUniforms(const DbgPipelineLayout& pipelineLayout, const ArrayView<DbgShader*>& shaders, const char* psoDebugName);

void Assert3DTextures();
void AssertCubeTextures();
Expand Down

0 comments on commit aaedbdf

Please sign in to comment.