From: Eunki, Hong Date: Thu, 17 Apr 2025 05:58:46 +0000 (+0900) Subject: Ensure to call program.GetUniform() only 1 times even if we found failed. X-Git-Tag: dali_2.4.16~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f982fbe5310c3848554fdf6062ad2d38722f20e;p=platform%2Fcore%2Fuifw%2Fdali-core.git Ensure to call program.GetUniform() only 1 times even if we found failed. Until now, UniformIndexMap state mark as initialized = false if given unform not found at shader. In this case, we always try to re-search about given uniform name, which is useless. To avoid this case, let we make the uniform found result as enum, and so we can ensure that program.GetUniform only 1 time. Change-Id: I23a180980f556e3f05302622453258f87742344d Signed-off-by: Eunki, Hong --- diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 445d10da6..04e3a1951 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -967,50 +967,58 @@ void Renderer::FillUniformBuffer(Program& { auto& uniform = iter; - if(!uniform.initialized) + switch(uniform.state) { - auto uniformInfo = Graphics::UniformInfo{}; - auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(), - uniform.uniformNameHash, - uniform.uniformNameHashNoArray, - uniformInfo); - - if(!uniformFound) + case UniformIndexMap::State::INITIALIZE_REQUIRED: { - continue; - } + auto uniformInfo = Graphics::UniformInfo{}; + auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(), + uniform.uniformNameHash, + uniform.uniformNameHashNoArray, + uniformInfo); - uniform.uniformOffset = uniformInfo.offset; - uniform.uniformLocation = int16_t(uniformInfo.location); - uniform.uniformBlockIndex = uniformInfo.bufferIndex; - uniform.initialized = true; + if(!uniformFound) + { + uniform.state = UniformIndexMap::State::NOT_USED; + continue; + } - const auto typeSize = iter.propertyValue->GetValueSize(); - uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize; - uniform.matrixStride = uniformInfo.matrixStride; + uniform.uniformOffset = uniformInfo.offset; + uniform.uniformLocation = int16_t(uniformInfo.location); + uniform.uniformBlockIndex = uniformInfo.bufferIndex; - WriteDynUniform(iter.propertyValue, uniform, uboViews, updateBufferIndex); - } - else - { - WriteDynUniform(iter.propertyValue, uniform, uboViews, updateBufferIndex); + const auto typeSize = iter.propertyValue->GetValueSize(); + uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize; + uniform.matrixStride = uniformInfo.matrixStride; + + uniform.state = UniformIndexMap::State::INITIALIZED; + DALI_FALLTHROUGH; + } + case UniformIndexMap::State::INITIALIZED: + { + Render::UniformBufferView* ubo = uboViews[uniform.uniformBlockIndex].get(); + if(ubo == nullptr) // Uniform belongs to shared UniformBlock, can't overwrite + { + uniform.state = UniformIndexMap::State::NOT_USED; + continue; + } + WriteDynUniform(iter.propertyValue, uniform, *ubo, updateBufferIndex); + break; + } + default: + { + break; + } } } } void Renderer::WriteDynUniform( - const PropertyInputImpl* propertyValue, - UniformIndexMap& uniform, - const std::vector>& uboViews, - BufferIndex updateBufferIndex) + const PropertyInputImpl* propertyValue, + UniformIndexMap& uniform, + Render::UniformBufferView& ubo, + BufferIndex updateBufferIndex) { - UniformBufferView* ubo = uboViews[uniform.uniformBlockIndex].get(); - - if(ubo == nullptr) // Uniform belongs to shared UniformBlock, can't overwrite - { - return; - } - const auto dest = uniform.uniformOffset + uniform.arrayElementStride * uniform.arrayIndex; const auto valueAddress = propertyValue->GetValueAddress(updateBufferIndex); @@ -1023,15 +1031,15 @@ void Renderer::WriteDynUniform( const uint32_t matrixRow = (propertyValue->GetType() == Property::MATRIX3) ? 3 : 2; for(uint32_t i = 0; i < matrixRow; ++i) { - ubo->Write(reinterpret_cast(valueAddress) + i * matrixRow, - sizeof(float) * matrixRow, - dest + (i * uniform.matrixStride)); + ubo.Write(reinterpret_cast(valueAddress) + i * matrixRow, + sizeof(float) * matrixRow, + dest + (i * uniform.matrixStride)); } } else { const auto typeSize = propertyValue->GetValueSize(); - ubo->Write(valueAddress, typeSize, dest); + ubo.Write(valueAddress, typeSize, dest); } } diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index ce572b6b4..8336b816d 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -649,13 +649,13 @@ private: * * @param[in] propertyValue The property value to write * @param[in] uniform The map describing the uniform - * @param[in] uboViews Target uniform buffer object + * @param[in] ubo Target uniform buffer view * @param[in] updateBufferIndex update buffer index */ - void WriteDynUniform(const PropertyInputImpl* propertyValue, - UniformIndexMap& uniform, - const std::vector>& uboViews, - BufferIndex updateBufferIndex); + void WriteDynUniform(const PropertyInputImpl* propertyValue, + UniformIndexMap& uniform, + Render::UniformBufferView& ubo, + BufferIndex updateBufferIndex); private: Graphics::Controller* mGraphicsController; @@ -676,6 +676,12 @@ private: struct UniformIndexMap { + enum class State : uint8_t + { + INITIALIZE_REQUIRED, + INITIALIZED, + NOT_USED, + }; ConstString uniformName; ///< The uniform name const PropertyInputImpl* propertyValue{nullptr}; ///< The property value Hash uniformNameHash{0u}; @@ -687,7 +693,7 @@ private: int16_t uniformLocation{0u}; uint16_t uniformOffset{0u}; uint16_t uniformBlockIndex{0u}; - bool initialized{false}; + State state{State::INITIALIZE_REQUIRED}; }; StencilParameters mStencilParameters; ///< Struct containing all stencil related options diff --git a/dali/internal/render/renderers/render-uniform-block.cpp b/dali/internal/render/renderers/render-uniform-block.cpp index f592bd785..0610d29c4 100644 --- a/dali/internal/render/renderers/render-uniform-block.cpp +++ b/dali/internal/render/renderers/render-uniform-block.cpp @@ -57,33 +57,42 @@ void UniformBlock::WriteUniforms(BufferIndex renderBufferIndex, const Program& p { auto& uniform = iter; - if(!uniform.initialized) + switch(uniform.state) { - auto uniformInfo = Graphics::UniformInfo{}; - auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(), - uniform.uniformNameHash, - uniform.uniformNameHashNoArray, - uniformInfo); - - if(!uniformFound) + case UniformIndexMap::State::INITIALIZE_REQUIRED: { - continue; + auto uniformInfo = Graphics::UniformInfo{}; + auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(), + uniform.uniformNameHash, + uniform.uniformNameHashNoArray, + uniformInfo); + + if(!uniformFound) + { + uniform.state = UniformIndexMap::State::NOT_USED; + continue; + } + + uniform.uniformOffset = uniformInfo.offset; + uniform.uniformLocation = int16_t(uniformInfo.location); + uniform.uniformBlockIndex = uniformInfo.bufferIndex; + + const auto typeSize = iter.propertyValue->GetValueSize(); + uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize; + uniform.matrixStride = uniformInfo.matrixStride; + + uniform.state = UniformIndexMap::State::INITIALIZED; + DALI_FALLTHROUGH; + } + case UniformIndexMap::State::INITIALIZED: + { + WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex); + break; + } + default: + { + break; } - - uniform.uniformOffset = uniformInfo.offset; - uniform.uniformLocation = int16_t(uniformInfo.location); - uniform.uniformBlockIndex = uniformInfo.bufferIndex; - uniform.initialized = true; - - const auto typeSize = iter.propertyValue->GetValueSize(); - uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize; - uniform.matrixStride = uniformInfo.matrixStride; - - WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex); - } - else - { - WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex); } } } diff --git a/dali/internal/render/renderers/render-uniform-block.h b/dali/internal/render/renderers/render-uniform-block.h index 11c1d6802..fc996da7f 100644 --- a/dali/internal/render/renderers/render-uniform-block.h +++ b/dali/internal/render/renderers/render-uniform-block.h @@ -69,6 +69,12 @@ private: using Hash = std::size_t; struct UniformIndexMap { + enum class State : uint8_t + { + INITIALIZE_REQUIRED, + INITIALIZED, + NOT_USED, + }; ConstString uniformName; ///< The uniform name const PropertyInputImpl* propertyValue{nullptr}; ///< The property value Hash uniformNameHash{0u}; @@ -80,7 +86,7 @@ private: int16_t uniformLocation{0u}; uint16_t uniformOffset{0u}; uint16_t uniformBlockIndex{0u}; - bool initialized{false}; + State state{State::INITIALIZE_REQUIRED}; }; void WriteDynUniform(const PropertyInputImpl* propertyValue,