forked from hupe1980/go-mtl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.m
More file actions
35 lines (27 loc) · 1.05 KB
/
Copy pathlibrary.m
File metadata and controls
35 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// +build darwin
#import <Metal/Metal.h>
#include "library.h"
struct Library Device_NewLibraryWithSource(void * device, const char * source, size_t sourceLength, struct CompileOptions opts) {
MTLCompileOptions *compileOptions = [MTLCompileOptions new];
// Replace deprecated fastMathEnabled with mathMode
if (opts.FastMathEnabled) {
compileOptions.mathMode = MTLMathModeFast;
} else {
compileOptions.mathMode = MTLMathModeDefault;
}
compileOptions.preserveInvariance = opts.PreserveInvariance;
NSError * error;
id<MTLLibrary> library = [(id<MTLDevice>)device
newLibraryWithSource:[[NSString alloc] initWithBytes:source length:sourceLength encoding:NSUTF8StringEncoding]
options:compileOptions
error:&error];
struct Library l;
l.Library = library;
if (!library) {
l.Error = error.localizedDescription.UTF8String;
}
return l;
}
void * Library_NewFunctionWithName(void * library, const char * name) {
return [(id<MTLLibrary>)library newFunctionWithName:[NSString stringWithUTF8String:name]];
}