radv: convert the meta depth decompression path to dynamic rendering

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15612>
This commit is contained in:
Samuel Pitoiset 2022-03-16 16:07:58 +01:00
parent 9309c3d887
commit 70e663aa21
2 changed files with 45 additions and 121 deletions

View file

@ -148,74 +148,6 @@ cleanup:
return result;
}
static VkResult
create_pass(struct radv_device *device, uint32_t samples, VkRenderPass *pass)
{
VkResult result;
VkDevice device_h = radv_device_to_handle(device);
const VkAllocationCallbacks *alloc = &device->meta_state.alloc;
VkAttachmentDescription2 attachment;
attachment.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
attachment.pNext = NULL;
attachment.flags = 0;
attachment.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
attachment.samples = samples;
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
attachment.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
result = radv_CreateRenderPass2(
device_h,
&(VkRenderPassCreateInfo2){
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2,
.attachmentCount = 1,
.pAttachments = &attachment,
.subpassCount = 1,
.pSubpasses =
&(VkSubpassDescription2){
.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.inputAttachmentCount = 0,
.colorAttachmentCount = 0,
.pColorAttachments = NULL,
.pResolveAttachments = NULL,
.pDepthStencilAttachment =
&(VkAttachmentReference2){
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,
.attachment = 0,
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
.preserveAttachmentCount = 0,
.pPreserveAttachments = NULL,
},
.dependencyCount = 2,
.pDependencies =
(VkSubpassDependency2[]){{.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
.srcSubpass = VK_SUBPASS_EXTERNAL,
.dstSubpass = 0,
.srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
.srcAccessMask = 0,
.dstAccessMask = 0,
.dependencyFlags = 0},
{.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
.srcSubpass = 0,
.dstSubpass = VK_SUBPASS_EXTERNAL,
.srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
.srcAccessMask = 0,
.dstAccessMask = 0,
.dependencyFlags = 0}},
},
alloc, pass);
return result;
}
static VkResult
create_pipeline_layout(struct radv_device *device, VkPipelineLayout *layout)
{
@ -232,8 +164,8 @@ create_pipeline_layout(struct radv_device *device, VkPipelineLayout *layout)
}
static VkResult
create_pipeline(struct radv_device *device, uint32_t samples, VkRenderPass pass,
VkPipelineLayout layout, enum radv_depth_op op, VkPipeline *pipeline)
create_pipeline(struct radv_device *device, uint32_t samples, VkPipelineLayout layout,
enum radv_depth_op op, VkPipeline *pipeline)
{
VkResult result;
VkDevice device_h = radv_device_to_handle(device);
@ -258,8 +190,15 @@ create_pipeline(struct radv_device *device, uint32_t samples, VkRenderPass pass,
.sampleLocationsEnable = false,
};
const VkPipelineRenderingCreateInfo rendering_create_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT,
.stencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT,
};
const VkGraphicsPipelineCreateInfo pipeline_create_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.pNext = &rendering_create_info,
.stageCount = 2,
.pStages =
(VkPipelineShaderStageCreateInfo[]){
@ -340,7 +279,7 @@ create_pipeline(struct radv_device *device, uint32_t samples, VkRenderPass pass,
},
},
.layout = layout,
.renderPass = pass,
.renderPass = VK_NULL_HANDLE,
.subpass = 0,
};
@ -368,8 +307,6 @@ radv_device_finish_meta_depth_decomp_state(struct radv_device *device)
struct radv_meta_state *state = &device->meta_state;
for (uint32_t i = 0; i < ARRAY_SIZE(state->depth_decomp); ++i) {
radv_DestroyRenderPass(radv_device_to_handle(device), state->depth_decomp[i].pass,
&state->alloc);
radv_DestroyPipelineLayout(radv_device_to_handle(device), state->depth_decomp[i].p_layout,
&state->alloc);
@ -396,10 +333,6 @@ radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_dem
for (uint32_t i = 0; i < ARRAY_SIZE(state->depth_decomp); ++i) {
uint32_t samples = 1 << i;
res = create_pass(device, samples, &state->depth_decomp[i].pass);
if (res != VK_SUCCESS)
goto fail;
res = create_pipeline_layout(device, &state->depth_decomp[i].p_layout);
if (res != VK_SUCCESS)
goto fail;
@ -407,14 +340,12 @@ radv_device_init_meta_depth_decomp_state(struct radv_device *device, bool on_dem
if (on_demand)
continue;
res = create_pipeline(device, samples, state->depth_decomp[i].pass,
state->depth_decomp[i].p_layout, DEPTH_DECOMPRESS,
res = create_pipeline(device, samples, state->depth_decomp[i].p_layout, DEPTH_DECOMPRESS,
&state->depth_decomp[i].decompress_pipeline);
if (res != VK_SUCCESS)
goto fail;
res = create_pipeline(device, samples, state->depth_decomp[i].pass,
state->depth_decomp[i].p_layout, DEPTH_RESUMMARIZE,
res = create_pipeline(device, samples, state->depth_decomp[i].p_layout, DEPTH_RESUMMARIZE,
&state->depth_decomp[i].resummarize_pipeline);
if (res != VK_SUCCESS)
goto fail;
@ -443,17 +374,15 @@ radv_get_depth_pipeline(struct radv_cmd_buffer *cmd_buffer, struct radv_image *i
if (!state->depth_decomp[samples_log2].decompress_pipeline) {
VkResult ret;
ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].pass,
state->depth_decomp[samples_log2].p_layout, DEPTH_DECOMPRESS,
&state->depth_decomp[samples_log2].decompress_pipeline);
ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].p_layout,
DEPTH_DECOMPRESS, &state->depth_decomp[samples_log2].decompress_pipeline);
if (ret != VK_SUCCESS) {
cmd_buffer->record_result = ret;
return NULL;
}
ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].pass,
state->depth_decomp[samples_log2].p_layout, DEPTH_RESUMMARIZE,
&state->depth_decomp[samples_log2].resummarize_pipeline);
ret = create_pipeline(cmd_buffer->device, samples, state->depth_decomp[samples_log2].p_layout,
DEPTH_RESUMMARIZE, &state->depth_decomp[samples_log2].resummarize_pipeline);
if (ret != VK_SUCCESS) {
cmd_buffer->record_result = ret;
return NULL;
@ -479,8 +408,6 @@ radv_process_depth_image_layer(struct radv_cmd_buffer *cmd_buffer, struct radv_i
const VkImageSubresourceRange *range, int level, int layer)
{
struct radv_device *device = cmd_buffer->device;
struct radv_meta_state *state = &device->meta_state;
uint32_t samples_log2 = ffs(image->info.samples) - 1;
struct radv_image_view iview;
uint32_t width, height;
@ -504,42 +431,40 @@ radv_process_depth_image_layer(struct radv_cmd_buffer *cmd_buffer, struct radv_i
},
NULL);
VkFramebuffer fb_h;
radv_CreateFramebuffer(
radv_device_to_handle(device),
&(VkFramebufferCreateInfo){.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.attachmentCount = 1,
.pAttachments = (VkImageView[]){radv_image_view_to_handle(&iview)},
.width = width,
.height = height,
.layers = 1},
&cmd_buffer->pool->vk.alloc, &fb_h);
const VkRenderingAttachmentInfo depth_att = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = radv_image_view_to_handle(&iview),
.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
};
radv_cmd_buffer_begin_render_pass(cmd_buffer,
&(VkRenderPassBeginInfo){
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.renderPass = state->depth_decomp[samples_log2].pass,
.framebuffer = fb_h,
.renderArea = {.offset =
{
0,
0,
},
.extent =
{
width,
height,
}},
.clearValueCount = 0,
.pClearValues = NULL,
});
radv_cmd_buffer_set_subpass(cmd_buffer, &cmd_buffer->state.pass->subpasses[0]);
const VkRenderingAttachmentInfo stencil_att = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = radv_image_view_to_handle(&iview),
.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
};
const VkRenderingInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = {
.offset = { 0, 0 },
.extent = { width, height }
},
.layerCount = 1,
.pDepthAttachment = &depth_att,
.pStencilAttachment = &stencil_att,
};
radv_CmdBeginRendering(radv_cmd_buffer_to_handle(cmd_buffer), &rendering_info);
radv_CmdDraw(radv_cmd_buffer_to_handle(cmd_buffer), 3, 1, 0, 0);
radv_cmd_buffer_end_render_pass(cmd_buffer);
radv_CmdEndRendering(radv_cmd_buffer_to_handle(cmd_buffer));
radv_image_view_finish(&iview);
radv_DestroyFramebuffer(radv_device_to_handle(device), fb_h, &cmd_buffer->pool->vk.alloc);
}
static void

View file

@ -630,7 +630,6 @@ struct radv_meta_state {
VkPipelineLayout p_layout;
VkPipeline decompress_pipeline;
VkPipeline resummarize_pipeline;
VkRenderPass pass;
} depth_decomp[MAX_SAMPLES_LOG2];
VkDescriptorSetLayout expand_depth_stencil_compute_ds_layout;