diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index 18476c7..b185aa2 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -703,10 +703,10 @@ typedef struct VulkanBufferContainer VulkanBuffer *vulkanBuffer; } VulkanBufferContainer; -/* CpuBuffers consist of multiple backing buffer containers so that data transfers +/* TransferBuffers consist of multiple backing buffer containers so that data transfers * can occur safely without the client having to explicitly manage transfer timing. */ -typedef struct VulkanCpuBufferContainer /* cast from Refresh_CpuBuffer */ +typedef struct VulkanTransferBufferContainer /* cast from Refresh_TransferBuffer */ { uint32_t sizeInBytes; VulkanBufferContainer *activeBuffer; @@ -719,7 +719,7 @@ typedef struct VulkanCpuBufferContainer /* cast from Refresh_CpuBuffer */ uint32_t bufferCapacity; uint32_t bufferCount; VulkanBufferContainer **backingBuffers; -} VulkanCpuBufferContainer; +} VulkanTransferBufferContainer; struct VulkanBuffer { @@ -5359,14 +5359,14 @@ static void VULKAN_DrawPrimitives( static void VULKAN_DrawPrimitivesIndirect( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, - Refresh_GpuBuffer *buffer, + Refresh_GpuBuffer *gpuBuffer, uint32_t offsetInBytes, uint32_t drawCount, uint32_t stride ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) buffer)->vulkanBuffer; + VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VkDescriptorSet descriptorSets[4]; uint32_t dynamicOffsets[2]; @@ -6837,17 +6837,17 @@ static Refresh_GpuBuffer* VULKAN_CreateGpuBuffer( ); } -static Refresh_CpuBuffer* VULKAN_CreateCpuBuffer( +static Refresh_TransferBuffer* VULKAN_CreateTransferBuffer( Refresh_Renderer *driverData, uint32_t sizeInBytes ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VkBufferUsageFlags vulkanUsageFlags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - VulkanCpuBufferContainer *bufferContainer = (VulkanCpuBufferContainer*) SDL_malloc(sizeof(VulkanCpuBufferContainer)); + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) SDL_malloc(sizeof(VulkanTransferBufferContainer)); - bufferContainer->sizeInBytes = sizeInBytes; - bufferContainer->activeBuffer = VULKAN_INTERNAL_CreateBufferContainer( + transferBufferContainer->sizeInBytes = sizeInBytes; + transferBufferContainer->activeBuffer = VULKAN_INTERNAL_CreateBufferContainer( renderer, sizeInBytes, RESOURCE_ACCESS_NONE, @@ -6859,14 +6859,14 @@ static Refresh_CpuBuffer* VULKAN_CreateCpuBuffer( 0 ); - bufferContainer->bufferCapacity = 1; - bufferContainer->bufferCount = 1; - bufferContainer->backingBuffers = SDL_malloc( - bufferContainer->bufferCapacity * sizeof(VulkanBufferContainer*) + transferBufferContainer->bufferCapacity = 1; + transferBufferContainer->bufferCount = 1; + transferBufferContainer->backingBuffers = SDL_malloc( + transferBufferContainer->bufferCapacity * sizeof(VulkanBufferContainer*) ); - bufferContainer->backingBuffers[0] = bufferContainer->activeBuffer; + transferBufferContainer->backingBuffers[0] = transferBufferContainer->activeBuffer; - return (Refresh_CpuBuffer*) bufferContainer; + return (Refresh_TransferBuffer*) transferBufferContainer; } /* Setters */ @@ -7288,10 +7288,10 @@ static void VULKAN_INTERNAL_QueueDestroyBuffer( static void VULKAN_QueueDestroyGpuBuffer( Refresh_Renderer *driverData, - Refresh_GpuBuffer *buffer + Refresh_GpuBuffer *gpuBuffer ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanBufferContainer *vulkanBufferContainer = (VulkanBufferContainer*) buffer; + VulkanBufferContainer *vulkanBufferContainer = (VulkanBufferContainer*) gpuBuffer; VulkanBuffer *vulkanBuffer = vulkanBufferContainer->vulkanBuffer; SDL_LockMutex(renderer->disposeLock); @@ -7304,25 +7304,25 @@ static void VULKAN_QueueDestroyGpuBuffer( SDL_UnlockMutex(renderer->disposeLock); } -static void VULKAN_QueueDestroyCpuBuffer( +static void VULKAN_QueueDestroyTransferBuffer( Refresh_Renderer *driverData, - Refresh_CpuBuffer *buffer + Refresh_TransferBuffer *transferBuffer ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanCpuBufferContainer *bufferContainer = (VulkanCpuBufferContainer*) buffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; uint32_t i; SDL_LockMutex(renderer->disposeLock); - for (i = 0; i < bufferContainer->bufferCount; i += 1) + for (i = 0; i < transferBufferContainer->bufferCount; i += 1) { - VULKAN_INTERNAL_QueueDestroyBuffer(renderer, bufferContainer->backingBuffers[i]->vulkanBuffer); - SDL_free(bufferContainer->backingBuffers[i]); + VULKAN_INTERNAL_QueueDestroyBuffer(renderer, transferBufferContainer->backingBuffers[i]->vulkanBuffer); + SDL_free(transferBufferContainer->backingBuffers[i]); } /* Containers are just client handles, so we can free immediately */ - SDL_free(bufferContainer->backingBuffers); - SDL_free(bufferContainer); + SDL_free(transferBufferContainer->backingBuffers); + SDL_free(transferBufferContainer); SDL_UnlockMutex(renderer->disposeLock); } @@ -8124,13 +8124,13 @@ static void VULKAN_BindVertexBuffers( static void VULKAN_BindIndexBuffer( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, - Refresh_GpuBuffer *buffer, + Refresh_GpuBuffer *gpuBuffer, uint64_t offset, Refresh_IndexElementSize indexElementSize ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer* vulkanBuffer = ((VulkanBufferContainer*) buffer)->vulkanBuffer; + VulkanBuffer* vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanBuffer); @@ -8387,30 +8387,30 @@ static void VULKAN_EndComputePass( vulkanCommandBuffer->currentComputePipeline = NULL; } -static void VULKAN_INTERNAL_DiscardActiveCpuBuffer( +static void VULKAN_INTERNAL_DiscardActiveTransferBuffer( VulkanRenderer *renderer, - VulkanCpuBufferContainer *cpuBufferContainer + VulkanTransferBufferContainer *transferBufferContainer ) { - VulkanBufferContainer *cpuBuffer; + VulkanBufferContainer *transferBuffer; uint32_t i; - cpuBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 0; + transferBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 0; /* If a previously-discarded buffer is available, we can use that. */ - for (i = 0; i < cpuBufferContainer->bufferCount; i += 1) + for (i = 0; i < transferBufferContainer->bufferCount; i += 1) { - cpuBuffer = cpuBufferContainer->backingBuffers[i]; - if (SDL_AtomicGet(&cpuBuffer->vulkanBuffer->referenceCount) == 0) + transferBuffer = transferBufferContainer->backingBuffers[i]; + if (SDL_AtomicGet(&transferBuffer->vulkanBuffer->referenceCount) == 0) { - cpuBufferContainer->activeBuffer = cpuBuffer; + transferBufferContainer->activeBuffer = transferBuffer; return; } } /* No buffer is available, generate a new one. */ - cpuBufferContainer->activeBuffer = VULKAN_INTERNAL_CreateBufferContainer( + transferBufferContainer->activeBuffer = VULKAN_INTERNAL_CreateBufferContainer( renderer, - cpuBufferContainer->sizeInBytes, + transferBufferContainer->sizeInBytes, RESOURCE_ACCESS_NONE, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, 1, @@ -8421,40 +8421,40 @@ static void VULKAN_INTERNAL_DiscardActiveCpuBuffer( ); EXPAND_ARRAY_IF_NEEDED( - cpuBufferContainer->backingBuffers, + transferBufferContainer->backingBuffers, VulkanBufferContainer*, - cpuBufferContainer->bufferCount + 1, - cpuBufferContainer->bufferCapacity, - cpuBufferContainer->bufferCapacity * 2 + transferBufferContainer->bufferCount + 1, + transferBufferContainer->bufferCapacity, + transferBufferContainer->bufferCapacity * 2 ); - cpuBufferContainer->backingBuffers[ - cpuBufferContainer->bufferCount - ] = cpuBufferContainer->activeBuffer; - cpuBufferContainer->bufferCount += 1; + transferBufferContainer->backingBuffers[ + transferBufferContainer->bufferCount + ] = transferBufferContainer->activeBuffer; + transferBufferContainer->bufferCount += 1; } static void VULKAN_SetData( Refresh_Renderer *driverData, void* data, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, Refresh_BufferCopy *copyParams, Refresh_SetDataOptions option ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanCpuBufferContainer *cpuBufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; - if (option == REFRESH_SETDATAOPTIONS_SAFEDISCARD && SDL_AtomicGet(&cpuBufferContainer->activeBuffer->vulkanBuffer->referenceCount) > 0) + if (option == REFRESH_SETDATAOPTIONS_SAFEDISCARD && SDL_AtomicGet(&transferBufferContainer->activeBuffer->vulkanBuffer->referenceCount) > 0) { - VULKAN_INTERNAL_DiscardActiveCpuBuffer( + VULKAN_INTERNAL_DiscardActiveTransferBuffer( renderer, - cpuBufferContainer + transferBufferContainer ); } uint8_t *bufferPointer = - cpuBufferContainer->activeBuffer->vulkanBuffer->usedRegion->allocation->mapPointer + - cpuBufferContainer->activeBuffer->vulkanBuffer->usedRegion->resourceOffset + + transferBufferContainer->activeBuffer->vulkanBuffer->usedRegion->allocation->mapPointer + + transferBufferContainer->activeBuffer->vulkanBuffer->usedRegion->resourceOffset + copyParams->dstOffset; SDL_memcpy( @@ -8466,13 +8466,13 @@ static void VULKAN_SetData( static void VULKAN_GetData( Refresh_Renderer *driverData, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, void* data, Refresh_BufferCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanCpuBufferContainer *cpuBufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; - VulkanBuffer *vulkanBuffer = cpuBufferContainer->activeBuffer->vulkanBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; + VulkanBuffer *vulkanBuffer = transferBufferContainer->activeBuffer->vulkanBuffer; uint8_t *bufferPointer = vulkanBuffer->usedRegion->allocation->mapPointer + @@ -8502,13 +8502,13 @@ static void VULKAN_BeginCopyPass( static void VULKAN_UploadToTexture( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, Refresh_TextureSlice *textureSlice, Refresh_BufferImageCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanCpuBufferContainer *bufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; VulkanTexture *vulkanTexture = ((VulkanTextureContainer*) textureSlice->texture)->vulkanTexture; VkBufferImageCopy imageCopy; @@ -8516,7 +8516,7 @@ static void VULKAN_UploadToTexture( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - bufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBuffer->vulkanBuffer ); VULKAN_INTERNAL_ImageMemoryBarrier( @@ -8549,14 +8549,14 @@ static void VULKAN_UploadToTexture( renderer->vkCmdCopyBufferToImage( vulkanCommandBuffer->commandBuffer, - bufferContainer->activeBuffer->vulkanBuffer->buffer, + transferBufferContainer->activeBuffer->vulkanBuffer->buffer, vulkanTexture->image, AccessMap[vulkanTexture->resourceAccessType].imageLayout, 1, &imageCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBuffer->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTexture); VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTexture); } @@ -8564,13 +8564,13 @@ static void VULKAN_UploadToTexture( static void VULKAN_UploadToBuffer( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, Refresh_GpuBuffer *gpuBuffer, Refresh_BufferCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanCpuBufferContainer *cpuBufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; VulkanBuffer *vulkanGpuBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VkBufferCopy bufferCopy; @@ -8578,7 +8578,7 @@ static void VULKAN_UploadToBuffer( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_READ, - cpuBufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBuffer->vulkanBuffer ); VULKAN_INTERNAL_BufferMemoryBarrier( @@ -8594,13 +8594,13 @@ static void VULKAN_UploadToBuffer( renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, - cpuBufferContainer->activeBuffer->vulkanBuffer->buffer, + transferBufferContainer->activeBuffer->vulkanBuffer->buffer, vulkanGpuBuffer->buffer, 1, &bufferCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, cpuBufferContainer->activeBuffer->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); } @@ -8609,20 +8609,20 @@ static void VULKAN_DownloadFromTexture( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, Refresh_BufferImageCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanTexture *vulkanTexture = ((VulkanTextureContainer*) textureSlice->texture)->vulkanTexture; - VulkanCpuBufferContainer *cpuBufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; VkBufferImageCopy imageCopy; VULKAN_INTERNAL_BufferMemoryBarrier( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - cpuBufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBuffer->vulkanBuffer ); VULKAN_INTERNAL_ImageMemoryBarrier( @@ -8657,28 +8657,28 @@ static void VULKAN_DownloadFromTexture( vulkanCommandBuffer->commandBuffer, vulkanTexture->image, AccessMap[vulkanTexture->resourceAccessType].imageLayout, - cpuBufferContainer->activeBuffer->vulkanBuffer->buffer, + transferBufferContainer->activeBuffer->vulkanBuffer->buffer, 1, &imageCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, cpuBufferContainer->activeBuffer->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); VULKAN_INTERNAL_TrackTexture(renderer, vulkanCommandBuffer, vulkanTexture); VULKAN_INTERNAL_TrackCopiedTexture(renderer, vulkanCommandBuffer, vulkanTexture); - cpuBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; + transferBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; } static void VULKAN_DownloadFromBuffer( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, Refresh_GpuBuffer *gpuBuffer, - Refresh_CpuBuffer *cpuBuffer, + Refresh_TransferBuffer *transferBuffer, Refresh_BufferCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanCpuBufferContainer *cpuBufferContainer = (VulkanCpuBufferContainer*) cpuBuffer; + VulkanTransferBufferContainer *transferBufferContainer = (VulkanTransferBufferContainer*) transferBuffer; VulkanBuffer *vulkanGpuBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VkBufferCopy bufferCopy; @@ -8686,7 +8686,7 @@ static void VULKAN_DownloadFromBuffer( renderer, vulkanCommandBuffer->commandBuffer, RESOURCE_ACCESS_TRANSFER_WRITE, - cpuBufferContainer->activeBuffer->vulkanBuffer + transferBufferContainer->activeBuffer->vulkanBuffer ); VULKAN_INTERNAL_BufferMemoryBarrier( @@ -8703,16 +8703,16 @@ static void VULKAN_DownloadFromBuffer( renderer->vkCmdCopyBuffer( vulkanCommandBuffer->commandBuffer, vulkanGpuBuffer->buffer, - cpuBufferContainer->activeBuffer->vulkanBuffer->buffer, + transferBufferContainer->activeBuffer->vulkanBuffer->buffer, 1, &bufferCopy ); - VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, cpuBufferContainer->activeBuffer->vulkanBuffer); + VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBuffer->vulkanBuffer); VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, vulkanGpuBuffer); - cpuBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; + transferBufferContainer->activeBuffer->vulkanBuffer->preserveContentsOnDefrag = 1; } static void VULKAN_CopyTextureToTexture( @@ -8793,13 +8793,13 @@ static void VULKAN_CopyTextureToBuffer( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, Refresh_TextureSlice *textureSlice, - Refresh_GpuBuffer *buffer, + Refresh_GpuBuffer *gpuBuffer, Refresh_BufferImageCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanTexture *vulkanTexture = ((VulkanTextureContainer*) textureSlice->texture)->vulkanTexture; - VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) buffer)->vulkanBuffer; + VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VkBufferImageCopy imageCopy; VULKAN_INTERNAL_ImageMemoryBarrier( @@ -8855,13 +8855,13 @@ static void VULKAN_CopyTextureToBuffer( static void VULKAN_CopyBufferToTexture( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, - Refresh_GpuBuffer *buffer, + Refresh_GpuBuffer *gpuBuffer, Refresh_TextureSlice *textureSlice, Refresh_BufferImageCopy *copyParams ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; - VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) buffer)->vulkanBuffer; + VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer*) gpuBuffer)->vulkanBuffer; VulkanTexture *vulkanTexture = ((VulkanTextureContainer*) textureSlice->texture)->vulkanTexture; VkBufferImageCopy imageCopy;