mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-11 15:51:36 +00:00
Use the render pass to clear the window
Very satisfying to get to this point.
This commit is contained in:
parent
ba654b09f7
commit
0a0035e5e5
2 changed files with 20 additions and 47 deletions
|
@ -65,58 +65,29 @@ vulkan_R_Init (void)
|
|||
Vulkan_CreateRenderPass (vulkan_ctx);
|
||||
Vulkan_CreateFramebuffers (vulkan_ctx);
|
||||
|
||||
qfv_swapchain_t *sc = vulkan_ctx->swapchain;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo
|
||||
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
VkClearColorValue clearColor = { {0.7294, 0.8549, 0.3333, 1.0} };
|
||||
VkImageSubresourceRange image_subresource_range = {
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
0, 1, 0, 1,
|
||||
VkClearValue clearValues[3] = {
|
||||
{ { {0.7294, 0.8549, 0.3333, 1.0} } },
|
||||
{ { {1.0, 0.0} } },
|
||||
{ { {0, 0, 0, 0} } },
|
||||
};
|
||||
VkRenderPassBeginInfo renderPassInfo = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, 0,
|
||||
vulkan_ctx->renderpass.renderpass, 0,
|
||||
{ {0, 0}, sc->extent },
|
||||
2, clearValues
|
||||
};
|
||||
VkImageMemoryBarrier pc_barrier = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, 0,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
device->queue.queueFamily,
|
||||
device->queue.queueFamily,
|
||||
0, // filled in later
|
||||
image_subresource_range
|
||||
};
|
||||
VkImageMemoryBarrier cp_barrier = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, 0,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
device->queue.queueFamily,
|
||||
device->queue.queueFamily,
|
||||
0, // filled in later
|
||||
image_subresource_range
|
||||
};
|
||||
for (size_t i = 0; i < vulkan_ctx->framebuffers.size; i++) {
|
||||
__auto_type framebuffer = &vulkan_ctx->framebuffers.a[i];
|
||||
pc_barrier.image = vulkan_ctx->swapchain->images->a[i];
|
||||
cp_barrier.image = vulkan_ctx->swapchain->images->a[i];
|
||||
dfunc->vkBeginCommandBuffer (framebuffer->cmdBuffer, &beginInfo);
|
||||
dfunc->vkCmdPipelineBarrier (framebuffer->cmdBuffer,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
0, 0, // memory barriers
|
||||
0, 0, // buffer barriers
|
||||
1, &pc_barrier);
|
||||
dfunc->vkCmdClearColorImage (framebuffer->cmdBuffer, pc_barrier.image,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
&clearColor, 1,
|
||||
&image_subresource_range);
|
||||
dfunc->vkCmdPipelineBarrier (framebuffer->cmdBuffer,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
0,
|
||||
0, 0,
|
||||
0, 0,
|
||||
1, &cp_barrier);
|
||||
renderPassInfo.framebuffer = framebuffer->framebuffer;
|
||||
dfunc->vkCmdBeginRenderPass (framebuffer->cmdBuffer, &renderPassInfo,
|
||||
VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
dfunc->vkCmdEndRenderPass (framebuffer->cmdBuffer);
|
||||
dfunc->vkEndCommandBuffer (framebuffer->cmdBuffer);
|
||||
}
|
||||
Sys_Printf ("R_Init %p %d", vulkan_ctx->swapchain->swapchain,
|
||||
|
|
|
@ -362,7 +362,7 @@ Vulkan_CreateRenderPass (vulkan_ctx_t *ctx)
|
|||
attachments->a[2].flags = 0;
|
||||
attachments->a[2].format = sc->format;
|
||||
attachments->a[2].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
attachments->a[2].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
attachments->a[2].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachments->a[2].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
attachments->a[2].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachments->a[2].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
|
@ -469,4 +469,6 @@ Vulkan_DestroyFramebuffers (vulkan_ctx_t *ctx)
|
|||
df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0);
|
||||
df->vkDestroyFramebuffer (dev, frame->framebuffer, 0);
|
||||
}
|
||||
|
||||
DARRAY_CLEAR (&ctx->framebuffers);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue