1
1
#pragma once
2
+ #ifdef __OBJC__
2
3
#include < Metal/Metal.h>
4
+ typedef id<MTLLibrary> MTLLibrary_t;
5
+ typedef id<MTLFunction> MTLFunction_t;
6
+ typedef id<MTLComputePipelineState> MTLComputePipelineState_t;
7
+ #else
8
+ typedef void MTLCompileOptions;
9
+ typedef void * MTLLibrary_t;
10
+ typedef void * MTLFunction_t;
11
+ typedef void * MTLComputePipelineState_t;
12
+ #endif
13
+
3
14
#include < unordered_map>
4
15
#include < vector>
5
16
@@ -19,43 +30,43 @@ class MetalShaderLibrary {
19
30
compile_options(compile_options_) {}
20
31
MetalShaderLibrary (const MetalShaderLibrary&) = delete;
21
32
virtual ~MetalShaderLibrary () = default ;
22
- inline id<MTLComputePipelineState> getPipelineStateForFunc (
33
+ inline MTLComputePipelineState_t getPipelineStateForFunc (
23
34
const std::string& fname) {
24
35
return getLibraryPipelineState (getLibrary (), fname).first ;
25
36
}
26
- id<MTLComputePipelineState> getPipelineStateForFunc (
37
+ MTLComputePipelineState_t getPipelineStateForFunc (
27
38
const std::string& fname,
28
39
const std::initializer_list<std::string>& params) {
29
40
return getLibraryPipelineState (getLibrary (params), fname).first ;
30
41
}
31
- inline id<MTLFunction> getMTLFunction (const std::string& fname) {
42
+ inline MTLFunction_t getMTLFunction (const std::string& fname) {
32
43
return getLibraryPipelineState (getLibrary (), fname).second ;
33
44
}
34
- id<MTLFunction> getMTLFunction (
45
+ MTLFunction_t getMTLFunction (
35
46
const std::string& fname,
36
47
const std::initializer_list<std::string>& params) {
37
48
return getLibraryPipelineState (getLibrary (params), fname).second ;
38
49
}
39
50
static MetalShaderLibrary& getBundledLibrary ();
40
51
41
52
protected:
42
- virtual id<MTLLibrary> getLibrary ();
43
- virtual id<MTLLibrary> getLibrary (
53
+ virtual MTLLibrary_t getLibrary ();
54
+ virtual MTLLibrary_t getLibrary (
44
55
const std::initializer_list<std::string>& params);
45
- id<MTLLibrary> library = nil ;
56
+ MTLLibrary_t library = nullptr ;
46
57
47
58
private:
48
- std::pair<id<MTLComputePipelineState>, id<MTLFunction>>
49
- getLibraryPipelineState (id<MTLLibrary> lib, const std::string& fname);
50
-
51
- id<MTLLibrary> compileLibrary (const std::string& src);
59
+ std::pair<MTLComputePipelineState_t, MTLFunction_t> getLibraryPipelineState (
60
+ MTLLibrary_t lib,
61
+ const std::string& fname);
62
+ MTLLibrary_t compileLibrary (const std::string& src);
52
63
std::string shaderSource;
53
64
unsigned nparams;
54
65
MTLCompileOptions* compile_options;
55
- std::unordered_map<std::string, id<MTLLibrary> > libMap;
66
+ std::unordered_map<std::string, MTLLibrary_t > libMap;
56
67
std::unordered_map<
57
68
std::string,
58
- std::pair<id<MTLComputePipelineState>, id<MTLFunction> >>
69
+ std::pair<MTLComputePipelineState_t, MTLFunction_t >>
59
70
cplMap;
60
71
};
61
72
0 commit comments