Original ID/Live ID fixups for Metal backend

This commit is contained in:
Jake Turner
2026-01-06 13:03:31 +13:00
parent 94df84d5d9
commit 5e286ad9b8
7 changed files with 44 additions and 41 deletions
@@ -59,8 +59,8 @@ WrappedMTLBlitCommandEncoder *WrappedMTLCommandBuffer::blitCommandEncoder()
MTL::BlitCommandEncoder *realMTLBlitCommandEncoder;
SERIALISE_TIME_CALL(realMTLBlitCommandEncoder = Unwrap(this)->blitCommandEncoder());
WrappedMTLBlitCommandEncoder *wrappedMTLBlitCommandEncoder;
ResourceId id =
GetResourceManager()->WrapResource(realMTLBlitCommandEncoder, wrappedMTLBlitCommandEncoder);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLBlitCommandEncoder,
wrappedMTLBlitCommandEncoder);
wrappedMTLBlitCommandEncoder->SetCommandBuffer(this);
if(IsCaptureMode(m_State))
{
@@ -113,7 +113,7 @@ WrappedMTLRenderCommandEncoder *WrappedMTLCommandBuffer::renderCommandEncoderWit
Unwrap(this)->renderCommandEncoder(mtlDescriptor));
mtlDescriptor->release();
WrappedMTLRenderCommandEncoder *wrappedMTLRenderCommandEncoder;
ResourceId id = GetResourceManager()->WrapResource(realMTLRenderCommandEncoder,
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLRenderCommandEncoder,
wrappedMTLRenderCommandEncoder);
wrappedMTLRenderCommandEncoder->SetCommandBuffer(this);
if(IsCaptureMode(m_State))
@@ -165,7 +165,7 @@ bool WrappedMTLCommandBuffer::Serialise_presentDrawable(SerialiserType &ser,
AddEvent();
ActionDescription action;
ResourceId presentedImageId = GetResourceManager()->GetOriginalID(GetResID(presentedImage));
ResourceId presentedImageId = GetResID(presentedImage);
action.customName = StringFormat::Fmt("presentDrawable(%s)", ToStr(presentedImageId).c_str());
action.flags |= ActionFlags::Present;
action.copyDestination = presentedImageId;
@@ -55,7 +55,8 @@ WrappedMTLCommandBuffer *WrappedMTLCommandQueue::commandBuffer()
MTL::CommandBuffer *realMTLCommandBuffer;
SERIALISE_TIME_CALL(realMTLCommandBuffer = Unwrap(this)->commandBuffer());
WrappedMTLCommandBuffer *wrappedMTLCommandBuffer;
ResourceId id = GetResourceManager()->WrapResource(realMTLCommandBuffer, wrappedMTLCommandBuffer);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLCommandBuffer,
wrappedMTLCommandBuffer);
wrappedMTLCommandBuffer->SetCommandQueue(this);
if(IsCaptureMode(m_State))
@@ -75,7 +76,7 @@ WrappedMTLCommandBuffer *WrappedMTLCommandQueue::commandBuffer()
else
{
// TODO: implement RD MTL replay
GetResourceManager()->AddLiveResource(id, wrappedMTLCommandBuffer);
GetResourceManager()->AddResource(id, wrappedMTLCommandBuffer);
}
return wrappedMTLCommandBuffer;
+1 -1
View File
@@ -487,7 +487,7 @@ void WrappedMTLDevice::AddResource(ResourceId id, ResourceType type, const char
void WrappedMTLDevice::DerivedResource(ResourceId parentLive, ResourceId child)
{
ResourceId parentId = GetResourceManager()->GetOriginalID(parentLive);
ResourceId parentId = parentLive;
GetReplay()->GetResourceDesc(parentId).derivedResources.push_back(child);
GetReplay()->GetResourceDesc(child).parentResources.push_back(parentId);
+16 -20
View File
@@ -66,7 +66,7 @@ WrappedMTLDevice::WrappedMTLDevice(MTL::Device *realMTLDevice, ResourceId objId)
}
RDCASSERT(m_Device == this);
GetResourceManager()->AddCurrentResource(objId, this);
GetResourceManager()->AddResource(objId, this);
if(IsCaptureMode(m_State))
{
@@ -184,8 +184,7 @@ bool WrappedMTLDevice::Serialise_newCommandQueue(SerialiserType &ser, WrappedMTL
{
MTL::CommandQueue *realMTLCommandQueue = Unwrap(this)->newCommandQueue();
WrappedMTLCommandQueue *wrappedMTLCommandQueue;
GetResourceManager()->WrapResource(realMTLCommandQueue, wrappedMTLCommandQueue);
GetResourceManager()->AddLiveResource(CommandQueue, wrappedMTLCommandQueue);
GetResourceManager()->WrapResource(CommandQueue, realMTLCommandQueue, wrappedMTLCommandQueue);
AddResource(CommandQueue, ResourceType::Queue, "Queue");
DerivedResource(this, CommandQueue);
@@ -198,7 +197,8 @@ WrappedMTLCommandQueue *WrappedMTLDevice::newCommandQueue()
MTL::CommandQueue *realMTLCommandQueue;
SERIALISE_TIME_CALL(realMTLCommandQueue = Unwrap(this)->newCommandQueue());
WrappedMTLCommandQueue *wrappedMTLCommandQueue;
ResourceId id = GetResourceManager()->WrapResource(realMTLCommandQueue, wrappedMTLCommandQueue);
ResourceId id =
GetResourceManager()->WrapResource(ResourceId(), realMTLCommandQueue, wrappedMTLCommandQueue);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
@@ -256,8 +256,7 @@ bool WrappedMTLDevice::Serialise_newDefaultLibrary(SerialiserType &ser, WrappedM
dispatch_release(dispatchData);
WrappedMTLLibrary *wrappedMTLLibrary;
GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
GetResourceManager()->AddLiveResource(Library, wrappedMTLLibrary);
GetResourceManager()->WrapResource(Library, realMTLLibrary, wrappedMTLLibrary);
AddResource(Library, ResourceType::Pool, "Library");
DerivedResource(this, Library);
}
@@ -270,7 +269,7 @@ WrappedMTLLibrary *WrappedMTLDevice::newDefaultLibrary()
SERIALISE_TIME_CALL(realMTLLibrary = Unwrap(this)->newDefaultLibrary());
WrappedMTLLibrary *wrappedMTLLibrary;
ResourceId id = GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLLibrary, wrappedMTLLibrary);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
@@ -309,8 +308,7 @@ bool WrappedMTLDevice::Serialise_newLibraryWithSource(SerialiserType &ser,
NS::Error *compileErrors = NULL;
MTL::Library *realMTLLibrary = Unwrap(this)->newLibrary(source, options, &compileErrors);
WrappedMTLLibrary *wrappedMTLLibrary;
GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
GetResourceManager()->AddLiveResource(Library, wrappedMTLLibrary);
GetResourceManager()->WrapResource(Library, realMTLLibrary, wrappedMTLLibrary);
AddResource(Library, ResourceType::Pool, "Library");
DerivedResource(this, Library);
}
@@ -324,7 +322,7 @@ WrappedMTLLibrary *WrappedMTLDevice::newLibraryWithSource(NS::String *source,
MTL::Library *realMTLLibrary;
SERIALISE_TIME_CALL(realMTLLibrary = Unwrap(this)->newLibrary(source, options, error));
WrappedMTLLibrary *wrappedMTLLibrary;
ResourceId id = GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLLibrary, wrappedMTLLibrary);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
@@ -377,8 +375,7 @@ bool WrappedMTLDevice::Serialise_newBufferWithBytes(SerialiserType &ser, Wrapped
realMTLBuffer = Unwrap(this)->newBuffer(initialData.data(), initialData.size(), options);
}
WrappedMTLBuffer *wrappedMTLBuffer;
GetResourceManager()->WrapResource(realMTLBuffer, wrappedMTLBuffer);
GetResourceManager()->AddLiveResource(Buffer, wrappedMTLBuffer);
GetResourceManager()->WrapResource(Buffer, realMTLBuffer, wrappedMTLBuffer);
AddResource(Buffer, ResourceType::Buffer, "Buffer");
DerivedResource(this, Buffer);
@@ -419,9 +416,8 @@ bool WrappedMTLDevice::Serialise_newRenderPipelineStateWithDescriptor(
Unwrap(this)->newRenderPipelineState(mtlDescriptor, error);
mtlDescriptor->release();
WrappedMTLRenderPipelineState *wrappedMTLRenderPipelineState;
liveID = GetResourceManager()->WrapResource(realMTLRenderPipelineState,
liveID = GetResourceManager()->WrapResource(RenderPipelineState, realMTLRenderPipelineState,
wrappedMTLRenderPipelineState);
GetResourceManager()->AddLiveResource(RenderPipelineState, wrappedMTLRenderPipelineState);
AddResource(RenderPipelineState, ResourceType::PipelineState, "Pipeline State");
DerivedResource(this, RenderPipelineState);
}
@@ -438,8 +434,8 @@ WrappedMTLRenderPipelineState *WrappedMTLDevice::newRenderPipelineStateWithDescr
realDescriptor->release();
WrappedMTLRenderPipelineState *wrappedMTLRenderPipelineState;
ResourceId id =
GetResourceManager()->WrapResource(realMTLRenderPipelineState, wrappedMTLRenderPipelineState);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLRenderPipelineState,
wrappedMTLRenderPipelineState);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
@@ -492,8 +488,8 @@ bool WrappedMTLDevice::Serialise_newTextureWithDescriptor(SerialiserType &ser,
MTL::Texture *realMTLTexture = Unwrap(this)->newTexture(mtlDescriptor);
mtlDescriptor->release();
WrappedMTLTexture *wrappedMTLTexture;
ResourceId liveID = GetResourceManager()->WrapResource(realMTLTexture, wrappedMTLTexture);
GetResourceManager()->AddLiveResource(Texture, wrappedMTLTexture);
ResourceId liveID =
GetResourceManager()->WrapResource(Texture, realMTLTexture, wrappedMTLTexture);
AddResource(Texture, ResourceType::Texture, "Texture");
DerivedResource(this, Texture);
@@ -676,7 +672,7 @@ WrappedMTLTexture *WrappedMTLDevice::Common_NewTexture(RDMTL::TextureDescriptor
realDescriptor, iosurface, plane));
realDescriptor->release();
WrappedMTLTexture *wrappedMTLTexture;
ResourceId id = GetResourceManager()->WrapResource(realMTLTexture, wrappedMTLTexture);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLTexture, wrappedMTLTexture);
if(IsCaptureMode(m_State))
{
RDMTL::TextureDescriptor rdDescriptor(descriptor);
@@ -712,7 +708,7 @@ WrappedMTLBuffer *WrappedMTLDevice::Common_NewBuffer(bool withBytes, const void
: Unwrap(this)->newBuffer(length, options));
WrappedMTLBuffer *wrappedMTLBuffer;
ResourceId id = GetResourceManager()->WrapResource(realMTLBuffer, wrappedMTLBuffer);
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLBuffer, wrappedMTLBuffer);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
+3 -3
View File
@@ -50,8 +50,7 @@ bool WrappedMTLLibrary::Serialise_newFunctionWithName(SerialiserType &ser,
{
MTL::Function *realMTLFunction = Unwrap(Library)->newFunction(FunctionName);
WrappedMTLFunction *wrappedMTLFunction;
GetResourceManager()->WrapResource(realMTLFunction, wrappedMTLFunction);
GetResourceManager()->AddLiveResource(Function, wrappedMTLFunction);
GetResourceManager()->WrapResource(ResourceId(), realMTLFunction, wrappedMTLFunction);
m_Device->AddResource(Function, ResourceType::Shader, "Function");
m_Device->DerivedResource(Library, Function);
}
@@ -64,7 +63,8 @@ WrappedMTLFunction *WrappedMTLLibrary::newFunctionWithName(NS::String *functionN
SERIALISE_TIME_CALL(realMTLFunction = Unwrap(this)->newFunction(functionName));
WrappedMTLFunction *wrappedMTLFunction;
ResourceId id = GetResourceManager()->WrapResource(realMTLFunction, wrappedMTLFunction);
ResourceId id =
GetResourceManager()->WrapResource(ResourceId(), realMTLFunction, wrappedMTLFunction);
if(IsCaptureMode(m_State))
{
+14 -8
View File
@@ -83,16 +83,14 @@ public:
// if any objects leaked past, it's no longer safe to delete them as we would
// be calling Shutdown() after the device that owns them is destroyed. Instead
// we just have to leak ourselves.
RDCASSERT(m_LiveResourceMap.empty());
RDCASSERT(m_InitialContents.empty());
RDCASSERT(m_ResourceRecords.empty());
RDCASSERT(m_CurrentResourceMap.empty());
RDCASSERT(m_ResourceMap.empty());
RDCASSERT(m_WrapperMap.empty());
m_LiveResourceMap.clear();
m_InitialContents.clear();
m_ResourceRecords.clear();
m_CurrentResourceMap.clear();
m_ResourceMap.clear();
m_WrapperMap.clear();
}
@@ -107,16 +105,24 @@ public:
// ResourceManager interface
template <typename realtype>
ResourceId WrapResource(realtype obj, typename UnwrapHelper<realtype>::Outer *&wrapped)
ResourceId WrapResource(ResourceId id, realtype obj,
typename UnwrapHelper<realtype>::Outer *&wrapped)
{
RDCASSERT(obj != NULL);
RDCASSERT(m_Device != NULL);
ResourceId id = ResourceIDGen::GetNewUniqueID();
// on replay, we provide an ID for replayed versions of capture-time resources. For
// replay-only/internal resources, we auto-gen a resource id.
// during capture we should always be auto-gen'ing a resource id for obvious reasons.
if(id == ResourceId())
id = ResourceIDGen::GetNewUniqueID();
else
RDCASSERT(IsReplayMode(m_State));
using WrappedType = typename UnwrapHelper<realtype>::Outer;
wrapped = new WrappedType(obj, id, m_Device);
wrapped->m_Real = obj;
AddCurrentResource(id, wrapped);
AddResource(id, wrapped);
// TODO: implement RD MTL replay
// if(IsReplayMode(m_State))
@@ -131,7 +137,7 @@ public:
// TODO: implement RD MTL replay
ResourceManager::ReleaseCurrentResource(id);
ResourceManager::ReleaseResource(id);
MetalResourceRecord *record = GetRecord(wrapped);
if(record)
{
+3 -3
View File
@@ -47,7 +47,7 @@ void DoSerialiseViaResourceId(SerialiserType &ser, type &el)
if(ser.IsWriting() && rm)
id = GetResID(el);
if(ser.IsStructurising() && rm)
id = rm->GetOriginalID(GetResID(el));
id = GetResID(el);
DoSerialise(ser, id);
@@ -59,10 +59,10 @@ void DoSerialiseViaResourceId(SerialiserType &ser, type &el)
{
if(id != ResourceId() && rm)
{
if(rm->HasLiveResource(id))
if(rm->HasResource(id))
{
// we leave this wrapped.
el = (type)rm->GetLiveResource(id);
el = (type)rm->GetResource(id);
}
}
}