diff --git a/include/Refresh.h b/include/Refresh.h index bf4f09a..4e071bf 100644 --- a/include/Refresh.h +++ b/include/Refresh.h @@ -1233,6 +1233,21 @@ REFRESHAPI void REFRESH_BindGraphicsPipeline( REFRESH_GraphicsPipeline *graphicsPipeline ); +REFRESHAPI void REFRESH_BindVertexBuffers( + REFRESH_Device *device, + uint32_t firstBinding, + uint32_t bindingCount, + REFRESH_Buffer **pBuffers, + uint64_t *pOffsets +); + +REFRESHAPI void REFRESH_BindIndexBuffer( + REFRESH_Device *device, + REFRESH_Buffer *buffer, + uint64_t offset, + REFRESH_IndexElementSize indexElementSize +); + /* Presentation */ REFRESHAPI void REFRESH_Present( diff --git a/src/Refresh_Driver.h b/src/Refresh_Driver.h index 33952d8..fe50f3c 100644 --- a/src/Refresh_Driver.h +++ b/src/Refresh_Driver.h @@ -481,6 +481,21 @@ struct REFRESH_Device REFRESH_GraphicsPipeline *graphicsPipeline ); + void(*BindVertexBuffers)( + REFRESH_Renderer *driverData, + uint32_t firstBinding, + uint32_t bindingCount, + REFRESH_Buffer **pBuffers, + uint64_t *pOffsets + ); + + void(*BindIndexBuffer)( + REFRESH_Renderer *driverData, + REFRESH_Buffer *buffer, + uint64_t offset, + REFRESH_IndexElementSize indexElementSize + ); + void(*Present)( REFRESH_Renderer *driverData, REFRESH_Rect *sourceRectangle, @@ -536,6 +551,8 @@ struct REFRESH_Device ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \ ASSIGN_DRIVER_FUNC(EndRenderPass, name) \ ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \ + ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \ + ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \ ASSIGN_DRIVER_FUNC(Present, name) typedef struct REFRESH_Driver diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index 4c1819b..b49cd82 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -183,6 +183,12 @@ static VkFormat RefreshToVK_VertexFormat[] = VK_FORMAT_R16G16B16A16_SFLOAT /* HALFVECTOR4 */ }; +static VkIndexType RefreshToVK_IndexType[] = +{ + VK_INDEX_TYPE_UINT16, + VK_INDEX_TYPE_UINT32 +}; + static VkPrimitiveTopology RefreshToVK_PrimitiveType[] = { VK_PRIMITIVE_TOPOLOGY_POINT_LIST, @@ -3887,6 +3893,51 @@ static void VULKAN_BindGraphicsPipeline( SDL_assert(0); } +static void VULKAN_BindVertexBuffers( + REFRESH_Renderer *driverData, + uint32_t firstBinding, + uint32_t bindingCount, + REFRESH_Buffer **pBuffers, + uint64_t *pOffsets +) { + VkBuffer *buffers = SDL_stack_alloc(VkBuffer, bindingCount); + VulkanBuffer* currentBuffer; + VulkanRenderer* renderer = (VulkanRenderer*) driverData; + + for (int i = 0; i < bindingCount; i += 1) + { + currentBuffer = (VulkanBuffer*) pBuffers[i]; + buffers[i] = currentBuffer->subBuffers[currentBuffer->currentSubBufferIndex]->buffer; + } + + RECORD_CMD(renderer->vkCmdBindVertexBuffers( + renderer->currentCommandBuffer, + firstBinding, + bindingCount, + buffers, + pOffsets + )); + + SDL_stack_free(buffers); +} + +static void VULKAN_BindIndexBuffer( + REFRESH_Renderer *driverData, + REFRESH_Buffer *buffer, + uint64_t offset, + REFRESH_IndexElementSize indexElementSize +) { + VulkanRenderer* renderer = (VulkanRenderer*) driverData; + VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer; + + RECORD_CMD(renderer->vkCmdBindIndexBuffer( + renderer->currentCommandBuffer, + vulkanBuffer->subBuffers[vulkanBuffer->currentSubBufferIndex]->buffer, + offset, + RefreshToVK_IndexType[indexElementSize] + )); +} + static void VULKAN_Present( REFRESH_Renderer *driverData, REFRESH_Rect *sourceRectangle,