Add Integration code for Shader + Open GenerateTaggedShaderPrefix 93/318193/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 25 Sep 2024 10:27:45 +0000 (19:27 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 25 Sep 2024 10:33:05 +0000 (19:33 +0900)
Let we make integration-api for shader, so other dali repo could use
GenerateTaggedShaderPrefix function.

Change-Id: I06dc62f7f75c3c2c0a5d78251ad028741d4ab024
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-internal/utc-Dali-Internal-Shader.cpp
dali/integration-api/file.list
dali/integration-api/shader-integ.cpp [new file with mode: 0644]
dali/integration-api/shader-integ.h [new file with mode: 0644]
dali/internal/event/rendering/shader-impl.h

index 64fcd73318e5a423a6ec10b1a299298c5d3734d8..5f294a4d15f30ee3ed0026725ab7b848bfbceab1 100644 (file)
@@ -16,6 +16,7 @@
 */
 
 #include <dali-test-suite-utils.h>
+#include <dali/integration-api/shader-integ.h>
 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/effects/shader-factory.h>
@@ -97,6 +98,49 @@ int UtcDaliShaderWithPrefixTestVersion(void)
   END_TEST;
 }
 
+int UtcDaliShaderWithPrefixTestVersion2(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test same case of UtcDaliShaderWithPrefixTestVersion with integration api");
+
+  std::string vertexShader =
+    "//@version 100\n"
+    "some code\n";
+  std::string fragmentShader =
+    "//@version 101\n"
+    "some code\n";
+
+  // Get prefix from graphics config.
+  auto vertexPrefix   = application.GetGlAbstraction().GetVertexShaderPrefix();
+  auto fragmentPrefix = application.GetGlAbstraction().GetFragmentShaderPrefix();
+
+  // And use GenerateTaggedShaderPrefix from integration-api.
+  vertexPrefix   = Dali::Integration::GenerateTaggedShaderPrefix(vertexPrefix);
+  fragmentPrefix = Dali::Integration::GenerateTaggedShaderPrefix(fragmentPrefix);
+
+  Dali::Shader shader = Dali::Shader::New(
+    vertexPrefix + vertexShader,
+    fragmentPrefix + fragmentShader);
+
+  DALI_TEST_EQUALS(vertexPrefix.substr(0, 20), "//@legacy-prefix-end", TEST_LOCATION);
+  DALI_TEST_EQUALS(fragmentPrefix.substr(0, 20), "//@legacy-prefix-end", TEST_LOCATION);
+
+  // Test version number in the shader data
+  Dali::Internal::ThreadLocalStorage& tls           = Dali::Internal::ThreadLocalStorage::Get();
+  Dali::Internal::ShaderFactory&      shaderFactory = tls.GetShaderFactory();
+  size_t                              shaderHash;
+  Internal::ShaderDataPtr             shaderData = shaderFactory.Load(vertexShader, fragmentShader, {}, {}, "", shaderHash);
+
+  bool dataValid = (shaderData != nullptr);
+  DALI_TEST_EQUALS(dataValid, true, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(shaderData->GetVertexShaderVersion(), 100, TEST_LOCATION);
+  DALI_TEST_EQUALS(shaderData->GetFragmentShaderVersion(), 101, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliInternalShaderSaveAndLoad01(void)
 {
   TestApplication application;
index bf08a162bfe37aec44c466a13574c9def4d7d84e..d7feadfef7502374513d2e92339a9ab47eb7bb6f 100644 (file)
@@ -13,6 +13,7 @@ SET( platform_abstraction_src_files
    ${platform_abstraction_src_dir}/profiling.cpp
    ${platform_abstraction_src_dir}/render-task-list-integ.cpp
    ${platform_abstraction_src_dir}/scene.cpp
+   ${platform_abstraction_src_dir}/shader-integ.cpp
    ${platform_abstraction_src_dir}/testing.cpp
    ${platform_abstraction_src_dir}/texture-integ.cpp
    ${platform_abstraction_src_dir}/trace.cpp
@@ -53,6 +54,7 @@ SET( platform_abstraction_header_files
    ${platform_abstraction_src_dir}/resource-policies.h
    ${platform_abstraction_src_dir}/resource-types.h
    ${platform_abstraction_src_dir}/scene.h
+   ${platform_abstraction_src_dir}/shader-integ.h
    ${platform_abstraction_src_dir}/testing.h
    ${platform_abstraction_src_dir}/texture-integ.h
    ${platform_abstraction_src_dir}/trace.h
diff --git a/dali/integration-api/shader-integ.cpp b/dali/integration-api/shader-integ.cpp
new file mode 100644 (file)
index 0000000..4219395
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024 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.
+ *
+ */
+
+// FILE HEADER
+#include <dali/integration-api/shader-integ.h>
+
+// INTERNAL INCLUDES
+#include <dali/internal/event/rendering/shader-impl.h>
+
+namespace Dali::Integration
+{
+std::string GenerateTaggedShaderPrefix(const std::string& shaderPrefix)
+{
+  return Dali::Internal::Shader::GenerateTaggedShaderPrefix(shaderPrefix);
+}
+} // namespace Dali::Integration
diff --git a/dali/integration-api/shader-integ.h b/dali/integration-api/shader-integ.h
new file mode 100644 (file)
index 0000000..fea64a8
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef DALI_SHADER_INTEG_H
+#define DALI_SHADER_INTEG_H
+
+/*
+ * Copyright (c) 2024 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <string> // std::string
+
+// INTERNAL INCLUDES
+#include <dali/public-api/rendering/shader.h>
+
+namespace Dali::Integration
+{
+/**
+ * @brief Generates tag 'legacy-prefix-end' with end position of
+ * prefix text to make shader code parsing easier.
+ *
+ * @SINCE_2_3.43
+ * @return Generated string with tag.
+ */
+DALI_CORE_API std::string GenerateTaggedShaderPrefix(const std::string& shaderPrefix);
+
+} // namespace Dali::Integration
+
+#endif // DALI_SHADER_INTEG_H
index 0f597d1f7633848854710871940e78d24cbf3492..1b46fc234d7d947b1cee92e6092d6c47878f7e0c 100644 (file)
@@ -146,7 +146,7 @@ public:
   /**
    * Generates tag 'legacy-prefix-end' with end position of
    * prefix text to make shader code parsing easier.
-   * Function is public to be testable
+   * Function is public to be testable and integration api.
    */
   static std::string GenerateTaggedShaderPrefix(const std::string& shaderPrefix);
 };