This commit is contained in:
Gregory Wells
2025-08-12 16:07:08 -04:00
34 changed files with 19842 additions and 167 deletions

View File

@@ -0,0 +1,15 @@
#pragma once
#include <stddef.h>
typedef void* (*PFN_gnMalloc) (size_t size, void* userData);
typedef void* (*PFN_gnCalloc) (int cnt, size_t size, void* userData);
typedef void* (*PFN_gnRealloc) (void* ptr, size_t size, void* userData);
typedef void (*PFN_gnFree) (void* ptr, void* userData);
typedef struct gnAllocators {
void* userData;
PFN_gnMalloc malloc;
PFN_gnCalloc calloc;
PFN_gnRealloc realloc;
PFN_gnFree free;
} gnAllocators;

View File

@@ -12,7 +12,7 @@ typedef enum gnReturnCode {
GN_FAILED_TO_FIND_ENTRY_POINT, GN_FAILED_TO_LOAD_FUNCTION, GN_INCOMPLETE,
GN_NOT_READY, GN_TIMEOUT, GN_DEVICE_LOST, GN_FAILED_MEMORY_MAP, GN_UNSUPPORTED_FEATURE,
GN_OVERALLOCATION, GN_FRAGMENTATION, GN_INVALID_HANDLE, GN_SURFACE_LOST, GN_WINDOW_IN_USE,
GN_INCOMPATIBLE_DISPLAY, GN_UNSUPPORTED_IMAGE_USE,
GN_INCOMPATIBLE_DISPLAY, GN_UNSUPPORTED_IMAGE_USE, GN_FAILED_CREATE_ALLOCATOR,
GN_UNLOADED_EXTENSION = -1,
GN_UNLOADED_LAYER = -2,

View File

@@ -21,6 +21,9 @@ void* gnMapBuffer(gnBufferHandle buffer) {
if (buffer->info.usage == GN_STATIC_DRAW) return NULL;
return buffer->device->instance->callingLayer->deviceFunctions._gnMapBuffer(buffer);
}
void gnUnmapBuffer(gnBufferHandle buffer) {
buffer->device->instance->callingLayer->deviceFunctions._gnUnmapBuffer(buffer);
}
void gnDestroyBuffer(gnBufferHandle buffer) {
buffer->device->instance->callingLayer->deviceFunctions._gnDestroyBuffer(buffer);
}

View File

@@ -9,10 +9,10 @@ typedef enum gnIndexType {
} gnIndexType;
typedef enum gnBufferType {
GN_VERTEX_BUFFER = 0x00000001,
GN_INDEX_BUFFER = 0x00000002,
GN_UNIFORM_BUFFER = 0x00000004,
GN_STORAGE_BUFFER = 0x00000008
GN_VERTEX_BUFFER = 1 << 0,
GN_INDEX_BUFFER = 1 << 2,
GN_UNIFORM_BUFFER = 1 << 3,
GN_STORAGE_BUFFER = 1 << 4
} gnBufferType; // I need to support more buffer types
// i love that OpenGL does this so im stealing it
@@ -44,4 +44,5 @@ gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device,
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
void gnBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data);
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
void gnUnmapBuffer(gnBufferHandle buffer);
void gnDestroyBuffer(gnBufferHandle buffer);

View File

@@ -0,0 +1,10 @@
#include "gryphn_debugger.h"
void gnDebuggerSetVerboseMessage(gnDebuggerCreateInfo* debugger, gnMessageData data) {
debugger->callback(
GN_MESSAGE_VERBOSE,
GN_DEBUG_MESSAGE_GENERAL,
data,
debugger->userData
);
}

View File

@@ -29,7 +29,8 @@ typedef gnBool (*gnDebuggerCallback)(
typedef enum gnDebuggerLayer {
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
GN_DEBUGGER_LAYER_FUNCTIONS, // enable the checks on every function
GN_DEBUGGER_LAYER_FUNCTIONS, // enable the checks on every function,
GN_DEBUGGER_LAYER_ALLOCATORS, // enable the layer which debugs all allocations within Gryphn
GN_LAYER_MAX
} gnDebuggerLayer;
@@ -42,6 +43,7 @@ typedef struct gnDebuggerCreateInfo {
} gnDebuggerCreateInfo;
#ifdef GN_REVEAL_IMPL
void gnDebuggerSetVerboseMessage(gnDebuggerCreateInfo* debugger, gnMessageData data);
static inline void gnDebuggerSetErrorMessage(gnDebuggerCreateInfo debugger, gnMessageData data) {
if (debugger.callback == 0) return;
debugger.callback(

View File

@@ -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;
}

View File

@@ -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);