Skip to content

Commit 3fa0977

Browse files
committed
Allow empty ShaderResource.
1 parent e149356 commit 3fa0977

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ class ShaderVkImpl final : public ShaderBase<EngineVkImplTraits>
9292

9393
const std::shared_ptr<const SPIRVShaderResources>& GetShaderResources() const
9494
{
95-
DEV_CHECK_ERR(!IsCompiling(), "Shader resources are not available until the shader is compiled. Use GetStatus() to check the shader status.");
95+
//DEV_CHECK_ERR(!IsCompiling(), "Shader resources are not available until the shader is compiled. Use GetStatus() to check the shader status.");
96+
97+
static const std::shared_ptr<const SPIRVShaderResources> NullShaderResource;
98+
// NOTE: while shader is compiled asynchronously, is not available
99+
if (IsCompiling())
100+
return NullShaderResource;
101+
96102
return m_pShaderResources;
97103
}
98104

Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -636,22 +636,14 @@ PipelineResourceSignatureDescWrapper PipelineStateVkImpl::GetDefaultResourceSign
636636

637637
// For inline constants, ArraySize specifies the number of 32-bit constants,
638638
// not the array dimension. We need to calculate it from the buffer size.
639+
// the SPIRV ArraySize is 1 (buffer is not an array), but we need
640+
// the number of 32-bit constants which is BufferStaticSize / sizeof(Uint32)
639641
Uint32 ArraySize = Attribs.ArraySize;
640-
if ((Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) != 0)
642+
if (Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
641643
{
642-
// For inline constants specified via ShaderResourceVariableDesc,
643-
// the SPIRV ArraySize is 1 (buffer is not an array), but we need
644-
// the number of 32-bit constants which is BufferStaticSize / sizeof(Uint32)
645-
if (Attribs.BufferStaticSize > 0)
646-
{
647-
ArraySize = Attribs.BufferStaticSize / sizeof(Uint32);
648-
}
649-
else
650-
{
651-
LOG_ERROR_AND_THROW("Resource '", Attribs.Name, "' in shader '", pShader->GetDesc().Name,
652-
"' is marked as inline constants, but has zero buffer size. "
653-
"Make sure the buffer type is defined in the shader.");
654-
}
644+
VERIFY(Flags == PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS, "INLINE_CONSTANTS flag cannot be combined with other flags.");
645+
646+
ArraySize = Attribs.GetInlineConstantCountOrThrow(pShader->GetDesc().Name);
655647
}
656648

657649
SignDesc.AddResource(VarDesc.ShaderStages, Attribs.Name, ArraySize, ResType, VarDesc.Type, Flags);

Graphics/ShaderTools/include/SPIRVShaderResources.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,39 @@ struct SPIRVShaderResourceAttribs
131131
{
132132
return IsMS != 0;
133133
}
134+
135+
Uint32 GetConstantBufferSize() const
136+
{
137+
VERIFY((Type == PushConstant || Type == UniformBuffer), "Invalid resource type: PushConstant or UniformBuffer expected");
138+
return BufferStaticSize;
139+
}
140+
141+
Uint32 GetInlineConstantCountOrThrow(const char* ShaderName) const
142+
{
143+
VERIFY_EXPR(Type == PushConstant || Type == UniformBuffer);
144+
145+
if (ArraySize != 1)
146+
{
147+
LOG_ERROR_AND_THROW("Inline constants resource '", Name, "' in shader '", ShaderName, "' can not be an array.");
148+
}
149+
const Uint32 NumConstants = GetConstantBufferSize() / sizeof(Uint32);
150+
151+
constexpr Uint32 kMaxInlineConstants = 64;
152+
if (NumConstants > kMaxInlineConstants)
153+
{
154+
LOG_ERROR_AND_THROW("Inline constants resource '", Name, "' in shader '", ShaderName, "' has ",
155+
NumConstants, " constants. The maximum supported number of inline constants is ",
156+
kMaxInlineConstants, '.');
157+
}
158+
159+
if (NumConstants == 0)
160+
{
161+
LOG_ERROR_AND_THROW("Resource '", Name, "' in shader '", ShaderName,
162+
"' is marked as inline constants, but has zero buffer size. ");
163+
}
164+
165+
return NumConstants;
166+
}
134167
};
135168
static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)");
136169

0 commit comments

Comments
 (0)