@@ -95,7 +95,7 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
9595 // For uniform and storage buffers only
9696/* 16 */ Uint64 BufferBaseOffset = 0 ;
9797/* 24 */ Uint64 BufferRangeSize = 0 ;
98- // For inline constant buffers only - points to staging data in cache tail
98+ // For inline constant buffers only - pointer to the staging data
9999/* 32 */ void * const pInlineConstantData = nullptr ;
100100 // clang-format on
101101
@@ -108,7 +108,7 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
108108 {
109109 VERIFY (pInlineConstantData != nullptr , " Inline constant data pointer is not initialized" );
110110 VERIFY (pData != nullptr , " Source data is null" );
111- memcpy (static_cast <Uint32 *>(pInlineConstantData) + FirstConstant, pData, NumConstants * sizeof (Uint32));
111+ memcpy (static_cast <Uint8 *>(pInlineConstantData) + FirstConstant * sizeof (Uint32) , pData, NumConstants * sizeof (Uint32));
112112 }
113113
114114 template <typename ResType>
@@ -196,7 +196,7 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
196196
197197 bool HasInlineConstants () const
198198 {
199- return m_pInlineConstantData != nullptr ;
199+ return m_HasInlineConstants != 0 ;
200200 }
201201
202202 ResourceCacheContentType GetContentType () const { return static_cast <ResourceCacheContentType>(m_ContentType); }
@@ -208,6 +208,16 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
208208 std::vector<uint32_t >& Offsets,
209209 Uint32 GroupIdx) const ;
210210
211+ // Writes inline constant data to the staging buffer
212+ void SetInlineConstants (Uint32 BindGroupIdx, Uint32 CacheOffset, const void * pConstants, Uint32 FirstConstant, Uint32 NumConstants);
213+
214+ // Copies inline constant data from source cache to this cache
215+ void CopyInlineConstants (const ShaderResourceCacheWebGPU& SrcCache,
216+ Uint32 BindGroupIdx,
217+ Uint32 SrcCacheOffset,
218+ Uint32 DstCacheOffset,
219+ Uint32 NumConstants);
220+
211221#ifdef DILIGENT_DEBUG
212222 // For debug purposes only
213223 void DbgVerifyResourceInitialization () const ;
@@ -221,9 +231,25 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
221231 return reinterpret_cast <const Resource*>(reinterpret_cast <const BindGroup*>(m_pMemory.get ()) + m_NumBindGroups);
222232 }
223233#endif
234+ BindGroup* GetFirstBindGroupPtr ()
235+ {
236+ return reinterpret_cast <BindGroup*>(m_pMemory.get ());
237+ }
224238 Resource* GetFirstResourcePtr ()
225239 {
226- return reinterpret_cast <Resource*>(reinterpret_cast <BindGroup*>(m_pMemory.get ()) + m_NumBindGroups);
240+ static_assert (alignof (BindGroup) >= alignof (Resource),
241+ " BindGroup alignment is less than Resource alignment, Resource pointer may be misaligned" );
242+ return reinterpret_cast <Resource*>(GetFirstBindGroupPtr () + m_NumBindGroups);
243+ }
244+ WGPUBindGroupEntry* GetFirstWGPUEntryPtr ()
245+ {
246+ static_assert (alignof (Resource) >= alignof (WGPUBindGroupEntry),
247+ " Resource alignment is less than WGPUBindGroupEntry alignment, WGPUBindGroupEntry pointer may be misaligned" );
248+ return reinterpret_cast <WGPUBindGroupEntry*>(GetFirstResourcePtr () + m_TotalResources);
249+ }
250+ Uint8* GetInlineConstantDataPtr (Uint32 Offset = 0 )
251+ {
252+ return reinterpret_cast <Uint8*>(GetFirstWGPUEntryPtr () + m_TotalResources) + Offset * sizeof (Uint32);
227253 }
228254
229255 BindGroup& GetBindGroup (Uint32 Index)
@@ -240,26 +266,14 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
240266 // The total actual number of dynamic buffers (that were created with USAGE_DYNAMIC) bound in the resource cache
241267 // regardless of the variable type.
242268 Uint16 m_NumDynamicBuffers = 0 ;
243- Uint32 m_TotalResources : 31 ;
269+ Uint32 m_TotalResources : 30 ;
244270
245271 // Indicates what types of resources are stored in the cache
246272 const Uint32 m_ContentType : 1 ;
247273
248- // Pointer to the start of inline constant staging data in the memory tail
249- Uint32* m_pInlineConstantData = nullptr ;
250-
251- public:
252- // Writes inline constant data to the staging buffer
253- void SetInlineConstants (Uint32 BindGroupIdx, Uint32 CacheOffset, const void * pConstants, Uint32 FirstConstant, Uint32 NumConstants);
254-
255- // Copies inline constant data from source cache to this cache
256- void CopyInlineConstants (const ShaderResourceCacheWebGPU& SrcCache,
257- Uint32 BindGroupIdx,
258- Uint32 SrcCacheOffset,
259- Uint32 DstCacheOffset,
260- Uint32 NumConstants);
274+ // Indicates whether the cache has inline constants
275+ Uint32 m_HasInlineConstants : 1 ;
261276
262- private:
263277#ifdef DILIGENT_DEBUG
264278 // Debug array that stores flags indicating if resources in the cache have been initialized
265279 std::vector<std::vector<bool >> m_DbgInitializedResources;
0 commit comments