Skip to content

Commit 7989d08

Browse files
committed
Original ID/Live ID fixups for Metal backend
1 parent 94df84d commit 7989d08

File tree

6 files changed

+41
-38
lines changed

6 files changed

+41
-38
lines changed

renderdoc/driver/metal/metal_command_buffer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ WrappedMTLBlitCommandEncoder *WrappedMTLCommandBuffer::blitCommandEncoder()
5959
MTL::BlitCommandEncoder *realMTLBlitCommandEncoder;
6060
SERIALISE_TIME_CALL(realMTLBlitCommandEncoder = Unwrap(this)->blitCommandEncoder());
6161
WrappedMTLBlitCommandEncoder *wrappedMTLBlitCommandEncoder;
62-
ResourceId id =
63-
GetResourceManager()->WrapResource(realMTLBlitCommandEncoder, wrappedMTLBlitCommandEncoder);
62+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLBlitCommandEncoder,
63+
wrappedMTLBlitCommandEncoder);
6464
wrappedMTLBlitCommandEncoder->SetCommandBuffer(this);
6565
if(IsCaptureMode(m_State))
6666
{
@@ -113,7 +113,7 @@ WrappedMTLRenderCommandEncoder *WrappedMTLCommandBuffer::renderCommandEncoderWit
113113
Unwrap(this)->renderCommandEncoder(mtlDescriptor));
114114
mtlDescriptor->release();
115115
WrappedMTLRenderCommandEncoder *wrappedMTLRenderCommandEncoder;
116-
ResourceId id = GetResourceManager()->WrapResource(realMTLRenderCommandEncoder,
116+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLRenderCommandEncoder,
117117
wrappedMTLRenderCommandEncoder);
118118
wrappedMTLRenderCommandEncoder->SetCommandBuffer(this);
119119
if(IsCaptureMode(m_State))
@@ -165,7 +165,7 @@ bool WrappedMTLCommandBuffer::Serialise_presentDrawable(SerialiserType &ser,
165165
AddEvent();
166166

167167
ActionDescription action;
168-
ResourceId presentedImageId = GetResourceManager()->GetOriginalID(GetResID(presentedImage));
168+
ResourceId presentedImageId = GetResID(presentedImage);
169169
action.customName = StringFormat::Fmt("presentDrawable(%s)", ToStr(presentedImageId).c_str());
170170
action.flags |= ActionFlags::Present;
171171
action.copyDestination = presentedImageId;

renderdoc/driver/metal/metal_command_queue.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ WrappedMTLCommandBuffer *WrappedMTLCommandQueue::commandBuffer()
5555
MTL::CommandBuffer *realMTLCommandBuffer;
5656
SERIALISE_TIME_CALL(realMTLCommandBuffer = Unwrap(this)->commandBuffer());
5757
WrappedMTLCommandBuffer *wrappedMTLCommandBuffer;
58-
ResourceId id = GetResourceManager()->WrapResource(realMTLCommandBuffer, wrappedMTLCommandBuffer);
58+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLCommandBuffer,
59+
wrappedMTLCommandBuffer);
5960
wrappedMTLCommandBuffer->SetCommandQueue(this);
6061

6162
if(IsCaptureMode(m_State))
@@ -75,7 +76,7 @@ WrappedMTLCommandBuffer *WrappedMTLCommandQueue::commandBuffer()
7576
else
7677
{
7778
// TODO: implement RD MTL replay
78-
GetResourceManager()->AddLiveResource(id, wrappedMTLCommandBuffer);
79+
GetResourceManager()->AddResource(id, wrappedMTLCommandBuffer);
7980
}
8081

8182
return wrappedMTLCommandBuffer;

renderdoc/driver/metal/metal_core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void WrappedMTLDevice::AddResource(ResourceId id, ResourceType type, const char
487487

488488
void WrappedMTLDevice::DerivedResource(ResourceId parentLive, ResourceId child)
489489
{
490-
ResourceId parentId = GetResourceManager()->GetOriginalID(parentLive);
490+
ResourceId parentId = parentLive;
491491

492492
GetReplay()->GetResourceDesc(parentId).derivedResources.push_back(child);
493493
GetReplay()->GetResourceDesc(child).parentResources.push_back(parentId);

renderdoc/driver/metal/metal_device.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ WrappedMTLDevice::WrappedMTLDevice(MTL::Device *realMTLDevice, ResourceId objId)
6666
}
6767

6868
RDCASSERT(m_Device == this);
69-
GetResourceManager()->AddCurrentResource(objId, this);
69+
GetResourceManager()->AddResource(objId, this);
7070

7171
if(IsCaptureMode(m_State))
7272
{
@@ -184,8 +184,7 @@ bool WrappedMTLDevice::Serialise_newCommandQueue(SerialiserType &ser, WrappedMTL
184184
{
185185
MTL::CommandQueue *realMTLCommandQueue = Unwrap(this)->newCommandQueue();
186186
WrappedMTLCommandQueue *wrappedMTLCommandQueue;
187-
GetResourceManager()->WrapResource(realMTLCommandQueue, wrappedMTLCommandQueue);
188-
GetResourceManager()->AddLiveResource(CommandQueue, wrappedMTLCommandQueue);
187+
GetResourceManager()->WrapResource(CommandQueue, realMTLCommandQueue, wrappedMTLCommandQueue);
189188

190189
AddResource(CommandQueue, ResourceType::Queue, "Queue");
191190
DerivedResource(this, CommandQueue);
@@ -198,7 +197,8 @@ WrappedMTLCommandQueue *WrappedMTLDevice::newCommandQueue()
198197
MTL::CommandQueue *realMTLCommandQueue;
199198
SERIALISE_TIME_CALL(realMTLCommandQueue = Unwrap(this)->newCommandQueue());
200199
WrappedMTLCommandQueue *wrappedMTLCommandQueue;
201-
ResourceId id = GetResourceManager()->WrapResource(realMTLCommandQueue, wrappedMTLCommandQueue);
200+
ResourceId id =
201+
GetResourceManager()->WrapResource(ResourceId(), realMTLCommandQueue, wrappedMTLCommandQueue);
202202
if(IsCaptureMode(m_State))
203203
{
204204
Chunk *chunk = NULL;
@@ -256,8 +256,7 @@ bool WrappedMTLDevice::Serialise_newDefaultLibrary(SerialiserType &ser, WrappedM
256256
dispatch_release(dispatchData);
257257

258258
WrappedMTLLibrary *wrappedMTLLibrary;
259-
GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
260-
GetResourceManager()->AddLiveResource(Library, wrappedMTLLibrary);
259+
GetResourceManager()->WrapResource(Library, realMTLLibrary, wrappedMTLLibrary);
261260
AddResource(Library, ResourceType::Pool, "Library");
262261
DerivedResource(this, Library);
263262
}
@@ -270,7 +269,7 @@ WrappedMTLLibrary *WrappedMTLDevice::newDefaultLibrary()
270269

271270
SERIALISE_TIME_CALL(realMTLLibrary = Unwrap(this)->newDefaultLibrary());
272271
WrappedMTLLibrary *wrappedMTLLibrary;
273-
ResourceId id = GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
272+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLLibrary, wrappedMTLLibrary);
274273
if(IsCaptureMode(m_State))
275274
{
276275
Chunk *chunk = NULL;
@@ -309,8 +308,7 @@ bool WrappedMTLDevice::Serialise_newLibraryWithSource(SerialiserType &ser,
309308
NS::Error *compileErrors = NULL;
310309
MTL::Library *realMTLLibrary = Unwrap(this)->newLibrary(source, options, &compileErrors);
311310
WrappedMTLLibrary *wrappedMTLLibrary;
312-
GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
313-
GetResourceManager()->AddLiveResource(Library, wrappedMTLLibrary);
311+
GetResourceManager()->WrapResource(Library, realMTLLibrary, wrappedMTLLibrary);
314312
AddResource(Library, ResourceType::Pool, "Library");
315313
DerivedResource(this, Library);
316314
}
@@ -324,7 +322,7 @@ WrappedMTLLibrary *WrappedMTLDevice::newLibraryWithSource(NS::String *source,
324322
MTL::Library *realMTLLibrary;
325323
SERIALISE_TIME_CALL(realMTLLibrary = Unwrap(this)->newLibrary(source, options, error));
326324
WrappedMTLLibrary *wrappedMTLLibrary;
327-
ResourceId id = GetResourceManager()->WrapResource(realMTLLibrary, wrappedMTLLibrary);
325+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLLibrary, wrappedMTLLibrary);
328326
if(IsCaptureMode(m_State))
329327
{
330328
Chunk *chunk = NULL;
@@ -377,8 +375,7 @@ bool WrappedMTLDevice::Serialise_newBufferWithBytes(SerialiserType &ser, Wrapped
377375
realMTLBuffer = Unwrap(this)->newBuffer(initialData.data(), initialData.size(), options);
378376
}
379377
WrappedMTLBuffer *wrappedMTLBuffer;
380-
GetResourceManager()->WrapResource(realMTLBuffer, wrappedMTLBuffer);
381-
GetResourceManager()->AddLiveResource(Buffer, wrappedMTLBuffer);
378+
GetResourceManager()->WrapResource(Buffer, realMTLBuffer, wrappedMTLBuffer);
382379

383380
AddResource(Buffer, ResourceType::Buffer, "Buffer");
384381
DerivedResource(this, Buffer);
@@ -419,9 +416,8 @@ bool WrappedMTLDevice::Serialise_newRenderPipelineStateWithDescriptor(
419416
Unwrap(this)->newRenderPipelineState(mtlDescriptor, error);
420417
mtlDescriptor->release();
421418
WrappedMTLRenderPipelineState *wrappedMTLRenderPipelineState;
422-
liveID = GetResourceManager()->WrapResource(realMTLRenderPipelineState,
419+
liveID = GetResourceManager()->WrapResource(RenderPipelineState, realMTLRenderPipelineState,
423420
wrappedMTLRenderPipelineState);
424-
GetResourceManager()->AddLiveResource(RenderPipelineState, wrappedMTLRenderPipelineState);
425421
AddResource(RenderPipelineState, ResourceType::PipelineState, "Pipeline State");
426422
DerivedResource(this, RenderPipelineState);
427423
}
@@ -438,8 +434,8 @@ WrappedMTLRenderPipelineState *WrappedMTLDevice::newRenderPipelineStateWithDescr
438434
realDescriptor->release();
439435

440436
WrappedMTLRenderPipelineState *wrappedMTLRenderPipelineState;
441-
ResourceId id =
442-
GetResourceManager()->WrapResource(realMTLRenderPipelineState, wrappedMTLRenderPipelineState);
437+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLRenderPipelineState,
438+
wrappedMTLRenderPipelineState);
443439
if(IsCaptureMode(m_State))
444440
{
445441
Chunk *chunk = NULL;
@@ -492,8 +488,8 @@ bool WrappedMTLDevice::Serialise_newTextureWithDescriptor(SerialiserType &ser,
492488
MTL::Texture *realMTLTexture = Unwrap(this)->newTexture(mtlDescriptor);
493489
mtlDescriptor->release();
494490
WrappedMTLTexture *wrappedMTLTexture;
495-
ResourceId liveID = GetResourceManager()->WrapResource(realMTLTexture, wrappedMTLTexture);
496-
GetResourceManager()->AddLiveResource(Texture, wrappedMTLTexture);
491+
ResourceId liveID =
492+
GetResourceManager()->WrapResource(Texture, realMTLTexture, wrappedMTLTexture);
497493

498494
AddResource(Texture, ResourceType::Texture, "Texture");
499495
DerivedResource(this, Texture);
@@ -676,7 +672,7 @@ WrappedMTLTexture *WrappedMTLDevice::Common_NewTexture(RDMTL::TextureDescriptor
676672
realDescriptor, iosurface, plane));
677673
realDescriptor->release();
678674
WrappedMTLTexture *wrappedMTLTexture;
679-
ResourceId id = GetResourceManager()->WrapResource(realMTLTexture, wrappedMTLTexture);
675+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLTexture, wrappedMTLTexture);
680676
if(IsCaptureMode(m_State))
681677
{
682678
RDMTL::TextureDescriptor rdDescriptor(descriptor);
@@ -712,7 +708,7 @@ WrappedMTLBuffer *WrappedMTLDevice::Common_NewBuffer(bool withBytes, const void
712708
: Unwrap(this)->newBuffer(length, options));
713709

714710
WrappedMTLBuffer *wrappedMTLBuffer;
715-
ResourceId id = GetResourceManager()->WrapResource(realMTLBuffer, wrappedMTLBuffer);
711+
ResourceId id = GetResourceManager()->WrapResource(ResourceId(), realMTLBuffer, wrappedMTLBuffer);
716712
if(IsCaptureMode(m_State))
717713
{
718714
Chunk *chunk = NULL;

renderdoc/driver/metal/metal_library.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ bool WrappedMTLLibrary::Serialise_newFunctionWithName(SerialiserType &ser,
5050
{
5151
MTL::Function *realMTLFunction = Unwrap(Library)->newFunction(FunctionName);
5252
WrappedMTLFunction *wrappedMTLFunction;
53-
GetResourceManager()->WrapResource(realMTLFunction, wrappedMTLFunction);
54-
GetResourceManager()->AddLiveResource(Function, wrappedMTLFunction);
53+
GetResourceManager()->WrapResource(ResourceId(), realMTLFunction, wrappedMTLFunction);
5554
m_Device->AddResource(Function, ResourceType::Shader, "Function");
5655
m_Device->DerivedResource(Library, Function);
5756
}
@@ -64,7 +63,8 @@ WrappedMTLFunction *WrappedMTLLibrary::newFunctionWithName(NS::String *functionN
6463
SERIALISE_TIME_CALL(realMTLFunction = Unwrap(this)->newFunction(functionName));
6564

6665
WrappedMTLFunction *wrappedMTLFunction;
67-
ResourceId id = GetResourceManager()->WrapResource(realMTLFunction, wrappedMTLFunction);
66+
ResourceId id =
67+
GetResourceManager()->WrapResource(ResourceId(), realMTLFunction, wrappedMTLFunction);
6868

6969
if(IsCaptureMode(m_State))
7070
{

renderdoc/driver/metal/metal_manager.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ class MetalResourceManager : public ResourceManager<MetalResourceManagerConfigur
8383
// if any objects leaked past, it's no longer safe to delete them as we would
8484
// be calling Shutdown() after the device that owns them is destroyed. Instead
8585
// we just have to leak ourselves.
86-
RDCASSERT(m_LiveResourceMap.empty());
8786
RDCASSERT(m_InitialContents.empty());
8887
RDCASSERT(m_ResourceRecords.empty());
89-
RDCASSERT(m_CurrentResourceMap.empty());
88+
RDCASSERT(m_ResourceMap.empty());
9089
RDCASSERT(m_WrapperMap.empty());
9190

92-
m_LiveResourceMap.clear();
9391
m_InitialContents.clear();
9492
m_ResourceRecords.clear();
95-
m_CurrentResourceMap.clear();
93+
m_ResourceMap.clear();
9694
m_WrapperMap.clear();
9795
}
9896

@@ -107,16 +105,24 @@ class MetalResourceManager : public ResourceManager<MetalResourceManagerConfigur
107105
// ResourceManager interface
108106

109107
template <typename realtype>
110-
ResourceId WrapResource(realtype obj, typename UnwrapHelper<realtype>::Outer *&wrapped)
108+
ResourceId WrapResource(ResourceId id, realtype obj,
109+
typename UnwrapHelper<realtype>::Outer *&wrapped)
111110
{
112111
RDCASSERT(obj != NULL);
113112
RDCASSERT(m_Device != NULL);
114113

115-
ResourceId id = ResourceIDGen::GetNewUniqueID();
114+
// on replay, we provide an ID for replayed versions of capture-time resources. For
115+
// replay-only/internal resources, we auto-gen a resource id.
116+
// during capture we should always be auto-gen'ing a resource id for obvious reasons.
117+
if(id == ResourceId())
118+
id = ResourceIDGen::GetNewUniqueID();
119+
else
120+
RDCASSERT(IsReplayMode(m_State));
121+
116122
using WrappedType = typename UnwrapHelper<realtype>::Outer;
117123
wrapped = new WrappedType(obj, id, m_Device);
118124
wrapped->m_Real = obj;
119-
AddCurrentResource(id, wrapped);
125+
AddResource(id, wrapped);
120126

121127
// TODO: implement RD MTL replay
122128
// if(IsReplayMode(m_State))
@@ -131,7 +137,7 @@ class MetalResourceManager : public ResourceManager<MetalResourceManagerConfigur
131137

132138
// TODO: implement RD MTL replay
133139

134-
ResourceManager::ReleaseCurrentResource(id);
140+
ResourceManager::ReleaseResource(id);
135141
MetalResourceRecord *record = GetRecord(wrapped);
136142
if(record)
137143
{

0 commit comments

Comments
 (0)