From: Adeel Kazmi Date: Mon, 13 May 2024 16:12:55 +0000 (+0100) Subject: (shader-generator) Only generate shaders if input shader has changed/added X-Git-Tag: dali_2.3.24~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F76%2F311076%2F2;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git (shader-generator) Only generate shaders if input shader has changed/added Change-Id: Ic165328a6e32876436220a2ebe3fe2356267e3cc --- diff --git a/automated-tests/src/dali-shader-generator/CMakeLists.txt b/automated-tests/src/dali-shader-generator/CMakeLists.txt index 30502d8..e3b52cd 100644 --- a/automated-tests/src/dali-shader-generator/CMakeLists.txt +++ b/automated-tests/src/dali-shader-generator/CMakeLists.txt @@ -110,25 +110,37 @@ ADD_CUSTOM_TARGET(test_invalid_indir ALL COMMAND ${SHADER_GENERATOR} ONE TWO > / ADD_CUSTOM_TARGET( test_check_built_in_created ALL - COMMAND ${SHADER_GENERATOR} . ${GENERATED_FOLDER} | grep builtin-shader | wc -l | grep 2 > /dev/null 2>&1 && echo "test_check_built_in_created Succeeded" + COMMAND rm -rf ${GENERATED_FOLDER}/check_built_in + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/check_built_in/generated | grep builtin-shader | wc -l | grep 2 > /dev/null 2>&1 && echo "test_check_built_in_created Succeeded" VERBATIM) ADD_CUSTOM_TARGET( test_check_built_in_not_created ALL - COMMAND ${SHADER_GENERATOR} --skip . ${GENERATED_FOLDER} | grep builtin-shader > /dev/null 2>&1 || echo "test_check_built_in_not_created Succeeded" + COMMAND rm -rf ${GENERATED_FOLDER}/skip_built_in + COMMAND ${SHADER_GENERATOR} --skip ${SHADER_FOLDER} ${GENERATED_FOLDER}/skip_built_in/generated | grep builtin-shader > /dev/null 2>&1 && exit 1 || echo "test_check_built_in_not_created Succeeded" VERBATIM) ADD_CUSTOM_TARGET( test_frag_correct ALL - COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER} | grep "SHADER_FRAGMENT_SHADER_FRAG" | grep "fragment-shader-frag.h" > /dev/null 2>&1 && echo "test_frag_correct Succeeded" + COMMAND rm -rf ${GENERATED_FOLDER}/frag_correct + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/frag_correct/generated | grep "SHADER_FRAGMENT_SHADER_FRAG" | grep "fragment-shader-frag.h" > /dev/null 2>&1 && echo "test_frag_correct Succeeded" VERBATIM) ADD_CUSTOM_TARGET( test_vert_correct ALL - COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER} | grep "SHADER_VERTEX_SHADER_VERT" | grep "vertex-shader-vert.h" > /dev/null 2>&1 && echo "test_vert_correct Succeeded" + COMMAND rm -rf ${GENERATED_FOLDER}/vert_correct + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/vert_correct/generated | grep "SHADER_VERTEX_SHADER_VERT" | grep "vertex-shader-vert.h" > /dev/null 2>&1 && echo "test_vert_correct Succeeded" VERBATIM) ADD_CUSTOM_TARGET( test_def_correct ALL - COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER} | grep "SHADER_SHADER_DEFINE_DEF" | grep "shader-define-def.h" > /dev/null 2>&1 && echo "test_def_correct Succeeded" + COMMAND rm -rf ${GENERATED_FOLDER}/def_correct + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/def_correct/generated | grep "SHADER_SHADER_DEFINE_DEF" | grep "shader-define-def.h" > /dev/null 2>&1 && echo "test_def_correct Succeeded" + VERBATIM) +ADD_CUSTOM_TARGET( + test_no_overwrite + ALL + COMMAND rm -rf ${GENERATED_FOLDER}/no_overwrite + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/no_overwrite/generated | grep "SHADER_SHADER_DEFINE_DEF" | grep "shader-define-def.h" > /dev/null 2>&1 + COMMAND ${SHADER_GENERATOR} ${SHADER_FOLDER} ${GENERATED_FOLDER}/no_overwrite/generated | grep "SHADER_SHADER_DEFINE_DEF" | grep "shader-define-def.h" > /dev/null 2>&1 && exit 1 || echo "test_no_overwrite Succeeded" VERBATIM) diff --git a/dali-toolkit/shader-generator/shader-generator.cpp b/dali-toolkit/shader-generator/shader-generator.cpp index 16cddcc..b841598 100644 --- a/dali-toolkit/shader-generator/shader-generator.cpp +++ b/dali-toolkit/shader-generator/shader-generator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * 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. @@ -287,6 +287,7 @@ int GenerateShaderSources(fs::path inDir, fs::path outDir, const bool generateBu cout << "====================================================================" << endl; BuiltInFilesGenerator generator(outDir); + bool shaderGenerated = false; for(auto& file : fs::directory_iterator(inDir)) { @@ -303,8 +304,19 @@ int GenerateShaderSources(fs::path inDir, fs::path outDir, const bool generateBu if(shaderFile.is_open()) { fs::path outFilePath(GetShaderOutputFilePath(outDir, filename)); - GenerateHeaderFile(shaderFile, shaderVariableName, outFilePath); generator.Add(std::move(shaderVariableName), outFilePath.filename().string()); + if(fs::exists(outFilePath)) + { + // Only overwrite if input file is newer than output file + fs::file_time_type inFileTime = fs::last_write_time(path); + fs::file_time_type outFileTime = fs::last_write_time(outFilePath); + if(outFileTime > inFileTime) + { + continue; + } + } + GenerateHeaderFile(shaderFile, shaderVariableName, outFilePath); + shaderGenerated = true; } break; } @@ -312,7 +324,7 @@ int GenerateShaderSources(fs::path inDir, fs::path outDir, const bool generateBu } } - if(generateBuiltInFiles) + if(generateBuiltInFiles && shaderGenerated) { generator.Generate(); }