continue instance functions redo

This commit is contained in:
Gregory Wells
2025-08-03 09:55:29 -04:00
parent 77b52b5d2d
commit da20b01638
6 changed files with 57 additions and 29 deletions

View File

@@ -4,10 +4,15 @@
#include <output_device/vulkan_output_devices.h>
#include <vulkan_surface/vulkan_surface.h>
gryphnInstanceFunctionLayers loadVulkanAPILayer() {
return (gryphnInstanceFunctionLayers) {
.createInstance = {vulkanCreateInstance, NULL},
.destroyInstance = {vulkanDestroyInstance, NULL}
};
}
gnInstanceFunctions loadVulkanInstanceFunctions() {
return (gnInstanceFunctions){
.createInstance = (PFN_gnCreateInstance)createVulkanInstance,
.destroyInstance = (PFN_gnDestroyInstance)destroyVulkanInstance,
._gnGetPhysicalDevices = getPhysicalDevices,
._gnPhysicalDeviceCanPresentToSurface = deviceCanPresentToSurface,

View File

@@ -35,7 +35,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
return VK_TRUE;
}
gnReturnCode createVulkanInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance* next) {
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next) {
instance->instance = malloc(sizeof(gnPlatformInstance));
vkStringArrayList extensions = vkStringArrayListCreate();
@@ -101,6 +101,6 @@ gnReturnCode createVulkanInstance(gnInstanceHandle instance, gnInstanceCreateInf
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
}
void destroyVulkanInstance(gnInstanceHandle instance, PFN_gnDestroyInstance* next) {
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next) {
vkDestroyInstance(instance->instance->vk_instance, NULL);
}

View File

@@ -14,8 +14,8 @@ typedef struct gnPlatformInstance_t {
vkUserData userData;
} gnPlatformInstance;
gnReturnCode createVulkanInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance* next);
void destroyVulkanInstance(gnInstanceHandle instance, PFN_gnDestroyInstance* next);
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next);
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next);
typedef const char* vkString;
GN_ARRAY_LIST(vkString);

View File

@@ -18,13 +18,11 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo;
typedef struct gnMacOSWindowSurfaceInfo gnMacOSWindowSurfaceInfo;
#endif
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, void* next);
typedef gnReturnCode (*PFN_gnDestroyInstance)(gnInstanceHandle instance, void* next);
typedef struct gryphnFunctionLayer gryphnFunctionLayer;
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnFunctionLayer* next);
typedef gnReturnCode (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnFunctionLayer* next);
typedef struct gnInstanceFunctions {
PFN_gnCreateInstance createInstance;
PFN_gnDestroyInstance destroyInstance;
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
gnBool (*_gnPhysicalDeviceCanPresentToSurface)(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);

View File

@@ -10,31 +10,47 @@
#include <apis/opengl/loader/opengl_loader.h>
#endif
#include "stdio.h"
#include "core/src/instance/gryphn_instance.h"
// load the speedy API functions or something like that
dispatcher_bool loadAPIInstanceFunctions(dispatcher_layer* layer) {
gnRenderingAPI api = *(gnRenderingAPI*)layer->userData;
gnInstanceFunctions* funcs = (gnInstanceFunctions*)layer->function_array;
gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_NONE: return (gryphnInstanceFunctionLayers){};
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: *funcs = loadVulkanInstanceFunctions();
case GN_RENDERINGAPI_VULKAN: return loadVulkanAPILayer();
#endif
case GN_RENDERINGAPI_SOFTWARE: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_SOFTWARE: return (gryphnInstanceFunctionLayers){};
case GN_RENDERINGAPI_DIRECTX11: return (gryphnInstanceFunctionLayers){};
case GN_RENDERINGAPI_DIRECTX12: return (gryphnInstanceFunctionLayers){};
#ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: *funcs = loadOpenGLInstanceFunctions();
// case GN_RENDERINGAPI_OPENGL: return loadOpenGLInstanceFunctions();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: *funcs = loadMetalInstanceFunctions();
// case GN_RENDERINGAPI_METAL: return loadMetalInstanceFunctions();
#endif
default: *funcs = (gnInstanceFunctions){NULL};
default: return (gryphnInstanceFunctionLayers){};
}
}
// load the speedy API functions or something like that
gnInstanceFunctions loadAPIInstanceFunctions(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gnInstanceFunctions){ NULL };
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanInstanceFunctions();
#endif
case GN_RENDERINGAPI_SOFTWARE: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnInstanceFunctions){ NULL };
#ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: return loadOpenGLInstanceFunctions();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalInstanceFunctions();
#endif
default: return (gnInstanceFunctions){NULL};
}
return dispatcher_true;
}
gnDeviceFunctions loadAPIDeviceFunctions(gnRenderingAPI api) {

View File

@@ -1,4 +1,5 @@
#pragma once
#include "gryphn_instance_functions.h"
#include "gryphn_device_functions.h"
#include "gryphn_command_functions.h"
#include "gryphn_loader_info.h"
@@ -8,6 +9,17 @@
#include "extensions/synchronization/loader/sync_functions.h"
#include "extensions/queues/queues_functions.h"
typedef struct gryphnFunctionLayer {
void* function;
struct gryphnFunctionLayer* next;
} gryphnFunctionLayer;
typedef struct gryphnInstanceFunctionLayers {
gryphnFunctionLayer createInstance; // PFN_gnCreateInstance
gryphnFunctionLayer destroyInstance; // PFN_gnDestroyInstance
} gryphnInstanceFunctionLayers;
gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api);
typedef struct loaderLayer {
// idk why I sperate these info different classes, I should really shove them in one bit class
// they used to be loaded seperatly but I guess there not anymore
@@ -31,9 +43,6 @@ GN_ARRAY_LIST(loaderLayer);
loaderLayer* loaderGetNextLayer(gnInstance instance);
void resetLayer(gnInstance instance);
gnInstanceFunctions loadAPIInstanceFunctions(gnRenderingAPI api);
gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api);
gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api);
dispatcher_bool loadAPIInstanceFunctions(dispatcher_layer* layer);