SetBufferData rework #6

Merged
cosmonaut merged 2 commits from SetBufferData_rework into main 2022-01-13 23:08:10 +00:00
5 changed files with 103 additions and 224 deletions

View File

@ -965,6 +965,7 @@ REFRESHAPI void Refresh_CopyTextureToBuffer(
*/ */
REFRESHAPI void Refresh_SetBufferData( REFRESHAPI void Refresh_SetBufferData(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer, Refresh_Buffer *buffer,
uint32_t offsetInBytes, uint32_t offsetInBytes,
void* data, void* data,

View File

@ -453,6 +453,7 @@ void Refresh_CopyTextureToBuffer(
void Refresh_SetBufferData( void Refresh_SetBufferData(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer, Refresh_Buffer *buffer,
uint32_t offsetInBytes, uint32_t offsetInBytes,
void* data, void* data,
@ -461,6 +462,7 @@ void Refresh_SetBufferData(
NULL_RETURN(device); NULL_RETURN(device);
device->SetBufferData( device->SetBufferData(
device->driverData, device->driverData,
commandBuffer,
buffer, buffer,
offsetInBytes, offsetInBytes,
data, data,

View File

@ -306,6 +306,7 @@ struct Refresh_Device
void(*SetBufferData)( void(*SetBufferData)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer, Refresh_Buffer *buffer,
uint32_t offsetInBytes, uint32_t offsetInBytes,
void* data, void* data,

View File

@ -71,7 +71,7 @@ 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 TRANSFER_BUFFER_STARTING_SIZE 8000000 /* 8MB */
#define UBO_BUFFER_SIZE 16000 /* 16KB */ #define UBO_BUFFER_SIZE 16000 /* 16KB */
#define DESCRIPTOR_POOL_STARTING_SIZE 128 #define DESCRIPTOR_POOL_STARTING_SIZE 128
#define DESCRIPTOR_SET_DEACTIVATE_FRAMES 10 #define DESCRIPTOR_SET_DEACTIVATE_FRAMES 10
@ -652,12 +652,7 @@ static const VulkanResourceAccessInfo AccessMap[RESOURCE_ACCESS_TYPES_COUNT] =
/* Memory structures */ /* Memory structures */
/* typedef struct VulkanBuffer /* cast from Refresh_Buffer */
* Our VulkanBuffer is actually a series of sub-buffers
* so we can properly support updates while a frame is in flight
* without needing a sync point
*/
typedef struct VulkanBuffer /* cast from FNA3D_Buffer */
{ {
VkBuffer buffer; VkBuffer buffer;
VkDeviceSize size; VkDeviceSize size;
@ -665,29 +660,8 @@ typedef struct VulkanBuffer /* cast from FNA3D_Buffer */
VulkanMemoryAllocation *allocation; /* see above */ VulkanMemoryAllocation *allocation; /* see above */
VulkanResourceAccessType resourceAccessType; VulkanResourceAccessType resourceAccessType;
VkBufferUsageFlags usage; VkBufferUsageFlags usage;
uint8_t bound;
} VulkanBuffer; } VulkanBuffer;
/* To properly support updating after drawing the "buffer handle"
* we return is actually a container pointing to a buffer.
* This lets us change out the internal buffer without affecting
* the client or requiring a stall.
* The "discarded" buffers are kept around to avoid memory fragmentation
* being created by buffers that frequently discard.
*/
typedef struct VulkanBufferContainer /* cast from Refresh_Buffer */
{
VulkanBuffer *vulkanBuffer;
/* These are all the buffers that have been used by this container.
* If a buffer is bound and then updated, a new buffer will be added to this list.
* These can be reused after they are submitted and command processing is complete.
*/
VulkanBuffer **buffers;
uint32_t bufferCount;
uint32_t bufferCapacity;
} VulkanBufferContainer;
typedef struct VulkanUniformBufferPool VulkanUniformBufferPool; typedef struct VulkanUniformBufferPool VulkanUniformBufferPool;
typedef struct VulkanUniformBuffer typedef struct VulkanUniformBuffer
@ -1207,6 +1181,7 @@ typedef struct VulkanCommandBuffer
uint8_t fixed; uint8_t fixed;
uint8_t submitted; uint8_t submitted;
uint8_t present; uint8_t present;
uint8_t renderPassInProgress;
VulkanCommandPool *commandPool; VulkanCommandPool *commandPool;
@ -1396,20 +1371,10 @@ typedef struct VulkanRenderer
VulkanUniformBuffer *dummyFragmentUniformBuffer; VulkanUniformBuffer *dummyFragmentUniformBuffer;
VulkanUniformBuffer *dummyComputeUniformBuffer; VulkanUniformBuffer *dummyComputeUniformBuffer;
/* FIXME: rename these */
VulkanBuffer** buffersInUse;
uint32_t buffersInUseCount;
uint32_t buffersInUseCapacity;
VulkanBuffer** submittedBuffers;
uint32_t submittedBufferCount;
uint32_t submittedBufferCapacity;
VkDeviceSize minUBOAlignment; VkDeviceSize minUBOAlignment;
SDL_mutex *allocatorLock; SDL_mutex *allocatorLock;
SDL_mutex *disposeLock; SDL_mutex *disposeLock;
SDL_mutex *boundBufferLock;
SDL_mutex *submitLock; SDL_mutex *submitLock;
/* Deferred destroy storage */ /* Deferred destroy storage */
@ -2480,12 +2445,6 @@ static void VULKAN_INTERNAL_DestroyBuffer(
VulkanRenderer* renderer, VulkanRenderer* renderer,
VulkanBuffer* buffer VulkanBuffer* buffer
) { ) {
if (buffer->bound)
{
Refresh_LogError("Tried to destroy a bound buffer!");
return;
}
if (buffer->allocation->dedicated) if (buffer->allocation->dedicated)
{ {
renderer->vkFreeMemory( renderer->vkFreeMemory(
@ -3118,7 +3077,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
buffer = SDL_malloc(sizeof(VulkanBuffer)); buffer = SDL_malloc(sizeof(VulkanBuffer));
buffer->size = size; buffer->size = size;
buffer->bound = 0;
buffer->resourceAccessType = resourceAccessType; buffer->resourceAccessType = resourceAccessType;
buffer->usage = usage; buffer->usage = usage;
@ -3184,8 +3142,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
} }
buffer->resourceAccessType = resourceAccessType; buffer->resourceAccessType = resourceAccessType;
buffer->bound = 0;
return buffer; return buffer;
} }
@ -3266,7 +3222,6 @@ static void VULKAN_INTERNAL_RotateBoundUniformBuffers(
for (i = 0; i < uniformBufferPool->submittedBufferCount; i += 1) for (i = 0; i < uniformBufferPool->submittedBufferCount; i += 1)
{ {
uniformBufferPool->submittedBuffers[i]->vulkanBuffer->bound = 0;
uniformBufferPool->availableBuffers[uniformBufferPool->availableBufferCount] = uniformBufferPool->submittedBuffers[i]; uniformBufferPool->availableBuffers[uniformBufferPool->availableBufferCount] = uniformBufferPool->submittedBuffers[i];
uniformBufferPool->availableBufferCount += 1; uniformBufferPool->availableBufferCount += 1;
} }
@ -3304,8 +3259,6 @@ static void VULKAN_INTERNAL_BindUniformBuffer(VulkanUniformBuffer *uniformBuffer
pool->boundBuffers[pool->boundBufferCount] = uniformBuffer; pool->boundBuffers[pool->boundBufferCount] = uniformBuffer;
pool->boundBufferCount += 1; pool->boundBufferCount += 1;
uniformBuffer->vulkanBuffer->bound = 1;
} }
static uint8_t VULKAN_INTERNAL_CreateUniformBuffer( static uint8_t VULKAN_INTERNAL_CreateUniformBuffer(
@ -3962,41 +3915,6 @@ static void VULKAN_INTERNAL_PostWorkCleanup(VulkanRenderer* renderer)
SDL_UnlockMutex(renderer->disposeLock); SDL_UnlockMutex(renderer->disposeLock);
/* Mark sub buffers of previously submitted buffers as unbound */
for (i = 0; i < renderer->submittedBufferCount; i += 1)
{
if (renderer->submittedBuffers[i] != NULL)
{
renderer->submittedBuffers[i]->bound = 0;
renderer->submittedBuffers[i] = NULL;
}
}
renderer->submittedBufferCount = 0;
/* Mark currently bound buffers as submitted buffers */
if (renderer->buffersInUseCount > renderer->submittedBufferCapacity)
{
renderer->submittedBuffers = SDL_realloc(
renderer->submittedBuffers,
sizeof(VulkanBuffer*) * renderer->buffersInUseCount
);
renderer->submittedBufferCapacity = renderer->buffersInUseCount;
}
for (i = 0; i < renderer->buffersInUseCount; i += 1)
{
if (renderer->buffersInUse[i] != NULL)
{
renderer->submittedBuffers[i] = renderer->buffersInUse[i];
renderer->buffersInUse[i] = NULL;
}
}
renderer->submittedBufferCount = renderer->buffersInUseCount;
renderer->buffersInUseCount = 0;
VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->vertexUniformBufferPool); VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->vertexUniformBufferPool);
VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->fragmentUniformBufferPool); VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->fragmentUniformBufferPool);
VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->computeUniformBufferPool); VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->computeUniformBufferPool);
@ -4755,11 +4673,8 @@ static void VULKAN_DestroyDevice(
SDL_DestroyMutex(renderer->allocatorLock); SDL_DestroyMutex(renderer->allocatorLock);
SDL_DestroyMutex(renderer->disposeLock); SDL_DestroyMutex(renderer->disposeLock);
SDL_DestroyMutex(renderer->boundBufferLock);
SDL_DestroyMutex(renderer->submitLock); SDL_DestroyMutex(renderer->submitLock);
SDL_free(renderer->buffersInUse);
if (!renderer->usesExternalDevice) if (!renderer->usesExternalDevice)
{ {
renderer->vkDestroyDevice(renderer->logicalDevice, NULL); renderer->vkDestroyDevice(renderer->logicalDevice, NULL);
@ -6298,8 +6213,7 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
Refresh_BufferUsageFlags usageFlags, Refresh_BufferUsageFlags usageFlags,
uint32_t sizeInBytes uint32_t sizeInBytes
) { ) {
VulkanBufferContainer* bufferContainer = SDL_malloc(sizeof(VulkanBufferContainer)); VulkanBuffer* buffer = SDL_malloc(sizeof(VulkanBuffer));
VulkanBuffer* buffer;
VkBufferUsageFlags vulkanUsageFlags = VkBufferUsageFlags vulkanUsageFlags =
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
@ -6332,14 +6246,7 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
return NULL; return NULL;
} }
bufferContainer->vulkanBuffer = buffer; return (Refresh_Buffer*) buffer;
bufferContainer->bufferCapacity = 1;
bufferContainer->bufferCount = 1;
bufferContainer->buffers = SDL_malloc(sizeof(VulkanBuffer*));
bufferContainer->buffers[0] = buffer;
return (Refresh_Buffer*) bufferContainer;
} }
/* Setters */ /* Setters */
@ -6347,13 +6254,15 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
static void VULKAN_INTERNAL_MaybeExpandTransferBuffer( static void VULKAN_INTERNAL_MaybeExpandTransferBuffer(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer, VulkanCommandBuffer *commandBuffer,
VkDeviceSize textureSize VkDeviceSize requiredSize
) { ) {
VkDeviceSize size = TEXTURE_STAGING_SIZE; VkDeviceSize size;
if (commandBuffer->transferBufferCount == 0) if (commandBuffer->transferBufferCount == 0)
{ {
while (size < textureSize) size = TRANSFER_BUFFER_STARTING_SIZE;
while (size < requiredSize)
{ {
size *= 2; size *= 2;
} }
@ -6381,12 +6290,12 @@ static void VULKAN_INTERNAL_MaybeExpandTransferBuffer(
VkDeviceSize currentSize = commandBuffer->transferBuffers[commandBuffer->transferBufferCount - 1]->buffer->size; VkDeviceSize currentSize = commandBuffer->transferBuffers[commandBuffer->transferBufferCount - 1]->buffer->size;
VkDeviceSize nextStagingSize = currentSize * 2; VkDeviceSize nextStagingSize = currentSize * 2;
if (commandBuffer->transferBuffers[commandBuffer->transferBufferCount - 1]->offset + textureSize <= currentSize) if (commandBuffer->transferBuffers[commandBuffer->transferBufferCount - 1]->offset + requiredSize <= currentSize)
{ {
return; return;
} }
while (nextStagingSize < textureSize) while (nextStagingSize < requiredSize)
{ {
nextStagingSize *= 2; nextStagingSize *= 2;
} }
@ -6423,6 +6332,12 @@ static void VULKAN_SetTextureData(
VkBufferImageCopy imageCopy; VkBufferImageCopy imageCopy;
uint8_t *stagingBufferPointer; uint8_t *stagingBufferPointer;
if (vulkanCommandBuffer->renderPassInProgress)
{
Refresh_LogError("Cannot perform buffer updates mid-render pass!");
return;
}
VULKAN_INTERNAL_MaybeExpandTransferBuffer( VULKAN_INTERNAL_MaybeExpandTransferBuffer(
renderer, renderer,
vulkanCommandBuffer, vulkanCommandBuffer,
@ -6842,62 +6757,71 @@ static void VULKAN_INTERNAL_SetBufferData(
); );
} }
/* FIXME: this should probably have a DataOptions enum */
static void VULKAN_SetBufferData( static void VULKAN_SetBufferData(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer, Refresh_Buffer *buffer,
uint32_t offsetInBytes, uint32_t offsetInBytes,
void* data, void* data,
uint32_t dataLength uint32_t dataLength
) { ) {
VulkanRenderer* renderer = (VulkanRenderer*)driverData; VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanBufferContainer* vulkanBufferContainer = (VulkanBufferContainer*) buffer; VulkanCommandBuffer* vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
VulkanBuffer* vulkanBuffer = vulkanBufferContainer->vulkanBuffer; VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer;
uint32_t i; VulkanTransferBuffer* transferBuffer;
uint8_t* transferBufferPointer;
VkBufferCopy bufferCopy;
if (vulkanBuffer->bound) if (vulkanCommandBuffer->renderPassInProgress)
{ {
for (i = 0; i < vulkanBufferContainer->bufferCount; i += 1) Refresh_LogError("Cannot perform buffer updates mid-render pass!");
{ return;
if (!vulkanBufferContainer->buffers[i]->bound)
{
vulkanBufferContainer->vulkanBuffer = vulkanBufferContainer->buffers[i];
break;
}
} }
if (i == vulkanBufferContainer->bufferCount) VULKAN_INTERNAL_MaybeExpandTransferBuffer(
{
vulkanBufferContainer->vulkanBuffer = VULKAN_INTERNAL_CreateBuffer(
renderer, renderer,
vulkanBufferContainer->vulkanBuffer->size, vulkanCommandBuffer,
vulkanBufferContainer->vulkanBuffer->resourceAccessType, dataLength
vulkanBufferContainer->vulkanBuffer->usage
); );
if (vulkanBufferContainer->bufferCount >= vulkanBufferContainer->bufferCapacity) transferBuffer = vulkanCommandBuffer->transferBuffers[vulkanCommandBuffer->transferBufferCount - 1];
{
vulkanBufferContainer->bufferCapacity += 1;
vulkanBufferContainer->buffers = SDL_realloc(
vulkanBufferContainer->buffers,
vulkanBufferContainer->bufferCapacity * sizeof(VulkanBuffer*)
);
}
vulkanBufferContainer->buffers[vulkanBufferContainer->bufferCount] = vulkanBufferContainer->vulkanBuffer; transferBufferPointer =
vulkanBufferContainer->bufferCount += 1; transferBuffer->buffer->allocation->mapPointer +
} transferBuffer->buffer->offset +
transferBuffer->offset;
vulkanBuffer = vulkanBufferContainer->vulkanBuffer; SDL_memcpy(
transferBufferPointer,
}
VULKAN_INTERNAL_SetBufferData(
vulkanBuffer,
offsetInBytes,
data, data,
dataLength dataLength
); );
VULKAN_INTERNAL_BufferMemoryBarrier(
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_TRANSFER_READ,
transferBuffer->buffer
);
VULKAN_INTERNAL_BufferMemoryBarrier(
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_TRANSFER_WRITE,
vulkanBuffer
);
bufferCopy.srcOffset = transferBuffer->offset;
bufferCopy.dstOffset = offsetInBytes;
bufferCopy.size = (VkDeviceSize) dataLength;
renderer->vkCmdCopyBuffer(
vulkanCommandBuffer->commandBuffer,
transferBuffer->buffer->buffer,
vulkanBuffer->buffer,
1,
&bufferCopy
);
} }
/* FIXME: this should return uint64_t */ /* FIXME: this should return uint64_t */
@ -7455,8 +7379,7 @@ static void VULKAN_GetBufferData(
uint32_t dataLengthInBytes uint32_t dataLengthInBytes
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanBufferContainer* vulkanBufferContainer = (VulkanBufferContainer*) buffer; VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer;
VulkanBuffer* vulkanBuffer = vulkanBufferContainer->vulkanBuffer;
uint8_t *dataPtr = (uint8_t*) data; uint8_t *dataPtr = (uint8_t*) data;
uint8_t *mapPointer; uint8_t *mapPointer;
@ -7480,8 +7403,7 @@ static void VULKAN_CopyTextureToBuffer(
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
VulkanTexture *vulkanTexture = (VulkanTexture*) textureSlice->texture; VulkanTexture *vulkanTexture = (VulkanTexture*) textureSlice->texture;
VulkanBufferContainer *vulkanBufferContainer = (VulkanBufferContainer*) buffer; VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer;
VulkanBuffer* vulkanBuffer = vulkanBufferContainer->vulkanBuffer;
VulkanResourceAccessType prevResourceAccess; VulkanResourceAccessType prevResourceAccess;
VkBufferImageCopy imageCopy; VkBufferImageCopy imageCopy;
@ -7596,13 +7518,10 @@ static void VULKAN_QueueDestroyBuffer(
Refresh_Buffer *buffer Refresh_Buffer *buffer
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanBufferContainer *vulkanBufferContainer = (VulkanBufferContainer*) buffer; VulkanBuffer *vulkanBuffer = (VulkanBuffer*) buffer;
uint32_t i;
SDL_LockMutex(renderer->disposeLock); SDL_LockMutex(renderer->disposeLock);
for (i = 0; i < vulkanBufferContainer->bufferCount; i += 1)
{
EXPAND_ARRAY_IF_NEEDED( EXPAND_ARRAY_IF_NEEDED(
renderer->buffersToDestroy, renderer->buffersToDestroy,
VulkanBuffer*, VulkanBuffer*,
@ -7613,12 +7532,10 @@ static void VULKAN_QueueDestroyBuffer(
renderer->buffersToDestroy[ renderer->buffersToDestroy[
renderer->buffersToDestroyCount renderer->buffersToDestroyCount
] = vulkanBufferContainer->buffers[i]; ] = vulkanBuffer;
renderer->buffersToDestroyCount += 1; renderer->buffersToDestroyCount += 1;
}
SDL_free(vulkanBufferContainer->buffers); SDL_free(vulkanBuffer);
SDL_free(vulkanBufferContainer);
SDL_UnlockMutex(renderer->disposeLock); SDL_UnlockMutex(renderer->disposeLock);
} }
@ -7867,6 +7784,7 @@ static void VULKAN_BeginRenderPass(
); );
vulkanCommandBuffer->currentFramebuffer = vulkanFramebuffer; vulkanCommandBuffer->currentFramebuffer = vulkanFramebuffer;
vulkanCommandBuffer->renderPassInProgress = 1;
SDL_stack_free(clearValues); SDL_stack_free(clearValues);
} }
@ -7953,6 +7871,7 @@ static void VULKAN_EndRenderPass(
vulkanCommandBuffer->currentGraphicsPipeline = NULL; vulkanCommandBuffer->currentGraphicsPipeline = NULL;
vulkanCommandBuffer->currentFramebuffer = NULL; vulkanCommandBuffer->currentFramebuffer = NULL;
vulkanCommandBuffer->renderPassInProgress = 0;
} }
static void VULKAN_BindGraphicsPipeline( static void VULKAN_BindGraphicsPipeline(
@ -8022,32 +7941,6 @@ static void VULKAN_BindGraphicsPipeline(
vulkanCommandBuffer->currentGraphicsPipeline = pipeline; vulkanCommandBuffer->currentGraphicsPipeline = pipeline;
} }
static void VULKAN_INTERNAL_MarkAsBound(
VulkanRenderer* renderer,
VulkanBuffer* buffer
) {
/* Don't rebind a bound buffer */
if (buffer->bound) return;
buffer->bound = 1;
SDL_LockMutex(renderer->boundBufferLock);
if (renderer->buffersInUseCount == renderer->buffersInUseCapacity)
{
renderer->buffersInUseCapacity *= 2;
renderer->buffersInUse = SDL_realloc(
renderer->buffersInUse,
sizeof(VulkanBuffer*) * renderer->buffersInUseCapacity
);
}
renderer->buffersInUse[renderer->buffersInUseCount] = buffer;
renderer->buffersInUseCount += 1;
SDL_UnlockMutex(renderer->boundBufferLock);
}
static void VULKAN_BindVertexBuffers( static void VULKAN_BindVertexBuffers(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
@ -8058,16 +7951,14 @@ static void VULKAN_BindVertexBuffers(
) { ) {
VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
VulkanBuffer *currentVulkanBuffer;
VkBuffer *buffers = SDL_stack_alloc(VkBuffer, bindingCount); VkBuffer *buffers = SDL_stack_alloc(VkBuffer, bindingCount);
VulkanBufferContainer* currentBufferContainer;
uint32_t i; uint32_t i;
for (i = 0; i < bindingCount; i += 1) for (i = 0; i < bindingCount; i += 1)
{ {
currentBufferContainer = (VulkanBufferContainer*) pBuffers[i]; currentVulkanBuffer = (VulkanBuffer*) pBuffers[i];
buffers[i] = currentBufferContainer->vulkanBuffer->buffer; buffers[i] = currentVulkanBuffer->buffer;
VULKAN_INTERNAL_MarkAsBound(renderer, currentBufferContainer->vulkanBuffer);
} }
renderer->vkCmdBindVertexBuffers( renderer->vkCmdBindVertexBuffers(
@ -8090,13 +7981,11 @@ static void VULKAN_BindIndexBuffer(
) { ) {
VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
VulkanBufferContainer* vulkanBufferContainer = (VulkanBufferContainer*) buffer; VulkanBuffer* vulkanBuffer = (VulkanBuffer*) buffer;
VULKAN_INTERNAL_MarkAsBound(renderer, vulkanBufferContainer->vulkanBuffer);
renderer->vkCmdBindIndexBuffer( renderer->vkCmdBindIndexBuffer(
vulkanCommandBuffer->commandBuffer, vulkanCommandBuffer->commandBuffer,
vulkanBufferContainer->vulkanBuffer->buffer, vulkanBuffer->buffer,
offset, offset,
RefreshToVK_IndexType[indexElementSize] RefreshToVK_IndexType[indexElementSize]
); );
@ -8156,7 +8045,7 @@ static void VULKAN_BindComputeBuffers(
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
VulkanComputePipeline *computePipeline = vulkanCommandBuffer->currentComputePipeline; VulkanComputePipeline *computePipeline = vulkanCommandBuffer->currentComputePipeline;
VulkanBufferContainer *currentBufferContainer; VulkanBuffer *currentVulkanBuffer;
BufferDescriptorSetData bufferDescriptorSetData; BufferDescriptorSetData bufferDescriptorSetData;
uint32_t i; uint32_t i;
@ -8167,14 +8056,13 @@ static void VULKAN_BindComputeBuffers(
for (i = 0; i < computePipeline->pipelineLayout->bufferDescriptorSetCache->bindingCount; i += 1) for (i = 0; i < computePipeline->pipelineLayout->bufferDescriptorSetCache->bindingCount; i += 1)
{ {
currentBufferContainer = (VulkanBufferContainer*) pBuffers[i]; currentVulkanBuffer = (VulkanBuffer*) pBuffers[i];
bufferDescriptorSetData.descriptorBufferInfo[i].buffer = currentBufferContainer->vulkanBuffer->buffer; bufferDescriptorSetData.descriptorBufferInfo[i].buffer = currentVulkanBuffer->buffer;
bufferDescriptorSetData.descriptorBufferInfo[i].offset = 0; bufferDescriptorSetData.descriptorBufferInfo[i].offset = 0;
bufferDescriptorSetData.descriptorBufferInfo[i].range = currentBufferContainer->vulkanBuffer->size; bufferDescriptorSetData.descriptorBufferInfo[i].range = currentVulkanBuffer->size;
VULKAN_INTERNAL_MarkAsBound(renderer, currentBufferContainer->vulkanBuffer); vulkanCommandBuffer->boundComputeBuffers[i] = currentVulkanBuffer;
vulkanCommandBuffer->boundComputeBuffers[i] = currentBufferContainer->vulkanBuffer;
} }
vulkanCommandBuffer->boundComputeBufferCount = computePipeline->pipelineLayout->bufferDescriptorSetCache->bindingCount; vulkanCommandBuffer->boundComputeBufferCount = computePipeline->pipelineLayout->bufferDescriptorSetCache->bindingCount;
@ -8395,6 +8283,7 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
commandBuffer->fixed = fixed; commandBuffer->fixed = fixed;
commandBuffer->submitted = 0; commandBuffer->submitted = 0;
commandBuffer->present = 0; commandBuffer->present = 0;
commandBuffer->renderPassInProgress = 0;
VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer); VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer);
@ -9557,7 +9446,6 @@ static Refresh_Device* VULKAN_INTERNAL_CreateDevice(
renderer->allocatorLock = SDL_CreateMutex(); renderer->allocatorLock = SDL_CreateMutex();
renderer->disposeLock = SDL_CreateMutex(); renderer->disposeLock = SDL_CreateMutex();
renderer->boundBufferLock = SDL_CreateMutex();
renderer->submitLock = SDL_CreateMutex(); renderer->submitLock = SDL_CreateMutex();
/* Create fence lists */ /* Create fence lists */
@ -9840,20 +9728,6 @@ static Refresh_Device* VULKAN_INTERNAL_CreateDevice(
UNIFORM_BUFFER_COMPUTE UNIFORM_BUFFER_COMPUTE
); );
/* Initialize buffer space */
renderer->buffersInUseCapacity = 32;
renderer->buffersInUseCount = 0;
renderer->buffersInUse = (VulkanBuffer**)SDL_malloc(
sizeof(VulkanBuffer*) * renderer->buffersInUseCapacity
);
renderer->submittedBufferCapacity = 32;
renderer->submittedBufferCount = 0;
renderer->submittedBuffers = (VulkanBuffer**)SDL_malloc(
sizeof(VulkanBuffer*) * renderer->submittedBufferCapacity
);
/* Initialize caches */ /* Initialize caches */
for (i = 0; i < NUM_COMMAND_POOL_BUCKETS; i += 1) for (i = 0; i < NUM_COMMAND_POOL_BUCKETS; i += 1)

View File

@ -86,6 +86,7 @@ VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdBlitImage, (VkCommandBuffer commandBuf
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearAttachments, (VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearAttachments, (VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearColorImage, (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue *pColor, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearColorImage, (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue *pColor, uint32_t rangeCount, const VkImageSubresourceRange *pRanges))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearDepthStencilImage, (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdClearDepthStencilImage, (VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange *pRanges))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdCopyBuffer, (VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdCopyBufferToImage, (VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy *pRegions)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdCopyBufferToImage, (VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy *pRegions))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdCopyImageToBuffer, (VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdCopyImageToBuffer, (VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions))
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdDispatch, (VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)) VULKAN_DEVICE_FUNCTION(BaseVK, void, vkCmdDispatch, (VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ))