From fd7f98d7fdde75908095a660a9a3ef6fc1ab5c72 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 9 Aug 2019 20:13:12 -0700 Subject: OpenGL backend: fixed issue with using unitialized binding points --- .../include/GLProgramResources.h | 30 +++--- .../src/DeviceContextGLImpl.cpp | 82 ++++++++++----- .../src/GLProgramResources.cpp | 114 ++++++++++----------- 3 files changed, 121 insertions(+), 105 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h index b0ebfa06..8e43dedb 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h @@ -176,7 +176,7 @@ namespace Diligent const GLuint UBIndex; }; - static_assert( (sizeof(UniformBufferInfo) % sizeof(void*)) == 0, "sizeof(UniformBufferInfo) must be multiple of sizeof(void*)"); + static_assert((sizeof(UniformBufferInfo) % sizeof(void*)) == 0, "sizeof(UniformBufferInfo) must be multiple of sizeof(void*)"); struct SamplerInfo final : GLProgramVariableBase @@ -218,7 +218,7 @@ namespace Diligent const GLenum SamplerType; RefCntAutoPtr pStaticSampler; }; - static_assert( (sizeof(SamplerInfo) % sizeof(void*)) == 0, "sizeof(SamplerInfo) must be multiple of sizeof(void*)"); + static_assert((sizeof(SamplerInfo) % sizeof(void*)) == 0, "sizeof(SamplerInfo) must be multiple of sizeof(void*)"); struct ImageInfo final : GLProgramVariableBase @@ -235,29 +235,29 @@ namespace Diligent Uint16 _VariableIndex, Uint32 _ArraySize, RefCntAutoPtr* _pResources, - GLint _BindingPoint, + GLint _Location, GLenum _ImageType) : GLProgramVariableBase(_Owner, _Name, _VariableType, _ResourceType, _VariableIndex, _ArraySize, _pResources), - BindingPoint(_BindingPoint), - ImageType (_ImageType) + Location (_Location), + ImageType (_ImageType) {} bool IsCompatibleWith(const ImageInfo& II)const { - return BindingPoint == II.BindingPoint && - ImageType == II.ImageType && + return Location == II.Location && + ImageType == II.ImageType && GLProgramVariableBase::IsCompatibleWith(II); } size_t GetHash()const { - return ComputeHash(BindingPoint, ImageType, GLProgramVariableBase::GetHash()); + return ComputeHash(Location, ImageType, GLProgramVariableBase::GetHash()); } - const GLint BindingPoint; + const GLint Location; const GLenum ImageType; }; - static_assert( (sizeof(ImageInfo) % sizeof(void*)) == 0, "sizeof(ImageInfo) must be multiple of sizeof(void*)"); + static_assert((sizeof(ImageInfo) % sizeof(void*)) == 0, "sizeof(ImageInfo) must be multiple of sizeof(void*)"); struct StorageBlockInfo final : GLProgramVariableBase @@ -274,23 +274,23 @@ namespace Diligent Uint16 _VariableIndex, Uint32 _ArraySize, RefCntAutoPtr* _pResources, - GLint _Binding) : + GLint _SBIndex) : GLProgramVariableBase(_Owner, _Name, _VariableType, _ResourceType, _VariableIndex, _ArraySize, _pResources), - Binding(_Binding) + SBIndex(_SBIndex) {} bool IsCompatibleWith(const StorageBlockInfo& SBI)const { - return Binding == SBI.Binding && + return SBIndex == SBI.SBIndex && GLProgramVariableBase::IsCompatibleWith(SBI); } size_t GetHash()const { - return ComputeHash(Binding, GLProgramVariableBase::GetHash()); + return ComputeHash(SBIndex, GLProgramVariableBase::GetHash()); } - const GLint Binding; + const GLint SBIndex; }; static_assert( (sizeof(StorageBlockInfo) % sizeof(void*)) == 0, "sizeof(StorageBlockInfo) must be multiple of sizeof(void*)"); diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 77342fa0..2b19d5f1 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -382,8 +382,10 @@ namespace Diligent } Uint32 NumPrograms = ProgramPipelineSupported ? m_pPipelineState->GetNumShaders() : 1; - GLuint UniformBuffBindPoint = 0; - GLuint TextureIndex = 0; + GLuint UnifromBufferBindSlot = 0; + GLuint StorageBufferBindSlot = 0; + GLuint TextureBindSlot = 0; + GLuint ImageBindSlot = 0; m_BoundWritableTextures.clear(); m_BoundWritableBuffers.clear(); for (Uint32 ProgNum = 0; ProgNum < NumPrograms; ++ProgNum) @@ -419,22 +421,22 @@ namespace Diligent // will reflect data written by shaders prior to the barrier m_ContextState); - glBindBufferBase(GL_UNIFORM_BUFFER, UniformBuffBindPoint, pBufferGL->m_GlBuffer); + glBindBufferBase(GL_UNIFORM_BUFFER, UnifromBufferBindSlot, pBufferGL->m_GlBuffer); CHECK_GL_ERROR("Failed to bind uniform buffer"); //glBindBufferRange(GL_UNIFORM_BUFFER, it->Index, pBufferGL->m_GlBuffer, 0, pBufferGL->GetDesc().uiSizeInBytes); - glUniformBlockBinding(GLProgID, UB.UBIndex + ArrInd, UniformBuffBindPoint); + glUniformBlockBinding(GLProgID, UB.UBIndex + ArrInd, UnifromBufferBindSlot); CHECK_GL_ERROR("glUniformBlockBinding() failed"); - ++UniformBuffBindPoint; + ++UnifromBufferBindSlot; } else { #define LOG_MISSING_BINDING(VarType, Res, ArrInd)\ - do{ \ - if(Res.ArraySize > 1) \ + do{ \ + if(Res.ArraySize > 1) \ LOG_ERROR_MESSAGE( "No ", VarType, " is bound to '", Res.Name, '[', ArrInd, "]' variable in shader '", pShaderGL->GetDesc().Name, "'" );\ - else \ + else \ LOG_ERROR_MESSAGE( "No ", VarType, " is bound to '", Res.Name, "' variable in shader '", pShaderGL->GetDesc().Name, "'" );\ }while(false) @@ -458,8 +460,8 @@ namespace Diligent auto* pBufViewGL = Resource.RawPtr(); auto* pBuffer = pBufViewGL->GetBuffer(); - m_ContextState.BindTexture( TextureIndex, GL_TEXTURE_BUFFER, pBufViewGL->GetTexBufferHandle() ); - m_ContextState.BindSampler( TextureIndex, GLObjectWrappers::GLSamplerObj(false) ); // Use default texture sampling parameters + m_ContextState.BindTexture(TextureBindSlot, GL_TEXTURE_BUFFER, pBufViewGL->GetTexBufferHandle()); + m_ContextState.BindSampler(TextureBindSlot, GLObjectWrappers::GLSamplerObj(false)); // Use default texture sampling parameters ValidatedCast(pBuffer)->BufferMemoryBarrier( GL_TEXTURE_FETCH_BARRIER_BIT, // Texture fetches from shaders, including fetches from buffer object @@ -470,7 +472,7 @@ namespace Diligent else { auto* pTexViewGL = Resource.RawPtr(); - m_ContextState.BindTexture( TextureIndex, pTexViewGL->GetBindTarget(), pTexViewGL->GetHandle() ); + m_ContextState.BindTexture(TextureBindSlot, pTexViewGL->GetBindTarget(), pTexViewGL->GetHandle()); auto* pTexture = pTexViewGL->GetTexture(); ValidatedCast(pTexture)->TextureMemoryBarrier( @@ -490,13 +492,13 @@ namespace Diligent pSamplerGL = ValidatedCast(pSampler); } - if( pSamplerGL ) + if (pSamplerGL) { - m_ContextState.BindSampler(TextureIndex, pSamplerGL->GetHandle()); + m_ContextState.BindSampler(TextureBindSlot, pSamplerGL->GetHandle()); } else { - m_ContextState.BindSampler(TextureIndex, GLObjectWrappers::GLSamplerObj(false)); + m_ContextState.BindSampler(TextureBindSlot, GLObjectWrappers::GLSamplerObj(false)); } } @@ -505,16 +507,16 @@ namespace Diligent if (ProgramPipelineSupported) { // glProgramUniform1i does not require program to be bound to the pipeline - glProgramUniform1i( GLProgramObj, Sam.Location + ArrInd, TextureIndex ); + glProgramUniform1i(GLProgramObj, Sam.Location + ArrInd, TextureBindSlot); } else { // glUniform1i requires program to be bound to the pipeline - glUniform1i(Sam.Location + ArrInd, TextureIndex); + glUniform1i(Sam.Location + ArrInd, TextureBindSlot); } - CHECK_GL_ERROR("Failed to bind sampler uniform to texture slot"); + CHECK_GL_ERROR("Failed to set binding point for sampler uniform '", Sam.Name, '\''); - ++TextureIndex; + ++TextureBindSlot; } else { @@ -549,10 +551,11 @@ namespace Diligent // stores, texture fetches, vertex fetches) initiated prior to the barrier // complete. m_ContextState); + m_BoundWritableBuffers.push_back(pBufferGL); auto GlFormat = TypeToGLTexFormat(ViewDesc.Format.ValueType, ViewDesc.Format.NumComponents, ViewDesc.Format.IsNormalized); - m_ContextState.BindImage(Img.BindingPoint + ArrInd, pBuffViewGL, GL_READ_WRITE, GlFormat); + m_ContextState.BindImage(ImageBindSlot, pBuffViewGL, GL_READ_WRITE, GlFormat); } else { @@ -602,8 +605,25 @@ namespace Diligent // That means that if an integer texture is being bound, its // GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER must be NEAREST, // otherwise it will be incomplete - m_ContextState.BindImage(Img.BindingPoint + ArrInd, pTexViewGL, ViewDesc.MostDetailedMip, Layered, Layer, GLAccess, GlTexFormat); + m_ContextState.BindImage(ImageBindSlot, pTexViewGL, ViewDesc.MostDetailedMip, Layered, Layer, GLAccess, GlTexFormat); + // Do not use binding points from reflection as they may not be initialized + } + + // Image is now bound to binding slot ImageIndex. + // We now need to set the program uniform to use that slot + if (ProgramPipelineSupported) + { + // glProgramUniform1i does not require program to be bound to the pipeline + glProgramUniform1i(GLProgramObj, Img.Location + ArrInd, ImageBindSlot); } + else + { + // glUniform1i requires program to be bound to the pipeline + glUniform1i(Img.Location + ArrInd, ImageBindSlot); + } + CHECK_GL_ERROR("Failed to set binding point for image uniform '", Img.Name, '\''); + + ++ImageBindSlot; } else { @@ -632,9 +652,14 @@ namespace Diligent // will reflect writes prior to the barrier m_ContextState); - glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SB.Binding + ArrInd, pBufferGL->m_GlBuffer, ViewDesc.ByteOffset, ViewDesc.ByteWidth); + glBindBufferRange(GL_SHADER_STORAGE_BUFFER, StorageBufferBindSlot, pBufferGL->m_GlBuffer, ViewDesc.ByteOffset, ViewDesc.ByteWidth); CHECK_GL_ERROR("Failed to bind shader storage buffer"); + glShaderStorageBlockBinding(GLProgID, SB.SBIndex + ArrInd, StorageBufferBindSlot); + CHECK_GL_ERROR("glUniformBlockBinding() failed"); + + ++StorageBufferBindSlot; + if (ViewDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS) m_BoundWritableBuffers.push_back(pBufferGL); } @@ -682,14 +707,15 @@ namespace Diligent for (auto* pWritableBuff : m_BoundWritableBuffers) { Uint32 BufferMemoryBarriers = - GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT | - GL_ELEMENT_ARRAY_BARRIER_BIT | - GL_UNIFORM_BARRIER_BIT | - GL_COMMAND_BARRIER_BIT | - GL_BUFFER_UPDATE_BARRIER_BIT | + GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT | + GL_ELEMENT_ARRAY_BARRIER_BIT | + GL_UNIFORM_BARRIER_BIT | + GL_COMMAND_BARRIER_BIT | + GL_BUFFER_UPDATE_BARRIER_BIT | GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT | - GL_SHADER_STORAGE_BARRIER_BIT | - GL_TEXTURE_FETCH_BARRIER_BIT; + GL_SHADER_STORAGE_BARRIER_BIT | + GL_TEXTURE_FETCH_BARRIER_BIT | + GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; NewMemoryBarriers |= BufferMemoryBarriers; // Set new required barriers for the time when buffer is used next time diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index 1ad1b73c..5fc43abd 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -207,7 +207,7 @@ namespace Diligent VariableIndex++, SrcImg.ArraySize, pCurrResource, - SrcImg.BindingPoint, + SrcImg.Location, SrcImg.ImageType }; if (pCurrResource != nullptr) @@ -226,7 +226,7 @@ namespace Diligent VariableIndex++, SrcSB.ArraySize, pCurrResource, - SrcSB.Binding + SrcSB.SBIndex }; if (pCurrResource != nullptr) @@ -295,17 +295,17 @@ namespace Diligent m_ShaderStages = ShaderStages; GLint numActiveUniforms = 0; - glGetProgramiv( GLProgram, GL_ACTIVE_UNIFORMS, &numActiveUniforms ); - CHECK_GL_ERROR_AND_THROW( "Unable to get number of active uniforms\n" ); + glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORMS, &numActiveUniforms); + CHECK_GL_ERROR_AND_THROW("Unable to get the number of active uniforms\n"); // Query the maximum name length of the active uniform (including null terminator) GLint activeUniformMaxLength = 0; - glGetProgramiv( GLProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength ); - CHECK_GL_ERROR_AND_THROW( "Unable to get maximum uniform name length\n" ); + glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength); + CHECK_GL_ERROR_AND_THROW("Unable to get the maximum uniform name length\n"); GLint numActiveUniformBlocks = 0; - glGetProgramiv( GLProgram, GL_ACTIVE_UNIFORM_BLOCKS, &numActiveUniformBlocks ); - CHECK_GL_ERROR_AND_THROW( "Unable to get the number of active uniform blocks\n" ); + glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_BLOCKS, &numActiveUniformBlocks); + CHECK_GL_ERROR_AND_THROW("Unable to get the number of active uniform blocks\n"); // // #### This parameter is currently unsupported by Intel OGL drivers. @@ -313,47 +313,47 @@ namespace Diligent // Query the maximum name length of the active uniform block (including null terminator) GLint activeUniformBlockMaxLength = 0; // On Intel driver, this call might fail: - glGetProgramiv( GLProgram, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &activeUniformBlockMaxLength ); + glGetProgramiv(GLProgram, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &activeUniformBlockMaxLength); //CHECK_GL_ERROR_AND_THROW("Unable to get the maximum uniform block name length\n"); - if( GL_NO_ERROR != glGetError() ) + if (glGetError() != GL_NO_ERROR) { LOG_WARNING_MESSAGE( "Unable to get the maximum uniform block name length. Using 1024 as a workaround\n" ); activeUniformBlockMaxLength = 1024; } - auto MaxNameLength = std::max( activeUniformMaxLength, activeUniformBlockMaxLength ); + auto MaxNameLength = std::max(activeUniformMaxLength, activeUniformBlockMaxLength); #if GL_ARB_program_interface_query GLint numActiveShaderStorageBlocks = 0; - if(glGetProgramInterfaceiv) + if (glGetProgramInterfaceiv) { - glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numActiveShaderStorageBlocks ); + glGetProgramInterfaceiv(GLProgram, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numActiveShaderStorageBlocks); CHECK_GL_ERROR_AND_THROW( "Unable to get the number of shader storage blocks blocks\n" ); // Query the maximum name length of the active shader storage block (including null terminator) GLint MaxShaderStorageBlockNameLen = 0; - glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &MaxShaderStorageBlockNameLen ); + glGetProgramInterfaceiv(GLProgram, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &MaxShaderStorageBlockNameLen); CHECK_GL_ERROR_AND_THROW( "Unable to get the maximum shader storage block name length\n" ); MaxNameLength = std::max( MaxNameLength, MaxShaderStorageBlockNameLen ); } #endif - MaxNameLength = std::max( MaxNameLength, 512 ); - std::vector Name( MaxNameLength + 1 ); - for( int i = 0; i < numActiveUniforms; i++ ) + MaxNameLength = std::max(MaxNameLength, 512); + std::vector Name(MaxNameLength + 1); + for (int i = 0; i < numActiveUniforms; i++) { GLenum dataType = 0; - GLint size = 0; - GLint NameLen = 0; - // If one or more elements of an array are active, the name of the array is returned in name?, - // the type is returned in type?, and the size? parameter returns the highest array element index used, + GLint size = 0; + GLint NameLen = 0; + // If one or more elements of an array are active, the name of the array is returned in 'name', + // the type is returned in 'type', and the 'size' parameter returns the highest array element index used, // plus one, as determined by the compiler and/or linker. // Only one active uniform variable will be reported for a uniform array. // Uniform variables other than arrays will have a size of 1 - glGetActiveUniform( GLProgram, i, MaxNameLength, &NameLen, &size, &dataType, Name.data() ); - CHECK_GL_ERROR_AND_THROW( "Unable to get active uniform\n" ); - VERIFY( NameLen < MaxNameLength && static_cast(NameLen) == strlen( Name.data() ), "Incorrect uniform name" ); - VERIFY( size >= 1, "Size is expected to be at least 1" ); + glGetActiveUniform(GLProgram, i, MaxNameLength, &NameLen, &size, &dataType, Name.data()); + CHECK_GL_ERROR_AND_THROW("Unable to get active uniform\n"); + VERIFY(NameLen < MaxNameLength && static_cast(NameLen) == strlen( Name.data() ), "Incorrect uniform name"); + VERIFY(size >= 1, "Size is expected to be at least 1"); // Note that // glGetActiveUniform( program, index, bufSize, length, size, type, name ); // @@ -366,7 +366,7 @@ namespace Diligent // // The latter is only available in GL 4.4 and GLES 3.1 - switch( dataType ) + switch (dataType) { case GL_SAMPLER_1D: case GL_SAMPLER_2D: @@ -410,9 +410,9 @@ namespace Diligent case GL_INT_SAMPLER_BUFFER: case GL_UNSIGNED_INT_SAMPLER_BUFFER: { - auto UniformLocation = glGetUniformLocation( GLProgram, Name.data() ); + auto UniformLocation = glGetUniformLocation(GLProgram, Name.data()); // Note that glGetUniformLocation(program, name) is equivalent to - // glGetProgramResourceLocation( program, GL_UNIFORM, name ); + // glGetProgramResourceLocation(program, GL_UNIFORM, name); // The latter is only available in GL 4.4 and GLES 3.1 const auto ResourceType = dataType == GL_SAMPLER_BUFFER || @@ -473,19 +473,14 @@ namespace Diligent case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: { auto UniformLocation = glGetUniformLocation( GLProgram, Name.data() ); - - GLint BindingPoint = -1; - // The value of an image uniform is an integer specifying the image unit accessed - glGetUniformiv( GLProgram, UniformLocation, &BindingPoint ); - CHECK_GL_ERROR_AND_THROW("Failed to get image binding point"); - VERIFY( BindingPoint >= 0, "Incorrect binding point" ); - - RemoveArrayBrackets(Name.data()); const auto ResourceType = dataType == GL_IMAGE_BUFFER || dataType == GL_INT_IMAGE_BUFFER || dataType == GL_UNSIGNED_INT_IMAGE_BUFFER ? SHADER_RESOURCE_TYPE_BUFFER_UAV : SHADER_RESOURCE_TYPE_TEXTURE_UAV; + + RemoveArrayBrackets(Name.data()); + Images.emplace_back( Owner, NamesPool.emplace(Name.data()).first->c_str(), @@ -494,7 +489,7 @@ namespace Diligent Uint16{0xFFFF}, // Variable index is assigned by AllocateResources static_cast(size), nullptr, // pResources - BindingPoint, + UniformLocation, dataType ); break; } @@ -505,20 +500,20 @@ namespace Diligent } } - for( int i = 0; i < numActiveUniformBlocks; i++ ) + for (int i = 0; i < numActiveUniformBlocks; i++) { // In contrast to shader uniforms, every element in uniform block array is enumerated individually GLsizei NameLen = 0; - glGetActiveUniformBlockName( GLProgram, i, MaxNameLength, &NameLen, Name.data() ); - CHECK_GL_ERROR_AND_THROW( "Unable to get active uniform block name\n" ); - VERIFY( NameLen < MaxNameLength && static_cast(NameLen) == strlen( Name.data() ), "Incorrect uniform block name" ); + glGetActiveUniformBlockName(GLProgram, i, MaxNameLength, &NameLen, Name.data()); + CHECK_GL_ERROR_AND_THROW("Unable to get active uniform block name\n"); + VERIFY(NameLen < MaxNameLength && static_cast(NameLen) == strlen( Name.data() ), "Incorrect uniform block name"); // glGetActiveUniformBlockName( program, uniformBlockIndex, bufSize, length, uniformBlockName ); // is equivalent to // glGetProgramResourceName(program, GL_UNIFORM_BLOCK, uniformBlockIndex, bufSize, length, uniformBlockName); - auto UniformBlockIndex = glGetUniformBlockIndex( GLProgram, Name.data() ); - CHECK_GL_ERROR_AND_THROW( "Unable to get active uniform block index\n" ); + auto UniformBlockIndex = glGetUniformBlockIndex(GLProgram, Name.data()); + CHECK_GL_ERROR_AND_THROW("Unable to get active uniform block index\n"); // glGetUniformBlockIndex( program, uniformBlockName ); // is equivalent to // glGetProgramResourceIndex( program, GL_UNIFORM_BLOCK, uniformBlockName ); @@ -544,8 +539,8 @@ namespace Diligent else { #ifdef _DEBUG - for(const auto& ub : UniformBlocks) - VERIFY( strcmp(ub.Name, Name.data()) != 0, "Uniform block with the name \"", ub.Name, "\" has already been enumerated"); + for (const auto& ub : UniformBlocks) + VERIFY(strcmp(ub.Name, Name.data()) != 0, "Uniform block with the name '", ub.Name, "' has already been enumerated"); #endif } } @@ -564,24 +559,19 @@ namespace Diligent } #if GL_ARB_shader_storage_buffer_object - for( int i = 0; i < numActiveShaderStorageBlocks; ++i ) + for (int i = 0; i < numActiveShaderStorageBlocks; ++i) { GLsizei Length = 0; - glGetProgramResourceName( GLProgram, GL_SHADER_STORAGE_BLOCK, i, MaxNameLength, &Length, Name.data() ); - CHECK_GL_ERROR_AND_THROW( "Unable to get shader storage block name\n" ); + glGetProgramResourceName(GLProgram, GL_SHADER_STORAGE_BLOCK, i, MaxNameLength, &Length, Name.data()); + CHECK_GL_ERROR_AND_THROW("Unable to get shader storage block name\n"); VERIFY( Length < MaxNameLength && static_cast(Length) == strlen( Name.data() ), "Incorrect shader storage block name" ); - GLenum Props[] = {GL_BUFFER_BINDING}; - GLint Binding = -1; - GLint ValuesWritten = 0; - glGetProgramResourceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, i, _countof(Props), Props, 1, &ValuesWritten, &Binding ); - CHECK_GL_ERROR_AND_THROW( "Unable to get shader storage block binding & array size\n" ); - VERIFY( ValuesWritten == _countof(Props), "Unexpected number of values written" ); - VERIFY( Binding >= 0, "Incorrect shader storage block binding" ); + auto SBIndex = glGetProgramResourceIndex(GLProgram, GL_SHADER_STORAGE_BLOCK, Name.data()); + CHECK_GL_ERROR_AND_THROW("Unable to get shader storage block index\n"); Int32 ArraySize = 1; auto* OpenBacketPtr = strchr(Name.data(), '['); - if(OpenBacketPtr != nullptr) + if (OpenBacketPtr != nullptr) { auto Ind = atoi(OpenBacketPtr+1); ArraySize = std::max(ArraySize, Ind+1); @@ -593,15 +583,15 @@ namespace Diligent if ( strcmp(LastBlock.Name, Name.data()) == 0) { ArraySize = std::max(ArraySize, static_cast(LastBlock.ArraySize)); - VERIFY(Binding == LastBlock.Binding + Ind, "Storage block bindings are expected to be continuous"); + VERIFY(SBIndex == LastBlock.SBIndex + Ind, "Storage block indices are expected to be continuous"); LastBlock.ArraySize = ArraySize; continue; } else { #ifdef _DEBUG - for(const auto& sb : StorageBlocks) - VERIFY( strcmp(sb.Name, Name.data()) != 0, "Storage block with the name \"", sb.Name, "\" has already been enumerated"); + for (const auto& sb : StorageBlocks) + VERIFY(strcmp(sb.Name, Name.data()) != 0, "Storage block with the name \"", sb.Name, "\" has already been enumerated"); #endif } } @@ -615,7 +605,7 @@ namespace Diligent Uint16{0xFFFF}, // Variable index is assigned by AllocateResources static_cast(ArraySize), nullptr, // pResources - Binding + SBIndex ); } #endif @@ -702,7 +692,7 @@ namespace Diligent Uint16{0xFFFF}, // Variable index is assigned by AllocateResources SrcImg.ArraySize, nullptr, // pResources - SrcImg.BindingPoint, + SrcImg.Location, SrcImg.ImageType ); } @@ -722,7 +712,7 @@ namespace Diligent Uint16{0xFFFF}, // Variable index is assigned by AllocateResources SrcSB.ArraySize, nullptr, // pResources - SrcSB.Binding + SrcSB.SBIndex ); } } -- cgit v1.2.3