2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "anv_private.h"
29 anv_render_pass_add_subpass_dep(struct anv_render_pass
*pass
,
30 const VkSubpassDependency2KHR
*dep
)
32 if (dep
->dstSubpass
== VK_SUBPASS_EXTERNAL
) {
33 pass
->subpass_flushes
[pass
->subpass_count
] |=
34 anv_pipe_invalidate_bits_for_access_flags(dep
->dstAccessMask
);
36 assert(dep
->dstSubpass
< pass
->subpass_count
);
37 pass
->subpass_flushes
[dep
->dstSubpass
] |=
38 anv_pipe_invalidate_bits_for_access_flags(dep
->dstAccessMask
);
41 if (dep
->srcSubpass
== VK_SUBPASS_EXTERNAL
) {
42 pass
->subpass_flushes
[0] |=
43 anv_pipe_flush_bits_for_access_flags(dep
->srcAccessMask
);
45 assert(dep
->srcSubpass
< pass
->subpass_count
);
46 pass
->subpass_flushes
[dep
->srcSubpass
+ 1] |=
47 anv_pipe_flush_bits_for_access_flags(dep
->srcAccessMask
);
51 /* Do a second "compile" step on a render pass */
53 anv_render_pass_compile(struct anv_render_pass
*pass
)
55 /* The CreateRenderPass code zeros the entire render pass and also uses a
56 * designated initializer for filling these out. There's no need for us to
59 * for (uint32_t i = 0; i < pass->attachment_count; i++) {
60 * pass->attachments[i].usage = 0;
61 * pass->attachments[i].first_subpass_layout = VK_IMAGE_LAYOUT_UNDEFINED;
65 VkImageUsageFlags all_usage
= 0;
66 for (uint32_t i
= 0; i
< pass
->subpass_count
; i
++) {
67 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
69 /* We don't allow depth_stencil_attachment to be non-NULL and be
70 * VK_ATTACHMENT_UNUSED. This way something can just check for NULL
71 * and be guaranteed that they have a valid attachment.
73 if (subpass
->depth_stencil_attachment
&&
74 subpass
->depth_stencil_attachment
->attachment
== VK_ATTACHMENT_UNUSED
)
75 subpass
->depth_stencil_attachment
= NULL
;
77 if (subpass
->ds_resolve_attachment
&&
78 subpass
->ds_resolve_attachment
->attachment
== VK_ATTACHMENT_UNUSED
)
79 subpass
->ds_resolve_attachment
= NULL
;
81 for (uint32_t j
= 0; j
< subpass
->attachment_count
; j
++) {
82 struct anv_subpass_attachment
*subpass_att
= &subpass
->attachments
[j
];
83 if (subpass_att
->attachment
== VK_ATTACHMENT_UNUSED
)
86 struct anv_render_pass_attachment
*pass_att
=
87 &pass
->attachments
[subpass_att
->attachment
];
89 pass_att
->usage
|= subpass_att
->usage
;
90 pass_att
->last_subpass_idx
= i
;
92 all_usage
|= subpass_att
->usage
;
94 if (pass_att
->first_subpass_layout
== VK_IMAGE_LAYOUT_UNDEFINED
) {
95 pass_att
->first_subpass_layout
= subpass_att
->layout
;
96 assert(pass_att
->first_subpass_layout
!= VK_IMAGE_LAYOUT_UNDEFINED
);
99 if (subpass_att
->usage
== VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
&&
100 subpass
->depth_stencil_attachment
&&
101 subpass_att
->attachment
== subpass
->depth_stencil_attachment
->attachment
)
102 subpass
->has_ds_self_dep
= true;
105 /* We have to handle resolve attachments specially */
106 subpass
->has_color_resolve
= false;
107 if (subpass
->resolve_attachments
) {
108 for (uint32_t j
= 0; j
< subpass
->color_count
; j
++) {
109 struct anv_subpass_attachment
*color_att
=
110 &subpass
->color_attachments
[j
];
111 struct anv_subpass_attachment
*resolve_att
=
112 &subpass
->resolve_attachments
[j
];
113 if (resolve_att
->attachment
== VK_ATTACHMENT_UNUSED
)
116 subpass
->has_color_resolve
= true;
118 assert(color_att
->attachment
< pass
->attachment_count
);
119 struct anv_render_pass_attachment
*color_pass_att
=
120 &pass
->attachments
[color_att
->attachment
];
122 assert(resolve_att
->usage
== VK_IMAGE_USAGE_TRANSFER_DST_BIT
);
123 assert(color_att
->usage
== VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
);
124 color_pass_att
->usage
|= VK_IMAGE_USAGE_TRANSFER_SRC_BIT
;
128 if (subpass
->ds_resolve_attachment
) {
129 struct anv_subpass_attachment
*ds_att
=
130 subpass
->depth_stencil_attachment
;
131 UNUSED
struct anv_subpass_attachment
*resolve_att
=
132 subpass
->ds_resolve_attachment
;
134 assert(ds_att
->attachment
< pass
->attachment_count
);
135 struct anv_render_pass_attachment
*ds_pass_att
=
136 &pass
->attachments
[ds_att
->attachment
];
138 assert(resolve_att
->usage
== VK_IMAGE_USAGE_TRANSFER_DST_BIT
);
139 assert(ds_att
->usage
== VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
);
140 ds_pass_att
->usage
|= VK_IMAGE_USAGE_TRANSFER_SRC_BIT
;
143 for (uint32_t j
= 0; j
< subpass
->attachment_count
; j
++)
144 assert(__builtin_popcount(subpass
->attachments
[j
].usage
) == 1);
147 /* From the Vulkan 1.0.39 spec:
149 * If there is no subpass dependency from VK_SUBPASS_EXTERNAL to the
150 * first subpass that uses an attachment, then an implicit subpass
151 * dependency exists from VK_SUBPASS_EXTERNAL to the first subpass it is
152 * used in. The subpass dependency operates as if defined with the
153 * following parameters:
155 * VkSubpassDependency implicitDependency = {
156 * .srcSubpass = VK_SUBPASS_EXTERNAL;
157 * .dstSubpass = firstSubpass; // First subpass attachment is used in
158 * .srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
159 * .dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
160 * .srcAccessMask = 0;
161 * .dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
162 * VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
163 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
164 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
165 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
166 * .dependencyFlags = 0;
169 * Similarly, if there is no subpass dependency from the last subpass
170 * that uses an attachment to VK_SUBPASS_EXTERNAL, then an implicit
171 * subpass dependency exists from the last subpass it is used in to
172 * VK_SUBPASS_EXTERNAL. The subpass dependency operates as if defined
173 * with the following parameters:
175 * VkSubpassDependency implicitDependency = {
176 * .srcSubpass = lastSubpass; // Last subpass attachment is used in
177 * .dstSubpass = VK_SUBPASS_EXTERNAL;
178 * .srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
179 * .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
180 * .srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
181 * VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
182 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
183 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
184 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
185 * .dstAccessMask = 0;
186 * .dependencyFlags = 0;
189 * We could implement this by walking over all of the attachments and
190 * subpasses and checking to see if any of them don't have an external
191 * dependency. Or, we could just be lazy and add a couple extra flushes.
192 * We choose to be lazy.
194 * From the documentation for vkCmdNextSubpass:
196 * "Moving to the next subpass automatically performs any multisample
197 * resolve operations in the subpass being ended. End-of-subpass
198 * multisample resolves are treated as color attachment writes for the
199 * purposes of synchronization. This applies to resolve operations for
200 * both color and depth/stencil attachments. That is, they are
201 * considered to execute in the
202 * VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage and
203 * their writes are synchronized with
204 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT."
206 * Therefore, the above flags concerning color attachments also apply to
207 * color and depth/stencil resolve attachments.
209 if (all_usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
210 pass
->subpass_flushes
[0] |=
211 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
213 if (all_usage
& (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
214 VK_IMAGE_USAGE_TRANSFER_DST_BIT
)) {
215 pass
->subpass_flushes
[pass
->subpass_count
] |=
216 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
218 if (all_usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
219 pass
->subpass_flushes
[pass
->subpass_count
] |=
220 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
225 num_subpass_attachments(const VkSubpassDescription
*desc
)
227 return desc
->inputAttachmentCount
+
228 desc
->colorAttachmentCount
+
229 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
230 (desc
->pDepthStencilAttachment
!= NULL
);
233 VkResult
anv_CreateRenderPass(
235 const VkRenderPassCreateInfo
* pCreateInfo
,
236 const VkAllocationCallbacks
* pAllocator
,
237 VkRenderPass
* pRenderPass
)
239 ANV_FROM_HANDLE(anv_device
, device
, _device
);
241 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
243 struct anv_render_pass
*pass
;
244 struct anv_subpass
*subpasses
;
245 struct anv_render_pass_attachment
*attachments
;
246 enum anv_pipe_bits
*subpass_flushes
;
249 anv_multialloc_add(&ma
, &pass
, 1);
250 anv_multialloc_add(&ma
, &subpasses
, pCreateInfo
->subpassCount
);
251 anv_multialloc_add(&ma
, &attachments
, pCreateInfo
->attachmentCount
);
252 anv_multialloc_add(&ma
, &subpass_flushes
, pCreateInfo
->subpassCount
+ 1);
254 struct anv_subpass_attachment
*subpass_attachments
;
255 uint32_t subpass_attachment_count
= 0;
256 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
257 subpass_attachment_count
+=
258 num_subpass_attachments(&pCreateInfo
->pSubpasses
[i
]);
260 anv_multialloc_add(&ma
, &subpass_attachments
, subpass_attachment_count
);
262 if (!anv_multialloc_alloc2(&ma
, &device
->alloc
, pAllocator
,
263 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
))
264 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
266 /* Clear the subpasses along with the parent pass. This required because
267 * each array member of anv_subpass must be a valid pointer if not NULL.
269 memset(pass
, 0, ma
.size
);
270 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
271 pass
->subpass_count
= pCreateInfo
->subpassCount
;
272 pass
->attachments
= attachments
;
273 pass
->subpass_flushes
= subpass_flushes
;
275 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
276 pass
->attachments
[i
] = (struct anv_render_pass_attachment
) {
277 .format
= pCreateInfo
->pAttachments
[i
].format
,
278 .samples
= pCreateInfo
->pAttachments
[i
].samples
,
279 .load_op
= pCreateInfo
->pAttachments
[i
].loadOp
,
280 .store_op
= pCreateInfo
->pAttachments
[i
].storeOp
,
281 .stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
,
282 .initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
,
283 .final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
,
285 .stencil_initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
,
286 .stencil_final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
,
290 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
291 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
292 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
294 subpass
->input_count
= desc
->inputAttachmentCount
;
295 subpass
->color_count
= desc
->colorAttachmentCount
;
296 subpass
->attachment_count
= num_subpass_attachments(desc
);
297 subpass
->attachments
= subpass_attachments
;
298 subpass
->view_mask
= 0;
300 if (desc
->inputAttachmentCount
> 0) {
301 subpass
->input_attachments
= subpass_attachments
;
302 subpass_attachments
+= desc
->inputAttachmentCount
;
304 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
305 subpass
->input_attachments
[j
] = (struct anv_subpass_attachment
) {
306 .usage
= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
,
307 .attachment
= desc
->pInputAttachments
[j
].attachment
,
308 .layout
= desc
->pInputAttachments
[j
].layout
,
309 .stencil_layout
= desc
->pInputAttachments
[j
].layout
,
314 if (desc
->colorAttachmentCount
> 0) {
315 subpass
->color_attachments
= subpass_attachments
;
316 subpass_attachments
+= desc
->colorAttachmentCount
;
318 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
319 subpass
->color_attachments
[j
] = (struct anv_subpass_attachment
) {
320 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
321 .attachment
= desc
->pColorAttachments
[j
].attachment
,
322 .layout
= desc
->pColorAttachments
[j
].layout
,
327 if (desc
->pResolveAttachments
) {
328 subpass
->resolve_attachments
= subpass_attachments
;
329 subpass_attachments
+= desc
->colorAttachmentCount
;
331 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
332 subpass
->resolve_attachments
[j
] = (struct anv_subpass_attachment
) {
333 .usage
= VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
334 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
335 .layout
= desc
->pResolveAttachments
[j
].layout
,
340 if (desc
->pDepthStencilAttachment
) {
341 subpass
->depth_stencil_attachment
= subpass_attachments
++;
343 *subpass
->depth_stencil_attachment
= (struct anv_subpass_attachment
) {
344 .usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
,
345 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
346 .layout
= desc
->pDepthStencilAttachment
->layout
,
347 .stencil_layout
= desc
->pDepthStencilAttachment
->layout
,
352 for (uint32_t i
= 0; i
< pCreateInfo
->dependencyCount
; i
++) {
353 /* Convert to a Dependency2KHR */
354 VkSubpassDependency2 dep2
= {
355 .srcSubpass
= pCreateInfo
->pDependencies
[i
].srcSubpass
,
356 .dstSubpass
= pCreateInfo
->pDependencies
[i
].dstSubpass
,
357 .srcStageMask
= pCreateInfo
->pDependencies
[i
].srcStageMask
,
358 .dstStageMask
= pCreateInfo
->pDependencies
[i
].dstStageMask
,
359 .srcAccessMask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
,
360 .dstAccessMask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
,
361 .dependencyFlags
= pCreateInfo
->pDependencies
[i
].dependencyFlags
,
363 anv_render_pass_add_subpass_dep(pass
, &dep2
);
366 vk_foreach_struct(ext
, pCreateInfo
->pNext
) {
367 switch (ext
->sType
) {
368 case VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO
:
369 /* We don't care about this information */
372 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO
: {
373 VkRenderPassMultiviewCreateInfo
*mv
= (void *)ext
;
375 for (uint32_t i
= 0; i
< mv
->subpassCount
; i
++) {
376 pass
->subpasses
[i
].view_mask
= mv
->pViewMasks
[i
];
382 anv_debug_ignored_stype(ext
->sType
);
386 anv_render_pass_compile(pass
);
388 *pRenderPass
= anv_render_pass_to_handle(pass
);
394 num_subpass_attachments2(const VkSubpassDescription2KHR
*desc
)
396 const VkSubpassDescriptionDepthStencilResolveKHR
*ds_resolve
=
397 vk_find_struct_const(desc
->pNext
,
398 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR
);
400 return desc
->inputAttachmentCount
+
401 desc
->colorAttachmentCount
+
402 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
403 (desc
->pDepthStencilAttachment
!= NULL
) +
404 (ds_resolve
&& ds_resolve
->pDepthStencilResolveAttachment
);
407 VkResult
anv_CreateRenderPass2(
409 const VkRenderPassCreateInfo2KHR
* pCreateInfo
,
410 const VkAllocationCallbacks
* pAllocator
,
411 VkRenderPass
* pRenderPass
)
413 ANV_FROM_HANDLE(anv_device
, device
, _device
);
415 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR
);
417 struct anv_render_pass
*pass
;
418 struct anv_subpass
*subpasses
;
419 struct anv_render_pass_attachment
*attachments
;
420 enum anv_pipe_bits
*subpass_flushes
;
423 anv_multialloc_add(&ma
, &pass
, 1);
424 anv_multialloc_add(&ma
, &subpasses
, pCreateInfo
->subpassCount
);
425 anv_multialloc_add(&ma
, &attachments
, pCreateInfo
->attachmentCount
);
426 anv_multialloc_add(&ma
, &subpass_flushes
, pCreateInfo
->subpassCount
+ 1);
428 struct anv_subpass_attachment
*subpass_attachments
;
429 uint32_t subpass_attachment_count
= 0;
430 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
431 subpass_attachment_count
+=
432 num_subpass_attachments2(&pCreateInfo
->pSubpasses
[i
]);
434 anv_multialloc_add(&ma
, &subpass_attachments
, subpass_attachment_count
);
436 if (!anv_multialloc_alloc2(&ma
, &device
->alloc
, pAllocator
,
437 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
))
438 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
440 /* Clear the subpasses along with the parent pass. This required because
441 * each array member of anv_subpass must be a valid pointer if not NULL.
443 memset(pass
, 0, ma
.size
);
444 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
445 pass
->subpass_count
= pCreateInfo
->subpassCount
;
446 pass
->attachments
= attachments
;
447 pass
->subpass_flushes
= subpass_flushes
;
449 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
450 const VkAttachmentDescriptionStencilLayoutKHR
*stencil_layout
=
451 vk_find_struct_const(pCreateInfo
->pAttachments
[i
].pNext
,
452 ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR
);
454 pass
->attachments
[i
] = (struct anv_render_pass_attachment
) {
455 .format
= pCreateInfo
->pAttachments
[i
].format
,
456 .samples
= pCreateInfo
->pAttachments
[i
].samples
,
457 .load_op
= pCreateInfo
->pAttachments
[i
].loadOp
,
458 .store_op
= pCreateInfo
->pAttachments
[i
].storeOp
,
459 .stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
,
460 .initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
,
461 .final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
,
463 .stencil_initial_layout
= (stencil_layout
?
464 stencil_layout
->stencilInitialLayout
:
465 pCreateInfo
->pAttachments
[i
].initialLayout
),
466 .stencil_final_layout
= (stencil_layout
?
467 stencil_layout
->stencilFinalLayout
:
468 pCreateInfo
->pAttachments
[i
].finalLayout
),
472 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
473 const VkSubpassDescription2KHR
*desc
= &pCreateInfo
->pSubpasses
[i
];
474 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
476 subpass
->input_count
= desc
->inputAttachmentCount
;
477 subpass
->color_count
= desc
->colorAttachmentCount
;
478 subpass
->attachment_count
= num_subpass_attachments2(desc
);
479 subpass
->attachments
= subpass_attachments
;
480 subpass
->view_mask
= desc
->viewMask
;
482 if (desc
->inputAttachmentCount
> 0) {
483 subpass
->input_attachments
= subpass_attachments
;
484 subpass_attachments
+= desc
->inputAttachmentCount
;
486 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
487 const VkAttachmentReferenceStencilLayoutKHR
*stencil_layout
=
488 vk_find_struct_const(desc
->pInputAttachments
[j
].pNext
,
489 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
491 subpass
->input_attachments
[j
] = (struct anv_subpass_attachment
) {
492 .usage
= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
,
493 .attachment
= desc
->pInputAttachments
[j
].attachment
,
494 .layout
= desc
->pInputAttachments
[j
].layout
,
495 .stencil_layout
= (stencil_layout
?
496 stencil_layout
->stencilLayout
:
497 desc
->pInputAttachments
[j
].layout
),
502 if (desc
->colorAttachmentCount
> 0) {
503 subpass
->color_attachments
= subpass_attachments
;
504 subpass_attachments
+= desc
->colorAttachmentCount
;
506 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
507 subpass
->color_attachments
[j
] = (struct anv_subpass_attachment
) {
508 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
509 .attachment
= desc
->pColorAttachments
[j
].attachment
,
510 .layout
= desc
->pColorAttachments
[j
].layout
,
515 if (desc
->pResolveAttachments
) {
516 subpass
->resolve_attachments
= subpass_attachments
;
517 subpass_attachments
+= desc
->colorAttachmentCount
;
519 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
520 subpass
->resolve_attachments
[j
] = (struct anv_subpass_attachment
) {
521 .usage
= VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
522 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
523 .layout
= desc
->pResolveAttachments
[j
].layout
,
528 if (desc
->pDepthStencilAttachment
) {
529 subpass
->depth_stencil_attachment
= subpass_attachments
++;
531 const VkAttachmentReferenceStencilLayoutKHR
*stencil_attachment
=
532 vk_find_struct_const(desc
->pDepthStencilAttachment
->pNext
,
533 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
535 *subpass
->depth_stencil_attachment
= (struct anv_subpass_attachment
) {
536 .usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
,
537 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
538 .layout
= desc
->pDepthStencilAttachment
->layout
,
539 .stencil_layout
= stencil_attachment
?
540 stencil_attachment
->stencilLayout
:
541 desc
->pDepthStencilAttachment
->layout
,
545 const VkSubpassDescriptionDepthStencilResolveKHR
*ds_resolve
=
546 vk_find_struct_const(desc
->pNext
,
547 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR
);
549 if (ds_resolve
&& ds_resolve
->pDepthStencilResolveAttachment
) {
550 subpass
->ds_resolve_attachment
= subpass_attachments
++;
552 const VkAttachmentReferenceStencilLayoutKHR
*stencil_resolve_attachment
=
553 vk_find_struct_const(ds_resolve
->pDepthStencilResolveAttachment
->pNext
,
554 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
556 *subpass
->ds_resolve_attachment
= (struct anv_subpass_attachment
) {
557 .usage
= VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
558 .attachment
= ds_resolve
->pDepthStencilResolveAttachment
->attachment
,
559 .layout
= ds_resolve
->pDepthStencilResolveAttachment
->layout
,
560 .stencil_layout
= stencil_resolve_attachment
?
561 stencil_resolve_attachment
->stencilLayout
:
562 ds_resolve
->pDepthStencilResolveAttachment
->layout
,
564 subpass
->depth_resolve_mode
= ds_resolve
->depthResolveMode
;
565 subpass
->stencil_resolve_mode
= ds_resolve
->stencilResolveMode
;
569 for (uint32_t i
= 0; i
< pCreateInfo
->dependencyCount
; i
++)
570 anv_render_pass_add_subpass_dep(pass
, &pCreateInfo
->pDependencies
[i
]);
572 vk_foreach_struct(ext
, pCreateInfo
->pNext
) {
573 switch (ext
->sType
) {
575 anv_debug_ignored_stype(ext
->sType
);
579 anv_render_pass_compile(pass
);
581 *pRenderPass
= anv_render_pass_to_handle(pass
);
586 void anv_DestroyRenderPass(
589 const VkAllocationCallbacks
* pAllocator
)
591 ANV_FROM_HANDLE(anv_device
, device
, _device
);
592 ANV_FROM_HANDLE(anv_render_pass
, pass
, _pass
);
594 vk_free2(&device
->alloc
, pAllocator
, pass
);
597 void anv_GetRenderAreaGranularity(
599 VkRenderPass renderPass
,
600 VkExtent2D
* pGranularity
)
602 ANV_FROM_HANDLE(anv_render_pass
, pass
, renderPass
);
604 /* This granularity satisfies HiZ fast clear alignment requirements
605 * for all sample counts.
607 for (unsigned i
= 0; i
< pass
->subpass_count
; ++i
) {
608 if (pass
->subpasses
[i
].depth_stencil_attachment
) {
609 *pGranularity
= (VkExtent2D
) { .width
= 8, .height
= 4 };
614 *pGranularity
= (VkExtent2D
) { 1, 1 };