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"
26 VkResult
anv_CreateRenderPass(
28 const VkRenderPassCreateInfo
* pCreateInfo
,
29 const VkAllocationCallbacks
* pAllocator
,
30 VkRenderPass
* pRenderPass
)
32 ANV_FROM_HANDLE(anv_device
, device
, _device
);
33 struct anv_render_pass
*pass
;
35 size_t attachments_offset
;
37 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
40 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
41 attachments_offset
= size
;
42 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
44 pass
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
45 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
47 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
49 /* Clear the subpasses along with the parent pass. This required because
50 * each array member of anv_subpass must be a valid pointer if not NULL.
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 anv_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
->store_op
= pCreateInfo
->pAttachments
[i
].storeOp
;
64 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
67 uint32_t subpass_attachment_count
= 0, *p
;
68 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
69 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
71 subpass_attachment_count
+=
72 desc
->inputAttachmentCount
+
73 desc
->colorAttachmentCount
+
74 /* Count colorAttachmentCount again for resolve_attachments */
75 desc
->colorAttachmentCount
;
78 pass
->subpass_attachments
=
79 vk_alloc2(&device
->alloc
, pAllocator
,
80 subpass_attachment_count
* sizeof(uint32_t), 8,
81 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
82 if (pass
->subpass_attachments
== NULL
) {
83 vk_free2(&device
->alloc
, pAllocator
, pass
);
84 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
87 p
= pass
->subpass_attachments
;
88 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
89 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
90 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
92 subpass
->input_count
= desc
->inputAttachmentCount
;
93 subpass
->color_count
= desc
->colorAttachmentCount
;
95 if (desc
->inputAttachmentCount
> 0) {
96 subpass
->input_attachments
= p
;
97 p
+= desc
->inputAttachmentCount
;
99 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
100 subpass
->input_attachments
[j
]
101 = desc
->pInputAttachments
[j
].attachment
;
105 if (desc
->colorAttachmentCount
> 0) {
106 subpass
->color_attachments
= p
;
107 p
+= desc
->colorAttachmentCount
;
109 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
110 subpass
->color_attachments
[j
]
111 = desc
->pColorAttachments
[j
].attachment
;
115 subpass
->has_resolve
= false;
116 if (desc
->pResolveAttachments
) {
117 subpass
->resolve_attachments
= p
;
118 p
+= desc
->colorAttachmentCount
;
120 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
121 uint32_t a
= desc
->pResolveAttachments
[j
].attachment
;
122 subpass
->resolve_attachments
[j
] = a
;
123 if (a
!= VK_ATTACHMENT_UNUSED
)
124 subpass
->has_resolve
= true;
128 if (desc
->pDepthStencilAttachment
) {
129 subpass
->depth_stencil_attachment
=
130 desc
->pDepthStencilAttachment
->attachment
;
132 subpass
->depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
;
136 *pRenderPass
= anv_render_pass_to_handle(pass
);
141 void anv_DestroyRenderPass(
144 const VkAllocationCallbacks
* pAllocator
)
146 ANV_FROM_HANDLE(anv_device
, device
, _device
);
147 ANV_FROM_HANDLE(anv_render_pass
, pass
, _pass
);
149 vk_free2(&device
->alloc
, pAllocator
, pass
->subpass_attachments
);
150 vk_free2(&device
->alloc
, pAllocator
, pass
);
153 void anv_GetRenderAreaGranularity(
155 VkRenderPass renderPass
,
156 VkExtent2D
* pGranularity
)
158 ANV_FROM_HANDLE(anv_render_pass
, pass
, renderPass
);
160 /* This granularity satisfies HiZ fast clear alignment requirements
161 * for all sample counts.
163 for (unsigned i
= 0; i
< pass
->subpass_count
; ++i
) {
164 if (pass
->subpasses
[i
].depth_stencil_attachment
!=
165 VK_ATTACHMENT_UNUSED
) {
166 *pGranularity
= (VkExtent2D
) { .width
= 8, .height
= 4 };
171 *pGranularity
= (VkExtent2D
) { 1, 1 };