@@ -45,6 +45,7 @@ ShaderResourceCacheD3D12::MemoryRequirements ShaderResourceCacheD3D12::GetMemory
4545{
4646 const Uint32 NumRootTables = RootParams.GetNumRootTables ();
4747 const Uint32 NumRootViews = RootParams.GetNumRootViews ();
48+ const Uint32 NumRootConsts = RootParams.GetNumRootConstants ();
4849
4950 MemoryRequirements MemReqs;
5051
@@ -61,17 +62,26 @@ ShaderResourceCacheD3D12::MemoryRequirements ShaderResourceCacheD3D12::GetMemory
6162 }
6263 }
6364 }
64- // Root views' resources are stored in one-descriptor tables
65+ // Root views and root constants resources are stored in one-descriptor tables
6566 MemReqs.TotalResources += NumRootViews;
67+ MemReqs.TotalResources += NumRootConsts;
6668
6769 static_assert (sizeof (RootTable) % sizeof (void *) == 0 , " sizeof(RootTable) is not aligned by the sizeof(void*)" );
6870 static_assert (sizeof (Resource) % sizeof (void *) == 0 , " sizeof(Resource) is not aligned by the sizeof(void*)" );
6971
70- MemReqs.NumTables = NumRootTables + NumRootViews;
72+ MemReqs.NumTables = NumRootTables + NumRootViews + NumRootConsts;
73+
74+ MemReqs.TotalInlineConstantValues = 0 ;
75+ for (Uint32 i = 0 ; i < NumRootConsts; ++i)
76+ {
77+ const RootParameter& RootConsts = RootParams.GetRootConstants (i);
78+ MemReqs.TotalInlineConstantValues += RootConsts.d3d12RootParam .Constants .Num32BitValues ;
79+ }
7180
7281 MemReqs.TotalSize = (MemReqs.NumTables * sizeof (RootTable) +
7382 MemReqs.TotalResources * sizeof (Resource) +
74- MemReqs.NumDescriptorAllocations * sizeof (DescriptorHeapAllocation));
83+ MemReqs.NumDescriptorAllocations * sizeof (DescriptorHeapAllocation) +
84+ MemReqs.TotalInlineConstantValues * sizeof (Uint32));
7585
7686 return MemReqs;
7787}
@@ -82,21 +92,23 @@ ShaderResourceCacheD3D12::MemoryRequirements ShaderResourceCacheD3D12::GetMemory
8292// m_pMemory | m_pResources, m_NumResources |
8393// | | |
8494// V | V
85- // | RootTable[0] | .... | RootTable[Nrt-1] | Res[0] | ... | Res[n-1] | .... | Res[0] | ... | Res[m-1] | DescriptorHeapAllocation[0] | ...
95+ // | RootTable[0] | .... | RootTable[Nrt-1] | Res[0] | ... | Res[n-1] | .... | Res[0] | ... | Res[m-1] | Descriptor Heap Allocations | Inline cnstant values |
8696// | A
8797// | |
8898// |________________________________________________|
8999// m_pResources, m_NumResources
90100//
91101
92- size_t ShaderResourceCacheD3D12::AllocateMemory (IMemoryAllocator& MemAllocator)
102+ size_t ShaderResourceCacheD3D12::AllocateMemory (IMemoryAllocator& MemAllocator,
103+ Uint32 TotalInlineConstantValues)
93104{
94105 VERIFY (!m_pMemory, " Memory has already been allocated" );
95106
96107 const size_t MemorySize =
97108 (m_NumTables * sizeof (RootTable) +
98109 m_TotalResourceCount * sizeof (Resource) +
99- m_NumDescriptorAllocations * sizeof (DescriptorHeapAllocation));
110+ m_NumDescriptorAllocations * sizeof (DescriptorHeapAllocation) +
111+ TotalInlineConstantValues * sizeof (Uint32));
100112
101113 if (MemorySize > 0 )
102114 {
@@ -105,12 +117,13 @@ size_t ShaderResourceCacheD3D12::AllocateMemory(IMemoryAllocator& MemAllocator)
105117 STDDeleter<void , IMemoryAllocator>(MemAllocator) //
106118 };
107119
108- RootTable* const pTables = reinterpret_cast <RootTable*>(m_pMemory.get ());
109- Resource* const pResources = reinterpret_cast <Resource*>(pTables + m_NumTables);
110- m_DescriptorAllocations = m_NumDescriptorAllocations > 0 ? reinterpret_cast <DescriptorHeapAllocation*>(pResources + m_TotalResourceCount) : nullptr ;
120+ Resource* const pResources = GetResourceStorage ();
121+ m_DescriptorAllocations = m_NumDescriptorAllocations > 0 ? GetDescriptorAllocationStorage () : nullptr ;
111122
112123 for (Uint32 res = 0 ; res < m_TotalResourceCount; ++res)
124+ {
113125 new (pResources + res) Resource{};
126+ }
114127
115128 for (Uint32 i = 0 ; i < m_NumDescriptorAllocations; ++i)
116129 new (m_DescriptorAllocations + i) DescriptorHeapAllocation{};
@@ -119,9 +132,10 @@ size_t ShaderResourceCacheD3D12::AllocateMemory(IMemoryAllocator& MemAllocator)
119132 return MemorySize;
120133}
121134
122- void ShaderResourceCacheD3D12::Initialize (IMemoryAllocator& MemAllocator,
123- Uint32 NumTables,
124- const Uint32 TableSizes[])
135+ void ShaderResourceCacheD3D12::Initialize (IMemoryAllocator& MemAllocator,
136+ Uint32 NumTables,
137+ const Uint32 TableSizes[],
138+ const InlineConstantInfoVectorType& InlineConstants)
125139{
126140 VERIFY (GetContentType () == ResourceCacheContentType::Signature,
127141 " This method should be called to initialize the cache to store resources of a pipeline resource signature" );
@@ -137,7 +151,13 @@ void ShaderResourceCacheD3D12::Initialize(IMemoryAllocator& MemAllocator,
137151
138152 m_DescriptorAllocations = 0 ;
139153
140- AllocateMemory (MemAllocator);
154+ Uint32 TotalInlineConstantValues = 0 ;
155+ for (const InlineConstantParamInfo& InlineConstInfo : InlineConstants)
156+ {
157+ TotalInlineConstantValues += InlineConstInfo.NumValues ;
158+ }
159+
160+ AllocateMemory (MemAllocator, TotalInlineConstantValues);
141161
142162 Uint32 ResIdx = 0 ;
143163 for (Uint32 t = 0 ; t < m_NumTables; ++t)
@@ -146,6 +166,15 @@ void ShaderResourceCacheD3D12::Initialize(IMemoryAllocator& MemAllocator,
146166 ResIdx += TableSizes[t];
147167 }
148168 VERIFY_EXPR (ResIdx == m_TotalResourceCount);
169+
170+ Uint32* pCurrInlineConstValueStorage = GetInlineConstantStorage ();
171+ for (const InlineConstantParamInfo& InlineConstInfo : InlineConstants)
172+ {
173+ Resource& Res = GetRootTable (InlineConstInfo.RootIndex ).GetResource (InlineConstInfo.OffsetFromTableStart );
174+ Res.CPUDescriptorHandle .ptr = reinterpret_cast <SIZE_T>(pCurrInlineConstValueStorage);
175+ pCurrInlineConstValueStorage += InlineConstInfo.NumValues ;
176+ }
177+ VERIFY_EXPR (pCurrInlineConstValueStorage == GetInlineConstantStorage () + TotalInlineConstantValues);
149178}
150179
151180
@@ -168,7 +197,7 @@ void ShaderResourceCacheD3D12::Initialize(IMemoryAllocator& MemAllocator,
168197 m_NumDescriptorAllocations = static_cast <decltype (m_NumDescriptorAllocations)>(MemReq.NumDescriptorAllocations );
169198 VERIFY_EXPR (m_NumDescriptorAllocations == MemReq.NumDescriptorAllocations );
170199
171- const size_t MemSize = AllocateMemory (MemAllocator);
200+ const size_t MemSize = AllocateMemory (MemAllocator, MemReq. TotalInlineConstantValues );
172201 VERIFY_EXPR (MemSize == MemReq.TotalSize );
173202
174203#ifdef DILIGENT_DEBUG
@@ -177,7 +206,7 @@ void ShaderResourceCacheD3D12::Initialize(IMemoryAllocator& MemAllocator,
177206
178207 Uint32 ResIdx = 0 ;
179208
180- // Initialize root tables
209+ // Initialize root tables.
181210 for (Uint32 i = 0 ; i < RootParams.GetNumRootTables (); ++i)
182211 {
183212 const RootParameter& RootTbl = RootParams.GetRootTable (i);
@@ -220,6 +249,37 @@ void ShaderResourceCacheD3D12::Initialize(IMemoryAllocator& MemAllocator,
220249 RootTableInitFlags[RootView.RootIndex ] = true ;
221250#endif
222251 }
252+
253+ if (Uint32 NumRootConstants = RootParams.GetNumRootConstants ())
254+ {
255+ Uint32* pCurrInlineConstValueStorage = GetInlineConstantStorage ();
256+
257+ // Initialize one-descriptor tables for root constants
258+ for (Uint32 i = 0 ; i < NumRootConstants; ++i)
259+ {
260+ const RootParameter& RootConsts = RootParams.GetRootConstants (i);
261+ VERIFY (!RootTableInitFlags[RootConsts.RootIndex ], " Root table at index " , RootConsts.RootIndex , " has already been initialized." );
262+ VERIFY_EXPR (RootConsts.TableOffsetInGroupAllocation == RootParameter::InvalidTableOffsetInGroupAllocation);
263+ VERIFY_EXPR (RootConsts.d3d12RootParam .ParameterType == D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS);
264+
265+ GetResource (ResIdx).CPUDescriptorHandle .ptr = reinterpret_cast <SIZE_T>(pCurrInlineConstValueStorage);
266+ pCurrInlineConstValueStorage += RootConsts.d3d12RootParam .Constants .Num32BitValues ;
267+
268+ new (&GetRootTable (RootConsts.RootIndex )) RootTable{
269+ 1 ,
270+ &GetResource (ResIdx),
271+ false // IsRootView
272+ };
273+ ++ResIdx;
274+
275+ #ifdef DILIGENT_DEBUG
276+ RootTableInitFlags[RootConsts.RootIndex ] = true ;
277+ #endif
278+ }
279+
280+ VERIFY_EXPR (pCurrInlineConstValueStorage == GetInlineConstantStorage () + MemReq.TotalInlineConstantValues );
281+ }
282+
223283 VERIFY_EXPR (ResIdx == m_TotalResourceCount);
224284
225285#ifdef DILIGENT_DEBUG
0 commit comments