#include "gryphn_instance.h" #include "instance/gryphn_instance.h" #include #include "loader/src/gryphn_extension_loader.h" #include "loader/src/gryphn_loader.h" #include "loader/src/gryphn_loader.h" #include "stdio.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) { *instance = malloc(sizeof(struct gnInstance_t)); (*instance)->hasDebugger = GN_FALSE; (*instance)->layers = loaderLayerArrayListCreate(); loaderLayerArrayListAdd((*instance)->layers, loadLayer((loaderInfo){ .api = info->coreAPI, .layerToLoad = api_layer })); 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 (uint32_t i = 0; i < info->extensionCount; i++) { (*instance)->enabledExtensions[info->extensions[i]] = GN_TRUE; if (!gnIsExtensionSuppoted(info->coreAPI, info->extensions[i])) unsupportedExtension = GN_TRUE; } if ((*instance)->enabledExtensions[GN_EXT_SYNCHRONIZATION]) loaderLayerArrayListRefAt((*instance)->layers, 0)->syncFunctions = loadAPISyncFunctions(info->coreAPI); if ((*instance)->enabledExtensions[GN_EXT_QUEUES]) loaderLayerArrayListRefAt((*instance)->layers, 0)->queueFunctions = loadAPIQueueFunctions(info->coreAPI); if (info->debuggerInfo.layerCount > 0) { for (uint32_t 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, .layerToLoad = function_checker_layer })); } } (*instance)->debugger = info->debuggerInfo; (*instance)->hasDebugger = GN_TRUE; } (*instance)->allLayers = malloc(sizeof(gryphnInstanceFunctionLayers) * ( (*instance)->enabledLayerCounts[GN_DEBUGGER_LAYER_FUNCTIONS] + 1 // for the core layer )); int layerIDX = 0; for (uint32_t 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]; resetLayer(*instance); for (uint32_t i = 0; i < loaderLayerArrayListCount((*instance)->layers); i++) loaderLayerArrayListRefAt((*instance)->layers, i)->layerIndex = i; (*instance)->callingLayer = loaderLayerArrayListRefAt((*instance)->layers, (*instance)->currentLayer); if (unsupportedExtension) return GN_UNLOADED_EXTENSION; return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next); } void gnDestroyInstance(gnInstanceHandle* instance) { if (instance == GN_NULL_HANDLE) return; (*instance)->functions->destroyInstance(*instance, (*instance)->functions->next); *instance = GN_NULL_HANDLE; }