Skip to content

Commit c61d4ef

Browse files
committed
Fix HLSL2GLSLConverter:
Root Cause The HLSL2GLSL converter was not assigning explicit layout(binding=N) qualifiers to uniform blocks (cbuffers), while it was already doing this for SSBOs and images. This caused OpenGL linking failures when: VS has cbInlinePositions (binding 0 by default) and cbInlineColors (binding 1 by default) PS has only cbInlineColors (binding 0 by default, since it's the first UBO in PS) When linked together, binding 0 had conflicting definitions → "buffer block with binding '0' has mismatching definitions".
1 parent 5a675bd commit c61d4ef

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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");
@@ -290,7 +290,7 @@ class HLSL2GLSLConverterImpl
290290

291291
void RegisterStruct(TokenListType::iterator& Token);
292292

293-
void ProcessConstantBuffer(TokenListType::iterator& Token);
293+
void ProcessConstantBuffer(TokenListType::iterator& Token, Uint32& UniformBlockBinding);
294294
void ProcessStructuredBuffer(TokenListType::iterator& Token, Uint32& ShaderStorageBlockBinding);
295295
void ProcessPreprocessorDirective(TokenListType::iterator& Token);
296296
void ParseSamplers(TokenListType::iterator& ScopeStart, SamplerHashType& SamplersHash);

Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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");
@@ -912,14 +912,20 @@ HLSL2GLSLConverterImpl::TokenListType::iterator HLSL2GLSLConverterImpl::Conversi
912912
// ...
913913
// }; <- Semicolon must be here
914914
//
915-
void HLSL2GLSLConverterImpl::ConversionStream::ProcessConstantBuffer(TokenListType::iterator& Token)
915+
void HLSL2GLSLConverterImpl::ConversionStream::ProcessConstantBuffer(TokenListType::iterator& Token, Uint32& UniformBlockBinding)
916916
{
917917
VERIFY_EXPR(Token->Type == TokenType::kw_cbuffer);
918918

919-
// Replace "cbuffer" with "uniform"
920-
Token->Literal = m_bUseRowMajorMatrices ?
921-
"layout(row_major) uniform" :
922-
"uniform";
919+
// Replace "cbuffer" with "layout(binding=N) uniform" or "layout(row_major, binding=N) uniform"
920+
{
921+
std::stringstream ss;
922+
if (m_bUseRowMajorMatrices)
923+
ss << "layout(row_major, binding=" << UniformBlockBinding << ") uniform";
924+
else
925+
ss << "layout(binding=" << UniformBlockBinding << ") uniform";
926+
Token->Literal = ss.str();
927+
++UniformBlockBinding;
928+
}
923929
++Token;
924930
// cbuffer CBufferName
925931
// ^
@@ -4554,6 +4560,7 @@ StringAlloc HLSL2GLSLConverterImpl::ConversionStream::Convert(const Char* EntryP
45544560

45554561
Uint32 ShaderStorageBlockBinding = 0;
45564562
Uint32 ImageBinding = 0;
4563+
Uint32 UniformBlockBinding = 0;
45574564

45584565
std::unordered_map<String, bool> SamplersHash;
45594566

@@ -4565,7 +4572,7 @@ StringAlloc HLSL2GLSLConverterImpl::ConversionStream::Convert(const Char* EntryP
45654572
switch (Token->Type)
45664573
{
45674574
case TokenType::kw_cbuffer:
4568-
ProcessConstantBuffer(Token);
4575+
ProcessConstantBuffer(Token, UniformBlockBinding);
45694576
break;
45704577

45714578
case TokenType::kw_RWStructuredBuffer:

0 commit comments

Comments
 (0)