|
|
@ -1,6 +1,7 @@
|
|
|
|
#include "draw.h"
|
|
|
|
#include "draw.h"
|
|
|
|
|
|
|
|
#include "gpu.h"
|
|
|
|
|
|
|
|
|
|
|
|
VkResult record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
void record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
@ -51,11 +52,9 @@ VkResult record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult record_ui_draw(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
void record_ui_draw(VkCommandBuffer command_buffer, UIContextStorage* ui_context) {
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
VkDeviceAddress push[2] = {ui_context->address, 0};
|
|
|
|
|
|
|
|
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.pipeline);
|
|
|
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, ui_context->pipeline.pipeline);
|
|
|
@ -72,45 +71,20 @@ VkResult record_ui_draw(VkCommandBuffer command_buffer, UIContextStorage* ui_con
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(
|
|
|
|
VkResult record_draw_commands(
|
|
|
|
RenderContext* context,
|
|
|
|
RenderContext* context,
|
|
|
|
UIContextStorage* ui_context) {
|
|
|
|
UIContextStorage* ui_context) {
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
for(uint32_t image_index = 0; image_index < context->swapchain_image_count; image_index++) {
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
VkCommandBuffer command_buffer = context->swapchain_command_buffers[image_index];
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
VK_RESULT(vkResetCommandBuffer(command_buffer, 0));
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = vkResetFences(context->device, 1, &context->in_flight_fences[context->current_frame]);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t image_index;
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = context->swapchain_command_buffers[context->current_frame];
|
|
|
|
|
|
|
|
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = vkResetCommandBuffer(command_buffer, 0);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
VkCommandBufferBeginInfo begin_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
result = vkBeginCommandBuffer(command_buffer, &begin_info);
|
|
|
|
VK_RESULT(vkBeginCommandBuffer(command_buffer, &begin_info));
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkViewport viewport = {
|
|
|
|
VkViewport viewport = {
|
|
|
|
.width = context->swapchain_extent.width,
|
|
|
|
.width = context->swapchain_extent.width,
|
|
|
@ -143,7 +117,29 @@ VkResult draw_frame(
|
|
|
|
record_ui_draw(command_buffer, ui_context);
|
|
|
|
record_ui_draw(command_buffer, ui_context);
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
vkCmdEndRenderPass(command_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
result = vkEndCommandBuffer(command_buffer);
|
|
|
|
VK_RESULT(vkEndCommandBuffer(command_buffer));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(
|
|
|
|
|
|
|
|
RenderContext* context) {
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = vkResetFences(context->device, 1, &context->in_flight_fences[context->current_frame]);
|
|
|
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t image_index;
|
|
|
|
|
|
|
|
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, context->image_available_semaphores[context->current_frame], VK_NULL_HANDLE, &image_index);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,7 +151,7 @@ VkResult draw_frame(
|
|
|
|
.pWaitSemaphores = &context->image_available_semaphores[context->current_frame],
|
|
|
|
.pWaitSemaphores = &context->image_available_semaphores[context->current_frame],
|
|
|
|
.pWaitDstStageMask = wait_stages,
|
|
|
|
.pWaitDstStageMask = wait_stages,
|
|
|
|
.commandBufferCount = 1,
|
|
|
|
.commandBufferCount = 1,
|
|
|
|
.pCommandBuffers = &command_buffer,
|
|
|
|
.pCommandBuffers = &context->swapchain_command_buffers[image_index],
|
|
|
|
.signalSemaphoreCount = 1,
|
|
|
|
.signalSemaphoreCount = 1,
|
|
|
|
.pSignalSemaphores = &context->render_finished_semaphores[context->current_frame],
|
|
|
|
.pSignalSemaphores = &context->render_finished_semaphores[context->current_frame],
|
|
|
|
};
|
|
|
|
};
|
|
|
|