inplement the allocators into instance creation
This commit is contained in:
@@ -33,8 +33,11 @@ add_subdirectory(projects/loader) # build gryphn loader
|
|||||||
add_subdirectory(projects/core) # build gryphn core
|
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 GryphnUtils GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnExtensions)
|
add_subdirectory(projects/validation_layers/allocators/)
|
||||||
|
|
||||||
|
target_link_libraries(Gryphn INTERFACE GryphnUtils GryphnCore GryphnLoader GryphnPlatform GryphnFunctionValidator GryphnAllocatorChecker GryphnExtensions)
|
||||||
|
|
||||||
if (VULKAN_BUILT)
|
if (VULKAN_BUILT)
|
||||||
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
|
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
|
||||||
|
@@ -7,5 +7,5 @@ typedef struct gnPlatformInstance_t {
|
|||||||
NSView* metalContentView;
|
NSView* metalContentView;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
gnReturnCode metalCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next);
|
void metalDestroyInstance(gnInstance instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
#include "metal_instance.h"
|
#include "metal_instance.h"
|
||||||
|
|
||||||
// metal instances are kinda useless
|
// 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 (next != NULL) return GN_SUCCESS;
|
||||||
|
|
||||||
if (instanceInfo == NULL) return GN_INCOMPLETE;
|
if (instanceInfo == NULL) return GN_INCOMPLETE;
|
||||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
instance->instance = allocators->malloc(sizeof(gnPlatformInstance), allocators->userData);
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next) {
|
void metalDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
|
||||||
if (next != NULL) return;
|
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;
|
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; }
|
if (next != NULL) { return GN_SUCCESS; }
|
||||||
instance->instance = malloc(sizeof(gnPlatformInstance));
|
instance->instance = alloctors->malloc(sizeof(gnPlatformInstance), alloctors->userData);
|
||||||
|
|
||||||
vkStringArrayList extensions = vkStringArrayListCreate();
|
vkStringArrayList extensions = vkStringArrayListCreate();
|
||||||
vkStringArrayListAdd(extensions, "VK_KHR_surface");
|
vkStringArrayListAdd(extensions, "VK_KHR_surface");
|
||||||
@@ -108,7 +108,8 @@ 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, gryphnInstanceFunctionLayers* next) {
|
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next != NULL) { return; }
|
if (next != NULL) { return; }
|
||||||
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
vkDestroyInstance(instance->instance->vk_instance, NULL);
|
||||||
|
alloctors->free(instance->instance, alloctors->userData);
|
||||||
}
|
}
|
||||||
|
@@ -14,8 +14,8 @@ typedef struct gnPlatformInstance_t {
|
|||||||
vkUserData userData;
|
vkUserData userData;
|
||||||
} gnPlatformInstance;
|
} gnPlatformInstance;
|
||||||
|
|
||||||
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next);
|
gnReturnCode vulkanCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
void vulkanDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
typedef const char* vkString;
|
typedef const char* vkString;
|
||||||
GN_ARRAY_LIST_HEADER(vkString);
|
GN_ARRAY_LIST_HEADER(vkString);
|
||||||
|
@@ -4,12 +4,30 @@
|
|||||||
#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 "validation_layers/function_loader/loader/function_loader.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
|
// this implementation of gnCreateInstance cannot return GN_UNLOADED_LAYER
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info) {
|
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)->hasDebugger = GN_FALSE;
|
||||||
(*instance)->layers = loaderLayerArrayListCreate();
|
(*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;
|
for (uint32_t i = 0; i < loaderLayerArrayListCount((*instance)->layers); i++) loaderLayerArrayListRefAt((*instance)->layers, i)->layerIndex = i;
|
||||||
(*instance)->callingLayer = loaderLayerArrayListRefAt((*instance)->layers, (*instance)->currentLayer);
|
(*instance)->callingLayer = loaderLayerArrayListRefAt((*instance)->layers, (*instance)->currentLayer);
|
||||||
if (unsupportedExtension) return GN_UNLOADED_EXTENSION;
|
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) {
|
void gnDestroyInstance(gnInstanceHandle* instance) {
|
||||||
if (instance == GN_NULL_HANDLE) return;
|
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;
|
*instance = GN_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,10 @@
|
|||||||
#include "utils/gryphn_version.h"
|
#include "utils/gryphn_version.h"
|
||||||
#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_allocators.h"
|
||||||
#include <gryphn_extensions.h>
|
#include <gryphn_extensions.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct gnApplicationInfo {
|
typedef struct gnApplicationInfo {
|
||||||
gnString applicationName;
|
gnString applicationName;
|
||||||
gnVersion applicationVersion;
|
gnVersion applicationVersion;
|
||||||
@@ -32,12 +34,14 @@ struct gnInstance_t {
|
|||||||
int enabledLayerCounts[GN_LAYER_MAX];
|
int enabledLayerCounts[GN_LAYER_MAX];
|
||||||
gryphnInstanceFunctionLayers* allLayers;
|
gryphnInstanceFunctionLayers* allLayers;
|
||||||
gryphnInstanceFunctionLayers* functions;
|
gryphnInstanceFunctionLayers* functions;
|
||||||
|
gnAllocators allocators;
|
||||||
|
|
||||||
loaderLayerArrayList layers;
|
loaderLayerArrayList layers;
|
||||||
loaderLayer* callingLayer;
|
loaderLayer* callingLayer;
|
||||||
uint32_t currentLayer;
|
uint32_t currentLayer;
|
||||||
gnBool hasDebugger;
|
gnBool hasDebugger;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceCreateInfo* info);
|
||||||
|
@@ -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_allocators.h"
|
||||||
|
|
||||||
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
typedef struct gnInstanceCreateInfo gnInstanceCreateInfo;
|
||||||
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
typedef struct gnSurfaceDetails gnSurfaceDetails;
|
||||||
@@ -19,8 +20,8 @@ typedef struct gnOutputDeviceInfo gnOutputDeviceInfo;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers;
|
typedef struct gryphnInstanceFunctionLayers gryphnInstanceFunctionLayers;
|
||||||
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next);
|
typedef gnReturnCode (*PFN_gnCreateInstance)(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
typedef void (*PFN_gnDestroyInstance)(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
typedef struct gnInstanceFunctions {
|
typedef struct gnInstanceFunctions {
|
||||||
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
|
||||||
|
@@ -4,24 +4,24 @@
|
|||||||
#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, gryphnInstanceFunctionLayers* next) {
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors) {
|
||||||
if (next == NULL || next->createInstance == NULL) {
|
if (next == NULL || next->createInstance == 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 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) {
|
if (next == NULL || next->destroyInstance == 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")
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
next->destroyInstance(instance, next->next);
|
next->destroyInstance(instance, next->next, alloctors);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, gryphnInstanceFunctionLayers* next);
|
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* info, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next);
|
void checkDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* alloctors);
|
||||||
|
|
||||||
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