Added DiffuseProbeGridClassification pass.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Type": "JsonSerialization",
|
||||
"Version": 1,
|
||||
"ClassName": "PassAsset",
|
||||
"ClassData": {
|
||||
"PassTemplate": {
|
||||
"Name": "DiffuseProbeGridClassificationPassTemplate",
|
||||
"PassClass": "DiffuseProbeGridClassificationPass"
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"Type": "JsonSerialization",
|
||||
"Version": 1,
|
||||
"ClassName": "PrecompiledShaderAssetSourceData",
|
||||
"ClassData":
|
||||
{
|
||||
"ShaderAssetFileName": "diffuseprobegridclassification.azshader",
|
||||
"PlatformIdentifiers":
|
||||
[
|
||||
"pc"
|
||||
],
|
||||
"ShaderResourceGroupAssets":
|
||||
[
|
||||
"diffuseprobegridclassification_passsrg.azsrg"
|
||||
],
|
||||
"RootShaderVariantAssets":
|
||||
[
|
||||
{
|
||||
"APIName": "dx12",
|
||||
"RootShaderVariantAssetFileName": "diffuseprobegridclassification_dx12_0.azshadervariant"
|
||||
},
|
||||
{
|
||||
"APIName": "vulkan",
|
||||
"RootShaderVariantAssetFileName": "diffuseprobegridclassification_vulkan_0.azshadervariant"
|
||||
},
|
||||
{
|
||||
"APIName": "null",
|
||||
"RootShaderVariantAssetFileName": "diffuseprobegridclassification_null_0.azshadervariant"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+8071
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
+182
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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 <DiffuseProbeGrid/DiffuseProbeGridClassificationPass.h>
|
||||
#include <Atom/RHI/Factory.h>
|
||||
#include <Atom/RHI/PipelineState.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 <Atom/RPI.Reflect/Pass/PassTemplate.h>
|
||||
#include <Atom/RPI.Public/View.h>
|
||||
#include <Atom/RPI.Public/Scene.h>
|
||||
#include <DiffuseProbeGrid/DiffuseProbeGridFeatureProcessor.h>
|
||||
#include <RayTracing/RayTracingFeatureProcessor.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
RPI::Ptr<DiffuseProbeGridClassificationPass> DiffuseProbeGridClassificationPass::Create(const RPI::PassDescriptor& descriptor)
|
||||
{
|
||||
RPI::Ptr<DiffuseProbeGridClassificationPass> pass = aznew DiffuseProbeGridClassificationPass(descriptor);
|
||||
return AZStd::move(pass);
|
||||
}
|
||||
|
||||
DiffuseProbeGridClassificationPass::DiffuseProbeGridClassificationPass(const RPI::PassDescriptor& descriptor)
|
||||
: RPI::RenderPass(descriptor)
|
||||
{
|
||||
LoadShader();
|
||||
}
|
||||
|
||||
void DiffuseProbeGridClassificationPass::LoadShader()
|
||||
{
|
||||
// load shader
|
||||
// Note: the shader may not be available on all platforms
|
||||
AZStd::string shaderFilePath = "Shaders/DiffuseGlobalIllumination/DiffuseProbeGridClassification.azshader";
|
||||
m_shader = RPI::LoadShader(shaderFilePath);
|
||||
if (m_shader == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// load pipeline state
|
||||
RHI::PipelineStateDescriptorForDispatch pipelineStateDescriptor;
|
||||
const auto& shaderVariant = m_shader->GetVariant(RPI::ShaderAsset::RootShaderVariantStableId);
|
||||
shaderVariant.ConfigurePipelineState(pipelineStateDescriptor);
|
||||
m_pipelineState = m_shader->AcquirePipelineState(pipelineStateDescriptor);
|
||||
|
||||
// load Pass Srg asset
|
||||
m_srgAsset = m_shader->FindShaderResourceGroupAsset(RPI::SrgBindingSlot::Pass);
|
||||
|
||||
// retrieve the number of threads per thread group from the shader
|
||||
const auto numThreads = m_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, "[DiffuseProbeClassificationPass '%s']: Shader '%s' contains invalid numthreads arguments.", GetPathName().GetCStr(), shaderFilePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_dispatchArgs.m_threadsPerGroupX = AZStd::any_cast<int>(args[0]);
|
||||
m_dispatchArgs.m_threadsPerGroupY = AZStd::any_cast<int>(args[1]);
|
||||
m_dispatchArgs.m_threadsPerGroupZ = AZStd::any_cast<int>(args[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void DiffuseProbeGridClassificationPass::FrameBeginInternal(FramePrepareParams params)
|
||||
{
|
||||
RPI::Scene* scene = m_pipeline->GetScene();
|
||||
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
||||
|
||||
if (!diffuseProbeGridFeatureProcessor || diffuseProbeGridFeatureProcessor->GetProbeGrids().empty())
|
||||
{
|
||||
// no diffuse probe grids
|
||||
return;
|
||||
}
|
||||
|
||||
RayTracingFeatureProcessor* rayTracingFeatureProcessor = scene->GetFeatureProcessor<RayTracingFeatureProcessor>();
|
||||
AZ_Assert(rayTracingFeatureProcessor, "DiffuseProbeGridClassificationPass requires the RayTracingFeatureProcessor");
|
||||
|
||||
if (!rayTracingFeatureProcessor->GetSubMeshCount())
|
||||
{
|
||||
// empty scene
|
||||
return;
|
||||
}
|
||||
|
||||
RenderPass::FrameBeginInternal(params);
|
||||
}
|
||||
|
||||
void DiffuseProbeGridClassificationPass::SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph)
|
||||
{
|
||||
RenderPass::SetupFrameGraphDependencies(frameGraph);
|
||||
|
||||
RPI::Scene* scene = m_pipeline->GetScene();
|
||||
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
||||
for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetProbeGrids())
|
||||
{
|
||||
// probe raytrace image
|
||||
{
|
||||
RHI::ImageScopeAttachmentDescriptor desc;
|
||||
desc.m_attachmentId = diffuseProbeGrid->GetRayTraceImageAttachmentId();
|
||||
desc.m_imageViewDescriptor = diffuseProbeGrid->GetRenderData()->m_probeRayTraceImageViewDescriptor;
|
||||
desc.m_loadStoreAction.m_loadAction = AZ::RHI::AttachmentLoadAction::Load;
|
||||
|
||||
frameGraph.UseShaderAttachment(desc, RHI::ScopeAttachmentAccess::ReadWrite);
|
||||
}
|
||||
|
||||
// probe classification image
|
||||
{
|
||||
RHI::ImageScopeAttachmentDescriptor desc;
|
||||
desc.m_attachmentId = diffuseProbeGrid->GetClassificationImageAttachmentId();
|
||||
desc.m_imageViewDescriptor = diffuseProbeGrid->GetRenderData()->m_probeClassificationImageViewDescriptor;
|
||||
desc.m_loadStoreAction.m_loadAction = AZ::RHI::AttachmentLoadAction::Load;
|
||||
|
||||
frameGraph.UseShaderAttachment(desc, RHI::ScopeAttachmentAccess::ReadWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiffuseProbeGridClassificationPass::CompileResources([[maybe_unused]] const RHI::FrameGraphCompileContext& context)
|
||||
{
|
||||
RPI::Scene* scene = m_pipeline->GetScene();
|
||||
DiffuseProbeGridFeatureProcessor* diffuseProbeGridFeatureProcessor = scene->GetFeatureProcessor<DiffuseProbeGridFeatureProcessor>();
|
||||
for (auto& diffuseProbeGrid : diffuseProbeGridFeatureProcessor->GetProbeGrids())
|
||||
{
|
||||
// the diffuse probe grid Srg must be updated in the Compile phase in order to successfully bind the ReadWrite shader inputs
|
||||
// (see ValidateSetImageView() in ShaderResourceGroupData.cpp)
|
||||
diffuseProbeGrid->UpdateClassificationSrg(m_srgAsset);
|
||||
diffuseProbeGrid->GetClassificationSrg()->Compile();
|
||||
}
|
||||
}
|
||||
|
||||
void DiffuseProbeGridClassificationPass::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->GetProbeGrids())
|
||||
{
|
||||
const RHI::ShaderResourceGroup* shaderResourceGroup = diffuseProbeGrid->GetClassificationSrg()->GetRHIShaderResourceGroup();
|
||||
commandList->SetShaderResourceGroupForDispatch(*shaderResourceGroup);
|
||||
|
||||
uint32_t probeCountX;
|
||||
uint32_t probeCountY;
|
||||
diffuseProbeGrid->GetTexture2DProbeCount(probeCountX, probeCountY);
|
||||
|
||||
RHI::DispatchItem dispatchItem;
|
||||
dispatchItem.m_arguments = m_dispatchArgs;
|
||||
dispatchItem.m_pipelineState = m_pipelineState;
|
||||
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsX = probeCountX;
|
||||
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsY = probeCountY;
|
||||
dispatchItem.m_arguments.m_direct.m_totalNumberOfThreadsZ = 1;
|
||||
|
||||
commandList->Submit(dispatchItem);
|
||||
}
|
||||
}
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
|
||||
#include <Atom/RHI/CommandList.h>
|
||||
#include <Atom/RHI/DrawItem.h>
|
||||
#include <Atom/RHI/ScopeProducer.h>
|
||||
#include <Atom/RHI.Reflect/ShaderResourceGroupLayoutDescriptor.h>
|
||||
#include <Atom/RPI.Public/Pass/ComputePass.h>
|
||||
#include <Atom/RPI.Public/Shader/Shader.h>
|
||||
#include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
|
||||
#include <Atom/RPI.Reflect/Pass/PassName.h>
|
||||
#include <Atom/RPI.Public/Image/AttachmentImage.h>
|
||||
#include <DiffuseProbeGrid/DiffuseProbeGrid.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
//! Compute shader that classifies probes as active or inactive in the diffuse probe grid.
|
||||
class DiffuseProbeGridClassificationPass final
|
||||
: public RPI::RenderPass
|
||||
{
|
||||
public:
|
||||
AZ_RPI_PASS(DiffuseProbeGridClassificationPass);
|
||||
|
||||
AZ_RTTI(AZ::Render::DiffuseProbeGridClassificationPass, "{98A6477A-F31C-4390-9BEB-9DB8E30BB281}", RPI::RenderPass);
|
||||
AZ_CLASS_ALLOCATOR(DiffuseProbeGridClassificationPass, SystemAllocator, 0);
|
||||
virtual ~DiffuseProbeGridClassificationPass() = default;
|
||||
|
||||
static RPI::Ptr<DiffuseProbeGridClassificationPass> Create(const RPI::PassDescriptor& descriptor);
|
||||
|
||||
private:
|
||||
DiffuseProbeGridClassificationPass(const RPI::PassDescriptor& descriptor);
|
||||
|
||||
void LoadShader();
|
||||
|
||||
// Pass overrides
|
||||
void FrameBeginInternal(FramePrepareParams params) override;
|
||||
|
||||
void SetupFrameGraphDependencies(RHI::FrameGraphInterface frameGraph) override;
|
||||
void CompileResources(const RHI::FrameGraphCompileContext& context) override;
|
||||
void BuildCommandListInternal(const RHI::FrameGraphExecuteContext& context) override;
|
||||
|
||||
// shader
|
||||
Data::Instance<RPI::Shader> m_shader;
|
||||
const RHI::PipelineState* m_pipelineState = nullptr;
|
||||
Data::Asset<RPI::ShaderResourceGroupAsset> m_srgAsset;
|
||||
RHI::DispatchDirect m_dispatchArgs;
|
||||
|
||||
// revision number of the ray tracing data when the shader table was built
|
||||
uint32_t m_rayTracingDataRevision = 0;
|
||||
};
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
Reference in New Issue
Block a user