rewrite device creation in C

This commit is contained in:
Greg Wells
2025-05-21 14:56:45 -04:00
parent 7341abb617
commit 586b5bdd0c
18 changed files with 274 additions and 219 deletions

View File

@@ -3,6 +3,8 @@
// why I dont know
#include "instance/gryphn_instance.h"
#include "debugger/gryphn_debugger.h"
#include "output_device/gryphn_physical_output_device.h"
#include "output_device/gryphn_output_device.h"
typedef struct gnFunctions_t {
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
@@ -10,4 +12,14 @@ typedef struct gnFunctions_t {
gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info);
void (*_gnDestroyDebugger)(gnDebugger* debugger);
gnBool (*_gnDeviceSupportsAPI)(const gnPhysicalDevice device);
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstance* instance, uint32_t* count);
gnReturnCode (*_gnRegisterOutputDevice)(gnOutputDevice* outputDevice, gnInstance* instance, const gnPhysicalDevice physicalDevice);
void (*_gnDestroyOutputDevice)(gnOutputDevice* device);
} gnFunctions;
typedef struct gnDeviceFunctions_t {
} gnDeviceFunctions;

View File

@@ -8,7 +8,6 @@ gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info
if (instance->dynamicLib == NULL) return GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY;
instance->functions = malloc(sizeof(struct gnFunctions_t));
gnLoadFunctions(instance->dynamicLib, instance->functions);
return instance->functions->_gnCreateInstance(instance, info);
}
void gnDestroyInstance(gnInstance* instance) {

View File

@@ -40,4 +40,12 @@ void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* funct
gnLoadDLLFunction(lib, functions->_gnDestroyInstance, "gnDestroyInstanceFn");
gnLoadDLLFunction(lib, functions->_gnCreateDebugger, "gnCreateDebuggerFn");
gnLoadDLLFunction(lib, functions->_gnDestroyDebugger, "gnDestroyDebuggerFn");
gnLoadDLLFunction(lib, functions->_gnGetPhysicalDevices, "gnGetPhysicalDevicesFn");
gnLoadDLLFunction(lib, functions->_gnDeviceSupportsAPI, "gnDeviceSupportsAPIFn");
gnLoadDLLFunction(lib, functions->_gnRegisterOutputDevice, "gnRegisterOutputDeviceFn");
gnLoadDLLFunction(lib, functions->_gnDestroyOutputDevice, "gnDestroyOutputDeviceFn");
}
void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions) {
}

View File

@@ -7,6 +7,7 @@
gnBool gnIsAPISupported(gnRenderingAPI RenderingAPI);
struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI RenderingAPI);
void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* functions);
void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions);
// #ifdef GN_REVEAL_IMPL
// gnErrorCode gnInit(gnRenderingAPI RenderingAPI);

View File

@@ -0,0 +1,14 @@
#include "gryphn_output_device.h"
#include "core/instance/gryphn_instance.h"
#include "core/gryphn_platform_functions.h"
#include "core/instance/init/gryphn_init.h"
gnReturnCode gnRegisterOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, const gnPhysicalDevice physicalDevice) {
outputDevice->deviceFunctions = malloc(sizeof(gnDeviceFunctions));
gnLoadDeviceFunctions(instance->dynamicLib, outputDevice->deviceFunctions);
outputDevice->physicalDevice = (gnPhysicalDevice*)(&physicalDevice);
return instance->functions->_gnRegisterOutputDevice(outputDevice, instance, physicalDevice);
}
void gnDestroyOutputDevice(gnOutputDevice* device) {
device->physicalDevice->instance->functions->_gnDestroyOutputDevice(device);
}

View File

@@ -1,19 +1,16 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include "gryphn_physical_output_device.h"
#include <core/output_device/gryphn_physical_output_device.h>
struct gnPlatformOutputDevice;
struct gnPhysicalOutputDevice;
struct gnInstance;
struct gnDeviceFunctions_t;
struct gnOutputDevice {
ACCESS_LEVEL:
gnPlatformOutputDevice* outputDevice = nullptr;
gnPhysicalOutputDevice* physicalOutputDevice;
public:
gnOutputDevice() {}
};
typedef struct gnOutputDevice_t {
struct gnPlatformOutputDevice* outputDevice;
struct gnDeviceFunctions_t* deviceFunctions;
gnPhysicalDevice* physicalDevice;
} gnOutputDevice;
inline gnReturnCode (*gnRegisterOutputDevice)(gnOutputDevice* outputDevice, const gnInstance& instance, const gnPhysicalOutputDevice& physicalDevice);
inline void (*gnWaitForDevice)(const gnOutputDevice& device);
inline void (*gnDestroyOutputDevice)(gnOutputDevice& device);
gnReturnCode gnRegisterOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, const gnPhysicalDevice physicalDevice);
void gnDestroyOutputDevice(gnOutputDevice* device);
// inline void (*gnWaitForDevice)(const gnOutputDevice& device);

View File

@@ -0,0 +1,13 @@
#include "gryphn_physical_output_device.h"
#include "core/gryphn_platform_functions.h"
gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count) {
gnPhysicalDevice* devices = instance->functions->_gnGetPhysicalDevices(instance, count);
for (int i = 0; i < *count; i++) {
devices[i].instance = instance;
}
return devices;
}
gnBool gnDeviceSupportsAPI(const gnPhysicalDevice device) {
return device.instance->functions->_gnDeviceSupportsAPI(device);
}

View File

@@ -1,19 +1,19 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include "core/instance/gryphn_instance.h"
struct gnPlatformPhysicalOutputDevice;
struct gnInstance;
struct gnPlatformPhysicalDevice;
struct gnPhysicalOutputDevice {
ACCESS_LEVEL:
bool valid = false;
gnPlatformPhysicalOutputDevice* physicalOutputDevice = nullptr;
gnString outputDeviceName;
public:
gnPhysicalOutputDevice() {}
};
typedef struct gnPhysicalDeviceProperties_t {
// there are currently no properties
} gnPhysicalDeviceProperties;
gnString gnGetPhysicalOutputDeviceName(const gnPhysicalOutputDevice& device);
inline bool (*gnDeviceSupportsAPI)(const gnPhysicalOutputDevice& device);
inline gnPhysicalOutputDevice* (*gnGetPhysicalOutputDevices)(const gnInstance& instance, uint32_t* count);
typedef struct gnPhysicalDevice_t {
struct gnPlatformPhysicalDevice* physicalDevice;
gnString name;
struct gnPhysicalDeviceProperties_t properties;
gnInstance* instance;
} gnPhysicalDevice;
gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count);
gnBool gnDeviceSupportsAPI(const gnPhysicalDevice device);

View File

@@ -6,7 +6,8 @@ typedef enum gnReturnCode_t {
GN_UNSUPPORTED_RENDERING_API,
GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY,
GN_FAILED_CREATE_INSTANCE,
GN_FAILED_TO_CREATE_DEBUGGER
GN_FAILED_TO_CREATE_DEBUGGER,
GN_FAILED_TO_CREATE_DEVICE
// GN_UNKNOWN_ERROR,
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
@@ -16,7 +17,6 @@ typedef enum gnReturnCode_t {
// GN_UNSUPPORTED_COLOR_FORMAT,
// GN_UNKNOWN_COLOR_FORMAT,
// GN_FUNCTION_NOT_FOUND,
// GN_FAILED_CREATE_DEVICE,
// GN_FAILED_CREATE_GRAPHICS_PIPELINE,
// GN_FAILED_CREATE_PRESENTATION_QUEUE,
// GN_FAILED_TO_CREATE_FRAMEBUFFER,
@@ -35,5 +35,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
case GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY: return "GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY";
case GN_FAILED_CREATE_INSTANCE: return "GN_FAILED_CREATE_INSTANCE";
case GN_FAILED_TO_CREATE_DEBUGGER: return "GN_FAILED_TO_CREATE_DEBUGGER";
case GN_FAILED_TO_CREATE_DEVICE: return "GN_FAILED_TO_CREATE_DEVICE";
}
}