From 48475b675fd3015833f4b0292849459a8b7dac73 Mon Sep 17 00:00:00 2001 From: Adam Bialogonski Date: Thu, 24 Oct 2024 11:09:22 +0100 Subject: [PATCH] Sending preprocessed code when fishing for samplers Change-Id: Ib3e93f244860308549791e1b5d1bc8c8a6f24464 --- .../gles-impl/gles-graphics-reflection.cpp | 12 +++++++----- .../graphics/gles-impl/gles-graphics-shader.cpp | 10 ++++++++++ .../graphics/gles-impl/gles-graphics-shader.h | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp index 1fb69a0be..912a74701 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp @@ -123,14 +123,16 @@ std::string GetShaderSource(Dali::Graphics::ShaderState shaderState) std::vector data; auto* shader = static_cast(shaderState.shader); auto& shaderCreateInfo = shader->GetCreateInfo(); - data.resize(shaderCreateInfo.sourceSize + 1); - std::memcpy(&data[0], shaderCreateInfo.sourceData, shaderCreateInfo.sourceSize); - data[shaderCreateInfo.sourceSize] = 0; - return std::string(reinterpret_cast(&data[0])); + auto shaderImpl = shader->GetImplementation(); + if(shaderImpl->HasPreprocessedCode()) + { + return std::string{shaderImpl->GetPreprocessedCode()}; + } + return {reinterpret_cast(&data[0]), shaderCreateInfo.sourceSize}; } -void ParseShaderSamplers(std::string shaderSource, std::vector& uniformOpaques, int& samplerPosition, std::vector& samplerPositions) +void ParseShaderSamplers(const std::string& shaderSource, std::vector& uniformOpaques, int& samplerPosition, std::vector& samplerPositions) { if(!shaderSource.empty()) { diff --git a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp index eb07d9ec5..c54c7dfa2 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp @@ -235,6 +235,16 @@ const ShaderCreateInfo& ShaderImpl::GetCreateInfo() const return mImpl->createInfo; } +bool ShaderImpl::HasPreprocessedCode() const +{ + return !mImpl->sourcePreprocessed.empty(); +} + +std::string_view ShaderImpl::GetPreprocessedCode() const +{ + return {reinterpret_cast(mImpl->sourcePreprocessed.data())}; +} + [[nodiscard]] EglGraphicsController& ShaderImpl::GetController() const { return mImpl->controller; diff --git a/dali/internal/graphics/gles-impl/gles-graphics-shader.h b/dali/internal/graphics/gles-impl/gles-graphics-shader.h index 077fcbd3a..f3a462ef5 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-shader.h +++ b/dali/internal/graphics/gles-impl/gles-graphics-shader.h @@ -120,6 +120,22 @@ public: */ void SetPreprocessedCode(void* data, uint32_t size); + /** + * @brief Returns preprocessed code + * + * @note Use HasPreprocessedCode() first before using this function. + * + * @return the string_view to the preprocessed code + */ + [[nodiscard]] std::string_view GetPreprocessedCode() const; + + /** + * @brief Checks whether preprocessed code is available + * + * @return true if there is a preprocessed code + */ + [[nodiscard]] bool HasPreprocessedCode() const; + /** * @brief Returns GLSL version * @return Returns valid GLSL version or 0 if undefined -- 2.34.1