22
33using namespace nri ;
44
5+
6+ static inline bool FindMTLGpuFamily (id <MTLDevice > device, MTLGPUFamily *family);
7+
8+
59BufferMetal::BufferMetal (const CallbackInterface& callbacks, const StdAllocator<uint8_t >& stdAllocator)
610 : DeviceBase(callbacks, stdAllocator) {
711 m_Desc.graphicsAPI = GraphicsAPI::VK;
@@ -23,42 +27,6 @@ Result CreateDeviceMTL(const DeviceCreationMTLDesc& deviceCreationDesc, DeviceBa
2327
2428}
2529
26- // ResultOrError<MTLGPUFamily> GetMTLGPUFamily(id<MTLDevice> device) {
27- // // https://developer.apple.com/documentation/metal/mtldevice/detecting_gpu_features_and_metal_software_versions?language=objc
28- //
29- // if (@available(macOS 10.15, iOS 10.13, *)) {
30- // if ([device supportsFamily:MTLGPUFamilyApple7]) {
31- // return MTLGPUFamily::Apple7;
32- // }
33- // if ([device supportsFamily:MTLGPUFamilyApple6]) {
34- // return MTLGPUFamily::Apple6;
35- // }
36- // if ([device supportsFamily:MTLGPUFamilyApple5]) {
37- // return MTLGPUFamily::Apple5;
38- // }
39- // if ([device supportsFamily:MTLGPUFamilyApple4]) {
40- // return MTLGPUFamily::Apple4;
41- // }
42- // if ([device supportsFamily:MTLGPUFamilyApple3]) {
43- // return MTLGPUFamily::Apple3;
44- // }
45- // if ([device supportsFamily:MTLGPUFamilyApple2]) {
46- // return MTLGPUFamily::Apple2;
47- // }
48- // if ([device supportsFamily:MTLGPUFamilyApple1]) {
49- // return MTLGPUFamily::Apple1;
50- // }
51- //
52- // // This family is no longer supported in the macOS 10.15 SDK but still exists so
53- // // default to it.
54- // return MTLGPUFamily::Mac1;
55- // }
56- //
57- // return DAWN_INTERNAL_ERROR("Unsupported Metal device");
58- // }
59- //
60- // } // anonymous namespace
61-
6230FormatSupportBits DeviceMTL::GetFormatSupport (const Device& device, Format format) {
6331 int currentFamily = HIGHEST_GPU_FAMILY;
6432 for (; currentFamily >= (int )MTLGPUFamilyApple1 ; currentFamily--) {
@@ -69,42 +37,14 @@ Result CreateDeviceMTL(const DeviceCreationMTLDesc& deviceCreationDesc, DeviceBa
6937 }
7038}
7139
72- static inline bool FindMTLGpuFamily (id <MTLDevice > device, MTLGPUFamily * family) {
73- // https://developer.apple.com/documentation/metal/mtldevice/detecting_gpu_features_and_metal_software_versions?language=objc
74- if (@available (macOS 10.15 , iOS 10.13 , *)) {
75- if ([device supportsFamily: MTLGPUFamilyApple7]) {
76- return MTLGPUFamily ::Apple7;
77- }
78- if ([device supportsFamily: MTLGPUFamilyApple6]) {
79- return MTLGPUFamily ::Apple6;
80- }
81- if ([device supportsFamily: MTLGPUFamilyApple5 ]) {
82- return MTLGPUFamily ::Apple5;
83- }
84- if ([device supportsFamily: MTLGPUFamilyApple4 ]) {
85- return MTLGPUFamily ::Apple4;
86- }
87- if ([device supportsFamily: MTLGPUFamilyApple3 ]) {
88- return MTLGPUFamily ::Apple3;
89- }
90- if ([device supportsFamily: MTLGPUFamilyApple2 ]) {
91- return MTLGPUFamily ::Apple2;
92- }
93- if ([device supportsFamily: MTLGPUFamilyApple1 ]) {
94- return MTLGPUFamily ::Apple1;
95- }
9640
97- // This family is no longer supported in the macOS 10.15 SDK but still exists so
98- // default to it.
99- // return MTLGPUFamily::Mac1;
100- (*family) = MTLGPUFamily ::Mac1;
101- return true ;
102- }
41+ Result DeviceMTL::GetCommandQueue (CommandQueueType commandQueueType, CommandQueue*& commandQueue) {
10342
104- return false ;
10543}
10644
10745
46+
47+
10848Result DeviceMTL::Create (const DeviceCreationDesc& deviceCreationDesc, const DeviceCreationMTLDesc& deviceCreationMTLDesc, bool isWrapper) {
10949 m_OwnsNativeObjects = !isWrapper;
11050
@@ -134,9 +74,66 @@ static inline bool FindMTLGpuFamily(id<MTLDevice> device, MTLGPUFamily* family)
13474 }
13575 }
13676
77+ MTLGPUFamily family;
78+ if (!FindMTLGpuFamily (m_Device, family)) {
79+ return Result::UNSUPPORTED;
80+ }
81+ // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
82+ // TODO: fill desc
83+ switch (family) {
84+ case MTLGPUFamily ::Apple1:
85+ break ;
86+ default :
87+ break ;
88+ }
89+
13790 m_Desc.adapterDesc .luid = 0 ;
13891 m_Desc.adapterDesc .videoMemorySize = 0 ;
13992 m_Desc.adapterDesc .systemMemorySize = 0 ;
14093 return Result::SUCCESS;
14194
14295}
96+
97+
98+ static inline bool FindMTLGpuFamily (id <MTLDevice > device,
99+ MTLGPUFamily *family) {
100+ // https://developer.apple.com/documentation/metal/mtldevice/detecting_gpu_features_and_metal_software_versions?language=objc
101+ if (@available (macOS 10.15 , iOS 10.13 , *)) {
102+ if ([device supportsFamily: MTLGPUFamilyApple7]) {
103+ (*family) = MTLGPUFamily ::Apple7;
104+ return true ;
105+ }
106+ if ([device supportsFamily: MTLGPUFamilyApple6]) {
107+ (*family) = MTLGPUFamily ::Apple6;
108+ return true ;
109+ }
110+ if ([device supportsFamily: MTLGPUFamilyApple5 ]) {
111+ (*family) = MTLGPUFamily ::Apple5;
112+ return true ;
113+ }
114+ if ([device supportsFamily: MTLGPUFamilyApple4 ]) {
115+ (*family) = MTLGPUFamily ::Apple4;
116+ return true ;
117+ }
118+ if ([device supportsFamily: MTLGPUFamilyApple3 ]) {
119+ (*family) = MTLGPUFamily ::Apple3;
120+ return true ;
121+ }
122+ if ([device supportsFamily: MTLGPUFamilyApple2 ]) {
123+ (*family) = MTLGPUFamily ::Apple2;
124+ return true ;
125+ }
126+ if ([device supportsFamily: MTLGPUFamilyApple1 ]) {
127+ (*family) = MTLGPUFamily ::Apple1;
128+ return true ;
129+ }
130+
131+ // This family is no longer supported in the macOS 10.15 SDK but still
132+ // exists so default to it.
133+ // return MTLGPUFamily::Mac1;
134+ (*family) = MTLGPUFamily ::Mac1;
135+ return true ;
136+ }
137+ return false ;
138+ }
139+
0 commit comments