ATOM-15252 [Atom 0.8.5] Track View capture crashes when scene contains certain postfx

The crash was because the "BlendColorGradingLutImageAttachmentId" attachment got imported to attachment database twice.
This fix avoids import this attachment twice. It also avoid crash but only report a warning if an imported attachment wasn't used in any scope.
Enable both RHI and RPI validation (no visiable performance impact observed.
This commit is contained in:
qingtao
2021-04-16 09:47:03 -07:00
parent 020d7801bb
commit 8e34d784e6
4 changed files with 21 additions and 4 deletions
@@ -131,8 +131,13 @@ namespace AZ
AZ_Assert(m_blendedLut.m_lutImage != nullptr, "BlendColorGradingLutsPass unable to acquire LUT image");
AZ::RHI::AttachmentId imageAttachmentId = AZ::RHI::AttachmentId("BlendColorGradingLutImageAttachmentId");
[[maybe_unused]] RHI::ResultCode result = frameGraph.GetAttachmentDatabase().ImportImage(imageAttachmentId, m_blendedLut.m_lutImage);
AZ_Error("BlendColorGradingLutsPass", result == RHI::ResultCode::Success, "Failed to import compute buffer with error %d", result);
// import this attachment if it wasn't imported
if (!frameGraph.GetAttachmentDatabase().IsAttachmentValid(imageAttachmentId))
{
[[maybe_unused]] RHI::ResultCode result = frameGraph.GetAttachmentDatabase().ImportImage(imageAttachmentId, m_blendedLut.m_lutImage);
AZ_Error("BlendColorGradingLutsPass", result == RHI::ResultCode::Success, "Failed to import BlendColorGradingLutImageAttachmentId with error %d", result);
}
RHI::ImageScopeAttachmentDescriptor desc;
desc.m_attachmentId = imageAttachmentId;
@@ -16,6 +16,6 @@ namespace AZ
{
namespace RHI
{
bool Validation::s_isEnabled = BuildOptions::IsDebugBuild;
bool Validation::s_isEnabled = BuildOptions::IsDebugBuild || BuildOptions::IsProfileBuild;
}
}
@@ -404,6 +404,12 @@ namespace AZ
Buffer& buffer = static_cast<Buffer&>(*bufferFrameAttachment.GetBuffer());
RHI::BufferScopeAttachment* scopeAttachment = bufferFrameAttachment.GetFirstScopeAttachment();
if (scopeAttachment == nullptr)
{
AZ_WarningOnce("RHI", false, "Imported BufferFrameAttachment isn't used in any Scope");
return;
}
D3D12_RESOURCE_TRANSITION_BARRIER transition;
transition.pResource = buffer.GetMemoryView().GetMemory();
transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
@@ -471,6 +477,12 @@ namespace AZ
Image& image = static_cast<Image&>(*imageFrameAttachment.GetImage());
RHI::ImageScopeAttachment* scopeAttachment = imageFrameAttachment.GetFirstScopeAttachment();
if (scopeAttachment == nullptr)
{
AZ_WarningOnce("RHI", false, "Imported ImageFrameAttachment isn't used in any Scope");
return;
}
D3D12_RESOURCE_TRANSITION_BARRIER transition;
transition.pResource = image.GetMemoryView().GetMemory();
@@ -16,6 +16,6 @@ namespace AZ
{
namespace RPI
{
bool Validation::s_isEnabled = RHI::BuildOptions::IsDebugBuild;
bool Validation::s_isEnabled = RHI::BuildOptions::IsDebugBuild || RHI::BuildOptions::IsProfileBuild;
}
}