169b8f3679
* [ATOM-5441] Shader Builders May Fail When Multiple New Files Are Added ShaderAssetBuilder::CreateJobs now recursively parses *.azsl files looking for #include lines and builds the list of source dependencies using a depth-first algorithm. It was using MCPP before but not anymore (during CreateJobs). The new algorithm may over prescribe, but fixes the issues when multiple new shader related files are added, at once or out of order, to a game project or Gem. Overall the new ShaderAssetBuilder::CreateJobs() is around 40% faster and, of course, handles source dependencies in a robust way. * Added new test suite to AutomatedTesting project: Gem/PythonTests/atom_renderer/test_Atom_ShaderBuildPipelineSuite.py Bug fix to Gems/Atom/Asset/Shader/Code/Source/Editor/ShaderAssetBuilder.cpp discovered thanks to the automated test suite. The idea is that CreateJobs doesn't fail if the AZSL file doesn't exist. The failure is deferred during ProcessJob. This way if the AZSL file exists the .shader file is rebuilt automatically. * For testability purposes and avoid memory leakage errors during Unit Tests created the class ShaderBuilderUtility::IncludedFilesParser Now accepts "# include <file>" with space between '#' and 'include'. Also now accepts the '-' character inside the file path. Added Unit Test to validate all cases of "#include <file>" parsing. * Fixed linux runtime issues for Unit Tests in Atom_Asset_Shader.Tests Signed-off-by: garrieta <garrieta@amazon.com>
87 lines
3.1 KiB
C++
87 lines
3.1 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <AzTest/AzTest.h>
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
|
|
#include "Common/ShaderBuilderTestFixture.h"
|
|
|
|
#include <ShaderBuilderUtility.h>
|
|
|
|
namespace UnitTest
|
|
{
|
|
using namespace AZ;
|
|
|
|
// The main purpose of this class is to test ShaderBuilderUtility functions
|
|
class ShaderBuilderUtilityTests : public ShaderBuilderTestFixture
|
|
{
|
|
}; // class ShaderBuilderUtilityTests
|
|
|
|
|
|
TEST_F(ShaderBuilderUtilityTests, IncludedFilesParser_ParseStringAndGetIncludedFiles)
|
|
{
|
|
AZStd::string haystack(
|
|
"Some content to parse\n"
|
|
"#include <valid_file1.azsli>\n"
|
|
"// #include <valid_file2.azsli>\n"
|
|
"blah # include \"valid_file3.azsli\"\n"
|
|
"bar include <a\\dire-ctory\\invalid-file4.azsli>\n"
|
|
"foo # include \"a/directory/valid-file5.azsli\"\n"
|
|
"# include <a\\dire-ctory\\valid-file6.azsli>\n"
|
|
"#includ \"a\\dire-ctory\\invalid-file7.azsli\"\n"
|
|
);
|
|
|
|
AZ::ShaderBuilder::ShaderBuilderUtility::IncludedFilesParser includedFilesParser;
|
|
auto fileList = includedFilesParser.ParseStringAndGetIncludedFiles(haystack);
|
|
EXPECT_EQ(fileList.size(), 5);
|
|
|
|
auto it = AZStd::find(fileList.begin(), fileList.end(), "valid_file1.azsli");
|
|
EXPECT_TRUE(it != fileList.end());
|
|
|
|
it = AZStd::find(fileList.begin(), fileList.end(), "valid_file2.azsli");
|
|
EXPECT_TRUE(it != fileList.end());
|
|
|
|
it = AZStd::find(fileList.begin(), fileList.end(), "valid_file3.azsli");
|
|
EXPECT_TRUE(it != fileList.end());
|
|
|
|
// Remark: From now on We must normalize because internally AZ::ShaderBuilder::ShaderBuilderUtility::IncludedFilesParser
|
|
// always returns normalized paths.
|
|
{
|
|
AZStd::string fileName("a\\dire-ctory\\invalid-file4.azsli");
|
|
AzFramework::StringFunc::Path::Normalize(fileName);
|
|
it = AZStd::find(fileList.begin(), fileList.end(), fileName);
|
|
EXPECT_TRUE(it == fileList.end());
|
|
}
|
|
|
|
{
|
|
AZStd::string fileName("a\\directory\\valid-file5.azsli");
|
|
AzFramework::StringFunc::Path::Normalize(fileName);
|
|
it = AZStd::find(fileList.begin(), fileList.end(), fileName);
|
|
EXPECT_TRUE(it != fileList.end());
|
|
}
|
|
|
|
{
|
|
AZStd::string fileName("a\\dire-ctory\\valid-file6.azsli");
|
|
AzFramework::StringFunc::Path::Normalize(fileName);
|
|
it = AZStd::find(fileList.begin(), fileList.end(), fileName);
|
|
EXPECT_TRUE(it != fileList.end());
|
|
}
|
|
|
|
{
|
|
AZStd::string fileName("a\\dire-ctory\\invalid-file7.azsli");
|
|
AzFramework::StringFunc::Path::Normalize(fileName);
|
|
it = AZStd::find(fileList.begin(), fileList.end(), fileName);
|
|
EXPECT_TRUE(it == fileList.end());
|
|
}
|
|
}
|
|
|
|
} //namespace UnitTest
|
|
|
|
//AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
|
|
|