Sending preprocessed code when fishing for samplers 98/319498/2
authorAdam Bialogonski <adam.b@samsung.com>
Thu, 24 Oct 2024 10:09:22 +0000 (11:09 +0100)
committerAdam Bialogonski <adam.b@samsung.com>
Thu, 24 Oct 2024 10:09:22 +0000 (11:09 +0100)
Change-Id: Ib3e93f244860308549791e1b5d1bc8c8a6f24464

dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp
dali/internal/graphics/gles-impl/gles-graphics-shader.cpp
dali/internal/graphics/gles-impl/gles-graphics-shader.h

index 1fb69a0befdc8ad6aa8abfc62f7d06f4930cfb6d..912a747014dd5cdb2fb5f7f02d3a8b1f726070a7 100644 (file)
@@ -123,14 +123,16 @@ std::string GetShaderSource(Dali::Graphics::ShaderState shaderState)
   std::vector<uint8_t> data;
   auto*                shader           = static_cast<const Dali::Graphics::GLES::Shader*>(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<char*>(&data[0]));
+  auto shaderImpl = shader->GetImplementation();
+  if(shaderImpl->HasPreprocessedCode())
+  {
+    return std::string{shaderImpl->GetPreprocessedCode()};
+  }
+  return {reinterpret_cast<char*>(&data[0]), shaderCreateInfo.sourceSize};
 }
 
-void ParseShaderSamplers(std::string shaderSource, std::vector<Dali::Graphics::UniformInfo>& uniformOpaques, int& samplerPosition, std::vector<int>& samplerPositions)
+void ParseShaderSamplers(const std::string& shaderSource, std::vector<Dali::Graphics::UniformInfo>& uniformOpaques, int& samplerPosition, std::vector<int>& samplerPositions)
 {
   if(!shaderSource.empty())
   {
index eb07d9ec59b5fe18c7282ea32649abb9d9476b5d..c54c7dfa2bae7891b6d27ac483e14d894f67bbfd 100644 (file)
@@ -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<char*>(mImpl->sourcePreprocessed.data())};
+}
+
 [[nodiscard]] EglGraphicsController& ShaderImpl::GetController() const
 {
   return mImpl->controller;
index 077fcbd3a591cd9d9851629501b55eefe2377c4e..f3a462ef500cad6e5dd5d8b4f5a08fcdb7b58894 100644 (file)
@@ -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