From 07956bbcae4cbc396d2e6b8dcf2bab5acbfd6507 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 24 Dec 2020 14:09:58 +1000 Subject: [PATCH] lavapipe: VK_KHR_depth_stencil_resolve support This adds support for depth stencil resolves to lavapipe. Reviewed-by: Roland Scheidegger Part-of: --- docs/features.txt | 2 +- docs/relnotes/new_features.txt | 1 + src/gallium/frontends/lavapipe/lvp_device.c | 10 ++++ src/gallium/frontends/lavapipe/lvp_execute.c | 54 ++++++++++++++++++++ src/gallium/frontends/lavapipe/lvp_pass.c | 21 +++++++- src/gallium/frontends/lavapipe/lvp_private.h | 2 + 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index dbc0e4b4329..30508497527 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -448,7 +448,7 @@ Vulkan 1.2 -- all DONE: anv, vn VK_KHR_8bit_storage DONE (anv/gen8+, lvp, radv, vn) VK_KHR_buffer_device_address DONE (anv/gen8+, lvp, radv, vn) VK_KHR_create_renderpass2 DONE (anv, lvp, radv, tu, vn) - VK_KHR_depth_stencil_resolve DONE (anv, radv, tu, vn) + VK_KHR_depth_stencil_resolve DONE (anv, lvp, radv, tu, vn) VK_KHR_draw_indirect_count DONE (anv, lvp, radv, tu, vn) VK_KHR_driver_properties DONE (anv, lvp, radv, vn) VK_KHR_image_format_list DONE (anv, lvp, radv, tu, v3dv, vn) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index b33a3e1b067..a1dd9164e9a 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -8,3 +8,4 @@ GL_AMD_pinned_memory on llvmpipe GL 4.5 compatibility on llvmpipe VK_EXT_primitive_topology_list_restart on RADV. ES 3.2 on zink +VK_KHR_depth_stencil_resolve on lavapipe diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 36c7facfb6f..4c7b7d31e34 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -95,6 +95,7 @@ static const struct vk_device_extension_table lvp_device_extensions_supported = .KHR_create_renderpass2 = true, .KHR_copy_commands2 = true, .KHR_dedicated_allocation = true, + .KHR_depth_stencil_resolve = true, .KHR_descriptor_update_template = true, .KHR_device_group = true, .KHR_draw_indirect_count = true, @@ -1022,6 +1023,15 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetPhysicalDeviceProperties2( props->maxMultiDrawCount = 2048; break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES: { + VkPhysicalDeviceDepthStencilResolveProperties *properties = + (VkPhysicalDeviceDepthStencilResolveProperties *)ext; + properties->supportedDepthResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT | VK_RESOLVE_MODE_AVERAGE_BIT; + properties->supportedStencilResolveModes = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; + properties->independentResolveNone = false; + properties->independentResolve = false; + break; + } default: break; } diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index 425527b1192..50668178fc5 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -1545,6 +1545,60 @@ slow_clear: static void render_pass_resolve(struct rendering_state *state) { const struct lvp_subpass *subpass = &state->pass->subpasses[state->subpass]; + + if (subpass->depth_stencil_attachment && subpass->ds_resolve_attachment) { + struct lvp_subpass_attachment src_att = *subpass->depth_stencil_attachment; + struct lvp_subpass_attachment dst_att = *subpass->ds_resolve_attachment; + if (dst_att.attachment != VK_ATTACHMENT_UNUSED) { + int num_blits = 1; + if (subpass->depth_resolve_mode != subpass->stencil_resolve_mode) + num_blits = 2; + + for (unsigned i = 0; i < num_blits; i++) { + + if (i == 0 && subpass->depth_resolve_mode == VK_RESOLVE_MODE_NONE) + continue; + + if (i == 1 && subpass->stencil_resolve_mode == VK_RESOLVE_MODE_NONE) + continue; + + struct lvp_image_view *src_imgv = get_attachment(state, src_att.attachment); + struct lvp_image_view *dst_imgv = get_attachment(state, dst_att.attachment); + + struct pipe_blit_info info; + memset(&info, 0, sizeof(info)); + + info.src.resource = src_imgv->image->bo; + info.dst.resource = dst_imgv->image->bo; + info.src.format = src_imgv->pformat; + info.dst.format = dst_imgv->pformat; + info.filter = PIPE_TEX_FILTER_NEAREST; + + if (num_blits == 1) + info.mask = PIPE_MASK_ZS; + else if (i == 0) + info.mask = PIPE_MASK_Z; + else + info.mask = PIPE_MASK_S; + + if (i == 0 && subpass->depth_resolve_mode == VK_RESOLVE_MODE_SAMPLE_ZERO_BIT) + info.sample0_only = true; + if (i == 1 && subpass->stencil_resolve_mode == VK_RESOLVE_MODE_SAMPLE_ZERO_BIT) + info.sample0_only = true; + + info.src.box.x = state->render_area.offset.x; + info.src.box.y = state->render_area.offset.y; + info.src.box.width = state->render_area.extent.width; + info.src.box.height = state->render_area.extent.height; + info.src.box.depth = state->vk_framebuffer->layers; + + info.dst.box = info.src.box; + + state->pctx->blit(state->pctx, &info); + } + } + } + if (!subpass->has_color_resolve) return; for (uint32_t i = 0; i < subpass->color_count; i++) { diff --git a/src/gallium/frontends/lavapipe/lvp_pass.c b/src/gallium/frontends/lavapipe/lvp_pass.c index ed279bc1296..babf825e6ee 100644 --- a/src/gallium/frontends/lavapipe/lvp_pass.c +++ b/src/gallium/frontends/lavapipe/lvp_pass.c @@ -138,10 +138,14 @@ lvp_render_pass_compile(struct lvp_render_pass *pass) static unsigned lvp_num_subpass_attachments2(const VkSubpassDescription2 *desc) { + const VkSubpassDescriptionDepthStencilResolve *ds_resolve = + vk_find_struct_const(desc->pNext, + SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE); return desc->inputAttachmentCount + desc->colorAttachmentCount + (desc->pResolveAttachments ? desc->colorAttachmentCount : 0) + - (desc->pDepthStencilAttachment != NULL); + (desc->pDepthStencilAttachment != NULL) + + (ds_resolve && ds_resolve->pDepthStencilResolveAttachment); } VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateRenderPass2( @@ -262,6 +266,21 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateRenderPass2( .layout = desc->pDepthStencilAttachment->layout, }; } + + const VkSubpassDescriptionDepthStencilResolve *ds_resolve = + vk_find_struct_const(desc->pNext, SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE); + + if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) { + subpass->ds_resolve_attachment = p++; + + *subpass->ds_resolve_attachment = (struct lvp_subpass_attachment){ + .attachment = ds_resolve->pDepthStencilResolveAttachment->attachment, + .layout = ds_resolve->pDepthStencilResolveAttachment->layout, + }; + + subpass->depth_resolve_mode = ds_resolve->depthResolveMode; + subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode; + } } lvp_render_pass_compile(pass); diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 5ad0bc94916..cad34870bde 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -290,6 +290,8 @@ struct lvp_subpass { struct lvp_subpass_attachment * resolve_attachments; struct lvp_subpass_attachment * depth_stencil_attachment; struct lvp_subpass_attachment * ds_resolve_attachment; + VkResolveModeFlagBits depth_resolve_mode; + VkResolveModeFlagBits stencil_resolve_mode; /** Subpass has at least one color resolve attachment */ bool has_color_resolve;