|
|
@ -1,6 +1,10 @@
|
|
|
|
#include "draw.h"
|
|
|
|
#include "draw.h"
|
|
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(RenderContext* context, UIContextStorage* ui_context, UILayerStorage* layers, uint32_t layer_count) {
|
|
|
|
VkResult draw_frame(
|
|
|
|
|
|
|
|
RenderContext* context,
|
|
|
|
|
|
|
|
UIContextStorage* ui_context,
|
|
|
|
|
|
|
|
UIContainerStorage* containers,
|
|
|
|
|
|
|
|
uint32_t container_count) {
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
@ -62,48 +66,50 @@ VkResult draw_frame(RenderContext* context, UIContextStorage* ui_context, UILaye
|
|
|
|
|
|
|
|
|
|
|
|
// Compute Pass
|
|
|
|
// Compute Pass
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, ui_context->string_pipeline.pipeline);
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, ui_context->string_pipeline.pipeline);
|
|
|
|
for(uint32_t i = 0; i < layer_count; i++) {
|
|
|
|
for(uint32_t i = 0; i < container_count; i++) {
|
|
|
|
push[1] = layers[i].address;
|
|
|
|
for(uint32_t j = 0; j < containers[i].layer_count; j++) {
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_1 = {
|
|
|
|
push[1] = containers[i].layers[j].address;
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_1 = {
|
|
|
|
.buffer = layers[i].layer,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.buffer = containers[i].layers[j].layer,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.srcAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
.srcAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT,
|
|
|
|
};
|
|
|
|
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1, &draw_command_barrier_1, 0, NULL);
|
|
|
|
};
|
|
|
|
command_copy_buffer(command_buffer, layers[i].layer, layers[i].layer, offsetof(UILayer, num_drawables), offsetof(UILayer, draw) + offsetof(DrawCommand, instance_count), sizeof(uint32_t));
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1, &draw_command_barrier_1, 0, NULL);
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_2 = {
|
|
|
|
command_copy_buffer(command_buffer, containers[i].layers[j].layer, containers[i].layers[j].layer, offsetof(UILayer, num_drawables), offsetof(UILayer, draw) + offsetof(DrawCommand, instance_count), sizeof(uint32_t));
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_2 = {
|
|
|
|
.buffer = layers[i].layer,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.buffer = containers[i].layers[j].layer,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
};
|
|
|
|
.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 1, &draw_command_barrier_2, 0, NULL);
|
|
|
|
};
|
|
|
|
vkCmdPushConstants(command_buffer, ui_context->string_pipeline.layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 16, push);
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 1, &draw_command_barrier_2, 0, NULL);
|
|
|
|
vkCmdDispatchIndirect(command_buffer, layers[i].layer, offsetof(UILayer, dispatch_strings));
|
|
|
|
vkCmdPushConstants(command_buffer, ui_context->string_pipeline.layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 16, push);
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_3 = {
|
|
|
|
vkCmdDispatchIndirect(command_buffer, containers[i].layers[j].layer, offsetof(UILayer, dispatch_strings));
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
VkBufferMemoryBarrier draw_command_barrier_3 = {
|
|
|
|
.buffer = layers[i].layer,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.buffer = containers[i].layers[j].layer,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.offset = offsetof(UILayer, draw),
|
|
|
|
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
.size = sizeof(DrawCommand),
|
|
|
|
.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT,
|
|
|
|
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
};
|
|
|
|
.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT,
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 0, NULL, 1, &draw_command_barrier_3, 0, NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 0, NULL, 1, &draw_command_barrier_3, 0, NULL);
|
|
|
|
VkBufferMemoryBarrier drawables_barrier = {
|
|
|
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
VkBufferMemoryBarrier drawables_barrier = {
|
|
|
|
.buffer = layers[i].drawables,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
|
|
|
.offset = 0,
|
|
|
|
.buffer = containers[i].layers[j].drawables,
|
|
|
|
.size = sizeof(UIDrawable)*layers[i].data.max_drawables,
|
|
|
|
.offset = 0,
|
|
|
|
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
.size = sizeof(UIDrawable)*containers[i].layers[j].data.max_drawables,
|
|
|
|
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
|
|
|
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
};
|
|
|
|
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, NULL, 1, &drawables_barrier, 0, NULL);
|
|
|
|
};
|
|
|
|
|
|
|
|
vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, NULL, 1, &drawables_barrier, 0, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -112,17 +118,17 @@ VkResult draw_frame(RenderContext* context, UIContextStorage* ui_context, UILaye
|
|
|
|
// World subpass
|
|
|
|
// World subpass
|
|
|
|
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
// UI subpass
|
|
|
|
// UI subpass
|
|
|
|
for(uint32_t i = 0; i < layer_count; i++) {
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.pipeline);
|
|
|
|
push[1] = layers[i].address;
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 0, 1, &ui_context->font_samplers, 0, NULL);
|
|
|
|
vkCmdPushConstants(command_buffer, ui_context->pipeline.layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, push);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 1, 1, &ui_context->font_textures, 0, NULL);
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.pipeline);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 2, 1, &ui_context->samplers, 0, NULL);
|
|
|
|
if(i == 0) {
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 3, 1, &ui_context->textures, 0, NULL);
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 0, 1, &ui_context->font_samplers, 0, NULL);
|
|
|
|
for(uint32_t i = 0; i < container_count; i++) {
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 1, 1, &ui_context->font_textures, 0, NULL);
|
|
|
|
for(uint32_t j = 0; j < containers[i].layer_count; j++) {
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 2, 1, &ui_context->samplers, 0, NULL);
|
|
|
|
push[1] = containers[i].layers[j].address;
|
|
|
|
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.layout, 3, 1, &ui_context->textures, 0, NULL);
|
|
|
|
vkCmdPushConstants(command_buffer, ui_context->pipeline.layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, push);
|
|
|
|
|
|
|
|
vkCmdDrawIndirect(command_buffer, containers[i].layers[j].layer, offsetof(UILayer, draw), 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vkCmdDrawIndirect(command_buffer, layers[i].layer, offsetof(UILayer, draw), 1, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|