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"
29 VkResult
radv_CreateRenderPass(
31 const VkRenderPassCreateInfo
* pCreateInfo
,
32 const VkAllocationCallbacks
* pAllocator
,
33 VkRenderPass
* pRenderPass
)
35 RADV_FROM_HANDLE(radv_device
, device
, _device
);
36 struct radv_render_pass
*pass
;
38 size_t attachments_offset
;
40 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
43 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
44 attachments_offset
= size
;
45 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
47 pass
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
48 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
50 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
52 memset(pass
, 0, size
);
53 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
54 pass
->subpass_count
= pCreateInfo
->subpassCount
;
55 pass
->attachments
= (void *) pass
+ attachments_offset
;
57 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
58 struct radv_render_pass_attachment
*att
= &pass
->attachments
[i
];
60 att
->format
= pCreateInfo
->pAttachments
[i
].format
;
61 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
62 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
63 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
64 att
->initial_layout
= pCreateInfo
->pAttachments
[i
].initialLayout
;
65 att
->final_layout
= pCreateInfo
->pAttachments
[i
].finalLayout
;
66 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
67 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
69 uint32_t subpass_attachment_count
= 0;
70 VkAttachmentReference
*p
;
71 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
72 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
74 subpass_attachment_count
+=
75 desc
->inputAttachmentCount
+
76 desc
->colorAttachmentCount
+
77 /* Count colorAttachmentCount again for resolve_attachments */
78 desc
->colorAttachmentCount
;
81 if (subpass_attachment_count
) {
82 pass
->subpass_attachments
=
83 vk_alloc2(&device
->alloc
, pAllocator
,
84 subpass_attachment_count
* sizeof(VkAttachmentReference
), 8,
85 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
86 if (pass
->subpass_attachments
== NULL
) {
87 vk_free2(&device
->alloc
, pAllocator
, pass
);
88 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
91 pass
->subpass_attachments
= NULL
;
93 p
= pass
->subpass_attachments
;
94 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
95 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
96 struct radv_subpass
*subpass
= &pass
->subpasses
[i
];
98 subpass
->input_count
= desc
->inputAttachmentCount
;
99 subpass
->color_count
= desc
->colorAttachmentCount
;
101 if (desc
->inputAttachmentCount
> 0) {
102 subpass
->input_attachments
= p
;
103 p
+= desc
->inputAttachmentCount
;
105 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
106 subpass
->input_attachments
[j
]
107 = desc
->pInputAttachments
[j
];
111 if (desc
->colorAttachmentCount
> 0) {
112 subpass
->color_attachments
= p
;
113 p
+= desc
->colorAttachmentCount
;
115 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
116 subpass
->color_attachments
[j
]
117 = desc
->pColorAttachments
[j
];
121 subpass
->has_resolve
= false;
122 if (desc
->pResolveAttachments
) {
123 subpass
->resolve_attachments
= p
;
124 p
+= desc
->colorAttachmentCount
;
126 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
127 uint32_t a
= desc
->pResolveAttachments
[j
].attachment
;
128 subpass
->resolve_attachments
[j
]
129 = desc
->pResolveAttachments
[j
];
130 if (a
!= VK_ATTACHMENT_UNUSED
)
131 subpass
->has_resolve
= true;
135 if (desc
->pDepthStencilAttachment
) {
136 subpass
->depth_stencil_attachment
=
137 *desc
->pDepthStencilAttachment
;
139 subpass
->depth_stencil_attachment
.attachment
= VK_ATTACHMENT_UNUSED
;
143 for (unsigned i
= 0; i
< pCreateInfo
->dependencyCount
; ++i
) {
144 uint32_t dst
= pCreateInfo
->pDependencies
[i
].dstSubpass
;
145 if (dst
== VK_SUBPASS_EXTERNAL
) {
146 pass
->end_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
147 pass
->end_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
148 pass
->end_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
150 pass
->subpasses
[dst
].start_barrier
.src_stage_mask
= pCreateInfo
->pDependencies
[i
].srcStageMask
;
151 pass
->subpasses
[dst
].start_barrier
.src_access_mask
= pCreateInfo
->pDependencies
[i
].srcAccessMask
;
152 pass
->subpasses
[dst
].start_barrier
.dst_access_mask
= pCreateInfo
->pDependencies
[i
].dstAccessMask
;
156 *pRenderPass
= radv_render_pass_to_handle(pass
);
161 void radv_DestroyRenderPass(
164 const VkAllocationCallbacks
* pAllocator
)
166 RADV_FROM_HANDLE(radv_device
, device
, _device
);
167 RADV_FROM_HANDLE(radv_render_pass
, pass
, _pass
);
171 vk_free2(&device
->alloc
, pAllocator
, pass
->subpass_attachments
);
172 vk_free2(&device
->alloc
, pAllocator
, pass
);
175 void radv_GetRenderAreaGranularity(
177 VkRenderPass renderPass
,
178 VkExtent2D
* pGranularity
)
180 pGranularity
->width
= 1;
181 pGranularity
->height
= 1;