Update MetalCmdBufferRecordingInfo data

Switch to caching the CA::MetalLayer & WrappedMTLTexture from the MTL::Drawable.
This is to avoid validation asserts about accessing the texture of a MTL::Drawable after calling MTLCommandBuffer::presentDrawable.

Switch "bool present" to "uint32_t flags" to future proof being able to store multiple flags on the command buffer recoring info
This commit is contained in:
Jake Turner
2022-06-28 20:34:17 +01:00
committed by Baldur Karlsson
parent ee82cf1476
commit 8b8027ff89
2 changed files with 15 additions and 12 deletions
@@ -25,6 +25,7 @@
#include "metal_command_buffer.h"
#include "metal_blit_command_encoder.h"
#include "metal_device.h"
#include "metal_helpers_bridge.h"
#include "metal_render_command_encoder.h"
#include "metal_resources.h"
#include "metal_texture.h"
@@ -163,6 +164,9 @@ bool WrappedMTLCommandBuffer::Serialise_presentDrawable(SerialiserType &ser, MTL
void WrappedMTLCommandBuffer::presentDrawable(MTL::Drawable *drawable)
{
// To avoid metal assert about accessing drawable texture after calling present
MTL::Texture *mtlBackBuffer = ObjC::Get_Texture(drawable);
SERIALISE_TIME_CALL(Unwrap(this)->presentDrawable(drawable));
if(IsCaptureMode(m_State))
{
@@ -173,10 +177,11 @@ void WrappedMTLCommandBuffer::presentDrawable(MTL::Drawable *drawable)
Serialise_presentDrawable(ser, drawable);
chunk = scope.Get();
}
MetalResourceRecord *record = GetRecord(this);
record->AddChunk(chunk);
record->cmdInfo->present = true;
record->cmdInfo->drawable = drawable;
MetalResourceRecord *bufferRecord = GetRecord(this);
bufferRecord->AddChunk(chunk);
bufferRecord->cmdInfo->flags |= MetalCmdBufferStatus::Presented;
bufferRecord->cmdInfo->outputLayer = ObjC::Get_Layer(drawable);
bufferRecord->cmdInfo->backBuffer = GetWrapped(mtlBackBuffer);
}
else
{
+6 -8
View File
@@ -137,10 +137,7 @@ BITMASK_OPERATORS(MetalCmdBufferStatus);
struct MetalCmdBufferRecordingInfo
{
MetalCmdBufferRecordingInfo(WrappedMTLCommandQueue *parentQueue)
: queue(parentQueue), present(false), drawable(NULL)
{
}
MetalCmdBufferRecordingInfo(WrappedMTLCommandQueue *parentQueue) : queue(parentQueue) {}
MetalCmdBufferRecordingInfo() = delete;
MetalCmdBufferRecordingInfo(const MetalCmdBufferRecordingInfo &) = delete;
MetalCmdBufferRecordingInfo(MetalCmdBufferRecordingInfo &&) = delete;
@@ -148,10 +145,11 @@ struct MetalCmdBufferRecordingInfo
~MetalCmdBufferRecordingInfo() {}
WrappedMTLCommandQueue *queue;
// The drawable that present was called on
MTL::Drawable *drawable;
// AdvanceFrame/Present should be called after this buffer is committed.
bool present;
// The MetalLayer to present
CA::MetalLayer *outputLayer = NULL;
// The texture to present
WrappedMTLTexture *backBuffer = NULL;
MetalCmdBufferStatus flags = MetalCmdBufferStatus::NoFlags;
};
struct MetalResourceRecord : public ResourceRecord