From 4f6e785317cc5499bb1762781ffdc3f955b6f564 Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Sat, 24 May 2025 15:42:48 -0400 Subject: [PATCH] begin rewriting metal classes in objective c --- .../metal/src/core/debugger/metal_debugger.m | 9 ++++++ .../src/core/devices/metal_output_devices.h | 27 ++++++++-------- .../core/devices/metal_physical_device.cpp | 23 -------------- .../src/core/devices/metal_physical_device.m | 31 +++++++++++++++++++ 4 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 rendering_api/metal/src/core/debugger/metal_debugger.m delete mode 100644 rendering_api/metal/src/core/devices/metal_physical_device.cpp create mode 100644 rendering_api/metal/src/core/devices/metal_physical_device.m diff --git a/rendering_api/metal/src/core/debugger/metal_debugger.m b/rendering_api/metal/src/core/debugger/metal_debugger.m new file mode 100644 index 0000000..1a7a43d --- /dev/null +++ b/rendering_api/metal/src/core/debugger/metal_debugger.m @@ -0,0 +1,9 @@ +#include + +// these do nothing because I am too lazy to write a debugger for metal at this point in time +gnReturnCode gnCreateDebuggerFn(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info) { + return GN_SUCCESS; +} +void gnDestroyDebuggerFn(gnDebugger* instance) { + +} diff --git a/rendering_api/metal/src/core/devices/metal_output_devices.h b/rendering_api/metal/src/core/devices/metal_output_devices.h index 9040f0d..7646dae 100644 --- a/rendering_api/metal/src/core/devices/metal_output_devices.h +++ b/rendering_api/metal/src/core/devices/metal_output_devices.h @@ -1,16 +1,15 @@ -// #pragma once -// #include -// #include +#pragma once +#include "core/instance/gryphn_instance.h" +#include "core/output_device/gryphn_output_device.h" +#include +#include -// struct gnPlatformPhysicalOutputDevice { -// MTL::Device* device; -// }; -// struct gnInstance; +struct gnPlatformPhysicalDevice_t { + id device; +} gnPlatformPhysicalDevice; -// struct gnPlatformOutputDevice { -// MTL::Device* device; -// MTL::CommandQueue* commandQueue; -// MTK::View* contentView; - -// gnInstance* instance; -// }; +struct gnPlatformOutputDevice_t { + id device; + // MTLCommandQueue* commandQueue; + MTKView* contentView; +} gnPlatformOutputDevice; diff --git a/rendering_api/metal/src/core/devices/metal_physical_device.cpp b/rendering_api/metal/src/core/devices/metal_physical_device.cpp deleted file mode 100644 index 6c57ab6..0000000 --- a/rendering_api/metal/src/core/devices/metal_physical_device.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// #include -// #include -// #include "metal_output_devices.h" - -// GN_EXPORT gnPhysicalOutputDevice* gnGetPhysicalOutputDevicesFn(const gnInstance& instance, uint32_t* count) { -// // gnList physicalOutputDevices = gnCreateList(); -// NS::Array *devices = MTL::CopyAllDevices(); -// gnPhysicalOutputDevice* devicesList = (gnPhysicalOutputDevice*)malloc(sizeof(gnPhysicalOutputDevice) * devices->count()); -// for (int i = 0; i < devices->count(); i++) { -// devicesList[i].outputDeviceName = reinterpret_cast(devices->object(0))->name()->cString(NS::StringEncoding::UTF8StringEncoding); -// devicesList[i].physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); -// devicesList[i].physicalOutputDevice->device = reinterpret_cast(devices->object(0)); -// } -// *count = devices->count(); -// return devicesList; -// } - -// GN_EXPORT gnBool gnDeviceSupportsAPIFn(const gnPhysicalOutputDevice& device) { -// // so as far as my understanding goes which is not very far I dont think that the -// // method I am using to ge the devices would return a list of devices that are not supported on -// // metal but idk or really care cuz fuck you for using metal -// return true; -// } diff --git a/rendering_api/metal/src/core/devices/metal_physical_device.m b/rendering_api/metal/src/core/devices/metal_physical_device.m new file mode 100644 index 0000000..309683c --- /dev/null +++ b/rendering_api/metal/src/core/devices/metal_physical_device.m @@ -0,0 +1,31 @@ +#include +#include +#include "metal_output_devices.h" +#include "core/window_surface/gryphn_surface.h" + +gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstance* instance, uint32_t* deviceCount) { + NSArray *devices = MTLCopyAllDevices(); + *deviceCount = [devices count]; + gnPhysicalDevice* devicesList = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * *deviceCount); + for (int i = 0; i < *deviceCount; i++) { + devicesList[i].physicalDevice = malloc(sizeof(gnPlatformPhysicalDevice)); + devicesList[i].physicalDevice->device = [devices objectAtIndex:0]; + + id device = [devices objectAtIndex:0]; + devicesList[i].properties.name = gnCreateString([[device name] cStringUsingEncoding:NSUTF8StringEncoding]); + + + // below I am going to fake that there is one queue that can support graphics, compute, and transfer queues + devicesList[i].queueProperties.queueProperties = malloc(sizeof(gnQueueProperties)); + devicesList[i].queueProperties.queueProperties[0] = (gnQueueProperties){ + .queueCount = 1, + .queueType = GN_QUEUE_GRAPHICS | GN_QUEUE_COMPUTE | GN_QUEUE_TRANSFER + }; + } + [devices release]; + return devicesList; +} + +gnBool gnQueueCanPresentToSurfaceFn(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface) { + return gnTrue; // I belive that a window should always be able to present to a surface in metal +}