From: sunghyun kim Date: Wed, 16 Apr 2025 08:17:25 +0000 (+0900) Subject: Add precompile-shader example X-Git-Tag: dali_2.4.16~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5348505fd9dbea684f4cb6cd2f6e7c556ffaa3f9;p=platform%2Fcore%2Fuifw%2Fdali-demo.git Add precompile-shader example Change-Id: I816b78750343f06680277e91e513babc1bb5c79c --- diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index f684d2e7d..5a1f35e4e 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -256,6 +256,9 @@ + + + diff --git a/examples/precompile-shader/README.md b/examples/precompile-shader/README.md new file mode 100644 index 000000000..7e2e84918 --- /dev/null +++ b/examples/precompile-shader/README.md @@ -0,0 +1,10 @@ +# Precompile Shader + +This is a test example for testing shader precompilation/file caching. +file caching can be enabled/disabled through environment variables, and precompiling refers to the code in the example. + +- Test precompile shader +- Test Shader File Caching + +Please update this note if you add some more test cases. +![](./precompile-shader.png) diff --git a/examples/precompile-shader/precompile-shader-example.cpp b/examples/precompile-shader/precompile-shader-example.cpp new file mode 100644 index 000000000..c3ec33d0e --- /dev/null +++ b/examples/precompile-shader/precompile-shader-example.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2025 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. + * + */ + +#include +#include + +// For Wait +#include +#include +#include + +using namespace Dali; +using Dali::Toolkit::TextLabel; + +const std::string_view SHADER_CUSTOM_VERT +{ +R"(attribute mediump vec2 aPosition; +uniform mediump mat4 uMvpMatrix; +uniform vec3 uSize; + +void main() +{ + gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0); +} +)" +}; + +const std::string_view SHADER_CUSTOM_FRAG +{ +R"(uniform lowp vec4 uColor; + +void main() +{ + gl_FragColor = vec4(0.0,0.0,0.0,1.0); +} +)" +}; + +using namespace Dali; +using namespace Dali::Toolkit; + +// This example shows how to create and display Hello World! using a simple TextActor +// +class PrecompileShaderController : public ConnectionTracker +{ +public: + PrecompileShaderController(Application& application) + : mApplication(application) + { + setenv("DALI_SHADER_USE_PROGRAM_BINARY", "1", 1); // Enable program binary + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &PrecompileShaderController::Create); + } + + ~PrecompileShaderController() = default; // Nothing to do in destructor + + // The Init signal is received once (only) during the Application lifetime + void Create(Application& application) + { + Property::Map imageShader; + imageShader["shaderType"] = "image"; + imageShader["shaderOption"] = Property::Map().Add("YUV_AND_RGB", true); + imageShader["shaderName"] = "IMAGE_SHADER_YUV_AND_RGB"; + + Property::Map imageShader2; + imageShader2["shaderType"] = "image"; + imageShader2["shaderOption"] = Property::Map() + .Add("ROUNDED_CORNER", true) + .Add("MASKING", true); + imageShader2["shaderName"] = ""; + + Property::Map textShader; + textShader["shaderType"] = "text"; + textShader["shaderOption"] = Property::Map() + .Add("MULTI_COLOR", true) + .Add("STYLES", true); + textShader["shaderName"] = ""; + + Property::Map colorShader; + colorShader["shaderType"] = "color"; + colorShader["shaderOption"] = Property::Map() + .Add("CUTOUT", true) + .Add("BORDERLINE", true); + colorShader["shaderName"] = "ColorBorderlineCutout"; + + + Property::Map customSHader; + customSHader["shaderType"] = "custom"; + customSHader["shaderName"] = "myShader"; + customSHader["vertexShader"] = SHADER_CUSTOM_VERT.data(); + customSHader["fragmentShader"] = SHADER_CUSTOM_FRAG.data(); + + Property::Map npatchShader; + npatchShader["shaderType"] = "npatch"; + npatchShader["xStretchCount"] = 4; + npatchShader["yStretchCount"] = 3; + + VisualFactory::Get().AddPrecompileShader(imageShader); + VisualFactory::Get().AddPrecompileShader(imageShader2); + VisualFactory::Get().AddPrecompileShader(textShader); + VisualFactory::Get().AddPrecompileShader(colorShader); + VisualFactory::Get().AddPrecompileShader(customSHader); + VisualFactory::Get().AddPrecompileShader(npatchShader); + VisualFactory::Get().UsePreCompiledShader(); + + // Get a handle to the window + Window window = application.GetWindow(); + window.SetBackgroundColor(Color::WHITE); + + TextLabel textLabel = TextLabel::New("Precomile Shader"); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + textLabel.SetProperty(Dali::Actor::Property::NAME, "Precompile Shader"); + window.Add(textLabel); + + // Need to wait forcelly for precompiling shaders + std::this_thread::sleep_for(std::chrono::seconds(3)); + } + +private: + Application& mApplication; +}; + +int DALI_EXPORT_API main(int argc, char** argv) +{ + Application application = Application::New(&argc, &argv); + PrecompileShaderController test(application); + application.MainLoop(); + return 0; +} diff --git a/examples/precompile-shader/precompile-shader.png b/examples/precompile-shader/precompile-shader.png new file mode 100755 index 000000000..06ecc6eda Binary files /dev/null and b/examples/precompile-shader/precompile-shader.png differ diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index 75db038f1..17f304350 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -214,6 +214,9 @@ msgstr "Pivot" msgid "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK" msgstr "Pre Render Callback" +msgid "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER" +msgstr "Precompile Shader" + msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" msgstr "Progress Bar" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index 9804df21a..56113ddb9 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -223,6 +223,9 @@ msgstr "Pivot" msgid "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK" msgstr "Pre Render Callback" +msgid "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER" +msgstr "Precompile Shader" + msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR" msgstr "Progress Bar" diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index c71151505..ada9d697d 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -113,6 +113,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") #define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT") #define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK") +#define DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER") #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") #define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION") @@ -244,6 +245,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_POPUP "Popup" #define DALI_DEMO_STR_TITLE_PIVOT "Pivot" #define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK "Pre Render Callback" +#define DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER "Precompile Shader" #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" #define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION "Property Notification" diff --git a/tests-reel/dali-tests-reel.cpp b/tests-reel/dali-tests-reel.cpp index 61f605c13..240cb8158 100644 --- a/tests-reel/dali-tests-reel.cpp +++ b/tests-reel/dali-tests-reel.cpp @@ -46,6 +46,7 @@ int DALI_EXPORT_API main(int argc, char** argv) demo.AddExample(Example("inherit-test.example", DALI_DEMO_STR_TITLE_INHERIT_TEST)); demo.AddExample(Example("image-view-yuv.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_YUV)); demo.AddExample(Example("pre-render-callback.example", DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK)); + demo.AddExample(Example("precompile-shader.example", DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER)); demo.AddExample(Example("perf-scroll.example", DALI_DEMO_STR_TITLE_PERF_SCROLL)); demo.AddExample(Example("perf-view-creation.example", DALI_DEMO_STR_TITLE_PERF_VIEW_CREATION)); demo.AddExample(Example("point-mesh.example", DALI_DEMO_STR_TITLE_POINT_MESH));