Added ObjC::Get_defaultLibraryData

This commit is contained in:
Jake Turner
2022-03-12 19:25:48 +00:00
committed by Baldur Karlsson
parent 07011138dc
commit a764744bc0
3 changed files with 75 additions and 0 deletions
+2
View File
@@ -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)
@@ -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);
};
@@ -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 <AppKit/AppKit.h>
#import <Foundation/NSStream.h>
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);
}