11/*
2- * Copyright 2019-2025 Diligent Graphics LLC
2+ * Copyright 2019-2026 Diligent Graphics LLC
33 * Copyright 2015-2019 Egor Yusov
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -698,7 +698,7 @@ void DeviceContextGLImpl::DvpValidateCommittedShaderResources()
698698}
699699#endif
700700
701- void DeviceContextGLImpl::BindProgramResources (Uint32 BindSRBMask)
701+ void DeviceContextGLImpl::BindProgramResources (Uint32 BindSRBMask, bool DynamicBuffersIntact, bool InlineConstantsIntact )
702702{
703703 VERIFY_EXPR (BindSRBMask != 0 );
704704 // if (m_CommittedResourcesTentativeBarriers != 0)
@@ -721,16 +721,55 @@ void DeviceContextGLImpl::BindProgramResources(Uint32 BindSRBMask)
721721
722722 const ShaderResourceCacheImplType* pResourceCache = m_BindInfo.ResourceCaches [sign];
723723 DEV_CHECK_ERR (pResourceCache != nullptr , " Resource cache at index " , sign, " is null" );
724- if (m_BindInfo.StaleSRBMask & SignBit)
724+
725+ const bool SRBStale = (m_BindInfo.StaleSRBMask & SignBit) != 0 ;
726+ if (SRBStale)
727+ {
725728 pResourceCache->BindResources (GetContextState (), BaseBindings, m_BoundWritableTextures, m_BoundWritableBuffers);
729+ }
726730 else
727731 {
728- VERIFY ((m_BindInfo.DynamicSRBMask & SignBit) != 0 ,
729- " When bit in StaleSRBMask is not set, the same bit in DynamicSRBMask must be set. Check GetCommitMask()." );
730- DEV_CHECK_ERR (pResourceCache->HasDynamicResources (),
731- " Bit in DynamicSRBMask is set, but the cache does not contain dynamic resources. This may indicate that resources "
732- " in the cache have changed, but the SRB has not been committed before the draw/dispatch command." );
733- pResourceCache->BindDynamicBuffers (GetContextState (), BaseBindings);
732+ VERIFY (((m_BindInfo.DynamicSRBMask | m_BindInfo.InlineConstantsSRBMask ) & SignBit) != 0 ,
733+ " When bit in StaleSRBMask is not set, the same bit in either DynamicSRBMask or InlineConstantsSRBMask must be set. Check GetCommitMask()." );
734+
735+ if ((m_BindInfo.DynamicSRBMask & SignBit) != 0 )
736+ {
737+ DEV_CHECK_ERR (pResourceCache->HasDynamicResources (),
738+ " Bit in DynamicSRBMask is set, but the cache does not contain dynamic resources. This may indicate that resources "
739+ " in the cache have changed, but the SRB has not been committed before the draw/dispatch command." );
740+ if (!DynamicBuffersIntact)
741+ {
742+ pResourceCache->BindDynamicBuffers (GetContextState (), BaseBindings);
743+ }
744+ }
745+ }
746+
747+ // Update inline constant buffers if needed
748+ if ((m_BindInfo.InlineConstantsSRBMask & SignBit) != 0 )
749+ {
750+ VERIFY (pResourceCache->HasInlineConstants (),
751+ " Shader resource cache does not contain inline constants, but the corresponding bit in InlineConstantsSRBMask is set. "
752+ " This may be a bug because inline constants flag in the cache never changes after SRB creation, "
753+ " while m_BindInfo.InlineConstantsSRBMask is initialized when SRB is committed." );
754+ // Always update inline constant buffers if the SRB is stale
755+ if (SRBStale || !InlineConstantsIntact)
756+ {
757+ if (PipelineResourceSignatureGLImpl* pSign = m_pPipelineState->GetResourceSignature (sign))
758+ {
759+ pSign->UpdateInlineConstantBuffers (*pResourceCache, GetContextState ());
760+ }
761+ else
762+ {
763+ UNEXPECTED (" Pipeline resource signature is null for signature index " , sign);
764+ }
765+ }
766+ }
767+ else
768+ {
769+ VERIFY (!pResourceCache->HasInlineConstants (),
770+ " Shader resource cache contains inline constants, but the corresponding bit in InlineConstantsSRBMask is not set. "
771+ " This may be a bug because inline constants flag in the cache never changes after SRB creation, "
772+ " while m_BindInfo.InlineConstantsSRBMask is initialized when SRB is committed." );
734773 }
735774 }
736775 m_BindInfo.StaleSRBMask &= ~m_BindInfo.ActiveSRBMask ;
@@ -797,9 +836,11 @@ void DeviceContextGLImpl::PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenu
797836 // The program might have changed since the last SetPipelineState call if a shader was
798837 // created after the call (ShaderResourcesGL needs to bind a program to load uniforms).
799838 m_pPipelineState->CommitProgram (m_ContextState);
800- if (Uint32 BindSRBMask = m_BindInfo.GetCommitMask (Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT, Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT))
839+ const bool DynamicBuffersIntact = (Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT) != 0 ;
840+ const bool InlineConstantsIntact = (Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT) != 0 ;
841+ if (Uint32 BindSRBMask = m_BindInfo.GetCommitMask (DynamicBuffersIntact, InlineConstantsIntact))
801842 {
802- BindProgramResources (BindSRBMask);
843+ BindProgramResources (BindSRBMask, DynamicBuffersIntact, InlineConstantsIntact );
803844 }
804845
805846#ifdef DILIGENT_DEVELOPMENT
0 commit comments