a lot of loader cleanup

This commit is contained in:
Gregory Wells
2025-08-03 11:43:20 -04:00
parent 988333c0ac
commit 17b1cff781
16 changed files with 77 additions and 64 deletions

View File

@@ -28,8 +28,10 @@ typedef gnBool (*gnDebuggerCallback)(
void* userData);
typedef enum gnDebuggerLayer {
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
GN_DEBUGGER_LAYER_FUNCTIONS // enable the checks on every function
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
GN_DEBUGGER_LAYER_FUNCTIONS, // enable the checks on every function
GN_LAYER_MAX
} gnDebuggerLayer;
typedef struct gnDebuggerCreateInfo {

View File

@@ -6,7 +6,8 @@
#include "loader/src/gryphn_loader.h"
#include "stdio.h"
#include "apis/vulkan/loader/vulkan_loader.h"
#include "validation_layers/function_loader/loader/function_loader.h"
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
@@ -14,8 +15,6 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
(*instance)->hasDebugger = GN_FALSE;
(*instance)->layers = loaderLayerArrayListCreate();
(*instance)->functions = gryphnLoadAPILayer(info->coreAPI);
loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){
.api = info->coreAPI,
.layerToLoad = api_layer
@@ -23,6 +22,7 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
gnBool unsupportedExtension = GN_FALSE;
for (int c = 0; c < GN_EXT_MAX; c++) (*instance)->enabledExtensions[c] = GN_FALSE;
for (int c = 0; c < GN_LAYER_MAX; c++) (*instance)->enabledLayerCounts[c] = 0;
for (int i = 0; i < info->extensionCount; i++) {
(*instance)->enabledExtensions[info->extensions[i]] = GN_TRUE;
if (!gnIsExtensionSuppoted(info->coreAPI, info->extensions[i])) unsupportedExtension = GN_TRUE;
@@ -33,6 +33,8 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
if (info->debuggerInfo.layerCount > 0) {
for (int i = 0; i < info->debuggerInfo.layerCount; i++) {
(*instance)->enabledLayerCounts[info->debuggerInfo.layers[i]]++;
if (info->debuggerInfo.layers[i] == GN_DEBUGGER_LAYER_FUNCTIONS) {
loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){
.api = info->coreAPI,
@@ -44,15 +46,27 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
(*instance)->hasDebugger = GN_TRUE;
}
(*instance)->allLayers = malloc(sizeof(gryphnInstanceFunctionLayers) * (
(*instance)->enabledLayerCounts[GN_DEBUGGER_LAYER_FUNCTIONS] +
1 // for the core layer
));
int layerIDX = 0;
for (int i = 0; i < info->debuggerInfo.layerCount; i++) {
if (info->debuggerInfo.layers[i] == GN_DEBUGGER_LAYER_FUNCTIONS) (*instance)->allLayers[layerIDX++] = checkerLoadInstanceFunctions();
(*instance)->allLayers[layerIDX - 1].next = &(*instance)->allLayers[layerIDX];
}
(*instance)->allLayers[layerIDX] = gryphnLoadAPILayer(info->coreAPI);
(*instance)->functions = &(*instance)->allLayers[0];
(*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];
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
return (*instance)->functions.createInstance.func(*instance, info, NULL);
return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next);
}
void gnDestroyInstance(gnInstanceHandle* instance) {
if (instance == GN_NULL_HANDLE) return;
(*instance)->functions.destroyInstance.func(*instance, NULL);
(*instance)->functions->destroyInstance(*instance, (*instance)->functions->next);
*instance = GN_NULL_HANDLE;
}

View File

@@ -29,8 +29,9 @@ struct gnInstance_t {
struct gnPlatformInstance_t* instance;
gnDebuggerCreateInfo debugger;
gnBool enabledExtensions[GN_EXT_MAX];
gryphnInstanceFunctionLayers functions;
int enabledLayerCounts[GN_LAYER_MAX];
gryphnInstanceFunctionLayers* allLayers;
gryphnInstanceFunctionLayers* functions;
loaderLayerArrayList layers;
loaderLayer* callingLayer;