Skip to content

Commit 1a25e22

Browse files
committed
Move pBuffer and pPushConstantData from PipelineResourceSignatureVkImpl to ShaderResourceCacheVk as per-SRB
1 parent e2bbc2a commit 1a25e22

File tree

4 files changed

+172
-114
lines changed

4 files changed

+172
-114
lines changed

Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@ ASSERT_SIZEOF(ImmutableSamplerAttribsVk, 8, "The struct is used in serialization
6363
/// Inline constants can be either:
6464
/// 1. True push constants (from SPIR-V push_constant storage class) - use vkCmdPushConstants
6565
/// 2. Emulated inline constants - use dynamic uniform buffers (similar to D3D11 backend)
66+
///
67+
/// Note: This structure only stores attributes/metadata. The actual storage (pBuffer for emulated
68+
/// inline constants, push constant data for true push constants) is managed per-SRB in
69+
/// ShaderResourceCacheVk to avoid conflicts between multiple PipelineStates sharing the same
70+
/// PipelineResourceSignature.
6671
struct InlineConstantBufferAttribsVk
6772
{
68-
Uint32 ResIndex = 0; // Resource index in the signature (used for matching)
69-
Uint32 DescrSet = 0; // Descriptor set index (0 for push constants as placeholder)
70-
Uint32 BindingIndex = 0; // Binding index within the descriptor set
71-
Uint32 NumConstants = 0; // Number of 32-bit constants
72-
bool IsPushConstant = false; // True if this is a Vulkan push constant (not emulated)
73-
RefCntAutoPtr<BufferVkImpl> pBuffer; // Internal dynamic uniform buffer (null for true push constants)
74-
void* pPushConstantData = nullptr; // CPU-side staging buffer for push constants (only used when IsPushConstant is true)
73+
Uint32 ResIndex = 0; // Resource index in the signature (used for matching)
74+
Uint32 DescrSet = 0; // Descriptor set index (0 for push constants as placeholder)
75+
Uint32 BindingIndex = 0; // Binding index within the descriptor set
76+
Uint32 NumConstants = 0; // Number of 32-bit constants
77+
bool IsPushConstant = false; // True if this is a Vulkan push constant (not emulated)
78+
// Note: pBuffer and pPushConstantData are now stored per-SRB in ShaderResourceCacheVk
7579
};
7680

7781
struct PipelineResourceSignatureInternalDataVk : PipelineResourceSignatureInternalData<PipelineResourceAttribsVk, ImmutableSamplerAttribsVk>
@@ -231,9 +235,10 @@ class PipelineResourceSignatureVkImpl final : public PipelineResourceSignatureBa
231235
// Inline constant buffer attributes
232236
std::unique_ptr<InlineConstantBufferAttribsVk[]> m_InlineConstantBuffers;
233237

234-
// Pointer to CPU-side staging buffer for static inline constants
235-
// This memory is allocated in CreateSetLayouts and must be freed in Destruct
236-
void* m_pStaticInlineConstantData = nullptr;
238+
// Note: Static inline constant data (including push constants) is stored in m_pStaticResCache.
239+
// For push constants, we use InitializePushConstantDataPtrs() and SetPushConstantDataPtr()
240+
// in the static resource cache, similar to how SRB caches store push constant data.
241+
// This ensures each SRB gets its own copy when CopyStaticResources() is called.
237242
};
238243

239244
template <> Uint32 PipelineResourceSignatureVkImpl::GetDescriptorSetIndex<PipelineResourceSignatureVkImpl::DESCRIPTOR_SET_ID_STATIC_MUTABLE>() const;

Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,32 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
313313

314314
Uint32 GetNumPushConstantBuffers() const { return m_NumPushConstantBuffers; }
315315

316+
// Initializes inline constant buffers array
317+
void InitializeInlineConstantBuffers(Uint32 NumBuffers)
318+
{
319+
m_NumInlineConstantBuffers = static_cast<Uint16>(NumBuffers);
320+
if (NumBuffers > 0)
321+
{
322+
m_pInlineConstantBuffers = std::make_unique<RefCntAutoPtr<BufferVkImpl>[]>(NumBuffers);
323+
}
324+
}
325+
326+
// Sets the inline constant buffer at the given index
327+
void SetInlineConstantBuffer(Uint32 Index, RefCntAutoPtr<BufferVkImpl>&& pBuffer)
328+
{
329+
VERIFY_EXPR(Index < m_NumInlineConstantBuffers);
330+
m_pInlineConstantBuffers[Index] = std::move(pBuffer);
331+
}
332+
333+
// Gets the inline constant buffer at the given index
334+
BufferVkImpl* GetInlineConstantBuffer(Uint32 Index) const
335+
{
336+
VERIFY_EXPR(Index < m_NumInlineConstantBuffers);
337+
return m_pInlineConstantBuffers[Index].RawPtr();
338+
}
339+
340+
Uint32 GetNumInlineConstantBuffers() const { return m_NumInlineConstantBuffers; }
341+
316342
Uint32 GetNumDescriptorSets() const { return m_NumSets; }
317343
bool HasDynamicResources() const { return m_NumDynamicBuffers > 0; }
318344

@@ -361,6 +387,12 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
361387
// Each pointer points to memory within m_pInlineConstantMemory
362388
std::unique_ptr<void*[]> m_pPushConstantDataPtrs;
363389

390+
// Array of inline constant buffers (one per emulated inline constant buffer)
391+
// Each SRB has its own copy of these buffers to avoid conflicts between
392+
// multiple PipelineStates sharing the same PipelineResourceSignature
393+
std::unique_ptr<RefCntAutoPtr<BufferVkImpl>[]> m_pInlineConstantBuffers;
394+
Uint16 m_NumInlineConstantBuffers = 0;
395+
364396
Uint16 m_NumSets = 0;
365397
Uint16 m_NumPushConstantBuffers = 0;
366398

0 commit comments

Comments
 (0)