Fix transfer buffer alignment (#31)

Reviewed-on: MoonsideGames/Refresh#31
no-fixed-command-buffers
cosmonaut 2023-01-07 05:24:58 +00:00
parent 28b4253fdf
commit 4cdd6a497a
1 changed files with 16 additions and 9 deletions

View File

@ -6734,9 +6734,11 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer( static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer, VulkanCommandBuffer *commandBuffer,
VkDeviceSize requiredSize VkDeviceSize requiredSize,
VkDeviceSize alignment
) { ) {
VkDeviceSize size; VkDeviceSize size;
VkDeviceSize offset;
uint32_t i; uint32_t i;
VulkanTransferBuffer *transferBuffer; VulkanTransferBuffer *transferBuffer;
@ -6745,9 +6747,11 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
for (i = 0; i < commandBuffer->transferBufferCount; i += 1) for (i = 0; i < commandBuffer->transferBufferCount; i += 1)
{ {
transferBuffer = commandBuffer->transferBuffers[i]; transferBuffer = commandBuffer->transferBuffers[i];
offset = transferBuffer->offset + alignment - (transferBuffer->offset % alignment);
if (transferBuffer->offset + requiredSize <= transferBuffer->buffer->size) if (offset + requiredSize <= transferBuffer->buffer->size)
{ {
transferBuffer->offset = offset;
return transferBuffer; return transferBuffer;
} }
} }
@ -6759,8 +6763,9 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
for (i = 0; i < renderer->transferBufferPool.availableBufferCount; i += 1) for (i = 0; i < renderer->transferBufferPool.availableBufferCount; i += 1)
{ {
transferBuffer = renderer->transferBufferPool.availableBuffers[i]; transferBuffer = renderer->transferBufferPool.availableBuffers[i];
offset = transferBuffer->offset + alignment - (transferBuffer->offset % alignment);
if (transferBuffer->offset + requiredSize <= transferBuffer->buffer->size) if (offset + requiredSize <= transferBuffer->buffer->size)
{ {
if (commandBuffer->transferBufferCount == commandBuffer->transferBufferCapacity) if (commandBuffer->transferBufferCount == commandBuffer->transferBufferCapacity)
{ {
@ -6778,6 +6783,7 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
renderer->transferBufferPool.availableBufferCount -= 1; renderer->transferBufferPool.availableBufferCount -= 1;
SDL_UnlockMutex(renderer->transferBufferPool.lock); SDL_UnlockMutex(renderer->transferBufferPool.lock);
transferBuffer->offset = offset;
return transferBuffer; return transferBuffer;
} }
} }
@ -6847,7 +6853,8 @@ static void VULKAN_SetTextureData(
textureSlice->rectangle.w, textureSlice->rectangle.w,
textureSlice->rectangle.h, textureSlice->rectangle.h,
vulkanTexture->format vulkanTexture->format
) ),
VULKAN_INTERNAL_BytesPerPixel(vulkanTexture->format)
); );
if (transferBuffer == NULL) if (transferBuffer == NULL)
@ -6944,7 +6951,7 @@ static void VULKAN_SetTextureDataYUV(
uint32_t dataLength uint32_t dataLength
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanTexture *tex; VulkanTexture *tex = (VulkanTexture*) y;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*)commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*)commandBuffer;
VulkanTransferBuffer *transferBuffer; VulkanTransferBuffer *transferBuffer;
@ -6957,7 +6964,8 @@ static void VULKAN_SetTextureDataYUV(
transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer( transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer(
renderer, renderer,
vulkanCommandBuffer, vulkanCommandBuffer,
yDataLength + uvDataLength yDataLength + uvDataLength,
VULKAN_INTERNAL_BytesPerPixel(tex->format)
); );
if (transferBuffer == NULL) if (transferBuffer == NULL)
@ -6983,8 +6991,6 @@ static void VULKAN_SetTextureDataYUV(
/* Y */ /* Y */
tex = (VulkanTexture*) y;
SDL_memcpy( SDL_memcpy(
stagingBufferPointer, stagingBufferPointer,
dataPtr, dataPtr,
@ -7336,7 +7342,8 @@ static void VULKAN_SetBufferData(
transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer( transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer(
renderer, renderer,
vulkanCommandBuffer, vulkanCommandBuffer,
dataLength dataLength,
renderer->physicalDeviceProperties.properties.limits.optimalBufferCopyOffsetAlignment
); );
if (transferBuffer == NULL) if (transferBuffer == NULL)