From c4af74aa52d697cabe15f110eb0035af6fc46220 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Sun, 3 Aug 2025 09:59:19 -0400 Subject: [PATCH] more loader redoing (for instance) --- projects/apis/metal/loader/metal_instance_loader.m | 9 +++++++-- projects/apis/metal/loader/metal_loader.h | 3 +++ projects/apis/metal/src/instance/metal_instance.h | 4 ++-- projects/apis/metal/src/instance/metal_instance.m | 4 ++-- projects/apis/vulkan/loader/vulkan_loader.h | 3 +++ projects/core/src/instance/gryphn_instance.c | 13 +++---------- projects/core/src/instance/gryphn_instance.h | 4 +++- projects/loader/src/gryphn_loader.c | 2 +- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/projects/apis/metal/loader/metal_instance_loader.m b/projects/apis/metal/loader/metal_instance_loader.m index 932cc44..0fef9a7 100644 --- a/projects/apis/metal/loader/metal_instance_loader.m +++ b/projects/apis/metal/loader/metal_instance_loader.m @@ -3,10 +3,15 @@ #include "surface/metal_surface.h" #include "devices/metal_output_devices.h" +gryphnInstanceFunctionLayers metalLoadAPILayer() { + return (gryphnInstanceFunctionLayers) { + .createInstance = { metalCreateInstance, NULL }, + .destroyInstance = { metalDestroyInstance, NULL } + }; +} + gnInstanceFunctions loadMetalInstanceFunctions() { return (gnInstanceFunctions){ - ._gnCreateInstance = createMetalInstance, - ._gnDestroyInstance = destroyMetalInstance, ._gnGetPhysicalDevices = getMetalDevices, ._gnPhysicalDeviceCanPresentToSurface = metalCanDevicePresent, ._gnCreateOutputDevice = createMetalOutputDevice, diff --git a/projects/apis/metal/loader/metal_loader.h b/projects/apis/metal/loader/metal_loader.h index 781b02d..c02bfc1 100644 --- a/projects/apis/metal/loader/metal_loader.h +++ b/projects/apis/metal/loader/metal_loader.h @@ -5,6 +5,9 @@ #include "extensions/synchronization/loader/sync_functions.h" #include "core/gryphn_extensions.h" +typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; +gryphnInstanceFunctionLayers metalLoadAPILayer(); + gnInstanceFunctions loadMetalInstanceFunctions(); gnDeviceFunctions loadMetalDeviceFunctions(); gnCommandFunctions loadMetalCommandFunctions(); diff --git a/projects/apis/metal/src/instance/metal_instance.h b/projects/apis/metal/src/instance/metal_instance.h index e251591..df0c732 100644 --- a/projects/apis/metal/src/instance/metal_instance.h +++ b/projects/apis/metal/src/instance/metal_instance.h @@ -7,5 +7,5 @@ typedef struct gnPlatformInstance_t { NSView* metalContentView; } gnPlatformInstance; -gnReturnCode createMetalInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo); -void destroyMetalInstance(gnInstance instance); +gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next); +void metalDestroyInstance(gnInstance instance, gryphnFunctionLayer* next); diff --git a/projects/apis/metal/src/instance/metal_instance.m b/projects/apis/metal/src/instance/metal_instance.m index 3d33743..c692d09 100644 --- a/projects/apis/metal/src/instance/metal_instance.m +++ b/projects/apis/metal/src/instance/metal_instance.m @@ -1,10 +1,10 @@ #include "metal_instance.h" // metal instances are kinda useless -gnReturnCode createMetalInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo) { +gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next) { if (instance->instance == NULL) instance->instance = malloc(sizeof(gnPlatformInstance)); return GN_SUCCESS; } -void destroyMetalInstance(gnInstance instance) { +void metalDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next) { free(instance->instance); } diff --git a/projects/apis/vulkan/loader/vulkan_loader.h b/projects/apis/vulkan/loader/vulkan_loader.h index 478fffa..200c878 100644 --- a/projects/apis/vulkan/loader/vulkan_loader.h +++ b/projects/apis/vulkan/loader/vulkan_loader.h @@ -6,6 +6,9 @@ #include "extensions/queues/queues_functions.h" #include "core/gryphn_extensions.h" +typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers; +gryphnInstanceFunctionLayers loadVulkanAPILayer(); + gnInstanceFunctions loadVulkanInstanceFunctions(); gnDeviceFunctions loadVulkanDeviceFunctions(); gnCommandFunctions loadVulkanCommandFunctions(); diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index e7ac817..d2f18e3 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -10,10 +10,8 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* *instance = malloc(sizeof(struct gnInstance_t)); (*instance)->hasDebugger = GN_FALSE; (*instance)->layers = loaderLayerArrayListCreate(); - dispatcher_init(&(*instance)->dispatch); - dispatcher_set_function_array_size(&(*instance)->dispatch, sizeof(gnInstanceFunctions)); - dispatcher_create_layer(&(*instance)->dispatch, loadAPIInstanceFunctions, &info->coreAPI); + // (*instance)->functions = loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){ .api = info->coreAPI, @@ -46,17 +44,12 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* (*instance)->currentLayer = ((*instance)->layers.count - 1); for (int i = 0; i < (*instance)->layers.count; i++) (*instance)->layers.data[i].layerIndex = i; (*instance)->callingLayer = &(*instance)->layers.data[(*instance)->layers.count - 1]; - - gnInstanceFunctions* instance_funcs = (gnInstanceFunctions*)((*instance)->dispatch.first_layer->function_array); - gnReturnCode core_code = instance_funcs->_gnCreateInstance((*instance), info); if (unsupportedExtension) return GN_UNLOADED_EXTENSION; - return core_code; + return (*(PFN_gnCreateInstance*)(*instance)->functions.createInstance.function)(*instance, info, (*instance)->functions.createInstance.next); } void gnDestroyInstance(gnInstanceHandle* instance) { if (instance == GN_NULL_HANDLE) return; - - gnInstanceFunctions* instance_funcs = (gnInstanceFunctions*)((*instance)->dispatch.first_layer->function_array); - instance_funcs->_gnDestroyInstance((*instance)); + (*(PFN_gnDestroyInstance*)(*instance)->functions.destroyInstance.function)(*instance, (*instance)->functions.destroyInstance.next); *instance = GN_NULL_HANDLE; } diff --git a/projects/core/src/instance/gryphn_instance.h b/projects/core/src/instance/gryphn_instance.h index c6ba5c4..e837c40 100644 --- a/projects/core/src/instance/gryphn_instance.h +++ b/projects/core/src/instance/gryphn_instance.h @@ -5,7 +5,6 @@ #include "core/gryphn_return_code.h" #include "core/src/instance/gryphn_debugger.h" #include -#include "Dispatcher/dispatcher.h" typedef struct gnApplicationInfo { gnString applicationName; @@ -25,11 +24,14 @@ typedef struct gnInstanceCreateInfo { #ifdef GN_REVEAL_IMPL #include + struct gnInstance_t { struct gnPlatformInstance_t* instance; gnDebuggerCreateInfo debugger; gnBool enabledExtensions[GN_EXT_MAX]; + gryphnInstanceFunctionLayers functions; + loaderLayerArrayList layers; loaderLayer* callingLayer; uint32_t currentLayer; diff --git a/projects/loader/src/gryphn_loader.c b/projects/loader/src/gryphn_loader.c index eebf1d3..71dc7d7 100644 --- a/projects/loader/src/gryphn_loader.c +++ b/projects/loader/src/gryphn_loader.c @@ -26,7 +26,7 @@ gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api) { // case GN_RENDERINGAPI_OPENGL: return loadOpenGLInstanceFunctions(); #endif #ifdef GN_API_METAL - // case GN_RENDERINGAPI_METAL: return loadMetalInstanceFunctions(); + case GN_RENDERINGAPI_METAL: return metalLoadAPILayer(); #endif default: return (gryphnInstanceFunctionLayers){}; }