Fixed static analysis errors in UBO code 77/294777/1
authorDavid Steele <david.steele@samsung.com>
Mon, 26 Jun 2023 11:33:36 +0000 (12:33 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 26 Jun 2023 11:33:36 +0000 (12:33 +0100)
Change-Id: I8fc912c8f93999c7a07b43246af9174f3127538d

dali/internal/graphics/gles-impl/gles-context.cpp
dali/internal/graphics/gles-impl/gles-graphics-command-buffer.cpp
dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp

index 3f15dae3c5c80a57fa6923ab7d9d74408bb875ee..569fdfc1aa4de1578de4611a32072a4b2f4528e0 100644 (file)
@@ -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);
   }
 }
 
index e1e57af4a6f9e2864ee7b966821788063a410518..80eec77d77aafb87ab4b236153a8d539d34a7936 100644 (file)
@@ -267,17 +267,17 @@ void CommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBuffer
   // temporary static set of binding slots (thread local)
   static const auto MAX_UNIFORM_BUFFER_BINDINGS = 64; // TODO: this should be read from introspection
 
-  // TODO: could use vector?
-  static thread_local UniformBufferBindingDescriptor sTempBindings[MAX_UNIFORM_BUFFER_BINDINGS];
+  static const UniformBufferBindingDescriptor                     NULL_DESCRIPTOR{nullptr, 0, 0, 0, 0, false};
+  static thread_local std::vector<UniformBufferBindingDescriptor> 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::vector<Graphics::UniformBuffer
       if(glesBuffer->IsCPUAllocated()) // 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<Graphics::UniformBuffer
     auto size = sizeof(UniformBufferBindingDescriptor) * (maxBinding + 1);
     if(!(size % sizeof(intptr_t)))
     {
-      auto* srcPtr = reinterpret_cast<intptr_t*>(sTempBindings);
+      auto* srcPtr = reinterpret_cast<intptr_t*>(&sTempBindings[0]);
       auto* dstPtr = reinterpret_cast<intptr_t*>(destBindings.Ptr());
       for(auto i = 0u; i < size / sizeof(intptr_t); ++i)
       {
@@ -325,7 +326,7 @@ void CommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBuffer
     }
     else
     {
-      memcpy(destBindings.Ptr(), sTempBindings, size);
+      memcpy(destBindings.Ptr(), &sTempBindings[0], size);
     }
     bindCmd.uniformBufferBindings      = destBindings;
     bindCmd.uniformBufferBindingsCount = maxBinding + 1;
index fb83dc389c8b0efd2b175fa4e3fcc3b1cb1b2a4c..5300acec3a548822e1000782ee5213a0b7015fd4 100644 (file)
@@ -318,8 +318,6 @@ void Reflection::BuildUniformBlockReflection()
   auto activeUniformOffset     = getActiveUniformParams(GL_UNIFORM_OFFSET);
 
   // Extract only uniform blocks and collect data
-  std::string uniformName;
-
   // collect samplers into separate array
   std::vector<UniformInfo> 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;