start using the dispatcher
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
||||
[submodule "projects/apis/metal/depends/SPIRV-Cross"]
|
||||
path = projects/apis/metal/depends/SPIRV-Cross
|
||||
url = https://github.com/KhronosGroup/SPIRV-Cross.git
|
||||
[submodule "depends/Dispatcher"]
|
||||
path = depends/Dispatcher
|
||||
url = https://github.com/GregoryWells2007/Dispatcher.git
|
||||
|
@@ -34,7 +34,8 @@ add_subdirectory(projects/core) # build gryphn core
|
||||
add_subdirectory(projects/extensions)
|
||||
add_subdirectory(projects/platform) # build gryphn platform
|
||||
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)
|
||||
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
|
||||
|
1
depends/Dispatcher
Submodule
1
depends/Dispatcher
Submodule
Submodule depends/Dispatcher added at c08c8f94ef
@@ -17,6 +17,7 @@ target_include_directories(GryphnMetalImpl PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../platform/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/
|
||||
depends/SPIRV-Cross/
|
||||
)
|
||||
|
@@ -22,6 +22,7 @@ target_include_directories(GryphnVulkanImpl PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../platform/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../depends/
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
@@ -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}/../utils)
|
||||
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../platform/)
|
||||
target_include_directories(GryphnCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../depends/)
|
||||
|
@@ -10,6 +10,11 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
||||
*instance = malloc(sizeof(struct gnInstance_t));
|
||||
(*instance)->hasDebugger = GN_FALSE;
|
||||
(*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){
|
||||
.api = info->coreAPI,
|
||||
.layerToLoad = api_layer
|
||||
@@ -41,11 +46,17 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
||||
(*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];
|
||||
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;
|
||||
return core_code;
|
||||
}
|
||||
|
||||
void gnDestroyInstance(gnInstanceHandle instance) {
|
||||
instance->callingLayer->instanceFunctions._gnDestroyInstance(instance);
|
||||
void gnDestroyInstance(gnInstanceHandle* 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;
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "core/gryphn_return_code.h"
|
||||
#include "core/src/instance/gryphn_debugger.h"
|
||||
#include <gryphn_extensions.h>
|
||||
#include "Dispatcher/dispatcher.h"
|
||||
|
||||
typedef struct gnApplicationInfo {
|
||||
gnString applicationName;
|
||||
@@ -26,14 +27,16 @@ typedef struct gnInstanceCreateInfo {
|
||||
#include <loader/src/gryphn_loader.h>
|
||||
struct gnInstance_t {
|
||||
struct gnPlatformInstance_t* instance;
|
||||
gnDebuggerCreateInfo debugger;
|
||||
gnBool enabledExtensions[GN_EXT_MAX];
|
||||
dispatcher dispatch;
|
||||
|
||||
loaderLayerArrayList layers;
|
||||
loaderLayer* callingLayer;
|
||||
uint32_t currentLayer;
|
||||
gnBool enabledExtensions[GN_EXT_MAX];
|
||||
gnBool hasDebugger;
|
||||
gnDebuggerCreateInfo debugger;
|
||||
};
|
||||
#endif
|
||||
|
||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
||||
void gnDestroyInstance(gnInstanceHandle instance);
|
||||
void gnDestroyInstance(gnInstanceHandle* instance);
|
||||
|
@@ -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}/../core/src/)
|
||||
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../core/)
|
||||
target_include_directories(GryphnLoader PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../depends/)
|
||||
|
@@ -25,7 +25,7 @@ typedef struct gnInstanceFunctions {
|
||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
||||
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);
|
||||
|
||||
|
||||
|
@@ -14,24 +14,27 @@
|
||||
#include "core/src/instance/gryphn_instance.h"
|
||||
|
||||
// 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) {
|
||||
case GN_RENDERINGAPI_NONE: return (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_NONE: *funcs = (gnInstanceFunctions){ NULL };
|
||||
#ifdef GN_API_VULKAN
|
||||
case GN_RENDERINGAPI_VULKAN: return loadVulkanInstanceFunctions();
|
||||
case GN_RENDERINGAPI_VULKAN: *funcs = loadVulkanInstanceFunctions();
|
||||
#endif
|
||||
|
||||
case GN_RENDERINGAPI_SOFTWARE: return (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_DIRECTX11: return (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_DIRECTX12: return (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_SOFTWARE: *funcs = (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_DIRECTX11: *funcs = (gnInstanceFunctions){ NULL };
|
||||
case GN_RENDERINGAPI_DIRECTX12: *funcs = (gnInstanceFunctions){ NULL };
|
||||
#ifdef GN_API_OPENGL
|
||||
case GN_RENDERINGAPI_OPENGL: return loadOpenGLInstanceFunctions();
|
||||
case GN_RENDERINGAPI_OPENGL: *funcs = loadOpenGLInstanceFunctions();
|
||||
#endif
|
||||
#ifdef GN_API_METAL
|
||||
case GN_RENDERINGAPI_METAL: return loadMetalInstanceFunctions();
|
||||
case GN_RENDERINGAPI_METAL: *funcs = loadMetalInstanceFunctions();
|
||||
#endif
|
||||
default: return (gnInstanceFunctions){NULL};
|
||||
default: *funcs = (gnInstanceFunctions){NULL};
|
||||
}
|
||||
return dispatcher_true;
|
||||
}
|
||||
|
||||
gnDeviceFunctions loadAPIDeviceFunctions(gnRenderingAPI api) {
|
||||
@@ -113,7 +116,6 @@ gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api) {
|
||||
|
||||
loaderLayer null_layer() {
|
||||
return (loaderLayer){
|
||||
.instanceFunctions = (gnInstanceFunctions){ NULL },
|
||||
.deviceFunctions = (gnDeviceFunctions){ NULL },
|
||||
.commandFunctions = (gnCommandFunctions){ NULL }
|
||||
};
|
||||
@@ -121,7 +123,6 @@ loaderLayer null_layer() {
|
||||
|
||||
loaderLayer api_loaded_layer(gnRenderingAPI api) {
|
||||
return (loaderLayer){
|
||||
.instanceFunctions = loadAPIInstanceFunctions(api),
|
||||
.deviceFunctions = loadAPIDeviceFunctions(api),
|
||||
.commandFunctions = loadAPICommandFunctions(api),
|
||||
};
|
||||
@@ -129,7 +130,6 @@ loaderLayer api_loaded_layer(gnRenderingAPI api) {
|
||||
|
||||
loaderLayer function_check_layer() {
|
||||
return (loaderLayer){
|
||||
.instanceFunctions = loadFunctionLoaderInstanceFunctions(),
|
||||
.deviceFunctions = loadFunctionLoaderDeviceFunctions(),
|
||||
.commandFunctions = loadFunctionLoaderCommandFunctions(),
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include "gryphn_instance_functions.h"
|
||||
#include "gryphn_device_functions.h"
|
||||
#include "gryphn_command_functions.h"
|
||||
#include "gryphn_loader_info.h"
|
||||
#include "utils/lists/gryphn_array_list.h"
|
||||
#include <Dispatcher/dispatcher.h>
|
||||
|
||||
#include "extensions/synchronization/loader/sync_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
|
||||
// they used to be loaded seperatly but I guess there not anymore
|
||||
// initlization is hard
|
||||
gnInstanceFunctions instanceFunctions;
|
||||
|
||||
// gnInstanceFunctions instanceFunctions;
|
||||
|
||||
gnDeviceFunctions deviceFunctions;
|
||||
gnCommandFunctions commandFunctions;
|
||||
|
||||
@@ -31,3 +33,7 @@ void resetLayer(gnInstance instance);
|
||||
|
||||
gnSyncExtFunctions loadAPISyncFunctions(gnRenderingAPI api);
|
||||
gnQueueExtFunctions loadAPIQueueFunctions(gnRenderingAPI api);
|
||||
|
||||
|
||||
|
||||
dispatcher_bool loadAPIInstanceFunctions(dispatcher_layer* layer);
|
||||
|
Reference in New Issue
Block a user