diff --git a/rendering_api/metal/src/core/commands/command_buffer/metal_command_buffer.m b/rendering_api/metal/src/core/commands/command_buffer/metal_command_buffer.m index 70afad8..9e82171 100644 --- a/rendering_api/metal/src/core/commands/command_buffer/metal_command_buffer.m +++ b/rendering_api/metal/src/core/commands/command_buffer/metal_command_buffer.m @@ -2,9 +2,9 @@ #include "core/commands/command_pool/metal_command_pool.h" #import -gnReturnCode gnCommandPoolAllocateCommandBuffersFn(struct gnCommandBuffer_t* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { +gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { for (int i = 0; i < count; i++) { - commandBuffers[i].commandBuffer = malloc(sizeof(gnPlatformCommandBuffer)); + commandBuffers[i]->commandBuffer = malloc(sizeof(gnPlatformCommandBuffer)); } return GN_SUCCESS; diff --git a/rendering_api/metal/src/core/submit/metal_submit.m b/rendering_api/metal/src/core/submit/metal_submit.m index 194ec46..f54eb46 100644 --- a/rendering_api/metal/src/core/submit/metal_submit.m +++ b/rendering_api/metal/src/core/submit/metal_submit.m @@ -15,8 +15,8 @@ gnReturnCode gnSubmitFn(struct gnOutputDevice_t* device, struct gnSubmitInfo_t i __block gnFence* fenceToSignal = info.fence; for (int i = 0; i < info.commandBufferCount; i++) { - id commandBuffer = info.commandBuffers[i].commandBuffer->commandBuffer; - [info.commandBuffers[i].commandBuffer->commandBuffer addCompletedHandler:^(id buffer) { + id commandBuffer = info.commandBuffers[i]->commandBuffer->commandBuffer; + [info.commandBuffers[i]->commandBuffer->commandBuffer addCompletedHandler:^(id buffer) { for (int c = 0; c < semsToSignalCount; c++) { semsToSignal[c].semaphore->eventTriggered = gnTrue; } diff --git a/rendering_api/vulkan/src/commands/command_buffer/vulkan_command_buffer.c b/rendering_api/vulkan/src/commands/command_buffer/vulkan_command_buffer.c index 95c76fd..ead4ea7 100644 --- a/rendering_api/vulkan/src/commands/command_buffer/vulkan_command_buffer.c +++ b/rendering_api/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(struct gnCommandBuffer_t* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { +gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { VkCommandBufferAllocateInfo allocInfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, .commandPool = pool->commandPool->commandPool, @@ -16,8 +16,8 @@ gnReturnCode gnCommandPoolAllocateCommandBuffersFn(struct gnCommandBuffer_t* com return GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS; for (int i = 0; i < count; i++) { - commandBuffers[i].commandBuffer = malloc(sizeof(gnPlatformCommandBuffer)); - commandBuffers[i].commandBuffer->buffer = buffers[i]; + commandBuffers[i]->commandBuffer = malloc(sizeof(gnPlatformCommandBuffer)); + commandBuffers[i]->commandBuffer->buffer = buffers[i]; } return GN_SUCCESS; diff --git a/rendering_api/vulkan/src/submit/vulkan_submit.c b/rendering_api/vulkan/src/submit/vulkan_submit.c index a75b684..bd760a9 100644 --- a/rendering_api/vulkan/src/submit/vulkan_submit.c +++ b/rendering_api/vulkan/src/submit/vulkan_submit.c @@ -21,7 +21,7 @@ gnReturnCode gnSubmitFn(struct gnOutputDevice_t* device, struct gnSubmitInfo_t i for (int i = 0; i < info.waitCount; i++) waitStages[i] = vkGryphnWaitStage(info.waitStages[i]); VkCommandBuffer* commandBuffers = malloc(sizeof(VkCommandBuffer) * info.commandBufferCount); - for (int i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i].commandBuffer->buffer; + for (int i = 0; i < info.commandBufferCount; i++) commandBuffers[i] = info.commandBuffers[i]->commandBuffer->buffer; VkSemaphore* signalSemaphores = malloc(sizeof(VkSemaphore) * info.signalCount); for (int i = 0; i < info.signalCount; i++) signalSemaphores[i] = info.signalSemaphores[i].semaphore->semaphore; diff --git a/src/core/command/command_buffer/gryphn_command_buffer.c b/src/core/command/command_buffer/gryphn_command_buffer.c index b92e539..31ed452 100644 --- a/src/core/command/command_buffer/gryphn_command_buffer.c +++ b/src/core/command/command_buffer/gryphn_command_buffer.c @@ -2,21 +2,22 @@ #include "core/gryphn_platform_functions.h" #include "stdio.h" -gnReturnCode gnCommandPoolAllocateCommandBuffers(struct gnCommandBuffer_t* buffers, uint32_t count, struct gnCommandPool_t* commandPool) { +gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) { for (int i = 0; i < count; i++) { - buffers[i].commandPool = commandPool; + buffers[i] = malloc(sizeof(struct gnCommandBuffer_t)); + buffers[i]->commandPool = commandPool; } return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool); } -void gnResetCommandBuffer(struct gnCommandBuffer_t* commandBuffer) { +void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) { commandBuffer->commandPool->commandFunctions->_gnResetCommandBuffer(commandBuffer); } -gnReturnCode gnBeginCommandBuffer(struct gnCommandBuffer_t* commandBuffer) { +gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer) { return commandBuffer->commandPool->commandFunctions->_gnBeginCommandBuffer(commandBuffer); } -gnReturnCode gnEndCommandBuffer(struct gnCommandBuffer_t* commandBuffer) { +gnReturnCode gnEndCommandBuffer(gnCommandBufferHandle commandBuffer) { return commandBuffer->commandPool->commandFunctions->_gnEndCommandBuffer(commandBuffer); } diff --git a/src/core/command/command_buffer/gryphn_command_buffer.h b/src/core/command/command_buffer/gryphn_command_buffer.h index 932968d..5ce643d 100644 --- a/src/core/command/command_buffer/gryphn_command_buffer.h +++ b/src/core/command/command_buffer/gryphn_command_buffer.h @@ -1,13 +1,17 @@ #pragma once -#include +#include "stdint.h" +#include "utils/gryphn_error_code.h" +#include "core/gryphn_handles.h" -typedef struct gnCommandBuffer_t { +#ifdef GN_REVEAL_IMPL +struct gnCommandBuffer_t { struct gnPlatformCommandBuffer_t* commandBuffer; - struct gnCommandPool_t* commandPool; -} gnCommandBuffer; + gnCommandPoolHandle commandPool; +}; +#endif -gnReturnCode gnCommandPoolAllocateCommandBuffers(struct gnCommandBuffer_t* buffers, uint32_t count, struct gnCommandPool_t* commandPool); +gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool); -void gnResetCommandBuffer(struct gnCommandBuffer_t* commandBuffer); -gnReturnCode gnBeginCommandBuffer(struct gnCommandBuffer_t* commandBuffer); -gnReturnCode gnEndCommandBuffer(struct gnCommandBuffer_t* commandBuffer); +void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer); +gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer); +gnReturnCode gnEndCommandBuffer(gnCommandBufferHandle commandBuffer); diff --git a/src/core/command/command_pool/gryphn_command_pool.c b/src/core/command/command_pool/gryphn_command_pool.c index e9a1b45..9d8368f 100644 --- a/src/core/command/command_pool/gryphn_command_pool.c +++ b/src/core/command/command_pool/gryphn_command_pool.c @@ -2,18 +2,19 @@ #include "core/gryphn_platform_functions.h" #include "core/instance/init/gryphn_init.h" -gnReturnCode gnCreateCommandPool(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info) { +gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info) { + *commandPool = malloc(sizeof(struct gnCommandPool_t)); if (!device->instance->loadCommandFunctions) { device->instance->commandFunctions = malloc(sizeof(struct gnCommandFunctions_t)); gnLoadCommandFunctions(device->instance->dynamicLib, device->instance->commandFunctions); device->instance->loadCommandFunctions = gnTrue; } - commandPool->commandFunctions = device->instance->commandFunctions; + (*commandPool)->commandFunctions = device->instance->commandFunctions; - commandPool->device = device; - return device->deviceFunctions->_gnCreateCommandPool(commandPool, device, info); + (*commandPool)->device = device; + return device->deviceFunctions->_gnCreateCommandPool((*commandPool), device, info); } -void gnDestroyCommandPool(struct gnCommandPool_t* commandPool) { +void gnDestroyCommandPool(gnCommandPoolHandle commandPool) { commandPool->device->deviceFunctions->_gnDestroyCommandPool(commandPool); } diff --git a/src/core/command/command_pool/gryphn_command_pool.h b/src/core/command/command_pool/gryphn_command_pool.h index a8d5219..778dd03 100644 --- a/src/core/command/command_pool/gryphn_command_pool.h +++ b/src/core/command/command_pool/gryphn_command_pool.h @@ -1,17 +1,19 @@ #pragma once #include "stdint.h" -#include #include +#include "core/gryphn_handles.h" typedef struct gnCommandPoolInfo_t { uint32_t queueIndex; } gnCommandPoolInfo; -typedef struct gnCommandPool_t { +#ifdef GN_REVEAL_IMPL +struct gnCommandPool_t { struct gnPlatformCommandPool_t* commandPool; struct gnCommandFunctions_t* commandFunctions; struct gnOutputDevice_t* device; -} gnCommandPool; +}; +#endif -gnReturnCode gnCreateCommandPool(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info); -void gnDestroyCommandPool(struct gnCommandPool_t* commandPool); +gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info); +void gnDestroyCommandPool(gnCommandPoolHandle commandPool); diff --git a/src/core/gryphn_handles.h b/src/core/gryphn_handles.h index 3ae3131..f89435d 100644 --- a/src/core/gryphn_handles.h +++ b/src/core/gryphn_handles.h @@ -13,3 +13,5 @@ GN_HANDLE(gnRenderPassDescriptor); GN_HANDLE(gnOutputDevice); GN_HANDLE(gnShaderModule); GN_HANDLE(gnGraphicsPipeline); +GN_HANDLE(gnCommandPool); +GN_HANDLE(gnCommandBuffer); diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index 01d259c..9d9799a 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -75,8 +75,8 @@ typedef struct gnDeviceFunctions_t { gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, gnOutputDeviceHandle device, struct gnFramebufferInfo_t framebufferInfo); void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer); - gnReturnCode (*_gnCreateCommandPool)(struct gnCommandPool_t* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info); - void (*_gnDestroyCommandPool)(struct gnCommandPool_t* commandPool); + gnReturnCode (*_gnCreateCommandPool)(gnCommandPoolHandle commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info); + void (*_gnDestroyCommandPool)(gnCommandPoolHandle commandPool); gnReturnCode (*_gnCreateSemaphore)(struct gnSemaphore_t* semaphore, gnOutputDeviceHandle device); void (*_gnDestroySemaphore)(struct gnSemaphore_t* semaphore); @@ -87,24 +87,24 @@ typedef struct gnDeviceFunctions_t { void (*_gnResetFence)(struct gnFence_t* fence); void (*_gnDestroyFence)(struct gnFence_t* fence); - gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, struct gnSubmitInfo_t submit); - gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, struct gnPresentInfo_t info); + gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, gnSubmitInfo submit); + gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, gnPresentInfo info); void (*_gnWaitForDevice)(gnOutputDeviceHandle device); } gnDeviceFunctions; typedef struct gnCommandFunctions_t { - gnReturnCode (*_gnCommandPoolAllocateCommandBuffers)(struct gnCommandBuffer_t* commandBuffers, uint32_t count, struct gnCommandPool_t* pool); - gnReturnCode (*_gnBeginCommandBuffer)(struct gnCommandBuffer_t* commandBuffer); - void (*_gnResetCommandBuffer)(struct gnCommandBuffer_t* commandBuffer); - gnReturnCode (*_gnEndCommandBuffer)(struct gnCommandBuffer_t* commandBuffer); + gnReturnCode (*_gnCommandPoolAllocateCommandBuffers)(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool); + gnReturnCode (*_gnBeginCommandBuffer)(gnCommandBufferHandle commandBuffer); + void (*_gnResetCommandBuffer)(gnCommandBufferHandle commandBuffer); + gnReturnCode (*_gnEndCommandBuffer)(gnCommandBufferHandle commandBuffer); - void (*_gnCommandBeginRenderPass)(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo); - void (*_gnCommandEndRenderPass)(struct gnCommandBuffer_t* buffer); + void (*_gnCommandBeginRenderPass)(gnCommandBufferHandle buffer, struct gnRenderPassInfo_t passInfo); + void (*_gnCommandEndRenderPass)(gnCommandBufferHandle buffer); - void (*_gnCommandBindGraphicsPipeline)(struct gnCommandBuffer_t* buffer, struct gnGraphicsPipeline_t* graphicsPipeline); - void (*_gnCommandSetViewport)(struct gnCommandBuffer_t* buffer, struct gnViewport_t viewport); - void (*_gnCommandSetScissor)(struct gnCommandBuffer_t* buffer, struct gnScissor_t scissor); + void (*_gnCommandBindGraphicsPipeline)(gnCommandBufferHandle buffer, gnGraphicsPipelineHandle graphicsPipeline); + void (*_gnCommandSetViewport)(gnCommandBufferHandle buffer, gnViewport viewport); + void (*_gnCommandSetScissor)(gnCommandBufferHandle buffer, gnScissor scissor); - 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); } gnCommandFunctions; diff --git a/src/core/submit/gryphn_submit.h b/src/core/submit/gryphn_submit.h index 6e1fabe..961da53 100644 --- a/src/core/submit/gryphn_submit.h +++ b/src/core/submit/gryphn_submit.h @@ -2,7 +2,6 @@ #include "stdint.h" #include "core/sync/semaphore/gryphn_semaphore.h" #include "core/sync/fence/gryphn_fence.h" -#include "core/command/command_buffer/gryphn_command_buffer.h" #include "core/output_device/gryphn_output_device.h" typedef struct gnSubmitInfo_t { @@ -12,7 +11,7 @@ typedef struct gnSubmitInfo_t { uint32_t signalCount; struct gnSemaphore_t* signalSemaphores; uint32_t commandBufferCount; - struct gnCommandBuffer_t* commandBuffers; + gnCommandBufferHandle* commandBuffers; uint32_t queueIndex; struct gnFence_t* fence; } gnSubmitInfo;