Files
Gryphn/projects/loader/src/gryphn_loader.c
2025-08-12 23:09:39 -04:00

183 lines
6.1 KiB
C

#include "gryphn_loader.h"
#include <validation_layers/function_loader/loader/function_loader.h>
#ifdef GN_API_VULKAN
#include <apis/vulkan/loader/vulkan_loader.h>
#endif
#ifdef GN_API_METAL
#include <apis/metal/loader/metal_loader.h>
#endif
#ifdef GN_API_OPENGL
#include <apis/opengl/loader/opengl_loader.h>
#endif
#include "core/src/instance/gryphn_instance.h"
gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gryphnInstanceFunctionLayers){};
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanAPILayer();
#endif
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: return loadOpenGLAPILayer();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return metalLoadAPILayer();
#endif
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};
}
}
gnDeviceFunctions loadAPIDeviceFunctions(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gnDeviceFunctions){ NULL };
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanDeviceFunctions();
#endif
case GN_RENDERINGAPI_SOFTWARE: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnDeviceFunctions){ NULL };
#ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: return loadOpenGLDeviceFunctions();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalDeviceFunctions();
#endif
default: return (gnDeviceFunctions){NULL};
}
}
gnCommandFunctions loadAPICommandFunctions(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gnCommandFunctions){ NULL };
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanCommandFunctions();
#endif
case GN_RENDERINGAPI_SOFTWARE: return (gnCommandFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnCommandFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnCommandFunctions){ NULL };
#ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: return loadOpenGLCommandFunctions();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalCommandFunctions();
#endif
default: return (gnCommandFunctions){NULL};
}
}
gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gnSyncExtFunctions){ NULL };
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanSyncFunctions();
#endif
case GN_RENDERINGAPI_SOFTWARE: return (gnSyncExtFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnSyncExtFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnSyncExtFunctions){ NULL };
case GN_RENDERINGAPI_OPENGL: return (gnSyncExtFunctions){ NULL };
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalSyncFunctions();
#endif
default: return (gnSyncExtFunctions){NULL};
}
}
gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return (gnQueueExtFunctions){ NULL };
#ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanQueueFunctions();
#endif
case GN_RENDERINGAPI_SOFTWARE: return (gnQueueExtFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnQueueExtFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnQueueExtFunctions){ NULL };
case GN_RENDERINGAPI_OPENGL: return (gnQueueExtFunctions){ NULL };
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return (gnQueueExtFunctions){ NULL };
#endif
default: return (gnQueueExtFunctions){NULL};
}
}
loaderLayer null_layer() {
return (loaderLayer){
.deviceFunctions = (gnDeviceFunctions){ NULL },
.commandFunctions = (gnCommandFunctions){ NULL }
};
}
loaderLayer api_loaded_layer(gnRenderingAPI api) {
return (loaderLayer){
.instanceFunctions = loadAPIInstanceFunctions(api),
.deviceFunctions = loadAPIDeviceFunctions(api),
.commandFunctions = loadAPICommandFunctions(api),
};
}
loaderLayer function_check_layer() {
return (loaderLayer){
.instanceFunctions = loadFunctionLoaderInstanceFunctions(),
.deviceFunctions = loadFunctionLoaderDeviceFunctions(),
.commandFunctions = loadFunctionLoaderCommandFunctions(),
.syncFunctions = loadFunctionLoaderSyncExtFunctions(),
.queueFunctions = loadFunctionLoaderQueueExtFunctions(),
};
}
loaderLayer loadLayer(loaderInfo info) {
if (info.layerToLoad == api_layer) return api_loaded_layer(info.api);
if (info.layerToLoad == function_checker_layer) return function_check_layer();
return null_layer();
}
loaderLayer* loaderGetNextLayer(gnInstance instance) {
instance->currentLayer--;
uint32_t nextLayer = instance->currentLayer;
if (instance->currentLayer == 0) {
nextLayer = 0;
resetLayer(instance);
}
return loaderLayerArrayListRefAt(instance->layers, nextLayer);
}
void resetLayer(gnInstance instance) {
instance->currentLayer = loaderLayerArrayListCount(instance->layers) - 1;
}
GN_ARRAY_LIST_DEFINITION(loaderLayer)