Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Gem/Code/Source/RHI/SubpassExampleComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace AtomSampleViewer
, m_depthStencilAttachmentId("depthAttachmentId")
{
m_supportRHISamplePipeline = true;
m_gbufferScopeId = AZ::RHI::ScopeId("GBufferScope");
m_compositionScopeId = AZ::RHI::ScopeId("CompositionScope");
}

void SubpassExampleComponent::Reflect(AZ::ReflectContext* context)
Expand Down Expand Up @@ -223,14 +225,14 @@ namespace AtomSampleViewer
// Build the render attachment layout with the 2 subpasses.
RHI::RenderAttachmentLayoutBuilder attachmentsBuilder;
// GBuffer Subpass
attachmentsBuilder.AddSubpass()
attachmentsBuilder.AddSubpass(&m_gbufferScopeId)
->RenderTargetAttachment(RHI::Format::R16G16B16A16_FLOAT, m_positionAttachmentId)
->RenderTargetAttachment(RHI::Format::R16G16B16A16_FLOAT, m_normalAttachmentId)
->RenderTargetAttachment(RHI::Format::R8G8B8A8_UNORM, m_albedoAttachmentId)
->RenderTargetAttachment(m_outputFormat, m_outputAttachmentId)
->DepthStencilAttachment(AZ::RHI::Format::D32_FLOAT, m_depthStencilAttachmentId);
// Composition Subpass
attachmentsBuilder.AddSubpass()
attachmentsBuilder.AddSubpass(&m_compositionScopeId)
->SubpassInputAttachment(m_positionAttachmentId, RHI::ImageAspectFlags::Color)
->SubpassInputAttachment(m_normalAttachmentId, RHI::ImageAspectFlags::Color)
->SubpassInputAttachment(m_albedoAttachmentId, RHI::ImageAspectFlags::Color)
Expand Down Expand Up @@ -341,6 +343,7 @@ namespace AtomSampleViewer
descriptor.m_attachmentId = m_positionAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
descriptor.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateVector4Float(0.f, 0.f, 0.f, 0.f);
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseColorAttachment(descriptor);
}

Expand All @@ -350,6 +353,7 @@ namespace AtomSampleViewer
descriptor.m_attachmentId = m_normalAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
descriptor.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateVector4Float(0.f, 0.f, 0.f, 0.f);
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseColorAttachment(descriptor);
}

Expand All @@ -359,6 +363,7 @@ namespace AtomSampleViewer
descriptor.m_attachmentId = m_albedoAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
descriptor.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateVector4Float(0.f, 0.f, 0.f, 0.f);
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseColorAttachment(descriptor);
}

Expand All @@ -367,6 +372,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor descriptor;
descriptor.m_attachmentId = m_outputAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseColorAttachment(descriptor);
}

Expand All @@ -376,6 +382,7 @@ namespace AtomSampleViewer
dsDesc.m_attachmentId = m_depthStencilAttachmentId;
dsDesc.m_loadStoreAction.m_clearValue = RHI::ClearValue::CreateDepthStencil(0, 0);
dsDesc.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Clear;
dsDesc.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Depth;
frameGraph.UseDepthStencilAttachment(dsDesc, RHI::ScopeAttachmentAccess::Write);
}

Expand Down Expand Up @@ -420,14 +427,13 @@ namespace AtomSampleViewer
}
};

const RHI::ScopeId forwardScope("GBufferScope");
m_scopeProducers.emplace_back(
aznew RHI::ScopeProducerFunction<
ScopeData,
decltype(prepareFunction),
decltype(compileFunction),
decltype(executeFunction)>(
forwardScope,
m_gbufferScopeId,
ScopeData{},
prepareFunction,
compileFunction,
Expand All @@ -447,6 +453,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor descriptor;
descriptor.m_attachmentId = m_positionAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseSubpassInputAttachment(descriptor);
}

Expand All @@ -455,6 +462,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor descriptor;
descriptor.m_attachmentId = m_normalAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseSubpassInputAttachment(descriptor);
}

Expand All @@ -463,6 +471,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor descriptor;
descriptor.m_attachmentId = m_albedoAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseSubpassInputAttachment(descriptor);
}

Expand All @@ -471,6 +480,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor descriptor;
descriptor.m_attachmentId = m_outputAttachmentId;
descriptor.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
descriptor.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Color;
frameGraph.UseColorAttachment(descriptor);
}

Expand All @@ -479,6 +489,7 @@ namespace AtomSampleViewer
RHI::ImageScopeAttachmentDescriptor dsDesc;
dsDesc.m_attachmentId = m_depthStencilAttachmentId;
dsDesc.m_loadStoreAction.m_loadAction = RHI::AttachmentLoadAction::Load;
dsDesc.m_imageViewDescriptor.m_aspectFlags = RHI::ImageAspectFlags::Depth;
frameGraph.UseDepthStencilAttachment(dsDesc, RHI::ScopeAttachmentAccess::Read);
}

Expand Down Expand Up @@ -531,14 +542,13 @@ namespace AtomSampleViewer
commandList->Submit(drawItem);
};

const RHI::ScopeId forwardScope("CompositionScope");
m_scopeProducers.emplace_back(
aznew RHI::ScopeProducerFunction<
ScopeData,
decltype(prepareFunction),
decltype(compileFunction),
decltype(executeFunction)>(
forwardScope,
m_compositionScopeId,
ScopeData{},
prepareFunction,
compileFunction,
Expand Down
3 changes: 3 additions & 0 deletions Gem/Code/Source/RHI/SubpassExampleComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,8 @@ namespace AtomSampleViewer
AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_compositionSubpassInputsSRG;
AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_viewShaderResourceGroup;
AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_compositionPipeline;

AZ::RHI::ScopeId m_gbufferScopeId;
AZ::RHI::ScopeId m_compositionScopeId;
};
} // namespace AtomSampleViewer