Files
Gryphn/projects/validation_layers/function_loader/src/instance_functions.c
2025-10-01 09:23:09 -04:00

111 lines
5.7 KiB
C

#include "instance_functions.h"
#include "../loader_utils.h"
#include <core/src/instance/gryphn_debugger.h>
#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, 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, alloctors);
}
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, alloctors);
}
gnBool checkIsInstanceSuitable(gnInstanceHandle instance, gnSuitableField field, gryphnInstanceFunctionLayers* next) {
if (next == NULL || next->isSuitable == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load gnIsInstanceSuitable this indicates a bug within gryphn")
});
return GN_FAILED_TO_LOAD_FUNCTION;
}
return next->isSuitable(instance, field, next);
}
gnReturnCode checkQueryDevices(gnInstanceHandle instance, uint32_t* count, gnPhysicalDeviceHandle* devices, gryphnInstanceFunctionLayers* next) {
if (next == NULL || next->queryDevices == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load gnQueryDevices this indicates a bug within gryphn")
});
return GN_FAILED_TO_LOAD_FUNCTION;
}
return next->queryDevices(instance, count, devices, next->next);
}
gnPhysicalDeviceProperties checkQueryPhysicalDeviceProperties(gnInstanceHandle instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* next) {
if (next == NULL || next->getPhysicalDeviceProperties == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load gnQueryPhysicalDeviceProperties this indicates a bug within gryphn")
});
return (gnPhysicalDeviceProperties){
.deviceID = -1,
.deviceName = gnCreateString("Invalid device"),
.deviceType = GN_PHYSICAL_DEVICE_TYPE_FAKED_GPU,
.driverVersion = -1
};
}
return next->getPhysicalDeviceProperties(instance, device, next->next);
}
gnPhysicalDeviceFeatures checkQueryPhysicalDeviceFeatures(gnInstanceHandle instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* next) {
if (next == NULL || next->getPhysicalDeviceFeatures == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load gnQueryPhysicalDeviceFeatures this indicates a bug within gryphn")
});
return (gnPhysicalDeviceFeatures){};
}
return next->getPhysicalDeviceFeatures(instance, device, next->next);
}
gnPhysicalDeviceLimits checkQueryPhysicalDeviceLimits(gnInstanceHandle instance, gnPhysicalDeviceHandle device, gryphnInstanceFunctionLayers* next) {
if (next == NULL || next->getPhysicalDeviceLimits == NULL) {
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString("Failed to load gnQueryPhysicalDeviceLimits this indicates a bug within gryphn")
});
return (gnPhysicalDeviceLimits){};
}
return next->getPhysicalDeviceLimits(instance, device, next->next);
}
gnBool checkCanDevicePresent(gnPhysicalDevice device, gnWindowSurfaceHandle windowSurface) {
// CHECK_RETURNED_FUNCTION(device->instance, _gnPhysicalDeviceCanPresentToSurface, instanceFunctions, GN_FALSE, device, windowSurface);
return GN_TRUE; // this shit needs to be fixed fast, il work out a spec part for it later
}
gnReturnCode checkCreateOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) {
CHECK_FUNCTION_WITH_RETURN_CODE(instance, _gnCreateOutputDevice, instanceFunctions, instance, device, deviceInfo);
}
void checkDestroyOutputDevice(gnOutputDeviceHandle device) {
CHECK_VOID_FUNCTION(device->instance, _gnDestroyOutputDevice, instanceFunctions, device);
}
#ifdef GN_PLATFORM_MACOS
gnReturnCode checkCreateSurfaceMacOS(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) {
CHECK_FUNCTION_WITH_RETURN_CODE(instance, _gnCreateMacOSWindowSurface, instanceFunctions, windowSurface, instance, createInfo);
}
#endif
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode checkCreateX11WindowSurface(gnWindowSurface surface, gnInstance instance, gnX11WindowSurfaceInfo info) {
CHECK_FUNCTION_WITH_RETURN_CODE(instance, _gnCreateX11WindowSurface, instanceFunctions, surface, instance, info);
}
#endif
#endif
void checkDestroyWindowSurface(gnWindowSurfaceHandle windowSurface) {
CHECK_VOID_FUNCTION(windowSurface->instance, _gnDestroyWindowSurface, instanceFunctions, windowSurface);
}
gnSurfaceDetails checkGetSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device) {
CHECK_RETURNED_FUNCTION(windowSurface->instance, _gnGetSurfaceDetails, instanceFunctions, (gnSurfaceDetails){ .formatCount = 0 }, windowSurface, device);
}