ec32e0ca3bd035118aaa3cde6c709f6ae27afd98
[mesa.git] / src / intel / vulkan / anv_pass.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include "anv_private.h"
25
26 #include "vk_util.h"
27
28 static void
29 anv_render_pass_add_subpass_dep(struct anv_render_pass *pass,
30 const VkSubpassDependency2KHR *dep)
31 {
32 if (dep->dstSubpass == VK_SUBPASS_EXTERNAL) {
33 pass->subpass_flushes[pass->subpass_count] |=
34 anv_pipe_invalidate_bits_for_access_flags(dep->dstAccessMask);
35 } else {
36 assert(dep->dstSubpass < pass->subpass_count);
37 pass->subpass_flushes[dep->dstSubpass] |=
38 anv_pipe_invalidate_bits_for_access_flags(dep->dstAccessMask);
39 }
40
41 if (dep->srcSubpass == VK_SUBPASS_EXTERNAL) {
42 pass->subpass_flushes[0] |=
43 anv_pipe_flush_bits_for_access_flags(dep->srcAccessMask);
44 } else {
45 assert(dep->srcSubpass < pass->subpass_count);
46 pass->subpass_flushes[dep->srcSubpass + 1] |=
47 anv_pipe_flush_bits_for_access_flags(dep->srcAccessMask);
48 }
49 }
50
51 /* Do a second "compile" step on a render pass */
52 static void
53 anv_render_pass_compile(struct anv_render_pass *pass)
54 {
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
57 * do it again.
58 *
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;
62 * }
63 */
64
65 VkImageUsageFlags all_usage = 0;
66 for (uint32_t i = 0; i < pass->subpass_count; i++) {
67 struct anv_subpass *subpass = &pass->subpasses[i];
68
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.
72 */
73 if (subpass->depth_stencil_attachment &&
74 subpass->depth_stencil_attachment->attachment == VK_ATTACHMENT_UNUSED)
75 subpass->depth_stencil_attachment = NULL;
76
77 if (subpass->ds_resolve_attachment &&
78 subpass->ds_resolve_attachment->attachment == VK_ATTACHMENT_UNUSED)
79 subpass->ds_resolve_attachment = NULL;
80
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)
84 continue;
85
86 struct anv_render_pass_attachment *pass_att =
87 &pass->attachments[subpass_att->attachment];
88
89 pass_att->usage |= subpass_att->usage;
90 pass_att->last_subpass_idx = i;
91
92 all_usage |= subpass_att->usage;
93
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);
97 }
98
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;
103 }
104
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)
114 continue;
115
116 subpass->has_color_resolve = true;
117
118 assert(color_att->attachment < pass->attachment_count);
119 struct anv_render_pass_attachment *color_pass_att =
120 &pass->attachments[color_att->attachment];
121
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;
125 }
126 }
127
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;
133
134 assert(ds_att->attachment < pass->attachment_count);
135 struct anv_render_pass_attachment *ds_pass_att =
136 &pass->attachments[ds_att->attachment];
137
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;
141 }
142
143 for (uint32_t j = 0; j < subpass->attachment_count; j++)
144 assert(__builtin_popcount(subpass->attachments[j].usage) == 1);
145 }
146
147 /* From the Vulkan 1.0.39 spec:
148 *
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:
154 *
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;
167 * };
168 *
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:
174 *
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;
187 * };
188 *
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.
193 *
194 * From the documentation for vkCmdNextSubpass:
195 *
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."
205 *
206 * Therefore, the above flags concerning color attachments also apply to
207 * color and depth/stencil resolve attachments.
208 */
209 if (all_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
210 pass->subpass_flushes[0] |=
211 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
212 }
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;
217 }
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;
221 }
222 }
223
224 static unsigned
225 num_subpass_attachments(const VkSubpassDescription *desc)
226 {
227 return desc->inputAttachmentCount +
228 desc->colorAttachmentCount +
229 (desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
230 (desc->pDepthStencilAttachment != NULL);
231 }
232
233 VkResult anv_CreateRenderPass(
234 VkDevice _device,
235 const VkRenderPassCreateInfo* pCreateInfo,
236 const VkAllocationCallbacks* pAllocator,
237 VkRenderPass* pRenderPass)
238 {
239 ANV_FROM_HANDLE(anv_device, device, _device);
240
241 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
242
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;
247
248 ANV_MULTIALLOC(ma);
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);
253
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]);
259 }
260 anv_multialloc_add(&ma, &subpass_attachments, subpass_attachment_count);
261
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);
265
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.
268 */
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;
274
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,
284
285 .stencil_initial_layout = pCreateInfo->pAttachments[i].initialLayout,
286 .stencil_final_layout = pCreateInfo->pAttachments[i].finalLayout,
287 };
288 }
289
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];
293
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;
299
300 if (desc->inputAttachmentCount > 0) {
301 subpass->input_attachments = subpass_attachments;
302 subpass_attachments += desc->inputAttachmentCount;
303
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,
310 };
311 }
312 }
313
314 if (desc->colorAttachmentCount > 0) {
315 subpass->color_attachments = subpass_attachments;
316 subpass_attachments += desc->colorAttachmentCount;
317
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,
323 };
324 }
325 }
326
327 if (desc->pResolveAttachments) {
328 subpass->resolve_attachments = subpass_attachments;
329 subpass_attachments += desc->colorAttachmentCount;
330
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,
336 };
337 }
338 }
339
340 if (desc->pDepthStencilAttachment) {
341 subpass->depth_stencil_attachment = subpass_attachments++;
342
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,
348 };
349 }
350 }
351
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,
362 };
363 anv_render_pass_add_subpass_dep(pass, &dep2);
364 }
365
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 */
370 break;
371
372 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO: {
373 VkRenderPassMultiviewCreateInfo *mv = (void *)ext;
374
375 for (uint32_t i = 0; i < mv->subpassCount; i++) {
376 pass->subpasses[i].view_mask = mv->pViewMasks[i];
377 }
378 break;
379 }
380
381 default:
382 anv_debug_ignored_stype(ext->sType);
383 }
384 }
385
386 anv_render_pass_compile(pass);
387
388 *pRenderPass = anv_render_pass_to_handle(pass);
389
390 return VK_SUCCESS;
391 }
392
393 static unsigned
394 num_subpass_attachments2(const VkSubpassDescription2KHR *desc)
395 {
396 const VkSubpassDescriptionDepthStencilResolveKHR *ds_resolve =
397 vk_find_struct_const(desc->pNext,
398 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR);
399
400 return desc->inputAttachmentCount +
401 desc->colorAttachmentCount +
402 (desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +
403 (desc->pDepthStencilAttachment != NULL) +
404 (ds_resolve && ds_resolve->pDepthStencilResolveAttachment);
405 }
406
407 VkResult anv_CreateRenderPass2(
408 VkDevice _device,
409 const VkRenderPassCreateInfo2KHR* pCreateInfo,
410 const VkAllocationCallbacks* pAllocator,
411 VkRenderPass* pRenderPass)
412 {
413 ANV_FROM_HANDLE(anv_device, device, _device);
414
415 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR);
416
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;
421
422 ANV_MULTIALLOC(ma);
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);
427
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]);
433 }
434 anv_multialloc_add(&ma, &subpass_attachments, subpass_attachment_count);
435
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);
439
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.
442 */
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;
448
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);
453
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,
462
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),
469 };
470 }
471
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];
475
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;
481
482 if (desc->inputAttachmentCount > 0) {
483 subpass->input_attachments = subpass_attachments;
484 subpass_attachments += desc->inputAttachmentCount;
485
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);
490
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),
498 };
499 }
500 }
501
502 if (desc->colorAttachmentCount > 0) {
503 subpass->color_attachments = subpass_attachments;
504 subpass_attachments += desc->colorAttachmentCount;
505
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,
511 };
512 }
513 }
514
515 if (desc->pResolveAttachments) {
516 subpass->resolve_attachments = subpass_attachments;
517 subpass_attachments += desc->colorAttachmentCount;
518
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,
524 };
525 }
526 }
527
528 if (desc->pDepthStencilAttachment) {
529 subpass->depth_stencil_attachment = subpass_attachments++;
530
531 const VkAttachmentReferenceStencilLayoutKHR *stencil_attachment =
532 vk_find_struct_const(desc->pDepthStencilAttachment->pNext,
533 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
534
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,
542 };
543 }
544
545 const VkSubpassDescriptionDepthStencilResolveKHR *ds_resolve =
546 vk_find_struct_const(desc->pNext,
547 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR);
548
549 if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) {
550 subpass->ds_resolve_attachment = subpass_attachments++;
551
552 const VkAttachmentReferenceStencilLayoutKHR *stencil_resolve_attachment =
553 vk_find_struct_const(ds_resolve->pDepthStencilResolveAttachment->pNext,
554 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
555
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,
563 };
564 subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
565 subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode;
566 }
567 }
568
569 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++)
570 anv_render_pass_add_subpass_dep(pass, &pCreateInfo->pDependencies[i]);
571
572 vk_foreach_struct(ext, pCreateInfo->pNext) {
573 switch (ext->sType) {
574 default:
575 anv_debug_ignored_stype(ext->sType);
576 }
577 }
578
579 anv_render_pass_compile(pass);
580
581 *pRenderPass = anv_render_pass_to_handle(pass);
582
583 return VK_SUCCESS;
584 }
585
586 void anv_DestroyRenderPass(
587 VkDevice _device,
588 VkRenderPass _pass,
589 const VkAllocationCallbacks* pAllocator)
590 {
591 ANV_FROM_HANDLE(anv_device, device, _device);
592 ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
593
594 vk_free2(&device->alloc, pAllocator, pass);
595 }
596
597 void anv_GetRenderAreaGranularity(
598 VkDevice device,
599 VkRenderPass renderPass,
600 VkExtent2D* pGranularity)
601 {
602 ANV_FROM_HANDLE(anv_render_pass, pass, renderPass);
603
604 /* This granularity satisfies HiZ fast clear alignment requirements
605 * for all sample counts.
606 */
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 };
610 return;
611 }
612 }
613
614 *pGranularity = (VkExtent2D) { 1, 1 };
615 }