diff --git a/renderdoc/driver/metal/metal_library.cpp b/renderdoc/driver/metal/metal_library.cpp index db5736efc..364809d9a 100644 --- a/renderdoc/driver/metal/metal_library.cpp +++ b/renderdoc/driver/metal/metal_library.cpp @@ -32,3 +32,53 @@ WrappedMTLLibrary::WrappedMTLLibrary(MTL::Library *realMTLLibrary, ResourceId ob { objcBridge = AllocateObjCBridge(this); } + +template +bool WrappedMTLLibrary::Serialise_newFunctionWithName(SerialiserType &ser, + WrappedMTLFunction *function, + NS::String *FunctionName) +{ + SERIALISE_ELEMENT_LOCAL(Library, this); + SERIALISE_ELEMENT_LOCAL(Function, GetResID(function)).TypedAs("MTLFunction"_lit); + SERIALISE_ELEMENT(FunctionName).Important(); + + SERIALISE_CHECK_READ_ERRORS(); + + // TODO: implement RD MTL replay + if(IsReplayingAndReading()) + { + } + return true; +} + +WrappedMTLFunction *WrappedMTLLibrary::newFunctionWithName(NS::String *functionName) +{ + MTL::Function *realMTLFunction; + SERIALISE_TIME_CALL(realMTLFunction = Unwrap(this)->newFunction(functionName)); + + WrappedMTLFunction *wrappedMTLFunction; + ResourceId id = GetResourceManager()->WrapResource(realMTLFunction, wrappedMTLFunction); + + if(IsCaptureMode(m_State)) + { + Chunk *chunk = NULL; + { + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(MetalChunk::MTLLibrary_newFunctionWithName); + Serialise_newFunctionWithName(ser, wrappedMTLFunction, functionName); + chunk = scope.Get(); + } + MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLFunction); + record->AddChunk(chunk); + GetResourceManager()->MarkResourceFrameReferenced(id, eFrameRef_Read); + record->AddParent(GetRecord(this)); + } + else + { + // TODO: implement RD MTL replay + } + return wrappedMTLFunction; +} + +INSTANTIATE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLLibrary, WrappedMTLFunction *function, + newFunctionWithName, NS::String *functionName); diff --git a/renderdoc/driver/metal/metal_library.h b/renderdoc/driver/metal/metal_library.h index fb4fe37e8..dcb1560c4 100644 --- a/renderdoc/driver/metal/metal_library.h +++ b/renderdoc/driver/metal/metal_library.h @@ -32,6 +32,9 @@ public: WrappedMTLLibrary(MTL::Library *realMTLLibrary, ResourceId objId, WrappedMTLDevice *wrappedMTLDevice); + DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLFunction *, newFunctionWithName, + NS::String *functionName); + enum { TypeEnum = eResLibrary diff --git a/renderdoc/driver/metal/metal_library_bridge.mm b/renderdoc/driver/metal/metal_library_bridge.mm index 69f6e0bf8..4ed1315b1 100644 --- a/renderdoc/driver/metal/metal_library_bridge.mm +++ b/renderdoc/driver/metal/metal_library_bridge.mm @@ -78,8 +78,8 @@ - (nullable id)newFunctionWithName:(NSString *)functionName { - METAL_NOT_HOOKED(); - return [self.real newFunctionWithName:functionName]; + return id( + GetObjCBridge(self.wrappedCPP->newFunctionWithName((NS::String *)functionName))); } - (nullable id)newFunctionWithName:(NSString *)name