Store ObjC bridge class in Wrapped C++ classes

Stored as first member data in Wrapped C++ classes (m_ObjcBridge)
Can cast WrappedMTL* C++ pointer to ObjCBridgeMTL* type to use as the ObjC bridge class
Can cast ObjCBridgeMTL* pointer to WrappedMTL* C++ type to use as the Wrapped C++ class

Removed use of term ObjCBridge except on the ObjC bridge declarations

WrappedMTLObject member initialization
Prefer member initialization instead of constructor initialization list
This commit is contained in:
Jake Turner
2022-05-09 05:57:20 +01:00
committed by Baldur Karlsson
parent 797fbcc181
commit f3fe008d73
22 changed files with 154 additions and 234 deletions
-1
View File
@@ -9,7 +9,6 @@ set(sources
metal_device_bridge.mm
metal_resources.cpp
metal_resources.h
metal_types_bridge.mm
metal_types_bridge.h
metal_types.cpp
metal_types.h
@@ -31,7 +31,7 @@ WrappedMTLCommandBuffer::WrappedMTLCommandBuffer(MTL::CommandBuffer *realMTLComm
ResourceId objId, WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLCommandBuffer, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
m_ObjcBridge = AllocateObjCBridge(this);
AllocateObjCBridge(this);
}
template <typename SerialiserType>
@@ -105,7 +105,7 @@ void WrappedMTLCommandBuffer::commit()
if(capframe)
{
bufferRecord->AddRef();
bufferRecord->MarkResourceFrameReferenced(GetResID(m_WrappedMTLCommandQueue), eFrameRef_Read);
bufferRecord->MarkResourceFrameReferenced(GetResID(m_CommandQueue), eFrameRef_Read);
// pull in frame refs from this command buffer
bufferRecord->AddResourceReferences(GetResourceManager());
}
+3 -11
View File
@@ -35,16 +35,8 @@ public:
WrappedMTLCommandBuffer(MTL::CommandBuffer *realMTLCommandBuffer, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice);
void SetWrappedMTLCommandQueue(WrappedMTLCommandQueue *wrappedMTLCommandQueue)
{
m_WrappedMTLCommandQueue = wrappedMTLCommandQueue;
}
MTL::CommandQueue *GetObjCBridgeMTLCommandQueue()
{
return GetObjCBridge(m_WrappedMTLCommandQueue);
}
void SetCommandQueue(WrappedMTLCommandQueue *commandQueue) { m_CommandQueue = commandQueue; }
MTL::CommandQueue *GetCommandQueue() { return (MTL::CommandQueue *)m_CommandQueue; }
DECLARE_FUNCTION_SERIALISED(void, presentDrawable, MTL::Drawable *drawable);
DECLARE_FUNCTION_SERIALISED(void, commit);
@@ -54,5 +46,5 @@ public:
};
private:
WrappedMTLCommandQueue *m_WrappedMTLCommandQueue;
WrappedMTLCommandQueue *m_CommandQueue;
};
@@ -31,14 +31,18 @@
// ObjCBridgeMTLCommandBuffer specific
- (id<MTLCommandBuffer>)real
{
return id<MTLCommandBuffer>(Unwrap(self.wrappedCPP));
return id<MTLCommandBuffer>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLCommandBuffer to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
@@ -63,12 +67,12 @@
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCBridgeMTLDevice());
return id<MTLDevice>(GetWrapped(self)->GetDevice());
}
- (id<MTLCommandQueue>)commandQueue
{
return id<MTLCommandQueue>(self.wrappedCPP->GetObjCBridgeMTLCommandQueue());
return id<MTLCommandQueue>(GetWrapped(self)->GetCommandQueue());
}
- (BOOL)retainedReferences
@@ -124,7 +128,7 @@
- (void)commit
{
self.wrappedCPP->commit();
GetWrapped(self)->commit();
}
- (void)addScheduledHandler:(MTLCommandBufferHandler)block
@@ -135,7 +139,7 @@
- (void)presentDrawable:(id<MTLDrawable>)drawable
{
self.wrappedCPP->presentDrawable((MTL::Drawable *)drawable);
GetWrapped(self)->presentDrawable((MTL::Drawable *)drawable);
}
- (void)presentDrawable:(id<MTLDrawable>)drawable atTime:(CFTimeInterval)presentationTime
@@ -30,7 +30,7 @@ WrappedMTLCommandQueue::WrappedMTLCommandQueue(MTL::CommandQueue *realMTLCommand
ResourceId objId, WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLCommandQueue, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
m_ObjcBridge = AllocateObjCBridge(this);
AllocateObjCBridge(this);
}
template <typename SerialiserType>
@@ -55,7 +55,7 @@ WrappedMTLCommandBuffer *WrappedMTLCommandQueue::commandBuffer()
SERIALISE_TIME_CALL(realMTLCommandBuffer = Unwrap(this)->commandBuffer());
WrappedMTLCommandBuffer *wrappedMTLCommandBuffer;
ResourceId id = GetResourceManager()->WrapResource(realMTLCommandBuffer, wrappedMTLCommandBuffer);
wrappedMTLCommandBuffer->SetWrappedMTLCommandQueue(this);
wrappedMTLCommandBuffer->SetCommandQueue(this);
if(IsCaptureMode(m_State))
{
@@ -31,14 +31,18 @@
// ObjCBridgeMTLCommandQueue specific
- (id<MTLCommandQueue>)real
{
return id<MTLCommandQueue>(Unwrap(self.wrappedCPP));
return id<MTLCommandQueue>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLCommandQueue to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
@@ -73,12 +77,12 @@
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCBridgeMTLDevice());
return id<MTLDevice>(GetWrapped(self)->GetDevice());
}
- (nullable id<MTLCommandBuffer>)commandBuffer
{
return id<MTLCommandBuffer>(GetObjCBridge(self.wrappedCPP->commandBuffer()));
return id<MTLCommandBuffer>(GetWrapped(self)->commandBuffer());
}
- (nullable id<MTLCommandBuffer>)commandBufferWithDescriptor:(MTLCommandBufferDescriptor *)descriptor
+3 -3
View File
@@ -109,11 +109,11 @@ enum class MetalChunk : uint32_t
DECLARE_REFLECTION_ENUM(MetalChunk);
// must be at the start of any function that serialises
#define CACHE_THREAD_SERIALISER() WriteSerialiser &ser = m_WrappedMTLDevice->GetThreadSerialiser();
#define CACHE_THREAD_SERIALISER() WriteSerialiser &ser = m_Device->GetThreadSerialiser();
#define SERIALISE_TIME_CALL(...) \
{ \
WriteSerialiser &ser = m_WrappedMTLDevice->GetThreadSerialiser(); \
WriteSerialiser &ser = m_Device->GetThreadSerialiser(); \
ser.ChunkMetadata().timestampMicro = Timing::GetTick(); \
__VA_ARGS__; \
ser.ChunkMetadata().durationMicro = Timing::GetTick() - ser.ChunkMetadata().timestampMicro; \
@@ -142,7 +142,7 @@ DECLARE_REFLECTION_ENUM(MetalChunk);
// path at compile-time, and the second because we might be just struct-serialising in which case we
// should be doing no work to restore states.
// Writing is unambiguously during capture mode, so we don't have to check both in that case.
#define IsReplayingAndReading() (ser.IsReading() && IsReplayMode(m_WrappedMTLDevice->GetState()))
#define IsReplayingAndReading() (ser.IsReading() && IsReplayMode(m_Device->GetState()))
#ifdef __OBJC__
#define METAL_NOT_HOOKED() \
+3 -3
View File
@@ -31,12 +31,12 @@
WrappedMTLDevice::WrappedMTLDevice(MTL::Device *realMTLDevice, ResourceId objId)
: WrappedMTLObject(realMTLDevice, objId, this, GetStateRef())
{
m_ObjcBridge = AllocateObjCBridge(this);
m_WrappedMTLDevice = this;
AllocateObjCBridge(this);
m_Device = this;
threadSerialiserTLSSlot = Threading::AllocateTLSSlot();
m_ResourceManager = new MetalResourceManager(m_State, this);
RDCASSERT(m_WrappedMTLDevice == this);
RDCASSERT(m_Device == this);
GetResourceManager()->AddCurrentResource(objId, this);
}
+36 -32
View File
@@ -34,14 +34,18 @@
// ObjCBridgeMTLDevice specific
- (id<MTLDevice>)real
{
return id<MTLDevice>(Unwrap(self.wrappedCPP));
return id<MTLDevice>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLDevice to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
@@ -123,37 +127,37 @@
- (BOOL)isDepth24Stencil8PixelFormatSupported API_AVAILABLE(macos(10.11), macCatalyst(13.0))
API_UNAVAILABLE(ios)
{
return self.wrappedCPP->isDepth24Stencil8PixelFormatSupported();
return GetWrapped(self)->isDepth24Stencil8PixelFormatSupported();
}
- (MTLReadWriteTextureTier)readWriteTextureSupport API_AVAILABLE(macos(10.13), ios(11.0))
{
return (MTLReadWriteTextureTier)self.wrappedCPP->readWriteTextureSupport();
return (MTLReadWriteTextureTier)GetWrapped(self)->readWriteTextureSupport();
}
- (MTLArgumentBuffersTier)argumentBuffersSupport API_AVAILABLE(macos(10.13), ios(11.0))
{
return (MTLArgumentBuffersTier)self.wrappedCPP->argumentBuffersSupport();
return (MTLArgumentBuffersTier)GetWrapped(self)->argumentBuffersSupport();
}
- (BOOL)areRasterOrderGroupsSupported API_AVAILABLE(macos(10.13), ios(11.0))
{
return self.wrappedCPP->areRasterOrderGroupsSupported();
return GetWrapped(self)->areRasterOrderGroupsSupported();
}
- (BOOL)supports32BitFloatFiltering API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supports32BitFloatFiltering();
return GetWrapped(self)->supports32BitFloatFiltering();
}
- (BOOL)supports32BitMSAA API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supports32BitMSAA();
return GetWrapped(self)->supports32BitMSAA();
}
- (BOOL)supportsQueryTextureLOD API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsQueryTextureLOD();
return GetWrapped(self)->supportsQueryTextureLOD();
}
- (BOOL)supportsBCTextureCompression API_AVAILABLE(macos(11.0))
@@ -162,21 +166,21 @@
API_UNAVAILABLE(ios)
#endif // #if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
{
return self.wrappedCPP->supportsBCTextureCompression();
return GetWrapped(self)->supportsBCTextureCompression();
}
- (BOOL)supportsPullModelInterpolation API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsPullModelInterpolation();
return GetWrapped(self)->supportsPullModelInterpolation();
}
- (BOOL)areBarycentricCoordsSupported API_AVAILABLE(macos(10.15))API_UNAVAILABLE(ios)
{
return self.wrappedCPP->areBarycentricCoordsSupported();
return GetWrapped(self)->areBarycentricCoordsSupported();
}
- (BOOL)supportsShaderBarycentricCoordinates API_AVAILABLE(macos(10.15))API_UNAVAILABLE(ios)
{
return self.wrappedCPP->supportsShaderBarycentricCoordinates();
return GetWrapped(self)->supportsShaderBarycentricCoordinates();
}
- (NSUInteger)currentAllocatedSize API_AVAILABLE(macos(10.13), ios(11.0))
@@ -186,7 +190,7 @@
- (nullable id<MTLCommandQueue>)newCommandQueue
{
return id<MTLCommandQueue>(GetObjCBridge(self.wrappedCPP->newCommandQueue()));
return id<MTLCommandQueue>(GetWrapped(self)->newCommandQueue());
}
- (nullable id<MTLCommandQueue>)newCommandQueueWithMaxCommandBufferCount:(NSUInteger)maxCommandBufferCount
@@ -288,7 +292,7 @@
- (nullable id<MTLLibrary>)newDefaultLibrary
{
return id<MTLLibrary>(GetObjCBridge(self.wrappedCPP->newDefaultLibrary()));
return id<MTLLibrary>(GetWrapped(self)->newDefaultLibrary());
}
- (nullable id<MTLLibrary>)newDefaultLibraryWithBundle:(NSBundle *)bundle
@@ -325,8 +329,8 @@
options:(nullable MTLCompileOptions *)options
error:(__autoreleasing NSError **)error
{
return (id<MTLLibrary>)(GetObjCBridge(self.wrappedCPP->newLibraryWithSource(
(NS::String *)source, (MTL::CompileOptions *)options, (NS::Error **)error)));
return (id<MTLLibrary>)(GetWrapped(self)->newLibraryWithSource(
(NS::String *)source, (MTL::CompileOptions *)options, (NS::Error **)error));
}
- (void)newLibraryWithSource:(NSString *)source
@@ -472,17 +476,17 @@ newComputePipelineStateWithDescriptor:(MTLComputePipelineDescriptor *)descriptor
- (BOOL)supportsFeatureSet:(MTLFeatureSet)featureSet
{
return self.wrappedCPP->supportsFeatureSet((MTL::FeatureSet)featureSet);
return GetWrapped(self)->supportsFeatureSet((MTL::FeatureSet)featureSet);
}
- (BOOL)supportsFamily:(MTLGPUFamily)gpuFamily API_AVAILABLE(macos(10.15), ios(13.0))
{
return self.wrappedCPP->supportsFamily((MTL::GPUFamily)gpuFamily);
return GetWrapped(self)->supportsFamily((MTL::GPUFamily)gpuFamily);
}
- (BOOL)supportsTextureSampleCount:(NSUInteger)sampleCount API_AVAILABLE(macos(10.11), ios(9.0))
{
return self.wrappedCPP->supportsTextureSampleCount(sampleCount);
return GetWrapped(self)->supportsTextureSampleCount(sampleCount);
}
- (NSUInteger)minimumLinearTextureAlignmentForPixelFormat:(MTLPixelFormat)format
@@ -537,7 +541,7 @@ newRenderPipelineStateWithTileDescriptor:(MTLTileRenderPipelineDescriptor *)desc
- (BOOL)areProgrammableSamplePositionsSupported API_AVAILABLE(macos(10.13), ios(11.0))
{
return self.wrappedCPP->areProgrammableSamplePositionsSupported();
return GetWrapped(self)->areProgrammableSamplePositionsSupported();
}
- (void)getDefaultSamplePositions:(MTLSamplePosition *)positions
@@ -557,7 +561,7 @@ newRenderPipelineStateWithTileDescriptor:(MTLTileRenderPipelineDescriptor *)desc
- (BOOL)supportsRasterizationRateMapWithLayerCount:(NSUInteger)layerCount
API_AVAILABLE(macos(10.15.4), ios(13.0), macCatalyst(13.4))
{
return self.wrappedCPP->supportsRasterizationRateMapWithLayerCount(layerCount);
return GetWrapped(self)->supportsRasterizationRateMapWithLayerCount(layerCount);
}
- (nullable id<MTLRasterizationRateMap>)newRasterizationRateMapWithDescriptor:
@@ -687,24 +691,24 @@ newIndirectCommandBufferWithDescriptor:(MTLIndirectCommandBufferDescriptor *)des
- (BOOL)supportsCounterSampling:(MTLCounterSamplingPoint)samplingPoint
API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsCounterSampling((MTL::CounterSamplingPoint)samplingPoint);
return GetWrapped(self)->supportsCounterSampling((MTL::CounterSamplingPoint)samplingPoint);
}
- (BOOL)supportsVertexAmplificationCount:(NSUInteger)count
API_AVAILABLE(macos(10.15.4), ios(13.0), macCatalyst(13.4))
{
return self.wrappedCPP->supportsVertexAmplificationCount(count);
return GetWrapped(self)->supportsVertexAmplificationCount(count);
}
- (BOOL)supportsDynamicLibraries API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsDynamicLibraries();
return GetWrapped(self)->supportsDynamicLibraries();
}
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
- (BOOL)supportsRenderDynamicLibraries API_AVAILABLE(macos(12.0), ios(15.0))
{
return self.wrappedCPP->supportsRenderDynamicLibraries();
return GetWrapped(self)->supportsRenderDynamicLibraries();
}
#endif
@@ -734,7 +738,7 @@ newIndirectCommandBufferWithDescriptor:(MTLIndirectCommandBufferDescriptor *)des
- (BOOL)supportsRaytracing API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsRaytracing();
return GetWrapped(self)->supportsRaytracing();
}
- (MTLAccelerationStructureSizes)accelerationStructureSizesWithDescriptor:
@@ -760,20 +764,20 @@ newIndirectCommandBufferWithDescriptor:(MTLIndirectCommandBufferDescriptor *)des
- (BOOL)supportsFunctionPointers API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsFunctionPointers();
return GetWrapped(self)->supportsFunctionPointers();
}
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
- (BOOL)supportsFunctionPointersFromRender API_AVAILABLE(macos(12.0), ios(15.0))
{
return self.wrappedCPP->supportsFunctionPointersFromRender();
return GetWrapped(self)->supportsFunctionPointersFromRender();
}
#endif
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
- (BOOL)supportsRaytracingFromRender API_AVAILABLE(macos(12.0), ios(15.0))
{
return self.wrappedCPP->supportsRaytracingFromRender();
return GetWrapped(self)->supportsRaytracingFromRender();
}
#endif
@@ -782,7 +786,7 @@ newIndirectCommandBufferWithDescriptor:(MTLIndirectCommandBufferDescriptor *)des
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0
- (BOOL)supportsPrimitiveMotionBlur API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.wrappedCPP->supportsPrimitiveMotionBlur();
return GetWrapped(self)->supportsPrimitiveMotionBlur();
}
#endif
+1 -1
View File
@@ -29,5 +29,5 @@ WrappedMTLFunction::WrappedMTLFunction(MTL::Function *realMTLFunction, ResourceI
WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLFunction, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
m_ObjcBridge = AllocateObjCBridge(this);
AllocateObjCBridge(this);
}
@@ -31,14 +31,18 @@
// ObjCBrdigeMTLFunction specific
- (id<MTLFunction>)real
{
return id<MTLFunction>(Unwrap(self.wrappedCPP));
return id<MTLFunction>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLFunction to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
@@ -73,7 +77,7 @@
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCBridgeMTLDevice());
return id<MTLDevice>(GetWrapped(self)->GetDevice());
}
- (MTLFunctionType)functionType
+1 -2
View File
@@ -54,8 +54,7 @@ id<MTLDevice> METAL_EXPORT_NAME(MTLCreateSystemDefaultDevice)(void)
}
id<MTLDevice> device = METAL.MTLCreateSystemDefaultDevice();
return id<MTLDevice>(
GetObjCBridge(WrappedMTLDevice::MTLCreateSystemDefaultDevice((MTL::Device *)device)));
return id<MTLDevice>(WrappedMTLDevice::MTLCreateSystemDefaultDevice((MTL::Device *)device));
}
/*
+1 -1
View File
@@ -30,7 +30,7 @@ WrappedMTLLibrary::WrappedMTLLibrary(MTL::Library *realMTLLibrary, ResourceId ob
WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLLibrary, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
m_ObjcBridge = AllocateObjCBridge(this);
AllocateObjCBridge(this);
}
template <typename SerialiserType>
@@ -31,14 +31,18 @@
// ObjCBridgeMTLLibrary specific
- (id<MTLLibrary>)real
{
return id<MTLLibrary>(Unwrap(self.wrappedCPP));
return id<MTLLibrary>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLLibrary to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
@@ -73,13 +77,12 @@
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCBridgeMTLDevice());
return id<MTLDevice>(GetWrapped(self)->GetDevice());
}
- (nullable id<MTLFunction>)newFunctionWithName:(NSString *)functionName
{
return id<MTLFunction>(
GetObjCBridge(self.wrappedCPP->newFunctionWithName((NS::String *)functionName)));
return id<MTLFunction>(GetWrapped(self)->newFunctionWithName((NS::String *)functionName));
}
- (nullable id<MTLFunction>)newFunctionWithName:(NSString *)name
+5 -5
View File
@@ -33,28 +33,28 @@ bool MetalResourceManager::ResourceTypeRelease(WrappedResourceType res)
bool MetalResourceManager::Prepare_InitialState(WrappedMTLObject *res)
{
return m_WrappedMTLDevice->Prepare_InitialState(res);
return m_Device->Prepare_InitialState(res);
}
uint64_t MetalResourceManager::GetSize_InitialState(ResourceId id, const MetalInitialContents &initial)
{
return m_WrappedMTLDevice->GetSize_InitialState(id, initial);
return m_Device->GetSize_InitialState(id, initial);
}
bool MetalResourceManager::Serialise_InitialState(WriteSerialiser &ser, ResourceId id,
MetalResourceRecord *record,
const MetalInitialContents *initial)
{
return m_WrappedMTLDevice->Serialise_InitialState(ser, id, record, initial);
return m_Device->Serialise_InitialState(ser, id, record, initial);
}
void MetalResourceManager::Create_InitialState(ResourceId id, WrappedMTLObject *live, bool hasData)
{
return m_WrappedMTLDevice->Create_InitialState(id, live, hasData);
return m_Device->Create_InitialState(id, live, hasData);
}
void MetalResourceManager::Apply_InitialState(WrappedMTLObject *live,
const MetalInitialContents &initial)
{
return m_WrappedMTLDevice->Apply_InitialState(live, initial);
return m_Device->Apply_InitialState(live, initial);
}
+4 -4
View File
@@ -65,7 +65,7 @@ class MetalResourceManager : public ResourceManager<MetalResourceManagerConfigur
{
public:
MetalResourceManager(CaptureState &state, WrappedMTLDevice *device)
: ResourceManager(state), m_WrappedMTLDevice(device)
: ResourceManager(state), m_Device(device)
{
}
void SetState(CaptureState state) { m_State = state; }
@@ -103,11 +103,11 @@ public:
ResourceId WrapResource(realtype obj, typename UnwrapHelper<realtype>::Outer *&wrapped)
{
RDCASSERT(obj != NULL);
RDCASSERT(m_WrappedMTLDevice != NULL);
RDCASSERT(m_Device != NULL);
ResourceId id = ResourceIDGen::GetNewUniqueID();
using WrappedType = typename UnwrapHelper<realtype>::Outer;
wrapped = new WrappedType(obj, id, m_WrappedMTLDevice);
wrapped = new WrappedType(obj, id, m_Device);
wrapped->m_Real = obj;
AddCurrentResource(id, wrapped);
@@ -147,5 +147,5 @@ private:
void Apply_InitialState(WrappedMTLObject *live, const MetalInitialContents &initial);
// ResourceManager interface
WrappedMTLDevice *m_WrappedMTLDevice;
WrappedMTLDevice *m_Device;
};
+3 -13
View File
@@ -37,13 +37,8 @@ ResourceId GetResID(WrappedMTLObject *obj)
return obj->m_ID;
}
#define IMPLEMENT_WRAPPED_TYPE_HELPERS(CPPTYPE) \
MTL::CPPTYPE *Unwrap(WrappedMTL##CPPTYPE *obj) { return Unwrap<MTL::CPPTYPE *>(obj); } \
MTL::CPPTYPE *GetObjCBridge(WrappedMTL##CPPTYPE *obj) \
{ \
return GetObjCBridge<MTL::CPPTYPE *>(obj); \
}
#define IMPLEMENT_WRAPPED_TYPE_HELPERS(CPPTYPE) \
MTL::CPPTYPE *Unwrap(WrappedMTL##CPPTYPE *obj) { return Unwrap<MTL::CPPTYPE *>(obj); }
METALCPP_WRAPPED_PROTOCOLS(IMPLEMENT_WRAPPED_TYPE_HELPERS)
#undef IMPLEMENT_WRAPPED_TYPE_HELPERS
@@ -54,12 +49,7 @@ void WrappedMTLObject::Dealloc()
MetalResourceManager *WrappedMTLObject::GetResourceManager()
{
return m_WrappedMTLDevice->GetResourceManager();
}
MTL::Device *WrappedMTLObject::GetObjCBridgeMTLDevice()
{
return GetObjCBridge(m_WrappedMTLDevice);
return m_Device->GetResourceManager();
}
MetalResourceRecord::~MetalResourceRecord()
+13 -33
View File
@@ -48,36 +48,26 @@ struct WrappedMTLObject
{
WrappedMTLObject() = delete;
WrappedMTLObject(WrappedMTLDevice *wrappedMTLDevice, CaptureState &captureState)
: m_ObjcBridge(NULL),
m_Real(NULL),
m_Record(NULL),
m_WrappedMTLDevice(wrappedMTLDevice),
m_State(captureState)
: m_Real(NULL), m_Device(wrappedMTLDevice), m_State(captureState)
{
}
WrappedMTLObject(void *mtlObject, ResourceId objId, WrappedMTLDevice *wrappedMTLDevice,
CaptureState &captureState)
: m_ObjcBridge(NULL),
m_Real(mtlObject),
m_ID(objId),
m_Record(NULL),
m_WrappedMTLDevice(wrappedMTLDevice),
m_State(captureState)
: m_Real(mtlObject), m_ID(objId), m_Device(wrappedMTLDevice), m_State(captureState)
{
}
~WrappedMTLObject() = default;
void Dealloc();
MTL::Device *GetObjCBridgeMTLDevice();
MTL::Device *GetDevice() { return (MTL::Device *)m_Device; }
MetalResourceManager *GetResourceManager();
void *m_ObjcBridge;
void *m_ObjcBridge = NULL;
void *m_Real;
ResourceId m_ID;
MetalResourceRecord *m_Record;
WrappedMTLDevice *m_WrappedMTLDevice;
MetalResourceRecord *m_Record = NULL;
WrappedMTLDevice *m_Device;
CaptureState &m_State;
};
@@ -101,29 +91,19 @@ RealType Unwrap(WrappedMTLObject *obj)
return (RealType)obj->m_Real;
}
template <typename RealType>
RealType GetObjCBridge(WrappedMTLObject *obj)
{
if(obj == NULL)
return RealType();
return (RealType)obj->m_ObjcBridge;
}
// template magic voodoo to unwrap types
template <typename inner>
struct UnwrapHelper
{
};
#define WRAPPED_TYPE_HELPERS(CPPTYPE) \
template <> \
struct UnwrapHelper<MTL::CPPTYPE *> \
{ \
typedef CONCAT(WrappedMTL, CPPTYPE) Outer; \
}; \
extern MTL::CPPTYPE *Unwrap(WrappedMTL##CPPTYPE *obj); \
extern MTL::CPPTYPE *GetObjCBridge(WrappedMTL##CPPTYPE *obj);
#define WRAPPED_TYPE_HELPERS(CPPTYPE) \
template <> \
struct UnwrapHelper<MTL::CPPTYPE *> \
{ \
typedef CONCAT(WrappedMTL, CPPTYPE) Outer; \
}; \
extern MTL::CPPTYPE *Unwrap(WrappedMTL##CPPTYPE *obj);
METALCPP_WRAPPED_PROTOCOLS(WRAPPED_TYPE_HELPERS)
#undef WRAPPED_TYPE_HELPERS
+26
View File
@@ -35,6 +35,32 @@ RDCCOMPILE_ASSERT(sizeof(NS::Integer) == sizeof(std::intptr_t), "NS::Integer siz
RDCCOMPILE_ASSERT(sizeof(NS::UInteger) == sizeof(std::uintptr_t),
"NS::UInteger size does not match");
#define DEFINE_OBJC_HELPERS(CPPTYPE) \
void AllocateObjCBridge(WrappedMTL##CPPTYPE *wrappedCPP) \
{ \
RDCCOMPILE_ASSERT((offsetof(WrappedMTL##CPPTYPE, m_ObjcBridge) == 0), \
"m_ObjcBridge must be at offsetof 0"); \
const char *const className = "ObjCBridgeMTL" #CPPTYPE; \
static Class klass = objc_lookUpClass(className); \
static size_t classSize = class_getInstanceSize(klass); \
if(classSize != sizeof(wrappedCPP->m_ObjcBridge)) \
{ \
RDCFATAL("'%s' classSize != sizeof(m_ObjcBridge) %lu != %lu", className, classSize, \
sizeof(wrappedCPP->m_ObjcBridge)); \
} \
wrappedCPP->m_ObjcBridge = klass; \
MTL::CPPTYPE *real = (MTL::CPPTYPE *)wrappedCPP->m_Real; \
if(real) \
{ \
id objc = (id)&wrappedCPP->m_ObjcBridge; \
objc_setAssociatedObject((id)real, objc, objc, OBJC_ASSOCIATION_RETAIN); \
((MTL::CPPTYPE *)objc)->release(); \
} \
}
METALCPP_WRAPPED_PROTOCOLS(DEFINE_OBJC_HELPERS)
#undef DEFINE_OBJC_HELPERS
// serialisation of object handles via IDs.
template <class SerialiserType, class type>
void DoSerialiseViaResourceId(SerialiserType &ser, type &el)
+7 -7
View File
@@ -50,13 +50,13 @@
METALCPP_WRAPPED_PROTOCOLS(DECLARE_WRAPPED_TYPE_SERIALISE);
#undef DECLARE_WRAPPED_TYPE_SERIALISE
#define DECLARE_OBJC_HELPERS(CPPTYPE) \
class WrappedMTL##CPPTYPE; \
extern WrappedMTL##CPPTYPE *GetWrapped(MTL::CPPTYPE *objCWrapped); \
extern MTL::CPPTYPE *GetReal(MTL::CPPTYPE *objCWrapped); \
extern bool IsObjCBridge(MTL::CPPTYPE *objCWrapped); \
extern ResourceId GetResID(MTL::CPPTYPE *objCWrapped); \
extern MTL::CPPTYPE *AllocateObjCBridge(WrappedMTL##CPPTYPE *wrapped);
#define DECLARE_OBJC_HELPERS(CPPTYPE) \
class WrappedMTL##CPPTYPE; \
inline WrappedMTL##CPPTYPE *GetWrapped(MTL::CPPTYPE *cppType) \
{ \
return (WrappedMTL##CPPTYPE *)cppType; \
} \
extern void AllocateObjCBridge(WrappedMTL##CPPTYPE *wrapped);
METALCPP_WRAPPED_PROTOCOLS(DECLARE_OBJC_HELPERS)
#undef DECLARE_OBJC_HELPERS
+7 -5
View File
@@ -29,11 +29,13 @@
#import <Metal/Metal.h>
// clang-format off
#define DECLARE_OBJC_WRAPPED_INTERFACES(CPPTYPE) \
@interface ObjCBridgeMTL##CPPTYPE : NSObject<MTL##CPPTYPE> \
@property(assign) WrappedMTL##CPPTYPE *wrappedCPP; \
@property(readonly) id<MTL##CPPTYPE> real; \
@end
#define DECLARE_OBJC_WRAPPED_INTERFACES(CPPTYPE) \
@interface ObjCBridgeMTL##CPPTYPE : NSObject<MTL##CPPTYPE> \
@end \
inline WrappedMTL##CPPTYPE *GetWrapped(ObjCBridgeMTL##CPPTYPE *objCWrapped) \
{ \
return (WrappedMTL##CPPTYPE *)objCWrapped; \
}
// clang-format on
METALCPP_WRAPPED_PROTOCOLS(DECLARE_OBJC_WRAPPED_INTERFACES)
@@ -1,87 +0,0 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "metal_types_bridge.h"
#include "metal_command_buffer.h"
#include "metal_command_queue.h"
#include "metal_device.h"
#include "metal_function.h"
#include "metal_library.h"
#define DEFINE_OBJC_HELPERS(CPPTYPE) \
static ObjCBridgeMTL##CPPTYPE *GetObjCBridge(MTL::CPPTYPE *cppType) \
{ \
if(cppType == NULL) \
{ \
return NULL; \
} \
ObjCBridgeMTL##CPPTYPE *objC = (ObjCBridgeMTL##CPPTYPE *)cppType; \
RDCASSERT([objC isKindOfClass:[ObjCBridgeMTL##CPPTYPE class]]); \
return objC; \
} \
\
WrappedMTL##CPPTYPE *GetWrapped(MTL::CPPTYPE *cppType) \
{ \
ObjCBridgeMTL##CPPTYPE *objC = GetObjCBridge(cppType); \
return objC.wrappedCPP; \
} \
\
MTL::CPPTYPE *GetReal(MTL::CPPTYPE *cppType) \
{ \
ObjCBridgeMTL##CPPTYPE *objC = GetObjCBridge(cppType); \
MTL::CPPTYPE *real = (MTL::CPPTYPE *)objC.real; \
return real; \
} \
\
bool IsObjCBridge(MTL::CPPTYPE *cppType) \
{ \
ObjCBridgeMTL##CPPTYPE *objC = (ObjCBridgeMTL##CPPTYPE *)cppType; \
return [objC isKindOfClass:[ObjCBridgeMTL##CPPTYPE class]]; \
} \
\
ResourceId GetResID(MTL::CPPTYPE *cppType) \
{ \
WrappedMTL##CPPTYPE *wrappedCPP = GetWrapped(cppType); \
if(wrappedCPP == NULL) \
{ \
return ResourceId(); \
} \
return wrappedCPP->m_ID; \
} \
\
MTL::CPPTYPE *AllocateObjCBridge(WrappedMTL##CPPTYPE *wrappedCPP) \
{ \
ObjCBridgeMTL##CPPTYPE *objC = [ObjCBridgeMTL##CPPTYPE alloc]; \
objC.wrappedCPP = wrappedCPP; \
MTL::CPPTYPE *real = (MTL::CPPTYPE *)objC.real; \
if(real) \
{ \
objc_setAssociatedObject((id)real, objC, (id)objC, OBJC_ASSOCIATION_RETAIN); \
[objC release]; \
} \
return (MTL::CPPTYPE *)objC; \
}
METALCPP_WRAPPED_PROTOCOLS(DEFINE_OBJC_HELPERS)
#undef DEFINE_OBJC_HELPERS