cc615a8f32
* [ATOM-15472] Shader Build Pipeline: Remove Deprecated Files And Functions That Predate The Shader Supervariants These are the essential impactful changes as a result of deprecating the ShaderResourceGroupAsset. * Addressed feedback by @moudgils. Better comments in header files. * More updates related with deprecation of ShaderResourceGroupAsset * Deleted the temporary version 2 classes. * Updated version of the shader asset builders. * Updated version of all the shader related classes impacted by the Supervariant concept and deprecation of ShaderResourceGroupAsset * Changes to *.pass and DGI, Reflections and RayTracing. * changes to material related assets * changes to core lights * Changes to auxgeom/dynamic draw. * changes to decals, lyshine, imguipass * changes to RPI Pass classes * Shader for SceneSrg, ViewSrg and ForwardPass Srgs. * changes to mesh, skinned mesh, Morphtarget. * Fixes to RayTracingPass.cpp & now allow empty srg in shaders. * Updated Atom_RPI.Tests * Simplified InstanceDatabase by removing AddHandler ------------------------------------------------------------------------------------ * Updated DiffuseGI precompiled shaders. Added RayTracingSceneSrg and RayTracingMaterialSrg shader asset. Updated ShaderAssetCreator::Clone to handle the supervariant when processing root variants. Co-authored-by: Doug McDiarmid <dmcdiar@amazon.com> ------------------------------------------------------------------------------------ * Changed semantics for some PassSrg to SRG_PerPass_WithFallback. AuxGeom/FixedShapeProcessor.cpp requires SRG_PerDraw on ObjectSrg. Removed names of SceneSrg and ViewSrg from RPISystemDescriptor.cpp * Moved ShaderLib/Atom/Features/DummyEntryFunctions.azsli To Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/DummyEntryFunctions.azsli Removed redundant checking for finalization in ShaderResourceGroupLayout.cpp * Fixed race condition bug for Shader::FindOrCreate. InstanceDatabase<>::CreateInstance() needs to be atomic for instance creation and initialization. Added optional InstanceHandler::CreateFunctionWithParams to accomodate to the needs of Instances that need more than an asset reference to be able to be created an initialzed. Removed ShaderResourceGroup::FindOrCreate() only ::Create is available now. * Renamed scene_and_view_srgs.* as SceneAndViewSrgs.* Changed GetAzslFileOfOrigin for GetUniqueId * Fixed unit tests. * Reverted the serialization name of m_uniqueId back to "m_azslFileOfOrigin" so precompiled shaders don't fail in layout comparison. * Fixed AtomCore.Tests Removed non-applicable test. InstanceDatabase.AddHandler() is not available anymore. * The Null rhi is re-enabled for shader compilation. Signed-off-by: garrieta <garrieta@amazon.com>
245 lines
12 KiB
C++
245 lines
12 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <Atom/RHI/Factory.h>
|
|
#include <Atom/RHI/FrameGraphInterface.h>
|
|
#include <Atom/RHI/FrameGraphAttachmentInterface.h>
|
|
#include <Atom/RHI/Device.h>
|
|
#include <Atom/RPI.Public/Pass/PassUtils.h>
|
|
#include <Atom/RPI.Public/RenderPipeline.h>
|
|
#include <Atom/RPI.Public/RPIUtils.h>
|
|
#include <DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessor.h>
|
|
#include <DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdatePass.h>
|
|
#include <RayTracing/RayTracingFeatureProcessor.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace Render
|
|
{
|
|
RPI::Ptr<DiffuseProbeGridBorderUpdatePass> DiffuseProbeGridBorderUpdatePass::Create(const RPI::PassDescriptor& descriptor)
|
|
{
|
|
RPI::Ptr<DiffuseProbeGridBorderUpdatePass> pass = aznew DiffuseProbeGridBorderUpdatePass(descriptor);
|
|
return AZStd::move(pass);
|
|
}
|
|
|
|
DiffuseProbeGridBorderUpdatePass::DiffuseProbeGridBorderUpdatePass(const RPI::PassDescriptor& descriptor)
|
|
: RPI::RenderPass(descriptor)
|
|
{
|
|
LoadShader("Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateRow.azshader",
|
|
m_rowShader,
|
|
m_rowPipelineState,
|
|
m_rowSrgLayout,
|
|
m_rowDispatchArgs);
|
|
|
|
LoadShader("Shaders/DiffuseGlobalIllumination/DiffuseProbeGridBorderUpdateColumn.azshader",
|
|
m_columnShader,
|
|
m_columnPipelineState,
|
|
m_columnSrgLayout,
|
|
m_columnDispatchArgs);
|
|
}
|
|
|
|
void DiffuseProbeGridBorderUpdatePass::LoadShader(AZStd::string shaderFilePath,
|
|
Data::Instance<RPI::Shader>& shader,
|
|
const RHI::PipelineState*& pipelineState,
|
|
RHI::Ptr<RHI::ShaderResourceGroupLayout>& srgLayout,
|
|
RHI::DispatchDirect& dispatchArgs)
|
|
{
|
|
// load shader
|
|
// Note: the shader may not be available on all platforms
|
|
shader = RPI::LoadShader(shaderFilePath);
|
|
if (shader == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// load pipeline state
|
|
RHI::PipelineStateDescriptorForDispatch pipelineStateDescriptor;
|
|
const auto& shaderVariant = shader->GetVariant(RPI::ShaderAsset::RootShaderVariantStableId);
|
|
shaderVariant.ConfigurePipelineState(pipelineStateDescriptor);
|
|
pipelineState = shader->AcquirePipelineState(pipelineStateDescriptor);
|
|
|
|
// load Pass Srg asset
|
|
srgLayout = shader->FindShaderResourceGroupLayout(RPI::SrgBindingSlot::Pass);
|
|
|
|
// retrieve the number of threads per thread group from the shader
|
|
const auto numThreads = shader->GetAsset()->GetAttribute(RHI::ShaderStage::Compute, Name{ "numthreads" });
|
|
if (numThreads)
|
|
{
|
|
const RHI::ShaderStageAttributeArguments& args = *numThreads;
|
|
bool validArgs = args.size() == 3;
|
|
if (validArgs)
|
|
{
|
|
validArgs &= args[0].type() == azrtti_typeid<int>();
|
|
validArgs &= args[1].type() == azrtti_typeid<int>();
|
|
validArgs &= args[2].type() == azrtti_typeid<int>();
|
|
}
|
|
|
|
if (!validArgs)
|
|
{
|
|
AZ_Error("PassSystem", false, "[DiffuseProbeGridBorderUpdatePass '%s']: Shader '%s' contains invalid numthreads arguments.", GetPathName().GetCStr(), shaderFilePath.c_str());
|
|
return;
|
|
}
|
|
|
|
dispatchArgs.m_threadsPerGroupX = AZStd::any_cast<int>(args[0]);
|
|
dispatchArgs.m_threadsPerGroupY = AZStd::any_cast<int>(args[1]);
|
|
dispatchArgs.m_threadsPerGroupZ = AZStd::any_cast<int>(args[2]);
|
|
}
|
|
}
|
|
|
|
void DiffuseProbeGridBorderUpdatePass::FrameBeginInternal(FramePrepareParams params)
|
|
{
|
|
RPI::Scene* scene = m_pipeline->GetScene();
|
|
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
|
|
|
if (!diffuseProbeGridFeatureProcessor || diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids().empty())
|
|
{
|
|
// no diffuse probe grids
|
|
return;
|
|
}
|
|
|
|
RayTracingFeatureProcessor* rayTracingFeatureProcessor = scene->GetFeatureProcessor<RayTracingFeatureProcessor>();
|
|
AZ_Assert(rayTracingFeatureProcessor, "DiffuseProbeGridBorderUpdatePass requires the RayTracingFeatureProcessor");
|
|
|
|
if (!rayTracingFeatureProcessor->GetSubMeshCount())
|
|
{
|
|
// empty scene
|
|
return;
|
|
}
|
|
|
|
RenderPass::FrameBeginInternal(params);
|
|
}
|
|
|
|
void DiffuseProbeGridBorderUpdatePass::SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph)
|
|
{
|
|
RenderPass::SetupFrameGraphDependencies(frameGraph);
|
|
|
|
RPI::Scene* scene = m_pipeline->GetScene();
|
|
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
|
for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids())
|
|
{
|
|
// probe irradiance image
|
|
{
|
|
RHI::ImageScopeAttachmentDescriptor desc;
|
|
desc.m_attachmentId = diffuseProbeGrid->GetIrradianceImageAttachmentId();
|
|
desc.m_imageViewDescriptor = diffuseProbeGrid->GetRenderData()->m_probeIrradianceImageViewDescriptor;
|
|
desc.m_loadStoreAction.m_loadAction = AZ::RHI::AttachmentLoadAction::Load;
|
|
|
|
frameGraph.UseShaderAttachment(desc, RHI::ScopeAttachmentAccess::ReadWrite);
|
|
}
|
|
|
|
// probe distance image
|
|
{
|
|
RHI::ImageScopeAttachmentDescriptor desc;
|
|
desc.m_attachmentId = diffuseProbeGrid->GetDistanceImageAttachmentId();
|
|
desc.m_imageViewDescriptor = diffuseProbeGrid->GetRenderData()->m_probeDistanceImageViewDescriptor;
|
|
desc.m_loadStoreAction.m_loadAction = AZ::RHI::AttachmentLoadAction::Load;
|
|
|
|
frameGraph.UseShaderAttachment(desc, RHI::ScopeAttachmentAccess::ReadWrite);
|
|
}
|
|
}
|
|
}
|
|
|
|
void DiffuseProbeGridBorderUpdatePass::CompileResources([[maybe_unused]] const RHI::FrameGraphCompileContext& context)
|
|
{
|
|
RPI::Scene* scene = m_pipeline->GetScene();
|
|
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
|
|
|
for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids())
|
|
{
|
|
// the diffuse probe grid Srg must be updated in the Compile phase in order to successfully bind the ReadWrite shader inputs
|
|
// (see line ValidateSetImageView() in ShaderResourceGroupData.cpp)
|
|
diffuseProbeGrid->UpdateBorderUpdateSrgs(m_rowShader, m_rowSrgLayout, m_columnShader, m_columnSrgLayout);
|
|
|
|
diffuseProbeGrid->GetBorderUpdateRowIrradianceSrg()->Compile();
|
|
diffuseProbeGrid->GetBorderUpdateColumnIrradianceSrg()->Compile();
|
|
diffuseProbeGrid->GetBorderUpdateRowDistanceSrg()->Compile();
|
|
diffuseProbeGrid->GetBorderUpdateColumnDistanceSrg()->Compile();
|
|
}
|
|
}
|
|
|
|
void DiffuseProbeGridBorderUpdatePass::BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context)
|
|
{
|
|
RHI::CommandList* commandList = context.GetCommandList();
|
|
RPI::Scene* scene = m_pipeline->GetScene();
|
|
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
|
|
|
// submit the DispatchItems for each DiffuseProbeGrid
|
|
for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetRealTimeProbeGrids())
|
|
{
|
|
uint32_t probeCountX;
|
|
uint32_t probeCountY;
|
|
diffuseProbeGrid->GetTexture2DProbeCount(probeCountX, probeCountY);
|
|
|
|
// row irradiance
|
|
{
|
|
const RHI::ShaderResourceGroup* shaderResourceGroup = diffuseProbeGrid->GetBorderUpdateRowIrradianceSrg()->GetRHIShaderResourceGroup();
|
|
commandList->SetShaderResourceGroupForDispatch(*shaderResourceGroup);
|
|
|
|
RHI::DispatchItem dispatchItem;
|
|
dispatchItem.m_arguments = m_rowDispatchArgs;
|
|
dispatchItem.m_pipelineState = m_rowPipelineState;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsX = probeCountX * (DiffuseProbeGrid::DefaultNumIrradianceTexels + 2);
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsY = probeCountY;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsZ = 1;
|
|
|
|
commandList->Submit(dispatchItem);
|
|
}
|
|
|
|
// column irradiance
|
|
{
|
|
const RHI::ShaderResourceGroup* shaderResourceGroup = diffuseProbeGrid->GetBorderUpdateColumnIrradianceSrg()->GetRHIShaderResourceGroup();
|
|
commandList->SetShaderResourceGroupForDispatch(*shaderResourceGroup);
|
|
|
|
RHI::DispatchItem dispatchItem;
|
|
dispatchItem.m_arguments = m_columnDispatchArgs;
|
|
dispatchItem.m_pipelineState = m_columnPipelineState;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsX = probeCountX;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsY = probeCountY * (DiffuseProbeGrid::DefaultNumIrradianceTexels + 2);
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsZ = 1;
|
|
|
|
commandList->Submit(dispatchItem);
|
|
}
|
|
|
|
// row distance
|
|
{
|
|
const RHI::ShaderResourceGroup* shaderResourceGroup = diffuseProbeGrid->GetBorderUpdateRowDistanceSrg()->GetRHIShaderResourceGroup();
|
|
commandList->SetShaderResourceGroupForDispatch(*shaderResourceGroup);
|
|
|
|
RHI::DispatchItem dispatchItem;
|
|
dispatchItem.m_arguments = m_rowDispatchArgs;
|
|
dispatchItem.m_pipelineState = m_rowPipelineState;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsX = probeCountX * (DiffuseProbeGrid::DefaultNumDistanceTexels + 2);
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsY = probeCountY;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsZ = 1;
|
|
|
|
commandList->Submit(dispatchItem);
|
|
}
|
|
|
|
// column distance
|
|
{
|
|
const RHI::ShaderResourceGroup* shaderResourceGroup = diffuseProbeGrid->GetBorderUpdateColumnDistanceSrg()->GetRHIShaderResourceGroup();
|
|
commandList->SetShaderResourceGroupForDispatch(*shaderResourceGroup);
|
|
|
|
RHI::DispatchItem dispatchItem;
|
|
dispatchItem.m_arguments = m_columnDispatchArgs;
|
|
dispatchItem.m_pipelineState = m_columnPipelineState;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsX = probeCountX;
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsY = probeCountY * (DiffuseProbeGrid::DefaultNumDistanceTexels + 2);
|
|
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsZ = 1;
|
|
|
|
commandList->Submit(dispatchItem);
|
|
}
|
|
}
|
|
}
|
|
} // namespace Render
|
|
} // namespace AZ
|