start using the dispatcher

This commit is contained in:
Gregory Wells
2025-07-30 21:32:04 -04:00
parent d130fff385
commit 797191c2b6
12 changed files with 51 additions and 22 deletions

3
.gitmodules vendored
View File

@@ -4,3 +4,6 @@
[submodule "projects/apis/metal/depends/SPIRV-Cross"] [submodule "projects/apis/metal/depends/SPIRV-Cross"]
path = projects/apis/metal/depends/SPIRV-Cross path = projects/apis/metal/depends/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git url = https://github.com/KhronosGroup/SPIRV-Cross.git
[submodule "depends/Dispatcher"]
path = depends/Dispatcher
url = https://github.com/GregoryWells2007/Dispatcher.git

View File

@@ -34,7 +34,8 @@ add_subdirectory(projects/core) # build gryphn core
add_subdirectory(projects/extensions) add_subdirectory(projects/extensions)
add_subdirectory(projects/platform) # build gryphn platform add_subdirectory(projects/platform) # build gryphn platform
add_subdirectory(projects/validation_layers/function_loader/) add_subdirectory(projects/validation_layers/function_loader/)
target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnExtensions) add_subdirectory(depends/Dispatcher/)
target_link_libraries(Gryphn INTERFACE dispatcher GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnExtensions)
if (VULKAN_BUILT) if (VULKAN_BUILT)
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl) target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)

1
depends/Dispatcher Submodule

Submodule depends/Dispatcher added at c08c8f94ef

View File

@@ -17,6 +17,7 @@ target_include_directories(GryphnMetalImpl PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/ ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
${CMAKE_CURRENT_SOURCE_DIR}/../../platform/ ${CMAKE_CURRENT_SOURCE_DIR}/../../platform/
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
${CMAKE_CURRENT_SOURCE_DIR}/src/ ${CMAKE_CURRENT_SOURCE_DIR}/src/
depends/SPIRV-Cross/ depends/SPIRV-Cross/
) )

View File

@@ -22,6 +22,7 @@ target_include_directories(GryphnVulkanImpl PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../platform/ ${CMAKE_CURRENT_SOURCE_DIR}/../../platform/
${CMAKE_CURRENT_SOURCE_DIR}/../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/ ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
) )
if(WIN32) if(WIN32)

View File

@@ -15,3 +15,4 @@ target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/)
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include/) target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include/)
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../utils) target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../utils)
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../platform/) target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../platform/)
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../depends/)

View File

@@ -10,6 +10,11 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
*instance = malloc(sizeof(struct gnInstance_t)); *instance = malloc(sizeof(struct gnInstance_t));
(*instance)->hasDebugger = GN_FALSE; (*instance)->hasDebugger = GN_FALSE;
(*instance)->layers = loaderLayerArrayListCreate(); (*instance)->layers = loaderLayerArrayListCreate();
dispatcher_init(&(*instance)->dispatch);
dispatcher_set_function_array_size(&(*instance)->dispatch, sizeof(gnInstanceFunctions));
dispatcher_create_layer(&(*instance)->dispatch, loadAPIInstanceFunctions, &info->coreAPI);
loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){ loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){
.api = info->coreAPI, .api = info->coreAPI,
.layerToLoad = api_layer .layerToLoad = api_layer
@@ -41,11 +46,17 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
(*instance)->currentLayer = ((*instance)->layers.count - 1); (*instance)->currentLayer = ((*instance)->layers.count - 1);
for (int i = 0; i < (*instance)->layers.count; i++) (*instance)->layers.data[i].layerIndex = i; for (int i = 0; i < (*instance)->layers.count; i++) (*instance)->layers.data[i].layerIndex = i;
(*instance)->callingLayer = &(*instance)->layers.data[(*instance)->layers.count - 1]; (*instance)->callingLayer = &(*instance)->layers.data[(*instance)->layers.count - 1];
gnReturnCode core_code = (*instance)->callingLayer->instanceFunctions._gnCreateInstance((*instance), info);
gnInstanceFunctions* instance_funcs = (gnInstanceFunctions*)((*instance)->dispatch.first_layer->function_array);
gnReturnCode core_code = instance_funcs->_gnCreateInstance((*instance), info);
if (unsupportedExtension) return GN_UNLOADED_EXTENSION; if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
return core_code; return core_code;
} }
void gnDestroyInstance(gnInstanceHandle instance) { void gnDestroyInstance(gnInstanceHandle* instance) {
instance->callingLayer->instanceFunctions._gnDestroyInstance(instance); if (instance == GN_NULL_HANDLE) return;
gnInstanceFunctions* instance_funcs = (gnInstanceFunctions*)((*instance)->dispatch.first_layer->function_array);
instance_funcs->_gnDestroyInstance((*instance));
*instance = GN_NULL_HANDLE;
} }

View File

@@ -5,6 +5,7 @@
#include "core/gryphn_return_code.h" #include "core/gryphn_return_code.h"
#include "core/src/instance/gryphn_debugger.h" #include "core/src/instance/gryphn_debugger.h"
#include <gryphn_extensions.h> #include <gryphn_extensions.h>
#include "Dispatcher/dispatcher.h"
typedef struct gnApplicationInfo { typedef struct gnApplicationInfo {
gnString applicationName; gnString applicationName;
@@ -26,14 +27,16 @@ typedef struct gnInstanceCreateInfo {
#include <loader/src/gryphn_loader.h> #include <loader/src/gryphn_loader.h>
struct gnInstance_t { struct gnInstance_t {
struct gnPlatformInstance_t* instance; struct gnPlatformInstance_t* instance;
gnDebuggerCreateInfo debugger;
gnBool enabledExtensions[GN_EXT_MAX];
dispatcher dispatch;
loaderLayerArrayList layers; loaderLayerArrayList layers;
loaderLayer* callingLayer; loaderLayer* callingLayer;
uint32_t currentLayer; uint32_t currentLayer;
gnBool enabledExtensions[GN_EXT_MAX];
gnBool hasDebugger; gnBool hasDebugger;
gnDebuggerCreateInfo debugger;
}; };
#endif #endif
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info); gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
void gnDestroyInstance(gnInstanceHandle instance); void gnDestroyInstance(gnInstanceHandle* instance);

View File

@@ -7,3 +7,4 @@ target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../ut
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/src/) target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/src/)
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/) target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/)
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../depends/)

View File

@@ -25,7 +25,7 @@ typedef struct gnInstanceFunctions {
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count); gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
gnBool (*_gnPhysicalDeviceCanPresentToSurface)(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface); gnBool (*_gnPhysicalDeviceCanPresentToSurface)(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
gnReturnCode (*_gnCreateOutputDevice)(gnOutputDeviceHandle device, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo); gnReturnCode (*_gnCreateOutputDevice)(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
void (*_gnDestroyOutputDevice)(gnOutputDeviceHandle device); void (*_gnDestroyOutputDevice)(gnOutputDeviceHandle device);

View File

@@ -14,24 +14,27 @@
#include "core/src/instance/gryphn_instance.h" #include "core/src/instance/gryphn_instance.h"
// load the speedy API functions or something like that // load the speedy API functions or something like that
gnInstanceFunctions loadAPIInstanceFunctions(gnRenderingAPI api) { dispatcher_bool loadAPIInstanceFunctions(dispatcher_layer* layer) {
gnRenderingAPI api = *(gnRenderingAPI*)layer->userData;
gnInstanceFunctions* funcs = (gnInstanceFunctions*)layer->function_array;
switch (api) { switch (api) {
case GN_RENDERINGAPI_NONE: return (gnInstanceFunctions){ NULL }; case GN_RENDERINGAPI_NONE: *funcs = (gnInstanceFunctions){ NULL };
#ifdef GN_API_VULKAN #ifdef GN_API_VULKAN
case GN_RENDERINGAPI_VULKAN: return loadVulkanInstanceFunctions(); case GN_RENDERINGAPI_VULKAN: *funcs = loadVulkanInstanceFunctions();
#endif #endif
case GN_RENDERINGAPI_SOFTWARE: return (gnInstanceFunctions){ NULL }; case GN_RENDERINGAPI_SOFTWARE: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnInstanceFunctions){ NULL }; case GN_RENDERINGAPI_DIRECTX11: *funcs = (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnInstanceFunctions){ NULL }; case GN_RENDERINGAPI_DIRECTX12: *funcs = (gnInstanceFunctions){ NULL };
#ifdef GN_API_OPENGL #ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: return loadOpenGLInstanceFunctions(); case GN_RENDERINGAPI_OPENGL: *funcs = loadOpenGLInstanceFunctions();
#endif #endif
#ifdef GN_API_METAL #ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalInstanceFunctions(); case GN_RENDERINGAPI_METAL: *funcs = loadMetalInstanceFunctions();
#endif #endif
default: return (gnInstanceFunctions){NULL}; default: *funcs = (gnInstanceFunctions){NULL};
} }
return dispatcher_true;
} }
gnDeviceFunctions loadAPIDeviceFunctions(gnRenderingAPI api) { gnDeviceFunctions loadAPIDeviceFunctions(gnRenderingAPI api) {
@@ -113,7 +116,6 @@ gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api) {
loaderLayer null_layer() { loaderLayer null_layer() {
return (loaderLayer){ return (loaderLayer){
.instanceFunctions = (gnInstanceFunctions){ NULL },
.deviceFunctions = (gnDeviceFunctions){ NULL }, .deviceFunctions = (gnDeviceFunctions){ NULL },
.commandFunctions = (gnCommandFunctions){ NULL } .commandFunctions = (gnCommandFunctions){ NULL }
}; };
@@ -121,7 +123,6 @@ loaderLayer null_layer() {
loaderLayer api_loaded_layer(gnRenderingAPI api) { loaderLayer api_loaded_layer(gnRenderingAPI api) {
return (loaderLayer){ return (loaderLayer){
.instanceFunctions = loadAPIInstanceFunctions(api),
.deviceFunctions = loadAPIDeviceFunctions(api), .deviceFunctions = loadAPIDeviceFunctions(api),
.commandFunctions = loadAPICommandFunctions(api), .commandFunctions = loadAPICommandFunctions(api),
}; };
@@ -129,7 +130,6 @@ loaderLayer api_loaded_layer(gnRenderingAPI api) {
loaderLayer function_check_layer() { loaderLayer function_check_layer() {
return (loaderLayer){ return (loaderLayer){
.instanceFunctions = loadFunctionLoaderInstanceFunctions(),
.deviceFunctions = loadFunctionLoaderDeviceFunctions(), .deviceFunctions = loadFunctionLoaderDeviceFunctions(),
.commandFunctions = loadFunctionLoaderCommandFunctions(), .commandFunctions = loadFunctionLoaderCommandFunctions(),

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include "gryphn_instance_functions.h"
#include "gryphn_device_functions.h" #include "gryphn_device_functions.h"
#include "gryphn_command_functions.h" #include "gryphn_command_functions.h"
#include "gryphn_loader_info.h" #include "gryphn_loader_info.h"
#include "utils/lists/gryphn_array_list.h" #include "utils/lists/gryphn_array_list.h"
#include <Dispatcher/dispatcher.h>
#include "extensions/synchronization/loader/sync_functions.h" #include "extensions/synchronization/loader/sync_functions.h"
#include "extensions/queues/queues_functions.h" #include "extensions/queues/queues_functions.h"
@@ -12,7 +12,9 @@ typedef struct loaderLayer {
// idk why I sperate these info different classes, I should really shove them in one bit class // 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 // they used to be loaded seperatly but I guess there not anymore
// initlization is hard // initlization is hard
gnInstanceFunctions instanceFunctions;
// gnInstanceFunctions instanceFunctions;
gnDeviceFunctions deviceFunctions; gnDeviceFunctions deviceFunctions;
gnCommandFunctions commandFunctions; gnCommandFunctions commandFunctions;
@@ -31,3 +33,7 @@ void resetLayer(gnInstance instance);
gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api); gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api);
gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api); gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api);
dispatcher_bool loadAPIInstanceFunctions(dispatcher_layer* layer);