diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp index cc80b38b85..eae4e804e0 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp @@ -120,7 +120,7 @@ namespace AZ // Register Precompiled Shader Builder AssetBuilderSDK::AssetBuilderDesc precompiledShaderBuilderDescriptor; precompiledShaderBuilderDescriptor.m_name = "Precompiled Shader Builder"; - precompiledShaderBuilderDescriptor.m_version = 10; // ATOM-15472 + precompiledShaderBuilderDescriptor.m_version = 11; // ATOM-15740 precompiledShaderBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern(AZStd::string::format("*.%s", AZ::PrecompiledShaderBuilder::Extension), AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard)); precompiledShaderBuilderDescriptor.m_busId = azrtti_typeid(); precompiledShaderBuilderDescriptor.m_createJobFunction = AZStd::bind(&PrecompiledShaderBuilder::CreateJobs, &m_precompiledShaderBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2); diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp index 2abee4d297..05b4ff309b 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/PrecompiledShaderBuilder.cpp @@ -68,20 +68,23 @@ namespace AZ { AZStd::vector jobDependencyList; - // setup dependencies on the root azshadervariant asset file names - for (const auto& rootShaderVariantAsset : precompiledShaderAsset.m_rootShaderVariantAssets) + // setup dependencies on the root azshadervariant asset file names, for each supervariant + for (const auto& supervariant : precompiledShaderAsset.m_supervariants) { - AZStd::string rootShaderVariantAssetPath = RPI::AssetUtils::ResolvePathReference(request.m_sourceFile.c_str(), rootShaderVariantAsset->m_rootShaderVariantAssetFileName); - AssetBuilderSDK::SourceFileDependency sourceDependency; - sourceDependency.m_sourceFileDependencyPath = rootShaderVariantAssetPath; - response.m_sourceFileDependencyList.push_back(sourceDependency); + for (const auto& rootShaderVariantAsset : supervariant->m_rootShaderVariantAssets) + { + AZStd::string rootShaderVariantAssetPath = RPI::AssetUtils::ResolvePathReference(request.m_sourceFile.c_str(), rootShaderVariantAsset->m_rootShaderVariantAssetFileName); + AssetBuilderSDK::SourceFileDependency sourceDependency; + sourceDependency.m_sourceFileDependencyPath = rootShaderVariantAssetPath; + response.m_sourceFileDependencyList.push_back(sourceDependency); - AssetBuilderSDK::JobDependency jobDependency; - jobDependency.m_jobKey = "azshadervariant"; - jobDependency.m_platformIdentifier = platformInfo.m_identifier; - jobDependency.m_type = AssetBuilderSDK::JobDependencyType::Order; - jobDependency.m_sourceFile = sourceDependency; - jobDependencyList.push_back(jobDependency); + AssetBuilderSDK::JobDependency jobDependency; + jobDependency.m_jobKey = "azshadervariant"; + jobDependency.m_platformIdentifier = platformInfo.m_identifier; + jobDependency.m_type = AssetBuilderSDK::JobDependencyType::Order; + jobDependency.m_sourceFile = sourceDependency; + jobDependencyList.push_back(jobDependency); + } } AssetBuilderSDK::JobDescriptor job; @@ -137,33 +140,37 @@ namespace AZ AssetBuilderSDK::JobProduct jobProduct; - // load the variant product assets + // load the variant product assets, for each supervariant // these are the dependency root variant asset products that were processed prior to running this job - RPI::ShaderAssetCreator::ShaderRootVariantAssets rootVariantProductAssets; - for (AZStd::unique_ptr& rootShaderVariantAsset : precompiledShaderAsset.m_rootShaderVariantAssets) + RPI::ShaderAssetCreator::ShaderSupervariants supervariants; + for (const auto& supervariant : precompiledShaderAsset.m_supervariants) { - // retrieve the variant asset - auto assetOutcome = RPI::AssetUtils::LoadAsset(request.m_fullPath, rootShaderVariantAsset->m_rootShaderVariantAssetFileName, 0); - if (!assetOutcome) + RPI::ShaderAssetCreator::ShaderRootVariantAssets rootVariantProductAssets; + for (const auto& rootShaderVariantAsset : supervariant->m_rootShaderVariantAssets) { - AZ_Error(PrecompiledShaderBuilderName, false, "Failed to retrieve Variant asset for file [%s]", rootShaderVariantAsset->m_rootShaderVariantAssetFileName.c_str()); - return; + // retrieve the variant asset + auto assetOutcome = RPI::AssetUtils::LoadAsset(request.m_fullPath, rootShaderVariantAsset->m_rootShaderVariantAssetFileName, 0); + if (!assetOutcome) + { + AZ_Error(PrecompiledShaderBuilderName, false, "Failed to retrieve Variant asset for file [%s]", rootShaderVariantAsset->m_rootShaderVariantAssetFileName.c_str()); + return; + } + + rootVariantProductAssets.push_back(AZStd::make_pair(RHI::APIType{ rootShaderVariantAsset->m_apiName.GetCStr() }, assetOutcome.GetValue())); + + AssetBuilderSDK::ProductDependency productDependency; + productDependency.m_dependencyId = assetOutcome.GetValue().GetId(); + productDependency.m_flags = AZ::Data::ProductDependencyInfo::CreateFlags(AZ::Data::AssetLoadBehavior::PreLoad); + jobProduct.m_dependencies.push_back(productDependency); } - rootVariantProductAssets.push_back(AZStd::make_pair(RHI::APIType{ rootShaderVariantAsset->m_apiName.GetCStr() }, assetOutcome.GetValue())); - - AssetBuilderSDK::ProductDependency productDependency; - productDependency.m_dependencyId = assetOutcome.GetValue().GetId(); - productDependency.m_flags = AZ::Data::ProductDependencyInfo::CreateFlags(AZ::Data::AssetLoadBehavior::PreLoad); - jobProduct.m_dependencies.push_back(productDependency); + supervariants.push_back({ supervariant->m_name, rootVariantProductAssets }); } // use the ShaderAssetCreator to clone the shader asset, which will update the embedded Srg and Variant asset UUIDs // Note that the Srg and Variant assets do not have embedded asset references and are processed with the RC Copy functionality RPI::ShaderAssetCreator shaderAssetCreator; - shaderAssetCreator.Clone(Uuid::CreateRandom(), - *shaderAsset, - rootVariantProductAssets); + shaderAssetCreator.Clone(Uuid::CreateRandom(), *shaderAsset, supervariants); Data::Asset outputShaderAsset; if (!shaderAssetCreator.End(outputShaderAsset)) diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader index be1d87ff3e..81d6bde5f0 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendDistance.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridblenddistance.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridblenddistance_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader index 92fb12d5cc..9fa8e27461 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBlendIrradiance.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridblendirradiance.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridblendirradiance_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader index 8de77320f0..f2363bd5ee 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.precompiledshader @@ -5,23 +5,30 @@ "ClassData": { "ShaderAssetFileName": "diffuseprobegridborderupdatecolumn.azshader", - "PlatformIdentifiers": + "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdatecolumn_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader index 274dae91af..d87cc47a38 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.precompiledshader @@ -2,26 +2,31 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": - { + "ClassData": { "ShaderAssetFileName": "diffuseprobegridborderupdaterow.azshader", - "PlatformIdentifiers": - [ - "pc", "linux" + "PlatformIdentifiers": [ + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridborderupdaterow_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader index 85f75e6364..66671fd7bc 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.precompiledshader @@ -7,21 +7,28 @@ "ShaderAssetFileName": "diffuseprobegridclassification.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridclassification_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridclassification_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader index 88aa115b63..7b156ca7e5 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracing.precompiledshader @@ -2,27 +2,33 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracing.azshader", - "PlatformIdentifiers": - [ - "pc", "linux" + "PlatformIdentifiers": [ + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracing_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader index 948fc793ab..d19eb4baf1 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingClosestHit.precompiledshader @@ -2,27 +2,34 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracingclosesthit.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingclosesthit_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader index dec0e244b1..d30783db14 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRayTracingMiss.precompiledshader @@ -2,26 +2,33 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridraytracingmiss.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridraytracingmiss_null_0.azshadervariant" + } + ] } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader index e09a29a7e8..56b487ceb6 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRelocation.precompiledshader @@ -2,27 +2,34 @@ "Type": "JsonSerialization", "Version": 1, "ClassName": "PrecompiledShaderAssetSourceData", - "ClassData": + "ClassData": { "ShaderAssetFileName": "diffuseprobegridrelocation.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_null_0.azshadervariant" + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridrelocation_null_0.azshadervariant" + } + ] } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader index 279deaaa29..97c58091a2 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/DiffuseGlobalIllumination/DiffuseProbeGridRender.precompiledshader @@ -7,22 +7,29 @@ "ShaderAssetFileName": "diffuseprobegridrender.azshader", "PlatformIdentifiers": [ - "pc", "linux" + "pc", + "linux" ], - "RootShaderVariantAssets": + "Supervariants": [ { - "APIName": "dx12", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_dx12_0.azshadervariant" - }, - { - "APIName": "vulkan", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_vulkan_0.azshadervariant" - }, - { - "APIName": "null", - "RootShaderVariantAssetFileName": "diffuseprobegridrender_null_0.azshadervariant" - } + "Name": "", + "RootShaderVariantAssets": + [ + { + "APIName": "dx12", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_dx12_0.azshadervariant" + }, + { + "APIName": "vulkan", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_vulkan_0.azshadervariant" + }, + { + "APIName": "null", + "RootShaderVariantAssetFileName": "diffuseprobegridrender_null_0.azshadervariant" + } + ] + } ] } -} +} \ No newline at end of file diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h index ce5a4c8a7a..956367c126 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.h @@ -17,14 +17,14 @@ namespace AZ namespace RPI { - //! This asset contains is loaded from a Json file and contains information about + //! This asset is loaded from a Json file and contains information about //! precompiled shader variants and their associated API name. - struct RootShaderVariantAssetSourceData final + struct PrecompiledRootShaderVariantAssetSourceData final : public Data::AssetData { public: - AZ_RTTI(RootShaderVariantAssetSourceData, "{661EF8A7-7BAC-41B6-AD5C-C7249B2390AD}"); - AZ_CLASS_ALLOCATOR(RootShaderVariantAssetSourceData, SystemAllocator, 0); + AZ_RTTI(PrecompiledRootShaderVariantAssetSourceData, "{661EF8A7-7BAC-41B6-AD5C-C7249B2390AD}"); + AZ_CLASS_ALLOCATOR(PrecompiledRootShaderVariantAssetSourceData, SystemAllocator, 0); static void Reflect(ReflectContext* context); @@ -32,7 +32,22 @@ namespace AZ AZStd::string m_rootShaderVariantAssetFileName; }; - //! This asset contains is loaded from a Json file and contains information about + //! This asset is loaded from a Json file and contains information about + //! precompiled shader supervariants + struct PrecompiledSupervariantSourceData final + : public Data::AssetData + { + public: + AZ_RTTI(PrecompiledSupervariantSourceData, "{630BDF15-CE7C-4E2C-882E-4F7AF09C8BB6}"); + AZ_CLASS_ALLOCATOR(PrecompiledSupervariantSourceData, SystemAllocator, 0); + + static void Reflect(ReflectContext* context); + + AZ::Name m_name; + AZStd::vector> m_rootShaderVariantAssets; + }; + + //! This asset is loaded from a Json file and contains information about //! precompiled shader assets. struct PrecompiledShaderAssetSourceData final : public Data::AssetData @@ -45,7 +60,7 @@ namespace AZ AZStd::string m_shaderAssetFileName; AZStd::vector m_platformIdentifiers; - AZStd::vector> m_rootShaderVariantAssets; + AZStd::vector> m_supervariants; }; } // namespace RPI } // namespace AZ diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h index 22854a4559..d0c9729948 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderAssetCreator.h @@ -75,11 +75,20 @@ namespace AZ bool End(Data::Asset& shaderAsset); - //! Clones an existing ShaderAsset nd replaces the referenced Srg and Variant assets - using ShaderRootVariantAssets = AZStd::vector>>; + //! Clones an existing ShaderAsset and replaces the ShaderVariant assets + using ShaderRootVariantAssetPair = AZStd::pair>; + using ShaderRootVariantAssets = AZStd::vector; + + struct ShaderSupervariant + { + AZ::Name m_name; + ShaderRootVariantAssets m_rootVariantAssets; + }; + using ShaderSupervariants = AZStd::vector; + void Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, - const ShaderRootVariantAssets& rootVariantAssets); + const ShaderSupervariants& supervariants); private: diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp index a7a9344d6e..62fb904b37 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/PrecompiledShaderAssetSourceData.cpp @@ -14,29 +14,43 @@ namespace AZ { namespace RPI { - void RootShaderVariantAssetSourceData::Reflect(ReflectContext* context) + void PrecompiledRootShaderVariantAssetSourceData::Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { - serializeContext->Class() + serializeContext->Class() ->Version(0) - ->Field("APIName", &RootShaderVariantAssetSourceData::m_apiName) - ->Field("RootShaderVariantAssetFileName", &RootShaderVariantAssetSourceData::m_rootShaderVariantAssetFileName) + ->Field("APIName", &PrecompiledRootShaderVariantAssetSourceData::m_apiName) + ->Field("RootShaderVariantAssetFileName", &PrecompiledRootShaderVariantAssetSourceData::m_rootShaderVariantAssetFileName) + ; + } + } + + void PrecompiledSupervariantSourceData::Reflect(ReflectContext* context) + { + PrecompiledRootShaderVariantAssetSourceData::Reflect(context); + + if (auto* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("Name", &PrecompiledSupervariantSourceData::m_name) + ->Field("RootShaderVariantAssets", &PrecompiledSupervariantSourceData::m_rootShaderVariantAssets) ; } } void PrecompiledShaderAssetSourceData::Reflect(ReflectContext* context) { - RootShaderVariantAssetSourceData::Reflect(context); + PrecompiledSupervariantSourceData::Reflect(context); if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(1) // ATOM-15472 + ->Version(2) // ATOM-15740 ->Field("ShaderAssetFileName", &PrecompiledShaderAssetSourceData::m_shaderAssetFileName) ->Field("PlatformIdentifiers", &PrecompiledShaderAssetSourceData::m_platformIdentifiers) - ->Field("RootShaderVariantAssets", &PrecompiledShaderAssetSourceData::m_rootShaderVariantAssets) + ->Field("Supervariants", &PrecompiledShaderAssetSourceData::m_supervariants) ; } } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp index 5df37aa211..e56561b400 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Shader/ShaderAssetCreator.cpp @@ -382,7 +382,7 @@ namespace AZ return EndCommon(shaderAsset); } - void ShaderAssetCreator::Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, [[maybe_unused]] const ShaderRootVariantAssets& rootVariantAssets) + void ShaderAssetCreator::Clone(const Data::AssetId& assetId, const ShaderAsset& sourceShaderAsset, [[maybe_unused]] const ShaderSupervariants& supervariants) { BeginCommon(assetId); @@ -392,38 +392,60 @@ namespace AZ m_asset->m_shaderOptionGroupLayout = sourceShaderAsset.m_shaderOptionGroupLayout; m_asset->m_buildTimestamp = sourceShaderAsset.m_buildTimestamp; - // copy root variant assets + // copy the perAPIShaderData for (auto& perAPIShaderData : sourceShaderAsset.m_perAPIShaderData) { - // find the matching ShaderVariantAsset - AZ::Data::Asset foundVariantAsset; - for (const auto& variantAsset : rootVariantAssets) - { - if (variantAsset.first == perAPIShaderData.m_APIType) - { - foundVariantAsset = variantAsset.second; - break; - } - } - - if (!foundVariantAsset) - { - ReportWarning("Failed to find variant asset for API [%d]", perAPIShaderData.m_APIType); - } - - m_asset->m_perAPIShaderData.push_back(perAPIShaderData); - if (m_asset->m_perAPIShaderData.back().m_supervariants.empty()) + if (perAPIShaderData.m_supervariants.empty()) { ReportWarning("Attempting to clone a shader asset that has no supervariants for API [%d]", perAPIShaderData.m_APIType); + continue; } - else + + if (perAPIShaderData.m_supervariants.size() != supervariants.size()) { - // currently we only support one supervariant when cloning - // [GFX TODO][ATOM-15740] Support multiple supervariants in ShaderAssetCreator::Clone - m_asset->m_perAPIShaderData.back().m_supervariants[0].m_rootShaderVariantAsset = foundVariantAsset; + ReportError("Incorrect number of supervariants provided to ShaderAssetCreator::Clone"); + return; + } + + m_asset->m_perAPIShaderData.push_back(perAPIShaderData); + + // set the supervariants for this API + for (auto& supervariant : m_asset->m_perAPIShaderData.back().m_supervariants) + { + // find the matching Supervariant by name from the incoming list + ShaderSupervariants::const_iterator itFoundSuperVariant = AZStd::find_if( + supervariants.begin(), + supervariants.end(), + [&supervariant](const ShaderSupervariant& shaderSupervariant) + { + return supervariant.m_name == shaderSupervariant.m_name; + }); + + if (itFoundSuperVariant == supervariants.end()) + { + ReportError("Failed to find supervariant [%s]", supervariant.m_name.GetCStr()); + return; + } + + // find the matching ShaderVariantAsset for this API + ShaderRootVariantAssets::const_iterator itFoundRootShaderVariantAsset = AZStd::find_if( + itFoundSuperVariant->m_rootVariantAssets.begin(), + itFoundSuperVariant->m_rootVariantAssets.end(), + [&perAPIShaderData](const ShaderRootVariantAssetPair& rootShaderVariantAsset) + { + return perAPIShaderData.m_APIType == rootShaderVariantAsset.first; + }); + + if (itFoundRootShaderVariantAsset == itFoundSuperVariant->m_rootVariantAssets.end()) + { + ReportWarning("Failed to find root shader variant asset for API [%d] Supervariant [%s]", perAPIShaderData.m_APIType, supervariant.m_name.GetCStr()); + } + else + { + supervariant.m_rootShaderVariantAsset = itFoundRootShaderVariantAsset->second; + } } } - } } // namespace RPI } // namespace AZ