Fix SSR Reflections on Mac amongst other things (#1618)

Fix writing to the correct mip in Metal
Set default m_outputScale to 1 in order to fix a 1/0 error
Add support for logging/printing errors pertaining to GPU crashes.
Setting Release queue's collection latency to MaxFrames.
Fix managed mem synchronization related offset bug
This commit is contained in:
moudgils
2021-06-28 17:57:06 -07:00
committed by GitHub
parent 9dc961ec35
commit 7780b83fdc
7 changed files with 53 additions and 5 deletions
@@ -51,7 +51,7 @@ namespace AZ
PassType m_passType;
uint32_t m_mipLevel = 0;
RHI::Size m_imageSize;
float m_outputScale = 0.0f;
float m_outputScale = 1.0f;
};
} // namespace RPI
} // namespace AZ
@@ -144,6 +144,7 @@ namespace Platform
}
mappedData += request.m_byteOffset;
response.m_data = mappedData;
buffer.SetMapRequestOffset(request.m_byteOffset);
break;
}
default:
@@ -159,6 +160,8 @@ namespace Platform
{
AZ::Metal::Buffer& buffer = static_cast<AZ::Metal::Buffer&>(bufferBase);
//Ony need to handle MTLStorageModeManaged memory.
SynchronizeBufferOnCPU(buffer.GetMemoryView().GetGpuAddress<id<MTLBuffer>>(), buffer.GetMemoryView().GetOffset(), buffer.GetMemoryView().GetSize());
SynchronizeBufferOnCPU(buffer.GetMemoryView().GetGpuAddress<id<MTLBuffer>>(),
buffer.GetMemoryView().GetOffset() + buffer.GetMapRequestOffset(),
buffer.GetMemoryView().GetSize());
}
}
@@ -35,6 +35,16 @@ namespace AZ
}
}
void Buffer::SetMapRequestOffset(const uint32_t mapRequestOffset)
{
m_mapRequestOffset = mapRequestOffset;
}
const uint32_t Buffer::GetMapRequestOffset() const
{
return m_mapRequestOffset;
}
void Buffer::ReportMemoryUsage(RHI::MemoryStatisticsBuilder& builder) const
{
//[GFX TODO][ATOM-493] - Report memory usage support
@@ -32,6 +32,9 @@ namespace AZ
const MemoryView& GetMemoryView() const;
MemoryView& GetMemoryView();
void SetMapRequestOffset(const uint32_t mapRequestOffset);
const uint32_t GetMapRequestOffset() const;
private:
Buffer() = default;
friend class BufferPool;
@@ -57,6 +60,9 @@ namespace AZ
// The number of resolve operations pending for this buffer.
AZStd::atomic<uint32_t> m_pendingResolves = 0;
// Offset related to the Map request. We need to cache it for cpu/gpu synchronization.
uint32_t m_mapRequestOffset = 0;
};
}
@@ -5,6 +5,7 @@
*
*/
#include <Atom/RHI.Reflect/Base.h>
#include <AzCore/Debug/EventTrace.h>
#include <RHI/CommandQueue.h>
@@ -24,8 +25,35 @@ namespace AZ
id <MTLCommandBuffer> CommandQueueCommandBuffer::AcquireMTLCommandBuffer()
{
AZ_Assert(m_mtlCommandBuffer==nil, "Previous command buffer was not commited");
//Create a new command buffer
m_mtlCommandBuffer = [m_hwQueue commandBuffer];
#if defined(__IPHONE_14_0) || defined(__MAC_11_0)
if(@available(iOS 14.0, macOS 11.0, *))
{
if(RHI::BuildOptions::IsDebugBuild)
{
//There is a perf cost associated with enhanced command buffer errors so only enabling them for debug builds.
MTLCommandBufferDescriptor* mtlCommandBufferDesc = [[MTLCommandBufferDescriptor alloc] init];
mtlCommandBufferDesc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
m_mtlCommandBuffer = [m_hwQueue commandBufferWithDescriptor:mtlCommandBufferDesc];
[m_mtlCommandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer)
{
// check command buffer's status for errors, print out all of its contents
MTLCommandBufferStatus stat = buffer.status;
if (stat == MTLCommandBufferStatusError)
{
NSLog(@"%@",buffer.error);
abort();
}
}];
}
}
#endif
if(m_mtlCommandBuffer == nil)
{
m_mtlCommandBuffer = [m_hwQueue commandBuffer];
}
//we call retain here as this CB is active across the autoreleasepools of multiple threads. Calling
//retain here means that if the current thread's autoreleasepool gets drained this CB will not die.
@@ -91,7 +119,7 @@ namespace AZ
AZ_Assert(false,"Insufficient memory");
break;
case MTLCommandBufferErrorInvalidResource:
AZ_Assert(false,"The command buffer referenced an invlid resource. This error is most commonly caused when caller deletes a resource before executing a command buffer that refers to it");
AZ_Assert(false,"This error is most commonly caused when the caller deletes a resource before executing a command buffer that refers to it. It would also trigger if the caller deletes the resource while the GPU is working on the command buffer");
break;
default:
break;
@@ -46,7 +46,7 @@ namespace AZ
{
{
ReleaseQueue::Descriptor releaseQueueDescriptor;
releaseQueueDescriptor.m_collectLatency = descriptor.m_frameCountMax - 1;
releaseQueueDescriptor.m_collectLatency = descriptor.m_frameCountMax;
m_releaseQueue.Init(releaseQueueDescriptor);
}
@@ -188,6 +188,7 @@ namespace AZ
{
m_renderPassDescriptor.colorAttachments[colorAttachmentIndex].slice = imgViewDescriptor.m_arraySliceMin;
}
m_renderPassDescriptor.colorAttachments[colorAttachmentIndex].level = imgViewDescriptor.m_mipSliceMin;
}
MTLRenderPassColorAttachmentDescriptor* colorAttachment = m_renderPassDescriptor.colorAttachments[colorAttachmentIndex];