Skip to content

Commit cfb5f3f

Browse files
PipelineStateD3D11: handle inline constants flag
1 parent 2f706ee commit cfb5f3f

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ PipelineResourceSignatureDescWrapper PipelineStateD3D11Impl::GetDefaultResourceS
9191

9292
const SHADER_RESOURCE_TYPE ResType = Attribs.GetShaderResourceType();
9393
const PIPELINE_RESOURCE_FLAGS ResFlags = Attribs.GetPipelineResourceFlags() | ShaderVariableFlagsToPipelineResourceFlags(VarDesc.Flags);
94-
SignDesc.AddResource(VarDesc.ShaderStages, Attribs.Name, Attribs.BindCount, ResType, VarDesc.Type, ResFlags);
94+
95+
Uint32 ArraySize = Attribs.BindCount;
96+
if (ResFlags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
97+
{
98+
VERIFY(ResFlags == PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS, "INLINE_CONSTANTS flag cannot be combined with other flags.");
99+
ArraySize = Attribs.GetInlineConstantCountOrThrow(pShader->GetDesc().Name);
100+
}
101+
SignDesc.AddResource(VarDesc.ShaderStages, Attribs.Name, ArraySize, ResType, VarDesc.Type, ResFlags);
95102
}
96103
else
97104
{

Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,20 +384,8 @@ PipelineResourceSignatureDescWrapper PipelineStateD3D12Impl::GetDefaultResourceS
384384
Uint32 ArraySize = Attribs.BindCount;
385385
if (ResFlags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
386386
{
387-
VERIFY_EXPR(ResType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER);
388387
VERIFY(ResFlags == PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS, "INLINE_CONSTANTS flag cannot be combined with other flags.");
389-
if (Attribs.BindCount != 1)
390-
{
391-
LOG_ERROR_AND_THROW("Inline constants resource '", Attribs.Name, "' in shader '", pShader->GetDesc().Name,
392-
"' can not be an array.");
393-
}
394-
const Uint32 NumConstants = Attribs.GetConstantBufferSize() / sizeof(Uint32);
395-
if (NumConstants > 64)
396-
{
397-
LOG_ERROR_AND_THROW("Inline constants resource '", Attribs.Name, "' in shader '", pShader->GetDesc().Name,
398-
"' has ", NumConstants, " constants. The maximum supported number of inline constants is 64.");
399-
}
400-
ArraySize = NumConstants;
388+
ArraySize = Attribs.GetInlineConstantCountOrThrow(pShader->GetDesc().Name);
401389
}
402390
SignDesc.AddResource(VarDesc.ShaderStages, Attribs.Name, ArraySize, ResType, VarDesc.Type, ResFlags);
403391
}

Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,26 @@ struct D3DShaderResourceAttribs
262262
return ExtraData;
263263
}
264264

265+
Uint32 GetInlineConstantCountOrThrow(const char* ShaderName) const
266+
{
267+
VERIFY_EXPR(GetShaderResourceType() == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER);
268+
if (BindCount != 1)
269+
{
270+
LOG_ERROR_AND_THROW("Inline constants resource '", Name, "' in shader '", ShaderName, "' can not be an array.");
271+
}
272+
const Uint32 NumConstants = GetConstantBufferSize() / sizeof(Uint32);
273+
274+
constexpr Uint32 kMaxInlineConstants = 64;
275+
if (NumConstants > kMaxInlineConstants)
276+
{
277+
LOG_ERROR_AND_THROW("Inline constants resource '", Name, "' in shader '", ShaderName, "' has ",
278+
NumConstants, " constants. The maximum supported number of inline constants is ",
279+
kMaxInlineConstants, '.');
280+
}
281+
282+
return NumConstants;
283+
}
284+
265285
SHADER_RESOURCE_TYPE GetShaderResourceType() const;
266286
PIPELINE_RESOURCE_FLAGS GetPipelineResourceFlags() const;
267287

0 commit comments

Comments
 (0)