diff --git a/projects/apis/vulkan/loader/vulkan_command_loader.c b/projects/apis/vulkan/loader/vulkan_command_loader.c new file mode 100644 index 0000000..57d8ca3 --- /dev/null +++ b/projects/apis/vulkan/loader/vulkan_command_loader.c @@ -0,0 +1,24 @@ +#include "vulkan_loader.h" +#include +#include + +gnCommandFunctions loadVulkanCommandFunctions() { + return (gnCommandFunctions){ + ._gnCommandPoolAllocateCommandBuffers = allocateCommandBuffers, + ._gnBeginCommandBuffer = beginCommandBuffer, + ._gnResetCommandBuffer = resetCommandBuffer, + ._gnEndCommandBuffer = endCommandBuffer, + + ._gnCommandBeginRenderPass = beginRenderPass, + ._gnCommandEndRenderPass = endRenderPass, + ._gnCommandBindGraphicsPipeline = bindGraphicsPipeline, + ._gnCommandSetViewport = setViewport, + ._gnCommandSetScissor = setScissor, + ._gnCommandBindUniform = bindUniform, + ._gnCommandPushConstant = pushConstant, + + ._gnCommandBindBuffer = bindBuffer, + ._gnCommandDraw = draw, + ._gnCommandDrawIndexed = drawIndexed, + }; +} diff --git a/projects/apis/vulkan/loader/vulkan_device_loader.c b/projects/apis/vulkan/loader/vulkan_device_loader.c index e0bfeb5..c214dea 100644 --- a/projects/apis/vulkan/loader/vulkan_device_loader.c +++ b/projects/apis/vulkan/loader/vulkan_device_loader.c @@ -6,7 +6,13 @@ #include #include #include +#include #include +#include +#include +#include +#include +#include #include gnDeviceFunctions loadVulkanDeviceFunctions() { @@ -30,33 +36,32 @@ gnDeviceFunctions loadVulkanDeviceFunctions() { ._gnCreateCommandPool = createCommandPool, ._gnDestroyCommandPool = destroyCommandPool, - // gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); - // void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore); + ._gnCreateSemaphore = createSemaphore, + ._gnDestroySemaphore = destroySemaphore, - // 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); + ._gnCreateBuffer = createBuffer, + ._gnBufferData = bufferData, + ._gnMapBuffer = mapBuffer, + ._gnDestroyBuffer = destroyBuffer, ._gnCreateUniformPool = createUniformPool, ._gnUniformPoolAllocateUniforms = allocateUniforms, ._gnDestroyUniformPool = destroyUniformPool, - // void (*_gnUpdateBufferUniform)(gnUniform uniform, gnBufferUniformInfo* bufferInfo); - // void (*_gnUpdateImageUniform)(gnUniform uniform, gnImageUniformInfo* imageInfo); + ._gnUpdateBufferUniform = updateBufferUniform, + ._gnUpdateImageUniform = updateImageUniform, ._gnCreateTexture = createTexture, ._gnTextureData = textureData, ._gnDestroyTexture = destroyTexture, - // 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); + ._gnCreateFence = createFence, + ._gnWaitForFence = waitForFence, + ._gnResetFence = resetFence, + ._gnDestroyFence = destroyFence, - // gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, gnSubmitInfo submit); - // gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, gnPresentInfo info); + ._gnSubmit = submit, + ._gnPresent = present, ._gnWaitForDevice = waitForDevice }; diff --git a/projects/apis/vulkan/loader/vulkan_loader.h b/projects/apis/vulkan/loader/vulkan_loader.h index c553e7e..b6f706d 100644 --- a/projects/apis/vulkan/loader/vulkan_loader.h +++ b/projects/apis/vulkan/loader/vulkan_loader.h @@ -1,6 +1,8 @@ #pragma once #include "loader/src/gryphn_instance_functions.h" #include "loader/src/gryphn_device_functions.h" +#include "loader/src/gryphn_command_functions.h" gnInstanceFunctions loadVulkanInstanceFunctions(); gnDeviceFunctions loadVulkanDeviceFunctions(); +gnCommandFunctions loadVulkanCommandFunctions(); diff --git a/projects/apis/vulkan/src/buffers/vulkan_buffer.c b/projects/apis/vulkan/src/buffers/vulkan_buffer.c index 7286d89..464539a 100644 --- a/projects/apis/vulkan/src/buffers/vulkan_buffer.c +++ b/projects/apis/vulkan/src/buffers/vulkan_buffer.c @@ -66,7 +66,7 @@ void VkCopyBuffer(VkBuffer source, VkBuffer destination, size_t size, VkCommandP VkEndTransferOperation(transferBuffer, pool, queue, device); } -gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) { +gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) { buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t)); VkBufferUsageFlags usage = vkGryphnBufferType(info.type); buffer->buffer->useStagingBuffer = gnFalse; @@ -98,7 +98,7 @@ gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device return GN_SUCCESS; } -void gnBufferDataFn(gnBufferHandle buffer, size_t dataSize, void* data) { +void bufferData(gnBufferHandle buffer, size_t dataSize, void* data) { void* bufferData; if (buffer->buffer->useStagingBuffer) { vkMapMemory(buffer->device->outputDevice->device, buffer->buffer->stagingBuffer.memory, 0, dataSize, 0, &bufferData); @@ -114,7 +114,7 @@ void gnBufferDataFn(gnBufferHandle buffer, size_t dataSize, void* data) { vkUnmapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory); } } -void* gnMapBufferFn(gnBufferHandle buffer) { +void* mapBuffer(gnBufferHandle buffer) { void* data; vkMapMemory(buffer->device->outputDevice->device, buffer->buffer->buffer.memory, 0, buffer->info.size, 0, &data); return data; @@ -125,7 +125,7 @@ void gnDestroyVulkanBuffer(VkGryphnBuffer* buffer, VkDevice device) { vkFreeMemory(device, buffer->memory, NULL); } -void gnDestroyBufferFn(gnBufferHandle buffer) { +void destroyBuffer(gnBufferHandle buffer) { if (buffer->buffer->useStagingBuffer == gnTrue) gnDestroyVulkanBuffer(&buffer->buffer->stagingBuffer, buffer->device->outputDevice->device); gnDestroyVulkanBuffer(&buffer->buffer->buffer, buffer->device->outputDevice->device); free(buffer->buffer); diff --git a/projects/apis/vulkan/src/buffers/vulkan_buffer.h b/projects/apis/vulkan/src/buffers/vulkan_buffer.h index f952d7a..8d5030b 100644 --- a/projects/apis/vulkan/src/buffers/vulkan_buffer.h +++ b/projects/apis/vulkan/src/buffers/vulkan_buffer.h @@ -22,3 +22,8 @@ gnReturnCode VkCreateBuffer( VkMemoryPropertyFlags flags, VkBufferUsageFlags usage ); uint32_t VkMemoryIndex(VkPhysicalDevice device, uint32_t memoryType, VkMemoryPropertyFlags flags, gnBool* foundMemory); + +gnReturnCode createBuffer(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info); +void bufferData(gnBufferHandle buffer, size_t dataSize, void* data); +void* mapBuffer(gnBufferHandle buffer); +void destroyBuffer(gnBufferHandle buffer); diff --git a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c index d6d59c8..5d98ef2 100644 --- a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c +++ b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.c @@ -2,7 +2,7 @@ #include "commands/command_pool/vulkan_command_pool.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { +gnReturnCode allocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPool pool) { VkCommandBufferAllocateInfo allocInfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, .commandPool = pool->commandPool->commandPool, @@ -23,12 +23,12 @@ gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* comman return GN_SUCCESS; } -void gnResetCommandBufferFn(struct gnCommandBuffer_t* commandBuffer) { +void resetCommandBuffer(gnCommandBufferHandle commandBuffer) { vkResetCommandBuffer(commandBuffer->commandBuffer->buffer, 0); } -gnReturnCode gnBeginCommandBufferFn(struct gnCommandBuffer_t* commandBuffer) { +gnReturnCode beginCommandBuffer(gnCommandBufferHandle commandBuffer) { VkCommandBufferBeginInfo beginInfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; @@ -39,7 +39,7 @@ gnReturnCode gnBeginCommandBufferFn(struct gnCommandBuffer_t* commandBuffer) { return GN_SUCCESS; } -gnReturnCode gnEndCommandBufferFn(struct gnCommandBuffer_t* commandBuffer) { +gnReturnCode endCommandBuffer(gnCommandBufferHandle commandBuffer) { if (vkEndCommandBuffer(commandBuffer->commandBuffer->buffer) != VK_SUCCESS) return GN_FAIELD_TO_END_RECORDING; return GN_SUCCESS; diff --git a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.h b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.h index b62ee9c..9030411 100644 --- a/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.h +++ b/projects/apis/vulkan/src/commands/command_buffer/vulkan_command_buffer.h @@ -13,3 +13,9 @@ typedef struct gnPlatformCommandBuffer_t { VkCommandBuffer VkBeginTransferOperation(VkDevice device, VkCommandPool pool); void VkEndTransferOperation(VkCommandBuffer transferBuffer, VkCommandPool pool, VkQueue syncQueue, VkDevice device); + + +gnReturnCode allocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPool pool); +gnReturnCode beginCommandBuffer(gnCommandBufferHandle commandBuffer); +void resetCommandBuffer(gnCommandBufferHandle commandBuffer); +gnReturnCode endCommandBuffer(gnCommandBufferHandle commandBuffer); diff --git a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c index fed4589..7a1feea 100644 --- a/projects/apis/vulkan/src/commands/commands/vulkan_commands.c +++ b/projects/apis/vulkan/src/commands/commands/vulkan_commands.c @@ -1,14 +1,6 @@ -#include -#include "command/commands/gryphn_command.h" -#include -#include "framebuffers/vulkan_framebuffer.h" -#include "commands/command_buffer/vulkan_command_buffer.h" -#include "pipelines/graphics_pipeline/vulkan_graphics_pipeline.h" -#include "buffers/vulkan_buffer.h" -#include "uniforms/vulkan_uniform.h" -#include "shader_module/vulkan_shader_module.h" +#include "vulkan_commands.h" -void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, gnRenderPassInfo passInfo) { +void beginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) { VkClearValue* values = malloc(sizeof(VkClearValue) * passInfo.clearValueCount); for (int i = 0; i < passInfo.clearValueCount; i++) { values[i] = (VkClearValue){{{ @@ -33,14 +25,14 @@ void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, gnRenderPassInfo passInf vkCmdBeginRenderPass(buffer->commandBuffer->buffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); } -void gnCommandEndRenderPassFn(gnCommandBuffer buffer) { +void endRenderPass(gnCommandBuffer buffer) { vkCmdEndRenderPass(buffer->commandBuffer->buffer); } -void gnCommandBindGraphicsPipelineFn(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline) { +void bindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline) { buffer->commandBuffer->boundGraphicsPipeline = graphicsPipeline; vkCmdBindPipeline(buffer->commandBuffer->buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline->graphicsPipeline->graphicsPipeline); } -void gnCommandSetViewportFn(gnCommandBuffer buffer, gnViewport viewport) { +void setViewport(gnCommandBuffer buffer, gnViewport viewport) { VkViewport vkViewport = { .x = viewport.position.x, .y = viewport.size.y, @@ -51,7 +43,7 @@ void gnCommandSetViewportFn(gnCommandBuffer buffer, gnViewport viewport) { }; vkCmdSetViewport(buffer->commandBuffer->buffer, 0, 1, &vkViewport); } -void gnCommandSetScissorFn(gnCommandBuffer buffer, gnScissor scissor) { +void setScissor(gnCommandBuffer buffer, gnScissor scissor) { VkRect2D vkScissor = { .extent = { scissor.size.x, scissor.size.y }, .offset = { scissor.position.x, scissor.position.y } @@ -59,7 +51,7 @@ void gnCommandSetScissorFn(gnCommandBuffer buffer, gnScissor scissor) { vkCmdSetScissor(buffer->commandBuffer->buffer, 0, 1, &vkScissor); } VkDeviceSize offsets[] = {0}; -void gnCommandBindBufferFn(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type) { +void bindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type) { if (type == GN_VERTEX_BUFFER) vkCmdBindVertexBuffers(buffer->commandBuffer->buffer, 0, 1, &bufferToBind->buffer->buffer.buffer, offsets); else if (type == GN_INDEX_BUFFER) { @@ -67,16 +59,16 @@ void gnCommandBindBufferFn(gnCommandBufferHandle buffer, gnBufferHandle bufferTo buffer->commandBuffer->boundIndexBuffer = bufferToBind; } } -void gnCommandDrawFn(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance) { +void draw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance) { vkCmdDraw(buffer->commandBuffer->buffer, vertexCount, instanceCount, firstVertex, firstInstance); } -void gnCommandDrawIndexedFn(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance) { +void drawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance) { if (buffer->commandBuffer->changedBuffer) vkCmdBindIndexBuffer(buffer->commandBuffer->buffer, buffer->commandBuffer->boundIndexBuffer->buffer->buffer.buffer, 0, (type == GN_UINT32) ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16); vkCmdDrawIndexed(buffer->commandBuffer->buffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); buffer->commandBuffer->changedBuffer = gnFalse; } -void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) { +void bindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) { vkCmdBindDescriptorSets( buffer->commandBuffer->buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, @@ -85,7 +77,7 @@ void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uin ); } -void gnCommandPushConstantFn(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) { +void pushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) { vkCmdPushConstants( buffer->commandBuffer->buffer, buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->pipelineLayout, diff --git a/projects/apis/vulkan/src/commands/commands/vulkan_commands.h b/projects/apis/vulkan/src/commands/commands/vulkan_commands.h new file mode 100644 index 0000000..60878e5 --- /dev/null +++ b/projects/apis/vulkan/src/commands/commands/vulkan_commands.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "command/commands/gryphn_command.h" +#include +#include +#include +#include +#include +#include +#include + +void beginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo); +void endRenderPass(gnCommandBuffer buffer); +void bindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline); +void setViewport(gnCommandBuffer buffer, gnViewport viewport); +void setScissor(gnCommandBuffer buffer, gnScissor scissor); +void bindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type); +void draw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance); +void drawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance); +void bindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set); +void pushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data); diff --git a/projects/apis/vulkan/src/present/vulkan_present.c b/projects/apis/vulkan/src/present/vulkan_present.c index 9dd2eb5..aafbfbc 100644 --- a/projects/apis/vulkan/src/present/vulkan_present.c +++ b/projects/apis/vulkan/src/present/vulkan_present.c @@ -1,9 +1,6 @@ -#include "present/gryphn_present.h" -#include "sync/semaphore/vulkan_semaphore.h" -#include "presentation_queue/vulkan_presentation_queue.h" -#include "output_device/vulkan_output_devices.h" +#include "vulkan_present.h" -gnReturnCode gnPresentFn(gnDevice device, gnPresentInfo info) { +gnReturnCode present(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/present/vulkan_present.h b/projects/apis/vulkan/src/present/vulkan_present.h new file mode 100644 index 0000000..f108d19 --- /dev/null +++ b/projects/apis/vulkan/src/present/vulkan_present.h @@ -0,0 +1,6 @@ +#include "present/gryphn_present.h" +#include +#include +#include + +gnReturnCode present(gnDevice device, gnPresentInfo info); diff --git a/projects/apis/vulkan/src/submit/vulkan_submit.c b/projects/apis/vulkan/src/submit/vulkan_submit.c index 0c5c8ef..7afe432 100644 --- a/projects/apis/vulkan/src/submit/vulkan_submit.c +++ b/projects/apis/vulkan/src/submit/vulkan_submit.c @@ -1,13 +1,7 @@ -#include -#include "submit/gryphn_submit.h" -#include "sync/semaphore/vulkan_semaphore.h" -#include "sync/fence/vulkan_fence.h" -#include "commands/command_buffer/vulkan_command_buffer.h" -#include "output_device/vulkan_output_devices.h" -#include "renderpass/vulkan_render_pass_descriptor.h" +#include "vulkan_submit.h" -gnReturnCode gnSubmitFn(gnDevice device, gnSubmitInfo info) { +gnReturnCode submit(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/apis/vulkan/src/submit/vulkan_submit.h b/projects/apis/vulkan/src/submit/vulkan_submit.h new file mode 100644 index 0000000..95129ae --- /dev/null +++ b/projects/apis/vulkan/src/submit/vulkan_submit.h @@ -0,0 +1,9 @@ +#include +#include +#include +#include +#include +#include +#include + +gnReturnCode submit(gnDevice device, gnSubmitInfo info); diff --git a/projects/apis/vulkan/src/sync/fence/vulkan_fence.c b/projects/apis/vulkan/src/sync/fence/vulkan_fence.c index c2cd997..1978f56 100644 --- a/projects/apis/vulkan/src/sync/fence/vulkan_fence.c +++ b/projects/apis/vulkan/src/sync/fence/vulkan_fence.c @@ -1,7 +1,7 @@ #include "vulkan_fence.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* device) { +gnReturnCode createFence(gnFence fence, gnDevice device) { fence->fence = malloc(sizeof(gnPlatformFence)); VkFenceCreateInfo fenceInfo = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO @@ -10,14 +10,13 @@ gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* d return GN_FAILED_TO_CREATE_FENCE; return GN_SUCCESS; } -void gnSignalFenceFn(struct gnFence_t* fence) {} -void gnWaitForFenceFn(struct gnFence_t* fence, uint64_t timeout) { +void waitForFence(gnFence fence, uint64_t timeout) { vkWaitForFences(fence->device->outputDevice->device, 1, &fence->fence->fence, VK_TRUE, timeout); } -void gnResetFenceFn(struct gnFence_t* fence) { +void resetFence(gnFence fence) { vkResetFences(fence->device->outputDevice->device, 1, &fence->fence->fence); } -void gnDestroyFenceFn(struct gnFence_t* fence) { +void destroyFence(gnFence fence) { vkDestroyFence(fence->device->outputDevice->device, fence->fence->fence, NULL); free(fence->fence); } diff --git a/projects/apis/vulkan/src/sync/fence/vulkan_fence.h b/projects/apis/vulkan/src/sync/fence/vulkan_fence.h index 94f920c..f4ca3fb 100644 --- a/projects/apis/vulkan/src/sync/fence/vulkan_fence.h +++ b/projects/apis/vulkan/src/sync/fence/vulkan_fence.h @@ -5,3 +5,8 @@ typedef struct gnPlatformFence_t { VkFence fence; } gnPlatformFence; + +gnReturnCode createFence(gnFence fence, gnDevice device); +void waitForFence(gnFence fence, uint64_t timeout); +void resetFence(gnFence fence); +void destroyFence(gnFence fence); diff --git a/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.c b/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.c index 211b035..241d9ef 100644 --- a/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.c +++ b/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.c @@ -1,7 +1,7 @@ #include "vulkan_semaphore.h" #include "output_device/vulkan_output_devices.h" -gnReturnCode gnCreateSemaphoreFn(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device) { +gnReturnCode createSemaphore(gnSemaphore semaphore, gnDevice device) { semaphore->semaphore = malloc(sizeof(gnPlatformSemaphore)); VkSemaphoreCreateInfo semaphoreInfo = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO @@ -11,7 +11,7 @@ gnReturnCode gnCreateSemaphoreFn(struct gnSemaphore_t* semaphore, struct gnOutpu return GN_FAILED_TO_CREATE_SEMAPHORE; return GN_SUCCESS; } -void gnDestroySemaphoreFn(struct gnSemaphore_t* semaphore) { +void destroySemaphore(gnSemaphore semaphore) { vkDestroySemaphore(semaphore->device->outputDevice->device, semaphore->semaphore->semaphore, NULL); free(semaphore->semaphore); } diff --git a/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.h b/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.h index d41ae86..90370ab 100644 --- a/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.h +++ b/projects/apis/vulkan/src/sync/semaphore/vulkan_semaphore.h @@ -5,3 +5,6 @@ typedef struct gnPlatformSemaphore_t { VkSemaphore semaphore; } gnPlatformSemaphore; + +gnReturnCode createSemaphore(gnSemaphore semaphore, gnDevice device); +void destroySemaphore(gnSemaphore semaphore); diff --git a/projects/apis/vulkan/src/uniforms/vulkan_uniform.c b/projects/apis/vulkan/src/uniforms/vulkan_uniform.c index 80f29db..4be168d 100644 --- a/projects/apis/vulkan/src/uniforms/vulkan_uniform.c +++ b/projects/apis/vulkan/src/uniforms/vulkan_uniform.c @@ -4,7 +4,7 @@ #include "uniforms/gryphn_uniform_pool.h" #include "textures/vulkan_texture.h" -void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { +void updateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info) { VkDescriptorBufferInfo bufferInfo = { .buffer = info->buffer->buffer->buffer.buffer, .offset = info->offset, @@ -24,7 +24,7 @@ void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { vkUpdateDescriptorSets(uniform->pool->device->outputDevice->device, 1, &write, 0, NULL); } -void gnUpdateImageUniformFn(gnUniform uniform, gnImageUniformInfo* info) { +void updateImageUniform(gnUniform uniform, gnImageUniformInfo* info) { VkDescriptorImageInfo imageInfo = { .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, .imageView = info->texture->texture->image.imageView, diff --git a/projects/apis/vulkan/src/uniforms/vulkan_uniform.h b/projects/apis/vulkan/src/uniforms/vulkan_uniform.h index 4ceeeec..8e59a30 100644 --- a/projects/apis/vulkan/src/uniforms/vulkan_uniform.h +++ b/projects/apis/vulkan/src/uniforms/vulkan_uniform.h @@ -5,3 +5,6 @@ typedef struct gnPlatformUniform_t { VkDescriptorSet set; } gnPlatformUniform; + +void updateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info); +void updateImageUniform(gnUniform uniform, gnImageUniformInfo* info); diff --git a/projects/core/src/buffers/gryphn_buffer.c b/projects/core/src/buffers/gryphn_buffer.c index c2bbce2..2c526aa 100644 --- a/projects/core/src/buffers/gryphn_buffer.c +++ b/projects/core/src/buffers/gryphn_buffer.c @@ -1,6 +1,5 @@ #include "gryphn_buffer.h" #include "output_device/gryphn_output_device.h" -#include "gryphn_platform_functions.h" gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info) { *buffer = malloc(sizeof(struct gnBuffer_t)); 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 5854101..85722b4 100644 --- a/projects/core/src/command/command_pool/gryphn_command_pool.c +++ b/projects/core/src/command/command_pool/gryphn_command_pool.c @@ -1,8 +1,11 @@ #include "gryphn_command_pool.h" +#include "stdlib.h" +#include "output_device/gryphn_output_device.h" +#include "instance/gryphn_instance.h" gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info) { *commandPool = malloc(sizeof(struct gnCommandPool_t)); - (*commandPool)->commandFunctions = device->instance->commandFunctions; + (*commandPool)->commandFunctions = &device->instance->commandFunctions; (*commandPool)->device = device; return device->deviceFunctions->_gnCreateCommandPool((*commandPool), device, info); 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 786aec1..218fb54 100644 --- a/projects/core/src/command/command_pool/gryphn_command_pool.h +++ b/projects/core/src/command/command_pool/gryphn_command_pool.h @@ -2,7 +2,7 @@ #include "stdint.h" #include #include "gryphn_handles.h" -#include +#include "loader/src/gryphn_command_functions.h" typedef struct gnCommandPoolInfo { uint32_t queueIndex; @@ -11,8 +11,8 @@ typedef struct gnCommandPoolInfo { #ifdef GN_REVEAL_IMPL struct gnCommandPool_t { struct gnPlatformCommandPool_t* commandPool; - struct gnCommandFunctions_t* commandFunctions; - struct gnOutputDevice_t* device; + gnCommandFunctions* commandFunctions; + gnDevice device; }; #endif diff --git a/projects/core/src/command/commands/gryphn_command.c b/projects/core/src/command/commands/gryphn_command.c index f2e271a..4e8da9c 100644 --- a/projects/core/src/command/commands/gryphn_command.c +++ b/projects/core/src/command/commands/gryphn_command.c @@ -1,7 +1,6 @@ #include "gryphn_command.h" #include "command/command_buffer/gryphn_command_buffer.h" #include "command/command_pool/gryphn_command_pool.h" -#include "gryphn_platform_functions.h" void gnCommandBeginRenderPass(gnCommandBufferHandle buffer, gnRenderPassInfo passInfo) { buffer->commandPool->commandFunctions->_gnCommandBeginRenderPass(buffer, passInfo); diff --git a/projects/core/src/debugger/gryphn_debugger.c b/projects/core/src/debugger/gryphn_debugger.c index 1e18ba5..eb65535 100644 --- a/projects/core/src/debugger/gryphn_debugger.c +++ b/projects/core/src/debugger/gryphn_debugger.c @@ -1,5 +1,4 @@ #include "gryphn_debugger.h" -#include gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const gnDebuggerInfo info) { *debugger = malloc(sizeof(struct gnDebugger_t)); diff --git a/projects/core/src/framebuffer/gryphn_framebuffer.c b/projects/core/src/framebuffer/gryphn_framebuffer.c index b8ed297..4b8ef1c 100644 --- a/projects/core/src/framebuffer/gryphn_framebuffer.c +++ b/projects/core/src/framebuffer/gryphn_framebuffer.c @@ -1,5 +1,6 @@ #include "gryphn_framebuffer.h" -#include "gryphn_platform_functions.h" +#include "stdlib.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateFramebuffer(gnFramebuffer* framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo) { *framebuffer = malloc(sizeof(struct gnFramebuffer_t)); diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index b779f10..a80b764 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -1,5 +1,4 @@ #include "gryphn_instance.h" -#include #include "instance/gryphn_instance.h" #include #include "loader/src/gryphn_loader.h" @@ -13,6 +12,7 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceInfo info) { (*instance)->instanceFunctions = loadInstanceFunctions(loadInfo); (*instance)->deviceFunctions = loadDeviceFunctions(loadInfo); + (*instance)->commandFunctions = loadCommandFunctions(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 0ad6ee7..253c04a 100644 --- a/projects/core/src/instance/gryphn_instance.h +++ b/projects/core/src/instance/gryphn_instance.h @@ -5,6 +5,7 @@ #include "utils/gryphn_error_code.h" #include "loader/src/gryphn_instance_functions.h" #include "loader/src/gryphn_device_functions.h" +#include "loader/src/gryphn_command_functions.h" typedef struct gnInstanceInfo { gnString applicationName; @@ -24,7 +25,7 @@ struct gnInstance_t { gnInstanceFunctions instanceFunctions; gnDeviceFunctions deviceFunctions; - struct gnCommandFunctions_t* commandFunctions; + gnCommandFunctions commandFunctions; gnDebuggerHandle debugger; }; diff --git a/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.c b/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.c index 8f71238..9a50b5a 100644 --- a/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.c +++ b/projects/core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.c @@ -1,5 +1,4 @@ #include "gryphn_graphics_pipeline.h" -#include "gryphn_platform_functions.h" gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) { *graphicsPipeline = malloc(sizeof(struct gnGraphicsPipeline_t)); diff --git a/projects/core/src/renderpass/gryphn_render_pass.h b/projects/core/src/renderpass/gryphn_render_pass.h index ab1d044..812b5b3 100644 --- a/projects/core/src/renderpass/gryphn_render_pass.h +++ b/projects/core/src/renderpass/gryphn_render_pass.h @@ -3,7 +3,7 @@ #include "utils/math/gryphn_vec2.h" #include "gryphn_handles.h" -typedef struct gnRenderPassInfo_t { +typedef struct gnRenderPassInfo { gnRenderPassDescriptorHandle renderPassDescriptor; gnFramebuffer framebuffer; gnUInt2 offset; diff --git a/projects/core/src/renderpass/gryphn_render_pass_descriptor.c b/projects/core/src/renderpass/gryphn_render_pass_descriptor.c index a8273ea..8931ad3 100644 --- a/projects/core/src/renderpass/gryphn_render_pass_descriptor.c +++ b/projects/core/src/renderpass/gryphn_render_pass_descriptor.c @@ -1,5 +1,5 @@ #include "gryphn_render_pass_descriptor.h" -#include "gryphn_platform_functions.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateRenderPassDescriptor(gnRenderPassDescriptorHandle* renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info) { *renderPass = malloc(sizeof(struct gnRenderPassDescriptor_t)); diff --git a/projects/core/src/shader_module/gryphn_shader_module.c b/projects/core/src/shader_module/gryphn_shader_module.c index 2153454..c4b35e5 100644 --- a/projects/core/src/shader_module/gryphn_shader_module.c +++ b/projects/core/src/shader_module/gryphn_shader_module.c @@ -1,5 +1,5 @@ -#include #include "gryphn_shader_module.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo shaderModuleInfo) { *module = malloc(sizeof(struct gnShaderModule_t)); diff --git a/projects/core/src/sync/fence/gryphn_fence.c b/projects/core/src/sync/fence/gryphn_fence.c index 74143d6..bfc91b1 100644 --- a/projects/core/src/sync/fence/gryphn_fence.c +++ b/projects/core/src/sync/fence/gryphn_fence.c @@ -1,5 +1,5 @@ #include "gryphn_fence.h" -#include "gryphn_platform_functions.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateFence(gnFenceHandle* fence, struct gnOutputDevice_t* device) { *fence = malloc(sizeof(struct gnFence_t)); @@ -9,7 +9,6 @@ gnReturnCode gnCreateFence(gnFenceHandle* fence, struct gnOutputDevice_t* device } void gnSignalFence(gnFenceHandle fence) { fence->signaled = gnTrue; - // fence->device->deviceFunctions->_gnSignalFence(fence); } void gnWaitForFence(gnFenceHandle fence, uint64_t timeout) { if (fence->signaled == gnTrue) return; diff --git a/projects/core/src/sync/semaphore/gryphn_semaphore.c b/projects/core/src/sync/semaphore/gryphn_semaphore.c index fb69559..97d5352 100644 --- a/projects/core/src/sync/semaphore/gryphn_semaphore.c +++ b/projects/core/src/sync/semaphore/gryphn_semaphore.c @@ -1,5 +1,5 @@ #include "gryphn_semaphore.h" -#include "gryphn_platform_functions.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device) { *semaphore = malloc(sizeof(struct gnSemaphore_t)); diff --git a/projects/core/src/textures/gryphn_texture.c b/projects/core/src/textures/gryphn_texture.c index d74a888..1ed3d1d 100644 --- a/projects/core/src/textures/gryphn_texture.c +++ b/projects/core/src/textures/gryphn_texture.c @@ -1,5 +1,5 @@ #include "gryphn_texture.h" -#include "gryphn_platform_functions.h" +#include "output_device/gryphn_output_device.h" gnReturnCode gnCreateTexture(gnTexture* texture, gnDevice device, const gnTextureInfo info) { *texture = malloc(sizeof(struct gnTexture_t)); diff --git a/projects/core/src/uniforms/gryphn_uniform.c b/projects/core/src/uniforms/gryphn_uniform.c index a38c19a..ef64533 100644 --- a/projects/core/src/uniforms/gryphn_uniform.c +++ b/projects/core/src/uniforms/gryphn_uniform.c @@ -1,7 +1,6 @@ #include "gryphn_uniform.h" #include "gryphn_uniform_pool.h" #include "output_device/gryphn_output_device.h" -#include "gryphn_platform_functions.h" void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo) { uniform->pool->device->deviceFunctions->_gnUpdateBufferUniform(uniform, &bufferInfo); diff --git a/projects/core/src/uniforms/gryphn_uniform_pool.c b/projects/core/src/uniforms/gryphn_uniform_pool.c index b690fa9..716247c 100644 --- a/projects/core/src/uniforms/gryphn_uniform_pool.c +++ b/projects/core/src/uniforms/gryphn_uniform_pool.c @@ -1,6 +1,5 @@ #include "gryphn_uniform_pool.h" #include "output_device/gryphn_output_device.h" -#include "gryphn_platform_functions.h" #include "gryphn_uniform.h" #include "stdlib.h" diff --git a/projects/core/src/gryphn_platform_functions.h b/projects/loader/src/gryphn_command_functions.h similarity index 79% rename from projects/core/src/gryphn_platform_functions.h rename to projects/loader/src/gryphn_command_functions.h index 4a05dea..ed6d5e4 100644 --- a/projects/core/src/gryphn_platform_functions.h +++ b/projects/loader/src/gryphn_command_functions.h @@ -1,12 +1,14 @@ #pragma once -// theoretically you could have multible gryphn instances running in one application, -// why I dont know -#include "instance/gryphn_instance.h" -#include -#include -#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" -#include "renderpass/gryphn_render_pass.h" -#include "buffers/gryphn_buffer.h" +#include "stdint.h" +#include "utils/gryphn_error_code.h" +#include "gryphn_handles.h" + +typedef struct gnRenderPassInfo gnRenderPassInfo; +typedef struct gnViewport gnViewport; +typedef struct gnScissor gnScissor; +typedef struct gnPushConstantLayout gnPushConstantLayout; +typedef enum gnBufferType gnBufferType; +typedef enum gnIndexType gnIndexType; typedef struct gnCommandFunctions_t { gnReturnCode (*_gnCommandPoolAllocateCommandBuffers)(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool); diff --git a/projects/loader/src/gryphn_device_functions.h b/projects/loader/src/gryphn_device_functions.h index 9da9be4..be02188 100644 --- a/projects/loader/src/gryphn_device_functions.h +++ b/projects/loader/src/gryphn_device_functions.h @@ -58,7 +58,6 @@ typedef struct gnDeviceFunctions { 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); diff --git a/projects/loader/src/gryphn_loader.c b/projects/loader/src/gryphn_loader.c index 7979874..c9770b0 100644 --- a/projects/loader/src/gryphn_loader.c +++ b/projects/loader/src/gryphn_loader.c @@ -26,3 +26,16 @@ gnDeviceFunctions loadDeviceFunctions(loaderInfo info) { case GN_RENDERINGAPI_METAL: return (gnDeviceFunctions){ NULL }; } } + +gnCommandFunctions loadCommandFunctions(loaderInfo info) { + switch (info.api) { + case GN_RENDERINGAPI_NONE: return (gnCommandFunctions){ NULL }; + case GN_RENDERINGAPI_VULKAN: return loadVulkanCommandFunctions(); + + case GN_RENDERINGAPI_SOFTWARE: return (gnCommandFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX11: return (gnCommandFunctions){ NULL }; + case GN_RENDERINGAPI_DIRECTX12: return (gnCommandFunctions){ NULL }; + case GN_RENDERINGAPI_OPENGL: return (gnCommandFunctions){ NULL }; + case GN_RENDERINGAPI_METAL: return (gnCommandFunctions){ NULL }; + } +} diff --git a/projects/loader/src/gryphn_loader.h b/projects/loader/src/gryphn_loader.h index 1eeaf9f..a659fe0 100644 --- a/projects/loader/src/gryphn_loader.h +++ b/projects/loader/src/gryphn_loader.h @@ -2,6 +2,7 @@ #include "gryphn_rendering_api.h" #include "gryphn_instance_functions.h" #include "gryphn_device_functions.h" +#include "gryphn_command_functions.h" typedef struct loaderInfo { gnRenderingAPI api; @@ -9,3 +10,4 @@ typedef struct loaderInfo { gnInstanceFunctions loadInstanceFunctions(loaderInfo info); gnDeviceFunctions loadDeviceFunctions(loaderInfo info); +gnCommandFunctions loadCommandFunctions(loaderInfo info);