1/*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 */
27#include "radv_private.h"
28
29#include "vk_util.h"
30
31static void
32radv_render_pass_add_subpass_dep(struct radv_render_pass *pass, const VkSubpassDependency2 *dep)
33{
34   uint32_t src = dep->srcSubpass;
35   uint32_t dst = dep->dstSubpass;
36
37   /* Ignore subpass self-dependencies as they allow the app to call
38    * vkCmdPipelineBarrier() inside the render pass and the driver should
39    * only do the barrier when called, not when starting the render pass.
40    */
41   if (src == dst)
42      return;
43
44   /* Accumulate all ingoing external dependencies to the first subpass. */
45   if (src == VK_SUBPASS_EXTERNAL)
46      dst = 0;
47
48   if (dst == VK_SUBPASS_EXTERNAL) {
49      if (dep->dstStageMask != VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT)
50         pass->end_barrier.src_stage_mask |= dep->srcStageMask;
51      pass->end_barrier.src_access_mask |= dep->srcAccessMask;
52      pass->end_barrier.dst_access_mask |= dep->dstAccessMask;
53   } else {
54      if (dep->dstStageMask != VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT)
55         pass->subpasses[dst].start_barrier.src_stage_mask |= dep->srcStageMask;
56      pass->subpasses[dst].start_barrier.src_access_mask |= dep->srcAccessMask;
57      pass->subpasses[dst].start_barrier.dst_access_mask |= dep->dstAccessMask;
58   }
59}
60
61static void
62radv_render_pass_add_implicit_deps(struct radv_render_pass *pass)
63{
64   /* From the Vulkan 1.0.39 spec:
65    *
66    *    If there is no subpass dependency from VK_SUBPASS_EXTERNAL to the
67    *    first subpass that uses an attachment, then an implicit subpass
68    *    dependency exists from VK_SUBPASS_EXTERNAL to the first subpass it is
69    *    used in. The implicit subpass dependency only exists if there
70    *    exists an automatic layout transition away from initialLayout.
71    *    The subpass dependency operates as if defined with the
72    *    following parameters:
73    *
74    *    VkSubpassDependency implicitDependency = {
75    *        .srcSubpass = VK_SUBPASS_EXTERNAL;
76    *        .dstSubpass = firstSubpass; // First subpass attachment is used in
77    *        .srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
78    *        .dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
79    *        .srcAccessMask = 0;
80    *        .dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
81    *                         VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
82    *                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
83    *                         VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
84    *                         VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
85    *        .dependencyFlags = 0;
86    *    };
87    *
88    *    Similarly, if there is no subpass dependency from the last subpass
89    *    that uses an attachment to VK_SUBPASS_EXTERNAL, then an implicit
90    *    subpass dependency exists from the last subpass it is used in to
91    *    VK_SUBPASS_EXTERNAL. The implicit subpass dependency only exists
92    *    if there exists an automatic layout transition into finalLayout.
93    *    The subpass dependency operates as if defined with the following
94    *    parameters:
95    *
96    *    VkSubpassDependency implicitDependency = {
97    *        .srcSubpass = lastSubpass; // Last subpass attachment is used in
98    *        .dstSubpass = VK_SUBPASS_EXTERNAL;
99    *        .srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
100    *        .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
101    *        .srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
102    *                         VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
103    *                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
104    *                         VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
105    *                         VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
106    *        .dstAccessMask = 0;
107    *        .dependencyFlags = 0;
108    *    };
109    */
110   for (uint32_t i = 0; i < pass->subpass_count; i++) {
111      struct radv_subpass *subpass = &pass->subpasses[i];
112      bool add_ingoing_dep = false, add_outgoing_dep = false;
113
114      for (uint32_t j = 0; j < subpass->attachment_count; j++) {
115         struct radv_subpass_attachment *subpass_att = &subpass->attachments[j];
116         if (subpass_att->attachment == VK_ATTACHMENT_UNUSED)
117            continue;
118
119         struct radv_render_pass_attachment *pass_att = &pass->attachments[subpass_att->attachment];
120         uint32_t initial_layout = pass_att->initial_layout;
121         uint32_t stencil_initial_layout = pass_att->stencil_initial_layout;
122         uint32_t final_layout = pass_att->final_layout;
123         uint32_t stencil_final_layout = pass_att->stencil_final_layout;
124
125         /* The implicit subpass dependency only exists if
126          * there exists an automatic layout transition away
127          * from initialLayout.
128          */
129         if (pass_att->first_subpass_idx == i && !subpass->has_ingoing_dep &&
130             ((subpass_att->layout != initial_layout) ||
131              (subpass_att->layout != stencil_initial_layout))) {
132            add_ingoing_dep = true;
133         }
134
135         /* The implicit subpass dependency only exists if
136          * there exists an automatic layout transition into
137          * finalLayout.
138          */
139         if (pass_att->last_subpass_idx == i && !subpass->has_outgoing_dep &&
140             ((subpass_att->layout != final_layout) ||
141              (subpass_att->layout != stencil_final_layout))) {
142            add_outgoing_dep = true;
143         }
144      }
145
146      if (add_ingoing_dep) {
147         const VkSubpassDependency2KHR implicit_ingoing_dep = {
148            .srcSubpass = VK_SUBPASS_EXTERNAL,
149            .dstSubpass = i, /* first subpass attachment is used in */
150            .srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
151            .dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
152            .srcAccessMask = 0,
153            .dstAccessMask =
154               VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
155               VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
156               VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
157            .dependencyFlags = 0,
158         };
159
160         radv_render_pass_add_subpass_dep(pass, &implicit_ingoing_dep);
161      }
162
163      if (add_outgoing_dep) {
164         const VkSubpassDependency2KHR implicit_outgoing_dep = {
165            .srcSubpass = i, /* last subpass attachment is used in */
166            .dstSubpass = VK_SUBPASS_EXTERNAL,
167            .srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
168            .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
169            .srcAccessMask =
170               VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
171               VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
172               VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
173            .dstAccessMask = 0,
174            .dependencyFlags = 0,
175         };
176
177         radv_render_pass_add_subpass_dep(pass, &implicit_outgoing_dep);
178      }
179   }
180}
181
182static void
183radv_render_pass_compile(struct radv_render_pass *pass)
184{
185   for (uint32_t i = 0; i < pass->subpass_count; i++) {
186      struct radv_subpass *subpass = &pass->subpasses[i];
187
188      for (uint32_t j = 0; j < subpass->attachment_count; j++) {
189         struct radv_subpass_attachment *subpass_att = &subpass->attachments[j];
190         if (subpass_att->attachment == VK_ATTACHMENT_UNUSED)
191            continue;
192
193         struct radv_render_pass_attachment *pass_att = &pass->attachments[subpass_att->attachment];
194
195         pass_att->first_subpass_idx = VK_SUBPASS_EXTERNAL;
196         pass_att->last_subpass_idx = VK_SUBPASS_EXTERNAL;
197      }
198   }
199
200   for (uint32_t i = 0; i < pass->subpass_count; i++) {
201      struct radv_subpass *subpass = &pass->subpasses[i];
202      uint32_t color_sample_count = 1, depth_sample_count = 1;
203
204      /* We don't allow depth_stencil_attachment to be non-NULL and
205       * be VK_ATTACHMENT_UNUSED.  This way something can just check
206       * for NULL and be guaranteed that they have a valid
207       * attachment.
208       */
209      if (subpass->depth_stencil_attachment &&
210          subpass->depth_stencil_attachment->attachment == VK_ATTACHMENT_UNUSED)
211         subpass->depth_stencil_attachment = NULL;
212
213      if (subpass->ds_resolve_attachment &&
214          subpass->ds_resolve_attachment->attachment == VK_ATTACHMENT_UNUSED)
215         subpass->ds_resolve_attachment = NULL;
216
217      if (subpass->vrs_attachment && subpass->vrs_attachment->attachment == VK_ATTACHMENT_UNUSED)
218         subpass->vrs_attachment = NULL;
219
220      for (uint32_t j = 0; j < subpass->attachment_count; j++) {
221         struct radv_subpass_attachment *subpass_att = &subpass->attachments[j];
222         if (subpass_att->attachment == VK_ATTACHMENT_UNUSED)
223            continue;
224
225         struct radv_render_pass_attachment *pass_att = &pass->attachments[subpass_att->attachment];
226
227         if (i < pass_att->first_subpass_idx)
228            pass_att->first_subpass_idx = i;
229         pass_att->last_subpass_idx = i;
230      }
231
232      subpass->has_color_att = false;
233      for (uint32_t j = 0; j < subpass->color_count; j++) {
234         struct radv_subpass_attachment *subpass_att = &subpass->color_attachments[j];
235         if (subpass_att->attachment == VK_ATTACHMENT_UNUSED)
236            continue;
237
238         subpass->has_color_att = true;
239
240         struct radv_render_pass_attachment *pass_att = &pass->attachments[subpass_att->attachment];
241
242         color_sample_count = pass_att->samples;
243      }
244
245      if (subpass->depth_stencil_attachment) {
246         const uint32_t a = subpass->depth_stencil_attachment->attachment;
247         struct radv_render_pass_attachment *pass_att = &pass->attachments[a];
248         depth_sample_count = pass_att->samples;
249      }
250
251      subpass->max_sample_count = MAX2(color_sample_count, depth_sample_count);
252      subpass->color_sample_count = color_sample_count;
253      subpass->depth_sample_count = depth_sample_count;
254
255      /* We have to handle resolve attachments specially */
256      subpass->has_color_resolve = false;
257      if (subpass->resolve_attachments) {
258         for (uint32_t j = 0; j < subpass->color_count; j++) {
259            struct radv_subpass_attachment *resolve_att = &subpass->resolve_attachments[j];
260
261            if (resolve_att->attachment == VK_ATTACHMENT_UNUSED)
262               continue;
263
264            subpass->has_color_resolve = true;
265         }
266      }
267
268      for (uint32_t j = 0; j < subpass->input_count; ++j) {
269         if (subpass->input_attachments[j].attachment == VK_ATTACHMENT_UNUSED)
270            continue;
271
272         for (uint32_t k = 0; k < subpass->color_count; ++k) {
273            if (subpass->color_attachments[k].attachment ==
274                subpass->input_attachments[j].attachment) {
275               subpass->input_attachments[j].in_render_loop = true;
276               subpass->color_attachments[k].in_render_loop = true;
277            }
278         }
279
280         if (subpass->depth_stencil_attachment && subpass->depth_stencil_attachment->attachment ==
281                                                     subpass->input_attachments[j].attachment) {
282            subpass->input_attachments[j].in_render_loop = true;
283            subpass->depth_stencil_attachment->in_render_loop = true;
284         }
285      }
286   }
287}
288
289static void
290radv_destroy_render_pass(struct radv_device *device, const VkAllocationCallbacks *pAllocator,
291                         struct radv_render_pass *pass)
292{
293   vk_object_base_finish(&pass->base);
294   vk_free2(&device->vk.alloc, pAllocator, pass->subpass_attachments);
295   vk_free2(&device->vk.alloc, pAllocator, pass);
296}
297
298static unsigned
299radv_num_subpass_attachments2(const VkSubpassDescription2 *desc)
300{
301   const VkSubpassDescriptionDepthStencilResolve *ds_resolve =
302      vk_find_struct_const(desc->pNext, SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE);
303   const VkFragmentShadingRateAttachmentInfoKHR *vrs =
304      vk_find_struct_const(desc->pNext, FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR);
305
306   return desc->inputAttachmentCount + desc->colorAttachmentCount +
307          (desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
308          (desc->pDepthStencilAttachment != NULL) +
309          (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) +
310          (vrs && vrs->pFragmentShadingRateAttachment);
311}
312
313static bool
314vk_image_layout_depth_only(VkImageLayout layout)
315{
316   switch (layout) {
317   case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL:
318   case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL:
319      return true;
320   default:
321      return false;
322   }
323}
324
325/* From the Vulkan Specification 1.2.166 - VkAttachmentReference2:
326 *
327 * "If layout only specifies the layout of the depth aspect of the attachment,
328 *  the layout of the stencil aspect is specified by the stencilLayout member
329 *  of a VkAttachmentReferenceStencilLayout structure included in the pNext
330 *  chain. Otherwise, layout describes the layout for all relevant image
331 *  aspects."
332 */
333static VkImageLayout
334stencil_ref_layout(const VkAttachmentReference2 *att_ref)
335{
336   if (!vk_image_layout_depth_only(att_ref->layout))
337      return att_ref->layout;
338
339   const VkAttachmentReferenceStencilLayoutKHR *stencil_ref =
340      vk_find_struct_const(att_ref->pNext, ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
341   if (!stencil_ref)
342      return VK_IMAGE_LAYOUT_UNDEFINED;
343
344   return stencil_ref->stencilLayout;
345}
346
347/* From the Vulkan Specification 1.2.184:
348 *
349 * "If the pNext chain includes a VkAttachmentDescriptionStencilLayout structure, then the
350 *  stencilInitialLayout and stencilFinalLayout members specify the initial and final layouts of the
351 *  stencil aspect of a depth/stencil format, and initialLayout and finalLayout only apply to the
352 *  depth aspect. For depth-only formats, the VkAttachmentDescriptionStencilLayout structure is
353 *  ignored. For stencil-only formats, the initial and final layouts of the stencil aspect are taken
354 *  from the VkAttachmentDescriptionStencilLayout structure if present, or initialLayout and
355 *  finalLayout if not present."
356 *
357 * "If format is a depth/stencil format, and either initialLayout or finalLayout does not specify a
358 *  layout for the stencil aspect, then the application must specify the initial and final layouts
359 *  of the stencil aspect by including a VkAttachmentDescriptionStencilLayout structure in the pNext
360 *  chain."
361 */
362static VkImageLayout
363stencil_desc_layout(const VkAttachmentDescription2KHR *att_desc, bool final)
364{
365   const struct util_format_description *desc = vk_format_description(att_desc->format);
366   if (!util_format_has_stencil(desc))
367      return VK_IMAGE_LAYOUT_UNDEFINED;
368
369   const VkAttachmentDescriptionStencilLayoutKHR *stencil_desc =
370      vk_find_struct_const(att_desc->pNext, ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR);
371
372   if (stencil_desc)
373      return final ? stencil_desc->stencilFinalLayout : stencil_desc->stencilInitialLayout;
374   return final ? att_desc->finalLayout : att_desc->initialLayout;
375}
376
377VkResult
378radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateInfo,
379                       const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass)
380{
381   RADV_FROM_HANDLE(radv_device, device, _device);
382   struct radv_render_pass *pass;
383   size_t size;
384   size_t attachments_offset;
385
386   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2);
387
388   size = sizeof(*pass);
389   size += pCreateInfo->subpassCount * sizeof(pass->subpasses[0]);
390   attachments_offset = size;
391   size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]);
392
393   pass = vk_alloc2(&device->vk.alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
394   if (pass == NULL)
395      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
396
397   memset(pass, 0, size);
398
399   vk_object_base_init(&device->vk, &pass->base, VK_OBJECT_TYPE_RENDER_PASS);
400
401   pass->attachment_count = pCreateInfo->attachmentCount;
402   pass->subpass_count = pCreateInfo->subpassCount;
403   pass->attachments = (struct radv_render_pass_attachment *)((uint8_t *)pass + attachments_offset);
404
405   for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
406      struct radv_render_pass_attachment *att = &pass->attachments[i];
407
408      att->format = pCreateInfo->pAttachments[i].format;
409      att->samples = pCreateInfo->pAttachments[i].samples;
410      att->load_op = pCreateInfo->pAttachments[i].loadOp;
411      att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
412      att->initial_layout = pCreateInfo->pAttachments[i].initialLayout;
413      att->final_layout = pCreateInfo->pAttachments[i].finalLayout;
414      att->stencil_initial_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i], false);
415      att->stencil_final_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i], true);
416      // att->store_op = pCreateInfo->pAttachments[i].storeOp;
417      // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
418   }
419   uint32_t subpass_attachment_count = 0;
420   struct radv_subpass_attachment *p;
421   for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
422      subpass_attachment_count += radv_num_subpass_attachments2(&pCreateInfo->pSubpasses[i]);
423   }
424
425   if (subpass_attachment_count) {
426      pass->subpass_attachments =
427         vk_alloc2(&device->vk.alloc, pAllocator,
428                   subpass_attachment_count * sizeof(struct radv_subpass_attachment), 8,
429                   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
430      if (pass->subpass_attachments == NULL) {
431         radv_destroy_render_pass(device, pAllocator, pass);
432         return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
433      }
434   } else
435      pass->subpass_attachments = NULL;
436
437   p = pass->subpass_attachments;
438   for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
439      const VkSubpassDescription2 *desc = &pCreateInfo->pSubpasses[i];
440      struct radv_subpass *subpass = &pass->subpasses[i];
441
442      subpass->input_count = desc->inputAttachmentCount;
443      subpass->color_count = desc->colorAttachmentCount;
444      subpass->attachment_count = radv_num_subpass_attachments2(desc);
445      subpass->attachments = p;
446      subpass->view_mask = desc->viewMask;
447
448      if (desc->inputAttachmentCount > 0) {
449         subpass->input_attachments = p;
450         p += desc->inputAttachmentCount;
451
452         for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
453            subpass->input_attachments[j] = (struct radv_subpass_attachment){
454               .attachment = desc->pInputAttachments[j].attachment,
455               .layout = desc->pInputAttachments[j].layout,
456               .stencil_layout = stencil_ref_layout(&desc->pInputAttachments[j]),
457            };
458         }
459      }
460
461      if (desc->colorAttachmentCount > 0) {
462         subpass->color_attachments = p;
463         p += desc->colorAttachmentCount;
464
465         for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
466            subpass->color_attachments[j] = (struct radv_subpass_attachment){
467               .attachment = desc->pColorAttachments[j].attachment,
468               .layout = desc->pColorAttachments[j].layout,
469            };
470         }
471      }
472
473      if (desc->pResolveAttachments) {
474         subpass->resolve_attachments = p;
475         p += desc->colorAttachmentCount;
476
477         for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
478            subpass->resolve_attachments[j] = (struct radv_subpass_attachment){
479               .attachment = desc->pResolveAttachments[j].attachment,
480               .layout = desc->pResolveAttachments[j].layout,
481            };
482         }
483      }
484
485      if (desc->pDepthStencilAttachment) {
486         subpass->depth_stencil_attachment = p++;
487
488         *subpass->depth_stencil_attachment = (struct radv_subpass_attachment){
489            .attachment = desc->pDepthStencilAttachment->attachment,
490            .layout = desc->pDepthStencilAttachment->layout,
491            .stencil_layout = stencil_ref_layout(desc->pDepthStencilAttachment),
492         };
493      }
494
495      const VkSubpassDescriptionDepthStencilResolve *ds_resolve =
496         vk_find_struct_const(desc->pNext, SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE);
497
498      if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) {
499         subpass->ds_resolve_attachment = p++;
500
501         *subpass->ds_resolve_attachment = (struct radv_subpass_attachment){
502            .attachment = ds_resolve->pDepthStencilResolveAttachment->attachment,
503            .layout = ds_resolve->pDepthStencilResolveAttachment->layout,
504            .stencil_layout = stencil_ref_layout(ds_resolve->pDepthStencilResolveAttachment),
505         };
506
507         subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
508         subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode;
509      }
510
511      const VkFragmentShadingRateAttachmentInfoKHR *vrs =
512         vk_find_struct_const(desc->pNext, FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR);
513
514      if (vrs && vrs->pFragmentShadingRateAttachment) {
515         subpass->vrs_attachment = p++;
516
517         *subpass->vrs_attachment = (struct radv_subpass_attachment){
518            .attachment = vrs->pFragmentShadingRateAttachment->attachment,
519            .layout = vrs->pFragmentShadingRateAttachment->layout,
520         };
521      }
522   }
523
524   for (unsigned i = 0; i < pCreateInfo->dependencyCount; ++i) {
525      const VkSubpassDependency2 *dep = &pCreateInfo->pDependencies[i];
526
527      radv_render_pass_add_subpass_dep(pass, &pCreateInfo->pDependencies[i]);
528
529      /* Determine if the subpass has explicit dependencies from/to
530       * VK_SUBPASS_EXTERNAL.
531       */
532      if (dep->srcSubpass == VK_SUBPASS_EXTERNAL && dep->dstSubpass != VK_SUBPASS_EXTERNAL) {
533         pass->subpasses[dep->dstSubpass].has_ingoing_dep = true;
534      }
535
536      if (dep->dstSubpass == VK_SUBPASS_EXTERNAL && dep->srcSubpass != VK_SUBPASS_EXTERNAL) {
537         pass->subpasses[dep->srcSubpass].has_outgoing_dep = true;
538      }
539   }
540
541   radv_render_pass_compile(pass);
542
543   radv_render_pass_add_implicit_deps(pass);
544
545   *pRenderPass = radv_render_pass_to_handle(pass);
546
547   return VK_SUCCESS;
548}
549
550void
551radv_DestroyRenderPass(VkDevice _device, VkRenderPass _pass,
552                       const VkAllocationCallbacks *pAllocator)
553{
554   RADV_FROM_HANDLE(radv_device, device, _device);
555   RADV_FROM_HANDLE(radv_render_pass, pass, _pass);
556
557   if (!_pass)
558      return;
559
560   radv_destroy_render_pass(device, pAllocator, pass);
561}
562
563void
564radv_GetRenderAreaGranularity(VkDevice device, VkRenderPass renderPass, VkExtent2D *pGranularity)
565{
566   pGranularity->width = 1;
567   pGranularity->height = 1;
568}
569