Added wrapped MTLLibrary & MTLFunction

Not currently created or used
This commit is contained in:
Jake Turner
2022-03-12 05:49:49 +00:00
committed by Baldur Karlsson
parent 596e7f0e11
commit 036a5c8da0
10 changed files with 432 additions and 2 deletions
+6
View File
@@ -12,6 +12,12 @@ set(sources
metal_types_bridge.mm
metal_types_bridge.h
metal_types.h
metal_library.cpp
metal_library.h
metal_library_bridge.mm
metal_function.cpp
metal_function.h
metal_function_bridge.mm
metal_common.h
official/metal-cpp.h
official/metal-cpp.cpp)
+33
View File
@@ -0,0 +1,33 @@
/******************************************************************************
* 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_function.h"
#include "metal_device.h"
WrappedMTLFunction::WrappedMTLFunction(MTL::Function *realMTLFunction, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLFunction, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
wrappedObjC = AllocateObjCWrapper(this);
}
+41
View File
@@ -0,0 +1,41 @@
/******************************************************************************
* 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.
******************************************************************************/
#pragma once
#include "metal_common.h"
class WrappedMTLFunction : public WrappedMTLObject
{
public:
WrappedMTLFunction(MTL::Function *realMTLFunction, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice);
enum
{
TypeEnum = eResFunction
};
private:
};
@@ -0,0 +1,118 @@
/******************************************************************************
* 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_function.h"
#include "metal_types_bridge.h"
// Wrapper for MTLFunction
@implementation ObjCWrappedMTLFunction
// ObjCWrappedMTLFunction specific
- (id<MTLFunction>)real
{
MTL::Function *real = Unwrap<MTL::Function *>(self.wrappedCPP);
return id<MTLFunction>(real);
}
- (void)dealloc
{
self.wrappedCPP->Dealloc();
[super dealloc];
}
// MTLFunction : based on the protocol defined in
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLLibrrary.h
- (NSString *)label API_AVAILABLE(macos(10.12), ios(10.0))
{
return self.real.label;
}
- (void)setLabel:value
{
self.real.label = value;
}
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCWrappedMTLDevice());
}
- (MTLFunctionType)functionType
{
return self.real.functionType;
}
- (MTLPatchType)patchType API_AVAILABLE(macos(10.12), ios(10.0))
{
return self.real.patchType;
}
- (NSInteger)patchControlPointCount API_AVAILABLE(macos(10.12), ios(10.0))
{
return self.real.patchControlPointCount;
}
- (NSArray<MTLVertexAttribute *> *)vertexAttributes
{
return self.real.vertexAttributes;
}
- (NSArray<MTLAttribute *> *)stageInputAttributes API_AVAILABLE(macos(10.12), ios(10.0))
{
return self.real.stageInputAttributes;
}
- (NSString *)name
{
return self.real.name;
}
- (NSDictionary<NSString *, MTLFunctionConstant *> *)functionConstantsDictionary
API_AVAILABLE(macos(10.12), ios(10.0))
{
return self.real.functionConstantsDictionary;
}
- (id<MTLArgumentEncoder>)newArgumentEncoderWithBufferIndex:(NSUInteger)bufferIndex
API_AVAILABLE(macos(10.13), ios(11.0))
{
METAL_NOT_HOOKED();
return [self.real newArgumentEncoderWithBufferIndex:bufferIndex];
}
- (id<MTLArgumentEncoder>)newArgumentEncoderWithBufferIndex:(NSUInteger)bufferIndex
reflection:(MTLAutoreleasedArgument *__nullable)reflection
API_AVAILABLE(macos(10.13), ios(11.0))
{
METAL_NOT_HOOKED();
return [self.real newArgumentEncoderWithBufferIndex:bufferIndex reflection:reflection];
}
- (MTLFunctionOptions)options API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.real.options;
}
@end
+34
View File
@@ -0,0 +1,34 @@
/******************************************************************************
* 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_library.h"
#include "metal_device.h"
#include "metal_function.h"
WrappedMTLLibrary::WrappedMTLLibrary(MTL::Library *realMTLLibrary, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice)
: WrappedMTLObject(realMTLLibrary, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
{
wrappedObjC = AllocateObjCWrapper(this);
}
+41
View File
@@ -0,0 +1,41 @@
/******************************************************************************
* 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.
******************************************************************************/
#pragma once
#include "metal_common.h"
class WrappedMTLLibrary : public WrappedMTLObject
{
public:
WrappedMTLLibrary(MTL::Library *realMTLLibrary, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice);
enum
{
TypeEnum = eResLibrary
};
private:
};
@@ -0,0 +1,152 @@
/******************************************************************************
* 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_library.h"
#include "metal_types_bridge.h"
// Wrapper for MTLLibrary
@implementation ObjCWrappedMTLLibrary
// ObjCWrappedMTLLibrary specific
- (id<MTLLibrary>)real
{
MTL::Library *real = Unwrap<MTL::Library *>(self.wrappedCPP);
return id<MTLLibrary>(real);
}
// Use the real MTLLibrary to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
id fwd = self.real;
return [fwd methodSignatureForSelector:aSelector];
}
// Forward any unknown messages to the real MTLLibrary
- (void)forwardInvocation:(NSInvocation *)invocation
{
SEL aSelector = [invocation selector];
if([self.real respondsToSelector:aSelector])
[invocation invokeWithTarget:self.real];
else
[super forwardInvocation:invocation];
}
// MTLLibrary : based on the protocol defined in
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLLibrrary.h
- (NSString *)label
{
return self.real.label;
}
- (void)setLabel:value
{
self.real.label = value;
}
- (id<MTLDevice>)device
{
return id<MTLDevice>(self.wrappedCPP->GetObjCWrappedMTLDevice());
}
- (nullable id<MTLFunction>)newFunctionWithName:(NSString *)functionName
{
METAL_NOT_HOOKED();
return [self.real newFunctionWithName:functionName];
}
- (nullable id<MTLFunction>)newFunctionWithName:(NSString *)name
constantValues:(MTLFunctionConstantValues *)constantValues
error:(__autoreleasing NSError **)error
API_AVAILABLE(macos(10.12), ios(10.0))
{
METAL_NOT_HOOKED();
return [self.real newFunctionWithName:name constantValues:constantValues error:error];
}
- (void)newFunctionWithName:(NSString *)name
constantValues:(MTLFunctionConstantValues *)constantValues
completionHandler:(void (^)(id<MTLFunction> __nullable function,
NSError *__nullable error))completionHandler
API_AVAILABLE(macos(10.12), ios(10.0))
{
METAL_NOT_HOOKED();
return [self.real newFunctionWithName:name
constantValues:constantValues
completionHandler:completionHandler];
}
- (void)newFunctionWithDescriptor:(nonnull MTLFunctionDescriptor *)descriptor
completionHandler:(void (^)(id<MTLFunction> __nullable function,
NSError *__nullable error))completionHandler
API_AVAILABLE(macos(11.0), ios(14.0))
{
METAL_NOT_HOOKED();
return [self.real newFunctionWithDescriptor:descriptor completionHandler:completionHandler];
}
- (nullable id<MTLFunction>)newFunctionWithDescriptor:(nonnull MTLFunctionDescriptor *)descriptor
error:(__autoreleasing NSError **)error
API_AVAILABLE(macos(11.0), ios(14.0))
{
METAL_NOT_HOOKED();
return [self.real newFunctionWithDescriptor:descriptor error:error];
}
- (void)newIntersectionFunctionWithDescriptor:(nonnull MTLIntersectionFunctionDescriptor *)descriptor
completionHandler:(void (^)(id<MTLFunction> __nullable function,
NSError *__nullable error))completionHandler
API_AVAILABLE(macos(11.0), ios(14.0))
{
METAL_NOT_HOOKED();
return [self.real newIntersectionFunctionWithDescriptor:descriptor
completionHandler:completionHandler];
}
- (nullable id<MTLFunction>)newIntersectionFunctionWithDescriptor:
(nonnull MTLIntersectionFunctionDescriptor *)descriptor
error:(__autoreleasing NSError **)error
API_AVAILABLE(macos(11.0), ios(14.0))
{
METAL_NOT_HOOKED();
return [self.real newIntersectionFunctionWithDescriptor:descriptor error:error];
}
- (NSArray<NSString *> *)functionNames
{
return self.real.functionNames;
}
- (MTLLibraryType)type API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.real.type;
}
- (NSString *)installName API_AVAILABLE(macos(11.0), ios(14.0))
{
return self.real.installName;
}
@end
+5 -2
View File
@@ -24,9 +24,12 @@
#pragma once
#include "official/metal-cpp.h"
#include "metal_common.h"
#define METALCPP_WRAPPED_PROTOCOLS(FUNC) FUNC(Device);
#define METALCPP_WRAPPED_PROTOCOLS(FUNC) \
FUNC(Device); \
FUNC(Function); \
FUNC(Library);
#define DECLARE_OBJC_HELPERS(CPPTYPE) \
class WrappedMTL##CPPTYPE; \
@@ -27,6 +27,7 @@
#include "metal_types.h"
#import <Metal/MTLDevice.h>
#import <Metal/MTLLibrary.h>
// clang-format off
#define DECLARE_OBJC_WRAPPED_INTERFACES(CPPTYPE) \
@@ -24,6 +24,7 @@
#include "metal_types_bridge.h"
#include "metal_device.h"
#include "metal_library.h"
#define DEFINE_OBJC_HELPERS(CPPTYPE) \
MTL::CPPTYPE *AllocateObjCWrapper(WrappedMTL##CPPTYPE *wrappedCPP) \