From a764744bc021b7d248eb02dc39ae11ee289058b8 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Sat, 12 Mar 2022 19:25:48 +0000 Subject: [PATCH] Added ObjC::Get_defaultLibraryData --- renderdoc/driver/metal/CMakeLists.txt | 2 + renderdoc/driver/metal/metal_helpers_bridge.h | 32 +++++++++++++++ .../driver/metal/metal_helpers_bridge.mm | 41 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 renderdoc/driver/metal/metal_helpers_bridge.h create mode 100644 renderdoc/driver/metal/metal_helpers_bridge.mm diff --git a/renderdoc/driver/metal/CMakeLists.txt b/renderdoc/driver/metal/CMakeLists.txt index a325542ac..2a9b78d62 100644 --- a/renderdoc/driver/metal/CMakeLists.txt +++ b/renderdoc/driver/metal/CMakeLists.txt @@ -20,6 +20,8 @@ set(sources metal_function.h metal_function_bridge.mm metal_common.h + metal_helpers_bridge.h + metal_helpers_bridge.mm official/metal-cpp.h official/metal-cpp.cpp) diff --git a/renderdoc/driver/metal/metal_helpers_bridge.h b/renderdoc/driver/metal/metal_helpers_bridge.h new file mode 100644 index 000000000..3d8c5bea1 --- /dev/null +++ b/renderdoc/driver/metal/metal_helpers_bridge.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * 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_types.h" + +namespace ObjC +{ +void Get_defaultLibraryData(void *&pData, uint32_t &bytesCount); +}; diff --git a/renderdoc/driver/metal/metal_helpers_bridge.mm b/renderdoc/driver/metal/metal_helpers_bridge.mm new file mode 100644 index 000000000..d364d6650 --- /dev/null +++ b/renderdoc/driver/metal/metal_helpers_bridge.mm @@ -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. + ******************************************************************************/ + +#include "metal_helpers_bridge.h" +#import +#import + +void ObjC::Get_defaultLibraryData(void *&pData, uint32_t &bytesCount) +{ + NSBundle *mainAppBundle = [NSBundle mainBundle]; + NSString *defaultLibaryPath = [mainAppBundle pathForResource:@"default" ofType:@"metallib"]; + NSData *myData = [NSData dataWithContentsOfFile:defaultLibaryPath]; + dispatch_data_t data = dispatch_data_create( + myData.bytes, myData.length, dispatch_get_main_queue(), DISPATCH_DATA_DESTRUCTOR_DEFAULT); + NSData *nsData = (NSData *)data; + pData = malloc(nsData.length); + memcpy(pData, nsData.bytes, nsData.length); + bytesCount = (uint32_t)nsData.length; + dispatch_release(data); +}