Add "Definitions" field to shader asset

Shaders can now specify a top-level field "Definitions" which
accepts an array of string values. Each string will be appended
to the set of preprocessor definitions defined globally and forwarded
to the MCPP preprocessor on shader build. The shader-reload soak test
was modified to accept a new shader to test this feature in the ASV.

Signed-off-by: Jeremy Ong <jcong@amazon.com>
monroegm-disable-blank-issue-2
Jeremy Ong 4 years ago
parent d6c419d630
commit 743ade1765

@ -82,7 +82,7 @@ namespace AZ
// Register Shader Asset Builder
AssetBuilderSDK::AssetBuilderDesc shaderAssetBuilderDescriptor;
shaderAssetBuilderDescriptor.m_name = "Shader Asset Builder";
shaderAssetBuilderDescriptor.m_version = 109; // Modify Metal shader platform to permit the precise keyword to fix depth bitwise mismatch between passes
shaderAssetBuilderDescriptor.m_version = 110; // Add "Definitions" field to shader asset to support convenient addition of preprocessor definitions
shaderAssetBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern( AZStd::string::format("*.%s", RPI::ShaderSourceData::Extension), AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
shaderAssetBuilderDescriptor.m_busId = azrtti_typeid<ShaderAssetBuilder>();
shaderAssetBuilderDescriptor.m_createJobFunction = AZStd::bind(&ShaderAssetBuilder::CreateJobs, &m_shaderAssetBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2);

@ -413,6 +413,9 @@ namespace AZ
// At this moment We have global build options that should be merged with the build options that are common
// to all the supervariants of this shader.
buildOptions.m_compilerArguments.Merge(shaderSourceData.m_compiler);
buildOptions.m_preprocessorSettings.m_predefinedMacros.insert(
buildOptions.m_preprocessorSettings.m_predefinedMacros.end(),
shaderSourceData.m_definitions.begin(), shaderSourceData.m_definitions.end());
for (RHI::ShaderPlatformInterface* shaderPlatformInterface : platformInterfaces)
{

@ -57,6 +57,7 @@ namespace AZ
};
AZStd::string m_source;
AZStd::vector<AZStd::string> m_definitions;
RHI::ShaderCompilerArguments m_compiler;
AZStd::string m_drawListName;

@ -21,13 +21,14 @@ namespace AZ
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
{
serializeContext->Class<ShaderSourceData>()
->Version(4)
->Version(5)
->Field("Source", &ShaderSourceData::m_source)
->Field("DrawList", &ShaderSourceData::m_drawListName)
->Field("DepthStencilState", &ShaderSourceData::m_depthStencilState)
->Field("RasterState", &ShaderSourceData::m_rasterState)
->Field("BlendState", &ShaderSourceData::m_blendState)
->Field("ProgramSettings", &ShaderSourceData::m_programSettings)
->Field("Definitions", &ShaderSourceData::m_definitions)
->Field("CompilerHints", &ShaderSourceData::m_compiler)
->Field("DisabledRHIBackends", &ShaderSourceData::m_disabledRhiBackends)
->Field("Supervariants", &ShaderSourceData::m_supervariants)

Loading…
Cancel
Save