Skip to content

Commit 0ffcb53

Browse files
D3D11: fix inline constant buffers remapping; enable inline constant tests
1 parent 1c3e30d commit 0ffcb53

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

Graphics/GraphicsEngine/interface/PipelineResourceSignature.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ struct PipelineResourceDesc
353353
{
354354
return !(*this == Rhs);
355355
}
356+
357+
Uint32 GetArraySize() const noexcept
358+
{
359+
return (Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) != 0 ?
360+
1 : // For inline constants, ArraySize is the number of 4-byte constants.
361+
ArraySize;
362+
}
356363
#endif
357364
};
358365
typedef struct PipelineResourceDesc PipelineResourceDesc;

Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ inline ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindCBs(
687687
// Offsets in Direct3D11 are measure in float4 constants.
688688
const UINT FirstCBConstant = StaticCast<UINT>((ResArrays.first[res].BaseOffset + ResArrays.first[res].DynamicOffset) / 16u);
689689
// The number of constants must be a multiple of 16 constants. It is OK if it is past the end of the buffer.
690-
const UINT NumCBConstants = StaticCast<UINT>(AlignUp(ResArrays.first[res].RangeSize / 16u, 16u));
690+
const UINT NumCBConstants = StaticCast<UINT>(AlignUp((ResArrays.first[res].RangeSize + 15u) / 16u, 16u));
691691
// clang-format off
692692
if (CommittedD3D11Resources[Slot] != pd3d11CB ||
693693
FirstConstants[Slot] != FirstCBConstant ||
@@ -734,7 +734,7 @@ inline void ShaderResourceCacheD3D11::BindDynamicCBs(Uint32
734734
// Offsets in Direct3D11 are measure in float4 constants.
735735
const UINT FirstCBConstant = StaticCast<UINT>((CB.BaseOffset + CB.DynamicOffset) / 16u);
736736
// The number of constants must be a multiple of 16 constants. It is OK if it is past the end of the buffer.
737-
const UINT NumCBConstants = StaticCast<UINT>(AlignUp(CB.RangeSize / 16u, 16u));
737+
const UINT NumCBConstants = StaticCast<UINT>(AlignUp((CB.RangeSize + 15u) / 16u, 16u));
738738
// clang-format off
739739
if (CommittedD3D11Resources[Slot] != pd3d11CB ||
740740
FirstConstants[Slot] != FirstCBConstant ||

Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout(const bool IsSerialized)
212212

213213
VERIFY((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) == 0 || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER,
214214
"Only constant buffers can have inline constants flag");
215-
const Uint32 ArraySize = (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) != 0 ?
216-
1 : // For inline constants, count only one resource as the ArraySize is the number of 4-byte constants.
217-
ResDesc.ArraySize;
215+
// For inline constants, ArraySize holds the number of 4-byte constants
216+
const Uint32 ArraySize = ResDesc.GetArraySize();
218217
AllocBindPoints(m_ResourceCounters, BindPoints, ResDesc.ShaderStages, ArraySize, Range);
219218
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
220219
{
@@ -229,7 +228,8 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout(const bool IsSerialized)
229228
}
230229
}
231230

232-
if (Range == D3D11_RESOURCE_RANGE_CBV && (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS) == 0)
231+
if (Range == D3D11_RESOURCE_RANGE_CBV &&
232+
(ResDesc.Flags & (PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS | PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)) == 0)
233233
{
234234
// Set corresponding bits in m_DynamicCBSlotsMask
235235
for (SHADER_TYPE ShaderStages = ResDesc.ShaderStages; ShaderStages != SHADER_TYPE_UNKNOWN;)
@@ -436,9 +436,9 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource
436436
ResourceBinding::BindInfo BindInfo //
437437
{
438438
Uint32{BaseBindings[Range][ShaderInd]} + Uint32{ResAttr.BindPoints[ShaderInd]},
439-
0u, // register space is not supported
440-
ResDesc.ArraySize,
441-
ResDesc.ResourceType //
439+
0u, // register space is not supported
440+
ResDesc.GetArraySize(), // For inline constants, ArraySize holds the number of 4-byte constants
441+
ResDesc.ResourceType,
442442
};
443443
bool IsUnique = ResourceMap.emplace(HashMapStringKey{ResDesc.Name}, BindInfo).second;
444444
VERIFY(IsUnique, "Shader resource '", ResDesc.Name,

Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ void PipelineResourceSignatureD3D12Impl::AllocateRootParameters(const bool IsSer
284284
// Normal resources go into space 0.
285285
Space = 0;
286286
Register = NumResources[d3d12DescriptorRangeType];
287-
NumResources[d3d12DescriptorRangeType] += (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) != 0 ?
288-
1 : // For inline constants, count only one resource as the ArraySize is the number of 4-byte constants.
289-
ResDesc.ArraySize;
287+
// For inline constants, ArraySize holds the number of 4-byte constants.
288+
NumResources[d3d12DescriptorRangeType] += ResDesc.GetArraySize();
290289
}
291290

292291
const PIPELINE_RESOURCE_FLAGS dbgValidResourceFlags = GetValidPipelineResourceFlags(ResDesc.ResourceType);
@@ -732,15 +731,12 @@ void PipelineResourceSignatureD3D12Impl::UpdateShaderResourceBindingMap(Resource
732731
{
733732
VERIFY((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) == 0 || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER,
734733
"Only constant buffers can be marked as INLINE_CONSTANTS. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
735-
const Uint32 ArraySize = (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) ?
736-
1 : // For inline constants, ArraySize is the number of 4-byte constants
737-
ResDesc.ArraySize;
738734

739735
ResourceBinding::BindInfo BindInfo //
740736
{
741737
Attribs.Register,
742738
Attribs.Space + BaseRegisterSpace,
743-
ArraySize,
739+
ResDesc.GetArraySize(), // For inline constants, ArraySize holds the number of 4-byte constants
744740
ResDesc.ResourceType,
745741
};
746742
bool IsUnique = ResourceMap.emplace(HashMapStringKey{ResDesc.Name}, BindInfo).second;

Tests/DiligentCoreAPITest/src/InlineConstantsTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class InlineConstants : public ::testing::Test
129129
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
130130
IRenderDevice* pDevice = pEnv->GetDevice();
131131

132-
if (pDevice->GetDeviceInfo().Type != RENDER_DEVICE_TYPE_D3D12)
132+
if (!pDevice->GetDeviceInfo().IsD3DDevice())
133133
{
134134
GTEST_SKIP();
135135
}

0 commit comments

Comments
 (0)