inplement the allocators into instance creation
This commit is contained in:
@@ -7,5 +7,5 @@ typedef struct gnPlatformInstance_t {
|
||||
NSView* metalContentView;
|
||||
} gnPlatformInstance;
|
||||
|
||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
||||
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next);
|
||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||
|
@@ -1,14 +1,14 @@
|
||||
#include "metal_instance.h"
|
||||
|
||||
// metal instances are kinda useless
|
||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next) {
|
||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||
if (next != NULL) return GN_SUCCESS;
|
||||
|
||||
if (instanceInfo == NULL) return GN_INCOMPLETE;
|
||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||
instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||
if (next != NULL) return;
|
||||
free(instance->instance);
|
||||
allocators->free(instance->instance, allocators->userData);
|
||||
}
|
||||
|
@@ -43,9 +43,9 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
|
||||
return VK_TRUE;
|
||||
}
|
||||
|
||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next) {
|
||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||
if (next != NULL) { return GN_SUCCESS; }
|
||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
||||
instance->instance = alloctors->malloc(sizeof(gnPlatformInstance), alloctors->userData);
|
||||
|
||||
vkStringArrayList extensions = vkStringArrayListCreate();
|
||||
vkStringArrayListAdd(extensions, "VK_KHR_surface");
|
||||
@@ -108,7 +108,8 @@ gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInf
|
||||
return VkResultToGnReturnCode(vkCreateInstance(&createInfo, NULL, &instance->instance->vk_instance));
|
||||
}
|
||||
|
||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||
if (next != NULL) { return; }
|
||||
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
||||
alloctors->free(instance->instance, alloctors->userData);
|
||||
}
|
||||
|
@@ -14,8 +14,8 @@ typedef struct gnPlatformInstance_t {
|
||||
vkUserData userData;
|
||||
} gnPlatformInstance;
|
||||
|
||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
|
||||
typedef const char* vkString;
|
||||
GN_ARRAY_LIST_HEADER(vkString);
|
||||
|
@@ -4,12 +4,30 @@
|
||||
#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"
|
||||
#include "validation_layers/allocators/allocator_checker.h"
|
||||
|
||||
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
||||
*instance = malloc(sizeof(struct gnInstance_t));
|
||||
*instance = GN_NULL_HANDLE;
|
||||
gnAllocators tmpAllocators = {
|
||||
.userData = &info->debuggerInfo,
|
||||
.malloc = (PFN_gnMalloc)malloc,
|
||||
.calloc = (PFN_gnCalloc)calloc,
|
||||
.realloc = (PFN_gnRealloc)realloc,
|
||||
.free = (PFN_gnFree)free
|
||||
};
|
||||
|
||||
for (int i = 0; i < info->debuggerInfo.layerCount; i++) {
|
||||
if (info->debuggerInfo.layers[i] == GN_DEBUGGER_LAYER_ALLOCATORS) {
|
||||
tmpAllocators.malloc = gnMallocFunc;
|
||||
tmpAllocators.calloc = gnCallocFunc;
|
||||
tmpAllocators.realloc = gnReallocFunc;
|
||||
tmpAllocators.free = gnFreeFunc;
|
||||
}
|
||||
}
|
||||
|
||||
*instance = tmpAllocators.malloc(sizeof(struct gnInstance_t), tmpAllocators.userData);
|
||||
(*instance)->hasDebugger = GN_FALSE;
|
||||
(*instance)->layers = loaderLayerArrayListCreate();
|
||||
|
||||
@@ -61,11 +79,14 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo*
|
||||
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);
|
||||
(*instance)->allocators = tmpAllocators;
|
||||
(*instance)->allocators.userData = &(*instance)->debugger;
|
||||
return (*instance)->functions->createInstance(*instance, info, (*instance)->functions->next, &(*instance)->allocators);
|
||||
}
|
||||
|
||||
void gnDestroyInstance(gnInstanceHandle* instance) {
|
||||
if (instance == GN_NULL_HANDLE) return;
|
||||
(*instance)->functions->destroyInstance(*instance, (*instance)->functions->next);
|
||||
(*instance)->functions->destroyInstance(*instance, (*instance)->functions->next, &(*instance)->allocators);
|
||||
(*instance)->allocators.free(*instance, (*instance)->allocators.userData);
|
||||
*instance = GN_NULL_HANDLE;
|
||||
}
|
||||
|
@@ -4,8 +4,10 @@
|
||||
#include "utils/gryphn_version.h"
|
||||
#include "core/gryphn_return_code.h"
|
||||
#include "core/src/instance/gryphn_debugger.h"
|
||||
#include "gryphn_allocators.h"
|
||||
#include <gryphn_extensions.h>
|
||||
|
||||
|
||||
typedef struct gnApplicationInfo {
|
||||
gnString applicationName;
|
||||
gnVersion applicationVersion;
|
||||
@@ -32,12 +34,14 @@ struct gnInstance_t {
|
||||
int enabledLayerCounts[GN_LAYER_MAX];
|
||||
gryphnInstanceFunctionLayers* allLayers;
|
||||
gryphnInstanceFunctionLayers* functions;
|
||||
gnAllocators allocators;
|
||||
|
||||
loaderLayerArrayList layers;
|
||||
loaderLayer* callingLayer;
|
||||
uint32_t currentLayer;
|
||||
gnBool hasDebugger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "core/gryphn_return_code.h"
|
||||
#include "utils/gryphn_bool.h"
|
||||
#include "gryphn_handles.h"
|
||||
#include "gryphn_allocators.h"
|
||||
|
||||
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
||||
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
||||
@@ -19,8 +20,8 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo;
|
||||
#endif
|
||||
|
||||
typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers;
|
||||
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next);
|
||||
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
||||
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
|
||||
typedef struct gnInstanceFunctions {
|
||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
||||
|
@@ -4,24 +4,24 @@
|
||||
#include "core/src/output_device/gryphn_output_device.h"
|
||||
#include "core/src/window_surface/gryphn_surface.h"
|
||||
|
||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next) {
|
||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||
if (next == NULL || next->createInstance == NULL) {
|
||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||
.message = gnCreateString("Failed to load gnCreateInstance this indicates a bug within gryphn")
|
||||
});
|
||||
return GN_FAILED_TO_LOAD_FUNCTION;
|
||||
}
|
||||
return next->createInstance(instance, info, next->next);
|
||||
return next->createInstance(instance, info, next->next, alloctors);
|
||||
}
|
||||
|
||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||
if (next == NULL || next->destroyInstance == NULL) {
|
||||
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
|
||||
.message = gnCreateString("Failed to load gnDestroyInstance this indicates a bug within gryphn")
|
||||
});
|
||||
return;
|
||||
}
|
||||
next->destroyInstance(instance, next->next);
|
||||
next->destroyInstance(instance, next->next, alloctors);
|
||||
}
|
||||
|
||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
|
||||
|
@@ -2,8 +2,8 @@
|
||||
#include "core/src/instance/gryphn_instance.h"
|
||||
#include <core/src/window_surface/gryphn_surface_create_functions.h>
|
||||
|
||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next);
|
||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
||||
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||
|
||||
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
|
||||
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface);
|
||||
|
Reference in New Issue
Block a user