Files
galibzon 169b8f3679 [ATOM-5441] Shader Builders May Fail When Multiple New Files Are Added (#3862)
* [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>
2021-09-15 07:50:14 -05:00

139 lines
4.1 KiB
CMake

#
# 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
#
#
if(NOT PAL_TRAIT_BUILD_HOST_TOOLS)
return()
endif()
ly_get_list_relative_pal_filename(pal_source_dir ${CMAKE_CURRENT_LIST_DIR}/Source/Platform/${PAL_PLATFORM_NAME})
ly_get_list_relative_pal_filename(common_source_dir ${CMAKE_CURRENT_LIST_DIR}/Source/Platform/Common)
include(${pal_source_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) #for PAL_TRAIT_BUILD_ATOM_ASSET_SHADER_SUPPORTED
if(NOT PAL_TRAIT_BUILD_ATOM_ASSET_SHADER_SUPPORTED)
# Create a stub
ly_add_target(
NAME Atom_Asset_Shader.Builders GEM_MODULE
NAMESPACE Gem
FILES_CMAKE
atom_asset_shader_builders_stub_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
)
return()
endif()
ly_add_target(
NAME Atom_Asset_Shader.Static STATIC
NAMESPACE Gem
FILES_CMAKE
atom_asset_shader_builders_files.cmake
${pal_source_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
PLATFORM_INCLUDE_FILES
${pal_source_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
${common_source_dir}/${PAL_TRAIT_COMPILER_ID}/atom_asset_shader_static_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
Source/Editor
${pal_source_dir}
COMPILE_DEFINITIONS
PRIVATE
NOT_USE_CRY_MEMORY_MANAGER
_SCL_SECURE_NO_WARNINGS
BUILD_DEPENDENCIES
PUBLIC
3rdParty::mcpp
AZ::AssetBuilderSDK
AZ::AtomCore
AZ::AzCore
AZ::AzFramework
AZ::AzFramework
AZ::AzToolsFramework
Gem::Atom_RHI.Edit
Gem::Atom_RPI.Edit
Gem::Atom_RPI.Public
)
set(builder_tools_include_files)
foreach(enabled_platform ${LY_PAL_TOOLS_ENABLED})
string(TOLOWER ${enabled_platform} enabled_platform_lowercase)
ly_get_list_relative_pal_filename(builder_tools_source_dir ${CMAKE_CURRENT_LIST_DIR}/Source/Platform/${enabled_platform})
list(APPEND builder_tools_include_files ${builder_tools_source_dir}/platform_builders_${enabled_platform_lowercase}.cmake)
endforeach()
ly_add_target(
NAME Atom_Asset_Shader.Builders GEM_MODULE
NAMESPACE Gem
FILES_CMAKE
atom_asset_shader_builders_shared_files.cmake
PLATFORM_INCLUDE_FILES
${pal_source_dir}/platform_builders_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
${builder_tools_include_files}
INCLUDE_DIRECTORIES
PRIVATE
Source
Source/Editor
BUILD_DEPENDENCIES
PRIVATE
3rdParty::mcpp
Gem::Atom_Asset_Shader.Static
Gem::Atom_RPI.Edit
RUNTIME_DEPENDENCIES
3rdParty::DirectXShaderCompilerDxc
3rdParty::SPIRVCross
3rdParty::azslc
)
# The Atom_Asset_Shader is a required gem for Builders in order to process the assets that come WITHOUT
# the Atom_Feature_Common required gem
ly_enable_gems(GEMS Atom_Asset_Shader)
################################################################################
# Tests
################################################################################
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
ly_add_target(
NAME Atom_Asset_Shader.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
NAMESPACE Gem
FILES_CMAKE
atom_asset_shader_builders_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
.
Source/Editor
Tests
BUILD_DEPENDENCIES
PRIVATE
AZ::AtomCore
AZ::AzTest
AZ::AzFramework
AZ::AzToolsFramework
Legacy::CryCommon
Gem::Atom_RPI.Public
Gem::Atom_RHI.Public
Gem::Atom_RPI.Edit
Gem::Atom_Asset_Shader.Static
)
ly_add_googletest(
NAME Gem::Atom_Asset_Shader.Tests
)
endif()