From: dongsug.song Date: Mon, 6 Nov 2023 10:19:48 +0000 (+0900) Subject: [Tizen] Apply precompile shader X-Git-Tag: accepted/tizen/8.0/unified/20231108.165841~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01e04a9c57ebd3a34bd4119bd6aa1d6af4a11133;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Apply precompile shader This reverts commit f30450538042b36128f22e0c0197374dba1c22ea. Change-Id: Ie047cb483282c3245e965ff392084f8ceb3b5217 --- diff --git a/dali-toolkit/devel-api/visual-factory/visual-factory.cpp b/dali-toolkit/devel-api/visual-factory/visual-factory.cpp index 93dcb4b..368f8d5 100644 --- a/dali-toolkit/devel-api/visual-factory/visual-factory.cpp +++ b/dali-toolkit/devel-api/visual-factory/visual-factory.cpp @@ -116,6 +116,11 @@ void VisualFactory::DiscardVisual(Visual::Base visual) GetImplementation(*this).DiscardVisual(visual); } +void VisualFactory::UsePreCompiledShader() +{ + GetImplementation(*this).UsePreCompiledShader(); +} + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/visual-factory/visual-factory.h b/dali-toolkit/devel-api/visual-factory/visual-factory.h index 1b7d9b5..cc62c2b 100644 --- a/dali-toolkit/devel-api/visual-factory/visual-factory.h +++ b/dali-toolkit/devel-api/visual-factory/visual-factory.h @@ -133,6 +133,17 @@ public: */ void DiscardVisual(Visual::Base visual); + /** + * @brief Compile the visual shader in advance. Afterwards, + * when a visual using a new shader is requested, the pre-compiled shader is used. + * + * @note It is recommended that this method be called at the top of the application code. + * @note Using precompiled shaders is helpful when the application is complex and uses + * many different styles of visual options. On the other hand,if most visuals are the same + * and the application is simple, it may use memory unnecessarily or slow down the application launching speed. + */ + void UsePreCompiledShader(); + private: explicit DALI_INTERNAL VisualFactory(Internal::VisualFactory* impl); }; diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp index 9761015..9af065d 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp @@ -36,8 +36,48 @@ namespace const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); const int NATIVE_SHADER_TYPE_OFFSET = VisualFactoryCache::ShaderType::NATIVE_IMAGE_SHADER - VisualFactoryCache::ShaderType::IMAGE_SHADER; + } // unnamed namespace +static constexpr auto SHADER_TYPE_COUNT = 16u; + +const std::string_view VertexPredefines[SHADER_TYPE_COUNT]{ + "", // VisualFactoryCache::IMAGE_SHADER, + "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, + "#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE, + "#define IS_REQUIRED_ALPHA_MASKING\n", // VisualFactoryCache::IMAGE_SHADER_MASKING, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING, + "#define IS_REQUIRED_BORDERLINE\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING, + "", //VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB, + "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB, + "#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_TO_RGB, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_TO_RGB}; + "", //VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB, + "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB, + "#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_AND_RGB, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n" //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_AND_RGB}; +}; +const std::string_view FragmentPredefines[SHADER_TYPE_COUNT]{ + "", // VisualFactoryCache::IMAGE_SHADER, + "#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, + "#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE, + "#define IS_REQUIRED_ALPHA_MASKING\n", // VisualFactoryCache::IMAGE_SHADER_MASKING, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_MASKING, + "#define IS_REQUIRED_BORDERLINE\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_MASKING, + "#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n#define IS_REQUIRED_ALPHA_MASKING\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING, + "#define IS_REQUIRED_YUV_TO_RGB\n", //VisualFactoryCache::IMAGE_SHADER_YUV_TO_RGB, + "#define IS_REQUIRED_YUV_TO_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB, + "#define IS_REQUIRED_YUV_TO_RGB\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_TO_RGB, + "#define IS_REQUIRED_YUV_TO_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_TO_RGB}; + "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n", //VisualFactoryCache::IMAGE_SHADER_YUV_AND_RGB, + "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n", //VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB, + "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n#define IS_REQUIRED_BORDERLINE\n", //VisualFactoryCache::IMAGE_SHADER_BORDERLINE_YUV_AND_RGB, + "#define IS_REQUIRED_UNIFIED_YUV_AND_RGB\n#define IS_REQUIRED_ROUNDED_CORNER\n#define IS_REQUIRED_BORDERLINE\n" //VisualFactoryCache::IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_AND_RGB}; +}; + ImageVisualShaderFactory::ImageVisualShaderFactory() : mFragmentShaderNeedChange(ImageVisualShaderFeature::ChangeFragmentShader::UNDECIDED) { @@ -127,6 +167,26 @@ std::string_view ImageVisualShaderFactory::GetFragmentShaderSource() return gFragmentShaderNoAtlas; } +void ImageVisualShaderFactory::GetPrecompiledShader(RawShaderData& shaders) +{ + std::vector vertexPrefix; + std::vector fragmentPrefix; + shaders.shaderCount = 0; + int shaderCount = 0; + for(int i = 0; i < SHADER_TYPE_COUNT; ++i) + { + vertexPrefix.push_back(VertexPredefines[i]); + fragmentPrefix.push_back(FragmentPredefines[i]); + shaderCount++; + } + + shaders.vertexPrefix = vertexPrefix; + shaders.fragmentPrefix = fragmentPrefix; + shaders.vertexShader = SHADER_IMAGE_VISUAL_SHADER_VERT; + shaders.fragmentShader = SHADER_IMAGE_VISUAL_SHADER_FRAG; + shaders.shaderCount += shaderCount; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.h b/dali-toolkit/internal/visuals/image-visual-shader-factory.h index cf1c25b..5f1b061 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.h +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.h @@ -20,8 +20,8 @@ // EXTERNAL INCLUDES // INTERNAL INCLUDES -#include #include +#include #include namespace Dali @@ -30,7 +30,6 @@ namespace Toolkit { namespace Internal { - /** * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals */ @@ -67,6 +66,12 @@ public: */ std::string_view GetFragmentShaderSource(); + /** + * @brief Get the default shader source. + * @param[in] shaders shaderList for precompile + */ + void GetPrecompiledShader(RawShaderData& shaders); + protected: /** * Undefined copy constructor. diff --git a/dali-toolkit/internal/visuals/visual-factory-cache.h b/dali-toolkit/internal/visuals/visual-factory-cache.h index f1d9703..15824e9 100644 --- a/dali-toolkit/internal/visuals/visual-factory-cache.h +++ b/dali-toolkit/internal/visuals/visual-factory-cache.h @@ -19,6 +19,7 @@ // EXTERNAL INCLUDES #include +#include #include #include #include diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 7cc5119..07e1ec9 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -393,6 +393,20 @@ void VisualFactory::DiscardVisual(Toolkit::Visual::Base visual) RegisterDiscardCallback(); } +void VisualFactory::UsePreCompiledShader() +{ + if(mPrecompiledShaderRequested) + { + return; + } + mPrecompiledShaderRequested = true; + + RawShaderData rawShaderData; + Integration::ShaderPrecompiler::Get().Enable(); + GetImageVisualShaderFactory().GetPrecompiledShader(rawShaderData); + Integration::ShaderPrecompiler::Get().SavePrecomipleShaderList(rawShaderData); +} + Internal::TextureManager& VisualFactory::GetTextureManager() { return GetFactoryCache().GetTextureManager(); @@ -431,6 +445,9 @@ Internal::VisualFactoryCache& VisualFactory::GetFactoryCache() } SetBrokenImageUrl(styleManager); } + + //UsePreCompiledShader(); // Call forcelly + return *mFactoryCache; } diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.h b/dali-toolkit/internal/visuals/visual-factory-impl.h index c0b95b4..04dce97 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.h +++ b/dali-toolkit/internal/visuals/visual-factory-impl.h @@ -18,6 +18,7 @@ */ // EXTERNAL INCLUDES +#include #include #include @@ -91,6 +92,11 @@ public: void DiscardVisual(Toolkit::Visual::Base visual); /** + * @copydoc Toolkit::VisualFactory::UsePreCompiledShader() + */ + void UsePreCompiledShader(); + + /** * @return the reference to texture manager */ Internal::TextureManager& GetTextureManager(); @@ -149,6 +155,7 @@ private: bool mDebugEnabled : 1; bool mPreMultiplyOnLoad : 1; ///< Local store for this flag + bool mPrecompiledShaderRequested{false}; }; /**