diff --git a/renderdoc/driver/metal/metal_device.cpp b/renderdoc/driver/metal/metal_device.cpp index 23675b781..af77e9c8d 100644 --- a/renderdoc/driver/metal/metal_device.cpp +++ b/renderdoc/driver/metal/metal_device.cpp @@ -256,25 +256,9 @@ bool WrappedMTLDevice::Serialise_newRenderPipelineStateWithDescriptor( } WrappedMTLRenderPipelineState *WrappedMTLDevice::newRenderPipelineStateWithDescriptor( - MTL::RenderPipelineDescriptor *descriptor, NS::Error **error) + RDMTL::RenderPipelineDescriptor &descriptor, NS::Error **error) { - MTL::RenderPipelineDescriptor *realDescriptor = descriptor->copy(); - - // realDescriptor needs the real resources - // TODO: need to unwrap more resources see - // RenderPipelineDescriptor::operator MTL::RenderPipelineDescriptor *() - WrappedMTLFunction *wrappedVertexFunction = GetWrapped(descriptor->vertexFunction()); - if(wrappedVertexFunction != NULL) - { - realDescriptor->setVertexFunction(Unwrap(wrappedVertexFunction)); - } - - WrappedMTLFunction *wrappedFragmentFunction = GetWrapped(descriptor->fragmentFunction()); - if(wrappedFragmentFunction != NULL) - { - realDescriptor->setFragmentFunction(Unwrap(wrappedFragmentFunction)); - } - + MTL::RenderPipelineDescriptor *realDescriptor(descriptor); MTL::RenderPipelineState *realMTLRenderPipelineState; SERIALISE_TIME_CALL(realMTLRenderPipelineState = Unwrap(this)->newRenderPipelineState(realDescriptor, error)); @@ -289,22 +273,21 @@ WrappedMTLRenderPipelineState *WrappedMTLDevice::newRenderPipelineStateWithDescr { CACHE_THREAD_SERIALISER(); SCOPED_SERIALISE_CHUNK(MetalChunk::MTLDevice_newRenderPipelineStateWithDescriptor); - RDMTL::RenderPipelineDescriptor rdDescriptor(descriptor); - Serialise_newRenderPipelineStateWithDescriptor(ser, wrappedMTLRenderPipelineState, - rdDescriptor, error); + Serialise_newRenderPipelineStateWithDescriptor(ser, wrappedMTLRenderPipelineState, descriptor, + error); chunk = scope.Get(); } MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLRenderPipelineState); record->AddChunk(chunk); - if(wrappedVertexFunction) + if(descriptor.vertexFunction) { - record->AddParent(GetRecord(wrappedVertexFunction)); + record->AddParent(GetRecord(descriptor.vertexFunction)); } - if(wrappedFragmentFunction) + if(descriptor.fragmentFunction) { - record->AddParent(GetRecord(wrappedFragmentFunction)); + record->AddParent(GetRecord(descriptor.fragmentFunction)); } } else @@ -331,13 +314,13 @@ bool WrappedMTLDevice::Serialise_newTextureWithDescriptor(SerialiserType &ser, return true; } -WrappedMTLTexture *WrappedMTLDevice::newTextureWithDescriptor(MTL::TextureDescriptor *descriptor) +WrappedMTLTexture *WrappedMTLDevice::newTextureWithDescriptor(RDMTL::TextureDescriptor &descriptor) { return Common_NewTexture(descriptor, MetalChunk::MTLDevice_newTextureWithDescriptor, false, NULL, 0); } -WrappedMTLTexture *WrappedMTLDevice::newTextureWithDescriptor(MTL::TextureDescriptor *descriptor, +WrappedMTLTexture *WrappedMTLDevice::newTextureWithDescriptor(RDMTL::TextureDescriptor &descriptor, IOSurfaceRef iosurface, NS::UInteger plane) { @@ -479,14 +462,16 @@ bool WrappedMTLDevice::supportsPrimitiveMotionBlur() // End of MTLDevice APIs -WrappedMTLTexture *WrappedMTLDevice::Common_NewTexture(MTL::TextureDescriptor *descriptor, +WrappedMTLTexture *WrappedMTLDevice::Common_NewTexture(RDMTL::TextureDescriptor &descriptor, MetalChunk chunkType, bool ioSurfaceTexture, IOSurfaceRef iosurface, NS::UInteger plane) { MTL::Texture *realMTLTexture; - SERIALISE_TIME_CALL(realMTLTexture = !ioSurfaceTexture - ? Unwrap(this)->newTexture(descriptor) - : Unwrap(this)->newTexture(descriptor, iosurface, plane)); + MTL::TextureDescriptor *realDescriptor(descriptor); + SERIALISE_TIME_CALL(realMTLTexture = !ioSurfaceTexture ? Unwrap(this)->newTexture(realDescriptor) + : Unwrap(this)->newTexture( + realDescriptor, iosurface, plane)); + realDescriptor->release(); WrappedMTLTexture *wrappedMTLTexture; ResourceId id = GetResourceManager()->WrapResource(realMTLTexture, wrappedMTLTexture); if(IsCaptureMode(m_State)) diff --git a/renderdoc/driver/metal/metal_device.h b/renderdoc/driver/metal/metal_device.h index 47d5d212c..dbbeabb8b 100644 --- a/renderdoc/driver/metal/metal_device.h +++ b/renderdoc/driver/metal/metal_device.h @@ -42,18 +42,13 @@ public: DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLLibrary *, newLibraryWithSource, NS::String *source, MTL::CompileOptions *options, NS::Error **error); - WrappedMTLRenderPipelineState *newRenderPipelineStateWithDescriptor( - MTL::RenderPipelineDescriptor *descriptor, NS::Error **error); - template - bool Serialise_newRenderPipelineStateWithDescriptor(SerialiserType &ser, - WrappedMTLRenderPipelineState *, - RDMTL::RenderPipelineDescriptor &descriptor, - NS::Error **error); - WrappedMTLTexture *newTextureWithDescriptor(MTL::TextureDescriptor *descriptor, + DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLRenderPipelineState *, + newRenderPipelineStateWithDescriptor, + RDMTL::RenderPipelineDescriptor &descriptor, + NS::Error **error); + WrappedMTLTexture *newTextureWithDescriptor(RDMTL::TextureDescriptor &descriptor, IOSurfaceRef iosurface, NS::UInteger plane); - WrappedMTLTexture *newTextureWithDescriptor(MTL::TextureDescriptor *descriptor); - template - bool Serialise_newTextureWithDescriptor(SerialiserType &ser, WrappedMTLTexture *, + DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLTexture *, newTextureWithDescriptor, RDMTL::TextureDescriptor &descriptor); // Non-Serialised MTLDevice APIs @@ -108,7 +103,7 @@ private: void Create_InitialState(ResourceId id, WrappedMTLObject *live, bool hasData); void Apply_InitialState(WrappedMTLObject *live, const MetalInitialContents &initial); - WrappedMTLTexture *Common_NewTexture(MTL::TextureDescriptor *descriptor, MetalChunk chunkType, + WrappedMTLTexture *Common_NewTexture(RDMTL::TextureDescriptor &descriptor, MetalChunk chunkType, bool ioSurfaceTexture, IOSurfaceRef iosurface, NS::UInteger plane); diff --git a/renderdoc/driver/metal/metal_device_bridge.mm b/renderdoc/driver/metal/metal_device_bridge.mm index af4686b79..e9c569f93 100644 --- a/renderdoc/driver/metal/metal_device_bridge.mm +++ b/renderdoc/driver/metal/metal_device_bridge.mm @@ -257,8 +257,8 @@ - (nullable id)newTextureWithDescriptor:(MTLTextureDescriptor *)descriptor { - return id( - GetWrapped(self)->newTextureWithDescriptor((MTL::TextureDescriptor *)descriptor)); + RDMTL::TextureDescriptor rdDescriptor((MTL::TextureDescriptor *)descriptor); + return id(GetWrapped(self)->newTextureWithDescriptor(rdDescriptor)); } - (nullable id)newTextureWithDescriptor:(MTLTextureDescriptor *)descriptor @@ -266,8 +266,8 @@ plane:(NSUInteger)plane API_AVAILABLE(macos(10.11), ios(11.0)) { - return id(GetWrapped(self)->newTextureWithDescriptor( - (MTL::TextureDescriptor *)descriptor, iosurface, plane)); + RDMTL::TextureDescriptor rdDescriptor((MTL::TextureDescriptor *)descriptor); + return id(GetWrapped(self)->newTextureWithDescriptor(rdDescriptor, iosurface, plane)); } - (nullable id)newSharedTextureWithDescriptor:(MTLTextureDescriptor *)descriptor @@ -366,8 +366,9 @@ newRenderPipelineStateWithDescriptor:(MTLRenderPipelineDescriptor *)descriptor error:(__autoreleasing NSError **)error { - return id(GetWrapped(self)->newRenderPipelineStateWithDescriptor( - (MTL::RenderPipelineDescriptor *)descriptor, (NS::Error **)error)); + RDMTL::RenderPipelineDescriptor rdDescriptor((MTL::RenderPipelineDescriptor *)descriptor); + return id( + GetWrapped(self)->newRenderPipelineStateWithDescriptor(rdDescriptor, (NS::Error **)error)); } - (nullable id)