From 3eea41018889aaf2661098b8466c7e9445e7c069 Mon Sep 17 00:00:00 2001 From: Adam Bialogonski Date: Thu, 11 Jan 2024 11:03:59 +0000 Subject: [PATCH] Prevents writing array uniforms with out-of-bound indices and accidental overwrite of next uniform. Change-Id: I3a90c54759159b7ac3a448a4694caa7047765c40 --- .../test-graphics-reflection.cpp | 33 ++++++++++++---------- .../gles-impl/gles-graphics-reflection.cpp | 3 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp index 3998fde..22d09e1 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ namespace { static const std::vector UNIFORMS = { + UniformData("uColor", Property::Type::VECTOR4), UniformData("uRendererColor", Property::Type::FLOAT), UniformData("uCustom", Property::Type::INTEGER), UniformData("uCustom3", Property::Type::VECTOR3), @@ -47,7 +48,6 @@ static const std::vector UNIFORMS = UniformData("sTexture", Property::Type::FLOAT), UniformData("sTextureRect", Property::Type::FLOAT), UniformData("sGloss", Property::Type::FLOAT), - UniformData("uColor", Property::Type::VECTOR4), UniformData("uActorColor", Property::Type::VECTOR4), UniformData("uModelMatrix", Property::Type::MATRIX), UniformData("uModelView", Property::Type::MATRIX), @@ -140,19 +140,6 @@ TestGraphicsReflection::TestGraphicsReflection(TestGraphicsController& controlle mDefaultUniformBlock.members.clear(); int offset = 0; - for(const auto& data : UNIFORMS) - { - mDefaultUniformBlock.members.emplace_back(); - auto& item = mDefaultUniformBlock.members.back(); - item.name = data.name; - item.binding = 0; - item.offsets.push_back(offset); - item.locations.push_back(gl.GetUniformLocation(programId, data.name.c_str())); - item.bufferIndex = 0; - item.uniformClass = Graphics::UniformClass::UNIFORM; - item.type = data.type; - offset += GetSizeForType(data.type); - } for(const auto& data : mCustomUniforms) { @@ -233,6 +220,21 @@ TestGraphicsReflection::TestGraphicsReflection(TestGraphicsController& controlle offset += GetSizeForType(data.type); } } + + for(const auto& data : UNIFORMS) + { + mDefaultUniformBlock.members.emplace_back(); + auto& item = mDefaultUniformBlock.members.back(); + item.name = data.name; + item.binding = 0; + item.offsets.push_back(offset); + item.locations.push_back(gl.GetUniformLocation(programId, data.name.c_str())); + item.bufferIndex = 0; + item.uniformClass = Graphics::UniformClass::UNIFORM; + item.type = data.type; + offset += GetSizeForType(data.type); + } + mDefaultUniformBlock.size = offset; mUniformBlocks.push_back(mDefaultUniformBlock); @@ -329,6 +331,7 @@ bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::Uni out.members[i].uniformClass = Graphics::UniformClass::UNIFORM; out.members[i].offset = memberUniform.offsets[0]; out.members[i].location = memberUniform.locations[0]; + out.members[i].elementCount = memberUniform.numElements; } return true; diff --git a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp index 5300ace..27e2b3b 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -512,6 +512,7 @@ bool Reflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInf out.members[i].uniformClass = Graphics::UniformClass::UNIFORM; out.members[i].offset = memberUniform.offset; out.members[i].location = memberUniform.location; + out.members[i].elementCount = memberUniform.elementCount; } return true; -- 2.7.4