X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fshaders%2Fprogram.cpp;h=1b899feaee3354d9317ccad7fef0057e4ddcdcec;hb=df66eaa6145d1d1ec9c43f49b7595b9cb359d336;hp=fca497223924b86a747d265a97be765609398430;hpb=beccefce103877b896aef8c460d71aac3e7d0d3d;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index fca4972..1b899fe 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/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. @@ -117,6 +117,13 @@ void Program::BuildReflection(const Graphics::Reflection& graphicsReflection) // for each member store data for(const auto& item : uboInfo.members) { + // Add a hash for the whole name. + // + // If the name represents an array of basic types, it won't contain an index + // operator "[",NN,"]". + // + // If the name represents an element in an array of structs, it will contain an + // index operator, but should be hashed in full. auto hashValue = CalculateHash(item.name); mReflection.emplace_back(ReflectionUniformInfo{hashValue, false, item}); @@ -169,35 +176,51 @@ void Program::BuildReflection(const Graphics::Reflection& graphicsReflection) // Calculate size of memory for uniform blocks mUniformBlockRequirements.totalSizeRequired = 0; - mUniformBlockRequirements.blockCount = graphicsReflection.GetUniformBlockCount(); - for (auto i = 0u; i < mUniformBlockRequirements.blockCount; ++i) + mUniformBlockRequirements.blockCount = graphicsReflection.GetUniformBlockCount(); + for(auto i = 0u; i < mUniformBlockRequirements.blockCount; ++i) { auto blockSize = GetUniformBufferDataAlignment(graphicsReflection.GetUniformBlockSize(i)); mUniformBlockRequirements.totalSizeRequired += blockSize; } } -void Program::SetGraphicsProgram( Graphics::UniquePtr&& program ) +void Program::SetGraphicsProgram(Graphics::UniquePtr&& program) { mGfxProgram = std::move(program); BuildReflection(mGfxController.GetProgramReflection(*mGfxProgram.get())); } - -bool Program::GetUniform(const std::string& name, size_t hashedName, Graphics::UniformInfo& out) const +bool Program::GetUniform(const std::string& name, Hash hashedName, Hash hashedNameNoArray, Graphics::UniformInfo& out) const { if(mReflection.empty()) { return false; } + DALI_ASSERT_DEBUG(hashedName != 0 && "GetUniform() hash is not set"); + + // If name contains a "]", but has nothing after, it's an element in an array, + // The reflection doesn't contain such elements, it only contains the name without square brackets + // Use the hash without array subscript. + + // If the name contains a "]" anywhere but the end, it's a structure element. The reflection + // does contain such elements, so use normal hash. + Hash hash = hashedName; + const std::string* match = &name; - hashedName = !hashedName ? CalculateHash(name, '[') : hashedName; + std::string baseName; + if(!name.empty() && name.back() == ']') + { + hash = hashedNameNoArray; + auto pos = name.rfind("["); + baseName = name.substr(0, pos - 1); // Remove subscript + match = &baseName; + } for(const ReflectionUniformInfo& item : mReflection) { - if(item.hashValue == hashedName) + if(item.hashValue == hash) { - if(!item.hasCollision || item.uniformInfo.name == name) + if(!item.hasCollision || item.uniformInfo.name == *match) { out = item.uniformInfo; return true;