2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
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:
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
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
27 #include "radv_private.h"
32 radv_render_pass_add_subpass_dep(struct radv_render_pass
*pass
,
33 const VkSubpassDependency2
*dep
)
35 uint32_t src
= dep
->srcSubpass
;
36 uint32_t dst
= dep
->dstSubpass
;
38 /* Ignore subpass self-dependencies as they allow the app to call
39 * vkCmdPipelineBarrier() inside the render pass and the driver should
40 * only do the barrier when called, not when starting the render pass.
45 /* Accumulate all ingoing external dependencies to the first subpass. */
46 if (src
== VK_SUBPASS_EXTERNAL
)
49 if (dst
== VK_SUBPASS_EXTERNAL
) {
50 if (dep
->dstStageMask
!= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
)
51 pass
->end_barrier
.src_stage_mask
|= dep
->srcStageMask
;
52 pass
->end_barrier
.src_access_mask
|= dep
->srcAccessMask
;
53 pass
->end_barrier
.dst_access_mask
|= dep
->dstAccessMask
;
55 if (dep
->dstStageMask
!= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
)
56 pass
->subpasses
[dst
].start_barrier
.src_stage_mask
|= dep
->srcStageMask
;
57 pass
->subpasses
[dst
].start_barrier
.src_access_mask
|= dep
->srcAccessMask
;
58 pass
->subpasses
[dst
].start_barrier
.dst_access_mask
|= dep
->dstAccessMask
;
63 radv_pass_has_layout_transitions(const struct radv_render_pass
*pass
)
65 for (unsigned i
= 0; i
< pass
->subpass_count
; i
++) {
66 const struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
67 for (unsigned j
= 0; j
< subpass
->attachment_count
; j
++) {
68 const uint32_t a
= subpass
->attachments
[j
].attachment
;
69 if (a
== VK_ATTACHMENT_UNUSED
)
72 uint32_t initial_layout
= pass
->attachments
[a
].initial_layout
;
73 uint32_t stencil_initial_layout
= pass
->attachments
[a
].stencil_initial_layout
;
74 uint32_t final_layout
= pass
->attachments
[a
].final_layout
;
75 uint32_t stencil_final_layout
= pass
->attachments
[a
].stencil_final_layout
;
77 if (subpass
->attachments
[j
].layout
!= initial_layout
||
78 subpass
->attachments
[j
].layout
!= stencil_initial_layout
||
79 subpass
->attachments
[j
].layout
!= final_layout
||
80 subpass
->attachments
[j
].layout
!= stencil_final_layout
)
89 radv_render_pass_add_implicit_deps(struct radv_render_pass
*pass
,
90 bool has_ingoing_dep
, bool has_outgoing_dep
)
92 /* From the Vulkan 1.0.39 spec:
94 * If there is no subpass dependency from VK_SUBPASS_EXTERNAL to the
95 * first subpass that uses an attachment, then an implicit subpass
96 * dependency exists from VK_SUBPASS_EXTERNAL to the first subpass it is
97 * used in. The implicit subpass dependency only exists if there
98 * exists an automatic layout transition away from initialLayout.
99 * The subpass dependency operates as if defined with the
100 * following parameters:
102 * VkSubpassDependency implicitDependency = {
103 * .srcSubpass = VK_SUBPASS_EXTERNAL;
104 * .dstSubpass = firstSubpass; // First subpass attachment is used in
105 * .srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
106 * .dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
107 * .srcAccessMask = 0;
108 * .dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
109 * VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
110 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
111 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
112 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
113 * .dependencyFlags = 0;
116 * Similarly, if there is no subpass dependency from the last subpass
117 * that uses an attachment to VK_SUBPASS_EXTERNAL, then an implicit
118 * subpass dependency exists from the last subpass it is used in to
119 * VK_SUBPASS_EXTERNAL. The implicit subpass dependency only exists
120 * if there exists an automatic layout transition into finalLayout.
121 * The subpass dependency operates as if defined with the following
124 * VkSubpassDependency implicitDependency = {
125 * .srcSubpass = lastSubpass; // Last subpass attachment is used in
126 * .dstSubpass = VK_SUBPASS_EXTERNAL;
127 * .srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
128 * .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
129 * .srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
130 * VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
131 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
132 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
133 * VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
134 * .dstAccessMask = 0;
135 * .dependencyFlags = 0;
139 /* Implicit subpass dependencies only make sense if automatic layout
140 * transitions are performed.
142 if (!radv_pass_has_layout_transitions(pass
))
145 if (!has_ingoing_dep
) {
146 const VkSubpassDependency2KHR implicit_ingoing_dep
= {
147 .srcSubpass
= VK_SUBPASS_EXTERNAL
,
149 .srcStageMask
= VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
,
150 .dstStageMask
= VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
,
152 .dstAccessMask
= VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
|
153 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
154 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
155 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
156 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
,
157 .dependencyFlags
= 0,
160 radv_render_pass_add_subpass_dep(pass
, &implicit_ingoing_dep
);
163 if (!has_outgoing_dep
) {
164 const VkSubpassDependency2KHR implicit_outgoing_dep
= {
166 .dstSubpass
= VK_SUBPASS_EXTERNAL
,
167 .srcStageMask
= VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
,
168 .dstStageMask
= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
,
169 .srcAccessMask
= VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
|
170 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
171 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
172 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
173 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
,
175 .dependencyFlags
= 0,
178 radv_render_pass_add_subpass_dep(pass
, &implicit_outgoing_dep
);
183 radv_render_pass_compile(struct radv_render_pass
*pass
)
185 for (uint32_t i
= 0; i
< pass
->subpass_count
; i
++) {
186 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
188 for (uint32_t j
= 0; j
< subpass
->attachment_count
; j
++) {
189 struct radv_subpass_attachment
*subpass_att
=
190 &subpass
->attachments
[j
];
191 if (subpass_att
->attachment
== VK_ATTACHMENT_UNUSED
)
194 struct radv_render_pass_attachment
*pass_att
=
195 &pass
->attachments
[subpass_att
->attachment
];
197 pass_att
->first_subpass_idx
= UINT32_MAX
;
201 for (uint32_t i
= 0; i
< pass
->subpass_count
; i
++) {
202 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
203 uint32_t color_sample_count
= 1, depth_sample_count
= 1;
205 /* We don't allow depth_stencil_attachment to be non-NULL and
206 * be VK_ATTACHMENT_UNUSED. This way something can just check
207 * for NULL and be guaranteed that they have a valid
210 if (subpass
->depth_stencil_attachment
&&
211 subpass
->depth_stencil_attachment
->attachment
== VK_ATTACHMENT_UNUSED
)
212 subpass
->depth_stencil_attachment
= NULL
;
214 if (subpass
->ds_resolve_attachment
&&
215 subpass
->ds_resolve_attachment
->attachment
== VK_ATTACHMENT_UNUSED
)
216 subpass
->ds_resolve_attachment
= NULL
;
218 for (uint32_t j
= 0; j
< subpass
->attachment_count
; j
++) {
219 struct radv_subpass_attachment
*subpass_att
=
220 &subpass
->attachments
[j
];
221 if (subpass_att
->attachment
== VK_ATTACHMENT_UNUSED
)
224 struct radv_render_pass_attachment
*pass_att
=
225 &pass
->attachments
[subpass_att
->attachment
];
227 if (i
< pass_att
->first_subpass_idx
)
228 pass_att
->first_subpass_idx
= i
;
229 pass_att
->last_subpass_idx
= i
;
232 subpass
->has_color_att
= false;
233 for (uint32_t j
= 0; j
< subpass
->color_count
; j
++) {
234 struct radv_subpass_attachment
*subpass_att
=
235 &subpass
->color_attachments
[j
];
236 if (subpass_att
->attachment
== VK_ATTACHMENT_UNUSED
)
239 subpass
->has_color_att
= true;
241 struct radv_render_pass_attachment
*pass_att
=
242 &pass
->attachments
[subpass_att
->attachment
];
244 color_sample_count
= pass_att
->samples
;
247 if (subpass
->depth_stencil_attachment
) {
249 subpass
->depth_stencil_attachment
->attachment
;
250 struct radv_render_pass_attachment
*pass_att
=
251 &pass
->attachments
[a
];
252 depth_sample_count
= pass_att
->samples
;
255 subpass
->max_sample_count
= MAX2(color_sample_count
,
257 subpass
->color_sample_count
= color_sample_count
;
258 subpass
->depth_sample_count
= depth_sample_count
;
260 /* We have to handle resolve attachments specially */
261 subpass
->has_color_resolve
= false;
262 if (subpass
->resolve_attachments
) {
263 for (uint32_t j
= 0; j
< subpass
->color_count
; j
++) {
264 struct radv_subpass_attachment
*resolve_att
=
265 &subpass
->resolve_attachments
[j
];
267 if (resolve_att
->attachment
== VK_ATTACHMENT_UNUSED
)
270 subpass
->has_color_resolve
= true;
274 for (uint32_t j
= 0; j
< subpass
->input_count
; ++j
) {
275 if (subpass
->input_attachments
[j
].attachment
== VK_ATTACHMENT_UNUSED
)
278 for (uint32_t k
= 0; k
< subpass
->color_count
; ++k
) {
279 if (subpass
->color_attachments
[k
].attachment
== subpass
->input_attachments
[j
].attachment
) {
280 subpass
->input_attachments
[j
].in_render_loop
= true;
281 subpass
->color_attachments
[k
].in_render_loop
= true;
285 if (subpass
->depth_stencil_attachment
&&
286 subpass
->depth_stencil_attachment
->attachment
== subpass
->input_attachments
[j
].attachment
) {
287 subpass
->input_attachments
[j
].in_render_loop
= true;
288 subpass
->depth_stencil_attachment
->in_render_loop
= true;
295 radv_num_subpass_attachments(const VkSubpassDescription
*desc
)
297 return desc
->inputAttachmentCount
+
298 desc
->colorAttachmentCount
+
299 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
300 (desc
->pDepthStencilAttachment
!= NULL
);
303 VkResult
radv_CreateRenderPass(
305 const VkRenderPassCreateInfo
* pCreateInfo
,
306 const VkAllocationCallbacks
* pAllocator
,
307 VkRenderPass
* pRenderPass
)
309 RADV_FROM_HANDLE(radv_device
, device
, _device
);
310 struct radv_render_pass
*pass
;
312 size_t attachments_offset
;
313 VkRenderPassMultiviewCreateInfo
*multiview_info
= NULL
;
315 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
317 size
= sizeof(*pass
);
318 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
319 attachments_offset
= size
;
320 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
322 pass
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
323 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
325 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
327 memset(pass
, 0, size
);
328 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
329 pass
->subpass_count
= pCreateInfo
->subpassCount
;
330 pass
->attachments
= (void *) pass
+ attachments_offset
;
332 vk_foreach_struct(ext
, pCreateInfo
->pNext
) {
334 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO
:
335 multiview_info
= (VkRenderPassMultiviewCreateInfo
*)ext
;
342 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
343 struct radv_render_pass_attachment
*att
= &pass
->attachments
[i
];
345 att
->format
= pCreateInfo
->pAttachments
[i
].format
;
346 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
347 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
348 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
349 att
->initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
350 att
->final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
351 att
->stencil_initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
352 att
->stencil_final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
353 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
354 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
356 uint32_t subpass_attachment_count
= 0;
357 struct radv_subpass_attachment
*p
;
358 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
359 subpass_attachment_count
+=
360 radv_num_subpass_attachments(&pCreateInfo
->pSubpasses
[i
]);
363 if (subpass_attachment_count
) {
364 pass
->subpass_attachments
=
365 vk_alloc2(&device
->vk
.alloc
, pAllocator
,
366 subpass_attachment_count
* sizeof(struct radv_subpass_attachment
), 8,
367 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
368 if (pass
->subpass_attachments
== NULL
) {
369 vk_free2(&device
->vk
.alloc
, pAllocator
, pass
);
370 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
373 pass
->subpass_attachments
= NULL
;
375 p
= pass
->subpass_attachments
;
376 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
377 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
378 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
380 subpass
->input_count
= desc
->inputAttachmentCount
;
381 subpass
->color_count
= desc
->colorAttachmentCount
;
382 subpass
->attachment_count
= radv_num_subpass_attachments(desc
);
383 subpass
->attachments
= p
;
386 subpass
->view_mask
= multiview_info
->pViewMasks
[i
];
388 if (desc
->inputAttachmentCount
> 0) {
389 subpass
->input_attachments
= p
;
390 p
+= desc
->inputAttachmentCount
;
392 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
393 subpass
->input_attachments
[j
] = (struct radv_subpass_attachment
) {
394 .attachment
= desc
->pInputAttachments
[j
].attachment
,
395 .layout
= desc
->pInputAttachments
[j
].layout
,
396 .stencil_layout
= desc
->pInputAttachments
[j
].layout
,
401 if (desc
->colorAttachmentCount
> 0) {
402 subpass
->color_attachments
= p
;
403 p
+= desc
->colorAttachmentCount
;
405 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
406 subpass
->color_attachments
[j
] = (struct radv_subpass_attachment
) {
407 .attachment
= desc
->pColorAttachments
[j
].attachment
,
408 .layout
= desc
->pColorAttachments
[j
].layout
,
413 if (desc
->pResolveAttachments
) {
414 subpass
->resolve_attachments
= p
;
415 p
+= desc
->colorAttachmentCount
;
417 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
418 subpass
->resolve_attachments
[j
] = (struct radv_subpass_attachment
) {
419 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
420 .layout
= desc
->pResolveAttachments
[j
].layout
,
421 .stencil_layout
= desc
->pResolveAttachments
[j
].layout
,
426 if (desc
->pDepthStencilAttachment
) {
427 subpass
->depth_stencil_attachment
= p
++;
429 *subpass
->depth_stencil_attachment
= (struct radv_subpass_attachment
) {
430 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
431 .layout
= desc
->pDepthStencilAttachment
->layout
,
432 .stencil_layout
= desc
->pDepthStencilAttachment
->layout
,
437 bool has_ingoing_dep
= false;
438 bool has_outgoing_dep
= false;
440 for (unsigned i
= 0; i
< pCreateInfo
->dependencyCount
; ++i
) {
441 /* Convert to a Dependency2 */
442 struct VkSubpassDependency2 dep2
= {
443 .srcSubpass
= pCreateInfo
->pDependencies
[i
].srcSubpass
,
444 .dstSubpass
= pCreateInfo
->pDependencies
[i
].dstSubpass
,
445 .srcStageMask
= pCreateInfo
->pDependencies
[i
].srcStageMask
,
446 .dstStageMask
= pCreateInfo
->pDependencies
[i
].dstStageMask
,
447 .srcAccessMask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
,
448 .dstAccessMask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
,
449 .dependencyFlags
= pCreateInfo
->pDependencies
[i
].dependencyFlags
,
451 radv_render_pass_add_subpass_dep(pass
, &dep2
);
453 /* Determine if the subpass has explicit dependencies from/to
454 * VK_SUBPASS_EXTERNAL.
456 if (pCreateInfo
->pDependencies
[i
].srcSubpass
== VK_SUBPASS_EXTERNAL
)
457 has_ingoing_dep
= true;
458 if (pCreateInfo
->pDependencies
[i
].dstSubpass
== VK_SUBPASS_EXTERNAL
)
459 has_outgoing_dep
= true;
462 radv_render_pass_add_implicit_deps(pass
,
463 has_ingoing_dep
, has_outgoing_dep
);
465 radv_render_pass_compile(pass
);
467 *pRenderPass
= radv_render_pass_to_handle(pass
);
473 radv_num_subpass_attachments2(const VkSubpassDescription2
*desc
)
475 const VkSubpassDescriptionDepthStencilResolve
*ds_resolve
=
476 vk_find_struct_const(desc
->pNext
,
477 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE
);
479 return desc
->inputAttachmentCount
+
480 desc
->colorAttachmentCount
+
481 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
482 (desc
->pDepthStencilAttachment
!= NULL
) +
483 (ds_resolve
&& ds_resolve
->pDepthStencilResolveAttachment
);
486 VkResult
radv_CreateRenderPass2(
488 const VkRenderPassCreateInfo2
* pCreateInfo
,
489 const VkAllocationCallbacks
* pAllocator
,
490 VkRenderPass
* pRenderPass
)
492 RADV_FROM_HANDLE(radv_device
, device
, _device
);
493 struct radv_render_pass
*pass
;
495 size_t attachments_offset
;
497 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2
);
499 size
= sizeof(*pass
);
500 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
501 attachments_offset
= size
;
502 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
504 pass
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, size
, 8,
505 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
507 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
509 memset(pass
, 0, size
);
510 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
511 pass
->subpass_count
= pCreateInfo
->subpassCount
;
512 pass
->attachments
= (void *) pass
+ attachments_offset
;
514 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
515 struct radv_render_pass_attachment
*att
= &pass
->attachments
[i
];
516 const VkAttachmentDescriptionStencilLayoutKHR
*stencil_layout
=
517 vk_find_struct_const(pCreateInfo
->pAttachments
[i
].pNext
,
518 ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR
);
520 att
->format
= pCreateInfo
->pAttachments
[i
].format
;
521 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
522 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
523 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
524 att
->initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
525 att
->final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
526 att
->stencil_initial_layout
= (stencil_layout
?
527 stencil_layout
->stencilInitialLayout
:
528 pCreateInfo
->pAttachments
[i
].initialLayout
);
529 att
->stencil_final_layout
= (stencil_layout
?
530 stencil_layout
->stencilFinalLayout
:
531 pCreateInfo
->pAttachments
[i
].finalLayout
);
532 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
533 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
535 uint32_t subpass_attachment_count
= 0;
536 struct radv_subpass_attachment
*p
;
537 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
538 subpass_attachment_count
+=
539 radv_num_subpass_attachments2(&pCreateInfo
->pSubpasses
[i
]);
542 if (subpass_attachment_count
) {
543 pass
->subpass_attachments
=
544 vk_alloc2(&device
->vk
.alloc
, pAllocator
,
545 subpass_attachment_count
* sizeof(struct radv_subpass_attachment
), 8,
546 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
547 if (pass
->subpass_attachments
== NULL
) {
548 vk_free2(&device
->vk
.alloc
, pAllocator
, pass
);
549 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
552 pass
->subpass_attachments
= NULL
;
554 p
= pass
->subpass_attachments
;
555 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
556 const VkSubpassDescription2
*desc
= &pCreateInfo
->pSubpasses
[i
];
557 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
559 subpass
->input_count
= desc
->inputAttachmentCount
;
560 subpass
->color_count
= desc
->colorAttachmentCount
;
561 subpass
->attachment_count
= radv_num_subpass_attachments2(desc
);
562 subpass
->attachments
= p
;
563 subpass
->view_mask
= desc
->viewMask
;
565 if (desc
->inputAttachmentCount
> 0) {
566 subpass
->input_attachments
= p
;
567 p
+= desc
->inputAttachmentCount
;
569 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
570 const VkAttachmentReferenceStencilLayoutKHR
*stencil_attachment
=
571 vk_find_struct_const(desc
->pInputAttachments
[j
].pNext
,
572 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
574 subpass
->input_attachments
[j
] = (struct radv_subpass_attachment
) {
575 .attachment
= desc
->pInputAttachments
[j
].attachment
,
576 .layout
= desc
->pInputAttachments
[j
].layout
,
577 .stencil_layout
= (stencil_attachment
?
578 stencil_attachment
->stencilLayout
:
579 desc
->pInputAttachments
[j
].layout
),
584 if (desc
->colorAttachmentCount
> 0) {
585 subpass
->color_attachments
= p
;
586 p
+= desc
->colorAttachmentCount
;
588 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
589 subpass
->color_attachments
[j
] = (struct radv_subpass_attachment
) {
590 .attachment
= desc
->pColorAttachments
[j
].attachment
,
591 .layout
= desc
->pColorAttachments
[j
].layout
,
596 if (desc
->pResolveAttachments
) {
597 subpass
->resolve_attachments
= p
;
598 p
+= desc
->colorAttachmentCount
;
600 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
601 subpass
->resolve_attachments
[j
] = (struct radv_subpass_attachment
) {
602 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
603 .layout
= desc
->pResolveAttachments
[j
].layout
,
608 if (desc
->pDepthStencilAttachment
) {
609 subpass
->depth_stencil_attachment
= p
++;
611 const VkAttachmentReferenceStencilLayoutKHR
*stencil_attachment
=
612 vk_find_struct_const(desc
->pDepthStencilAttachment
->pNext
,
613 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
615 *subpass
->depth_stencil_attachment
= (struct radv_subpass_attachment
) {
616 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
617 .layout
= desc
->pDepthStencilAttachment
->layout
,
618 .stencil_layout
= (stencil_attachment
?
619 stencil_attachment
->stencilLayout
:
620 desc
->pDepthStencilAttachment
->layout
),
624 const VkSubpassDescriptionDepthStencilResolve
*ds_resolve
=
625 vk_find_struct_const(desc
->pNext
,
626 SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE
);
628 if (ds_resolve
&& ds_resolve
->pDepthStencilResolveAttachment
) {
629 subpass
->ds_resolve_attachment
= p
++;
631 const VkAttachmentReferenceStencilLayoutKHR
*stencil_resolve_attachment
=
632 vk_find_struct_const(ds_resolve
->pDepthStencilResolveAttachment
->pNext
,
633 ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR
);
635 *subpass
->ds_resolve_attachment
= (struct radv_subpass_attachment
) {
636 .attachment
= ds_resolve
->pDepthStencilResolveAttachment
->attachment
,
637 .layout
= ds_resolve
->pDepthStencilResolveAttachment
->layout
,
638 .stencil_layout
= (stencil_resolve_attachment
?
639 stencil_resolve_attachment
->stencilLayout
:
640 ds_resolve
->pDepthStencilResolveAttachment
->layout
),
643 subpass
->depth_resolve_mode
= ds_resolve
->depthResolveMode
;
644 subpass
->stencil_resolve_mode
= ds_resolve
->stencilResolveMode
;
648 bool has_ingoing_dep
= false;
649 bool has_outgoing_dep
= false;
651 for (unsigned i
= 0; i
< pCreateInfo
->dependencyCount
; ++i
) {
652 radv_render_pass_add_subpass_dep(pass
,
653 &pCreateInfo
->pDependencies
[i
]);
655 /* Determine if the subpass has explicit dependencies from/to
656 * VK_SUBPASS_EXTERNAL.
658 if (pCreateInfo
->pDependencies
[i
].srcSubpass
== VK_SUBPASS_EXTERNAL
)
659 has_ingoing_dep
= true;
660 if (pCreateInfo
->pDependencies
[i
].dstSubpass
== VK_SUBPASS_EXTERNAL
)
661 has_outgoing_dep
= true;
664 radv_render_pass_add_implicit_deps(pass
,
665 has_ingoing_dep
, has_outgoing_dep
);
667 radv_render_pass_compile(pass
);
669 *pRenderPass
= radv_render_pass_to_handle(pass
);
674 void radv_DestroyRenderPass(
677 const VkAllocationCallbacks
* pAllocator
)
679 RADV_FROM_HANDLE(radv_device
, device
, _device
);
680 RADV_FROM_HANDLE(radv_render_pass
, pass
, _pass
);
684 vk_free2(&device
->vk
.alloc
, pAllocator
, pass
->subpass_attachments
);
685 vk_free2(&device
->vk
.alloc
, pAllocator
, pass
);
688 void radv_GetRenderAreaGranularity(
690 VkRenderPass renderPass
,
691 VkExtent2D
* pGranularity
)
693 pGranularity
->width
= 1;
694 pGranularity
->height
= 1;