Skip to content

Commit

Permalink
Fix missing & incomplete barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
Novum committed Aug 3, 2024
1 parent 871540a commit 6a28197
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
43 changes: 38 additions & 5 deletions Quake/gl_vidsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,12 +1369,27 @@ static void GL_CreateRenderPasses ()
if (resolve)
subpass_description.pResolveAttachments = &resolve_attachment_reference;

VkSubpassDependency subpass_dependencies[1];
subpass_dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
subpass_dependencies[0].dstSubpass = 0;
subpass_dependencies[0].srcStageMask =
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[0].dstStageMask =
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
subpass_dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
subpass_dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

ZEROED_STRUCT (VkRenderPassCreateInfo, render_pass_create_info);
render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
render_pass_create_info.attachmentCount = resolve ? 3 : 2;
render_pass_create_info.pAttachments = attachment_descriptions;
render_pass_create_info.subpassCount = 1;
render_pass_create_info.pSubpasses = &subpass_description;
render_pass_create_info.dependencyCount = 1;
render_pass_create_info.pDependencies = subpass_dependencies;

for (int scbx_index = SCBX_WORLD; scbx_index <= SCBX_VIEW_MODEL; ++scbx_index)
{
Expand Down Expand Up @@ -1450,9 +1465,9 @@ static void GL_CreateRenderPasses ()
subpass_dependencies[0].srcSubpass = 0;
subpass_dependencies[0].dstSubpass = 1;
subpass_dependencies[0].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[0].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
subpass_dependencies[0].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpass_dependencies[0].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
subpass_dependencies[0].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpass_dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

ZEROED_STRUCT (VkRenderPassCreateInfo, render_pass_create_info);
Expand Down Expand Up @@ -1506,6 +1521,22 @@ static void GL_CreateRenderPasses ()
subpass_description.pDepthStencilAttachment = NULL;
subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;

VkSubpassDependency subpass_dependencies[2];
subpass_dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
subpass_dependencies[0].dstSubpass = 0;
subpass_dependencies[0].srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
subpass_dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[0].srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
subpass_dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpass_dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
subpass_dependencies[1].srcSubpass = 0;
subpass_dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
subpass_dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpass_dependencies[1].dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
subpass_dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpass_dependencies[1].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
subpass_dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

ZEROED_STRUCT (VkRenderPassCreateInfo, render_pass_create_info);
render_pass_create_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
render_pass_create_info.pAttachments = &attachment_description;
Expand All @@ -1514,6 +1545,8 @@ static void GL_CreateRenderPasses ()
render_pass_create_info.attachmentCount = 1;
render_pass_create_info.dependencyCount = 0;
render_pass_create_info.pDependencies = NULL;
render_pass_create_info.dependencyCount = 2;
render_pass_create_info.pDependencies = subpass_dependencies;

err = vkCreateRenderPass (vulkan_globals.device, &render_pass_create_info, NULL, &vulkan_globals.warp_render_pass);
if (err != VK_SUCCESS)
Expand Down Expand Up @@ -2623,7 +2656,7 @@ static void GL_ScreenEffects (cb_context_t *cbx, qboolean enabled, end_rendering
VkImageMemoryBarrier image_barriers[2];
image_barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_barriers[0].pNext = NULL;
image_barriers[0].srcAccessMask = 0;
image_barriers[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
image_barriers[0].dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
image_barriers[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image_barriers[0].newLayout = VK_IMAGE_LAYOUT_GENERAL;
Expand All @@ -2638,7 +2671,7 @@ static void GL_ScreenEffects (cb_context_t *cbx, qboolean enabled, end_rendering

image_barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_barriers[1].pNext = NULL;
image_barriers[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
image_barriers[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
image_barriers[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
image_barriers[1].oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
image_barriers[1].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Expand Down Expand Up @@ -2886,7 +2919,7 @@ static void GL_EndRenderingTask (end_rendering_parms_t *parms)
submit_info.pWaitSemaphores = &image_aquired_semaphores[cb_index];
submit_info.signalSemaphoreCount = swapchain_acquired ? 1 : 0;
submit_info.pSignalSemaphores = &draw_complete_semaphores[cb_index];
VkPipelineStageFlags wait_dst_stage_mask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkPipelineStageFlags wait_dst_stage_mask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
submit_info.pWaitDstStageMask = &wait_dst_stage_mask;

err = vkQueueSubmit (vulkan_globals.queue, 1, &submit_info, command_buffer_fences[cb_index]);
Expand Down
10 changes: 6 additions & 4 deletions Quake/gl_warp.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void R_UpdateWarpTextures (void *unused)

int num_warp_textures = 0;

// Count warp texture & prepare barrier from undefined to GENERL if using compute warp
// Count warp texture & prepare barrier from undefined to GENERAL if using compute warp
for (int j = 1; j < MAX_MODELS; j++)
{
qmodel_t *m = cl.model_precache[j];
Expand All @@ -181,7 +181,7 @@ void R_UpdateWarpTextures (void *unused)
VkImageMemoryBarrier *image_barrier = &warp_image_barriers[num_warp_textures];
image_barrier->sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_barrier->pNext = NULL;
image_barrier->srcAccessMask = 0;
image_barrier->srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
image_barrier->dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
image_barrier->oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image_barrier->newLayout = VK_IMAGE_LAYOUT_GENERAL;
Expand All @@ -203,7 +203,7 @@ void R_UpdateWarpTextures (void *unused)
// Transfer mips from UNDEFINED to GENERAL layout
if (r_waterwarpcompute.value)
vkCmdPipelineBarrier (
cbx->cb, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, num_warp_textures, warp_image_barriers);
cbx->cb, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, num_warp_textures, warp_image_barriers);

// Render warp to top mips
for (i = 0; i < num_warp_textures; ++i)
Expand Down Expand Up @@ -241,7 +241,9 @@ void R_UpdateWarpTextures (void *unused)

// Transfer all other mips from UNDEFINED to GENERAL layout
vkCmdPipelineBarrier (
cbx->cb, r_waterwarpcompute.value ? VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
cbx->cb,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
(r_waterwarpcompute.value ? VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT),
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &memory_barrier, 0, NULL, num_warp_textures, warp_image_barriers);

// Generate mip chains
Expand Down
2 changes: 1 addition & 1 deletion Quake/r_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ void R_FlushUpdateLightmaps (
(r_rtshadows.value && (bmodel_tlas != VK_NULL_HANDLE)) ? &vulkan_globals.update_lightmap_rt_pipeline : &vulkan_globals.update_lightmap_pipeline;

vkCmdPipelineBarrier (
cbx->cb, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, num_batch_lightmaps, pre_barriers);
cbx->cb, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, num_batch_lightmaps, pre_barriers);
R_BindPipeline (cbx, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
uint32_t offsets[2] = {
current_compute_buffer_index * MAX_LIGHTSTYLES * sizeof (float), current_compute_buffer_index * MAX_DLIGHTS * 2 * sizeof (lm_compute_light_t)};
Expand Down

0 comments on commit 6a28197

Please sign in to comment.