fix issue where texture staging buffer would be too small to contain incoming data

submit_rewrite
cosmonaut 2021-01-31 18:01:21 -08:00
parent a60725fecc
commit 254d209a48
1 changed files with 21 additions and 19 deletions

View File

@ -72,7 +72,6 @@ static uint32_t deviceExtensionCount = SDL_arraysize(deviceExtensionNames);
#define STARTING_ALLOCATION_SIZE 64000000 /* 64MB */ #define STARTING_ALLOCATION_SIZE 64000000 /* 64MB */
#define MAX_ALLOCATION_SIZE 256000000 /* 256MB */ #define MAX_ALLOCATION_SIZE 256000000 /* 256MB */
#define TEXTURE_STAGING_SIZE 8000000 /* 8MB */ #define TEXTURE_STAGING_SIZE 8000000 /* 8MB */
#define MAX_TEXTURE_STAGING_SIZE 128000000 /* 128MB */
#define UBO_BUFFER_SIZE 8000000 /* 8MB */ #define UBO_BUFFER_SIZE 8000000 /* 8MB */
#define UBO_ACTUAL_SIZE (UBO_BUFFER_SIZE * 2) #define UBO_ACTUAL_SIZE (UBO_BUFFER_SIZE * 2)
#define DESCRIPTOR_POOL_STARTING_SIZE 128 #define DESCRIPTOR_POOL_STARTING_SIZE 128
@ -5877,7 +5876,7 @@ static void VULKAN_INTERNAL_MaybeExpandStagingBuffer(
VulkanRenderer *renderer, VulkanRenderer *renderer,
uint32_t textureSize uint32_t textureSize
) { ) {
VkDeviceSize currentStagingSize = renderer->textureStagingBuffer->size; VkDeviceSize nextStagingSize = renderer->textureStagingBuffer->size;
if (renderer->textureStagingBufferOffset + textureSize <= renderer->textureStagingBuffer->size) if (renderer->textureStagingBufferOffset + textureSize <= renderer->textureStagingBuffer->size)
{ {
@ -5887,16 +5886,19 @@ static void VULKAN_INTERNAL_MaybeExpandStagingBuffer(
/* not enough room in the staging buffer, time to flush */ /* not enough room in the staging buffer, time to flush */
VULKAN_INTERNAL_FlushTransfers(renderer); VULKAN_INTERNAL_FlushTransfers(renderer);
/* double staging buffer size up to max */ while (nextStagingSize < textureSize)
if (currentStagingSize * 2 <= MAX_TEXTURE_STAGING_SIZE)
{ {
nextStagingSize *= 2;
}
/* double staging buffer size up to max */
VULKAN_INTERNAL_DestroyTextureStagingBuffer(renderer); VULKAN_INTERNAL_DestroyTextureStagingBuffer(renderer);
renderer->textureStagingBuffer = (VulkanBuffer*) SDL_malloc(sizeof(VulkanBuffer)); renderer->textureStagingBuffer = (VulkanBuffer*) SDL_malloc(sizeof(VulkanBuffer));
if (!VULKAN_INTERNAL_CreateBuffer( if (!VULKAN_INTERNAL_CreateBuffer(
renderer, renderer,
currentStagingSize * 2, nextStagingSize,
RESOURCE_ACCESS_MEMORY_TRANSFER_READ_WRITE, RESOURCE_ACCESS_MEMORY_TRANSFER_READ_WRITE,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
1, 1,
@ -5905,7 +5907,7 @@ static void VULKAN_INTERNAL_MaybeExpandStagingBuffer(
Refresh_LogError("Failed to expand texture staging buffer!"); Refresh_LogError("Failed to expand texture staging buffer!");
return; return;
} }
}
} }
static void VULKAN_INTERNAL_MaybeBeginTransferCommandBuffer( static void VULKAN_INTERNAL_MaybeBeginTransferCommandBuffer(