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");
@@ -130,12 +130,48 @@ PipelineResourceSignatureDescWrapper PipelineStateGLImpl::GetDefaultSignatureDes
130130 }
131131 };
132132
133+ // Specialized handler for uniform buffers to handle inline constants correctly
134+ const auto HandleUniformBuffer = [&](const ShaderResourcesGL::UniformBufferInfo& UB) //
135+ {
136+ const ShaderResourceVariableDesc VarDesc = FindPipelineResourceLayoutVariable (ResourceLayout, UB.Name , UB.ShaderStages , nullptr );
137+ const auto it_assigned = UniqueResources.emplace (ShaderResourceHashKey{VarDesc.ShaderStages , UB.Name }, UB);
138+ if (it_assigned.second )
139+ {
140+ const PIPELINE_RESOURCE_FLAGS Flags = UB.ResourceFlags | ShaderVariableFlagsToPipelineResourceFlags (VarDesc.Flags );
141+
142+ // For inline constants, use the constant count instead of the UBO array size
143+ Uint32 ArraySize = UB.ArraySize ;
144+ if (Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
145+ {
146+ VERIFY (Flags == PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS, " INLINE_CONSTANTS flag cannot be combined with other flags." );
147+ ArraySize = UB.GetInlineConstantCount ();
148+ if (ArraySize == 0 )
149+ {
150+ LOG_ERROR_AND_THROW (" Inline constants resource '" , UB.Name , " ' has zero buffer size. "
151+ " Make sure the shader was compiled with constant buffer reflection enabled." );
152+ }
153+ if (ArraySize > MAX_INLINE_CONSTANTS)
154+ {
155+ LOG_ERROR_AND_THROW (" Inline constants resource '" , UB.Name , " ' has " ,
156+ ArraySize, " constants. The maximum supported number of inline constants is " ,
157+ MAX_INLINE_CONSTANTS, ' .' );
158+ }
159+ }
160+
161+ SignDesc.AddResource (VarDesc.ShaderStages , UB.Name , ArraySize, UB.ResourceType , VarDesc.Type , Flags);
162+ }
163+ else
164+ {
165+ VerifyResourceMerge (m_Desc, it_assigned.first ->second , UB);
166+ }
167+ };
168+
133169 if (m_IsProgramPipelineSupported)
134170 {
135171 for (size_t i = 0 ; i < ShaderStages.size (); ++i)
136172 {
137173 ShaderGLImpl* pShaderGL = ShaderStages[i];
138- pShaderGL->GetShaderResources ()->ProcessConstResources (HandleResource , HandleResource, HandleResource, HandleResource);
174+ pShaderGL->GetShaderResources ()->ProcessConstResources (HandleUniformBuffer , HandleResource, HandleResource, HandleResource);
139175 }
140176 }
141177 else
@@ -153,7 +189,7 @@ PipelineResourceSignatureDescWrapper PipelineStateGLImpl::GetDefaultSignatureDes
153189 SamplerResFlag,
154190 pImmediateCtx->GetContextState ());
155191 }
156- m_GLPrograms[0 ]->GetResources ()->ProcessConstResources (HandleResource , HandleResource, HandleResource, HandleResource);
192+ m_GLPrograms[0 ]->GetResources ()->ProcessConstResources (HandleUniformBuffer , HandleResource, HandleResource, HandleResource);
157193
158194 if (ResourceLayout.NumImmutableSamplers > 0 )
159195 {
0 commit comments