Use bytebuf to serialise default library data

This commit is contained in:
Jake Turner
2022-03-14 17:36:21 +00:00
committed by Baldur Karlsson
parent 00e8c31255
commit 247e2d7d0b
3 changed files with 7 additions and 15 deletions
+3 -10
View File
@@ -50,21 +50,14 @@ WrappedMTLDevice *WrappedMTLDevice::MTLCreateSystemDefaultDevice(MTL::Device *re
template <typename SerialiserType>
bool WrappedMTLDevice::Serialise_newDefaultLibrary(SerialiserType &ser, WrappedMTLLibrary *library)
{
void *pData;
uint32_t bytesCount;
bytebuf buffer;
if(ser.IsWriting())
{
ObjC::Get_defaultLibraryData(pData, bytesCount);
ObjC::Get_defaultLibraryData(buffer);
}
SERIALISE_ELEMENT_LOCAL(Library, GetResID(library)).TypedAs("MTLLibrary"_lit);
SERIALISE_ELEMENT(bytesCount);
SERIALISE_ELEMENT_ARRAY(pData, bytesCount);
if(ser.IsWriting())
{
free(pData);
}
SERIALISE_ELEMENT(buffer);
SERIALISE_CHECK_READ_ERRORS();
@@ -28,5 +28,5 @@
namespace ObjC
{
void Get_defaultLibraryData(void *&pData, uint32_t &bytesCount);
void Get_defaultLibraryData(bytebuf &buffer);
};
@@ -26,7 +26,7 @@
#import <AppKit/AppKit.h>
#import <Foundation/NSStream.h>
void ObjC::Get_defaultLibraryData(void *&pData, uint32_t &bytesCount)
void ObjC::Get_defaultLibraryData(bytebuf &buffer)
{
NSBundle *mainAppBundle = [NSBundle mainBundle];
NSString *defaultLibaryPath = [mainAppBundle pathForResource:@"default" ofType:@"metallib"];
@@ -34,8 +34,7 @@ void ObjC::Get_defaultLibraryData(void *&pData, uint32_t &bytesCount)
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;
buffer.resize(nsData.length);
memcpy(buffer.data(), nsData.bytes, buffer.size());
dispatch_release(data);
}