From 83a3f9cc82dc0b04973dd2187766cf9b7fe6deac Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 7 Mar 2022 11:32:39 +0000 Subject: [PATCH] Removed old context test cases Synced with toolkit tests Change-Id: I67f21c445cb9b17972e8994bee558d0bd0836e58 --- automated-tests/src/dali/CMakeLists.txt | 1 - .../dali-test-suite-utils/test-gl-abstraction.h | 24 +++- .../dali-test-suite-utils/test-graphics-buffer.cpp | 104 ++++++++-------- .../test-graphics-program.cpp | 11 +- .../test-graphics-reflection.cpp | 137 +++++++++++++++++---- .../test-graphics-reflection.h | 34 ++++- automated-tests/src/dali/utc-Dali-Actor.cpp | 2 - automated-tests/src/dali/utc-Dali-Context.cpp | 120 ------------------ .../dali/utc-Dali-RotationGestureRecognizer.cpp | 4 +- 9 files changed, 220 insertions(+), 217 deletions(-) delete mode 100644 automated-tests/src/dali/utc-Dali-Context.cpp diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index cba77af..a6c8ac8 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -22,7 +22,6 @@ SET(TC_SOURCES utc-Dali-ConstraintFunction.cpp utc-Dali-Constraints.cpp utc-Dali-ConstraintSource.cpp - utc-Dali-Context.cpp utc-Dali-Core.cpp utc-Dali-CustomActor.cpp utc-Dali-Degree.cpp diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index aec9f5d..cc7fac4 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -2,7 +2,7 @@ #define TEST_GL_ABSTRACTION_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -913,8 +913,8 @@ public: if(it2 == uniformIDs.end()) { // Uniform not found, so add it... - uniformIDs[name] = mLastUniformIdUsed++; - return mLastUniformIdUsed; + uniformIDs[name] = ++mLastUniformIdUsed; + return uniformIDs[name]; } return it2->second; @@ -991,7 +991,23 @@ public: for(const auto& uniform : mCustomUniformData) { - GetUniformLocation(program, uniform.name.c_str()); + auto iter = uniform.name.find("["); + auto name = uniform.name; + if(iter != std::string::npos) + { + name = uniform.name.substr(0, iter); + auto arrayCount = std::stoi(uniform.name.substr(iter + 1)); + for(int i = 0; i < arrayCount; ++i) + { + std::stringstream nss; + nss << name << "[" << i << "]"; + GetUniformLocation(program, nss.str().c_str()); // Generate a GL loc per element + } + } + else + { + GetUniformLocation(program, name.c_str()); + } } } diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-buffer.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-buffer.cpp index 8f9b9fc..27f0dce 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-buffer.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-buffer.cpp @@ -82,65 +82,67 @@ GLenum TestGraphicsBuffer::GetTarget() void TestGraphicsBuffer::BindAsUniformBuffer(const TestGraphicsProgram* program, const Dali::UniformBufferBindingDescriptor& uboBinding) const { - auto* reflection = static_cast(&program->GetReflection()); - - Graphics::UniformBlockInfo uboInfo{}; - reflection->GetUniformBlock(0, uboInfo); + auto* reflection = static_cast(&program->GetReflection()); + const auto& uboInfo = reflection->GetTestUniformBlock(0u); auto offset = uboBinding.offset; auto* data = memory.data() + offset; for(const auto& member : uboInfo.members) { - auto type = reflection->GetMemberType(0, member.location); - switch(type) + uint32_t numElements = member.numElements > 0 ? member.numElements : 1; + + for(uint32_t i = 0; i < numElements; ++i) { - case Property::VECTOR4: - { - auto value = *reinterpret_cast(data + member.offset); - mGl.Uniform4f(member.location, value.x, value.y, value.z, value.w); - break; - } - case Property::VECTOR3: - { - auto value = *reinterpret_cast(data + member.offset); - mGl.Uniform3f(member.location, value.x, value.y, value.z); - break; - } - case Property::VECTOR2: - { - auto value = *reinterpret_cast(data + member.offset); - mGl.Uniform2f(member.location, value.x, value.y); - break; - } - case Property::FLOAT: - { - auto value = *reinterpret_cast(data + member.offset); - mGl.Uniform1f(member.location, value); - break; - } - case Property::INTEGER: - { - auto ptr = reinterpret_cast(data + member.offset); - auto value = *ptr; - mGl.Uniform1i(member.location, value); - break; - } - case Property::MATRIX: - { - auto value = reinterpret_cast(data + member.offset); - mGl.UniformMatrix4fv(member.location, 1, GL_FALSE, value); - break; - } - case Property::MATRIX3: - { - auto value = reinterpret_cast(data + member.offset); - mGl.UniformMatrix3fv(member.location, 1, GL_FALSE, value); - break; - } - default: + switch(member.type) { - fprintf(stderr, "\n%s type not found\n", member.name.c_str()); + case Property::VECTOR4: + { + auto value = *reinterpret_cast(data + member.offsets[i]); + mGl.Uniform4f(member.locations[i], value.x, value.y, value.z, value.w); + break; + } + case Property::VECTOR3: + { + auto value = *reinterpret_cast(data + member.offsets[i]); + mGl.Uniform3f(member.locations[i], value.x, value.y, value.z); + break; + } + case Property::VECTOR2: + { + auto value = *reinterpret_cast(data + member.offsets[i]); + mGl.Uniform2f(member.locations[i], value.x, value.y); + break; + } + case Property::FLOAT: + { + auto value = *reinterpret_cast(data + member.offsets[i]); + mGl.Uniform1f(member.locations[i], value); + break; + } + case Property::INTEGER: + { + auto ptr = reinterpret_cast(data + member.offsets[i]); + auto value = *ptr; + mGl.Uniform1i(member.locations[i], value); + break; + } + case Property::MATRIX: + { + auto value = reinterpret_cast(data + member.offsets[i]); + mGl.UniformMatrix4fv(member.locations[i], 1, GL_FALSE, value); + break; + } + case Property::MATRIX3: + { + auto value = reinterpret_cast(data + member.offsets[i]); + mGl.UniformMatrix3fv(member.locations[i], 1, GL_FALSE, value); + break; + } + default: + { + fprintf(stderr, "\n%s type not found\n", member.name.c_str()); + } } } } diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp index a994157..8f2e0c7 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -20,14 +20,15 @@ namespace Dali { TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector& customUniforms) : mGl(gl), + mId(gl.CreateProgram()), mCreateInfo(createInfo), - mReflection(gl, vertexFormats, createInfo, customUniforms) + mReflection(gl, mId, vertexFormats, createInfo, customUniforms) { - mId = mGl.CreateProgram(); - // Ensure active sampler uniforms are set mGl.SetCustomUniforms(customUniforms); - mGl.LinkProgram(mId); + + // Don't need to re-register uniforms in GL side - now done in creation of mReflection. + // Was previously done in mGl.LinkProgram(mId); } bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp index 6971b71..5b3da8c 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp @@ -53,9 +53,57 @@ static const std::vector UNIFORMS = // WARNING: IF YOU CHANGE THIS LIST, ALSO CHANGE mActiveUniforms IN test-gl-abstraction, Initialize }; + +/** + * Helper function that returns size of uniform datatypes based + * on property type. + */ +constexpr int GetSizeForType(Property::Type type) +{ + switch(type) + { + case Property::Type::BOOLEAN: + { + return sizeof(bool); + } + case Property::Type::FLOAT: + { + return sizeof(float); + } + case Property::Type::INTEGER: + { + return sizeof(int); + } + case Property::Type::VECTOR2: + { + return sizeof(Vector2); + } + case Property::Type::VECTOR3: + { + return sizeof(Vector3); + } + case Property::Type::VECTOR4: + { + return sizeof(Vector4); + } + case Property::Type::MATRIX3: + { + return sizeof(Matrix3); + } + case Property::Type::MATRIX: + { + return sizeof(Matrix); + } + default: + { + return 0; + } + }; } -TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms) +} // namespace + +TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms) : mGl(gl), mCustomUniforms(customUniforms) { @@ -78,34 +126,72 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property:: mDefaultUniformBlock.name = ""; mDefaultUniformBlock.members = {}; mDefaultUniformBlock.binding = 0; - mDefaultUniformBlock.size = 64 * (UNIFORMS.size() + mCustomUniforms.size()); mDefaultUniformBlock.descriptorSet = 0; mDefaultUniformBlock.members.clear(); - int loc = 0; + + 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.offset = loc * 64; - item.location = loc++; + 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) { fprintf(stderr, "\ncustom uniforms: %s\n", data.name.c_str()); mDefaultUniformBlock.members.emplace_back(); - auto& item = mDefaultUniformBlock.members.back(); - item.name = data.name; - item.binding = 0; - item.offset = loc * 64; - item.location = loc++; - item.bufferIndex = 0; - item.uniformClass = Graphics::UniformClass::UNIFORM; + auto& item = mDefaultUniformBlock.members.back(); + + auto iter = data.name.find("[", 0); + int numElements = 1; + if(iter != std::string::npos) + { + auto baseName = data.name.substr(0, iter); + iter++; + numElements = std::stoi(data.name.substr(iter)); + if(numElements == 0) + { + numElements = 1; + } + + item.name = baseName; + item.binding = 0; + item.bufferIndex = 0; + item.uniformClass = Graphics::UniformClass::UNIFORM; + item.type = data.type; + item.numElements = numElements; + + for(int i = 0; i < numElements; ++i) + { + std::stringstream elementNameStream; + elementNameStream << baseName << "[" << i << "]"; + + item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str())); + item.offsets.push_back(offset); + offset += GetSizeForType(data.type); + } + } + else + { + item.name = data.name; + item.binding = 0; + item.offsets.push_back(offset); + item.locations.push_back(gl.GetUniformLocation(programId, item.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); } @@ -159,9 +245,13 @@ uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const uint32_t TestGraphicsReflection::GetUniformBlockSize(uint32_t index) const { - // 64 bytes per uniform (64 = 4x4 matrix) - // TODO: fix if array will be used - return 64 * (UNIFORMS.size() + mCustomUniforms.size()); + if(index >= mUniformBlocks.size()) + { + return 0; + } + + const auto& block = mUniformBlocks[index]; + return block.size; } bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const @@ -185,8 +275,8 @@ bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::Uni out.members[i].name = memberUniform.name; out.members[i].binding = block.binding; out.members[i].uniformClass = Graphics::UniformClass::UNIFORM; - out.members[i].offset = memberUniform.offset; - out.members[i].location = memberUniform.location; + out.members[i].offset = memberUniform.offsets[0]; + out.members[i].location = memberUniform.locations[0]; } return true; @@ -230,7 +320,7 @@ uint32_t TestGraphicsReflection::GetUniformBlockMemberOffset(uint32_t blockIndex { if(blockIndex < mUniformBlocks.size() && memberLocation < mUniformBlocks[blockIndex].members.size()) { - return mUniformBlocks[blockIndex].members[memberLocation].offset; + return mUniformBlocks[blockIndex].members[memberLocation].offsets[0]; } else { @@ -254,9 +344,4 @@ Graphics::ShaderLanguage TestGraphicsReflection::GetLanguage() const return Graphics::ShaderLanguage::GLSL_3_1; } -Dali::Property::Type TestGraphicsReflection::GetMemberType(int blockIndex, int location) const -{ - return location < static_cast(UNIFORMS.size()) ? UNIFORMS[location].type : mCustomUniforms[location - UNIFORMS.size()].type; -} - } // namespace Dali diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h index 2147cae..e968bd5 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h @@ -2,7 +2,7 @@ #define DALI_TEST_GRAPHICS_REFLECTION_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -26,7 +26,7 @@ namespace Dali class TestGraphicsReflection : public Graphics::Reflection { public: - TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vertexFormats, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms); + TestGraphicsReflection(TestGlAbstraction& gl, uint32_t program_id, Property::Array& vertexFormats, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms); uint32_t GetVertexAttributeLocation(const std::string& name) const override; Dali::Graphics::VertexInputAttributeFormat GetVertexAttributeFormat(uint32_t location) const override; @@ -46,6 +46,27 @@ public: Graphics::ShaderLanguage GetLanguage() const override; public: // Test methods + struct TestUniformInfo + { + std::string name{""}; // baseName in the case of arrays + Graphics::UniformClass uniformClass{Graphics::UniformClass::UNDEFINED}; + uint32_t binding{0u}; + uint32_t bufferIndex{0u}; + std::vector offsets{}; + std::vector locations{}; + uint32_t numElements{0u}; // 0 elements means this isn't an array; 1 element means this is an array of size 1 + Property::Type type; + }; + + struct TestUniformBlockInfo + { + std::string name{""}; + uint32_t descriptorSet{0u}; + uint32_t binding{0u}; + uint32_t size{0u}; + std::vector members{}; + }; + void SetAttributes(std::vector locations) { mAttributes.clear(); @@ -56,14 +77,17 @@ public: // Test methods } } - Dali::Property::Type GetMemberType(int blockIndex, int location) const; + const TestUniformBlockInfo& GetTestUniformBlock(uint32_t index) const + { + return mUniformBlocks[index]; + } TestGlAbstraction& mGl; mutable std::vector mAttributes; std::vector mCustomUniforms; - Graphics::UniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms - std::vector mUniformBlocks{}; ///< List of uniform blocks + TestUniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms + std::vector mUniformBlocks{}; ///< List of uniform blocks }; } // namespace Dali diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 05b5732..198fa00 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -4945,8 +4945,6 @@ int UtcDaliActorPropertyClippingActorWithRendererOverride(void) // Check stencil functions are not called. DALI_TEST_CHECK(!stencilTrace.FindMethod("StencilFunc")); - // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back. - // DALI_TEST_CHECK(!stencilTrace.FindMethod("StencilMask")); DALI_TEST_CHECK(!stencilTrace.FindMethod("StencilOp")); // Check that scissor clipping is overriden by the renderer properties. diff --git a/automated-tests/src/dali/utc-Dali-Context.cpp b/automated-tests/src/dali/utc-Dali-Context.cpp deleted file mode 100644 index a5e20a9..0000000 --- a/automated-tests/src/dali/utc-Dali-Context.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include - -using namespace Dali; - -namespace -{ -// Size of the VertexAttributeArray enables -// GLES specification states that there's a minimum of 8 -const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8; - -enum TestAttribType -{ - ATTRIB_UNKNOWN = -1, - ATTRIB_POSITION, - ATTRIB_NORMAL, - ATTRIB_TEXCOORD, - ATTRIB_COLOR, - ATTRIB_BONE_WEIGHTS, - ATTRIB_BONE_INDICES, - ATTRIB_TYPE_LAST -}; - -// Create bitmap actor -static Actor CreateBitmapActor() -{ - Actor actor = CreateRenderableActor(); - actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); - actor.SetProperty(Actor::Property::NAME, "Test Image Rendering Actor"); - return actor; -} - -} // anonymous namespace - -// Positive test case for a method -int UtcDaliContextVertexAttribStartup(void) -{ - tet_infoline("Testing vertex attrib initial state in context"); - - TestApplication application; - - // start up - application.SendNotification(); - application.Render(); - application.Render(); - - // check the locations - for(unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++) - { - DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayState(i) == false); - } - - tet_result(TET_PASS); - END_TEST; -} - -// Tests to make the attribs only get set once when continually rendering an image actor -int UtcDaliContextVertexAttribImageRendering(void) -{ - tet_infoline("Testing vertex attrib rendering state in context with images"); - - TestApplication application; - - // start up - application.SendNotification(); - application.Render(); - application.Render(); - - // the vertex attribs get modified on startup to set them to disabled - // clear the flag to say they've changed - application.GetGlAbstraction().ClearVertexAttribArrayChanged(); - - // create a test bitmap actor - Actor actor(CreateBitmapActor()); - application.GetScene().Add(actor); - - application.SendNotification(); - application.Render(); - application.Render(); - - // check to make sure the state has changed (the image renderer will enable some - // locations). - DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged()); - -#ifdef REMOVE_CACHE_TESTING_TEMPORARILY - // Now check to make sure the state is cached, and isn't being set each frame. - application.GetGlAbstraction().ClearVertexAttribArrayChanged(); - - application.Render(); - application.Render(); - application.Render(); - - // if it has changed then the caching has failed - DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false); - - //tet_result(TET_PASS); -#endif - - END_TEST; -} diff --git a/automated-tests/src/dali/utc-Dali-RotationGestureRecognizer.cpp b/automated-tests/src/dali/utc-Dali-RotationGestureRecognizer.cpp index c8d07d0..1aa7101 100644 --- a/automated-tests/src/dali/utc-Dali-RotationGestureRecognizer.cpp +++ b/automated-tests/src/dali/utc-Dali-RotationGestureRecognizer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -179,8 +179,6 @@ int UtcDaliRotationGestureRecognizerBasicInterrupted(void) GestureReceivedFunctor functor(data); detector.DetectedSignal().Connect(&application, functor); - // application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 20.0f, 20.0f ), 150 ) ); - // application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 20.0f, 25.0f ), 151 ) ); application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(20.0f, 30.0f), 152)); application.SendNotification(); -- 2.7.4