device handles

This commit is contained in:
Greg Wells
2025-06-03 13:49:05 -04:00
parent ee03b87600
commit d39f598d3c
7 changed files with 41 additions and 34 deletions

View File

@@ -5,7 +5,7 @@
#include "core/instance/gryphn_instance.h"
#include <core/debugger/gryphn_debugger.h>
gnReturnCode gnCreateOutputDeviceFn(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain;
outputDevice->outputDevice->queueCount = deviceInfo.queueInfoCount;
@@ -17,11 +17,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDevice* outputDevice, gnInstanceHand
return GN_SUCCESS;
}
void gnWaitForDeviceFn(gnOutputDevice *device) {
void gnWaitForDeviceFn(gnOutputDeviceHandle device) {
[device->outputDevice->executingCommandBuffer waitUntilCompleted];
}
void gnDestroyOutputDeviceFn(gnOutputDevice* device) {
void gnDestroyOutputDeviceFn(gnOutputDeviceHandle device) {
for (int i = 0; i < device->outputDevice->queueCount; i++) {
[device->outputDevice->queues[i] release];
}

View File

@@ -5,7 +5,7 @@
#include "core/texture/metal_texture.h"
#include "core/sync/semaphore/metal_semaphore.h"
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) {
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo) {
if (presentationInfo.minImageCount > 3) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("On Metal you cannot have more than 3 images in a presentation queue")

View File

@@ -5,7 +5,7 @@
#include <stdio.h>
gnReturnCode gnCreateOutputDeviceFn(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
VkDeviceQueueCreateInfo* queueCreateInfos = malloc(sizeof(VkDeviceQueueCreateInfo) * deviceInfo.queueInfoCount);
@@ -64,11 +64,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDevice* outputDevice, gnInstanceHand
return GN_SUCCESS;
}
void gnWaitForDeviceFn(const gnOutputDevice* device) {
void gnWaitForDeviceFn(const gnOutputDeviceHandle device) {
vkDeviceWaitIdle(device->outputDevice->device);
}
void gnDestroyOutputDeviceFn(gnOutputDevice* device) {
void gnDestroyOutputDeviceFn(gnOutputDeviceHandle device) {
vkDestroyDevice(device->outputDevice->device, NULL);
free(device->outputDevice);
}

View File

@@ -6,7 +6,7 @@
#include "textures/vulkan_texture.h"
#include "sync/semaphore/vulkan_semaphore.h"
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) {
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo) {
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
vkSwapchainSupportDetails details = vkGetSwapchainSupport(device->physicalDevice.physicalDevice->device, presentationInfo.surface.windowSurface->surface);

View File

@@ -30,8 +30,8 @@ typedef struct gnFunctions_t {
gnBool (*_gnQueueCanPresentToSurface)(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface);
gnReturnCode (*_gnCreateOutputDevoce)(gnOutputDevice* device, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void (*_gnDestroyOutputDevice)(gnOutputDevice* device);
gnReturnCode (*_gnCreateOutputDevoce)(gnOutputDeviceHandle device, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void (*_gnDestroyOutputDevice)(gnOutputDeviceHandle device);
@@ -59,38 +59,38 @@ typedef struct gnFunctions_t {
#include "core/presentation_queue/gryphn_presentation_queue.h"
typedef struct gnDeviceFunctions_t {
gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo);
gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueue* presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo);
gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueue* presentationQueue, uint64_t timeout, struct gnSemaphore_t* semaphore, uint32_t* imageIndex);
void (*_gnDestroyPresentationQueue)(gnPresentationQueue *presentationQueue);
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, struct gnOutputDevice_t* device, struct gnShaderModuleInfo_t shaderModuleInfo);
gnReturnCode (*_gnCreateShaderModule)(struct gnShaderModule_t* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo);
void (*_gnDestroyShaderModule)(struct gnShaderModule_t* module);
gnReturnCode (*_gnCreateRenderPassDescriptor)(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info);
gnReturnCode (*_gnCreateRenderPassDescriptor)(struct gnRenderPassDescriptor_t* renderPass, gnOutputDeviceHandle device, struct gnRenderPassDescriptorInfo_t info);
void (*_gnDestroyRenderPassDescriptor)(struct gnRenderPassDescriptor_t* renderPass);
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t pipelineInfo);
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, gnOutputDeviceHandle device, struct gnGraphicsPipelineInfo_t pipelineInfo);
void (*_gnDestroyGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline);
gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t framebufferInfo);
gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, gnOutputDeviceHandle device, struct gnFramebufferInfo_t framebufferInfo);
void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer);
gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info);
gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info);
void (*_gnDestroyCommandPool)(struct gnCommandPool_t* commandPool);
gnReturnCode (*_gnCreateSemaphore)(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device);
gnReturnCode (*_gnCreateSemaphore)(struct gnSemaphore_t* semaphore, gnOutputDeviceHandle device);
void (*_gnDestroySemaphore)(struct gnSemaphore_t* semaphore);
gnReturnCode (*_gnCreateFence)(struct gnFence_t* fence, struct gnOutputDevice_t* device);
gnReturnCode (*_gnCreateFence)(struct gnFence_t* fence, gnOutputDeviceHandle device);
void (*_gnSignalFence)(struct gnFence_t* fence);
void (*_gnWaitForFence)(struct gnFence_t* fence, uint64_t timeout);
void (*_gnResetFence)(struct gnFence_t* fence);
void (*_gnDestroyFence)(struct gnFence_t* fence);
gnReturnCode (*_gnSubmit)(struct gnOutputDevice_t* device, struct gnSubmitInfo_t submit);
gnReturnCode (*_gnPresent)(struct gnOutputDevice_t* device, struct gnPresentInfo_t info);
gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, struct gnSubmitInfo_t submit);
gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, struct gnPresentInfo_t info);
void (*_gnWaitForDevice)(struct gnOutputDevice_t* device);
void (*_gnWaitForDevice)(gnOutputDeviceHandle device);
} gnDeviceFunctions;
typedef struct gnCommandFunctions_t {

View File

@@ -3,23 +3,26 @@
#include "core/gryphn_platform_functions.h"
#include "core/instance/init/gryphn_init.h"
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
*outputDevice = malloc(sizeof(struct gnOutputDevice_t));
if (instance->loadDeviceFunctions == gnFalse) {
instance->deviceFunctions = malloc(sizeof(struct gnDeviceFunctions_t));
gnLoadDeviceFunctions(instance->dynamicLib, instance->deviceFunctions);
instance->loadDeviceFunctions = gnTrue;
}
outputDevice->deviceFunctions = instance->deviceFunctions;
(*outputDevice)->deviceFunctions = instance->deviceFunctions;
outputDevice->instance = instance;
outputDevice->physicalDevice = deviceInfo.physicalDevice;
outputDevice->deviceInfo = deviceInfo;
return instance->functions->_gnCreateOutputDevoce(outputDevice, instance, deviceInfo);
(*outputDevice)->instance = instance;
(*outputDevice)->physicalDevice = deviceInfo.physicalDevice;
(*outputDevice)->deviceInfo = deviceInfo;
return instance->functions->_gnCreateOutputDevoce(*outputDevice, instance, deviceInfo);
}
void gnWaitForDevice(gnOutputDevice *device) {
void gnWaitForDevice(gnOutputDeviceHandle device) {
device->deviceFunctions->_gnWaitForDevice(device);
}
void gnDestroyOutputDevice(gnOutputDevice* device) {
void gnDestroyOutputDevice(gnOutputDeviceHandle device) {
device->instance->functions->_gnDestroyOutputDevice(device);
free(device);
}

View File

@@ -17,14 +17,18 @@ typedef struct gnOutputDeviceInfo_t {
struct gnPhysicalDevice_t physicalDevice;
} gnOutputDeviceInfo;
typedef struct gnOutputDevice_t {
#ifdef GN_REVEAL_IMPL
struct gnOutputDevice_t {
struct gnPlatformOutputDevice_t* outputDevice;
struct gnDeviceFunctions_t* deviceFunctions;
struct gnOutputDeviceInfo_t deviceInfo;
gnInstanceHandle instance;
gnPhysicalDevice physicalDevice;
} gnOutputDevice;
};
#endif
typedef struct gnOutputDevice_t* gnOutputDeviceHandle;
typedef gnOutputDeviceHandle gnOutputDevice;
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void gnWaitForDevice(gnOutputDevice* device);
void gnDestroyOutputDevice(gnOutputDevice* device);
gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void gnWaitForDevice(gnOutputDeviceHandle device);
void gnDestroyOutputDevice(gnOutputDeviceHandle device);