proper sub buffer index system
parent
87920c0048
commit
a174573b02
|
@ -605,6 +605,7 @@ struct VulkanBuffer /* cast from FNA3D_Buffer */
|
||||||
VkDeviceSize size;
|
VkDeviceSize size;
|
||||||
VulkanSubBuffer **subBuffers;
|
VulkanSubBuffer **subBuffers;
|
||||||
uint32_t subBufferCount;
|
uint32_t subBufferCount;
|
||||||
|
uint32_t currentSubBufferIndex;
|
||||||
VulkanResourceAccessType resourceAccessType;
|
VulkanResourceAccessType resourceAccessType;
|
||||||
VkBufferUsageFlags usage;
|
VkBufferUsageFlags usage;
|
||||||
uint8_t bound;
|
uint8_t bound;
|
||||||
|
@ -2050,6 +2051,7 @@ static uint8_t VULKAN_INTERNAL_CreateBuffer(
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
buffer->size = size;
|
buffer->size = size;
|
||||||
|
buffer->currentSubBufferIndex = 0;
|
||||||
buffer->bound = 0;
|
buffer->bound = 0;
|
||||||
buffer->boundSubmitted = 0;
|
buffer->boundSubmitted = 0;
|
||||||
buffer->resourceAccessType = resourceAccessType;
|
buffer->resourceAccessType = resourceAccessType;
|
||||||
|
@ -2123,7 +2125,7 @@ static uint8_t VULKAN_INTERNAL_CreateBuffer(
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->subBuffers[i]->resourceAccessType = resourceAccessType;
|
buffer->subBuffers[i]->resourceAccessType = resourceAccessType;
|
||||||
buffer->subBuffers[i]->bound = 0;
|
buffer->subBuffers[i]->bound = -1;
|
||||||
|
|
||||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||||
renderer,
|
renderer,
|
||||||
|
@ -4250,16 +4252,30 @@ static void VULKAN_INTERNAL_SetBufferData(
|
||||||
VulkanBuffer* vulkanBuffer = (VulkanBuffer*)buffer;
|
VulkanBuffer* vulkanBuffer = (VulkanBuffer*)buffer;
|
||||||
uint8_t* mapPointer;
|
uint8_t* mapPointer;
|
||||||
VkResult vulkanResult;
|
VkResult vulkanResult;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
#define SUBBUF vulkanBuffer->subBuffers[0] // FIXME: testing
|
#define CURIDX vulkanBuffer->currentSubBufferIndex
|
||||||
|
#define SUBBUF vulkanBuffer->subBuffers[CURIDX]
|
||||||
|
|
||||||
/* Buffer already bound, time to die */
|
/* If buffer has not been bound this frame, set the first unbound index */
|
||||||
if (SUBBUF->bound)
|
if (!vulkanBuffer->bound)
|
||||||
{
|
{
|
||||||
REFRESH_LogError("Buffer already bound. It is an error to write data to a buffer after binding before calling Present.");
|
for (i = 0; i < vulkanBuffer->subBufferCount; i += 1)
|
||||||
|
{
|
||||||
|
if (vulkanBuffer->subBuffers[i]->bound == -1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CURIDX = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
REFRESH_LogError("Buffer already bound. It is an error to set vertex data after binding but before submitting.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Map the memory and perform the copy */
|
/* Map the memory and perform the copy */
|
||||||
vulkanResult = renderer->vkMapMemory(
|
vulkanResult = renderer->vkMapMemory(
|
||||||
renderer->logicalDevice,
|
renderer->logicalDevice,
|
||||||
|
@ -4287,6 +4303,7 @@ static void VULKAN_INTERNAL_SetBufferData(
|
||||||
SUBBUF->allocation->memory
|
SUBBUF->allocation->memory
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#undef CURIDX
|
||||||
#undef SUBBUF
|
#undef SUBBUF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4717,8 +4734,8 @@ static void VULKAN_INTERNAL_MarkAsBound(
|
||||||
VulkanRenderer* renderer,
|
VulkanRenderer* renderer,
|
||||||
VulkanBuffer* buf
|
VulkanBuffer* buf
|
||||||
) {
|
) {
|
||||||
VulkanSubBuffer* subbuf = buf->subBuffers[renderer->frameIndex];
|
VulkanSubBuffer *subbuf = buf->subBuffers[buf->currentSubBufferIndex];
|
||||||
subbuf->bound = 1;
|
subbuf->bound = renderer->frameIndex;
|
||||||
|
|
||||||
/* Don't rebind a bound buffer */
|
/* Don't rebind a bound buffer */
|
||||||
if (buf->bound) return;
|
if (buf->bound) return;
|
||||||
|
@ -4949,7 +4966,7 @@ static void VULKAN_Submit(
|
||||||
VulkanRenderer* renderer = (VulkanRenderer*)driverData;
|
VulkanRenderer* renderer = (VulkanRenderer*)driverData;
|
||||||
VkSubmitInfo submitInfo;
|
VkSubmitInfo submitInfo;
|
||||||
VkResult vulkanResult, presentResult = VK_SUCCESS;
|
VkResult vulkanResult, presentResult = VK_SUCCESS;
|
||||||
uint32_t i;
|
uint32_t i, j;
|
||||||
uint8_t present;
|
uint8_t present;
|
||||||
|
|
||||||
VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
@ -5014,7 +5031,16 @@ static void VULKAN_Submit(
|
||||||
{
|
{
|
||||||
if (renderer->submittedBuffers[i] != NULL)
|
if (renderer->submittedBuffers[i] != NULL)
|
||||||
{
|
{
|
||||||
renderer->submittedBuffers[i]->subBuffers[renderer->frameIndex]->bound = 0;
|
renderer->submittedBuffers[i]->boundSubmitted = 0;
|
||||||
|
|
||||||
|
for (j = 0; j < renderer->submittedBuffers[i]->subBufferCount; j += 1)
|
||||||
|
{
|
||||||
|
if (renderer->submittedBuffers[i]->subBuffers[j]->bound == renderer->frameIndex)
|
||||||
|
{
|
||||||
|
renderer->submittedBuffers[i]->subBuffers[j]->bound = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderer->submittedBuffers[i] = NULL;
|
renderer->submittedBuffers[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue