From b30ac188a1e76825e564b3ea8dc3f7166902323c Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 26 Jun 2023 12:33:36 +0100 Subject: [PATCH] Fixed static analysis errors in UBO code Change-Id: I8fc912c8f93999c7a07b43246af9174f3127538d --- dali/internal/graphics/gles-impl/gles-context.cpp | 2 +- .../gles-impl/gles-graphics-command-buffer.cpp | 31 +++++++++++----------- .../gles-impl/gles-graphics-reflection.cpp | 10 +++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/dali/internal/graphics/gles-impl/gles-context.cpp b/dali/internal/graphics/gles-impl/gles-context.cpp index 3f15dae..569fdfc 100644 --- a/dali/internal/graphics/gles-impl/gles-context.cpp +++ b/dali/internal/graphics/gles-impl/gles-context.cpp @@ -718,7 +718,7 @@ void Context::ResolveGpuUniformBuffers() auto i = 0u; for(auto& binding : mImpl->mCurrentUBOBindings) { - gl.BindBufferRange(GL_UNIFORM_BUFFER, i++, binding.buffer->GetGLBuffer(), binding.offset, binding.dataSize); + gl.BindBufferRange(GL_UNIFORM_BUFFER, i++, binding.buffer->GetGLBuffer(), GLintptr(binding.offset), binding.dataSize); } } diff --git a/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp b/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp index e1e57af..80eec77 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp @@ -267,17 +267,17 @@ void CommandBuffer::BindUniformBuffers(const std::vector sTempBindings(MAX_UNIFORM_BUFFER_BINDINGS, NULL_DESCRIPTOR); // reset temp bindings - memset(sTempBindings, 0, sizeof(UniformBufferBindingDescriptor) * MAX_UNIFORM_BUFFER_BINDINGS); + std::fill_n(sTempBindings.begin(), MAX_UNIFORM_BUFFER_BINDINGS, NULL_DESCRIPTOR); - auto maxBinding = 0u; - bool hasBindings = false; + memset(&bindCmd.standaloneUniformsBufferBinding, 0, sizeof(UniformBufferBindingDescriptor)); // find max binding and standalone UBO - memset(&bindCmd.standaloneUniformsBufferBinding, 0, sizeof(UniformBufferBindingDescriptor)); + auto maxBinding = 0u; + bool hasBindings = false; for(const auto& binding : bindings) { if(binding.buffer) @@ -286,22 +286,23 @@ void CommandBuffer::BindUniformBuffers(const std::vectorIsCPUAllocated()) // standalone uniforms { bindCmd.standaloneUniformsBufferBinding.buffer = glesBuffer; - bindCmd.standaloneUniformsBufferBinding.offset = binding.offset; bindCmd.standaloneUniformsBufferBinding.binding = binding.binding; + bindCmd.standaloneUniformsBufferBinding.offset = binding.offset; bindCmd.standaloneUniformsBufferBinding.emulated = true; } else // Bind regular UBO { - auto& slot = sTempBindings[binding.binding]; + auto& slot = sTempBindings[binding.binding]; + slot.buffer = glesBuffer; - slot.offset = binding.offset; slot.binding = binding.binding; - slot.blockIndex = 0; - slot.binding = binding.binding; // implicitly + slot.offset = binding.offset; slot.dataSize = binding.dataSize; + slot.blockIndex = 0; slot.emulated = false; - maxBinding = std::max(maxBinding, binding.binding); - hasBindings = true; + + maxBinding = std::max(maxBinding, binding.binding); + hasBindings = true; } } } @@ -316,7 +317,7 @@ void CommandBuffer::BindUniformBuffers(const std::vector(sTempBindings); + auto* srcPtr = reinterpret_cast(&sTempBindings[0]); auto* dstPtr = reinterpret_cast(destBindings.Ptr()); for(auto i = 0u; i < size / sizeof(intptr_t); ++i) { @@ -325,7 +326,7 @@ void CommandBuffer::BindUniformBuffers(const std::vector samplers; @@ -333,7 +331,6 @@ void Reflection::BuildUniformBlockReflection() gl->GetActiveUniform(glProgram, i, maxUniformNameLength, &written, &elementCount, &type, name); auto location = gl->GetUniformLocation(glProgram, name); - uniformName = name; UniformInfo* uniformInfo{nullptr}; if(IsSampler(activeUniformType[i])) @@ -357,17 +354,20 @@ void Reflection::BuildUniformBlockReflection() uniformInfo->location = location; // location must be set later and sorted by offset uniformInfo->name = name; + // Strip off array index from name, use element count instead if(elementCount > 1) { - auto iter = std::string(uniformName).find('[', 0); + std::string uniformName = name; + auto iter = uniformName.find('[', 0); if(iter != std::string::npos) { - uniformInfo->name = std::string(name).substr(0, iter); + uniformInfo->name = uniformName.substr(0, iter); uniformInfo->elementCount = elementCount; } } } + delete[] name; // Sort by offset uint32_t blockIndex = 0; -- 2.7.4