radv: record number of color/depth samples for each subpass
[mesa.git] / src / amd / vulkan / radv_pass.c
index 4d1e38a780e89e3092665e0e9b8c433a50bd206a..ae6a3c1718418573bdd1d03a481916a367c70b07 100644 (file)
@@ -62,6 +62,22 @@ radv_render_pass_add_subpass_dep(struct radv_render_pass *pass,
 static void
 radv_render_pass_compile(struct radv_render_pass *pass)
 {
+       for (uint32_t i = 0; i < pass->subpass_count; i++) {
+               struct radv_subpass *subpass = &pass->subpasses[i];
+
+               for (uint32_t j = 0; j < subpass->attachment_count; j++) {
+                       struct radv_subpass_attachment *subpass_att =
+                               &subpass->attachments[j];
+                       if (subpass_att->attachment == VK_ATTACHMENT_UNUSED)
+                               continue;
+
+                       struct radv_render_pass_attachment *pass_att =
+                               &pass->attachments[subpass_att->attachment];
+
+                       pass_att->first_subpass_idx = UINT32_MAX;
+               }
+       }
+
        for (uint32_t i = 0; i < pass->subpass_count; i++) {
                struct radv_subpass *subpass = &pass->subpasses[i];
                uint32_t color_sample_count = 1, depth_sample_count = 1;
@@ -75,6 +91,10 @@ radv_render_pass_compile(struct radv_render_pass *pass)
                    subpass->depth_stencil_attachment->attachment == VK_ATTACHMENT_UNUSED)
                        subpass->depth_stencil_attachment = NULL;
 
+               if (subpass->ds_resolve_attachment &&
+                   subpass->ds_resolve_attachment->attachment == VK_ATTACHMENT_UNUSED)
+                       subpass->ds_resolve_attachment = NULL;
+
                for (uint32_t j = 0; j < subpass->attachment_count; j++) {
                        struct radv_subpass_attachment *subpass_att =
                                &subpass->attachments[j];
@@ -84,6 +104,8 @@ radv_render_pass_compile(struct radv_render_pass *pass)
                        struct radv_render_pass_attachment *pass_att =
                                &pass->attachments[subpass_att->attachment];
 
+                       if (i < pass_att->first_subpass_idx)
+                               pass_att->first_subpass_idx = i;
                        pass_att->last_subpass_idx = i;
                }
 
@@ -112,9 +134,11 @@ radv_render_pass_compile(struct radv_render_pass *pass)
 
                subpass->max_sample_count = MAX2(color_sample_count,
                                                 depth_sample_count);
+               subpass->color_sample_count = color_sample_count;
+               subpass->depth_sample_count = depth_sample_count;
 
                /* We have to handle resolve attachments specially */
-               subpass->has_resolve = false;
+               subpass->has_color_resolve = false;
                if (subpass->resolve_attachments) {
                        for (uint32_t j = 0; j < subpass->color_count; j++) {
                                struct radv_subpass_attachment *resolve_att =
@@ -123,7 +147,25 @@ radv_render_pass_compile(struct radv_render_pass *pass)
                                if (resolve_att->attachment == VK_ATTACHMENT_UNUSED)
                                        continue;
 
-                               subpass->has_resolve = true;
+                               subpass->has_color_resolve = true;
+                       }
+               }
+
+               for (uint32_t j = 0; j < subpass->input_count; ++j) {
+                       if (subpass->input_attachments[j].attachment == VK_ATTACHMENT_UNUSED)
+                               continue;
+
+                       for (uint32_t k = 0; k < subpass->color_count; ++k) {
+                               if (subpass->color_attachments[k].attachment == subpass->input_attachments[j].attachment) {
+                                       subpass->input_attachments[j].in_render_loop = true;
+                                       subpass->color_attachments[k].in_render_loop = true;
+                               }
+                       }
+
+                       if (subpass->depth_stencil_attachment &&
+                           subpass->depth_stencil_attachment->attachment == subpass->input_attachments[j].attachment) {
+                               subpass->input_attachments[j].in_render_loop = true;
+                               subpass->depth_stencil_attachment->in_render_loop = true;
                        }
                }
        }
@@ -186,6 +228,8 @@ VkResult radv_CreateRenderPass(
                att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
                att->initial_layout =  pCreateInfo->pAttachments[i].initialLayout;
                att->final_layout =  pCreateInfo->pAttachments[i].finalLayout;
+               att->stencil_initial_layout = pCreateInfo->pAttachments[i].initialLayout;
+               att->stencil_final_layout = pCreateInfo->pAttachments[i].finalLayout;
                // att->store_op = pCreateInfo->pAttachments[i].storeOp;
                // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
        }
@@ -229,6 +273,7 @@ VkResult radv_CreateRenderPass(
                                subpass->input_attachments[j] = (struct radv_subpass_attachment) {
                                        .attachment = desc->pInputAttachments[j].attachment,
                                        .layout = desc->pInputAttachments[j].layout,
+                                       .stencil_layout = desc->pInputAttachments[j].layout,
                                };
                        }
                }
@@ -253,6 +298,7 @@ VkResult radv_CreateRenderPass(
                                subpass->resolve_attachments[j] = (struct radv_subpass_attachment) {
                                        .attachment = desc->pResolveAttachments[j].attachment,
                                        .layout = desc->pResolveAttachments[j].layout,
+                                       .stencil_layout = desc->pResolveAttachments[j].layout,
                                };
                        }
                }
@@ -263,6 +309,7 @@ VkResult radv_CreateRenderPass(
                        *subpass->depth_stencil_attachment = (struct radv_subpass_attachment) {
                                .attachment = desc->pDepthStencilAttachment->attachment,
                                .layout = desc->pDepthStencilAttachment->layout,
+                               .stencil_layout = desc->pDepthStencilAttachment->layout,
                        };
                }
        }
@@ -291,10 +338,15 @@ VkResult radv_CreateRenderPass(
 static unsigned
 radv_num_subpass_attachments2(const VkSubpassDescription2KHR *desc)
 {
+       const VkSubpassDescriptionDepthStencilResolveKHR *ds_resolve =
+               vk_find_struct_const(desc->pNext,
+                                    SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR);
+
        return desc->inputAttachmentCount +
               desc->colorAttachmentCount +
               (desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
-              (desc->pDepthStencilAttachment != NULL);
+              (desc->pDepthStencilAttachment != NULL) +
+              (ds_resolve && ds_resolve->pDepthStencilResolveAttachment);
 }
 
 VkResult radv_CreateRenderPass2KHR(
@@ -327,6 +379,9 @@ VkResult radv_CreateRenderPass2KHR(
 
        for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
                struct radv_render_pass_attachment *att = &pass->attachments[i];
+               const VkAttachmentDescriptionStencilLayoutKHR *stencil_layout =
+                       vk_find_struct_const(pCreateInfo->pAttachments[i].pNext,
+                                            ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR);
 
                att->format = pCreateInfo->pAttachments[i].format;
                att->samples = pCreateInfo->pAttachments[i].samples;
@@ -334,6 +389,12 @@ VkResult radv_CreateRenderPass2KHR(
                att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
                att->initial_layout =  pCreateInfo->pAttachments[i].initialLayout;
                att->final_layout =  pCreateInfo->pAttachments[i].finalLayout;
+               att->stencil_initial_layout = (stencil_layout ?
+                                              stencil_layout->stencilInitialLayout :
+                                              pCreateInfo->pAttachments[i].initialLayout);
+               att->stencil_final_layout = (stencil_layout ?
+                                            stencil_layout->stencilFinalLayout :
+                                            pCreateInfo->pAttachments[i].finalLayout);
                // att->store_op = pCreateInfo->pAttachments[i].storeOp;
                // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
        }
@@ -372,9 +433,16 @@ VkResult radv_CreateRenderPass2KHR(
                        p += desc->inputAttachmentCount;
 
                        for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
+                               const VkAttachmentReferenceStencilLayoutKHR *stencil_attachment =
+                                   vk_find_struct_const(desc->pInputAttachments[j].pNext,
+                                                        ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
+
                                subpass->input_attachments[j] = (struct radv_subpass_attachment) {
                                        .attachment = desc->pInputAttachments[j].attachment,
                                        .layout = desc->pInputAttachments[j].layout,
+                                       .stencil_layout = (stencil_attachment ?
+                                                          stencil_attachment->stencilLayout :
+                                                          desc->pInputAttachments[j].layout),
                                };
                        }
                }
@@ -406,10 +474,40 @@ VkResult radv_CreateRenderPass2KHR(
                if (desc->pDepthStencilAttachment) {
                        subpass->depth_stencil_attachment = p++;
 
+                       const VkAttachmentReferenceStencilLayoutKHR *stencil_attachment =
+                           vk_find_struct_const(desc->pDepthStencilAttachment->pNext,
+                                                ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
+
                        *subpass->depth_stencil_attachment = (struct radv_subpass_attachment) {
                                .attachment = desc->pDepthStencilAttachment->attachment,
                                .layout = desc->pDepthStencilAttachment->layout,
+                               .stencil_layout = (stencil_attachment ?
+                                                  stencil_attachment->stencilLayout :
+                                                  desc->pDepthStencilAttachment->layout),
+                       };
+               }
+
+               const VkSubpassDescriptionDepthStencilResolveKHR *ds_resolve =
+                       vk_find_struct_const(desc->pNext,
+                                            SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR);
+
+               if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) {
+                       subpass->ds_resolve_attachment = p++;
+
+                       const VkAttachmentReferenceStencilLayoutKHR *stencil_resolve_attachment =
+                           vk_find_struct_const(ds_resolve->pDepthStencilResolveAttachment->pNext,
+                                                ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
+
+                       *subpass->ds_resolve_attachment = (struct radv_subpass_attachment) {
+                               .attachment =  ds_resolve->pDepthStencilResolveAttachment->attachment,
+                               .layout =      ds_resolve->pDepthStencilResolveAttachment->layout,
+                               .stencil_layout = (stencil_resolve_attachment ?
+                                                  stencil_resolve_attachment->stencilLayout :
+                                                  ds_resolve->pDepthStencilResolveAttachment->layout),
                        };
+
+                       subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
+                       subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode;
                }
        }