From c92f527a45f85f8f229bb7996e9591a9619c2a9c Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 2 Oct 2019 20:36:54 -0700 Subject: HLSL2GLSL converter: implemented automatic assignment of shader storage buffer binding points --- .../GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 3 ++- .../include/HLSL2GLSLConverterImpl.h | 2 +- .../HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 9e1a8a2b..c04d54ea 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -665,7 +665,8 @@ namespace Diligent LOG_WARNING_MESSAGE_ONCE("glShaderStorageBlockBinding is not available on this device and " "the engine is unable to automatically assign shader storage block bindindg points. " "To make shader storage blocks work properly, all binding points must be explicitly assigned " - "in the shader starting from 0 and proceeding in the storage block declaration order."); + "in the shader starting from 0 and proceeding in the storage block declaration order. " + "Note that the binding points are properly assigned by HLSL->GLSL converter."); } ++StorageBufferBindSlot; diff --git a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h index 6db5cf61..9bb04d38 100644 --- a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h +++ b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h @@ -258,7 +258,7 @@ namespace Diligent void RegisterStruct(TokenListType::iterator& Token); void ProcessConstantBuffer(TokenListType::iterator& Token); - void ProcessStructuredBuffer(TokenListType::iterator& Token); + void ProcessStructuredBuffer(TokenListType::iterator& Token, Uint32& ShaderStorageBlockBinding); void ParseSamplers(TokenListType::iterator& ScopeStart, SamplerHashType& SamplersHash); void ProcessTextureDeclaration(TokenListType::iterator& Token, const std::vector& SamplersHash, ObjectsTypeHashType& Objects, const char* SamplerSuffix); bool ProcessObjectMethod(TokenListType::iterator& Token, const TokenListType::iterator& ScopeStart, const TokenListType::iterator& ScopeEnd); diff --git a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp index 91d4127d..11c52576 100644 --- a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp +++ b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp @@ -1423,12 +1423,20 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessConstantBuffer( TokenListT } } -void HLSL2GLSLConverterImpl::ConversionStream::ProcessStructuredBuffer(TokenListType::iterator &Token) +void HLSL2GLSLConverterImpl::ConversionStream::ProcessStructuredBuffer(TokenListType::iterator& Token, Uint32& ShaderStorageBlockBinding) { // StructuredBuffer g_Data; // ^ VERIFY_EXPR( Token->Type == TokenType::kw_StructuredBuffer || Token->Type == TokenType::kw_RWStructuredBuffer ); - Token->Literal = "layout(std140) buffer"; + if (Token->Type == TokenType::kw_RWStructuredBuffer) + { + std::stringstream ss; + ss << "layout(std140, binding=" << ShaderStorageBlockBinding << ") buffer"; + Token->Literal = ss.str(); + ++ShaderStorageBlockBinding; + } + else + Token->Literal = "layout(std140) buffer"; // buffer g_Data; // ^ @@ -4481,6 +4489,8 @@ String HLSL2GLSLConverterImpl::ConversionStream::Convert(const Char* EntryPoint, m_bUseInOutLocationQualifiers = UseInOutLocationQualifiers; TokenListType TokensCopy(m_bPreserveTokens ? m_Tokens : TokenListType()); + Uint32 ShaderStorageBlockBinding = 0; + std::unordered_map SamplersHash; auto Token = m_Tokens.begin(); // Process constant buffers, fix floating point constants and @@ -4495,7 +4505,7 @@ String HLSL2GLSLConverterImpl::ConversionStream::Convert(const Char* EntryPoint, case TokenType::kw_RWStructuredBuffer: case TokenType::kw_StructuredBuffer: - ProcessStructuredBuffer( Token ); + ProcessStructuredBuffer( Token, ShaderStorageBlockBinding ); break; case TokenType::kw_struct: -- cgit v1.2.3