push vertex param functions

pull/8/head
cosmonaut 2020-12-21 13:02:07 -08:00
parent feb4b5e16b
commit 6827eea6d3
1 changed files with 69 additions and 8 deletions

View File

@ -690,8 +690,20 @@ typedef struct VulkanRenderer
VkDescriptorSet fragmentUBODescriptorSet; VkDescriptorSet fragmentUBODescriptorSet;
VulkanBuffer *textureStagingBuffer; VulkanBuffer *textureStagingBuffer;
VulkanBuffer *vertexUBO; VulkanBuffer *vertexUBO;
VulkanBuffer *fragmentUBO; VulkanBuffer *fragmentUBO;
uint32_t minUBOAlignment;
uint32_t vertexUBOOffset;
uint32_t vertexUBOBlockSize;
uint32_t vertexUBOBlockIncrement;
uint32_t fragmentUBOOffset;
uint32_t fragmentUBOBlockSize;
uint32_t fragmentUBOBlockIncrement;
uint32_t frameIndex;
SDL_mutex *allocatorLock; SDL_mutex *allocatorLock;
SDL_mutex *commandLock; SDL_mutex *commandLock;
@ -761,8 +773,6 @@ typedef struct VulkanGraphicsPipeline
uint32_t fragmentSamplerBindingCount; uint32_t fragmentSamplerBindingCount;
VkDescriptorSet vertexSamplerDescriptorSet; /* updated by SetVertexSamplers */ VkDescriptorSet vertexSamplerDescriptorSet; /* updated by SetVertexSamplers */
VkDescriptorSet fragmentSamplerDescriptorSet; /* updated by SetFragmentSamplers */ VkDescriptorSet fragmentSamplerDescriptorSet; /* updated by SetFragmentSamplers */
uint32_t vertexUBOOffset; /* updated by PushVertexShaderParams */
uint32_t fragmentUBOOffset; /* updated by PushFragmentShaderParams */
} VulkanGraphicsPipeline; } VulkanGraphicsPipeline;
/* Forward declarations */ /* Forward declarations */
@ -851,6 +861,13 @@ static inline VkDeviceSize VULKAN_INTERNAL_NextHighestAlignment(
return align * ((n + align - 1) / align); return align * ((n + align - 1) / align);
} }
static inline uint32_t VULKAN_INTERNAL_NextHighestAlignment32(
uint32_t n,
uint32_t align
) {
return align * ((n + align - 1) / align);
}
static VulkanMemoryFreeRegion* VULKAN_INTERNAL_NewMemoryFreeRegion( static VulkanMemoryFreeRegion* VULKAN_INTERNAL_NewMemoryFreeRegion(
VulkanMemoryAllocation *allocation, VulkanMemoryAllocation *allocation,
VkDeviceSize offset, VkDeviceSize offset,
@ -1738,8 +1755,8 @@ static void VULKAN_DrawInstancedPrimitives(
descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet;
descriptorSets[3] = renderer->fragmentUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet;
dynamicOffsets[0] = pipeline->vertexUBOOffset; dynamicOffsets[0] = renderer->vertexUBOOffset;
dynamicOffsets[1] = pipeline->fragmentUBOOffset; dynamicOffsets[1] = renderer->fragmentUBOOffset;
RECORD_CMD(renderer->vkCmdBindDescriptorSets( RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
@ -1806,8 +1823,8 @@ static void VULKAN_DrawPrimitives(
descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet;
descriptorSets[3] = renderer->fragmentUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet;
dynamicOffsets[0] = pipeline->vertexUBOOffset; dynamicOffsets[0] = renderer->vertexUBOOffset;
dynamicOffsets[1] = pipeline->fragmentUBOOffset; dynamicOffsets[1] = renderer->fragmentUBOOffset;
RECORD_CMD(renderer->vkCmdBindDescriptorSets( RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
@ -3773,7 +3790,29 @@ static void VULKAN_PushVertexShaderParams(
uint32_t elementCount, uint32_t elementCount,
uint32_t elementSizeInBytes uint32_t elementSizeInBytes
) { ) {
SDL_assert(0); VulkanRenderer* renderer = (VulkanRenderer*)driverData;
VulkanGraphicsPipeline* vulkanPipeline = (VulkanGraphicsPipeline*)pipeline;
renderer->vertexUBOOffset += renderer->vertexUBOBlockIncrement;
renderer->vertexUBOBlockSize = VULKAN_INTERNAL_NextHighestAlignment32(
renderer->vertexUBOOffset,
renderer->minUBOAlignment
);
renderer->vertexUBOBlockIncrement = renderer->vertexUBOBlockSize;
if (renderer->vertexUBOOffset + renderer->vertexUBOBlockSize >= UBO_BUFFER_SIZE * renderer->frameIndex)
{
REFRESH_LogError("Vertex UBO overflow!");
return;
}
VULKAN_INTERNAL_SetBufferData(
driverData,
(REFRESH_Buffer*) renderer->vertexUBO,
renderer->vertexUBOOffset,
data,
elementCount * elementSizeInBytes
);
} }
static void VULKAN_PushFragmentShaderParams( static void VULKAN_PushFragmentShaderParams(
@ -3783,7 +3822,29 @@ static void VULKAN_PushFragmentShaderParams(
uint32_t elementCount, uint32_t elementCount,
uint32_t elementSizeInBytes uint32_t elementSizeInBytes
) { ) {
SDL_assert(0); VulkanRenderer* renderer = (VulkanRenderer*)driverData;
VulkanGraphicsPipeline* vulkanPipeline = (VulkanGraphicsPipeline*)pipeline;
renderer->fragmentUBOOffset += renderer->fragmentUBOBlockIncrement;
renderer->fragmentUBOBlockSize = VULKAN_INTERNAL_NextHighestAlignment32(
renderer->fragmentUBOOffset,
renderer->minUBOAlignment
);
renderer->fragmentUBOBlockIncrement = renderer->fragmentUBOBlockSize;
if (renderer->fragmentUBOOffset + renderer->fragmentUBOBlockSize >= UBO_BUFFER_SIZE * renderer->frameIndex)
{
REFRESH_LogError("Fragment UBO overflow!");
return;
}
VULKAN_INTERNAL_SetBufferData(
driverData,
(REFRESH_Buffer*) renderer->fragmentUBO,
renderer->fragmentUBOOffset,
data,
elementCount * elementSizeInBytes
);
} }
static void VULKAN_SetVertexSamplers( static void VULKAN_SetVertexSamplers(