Skip to content

Commit 158868a

Browse files
Do not serialize PRS attributes that can be computed from description
1 parent 0ac67d2 commit 158868a

9 files changed

Lines changed: 66 additions & 70 deletions

File tree

Graphics/GraphicsEngine/include/PSOSerializer.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,10 +101,7 @@ struct PRSSerializer
101101
ConstQual<PipelineResourceSignatureInternalDataType>& InternalData,
102102
DynamicLinearAllocator* Allocator)
103103
{
104-
if (!Ser(InternalData.ShaderStages,
105-
InternalData.StaticResShaderStages,
106-
InternalData.PipelineType,
107-
InternalData.StaticResStageIndex))
104+
if (!Ser(InternalData.ShaderStages))
108105
return false;
109106

110107
if (!Ser.SerializeArrayRaw(Allocator, InternalData.pResourceAttribs, InternalData.NumResources))

Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,10 @@ void CopyPipelineResourceSignatureDesc(FixedLinearAllocator&
104104
template <typename PipelineResourceAttribsType, typename ImmutableSamplerAttribsType>
105105
struct PipelineResourceSignatureInternalData
106106
{
107-
SHADER_TYPE ShaderStages = SHADER_TYPE_UNKNOWN;
108-
SHADER_TYPE StaticResShaderStages = SHADER_TYPE_UNKNOWN;
109-
PIPELINE_TYPE PipelineType = PIPELINE_TYPE_INVALID;
110-
std::array<Int8, MAX_SHADERS_IN_PIPELINE> StaticResStageIndex = {};
107+
SHADER_TYPE ShaderStages = SHADER_TYPE_UNKNOWN;
111108

112109
// The struct is used in serialization and must be tightly packed
113-
Uint8 _Padding = 0;
110+
Uint32 _Padding = 0;
114111

115112
Uint32 NumResources = 0;
116113
Uint32 NumImmutableSamplers = 0;
@@ -121,12 +118,9 @@ struct PipelineResourceSignatureInternalData
121118
constexpr bool operator==(const PipelineResourceSignatureInternalData& Rhs) const
122119
{
123120
// clang-format off
124-
if (ShaderStages != Rhs.ShaderStages ||
125-
StaticResShaderStages != Rhs.StaticResShaderStages ||
126-
PipelineType != Rhs.PipelineType ||
127-
StaticResStageIndex != Rhs.StaticResStageIndex ||
128-
NumResources != Rhs.NumResources ||
129-
NumImmutableSamplers != Rhs.NumImmutableSamplers)
121+
if (ShaderStages != Rhs.ShaderStages ||
122+
NumResources != Rhs.NumResources ||
123+
NumImmutableSamplers != Rhs.NumImmutableSamplers)
130124
// clang-format on
131125
{
132126
return false;
@@ -383,46 +377,16 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
383377

384378
ValidatePipelineResourceSignatureDesc(Desc, pDevice, EngineImplTraits::DeviceType);
385379

386-
// Determine shader stages that have any resources as well as
387-
// shader stages that have static resources.
388-
for (Uint32 i = 0; i < Desc.NumResources; ++i)
389-
{
390-
const PipelineResourceDesc& ResDesc = Desc.Resources[i];
391-
392-
m_ShaderStages |= ResDesc.ShaderStages;
393-
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
394-
m_StaticResShaderStages |= ResDesc.ShaderStages;
395-
}
396-
397-
if (m_ShaderStages != SHADER_TYPE_UNKNOWN)
398-
{
399-
m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages);
400-
DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages");
401-
}
402-
403-
{
404-
Uint32 StaticVarStageIdx = 0;
405-
for (SHADER_TYPE StaticResStages = m_StaticResShaderStages; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageIdx)
406-
{
407-
const SHADER_TYPE StageBit = ExtractLSB(StaticResStages);
408-
const Int32 ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType);
409-
m_StaticResStageIndex[ShaderTypeInd] = static_cast<Int8>(StaticVarStageIdx);
410-
}
411-
VERIFY_EXPR(StaticVarStageIdx == GetNumStaticResStages());
412-
}
380+
InitAttribs(Desc);
413381
}
414382

415383
PipelineResourceSignatureBase(IReferenceCounters* pRefCounters,
416384
RenderDeviceImplType* pDevice,
417385
const PipelineResourceSignatureDesc& Desc,
418386
const PipelineResourceSignatureInternalDataType& InternalData) :
419387
TDeviceObjectBase{pRefCounters, pDevice, Desc, false /*bIsDeviceInternal*/},
420-
// clang-format off
421-
m_ShaderStages {InternalData.ShaderStages},
422-
m_StaticResShaderStages{InternalData.StaticResShaderStages},
423-
m_PipelineType {InternalData.PipelineType},
424-
m_StaticResStageIndex {InternalData.StaticResStageIndex},
425-
m_SRBMemAllocator {GetRawAllocator()}
388+
m_ShaderStages{InternalData.ShaderStages},
389+
m_SRBMemAllocator{GetRawAllocator()}
426390
// clang-format on
427391
{
428392
// Don't read from m_Desc until it was allocated and copied in CopyPipelineResourceSignatureDesc()
@@ -433,6 +397,8 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
433397
#ifdef DILIGENT_DEVELOPMENT
434398
ValidatePipelineResourceSignatureDesc(Desc, pDevice, EngineImplTraits::DeviceType);
435399
#endif
400+
401+
InitAttribs(Desc);
436402
}
437403

438404
~PipelineResourceSignatureBase()
@@ -778,10 +744,7 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
778744
{
779745
PipelineResourceSignatureInternalDataType InternalData;
780746

781-
InternalData.ShaderStages = m_ShaderStages;
782-
InternalData.StaticResShaderStages = m_StaticResShaderStages;
783-
InternalData.PipelineType = m_PipelineType;
784-
InternalData.StaticResStageIndex = m_StaticResStageIndex;
747+
InternalData.ShaderStages = m_ShaderStages;
785748

786749
InternalData.pResourceAttribs = m_pResourceAttribs;
787750
InternalData.NumResources = this->m_Desc.NumResources;
@@ -791,6 +754,38 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<typename EngineImp
791754
return InternalData;
792755
}
793756

757+
private:
758+
void InitAttribs(const PipelineResourceSignatureDesc& Desc)
759+
{
760+
// Determine shader stages that have any resources as well as
761+
// shader stages that have static resources.
762+
for (Uint32 i = 0; i < Desc.NumResources; ++i)
763+
{
764+
const PipelineResourceDesc& ResDesc = Desc.Resources[i];
765+
766+
m_ShaderStages |= ResDesc.ShaderStages;
767+
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
768+
m_StaticResShaderStages |= ResDesc.ShaderStages;
769+
}
770+
771+
if (m_ShaderStages != SHADER_TYPE_UNKNOWN)
772+
{
773+
m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages);
774+
DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages");
775+
}
776+
777+
{
778+
Uint32 StaticVarStageIdx = 0;
779+
for (SHADER_TYPE StaticResStages = m_StaticResShaderStages; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageIdx)
780+
{
781+
const SHADER_TYPE StageBit = ExtractLSB(StaticResStages);
782+
const Int32 ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType);
783+
m_StaticResStageIndex[ShaderTypeInd] = static_cast<Int8>(StaticVarStageIdx);
784+
}
785+
VERIFY_EXPR(StaticVarStageIdx == GetNumStaticResStages());
786+
}
787+
}
788+
794789
protected:
795790
using AllocResourceAttribsCallbackType = std::function<PipelineResourceAttribsType*(FixedLinearAllocator&)>;
796791
using AllocImmutableSamplerAttribsCallbackType = std::function<void*(FixedLinearAllocator&)>;

Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
namespace Diligent
3636
{
3737

38+
namespace
39+
{
40+
41+
using TestPipelineResourceSignatureInternalData = PipelineResourceSignatureInternalData<Uint32, Uint32>;
42+
ASSERT_SIZEOF64(TestPipelineResourceSignatureInternalData, 32, "Did you add new members to PipelineResourceSignatureInternalData? You need to implement serialization for them in PRSSerializer.");
43+
44+
} // namespace
45+
3846
#define LOG_PRS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of a pipeline resource signature '", (Desc.Name ? Desc.Name : ""), "' is invalid: ", ##__VA_ARGS__)
3947

4048
void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& Desc,

Graphics/GraphicsEngineD3D11/src/DeviceObjectArchiveD3D11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ bool PRSSerializerD3D11<Mode>::SerializeInternalData(
3838
ConstQual<PipelineResourceSignatureInternalDataD3D11>& InternalData,
3939
DynamicLinearAllocator* Allocator)
4040
{
41-
ASSERT_SIZEOF64(InternalData, 40, "Did you add a new member to PipelineResourceSignatureInternalDataD3D11? Please add serialization here.");
41+
ASSERT_SIZEOF64(InternalData, 32, "Did you add a new member to PipelineResourceSignatureInternalDataD3D11? Please add serialization here.");
4242
return PRSSerializer<Mode>::template SerializeInternalData<PipelineResourceSignatureInternalDataD3D11>(Ser, InternalData, Allocator);
4343
}
4444

Graphics/GraphicsEngineD3D12/src/DeviceObjectArchiveD3D12.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ bool PRSSerializerD3D12<Mode>::SerializeInternalData(
3838
ConstQual<PipelineResourceSignatureInternalDataD3D12>& InternalData,
3939
DynamicLinearAllocator* Allocator)
4040
{
41-
ASSERT_SIZEOF64(InternalData, 40, "Did you add a new member to PipelineResourceSignatureInternalDataD3D12? Please add serialization here.");
41+
ASSERT_SIZEOF64(InternalData, 32, "Did you add a new member to PipelineResourceSignatureInternalDataD3D12? Please add serialization here.");
4242
return PRSSerializer<Mode>::template SerializeInternalData<PipelineResourceSignatureInternalDataD3D12>(Ser, InternalData, Allocator);
4343
}
4444

Graphics/GraphicsEngineOpenGL/src/DeviceObjectArchiveGL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ bool PRSSerializerGL<Mode>::SerializeInternalData(
3838
ConstQual<PipelineResourceSignatureInternalDataGL>& InternalData,
3939
DynamicLinearAllocator* Allocator)
4040
{
41-
ASSERT_SIZEOF64(InternalData, 40, "Did you add a new member to PipelineResourceSignatureInternalDataGL? Please add serialization here.");
41+
ASSERT_SIZEOF64(InternalData, 32, "Did you add a new member to PipelineResourceSignatureInternalDataGL? Please add serialization here.");
4242
return PRSSerializer<Mode>::template SerializeInternalData<PipelineResourceSignatureInternalDataGL>(Ser, InternalData, Allocator);
4343
}
4444

Graphics/GraphicsEngineVulkan/src/DeviceObjectArchiveVk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ bool PRSSerializerVk<Mode>::SerializeInternalData(
3838
ConstQual<PipelineResourceSignatureInternalDataVk>& InternalData,
3939
DynamicLinearAllocator* Allocator)
4040
{
41-
ASSERT_SIZEOF64(InternalData, 48, "Did you add a new member to PipelineResourceSignatureInternalDataVk? Please add serialization here.");
41+
ASSERT_SIZEOF64(InternalData, 40, "Did you add a new member to PipelineResourceSignatureInternalDataVk? Please add serialization here.");
4242

4343
if (!PRSSerializer<Mode>::template SerializeInternalData<PipelineResourceSignatureInternalDataVk>(Ser, InternalData, Allocator))
4444
return false;

Graphics/GraphicsEngineWebGPU/src/DeviceObjectArchiveWebGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Diligent Graphics LLC
2+
* Copyright 2024-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ bool PRSSerializerWebGPU<Mode>::SerializeInternalData(
3838
ConstQual<PipelineResourceSignatureInternalDataWebGPU>& InternalData,
3939
DynamicLinearAllocator* Allocator)
4040
{
41-
ASSERT_SIZEOF64(InternalData, 40, "Did you add a new member to PipelineResourceSignatureInternalDataWebGPU? Please add serialization here.");
41+
ASSERT_SIZEOF64(InternalData, 32, "Did you add a new member to PipelineResourceSignatureInternalDataWebGPU? Please add serialization here.");
4242

4343
return PRSSerializer<Mode>::template SerializeInternalData<PipelineResourceSignatureInternalDataWebGPU>(Ser, InternalData, Allocator);
4444
}

Tests/DiligentCoreTest/src/GraphicsEngine/PSOSerializerTest.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -132,6 +132,7 @@ struct ValueIterator
132132
};
133133

134134
using TestPRSInternalData = PipelineResourceSignatureInternalData<TestResourceAttribs, TestImmutableSamplerAttribs>;
135+
ASSERT_SIZEOF64(TestPRSInternalData, 32, "Did you add new members to PipelineResourceSignatureInternalData? You need to implement serialization for them in PRSSerializer.");
135136

136137
TEST(PSOSerializerTest, SerializePRSDesc)
137138
{
@@ -214,12 +215,7 @@ TEST(PSOSerializerTest, SerializePRSDesc)
214215
SrcInternalData.NumImmutableSamplers = _countof(ImmSamAttribs);
215216
SrcInternalData.pImmutableSamplers = ImmSamAttribs;
216217

217-
SrcInternalData.ShaderStages = Val(SHADER_TYPE_GEOMETRY, (SHADER_TYPE_LAST << 1) - 1);
218-
SrcInternalData.StaticResShaderStages = Val(SHADER_TYPE_HULL, (SHADER_TYPE_LAST << 1) - 1);
219-
SrcInternalData.PipelineType = Val(PIPELINE_TYPE_GRAPHICS, PIPELINE_TYPE_LAST);
220-
221-
for (size_t i = 0; i < SrcInternalData.StaticResStageIndex.size(); ++i)
222-
SrcInternalData.StaticResStageIndex[i] = Val(static_cast<Int8>(i), Int8{127});
218+
SrcInternalData.ShaderStages = Val(SHADER_TYPE_GEOMETRY, (SHADER_TYPE_LAST << 1) - 1);
223219

224220
DynamicLinearAllocator Allocator{GetRawAllocator()};
225221
SerializedData Data;

0 commit comments

Comments
 (0)