Skip to content

Commit 5b206b2

Browse files
committed
Fix: Re-bind inline constant buffers after update when using compatible SRB
1 parent 10dbe81 commit 5b206b2

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ class PipelineResourceSignatureGLImpl final : public PipelineResourceSignatureBa
143143

144144
// Updates inline constant buffers by mapping the shared dynamic UBOs and copying
145145
// data from the CPU-side staging buffer in the resource cache.
146-
void UpdateInlineConstantBuffers(const ShaderResourceCacheGL& ResourceCache, class GLContextState& CtxState) const;
146+
// Also re-binds the inline constant buffers to the correct GL slots to ensure
147+
// the signature's shared buffers are used even when an SRB from a compatible
148+
// but different signature is used.
149+
void UpdateInlineConstantBuffers(const ShaderResourceCacheGL& ResourceCache,
150+
class GLContextState& CtxState,
151+
const TBindings& BaseBindings) const;
147152

148153
bool HasInlineConstants() const
149154
{

Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ void DeviceContextGLImpl::BindProgramResources(Uint32 BindSRBMask, bool DynamicB
756756
{
757757
if (PipelineResourceSignatureGLImpl* pSign = m_pPipelineState->GetResourceSignature(sign))
758758
{
759-
pSign->UpdateInlineConstantBuffers(*pResourceCache, GetContextState());
759+
pSign->UpdateInlineConstantBuffers(*pResourceCache, GetContextState(), BaseBindings);
760760
}
761761
else
762762
{

Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,12 @@ void PipelineResourceSignatureGLImpl::CopyStaticResources(ShaderResourceCacheGL&
605605
#endif
606606
}
607607

608-
void PipelineResourceSignatureGLImpl::UpdateInlineConstantBuffers(const ShaderResourceCacheGL& ResourceCache, GLContextState& CtxState) const
608+
void PipelineResourceSignatureGLImpl::UpdateInlineConstantBuffers(const ShaderResourceCacheGL& ResourceCache,
609+
GLContextState& CtxState,
610+
const TBindings& BaseBindings) const
609611
{
612+
const Uint16 BaseUBOBinding = BaseBindings[BINDING_RANGE_UNIFORM_BUFFER];
613+
610614
for (Uint32 i = 0; i < m_NumInlineConstantBuffers; ++i)
611615
{
612616
const InlineConstantBufferAttribsGL& InlineCBAttr = GetInlineConstantBuffer(i);
@@ -616,11 +620,24 @@ void PipelineResourceSignatureGLImpl::UpdateInlineConstantBuffers(const ShaderRe
616620
VERIFY(InlineCBAttr.NumConstants * sizeof(Uint32) == InlineCB.RangeSize, "Inline constant buffer size mismatch");
617621
VERIFY(InlineCB.pInlineConstantData != nullptr, "Inline constant data pointer is null");
618622

623+
const Uint32 BufferSize = InlineCBAttr.NumConstants * sizeof(Uint32);
624+
619625
// Map the shared buffer and copy the data
620626
PVoid pMappedData = nullptr;
621627
InlineCBAttr.pBuffer->Map(CtxState, MAP_WRITE, MAP_FLAG_DISCARD, pMappedData);
622-
memcpy(pMappedData, InlineCB.pInlineConstantData, InlineCBAttr.NumConstants * sizeof(Uint32));
628+
memcpy(pMappedData, InlineCB.pInlineConstantData, BufferSize);
623629
InlineCBAttr.pBuffer->Unmap(CtxState);
630+
631+
// Re-bind the signature's shared inline constant buffer to the GL slot.
632+
// This is necessary because when an SRB created from a compatible but different
633+
// signature is used, the SRB's cache contains buffer pointers to the original
634+
// signature's shared buffers. BindResources() binds those buffers, but we need
635+
// to bind *this* signature's shared buffers which now contain the updated data.
636+
InlineCBAttr.pBuffer->BufferMemoryBarrier(MEMORY_BARRIER_UNIFORM_BUFFER, CtxState);
637+
CtxState.BindUniformBuffer(BaseUBOBinding + InlineCBAttr.CacheOffset,
638+
InlineCBAttr.pBuffer->GetGLHandle(),
639+
0, // BaseOffset
640+
BufferSize);
624641
}
625642
}
626643

0 commit comments

Comments
 (0)