From 8d2c58b0e969a255b7b30db35e2464869398e2e1 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Tue, 24 Jun 2025 13:46:01 -0400 Subject: [PATCH] move device functions over to loader --- .../apis/vulkan/loader/vulkan_device_loader.c | 7 ++ .../vulkan/loader/vulkan_instance_loader.c | 2 +- projects/apis/vulkan/loader/vulkan_loader.h | 5 +- .../command_pool/vulkan_command_pool.c | 2 +- .../src/commands/commands/vulkan_commands.c | 4 +- .../src/framebuffers/vulkan_framebuffer.c | 4 +- .../vulkan_graphics_pipeline.c | 13 ++-- .../apis/vulkan/src/present/vulkan_present.c | 2 +- .../vulkan_presentation_queue.c | 2 +- .../apis/vulkan/src/submit/vulkan_submit.c | 4 +- .../command_buffer/gryphn_command_buffer.c | 2 +- .../command_pool/gryphn_command_pool.c | 3 +- .../command_pool/gryphn_command_pool.h | 5 +- .../src/command/commands/gryphn_command.c | 12 ++-- .../core/src/framebuffer/gryphn_framebuffer.h | 2 +- projects/core/src/gryphn_platform_functions.h | 64 ----------------- projects/core/src/instance/gryphn_instance.c | 8 ++- projects/core/src/instance/gryphn_instance.h | 7 +- .../src/output_device/gryphn_output_device.c | 3 +- .../src/output_device/gryphn_output_device.h | 3 +- .../gryphn_graphics_pipeline.h | 26 +++---- projects/core/src/present/gryphn_present.c | 4 +- projects/core/src/present/gryphn_present.h | 2 +- .../gryphn_presentation_queue.c | 1 - .../gryphn_presentation_queue.h | 4 +- .../src/shader_module/gryphn_shader_module.c | 2 +- .../src/shader_module/gryphn_shader_module.h | 6 +- projects/core/src/submit/gryphn_submit.c | 2 +- projects/core/src/submit/gryphn_submit.h | 2 +- projects/loader/src/gryphn_device_functions.h | 70 +++++++++++++++++++ projects/loader/src/gryphn_loader.c | 25 ++++++- projects/loader/src/gryphn_loader.h | 8 ++- 32 files changed, 172 insertions(+), 134 deletions(-) create mode 100644 projects/apis/vulkan/loader/vulkan_device_loader.c create mode 100644 projects/loader/src/gryphn_device_functions.h diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c new file mode 100644 index 0000000..3cce394 --- /dev/null +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -0,0 +1,7 @@ +#include "vulkan_loader.h" + +gnDeviceFunctions loadVulkanDeviceFunctions() { + return (gnDeviceFunctions){ + NULL + }; +} diff --git a/projects/apis/vulkan/loader/vulkan_instance_loader.c b/projects/apis/vulkan/loader/vulkan_instance_loader.c index 23947a0..f74959a 100644 --- a/projects/apis/vulkan/loader/vulkan_instance_loader.c +++ b/projects/apis/vulkan/loader/vulkan_instance_loader.c @@ -4,7 +4,7 @@ #include #include -gnInstanceFunctions loadVulkanFunctions(gnRenderingAPI api) { +gnInstanceFunctions loadVulkanInstanceFunctions() { return (gnInstanceFunctions){ ._gnCreateInstance = createInstance, ._gnDestroyInstance = destroyInstance, diff --git a/projects/apis/vulkan/loader/vulkan_loader.h b/projects/apis/vulkan/loader/vulkan_loader.h index 7246c4c..c553e7e 100644 --- a/projects/apis/vulkan/loader/vulkan_loader.h +++ b/projects/apis/vulkan/loader/vulkan_loader.h @@ -1,5 +1,6 @@ #pragma once #include "loader/src/gryphn_instance_functions.h" -#include "core/src/gryphn_rendering_api.h" +#include "loader/src/gryphn_device_functions.h" -gnInstanceFunctions loadVulkanFunctions(gnRenderingAPI api); +gnInstanceFunctions loadVulkanInstanceFunctions(); +gnDeviceFunctions loadVulkanDeviceFunctions(); diff --git a/projects/apis/vulkan/src/commands/command_pool/vulkan_command_pool.c b/projects/apis/vulkan/src/commands/command_pool/vulkan_command_pool.c index ba5aab1..7ab713d 100644 --- a/projects/apis/vulkan/src/commands/command_pool/vulkan_command_pool.c +++ b/projects/apis/vulkan/src/commands/command_pool/vulkan_command_pool.c @@ -1,7 +1,7 @@ #include "vulkan_command_pool.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info) { +gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, gnCommandPoolInfo info) { commandPool->commandPool = malloc(sizeof(gnPlatformCommandPool)); VkCommandPoolCreateInfo poolInfo = { diff --git a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c index af316ab..fed4589 100644 --- a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c +++ b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c @@ -8,7 +8,7 @@ #include "uniforms/vulkan_uniform.h" #include "shader_module/vulkan_shader_module.h" -void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, struct gnRenderPassInfo_t passInfo) { +void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, gnRenderPassInfo passInfo) { VkClearValue* values = malloc(sizeof(VkClearValue) * passInfo.clearValueCount); for (int i = 0; i < passInfo.clearValueCount; i++) { values[i] = (VkClearValue){{{ @@ -51,7 +51,7 @@ void gnCommandSetViewportFn(gnCommandBuffer buffer, gnViewport viewport) { }; vkCmdSetViewport(buffer->commandBuffer->buffer, 0, 1, &vkViewport); } -void gnCommandSetScissorFn(gnCommandBuffer buffer, struct gnScissor_t scissor) { +void gnCommandSetScissorFn(gnCommandBuffer buffer, gnScissor scissor) { VkRect2D vkScissor = { .extent = { scissor.size.x, scissor.size.y }, .offset = { scissor.position.x, scissor.position.y } diff --git a/projects/apis/vulkan/src/framebuffers/vulkan_framebuffer.c b/projects/apis/vulkan/src/framebuffers/vulkan_framebuffer.c index 8ce9ee3..1154d76 100644 --- a/projects/apis/vulkan/src/framebuffers/vulkan_framebuffer.c +++ b/projects/apis/vulkan/src/framebuffers/vulkan_framebuffer.c @@ -3,7 +3,7 @@ #include "renderpass/vulkan_render_pass_descriptor.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t info) { +gnReturnCode gnCreateFramebufferFn(gnFramebuffer framebuffer, gnDevice device, gnFramebufferInfo info) { framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t)); VkImageView* attachments = malloc(sizeof(VkImageView) * info.attachmentCount); @@ -28,7 +28,7 @@ gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct g return GN_SUCCESS; } -void gnDestroyFramebufferFn(struct gnFramebuffer_t* framebuffer) { +void gnDestroyFramebufferFn(gnFramebuffer framebuffer) { vkDestroyFramebuffer(framebuffer->device->outputDevice->device, framebuffer->framebuffer->framebuffer, NULL); free(framebuffer->framebuffer); } diff --git a/projects/apis/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c b/projects/apis/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c index 13edd55..b97579d 100644 --- a/projects/apis/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c +++ b/projects/apis/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c @@ -4,10 +4,7 @@ #include "renderpass/vulkan_render_pass_descriptor.h" #include "uniforms/vulkan_uniform_layout.h" -#include "stdio.h" - - -VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) { +VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(gnDynamicState state) { switch (state) { case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT; case GN_DYNAMIC_SCISSOR: return VK_DYNAMIC_STATE_SCISSOR; @@ -26,7 +23,7 @@ VkPrimitiveTopology vkGryphnPrimitiveType(gnPrimitiveType primitiveType) { } } -VkPolygonMode vkGryphnPolygonMode(enum gnFillMode_e fillMode) { +VkPolygonMode vkGryphnPolygonMode(gnFillMode fillMode) { switch (fillMode) { case GN_FILL_MODE_FILL: return VK_POLYGON_MODE_FILL; case GN_FILL_MODE_LINE: return VK_POLYGON_MODE_LINE; @@ -34,7 +31,7 @@ VkPolygonMode vkGryphnPolygonMode(enum gnFillMode_e fillMode) { } } -VkCullModeFlags vkGryphnCullMode(enum gnCullFace_e face) { +VkCullModeFlags vkGryphnCullMode(gnCullFace face) { switch (face) { case GN_CULL_FACE_NONE: return VK_CULL_MODE_NONE; case GN_CULL_FACE_BACK: return VK_CULL_MODE_BACK_BIT; @@ -42,7 +39,7 @@ VkCullModeFlags vkGryphnCullMode(enum gnCullFace_e face) { } } -VkBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) { +VkBlendFactor vkGryphnBlendFactor(gnBlendFactor factor) { switch (factor) { case GN_BLEND_FACTOR_ZERO: return VK_BLEND_FACTOR_ZERO; case GN_BLEND_FACTOR_ONE: return VK_BLEND_FACTOR_ONE; @@ -51,7 +48,7 @@ VkBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) { } } -VkBlendOp vkGryphnBlendOperation(enum gnBlendOperation_e operation) { +VkBlendOp vkGryphnBlendOperation(gnBlendOperation operation) { switch(operation) { case GN_OPERATION_ADD: return VK_BLEND_OP_ADD; } diff --git a/projects/apis/vulkan/src/present/vulkan_present.c b/projects/apis/vulkan/src/present/vulkan_present.c index 551ba4f..9dd2eb5 100644 --- a/projects/apis/vulkan/src/present/vulkan_present.c +++ b/projects/apis/vulkan/src/present/vulkan_present.c @@ -3,7 +3,7 @@ #include "presentation_queue/vulkan_presentation_queue.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t info) { +gnReturnCode gnPresentFn(gnDevice device, gnPresentInfo info) { VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c index e1dabf9..fd22a1e 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -7,7 +7,7 @@ #include "sync/semaphore/vulkan_semaphore.h" #include "stdio.h" -gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo) { +gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnDevice device, gnPresentationQueueInfo presentationInfo) { presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t)); vkSwapchainSupportDetails details = vkGetSwapchainSupport(device->physicalDevice.physicalDevice->device, presentationInfo.surface->windowSurface->surface); diff --git a/projects/apis/vulkan/src/submit/vulkan_submit.c b/projects/apis/vulkan/src/submit/vulkan_submit.c index 3e6828d..0c5c8ef 100644 --- a/projects/apis/vulkan/src/submit/vulkan_submit.c +++ b/projects/apis/vulkan/src/submit/vulkan_submit.c @@ -7,9 +7,7 @@ #include "renderpass/vulkan_render_pass_descriptor.h" -gnReturnCode gnSubmitFn(struct gnOutputDevice_t* device, struct gnSubmitInfo_t info) { - VK_SUBPASS_EXTERNAL; - +gnReturnCode gnSubmitFn(gnDevice device, gnSubmitInfo info) { VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount); VkPipelineStageFlags* waitStages = malloc(sizeof(VkPipelineStageFlags) * info.waitCount); for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore; diff --git a/projects/core/src/command/command_buffer/gryphn_command_buffer.c b/projects/core/src/command/command_buffer/gryphn_command_buffer.c index b4c5d92..fff18cc 100644 --- a/projects/core/src/command/command_buffer/gryphn_command_buffer.c +++ b/projects/core/src/command/command_buffer/gryphn_command_buffer.c @@ -1,5 +1,5 @@ #include "gryphn_command_buffer.h" -#include "gryphn_platform_functions.h" +#include "command/command_pool/gryphn_command_pool.h" gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) { for (int i = 0; i < count; i++) { diff --git a/projects/core/src/command/command_pool/gryphn_command_pool.c b/projects/core/src/command/command_pool/gryphn_command_pool.c index d6c9b72..5854101 100644 --- a/projects/core/src/command/command_pool/gryphn_command_pool.c +++ b/projects/core/src/command/command_pool/gryphn_command_pool.c @@ -1,7 +1,6 @@ #include "gryphn_command_pool.h" -#include "gryphn_platform_functions.h" -gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info) { +gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info) { *commandPool = malloc(sizeof(struct gnCommandPool_t)); (*commandPool)->commandFunctions = device->instance->commandFunctions; diff --git a/projects/core/src/command/command_pool/gryphn_command_pool.h b/projects/core/src/command/command_pool/gryphn_command_pool.h index bfc84a7..786aec1 100644 --- a/projects/core/src/command/command_pool/gryphn_command_pool.h +++ b/projects/core/src/command/command_pool/gryphn_command_pool.h @@ -2,8 +2,9 @@ #include "stdint.h" #include #include "gryphn_handles.h" +#include -typedef struct gnCommandPoolInfo_t { +typedef struct gnCommandPoolInfo { uint32_t queueIndex; } gnCommandPoolInfo; @@ -15,5 +16,5 @@ struct gnCommandPool_t { }; #endif -gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info); +gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info); void gnDestroyCommandPool(gnCommandPoolHandle commandPool); diff --git a/projects/core/src/command/commands/gryphn_command.c b/projects/core/src/command/commands/gryphn_command.c index b9bd0f8..f2e271a 100644 --- a/projects/core/src/command/commands/gryphn_command.c +++ b/projects/core/src/command/commands/gryphn_command.c @@ -3,20 +3,20 @@ #include "command/command_pool/gryphn_command_pool.h" #include "gryphn_platform_functions.h" -void gnCommandBeginRenderPass(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) { +void gnCommandBeginRenderPass(gnCommandBufferHandle buffer, gnRenderPassInfo passInfo) { buffer->commandPool->commandFunctions->_gnCommandBeginRenderPass(buffer, passInfo); } -void gnCommandEndRenderPass(struct gnCommandBuffer_t* buffer) { +void gnCommandEndRenderPass(gnCommandBufferHandle buffer) { buffer->commandPool->commandFunctions->_gnCommandEndRenderPass(buffer); } -void gnCommandBindGraphicsPipeline(struct gnCommandBuffer_t* buffer, struct gnGraphicsPipeline_t* graphicsPipeline) { +void gnCommandBindGraphicsPipeline(gnCommandBufferHandle buffer, gnGraphicsPipeline graphicsPipeline) { buffer->commandPool->commandFunctions->_gnCommandBindGraphicsPipeline(buffer, graphicsPipeline); } -void gnCommandSetViewport(struct gnCommandBuffer_t* buffer, struct gnViewport_t viewport) { +void gnCommandSetViewport(gnCommandBufferHandle buffer, gnViewport viewport) { buffer->commandPool->commandFunctions->_gnCommandSetViewport(buffer, viewport); } -void gnCommandSetScissor(struct gnCommandBuffer_t* buffer, struct gnScissor_t scissor) { +void gnCommandSetScissor(gnCommandBufferHandle buffer, gnScissor scissor) { buffer->commandPool->commandFunctions->_gnCommandSetScissor(buffer, scissor); } void gnCommandBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) { @@ -28,7 +28,7 @@ void gnCommandBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBi void gnCommandPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) { buffer->commandPool->commandFunctions->_gnCommandPushConstant(buffer, layout, data); } -void gnCommandDraw(struct gnCommandBuffer_t* buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance) { +void gnCommandDraw(gnCommandBufferHandle buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance) { buffer->commandPool->commandFunctions->_gnCommandDraw(buffer, vertexCount, firstVertex, instanceCount, firstInstance); } void gnCommandDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance) { diff --git a/projects/core/src/framebuffer/gryphn_framebuffer.h b/projects/core/src/framebuffer/gryphn_framebuffer.h index 2c7e296..a7516c4 100644 --- a/projects/core/src/framebuffer/gryphn_framebuffer.h +++ b/projects/core/src/framebuffer/gryphn_framebuffer.h @@ -3,7 +3,7 @@ #include "utils/gryphn_error_code.h" #include "gryphn_handles.h" -typedef struct gnFramebufferInfo_t { +typedef struct gnFramebufferInfo { gnRenderPassDescriptorHandle renderPassDescriptor; uint32_t attachmentCount; gnTextureHandle* attachments; diff --git a/projects/core/src/gryphn_platform_functions.h b/projects/core/src/gryphn_platform_functions.h index 7eb5b79..4a05dea 100644 --- a/projects/core/src/gryphn_platform_functions.h +++ b/projects/core/src/gryphn_platform_functions.h @@ -3,74 +3,10 @@ // why I dont know #include "instance/gryphn_instance.h" #include -#include "output_device/gryphn_physical_output_device.h" -#include "output_device/gryphn_output_device.h" -#include "window_surface/gryphn_surface.h" #include -#include "shader_module/gryphn_shader_module.h" -#include "renderpass/gryphn_render_pass_descriptor.h" #include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" -#include "framebuffer/gryphn_framebuffer.h" -#include "command/command_pool/gryphn_command_pool.h" #include "renderpass/gryphn_render_pass.h" -#include "submit/gryphn_submit.h" -#include "present/gryphn_present.h" #include "buffers/gryphn_buffer.h" -#include "uniforms/gryphn_uniform.h" -#include "textures/gryphn_texture.h" -#include "uniforms/gryphn_uniform_pool.h" - -#include "presentation_queue/gryphn_presentation_queue.h" -typedef struct gnDeviceFunctions_t { - gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo); - gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); - void (*_gnDestroyPresentationQueue)(gnPresentationQueueHandle presentationQueue); - - gnReturnCode (*_gnCreateShaderModule)(gnShaderModuleHandle module, gnOutputDeviceHandle device, gnShaderModuleInfo shaderModuleInfo); - void (*_gnDestroyShaderModule)(gnShaderModuleHandle module); - - gnReturnCode (*_gnCreateRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info); - void (*_gnDestroyRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass); - - gnReturnCode (*_gnCreateGraphicsPipeline)(gnGraphicsPipelineHandle pipeline, gnOutputDeviceHandle device, gnGraphicsPipelineInfo pipelineInfo); - void (*_gnDestroyGraphicsPipeline)(gnGraphicsPipelineHandle pipeline); - - gnReturnCode (*_gnCreateFramebuffer)(gnFramebuffer framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo); - void (*_gnDestroyFramebuffer)(gnFramebuffer framebuffer); - - gnReturnCode (*_gnCreateCommandPool)(gnCommandPoolHandle commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info); - void (*_gnDestroyCommandPool)(gnCommandPoolHandle commandPool); - - gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); - void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore); - - gnReturnCode (*_gnCreateBuffer)(gnBufferHandle buffer, gnDeviceHandle device, gnBufferInfo info); - void (*_gnBufferData)(gnBufferHandle buffer, size_t size, void* data); - void* (*_gnMapBuffer)(gnBufferHandle buffer); - void (*_gnDestroyBuffer)(gnBufferHandle buffer); - - gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device); - gnUniform* (*_gnUniformPoolAllocateUniforms)(gnUniformPool pool, gnUniformAllocationInfo allocInfo); - void (*_gnDestroyUniformPool)(gnUniformPool pool); - - void (*_gnUpdateBufferUniform)(gnUniform uniform, gnBufferUniformInfo* bufferInfo); - void (*_gnUpdateImageUniform)(gnUniform uniform, gnImageUniformInfo* imageInfo); - - gnReturnCode (*_gnCreateTexture)(gnTexture texture, gnDevice device, const gnTextureInfo info); - void (*_gnTextureData)(gnTextureHandle texture, void* pixelData); - void (*_gnDestroyTexture)(gnTexture texture); - - gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device); - void (*_gnSignalFence)(gnFenceHandle fence); - void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout); - void (*_gnResetFence)(gnFenceHandle fence); - void (*_gnDestroyFence)(gnFenceHandle fence); - - gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, gnSubmitInfo submit); - gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, gnPresentInfo info); - - void (*_gnWaitForDevice)(gnOutputDeviceHandle device); -} gnDeviceFunctions; typedef struct gnCommandFunctions_t { gnReturnCode (*_gnCommandPoolAllocateCommandBuffers)(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool); diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index 39716c7..b779f10 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -6,7 +6,13 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceInfo info) { *instance = malloc(sizeof(struct gnInstance_t)); - (*instance)->instanceFunctions = loadInstanceFunctions(info.renderingAPI); + + loaderInfo loadInfo = { + .api = info.renderingAPI + }; + + (*instance)->instanceFunctions = loadInstanceFunctions(loadInfo); + (*instance)->deviceFunctions = loadDeviceFunctions(loadInfo); (*instance)->debugger = info.debugger; return (*instance)->instanceFunctions._gnCreateInstance((*instance), info); } diff --git a/projects/core/src/instance/gryphn_instance.h b/projects/core/src/instance/gryphn_instance.h index 3513363..0ad6ee7 100644 --- a/projects/core/src/instance/gryphn_instance.h +++ b/projects/core/src/instance/gryphn_instance.h @@ -4,6 +4,7 @@ #include "utils/gryphn_version.h" #include "utils/gryphn_error_code.h" #include "loader/src/gryphn_instance_functions.h" +#include "loader/src/gryphn_device_functions.h" typedef struct gnInstanceInfo { gnString applicationName; @@ -19,12 +20,10 @@ typedef struct gnInstanceInfo { #ifdef GN_REVEAL_IMPL struct gnInstance_t { struct gnPlatformInstance_t* instance; - gnBool valid, - loadDeviceFunctions, - loadCommandFunctions; + gnBool valid; gnInstanceFunctions instanceFunctions; - struct gnDeviceFunctions_t* deviceFunctions; + gnDeviceFunctions deviceFunctions; struct gnCommandFunctions_t* commandFunctions; gnDebuggerHandle debugger; diff --git a/projects/core/src/output_device/gryphn_output_device.c b/projects/core/src/output_device/gryphn_output_device.c index c1228c6..e8b415d 100644 --- a/projects/core/src/output_device/gryphn_output_device.c +++ b/projects/core/src/output_device/gryphn_output_device.c @@ -1,10 +1,9 @@ #include "gryphn_output_device.h" #include "instance/gryphn_instance.h" -#include "gryphn_platform_functions.h" gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) { *outputDevice = malloc(sizeof(struct gnOutputDevice_t)); - (*outputDevice)->deviceFunctions = instance->deviceFunctions; + (*outputDevice)->deviceFunctions = &instance->deviceFunctions; (*outputDevice)->instance = instance; (*outputDevice)->physicalDevice = deviceInfo.physicalDevice; diff --git a/projects/core/src/output_device/gryphn_output_device.h b/projects/core/src/output_device/gryphn_output_device.h index c1c6065..e4010c8 100644 --- a/projects/core/src/output_device/gryphn_output_device.h +++ b/projects/core/src/output_device/gryphn_output_device.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include "loader/src/gryphn_device_functions.h" typedef struct gnDeviceQueueInfo { int queueIndex; @@ -18,7 +19,7 @@ typedef struct gnOutputDeviceInfo { #ifdef GN_REVEAL_IMPL struct gnOutputDevice_t { struct gnPlatformOutputDevice_t* outputDevice; - struct gnDeviceFunctions_t* deviceFunctions; + gnDeviceFunctions* deviceFunctions; gnOutputDeviceInfo deviceInfo; gnInstanceHandle instance; gnPhysicalDevice physicalDevice; diff --git a/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h b/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h index 978cc72..e7b6e5e 100644 --- a/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h +++ b/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h @@ -7,7 +7,7 @@ #include "gryphn_handles.h" #include "shader_input/gryphn_shader_layout.h" -typedef enum gnDynamicState_e { +typedef enum gnDynamicState { GN_DYNAMIC_VIEWPORT, GN_DYNAMIC_SCISSOR, @@ -16,45 +16,45 @@ typedef enum gnDynamicState_e { typedef struct gnDynamicStateInfo { uint32_t dynamicStateCount; - enum gnDynamicState_e* dynamicStates; + gnDynamicState* dynamicStates; } gnDynamicStateInfo; typedef enum gnPrimitiveType { GN_PRIMITIVE_POINTS, GN_PRIMITIVE_LINES, GN_PRIMITIVE_LINE_STRIP, GN_PRIMITIVE_TRIANGLES, GN_PRIMITIVE_TRIANGLE_STRIP } gnPrimitiveType; -typedef enum gnBlendFactor_e { +typedef enum gnBlendFactor { GN_BLEND_FACTOR_ZERO, GN_BLEND_FACTOR_ONE, GN_BLEND_FACTOR_SRC_ALPHA, GN_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA } gnBlendFactor; -typedef enum gnBlendOperation_e { +typedef enum gnBlendOperation { GN_OPERATION_ADD } gnBlendOperation; -typedef struct gnViewport_t { +typedef struct gnViewport { gnVec2 position; gnVec2 size; float minDepth; float maxDepth; } gnViewport; -typedef struct gnScissor_t { +typedef struct gnScissor { gnInt2 position; gnUInt2 size; } gnScissor; -typedef enum gnFillMode_e { +typedef enum gnFillMode { GN_FILL_MODE_FILL, GN_FILL_MODE_LINE, GN_FILL_MODE_POINT } gnFillMode; -typedef enum gnCullFace_e { +typedef enum gnCullFace { GN_CULL_FACE_NONE, GN_CULL_FACE_BACK, GN_CULL_FACE_FRONT } gnCullFace; -typedef enum gnCullDirection_e { +typedef enum gnCullDirection { GN_DIRECTION_CLOCK_WISE, GN_DIRECTION_COUNTER_CLOCK_WISE } gnCullDirection; @@ -72,11 +72,11 @@ typedef enum gnStencilOperation { } gnStencilOperation; typedef struct gnCullMode_t { - enum gnCullFace_e face; - enum gnCullDirection_e direction; + gnCullFace face; + gnCullDirection direction; } gnCullMode; -typedef struct gnColorBlending_t { +typedef struct gnColorBlending { gnBool enable; gnBlendFactor sourceColorBlendFactor; gnBlendFactor sourceAlphaBlendFactor; @@ -100,7 +100,7 @@ typedef struct gnDepthStencilState { gnStencilState front, back; } gnDepthStencilState; -typedef struct gnGraphicsPipelineInfo_t { +typedef struct gnGraphicsPipelineInfo { gnDynamicStateInfo dynamicState; gnPrimitiveType primitiveType; gnViewport viewport; diff --git a/projects/core/src/present/gryphn_present.c b/projects/core/src/present/gryphn_present.c index ef897c8..6938b11 100644 --- a/projects/core/src/present/gryphn_present.c +++ b/projects/core/src/present/gryphn_present.c @@ -1,6 +1,6 @@ -#include "gryphn_platform_functions.h" #include "gryphn_present.h" +#include "output_device/gryphn_output_device.h" -gnReturnCode gnPresent(gnOutputDeviceHandle device, gnPresentInfo info) { +gnReturnCode gnPresent(gnDevice device, gnPresentInfo info) { return device->deviceFunctions->_gnPresent(device, info); } diff --git a/projects/core/src/present/gryphn_present.h b/projects/core/src/present/gryphn_present.h index 1b88326..a3e4a35 100644 --- a/projects/core/src/present/gryphn_present.h +++ b/projects/core/src/present/gryphn_present.h @@ -3,7 +3,7 @@ #include "stdint.h" #include "gryphn_handles.h" -typedef struct gnPresentInfo_t { +typedef struct gnPresentInfo { uint32_t waitCount; gnSemaphoreHandle* waitSemaphores; uint32_t presentationQueueCount; diff --git a/projects/core/src/presentation_queue/gryphn_presentation_queue.c b/projects/core/src/presentation_queue/gryphn_presentation_queue.c index 67827b1..acf759a 100644 --- a/projects/core/src/presentation_queue/gryphn_presentation_queue.c +++ b/projects/core/src/presentation_queue/gryphn_presentation_queue.c @@ -1,5 +1,4 @@ #include "gryphn_presentation_queue.h" -#include "gryphn_platform_functions.h" gnReturnCode gnCreatePresentationQueue(gnPresentationQueueHandle* presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo){ *presentationQueue = malloc(sizeof(struct gnPresentationQueue_t)); diff --git a/projects/core/src/presentation_queue/gryphn_presentation_queue.h b/projects/core/src/presentation_queue/gryphn_presentation_queue.h index dbf474d..a2b2850 100644 --- a/projects/core/src/presentation_queue/gryphn_presentation_queue.h +++ b/projects/core/src/presentation_queue/gryphn_presentation_queue.h @@ -6,7 +6,7 @@ #include #include "gryphn_handles.h" -typedef struct gnPresentationQueueInfo_t { +typedef struct gnPresentationQueueInfo { uint32_t minImageCount; gnUInt2 imageSize; gnWindowSurfaceHandle surface; @@ -25,7 +25,7 @@ struct gnPresentationQueue_t { gnBool valid; uint32_t imageCount; gnTextureHandle* images; - struct gnPresentationQueueInfo_t info; + gnPresentationQueueInfo info; }; #endif diff --git a/projects/core/src/shader_module/gryphn_shader_module.c b/projects/core/src/shader_module/gryphn_shader_module.c index dd1dea3..2153454 100644 --- a/projects/core/src/shader_module/gryphn_shader_module.c +++ b/projects/core/src/shader_module/gryphn_shader_module.c @@ -1,7 +1,7 @@ #include #include "gryphn_shader_module.h" -gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo) { +gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo shaderModuleInfo) { *module = malloc(sizeof(struct gnShaderModule_t)); (*module)->device = device; (*module)->info = shaderModuleInfo; diff --git a/projects/core/src/shader_module/gryphn_shader_module.h b/projects/core/src/shader_module/gryphn_shader_module.h index 4734ce2..9ebe7f2 100644 --- a/projects/core/src/shader_module/gryphn_shader_module.h +++ b/projects/core/src/shader_module/gryphn_shader_module.h @@ -4,13 +4,13 @@ #include "utils/gryphn_error_code.h" #include "gryphn_handles.h" -typedef enum gnShaderModuleStage_e { +typedef enum gnShaderModuleStage { GN_VERTEX_SHADER_MODULE = 0x00000001, GN_FRAGMENT_SHADER_MODULE = 0x00000002, GN_ALL_SHADER_MODULE = 0xffffffff } gnShaderModuleStage; -typedef struct gnShaderModuleInfo_t { +typedef struct gnShaderModuleInfo { gnShaderModuleStage stage; uint32_t* code; uint32_t size; @@ -25,5 +25,5 @@ struct gnShaderModule_t { }; #endif -gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo); +gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo shaderModuleInfo); void gnDestroyShaderModule(gnShaderModuleHandle module); diff --git a/projects/core/src/submit/gryphn_submit.c b/projects/core/src/submit/gryphn_submit.c index 7e45b17..210c087 100644 --- a/projects/core/src/submit/gryphn_submit.c +++ b/projects/core/src/submit/gryphn_submit.c @@ -1,5 +1,5 @@ #include "gryphn_submit.h" -#include "gryphn_platform_functions.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnSubmit(gnOutputDevice device, gnSubmitInfo info) { return device->deviceFunctions->_gnSubmit(device, info); diff --git a/projects/core/src/submit/gryphn_submit.h b/projects/core/src/submit/gryphn_submit.h index cd0b47f..9d12b05 100644 --- a/projects/core/src/submit/gryphn_submit.h +++ b/projects/core/src/submit/gryphn_submit.h @@ -3,7 +3,7 @@ #include "renderpass/gryphn_render_pass_descriptor.h" #include "gryphn_handles.h" -typedef struct gnSubmitInfo_t { +typedef struct gnSubmitInfo { uint32_t waitCount; gnRenderPassStage* waitStages; gnSemaphoreHandle* waitSemaphores; diff --git a/projects/loader/src/gryphn_device_functions.h b/projects/loader/src/gryphn_device_functions.h new file mode 100644 index 0000000..9da9be4 --- /dev/null +++ b/projects/loader/src/gryphn_device_functions.h @@ -0,0 +1,70 @@ +#pragma once +#include "stdint.h" +#include "stdlib.h" +#include "utils/gryphn_error_code.h" +#include "gryphn_handles.h" + +typedef struct gnPresentationQueueInfo gnPresentationQueueInfo; +typedef struct gnShaderModuleInfo gnShaderModuleInfo; +typedef struct gnRenderPassDescriptorInfo gnRenderPassDescriptorInfo; +typedef struct gnGraphicsPipelineInfo gnGraphicsPipelineInfo; +typedef struct gnFramebufferInfo gnFramebufferInfo; +typedef struct gnCommandPoolInfo gnCommandPoolInfo; +typedef struct gnBufferInfo gnBufferInfo; +typedef struct gnUniformAllocationInfo gnUniformAllocationInfo; +typedef struct gnBufferUniformInfo gnBufferUniformInfo; +typedef struct gnImageUniformInfo gnImageUniformInfo; +typedef struct gnTextureInfo gnTextureInfo; +typedef struct gnSubmitInfo gnSubmitInfo; +typedef struct gnPresentInfo gnPresentInfo; + +typedef struct gnDeviceFunctions { + gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo); + gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex); + void (*_gnDestroyPresentationQueue)(gnPresentationQueueHandle presentationQueue); + + gnReturnCode (*_gnCreateShaderModule)(gnShaderModuleHandle module, gnOutputDeviceHandle device, gnShaderModuleInfo shaderModuleInfo); + void (*_gnDestroyShaderModule)(gnShaderModuleHandle module); + + gnReturnCode (*_gnCreateRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info); + void (*_gnDestroyRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass); + + gnReturnCode (*_gnCreateGraphicsPipeline)(gnGraphicsPipelineHandle pipeline, gnOutputDeviceHandle device, gnGraphicsPipelineInfo pipelineInfo); + void (*_gnDestroyGraphicsPipeline)(gnGraphicsPipelineHandle pipeline); + + gnReturnCode (*_gnCreateFramebuffer)(gnFramebuffer framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo); + void (*_gnDestroyFramebuffer)(gnFramebuffer framebuffer); + + gnReturnCode (*_gnCreateCommandPool)(gnCommandPoolHandle commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info); + void (*_gnDestroyCommandPool)(gnCommandPoolHandle commandPool); + + gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); + void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore); + + gnReturnCode (*_gnCreateBuffer)(gnBufferHandle buffer, gnDeviceHandle device, gnBufferInfo info); + void (*_gnBufferData)(gnBufferHandle buffer, size_t size, void* data); + void* (*_gnMapBuffer)(gnBufferHandle buffer); + void (*_gnDestroyBuffer)(gnBufferHandle buffer); + + gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device); + gnUniform* (*_gnUniformPoolAllocateUniforms)(gnUniformPool pool, gnUniformAllocationInfo allocInfo); + void (*_gnDestroyUniformPool)(gnUniformPool pool); + + void (*_gnUpdateBufferUniform)(gnUniform uniform, gnBufferUniformInfo* bufferInfo); + void (*_gnUpdateImageUniform)(gnUniform uniform, gnImageUniformInfo* imageInfo); + + gnReturnCode (*_gnCreateTexture)(gnTexture texture, gnDevice device, const gnTextureInfo info); + void (*_gnTextureData)(gnTextureHandle texture, void* pixelData); + void (*_gnDestroyTexture)(gnTexture texture); + + gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device); + void (*_gnSignalFence)(gnFenceHandle fence); + void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout); + void (*_gnResetFence)(gnFenceHandle fence); + void (*_gnDestroyFence)(gnFenceHandle fence); + + gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, gnSubmitInfo submit); + gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, gnPresentInfo info); + + void (*_gnWaitForDevice)(gnOutputDeviceHandle device); +} gnDeviceFunctions; diff --git a/projects/loader/src/gryphn_loader.c b/projects/loader/src/gryphn_loader.c index a00c1d3..7979874 100644 --- a/projects/loader/src/gryphn_loader.c +++ b/projects/loader/src/gryphn_loader.c @@ -1,9 +1,28 @@ #include "gryphn_loader.h" #include -gnInstanceFunctions loadInstanceFunctions(gnRenderingAPI api) { - switch (api) { +gnInstanceFunctions loadInstanceFunctions(loaderInfo info) { + switch (info.api) { case GN_RENDERINGAPI_NONE: return (gnInstanceFunctions){ NULL }; - case GN_RENDERINGAPI_VULKAN: return loadVulkanFunctions(api); + case GN_RENDERINGAPI_VULKAN: return loadVulkanInstanceFunctions(); + + case GN_RENDERINGAPI_SOFTWARE: return (gnInstanceFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX11: return (gnInstanceFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX12: return (gnInstanceFunctions){ NULL }; + case GN_RENDERINGAPI_OPENGL: return (gnInstanceFunctions){ NULL }; + case GN_RENDERINGAPI_METAL: return (gnInstanceFunctions){ NULL }; + } +} + +gnDeviceFunctions loadDeviceFunctions(loaderInfo info) { + switch (info.api) { + case GN_RENDERINGAPI_NONE: return (gnDeviceFunctions){ NULL }; + case GN_RENDERINGAPI_VULKAN: return loadVulkanDeviceFunctions(); + + case GN_RENDERINGAPI_SOFTWARE: return (gnDeviceFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX11: return (gnDeviceFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX12: return (gnDeviceFunctions){ NULL }; + case GN_RENDERINGAPI_OPENGL: return (gnDeviceFunctions){ NULL }; + case GN_RENDERINGAPI_METAL: return (gnDeviceFunctions){ NULL }; } } diff --git a/projects/loader/src/gryphn_loader.h b/projects/loader/src/gryphn_loader.h index c874e48..1eeaf9f 100644 --- a/projects/loader/src/gryphn_loader.h +++ b/projects/loader/src/gryphn_loader.h @@ -1,5 +1,11 @@ #pragma once #include "gryphn_rendering_api.h" #include "gryphn_instance_functions.h" +#include "gryphn_device_functions.h" -gnInstanceFunctions loadInstanceFunctions(gnRenderingAPI api); +typedef struct loaderInfo { + gnRenderingAPI api; +} loaderInfo; + +gnInstanceFunctions loadInstanceFunctions(loaderInfo info); +gnDeviceFunctions loadDeviceFunctions(loaderInfo info);