essentially finish the loader rewrite
This commit is contained in:
@@ -7,5 +7,5 @@ typedef struct gnPlatformInstance_t {
|
|||||||
NSView* metalContentView;
|
NSView* metalContentView;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next);
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance_layer* next);
|
||||||
void metalDestroyInstance(gnInstance instance, gryphnFunctionLayer* next);
|
void metalDestroyInstance(gnInstance instance, PFN_gnDestroyInstance_layer* next);
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
#include "metal_instance.h"
|
#include "metal_instance.h"
|
||||||
|
|
||||||
// metal instances are kinda useless
|
// metal instances are kinda useless
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next) {
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance_layer* next) {
|
||||||
if (instance->instance == NULL) instance->instance = malloc(sizeof(gnPlatformInstance));
|
if (instance->instance == NULL) instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next) {
|
void metalDestroyInstance(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next) {
|
||||||
free(instance->instance);
|
free(instance->instance);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#include "vulkan_instance.h"
|
#include "vulkan_instance.h"
|
||||||
#include "vulkan_result_converter.h"
|
#include "vulkan_result_converter.h"
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
||||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
@@ -35,7 +37,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
|||||||
return VK_TRUE;
|
return VK_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next) {
|
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance_layer* next) {
|
||||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||||
|
|
||||||
vkStringArrayList extensions = vkStringArrayListCreate();
|
vkStringArrayList extensions = vkStringArrayListCreate();
|
||||||
@@ -101,6 +103,6 @@ gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInf
|
|||||||
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
|
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next) {
|
void vulkanDestroyInstance(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next) {
|
||||||
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,8 @@ typedef struct gnPlatformInstance_t {
|
|||||||
vkUserData userData;
|
vkUserData userData;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnFunctionLayer* next);
|
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, PFN_gnCreateInstance_layer* next);
|
||||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next);
|
void vulkanDestroyInstance(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next);
|
||||||
|
|
||||||
typedef const char* vkString;
|
typedef const char* vkString;
|
||||||
GN_ARRAY_LIST(vkString);
|
GN_ARRAY_LIST(vkString);
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
#include "loader/src/gryphn_extension_loader.h"
|
#include "loader/src/gryphn_extension_loader.h"
|
||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
#include "loader/src/gryphn_loader.h"
|
#include "loader/src/gryphn_loader.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
#include "apis/vulkan/loader/vulkan_loader.h"
|
||||||
|
|
||||||
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
||||||
@@ -11,7 +14,7 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
|||||||
(*instance)->hasDebugger = GN_FALSE;
|
(*instance)->hasDebugger = GN_FALSE;
|
||||||
(*instance)->layers = loaderLayerArrayListCreate();
|
(*instance)->layers = loaderLayerArrayListCreate();
|
||||||
|
|
||||||
// (*instance)->functions =
|
(*instance)->functions = gryphnLoadAPILayer(info->coreAPI);
|
||||||
|
|
||||||
loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){
|
loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){
|
||||||
.api = info->coreAPI,
|
.api = info->coreAPI,
|
||||||
@@ -45,11 +48,11 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
|||||||
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];
|
||||||
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
|
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
|
||||||
return (*(PFN_gnCreateInstance*)(*instance)->functions.createInstance.function)(*instance, info, (*instance)->functions.createInstance.next);
|
return (*instance)->functions.createInstance.func(*instance, info, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyInstance(gnInstanceHandle* instance) {
|
void gnDestroyInstance(gnInstanceHandle* instance) {
|
||||||
if (instance == GN_NULL_HANDLE) return;
|
if (instance == GN_NULL_HANDLE) return;
|
||||||
(*(PFN_gnDestroyInstance*)(*instance)->functions.destroyInstance.function)(*instance, (*instance)->functions.destroyInstance.next);
|
(*instance)->functions.destroyInstance.func(*instance, NULL);
|
||||||
*instance = GN_NULL_HANDLE;
|
*instance = GN_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "core/gryphn_return_code.h"
|
#include "core/gryphn_return_code.h"
|
||||||
#include "utils/gryphn_bool.h"
|
#include "utils/gryphn_bool.h"
|
||||||
#include "gryphn_handles.h"
|
#include "gryphn_handles.h"
|
||||||
|
#include "gryphn_loader_helpers.h"
|
||||||
|
|
||||||
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
||||||
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
||||||
@@ -18,9 +19,13 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo;
|
|||||||
typedef struct gnMacOSWindowSurfaceInfo gnMacOSWindowSurfaceInfo;
|
typedef struct gnMacOSWindowSurfaceInfo gnMacOSWindowSurfaceInfo;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct gryphnFunctionLayer gryphnFunctionLayer;
|
typedef struct PFN_gnCreateInstance_layer PFN_gnCreateInstance_layer;
|
||||||
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnFunctionLayer* next);
|
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, PFN_gnCreateInstance_layer* next);
|
||||||
typedef gnReturnCode (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnFunctionLayer* next);
|
gryphnFunctionLayer(PFN_gnCreateInstance);
|
||||||
|
|
||||||
|
typedef struct PFN_gnDestroyInstance_layer PFN_gnDestroyInstance_layer;
|
||||||
|
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next);
|
||||||
|
gryphnFunctionLayer(PFN_gnDestroyInstance);
|
||||||
|
|
||||||
typedef struct gnInstanceFunctions {
|
typedef struct gnInstanceFunctions {
|
||||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
||||||
|
@@ -14,8 +14,8 @@ typedef struct gryphnFunctionLayer {
|
|||||||
} gryphnFunctionLayer;
|
} gryphnFunctionLayer;
|
||||||
|
|
||||||
typedef struct gryphnInstanceFunctionLayers {
|
typedef struct gryphnInstanceFunctionLayers {
|
||||||
gryphnFunctionLayer createInstance; // PFN_gnCreateInstance
|
PFN_gnCreateInstance_layer createInstance;
|
||||||
gryphnFunctionLayer destroyInstance; // PFN_gnDestroyInstance
|
PFN_gnDestroyInstance_layer destroyInstance;
|
||||||
} gryphnInstanceFunctionLayers;
|
} gryphnInstanceFunctionLayers;
|
||||||
gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api);
|
gryphnInstanceFunctionLayers gryphnLoadAPILayer(gnRenderingAPI api);
|
||||||
|
|
||||||
|
6
projects/loader/src/gryphn_loader_helpers.h
Normal file
6
projects/loader/src/gryphn_loader_helpers.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define gryphnFunctionLayer(function) typedef struct function##_layer { \
|
||||||
|
function func;\
|
||||||
|
struct function##_layer* next; \
|
||||||
|
} function##_layer;\
|
@@ -4,23 +4,23 @@
|
|||||||
#include "core/src/output_device/gryphn_output_device.h"
|
#include "core/src/output_device/gryphn_output_device.h"
|
||||||
#include "core/src/window_surface/gryphn_surface.h"
|
#include "core/src/window_surface/gryphn_surface.h"
|
||||||
|
|
||||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnFunctionLayer* next) {
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, PFN_gnCreateInstance_layer* next) {
|
||||||
if (next->function == NULL) {
|
if (next->func == NULL) {
|
||||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||||
.message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn")
|
.message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn")
|
||||||
});
|
});
|
||||||
return GN_FAILED_TO_LOAD_FUNCTION;
|
return GN_FAILED_TO_LOAD_FUNCTION;
|
||||||
}
|
}
|
||||||
return (*(PFN_gnCreateInstance*)next->function)(instance, info, next->next);
|
return (*(PFN_gnCreateInstance*)next->func)(instance, info, next->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next) {
|
void checkDestroyInstance(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next) {
|
||||||
if (next->function == NULL) {
|
if (next->func == NULL) {
|
||||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||||
.message = gnCreateString("Failed to load gnDestroyInstance this indicates a bug within gryphn")
|
.message = gnCreateString("Failed to load gnDestroyInstance this indicates a bug within gryphn")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(*(PFN_gnDestroyInstance*)next->function)(instance, next->next);
|
(*(PFN_gnDestroyInstance*)next->func)(instance, next->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
|
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
#include "core/src/instance/gryphn_instance.h"
|
#include "core/src/instance/gryphn_instance.h"
|
||||||
#include <core/src/window_surface/gryphn_surface_create_functions.h>
|
#include <core/src/window_surface/gryphn_surface_create_functions.h>
|
||||||
|
|
||||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnFunctionLayer* next);
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, PFN_gnCreateInstance_layer* next);
|
||||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnFunctionLayer* next);
|
void checkDestroyInstance(gnInstanceHandle instance, PFN_gnDestroyInstance_layer* next);
|
||||||
|
|
||||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
|
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
|
||||||
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
||||||
|
Reference in New Issue
Block a user