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"
31 VkResult
radv_CreateRenderPass(
33 const VkRenderPassCreateInfo
* pCreateInfo
,
34 const VkAllocationCallbacks
* pAllocator
,
35 VkRenderPass
* pRenderPass
)
37 RADV_FROM_HANDLE(radv_device
, device
, _device
);
38 struct radv_render_pass
*pass
;
40 size_t attachments_offset
;
41 VkRenderPassMultiviewCreateInfo
*multiview_info
= NULL
;
43 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
46 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
47 attachments_offset
= size
;
48 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
50 pass
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
51 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
53 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
55 memset(pass
, 0, size
);
56 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
57 pass
->subpass_count
= pCreateInfo
->subpassCount
;
58 pass
->attachments
= (void *) pass
+ attachments_offset
;
60 vk_foreach_struct(ext
, pCreateInfo
->pNext
) {
62 case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO
:
63 multiview_info
= (VkRenderPassMultiviewCreateInfo
*)ext
;
70 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
71 struct radv_render_pass_attachment
*att
= &pass
->attachments
[i
];
73 att
->format
= pCreateInfo
->pAttachments
[i
].format
;
74 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
75 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
76 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
77 att
->initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
78 att
->final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
79 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
80 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
82 uint32_t subpass_attachment_count
= 0;
83 struct radv_subpass_attachment
*p
;
84 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
85 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
87 subpass_attachment_count
+=
88 desc
->inputAttachmentCount
+
89 desc
->colorAttachmentCount
+
90 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
91 (desc
->pDepthStencilAttachment
!= NULL
);
94 if (subpass_attachment_count
) {
95 pass
->subpass_attachments
=
96 vk_alloc2(&device
->alloc
, pAllocator
,
97 subpass_attachment_count
* sizeof(struct radv_subpass_attachment
), 8,
98 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
99 if (pass
->subpass_attachments
== NULL
) {
100 vk_free2(&device
->alloc
, pAllocator
, pass
);
101 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
104 pass
->subpass_attachments
= NULL
;
106 p
= pass
->subpass_attachments
;
107 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
108 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
109 uint32_t color_sample_count
= 1, depth_sample_count
= 1;
110 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
112 subpass
->input_count
= desc
->inputAttachmentCount
;
113 subpass
->color_count
= desc
->colorAttachmentCount
;
115 subpass
->view_mask
= multiview_info
->pViewMasks
[i
];
117 if (desc
->inputAttachmentCount
> 0) {
118 subpass
->input_attachments
= p
;
119 p
+= desc
->inputAttachmentCount
;
121 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
122 subpass
->input_attachments
[j
] = (struct radv_subpass_attachment
) {
123 .attachment
= desc
->pInputAttachments
[j
].attachment
,
124 .layout
= desc
->pInputAttachments
[j
].layout
,
129 if (desc
->colorAttachmentCount
> 0) {
130 subpass
->color_attachments
= p
;
131 p
+= desc
->colorAttachmentCount
;
133 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
134 subpass
->color_attachments
[j
] = (struct radv_subpass_attachment
) {
135 .attachment
= desc
->pColorAttachments
[j
].attachment
,
136 .layout
= desc
->pColorAttachments
[j
].layout
,
138 if (desc
->pColorAttachments
[j
].attachment
!= VK_ATTACHMENT_UNUSED
) {
139 color_sample_count
= pCreateInfo
->pAttachments
[desc
->pColorAttachments
[j
].attachment
].samples
;
144 subpass
->has_resolve
= false;
145 if (desc
->pResolveAttachments
) {
146 subpass
->resolve_attachments
= p
;
147 p
+= desc
->colorAttachmentCount
;
149 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
150 uint32_t a
= desc
->pResolveAttachments
[j
].attachment
;
151 subpass
->resolve_attachments
[j
] = (struct radv_subpass_attachment
) {
152 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
153 .layout
= desc
->pResolveAttachments
[j
].layout
,
155 if (a
!= VK_ATTACHMENT_UNUSED
) {
156 subpass
->has_resolve
= true;
161 if (desc
->pDepthStencilAttachment
) {
162 subpass
->depth_stencil_attachment
= (struct radv_subpass_attachment
) {
163 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
164 .layout
= desc
->pDepthStencilAttachment
->layout
,
166 if (desc
->pDepthStencilAttachment
->attachment
!= VK_ATTACHMENT_UNUSED
) {
167 depth_sample_count
= pCreateInfo
->pAttachments
[desc
->pDepthStencilAttachment
->attachment
].samples
;
170 subpass
->depth_stencil_attachment
.attachment
= VK_ATTACHMENT_UNUSED
;
173 subpass
->max_sample_count
= MAX2(color_sample_count
,
177 for (unsigned i
= 0; i
< pCreateInfo
->dependencyCount
; ++i
) {
178 uint32_t src
= pCreateInfo
->pDependencies
[i
].srcSubpass
;
179 uint32_t dst
= pCreateInfo
->pDependencies
[i
].dstSubpass
;
181 /* Ignore subpass self-dependencies as they allow the app to
182 * call vkCmdPipelineBarrier() inside the render pass and the
183 * driver should only do the barrier when called, not when
184 * starting the render pass.
189 if (dst
== VK_SUBPASS_EXTERNAL
) {
190 pass
->end_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
191 pass
->end_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
192 pass
->end_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
194 pass
->subpasses
[dst
].start_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
195 pass
->subpasses
[dst
].start_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
196 pass
->subpasses
[dst
].start_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
200 *pRenderPass
= radv_render_pass_to_handle(pass
);
205 VkResult
radv_CreateRenderPass2KHR(
207 const VkRenderPassCreateInfo2KHR
* pCreateInfo
,
208 const VkAllocationCallbacks
* pAllocator
,
209 VkRenderPass
* pRenderPass
)
211 RADV_FROM_HANDLE(radv_device
, device
, _device
);
212 struct radv_render_pass
*pass
;
214 size_t attachments_offset
;
216 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR
);
218 size
= sizeof(*pass
);
219 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
220 attachments_offset
= size
;
221 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
223 pass
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
224 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
226 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
228 memset(pass
, 0, size
);
229 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
230 pass
->subpass_count
= pCreateInfo
->subpassCount
;
231 pass
->attachments
= (void *) pass
+ attachments_offset
;
233 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
234 struct radv_render_pass_attachment
*att
= &pass
->attachments
[i
];
236 att
->format
= pCreateInfo
->pAttachments
[i
].format
;
237 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
238 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
239 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
240 att
->initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
241 att
->final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
242 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
243 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
245 uint32_t subpass_attachment_count
= 0;
246 struct radv_subpass_attachment
*p
;
247 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
248 const VkSubpassDescription2KHR
*desc
= &pCreateInfo
->pSubpasses
[i
];
250 subpass_attachment_count
+=
251 desc
->inputAttachmentCount
+
252 desc
->colorAttachmentCount
+
253 (desc
->pResolveAttachments
? desc
->colorAttachmentCount
: 0) +
254 (desc
->pDepthStencilAttachment
!= NULL
);
257 if (subpass_attachment_count
) {
258 pass
->subpass_attachments
=
259 vk_alloc2(&device
->alloc
, pAllocator
,
260 subpass_attachment_count
* sizeof(struct radv_subpass_attachment
), 8,
261 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
262 if (pass
->subpass_attachments
== NULL
) {
263 vk_free2(&device
->alloc
, pAllocator
, pass
);
264 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
267 pass
->subpass_attachments
= NULL
;
269 p
= pass
->subpass_attachments
;
270 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
271 const VkSubpassDescription2KHR
*desc
= &pCreateInfo
->pSubpasses
[i
];
272 uint32_t color_sample_count
= 1, depth_sample_count
= 1;
273 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
275 subpass
->input_count
= desc
->inputAttachmentCount
;
276 subpass
->color_count
= desc
->colorAttachmentCount
;
277 subpass
->view_mask
= desc
->viewMask
;
279 if (desc
->inputAttachmentCount
> 0) {
280 subpass
->input_attachments
= p
;
281 p
+= desc
->inputAttachmentCount
;
283 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
284 subpass
->input_attachments
[j
] = (struct radv_subpass_attachment
) {
285 .attachment
= desc
->pInputAttachments
[j
].attachment
,
286 .layout
= desc
->pInputAttachments
[j
].layout
,
291 if (desc
->colorAttachmentCount
> 0) {
292 subpass
->color_attachments
= p
;
293 p
+= desc
->colorAttachmentCount
;
295 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
296 subpass
->color_attachments
[j
] = (struct radv_subpass_attachment
) {
297 .attachment
= desc
->pColorAttachments
[j
].attachment
,
298 .layout
= desc
->pColorAttachments
[j
].layout
,
300 if (desc
->pColorAttachments
[j
].attachment
!= VK_ATTACHMENT_UNUSED
) {
301 color_sample_count
= pCreateInfo
->pAttachments
[desc
->pColorAttachments
[j
].attachment
].samples
;
306 subpass
->has_resolve
= false;
307 if (desc
->pResolveAttachments
) {
308 subpass
->resolve_attachments
= p
;
309 p
+= desc
->colorAttachmentCount
;
311 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
312 uint32_t a
= desc
->pResolveAttachments
[j
].attachment
;
313 subpass
->resolve_attachments
[j
] = (struct radv_subpass_attachment
) {
314 .attachment
= desc
->pResolveAttachments
[j
].attachment
,
315 .layout
= desc
->pResolveAttachments
[j
].layout
,
317 if (a
!= VK_ATTACHMENT_UNUSED
) {
318 subpass
->has_resolve
= true;
323 if (desc
->pDepthStencilAttachment
) {
324 subpass
->depth_stencil_attachment
= (struct radv_subpass_attachment
) {
325 .attachment
= desc
->pDepthStencilAttachment
->attachment
,
326 .layout
= desc
->pDepthStencilAttachment
->layout
,
328 if (desc
->pDepthStencilAttachment
->attachment
!= VK_ATTACHMENT_UNUSED
) {
329 depth_sample_count
= pCreateInfo
->pAttachments
[desc
->pDepthStencilAttachment
->attachment
].samples
;
332 subpass
->depth_stencil_attachment
.attachment
= VK_ATTACHMENT_UNUSED
;
335 subpass
->max_sample_count
= MAX2(color_sample_count
,
339 for (unsigned i
= 0; i
< pCreateInfo
->dependencyCount
; ++i
) {
340 uint32_t src
= pCreateInfo
->pDependencies
[i
].srcSubpass
;
341 uint32_t dst
= pCreateInfo
->pDependencies
[i
].dstSubpass
;
343 /* Ignore subpass self-dependencies as they allow the app to
344 * call vkCmdPipelineBarrier() inside the render pass and the
345 * driver should only do the barrier when called, not when
346 * starting the render pass.
351 if (dst
== VK_SUBPASS_EXTERNAL
) {
352 pass
->end_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
353 pass
->end_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
354 pass
->end_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
356 pass
->subpasses
[dst
].start_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
357 pass
->subpasses
[dst
].start_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
358 pass
->subpasses
[dst
].start_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
362 *pRenderPass
= radv_render_pass_to_handle(pass
);
367 void radv_DestroyRenderPass(
370 const VkAllocationCallbacks
* pAllocator
)
372 RADV_FROM_HANDLE(radv_device
, device
, _device
);
373 RADV_FROM_HANDLE(radv_render_pass
, pass
, _pass
);
377 vk_free2(&device
->alloc
, pAllocator
, pass
->subpass_attachments
);
378 vk_free2(&device
->alloc
, pAllocator
, pass
);
381 void radv_GetRenderAreaGranularity(
383 VkRenderPass renderPass
,
384 VkExtent2D
* pGranularity
)
386 pGranularity
->width
= 1;
387 pGranularity
->height
= 1;