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 VkRenderPass
* pRenderPass
)
31 ANV_FROM_HANDLE(anv_device
, device
, _device
);
32 struct anv_render_pass
*pass
;
34 size_t attachments_offset
;
36 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
39 size
+= pCreateInfo
->subpassCount
* sizeof(pass
->subpasses
[0]);
40 attachments_offset
= size
;
41 size
+= pCreateInfo
->attachmentCount
* sizeof(pass
->attachments
[0]);
43 pass
= anv_device_alloc(device
, size
, 8,
44 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
46 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
48 /* Clear the subpasses along with the parent pass. This required because
49 * each array member of anv_subpass must be a valid pointer if not NULL.
51 memset(pass
, 0, size
);
52 pass
->attachment_count
= pCreateInfo
->attachmentCount
;
53 pass
->subpass_count
= pCreateInfo
->subpassCount
;
54 pass
->attachments
= (void *) pass
+ attachments_offset
;
56 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
57 struct anv_render_pass_attachment
*att
= &pass
->attachments
[i
];
59 att
->format
= anv_format_for_vk_format(pCreateInfo
->pAttachments
[i
].format
);
60 att
->samples
= pCreateInfo
->pAttachments
[i
].samples
;
61 att
->load_op
= pCreateInfo
->pAttachments
[i
].loadOp
;
62 att
->stencil_load_op
= pCreateInfo
->pAttachments
[i
].stencilLoadOp
;
63 // att->store_op = pCreateInfo->pAttachments[i].storeOp;
64 // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
67 for (uint32_t i
= 0; i
< pCreateInfo
->subpassCount
; i
++) {
68 const VkSubpassDescription
*desc
= &pCreateInfo
->pSubpasses
[i
];
69 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
71 subpass
->input_count
= desc
->inputCount
;
72 subpass
->color_count
= desc
->colorCount
;
74 if (desc
->inputCount
> 0) {
75 subpass
->input_attachments
=
76 anv_device_alloc(device
, desc
->inputCount
* sizeof(uint32_t),
77 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
79 for (uint32_t j
= 0; j
< desc
->inputCount
; j
++) {
80 subpass
->input_attachments
[j
]
81 = desc
->pInputAttachments
[j
].attachment
;
85 if (desc
->colorCount
> 0) {
86 subpass
->color_attachments
=
87 anv_device_alloc(device
, desc
->colorCount
* sizeof(uint32_t),
88 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
90 for (uint32_t j
= 0; j
< desc
->colorCount
; j
++) {
91 subpass
->color_attachments
[j
]
92 = desc
->pColorAttachments
[j
].attachment
;
96 if (desc
->pResolveAttachments
) {
97 subpass
->resolve_attachments
=
98 anv_device_alloc(device
, desc
->colorCount
* sizeof(uint32_t),
99 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
101 for (uint32_t j
= 0; j
< desc
->colorCount
; j
++) {
102 subpass
->resolve_attachments
[j
]
103 = desc
->pResolveAttachments
[j
].attachment
;
107 subpass
->depth_stencil_attachment
= desc
->depthStencilAttachment
.attachment
;
110 *pRenderPass
= anv_render_pass_to_handle(pass
);
115 void anv_DestroyRenderPass(
119 ANV_FROM_HANDLE(anv_device
, device
, _device
);
120 ANV_FROM_HANDLE(anv_render_pass
, pass
, _pass
);
122 for (uint32_t i
= 0; i
< pass
->subpass_count
; i
++) {
123 /* In VkSubpassCreateInfo, each of the attachment arrays may be null.
124 * Don't free the null arrays.
126 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
128 anv_device_free(device
, subpass
->input_attachments
);
129 anv_device_free(device
, subpass
->color_attachments
);
130 anv_device_free(device
, subpass
->resolve_attachments
);
133 anv_device_free(device
, pass
);
136 VkResult
anv_GetRenderAreaGranularity(
138 VkRenderPass renderPass
,
139 VkExtent2D
* pGranularity
)
141 *pGranularity
= (VkExtent2D
) { 1, 1 };