11#include " SharedMTL.h"
22
3+ #include " CommandQueueMTL.h"
4+
35#include " DeviceMTL.h"
46
57using namespace nri ;
@@ -48,15 +50,18 @@ static bool FindMTLGpuFamily(id<MTLDevice> device,
4850
4951
5052
51-
52- DeviceMTL::DeviceMTL (const CallbackInterface& callbacks, const StdAllocator<uint8_t >& stdAllocator)
53- : DeviceBase(callbacks, stdAllocator) {
53+ DeviceMTL::DeviceMTL (const CallbackInterface& callbacks, const StdAllocator<uint8_t >& stdAllocator) : DeviceBase(callbacks, stdAllocator) {
5454 m_Desc.graphicsAPI = GraphicsAPI::VK;
5555 m_Desc.nriVersionMajor = NRI_VERSION_MAJOR;
5656 m_Desc.nriVersionMinor = NRI_VERSION_MINOR;
5757
5858}
5959
60+
61+ void DeviceMTL::Destruct () {
62+ Destroy (GetStdAllocator (), this );
63+ }
64+
6065DeviceMTL::~DeviceMTL () {
6166
6267}
@@ -74,7 +79,31 @@ static bool FindMTLGpuFamily(id<MTLDevice> device,
7479
7580
7681Result DeviceMTL::GetCommandQueue (CommandQueueType commandQueueType, CommandQueue*& commandQueue) {
77- return Result::SUCCESS;
82+ ExclusiveScope lock (m_Lock);
83+
84+ // Check if already created (or wrapped)
85+ uint32_t index = (uint32_t )commandQueueType;
86+ if (m_CommandQueues[index]) {
87+ commandQueue = (CommandQueue*)m_CommandQueues[index];
88+ return Result::SUCCESS;
89+ }
90+
91+ // Check if supported
92+ // uint32_t queueFamilyIndex = m_QueueFamilyIndices[index];
93+ // if (queueFamilyIndex == INVALID_FAMILY_INDEX) {
94+ // commandQueue = nullptr;
95+ // return Result::UNSUPPORTED;
96+ // }
97+
98+ // Create
99+ // VkQueue handle = VK_NULL_HANDLE;
100+ // m_VK.GetDeviceQueue(m_Device, queueFamilyIndex, 0, &handle);
101+
102+ Result result = CreateImplementation<CommandQueueMTL>(commandQueue, commandQueueType);
103+ if (result == Result::SUCCESS)
104+ m_CommandQueues[index] = (CommandQueueMTL*)commandQueue;
105+
106+ return result;
78107}
79108
80109// void DeviceMTL::FillCreateInfo(const TextureDesc& textureDesc, MTLTextureDescriptor* info) const {
@@ -90,36 +119,36 @@ static bool FindMTLGpuFamily(id<MTLDevice> device,
90119
91120Result DeviceMTL::Create (const DeviceCreationDesc& deviceCreationDesc, const DeviceCreationMTLDesc& deviceCreationMTLDesc, bool isWrapper) {
92121 m_OwnsNativeObjects = !isWrapper;
93-
122+
94123 if (isWrapper) {
95- // m_Device = deviceCreationMTLDesc.MtlDevice;
124+ // m_Device = deviceCreationMTLDesc.MtlDevice;
96125 }
97-
126+
98127 strncpy (m_Desc.adapterDesc .name , [m_Device.name UTF8String ], sizeof (m_Desc.adapterDesc .name ));
99128 // No vendor id, device id for Apple GPUs
100129 if (strstr (m_Desc.adapterDesc .name , " Apple" )) {
101130 m_Desc.adapterDesc .vendor = nri::Vendor::APPLE;
102- }
103-
131+ }
132+
104133 const uint64_t regID = [m_Device registryID ];
105134 if (regID)
106135 {
107- // IORef<io_registry_entry_t> entry =AcquireIORef(IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(regID)));
108- // if (entry)
109- // {
110- // That returned the IOGraphicsAccelerator nub. Its parent, then, is the actual PCI device.
111- // IORef<io_registry_entry_t> deviceEntry;
112- // if (IORegistryEntryGetParentEntry(entry, kIOServicePlane, &deviceEntry) == kIOReturnSuccess)
113- // {
114- // m_Desc.adapterDesc.vendor = GetVendorFromID(GetEntryProperty(deviceEntry, CFSTR("vendor-id")));
115- // m_Desc.adapterDesc.deviceId = GetEntryProperty(deviceEntry, CFSTR("device-id"));
116- // }
117- // }
136+ // IORef<io_registry_entry_t> entry =AcquireIORef(IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(regID)));
137+ // if (entry)
138+ // {
139+ // That returned the IOGraphicsAccelerator nub. Its parent, then, is the actual PCI device.
140+ // IORef<io_registry_entry_t> deviceEntry;
141+ // if (IORegistryEntryGetParentEntry(entry, kIOServicePlane, &deviceEntry) == kIOReturnSuccess)
142+ // {
143+ // m_Desc.adapterDesc.vendor = GetVendorFromID(GetEntryProperty(deviceEntry, CFSTR("vendor-id")));
144+ // m_Desc.adapterDesc.deviceId = GetEntryProperty(deviceEntry, CFSTR("device-id"));
145+ // }
146+ // }
118147 }
119-
148+
120149 MTLGPUFamily family;
121- // if(!FindMTLGpuFamily(m_Device, family)) {
122- // return Result::UNSUPPORTED;
150+ // if(!FindMTLGpuFamily(m_Device, family)) {
151+ // return Result::UNSUPPORTED;
123152 // }
124153 // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
125154 // TODO: fill desc
0 commit comments