start checking all instance functions

This commit is contained in:
Greg Wells
2025-06-27 21:22:05 -04:00
parent f98dc5fead
commit 502634770e
10 changed files with 205 additions and 16 deletions

View File

@@ -1,11 +1,47 @@
#include "function_loader.h"
#include "instance_functions.h"
gnInstanceFunctions loadFunctionLoaderInstanceFunctions(gnInstanceFunctions* callbacks) {
return *callbacks;
gnInstanceFunctions loadFunctionLoaderInstanceFunctions() {
return (gnInstanceFunctions){
._gnCreateInstance = checkCreateInstance,
._gnDestroyInstance = checkDestroyInstance,
._gnGetPhysicalDevices = checkGetPhysicalDevices,
._gnQueueCanPresentToSurface = checkQueueCanPresentToSurface,
._gnCreateOutputDevice = checkCreateOutputDevice,
._gnDestroyOutputDevice = checkDestroyOutputDevice,
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
._gnCreateX11WindowSurface = checkCreateX11WindowSurface,
#endif
#ifdef GN_WINDOW_WAYLAND
._gnCreateWaylandWindowSurface,
#endif
#endif
#ifdef GN_PLATFORM_WIN32
._gnCreateWin32WindowSurface,
#endif
#ifdef GN_PLATFORM_MACOS
._gnCreateMacOSWindowSurface = checkCreateSurfaceMacOS,
#endif
._gnDestroyWindowSurface = checkDestroyWindowSurface,
._gnGetSurfaceDetails = checkGetSurfaceDetails
};
}
gnDeviceFunctions loadFunctionLoaderDeviceFunctions(gnDeviceFunctions* callbacks) {
return *callbacks;
gnDeviceFunctions loadFunctionLoaderDeviceFunctions() {
return (gnDeviceFunctions){
NULL
};
}
gnCommandFunctions loadFunctionLoaderCommandFunctions(gnCommandFunctions* callbacks) {
return *callbacks;
gnCommandFunctions loadFunctionLoaderCommandFunctions() {
return (gnCommandFunctions){
NULL
};
}

View File

@@ -3,6 +3,6 @@
#include "loader/src/gryphn_device_functions.h"
#include "loader/src/gryphn_command_functions.h"
gnInstanceFunctions loadFunctionLoaderInstanceFunctions(gnInstanceFunctions* callbacks);
gnDeviceFunctions loadFunctionLoaderDeviceFunctions(gnDeviceFunctions* callbacks);
gnCommandFunctions loadFunctionLoaderCommandFunctions(gnCommandFunctions* callbacks);
gnInstanceFunctions loadFunctionLoaderInstanceFunctions();
gnDeviceFunctions loadFunctionLoaderDeviceFunctions();
gnCommandFunctions loadFunctionLoaderCommandFunctions();

View File

@@ -0,0 +1,95 @@
#include "instance_functions.h"
#include "core/src/debugger/gryphn_debugger.h"
#include "core/src/output_device/gryphn_output_device.h"
#include "core/src/window_surface/gryphn_surface.h"
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceInfo info) {
loaderLayer* nextLayer = loaderGetNextLayer(instance);
if (nextLayer->instanceFunctions._gnCreateInstance == NULL) {
return GN_FAILED_TO_LOAD_FUNCTION;
resetLayer(instance);
}
return nextLayer->instanceFunctions._gnCreateInstance(instance, info);
}
void checkDestroyInstance(gnInstance instance) {
loaderLayer* nextLayer = loaderGetNextLayer(instance);
if (nextLayer->instanceFunctions._gnDestroyInstance == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load destroy instance function")
});
resetLayer(instance);
}
return nextLayer->instanceFunctions._gnDestroyInstance(instance);
}
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count) {
loaderLayer* nextLayer = loaderGetNextLayer(instance);
if (nextLayer->instanceFunctions._gnGetPhysicalDevices == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load get physical devices function")
});
resetLayer(instance);
}
return nextLayer->instanceFunctions._gnGetPhysicalDevices(instance, count);
}
gnBool checkQueueCanPresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, const gnWindowSurfaceHandle windowSurface) {
loaderLayer* nextLayer = loaderGetNextLayer(device.instance);
if (nextLayer->instanceFunctions._gnQueueCanPresentToSurface == NULL) {
gnDebuggerSetErrorMessage(device.instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load queue can present to surface function")
});
resetLayer(device.instance);
return gnFalse;
}
return nextLayer->instanceFunctions._gnQueueCanPresentToSurface(device, queueIndex, windowSurface);
}
gnReturnCode checkCreateOutputDevice(gnOutputDeviceHandle device, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
loaderLayer* nextLayer = loaderGetNextLayer(device->instance);
if (nextLayer->instanceFunctions._gnCreateOutputDevice == NULL) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load create output device function")
});
resetLayer(device->instance);
return GN_FAILED_TO_LOAD_FUNCTION;
}
return nextLayer->instanceFunctions._gnCreateOutputDevice(device, instance, deviceInfo);
}
void checkDestroyOutputDevice(gnOutputDeviceHandle device) {
loaderLayer* nextLayer = loaderGetNextLayer(device->instance);
if (nextLayer->instanceFunctions._gnDestroyOutputDevice == NULL) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load destroy output device function")
});
resetLayer(device->instance);
}
return nextLayer->instanceFunctions._gnDestroyOutputDevice(device);
}
gnReturnCode checkCreateSurfaceMacOS(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
loaderLayer* nextLayer = loaderGetNextLayer(instance);
if (nextLayer->instanceFunctions._gnCreateMacOSWindowSurface == NULL) { return GN_FAILED_TO_LOAD_FUNCTION; }
return nextLayer->instanceFunctions._gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
}
void checkDestroyWindowSurface(gnWindowSurfaceHandle windowSurface) {
loaderLayer* nextLayer = loaderGetNextLayer(windowSurface->instance);
if (nextLayer->instanceFunctions._gnDestroyWindowSurface == NULL) {
gnDebuggerSetErrorMessage(windowSurface->instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load destroy create surface function")
});
resetLayer(windowSurface->instance);
}
return nextLayer->instanceFunctions._gnDestroyWindowSurface(windowSurface);
}
gnSurfaceDetails checkGetSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device) {
loaderLayer* nextLayer = loaderGetNextLayer(windowSurface->instance);
if (nextLayer->instanceFunctions._gnGetSurfaceDetails == NULL) {
gnDebuggerSetErrorMessage(windowSurface->instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load get surface details function")
});
resetLayer(windowSurface->instance);
}
return nextLayer->instanceFunctions._gnGetSurfaceDetails(windowSurface, device);
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "core/src/instance/gryphn_instance.h"
#include <core/src/window_surface/gryphn_surface_create_functions.h>
gnReturnCode checkCreateInstance(gnInstanceHandle instance, gnInstanceInfo info);
void checkDestroyInstance(gnInstance instance);
gnPhysicalDevice* checkGetPhysicalDevices(gnInstanceHandle instance, uint32_t* count);
gnBool checkQueueCanPresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, const gnWindowSurfaceHandle windowSurface);
gnReturnCode checkCreateOutputDevice(gnOutputDeviceHandle device, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo);
void checkDestroyOutputDevice(gnOutputDeviceHandle device);
#ifdef GN_PLATFORM_MACOS
gnReturnCode checkCreateSurfaceMacOS(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo);
#endif
void checkDestroyWindowSurface(gnWindowSurfaceHandle windowSurface);
gnSurfaceDetails checkGetSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device);