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
->inputAttachmentCount
;
72 subpass
->color_count
= desc
->colorAttachmentCount
;
74 if (desc
->inputAttachmentCount
> 0) {
75 subpass
->input_attachments
=
76 anv_device_alloc(device
,
77 desc
->inputAttachmentCount
* sizeof(uint32_t),
78 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
80 for (uint32_t j
= 0; j
< desc
->inputAttachmentCount
; j
++) {
81 subpass
->input_attachments
[j
]
82 = desc
->pInputAttachments
[j
].attachment
;
86 if (desc
->colorAttachmentCount
> 0) {
87 subpass
->color_attachments
=
88 anv_device_alloc(device
,
89 desc
->colorAttachmentCount
* sizeof(uint32_t),
90 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
92 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
93 subpass
->color_attachments
[j
]
94 = desc
->pColorAttachments
[j
].attachment
;
98 if (desc
->pResolveAttachments
) {
99 subpass
->resolve_attachments
=
100 anv_device_alloc(device
,
101 desc
->colorAttachmentCount
* sizeof(uint32_t),
102 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
104 for (uint32_t j
= 0; j
< desc
->colorAttachmentCount
; j
++) {
105 subpass
->resolve_attachments
[j
]
106 = desc
->pResolveAttachments
[j
].attachment
;
110 if (desc
->pDepthStencilAttachment
) {
111 subpass
->depth_stencil_attachment
=
112 desc
->pDepthStencilAttachment
->attachment
;
114 subpass
->depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
;
118 *pRenderPass
= anv_render_pass_to_handle(pass
);
123 void anv_DestroyRenderPass(
127 ANV_FROM_HANDLE(anv_device
, device
, _device
);
128 ANV_FROM_HANDLE(anv_render_pass
, pass
, _pass
);
130 for (uint32_t i
= 0; i
< pass
->subpass_count
; i
++) {
131 /* In VkSubpassCreateInfo, each of the attachment arrays may be null.
132 * Don't free the null arrays.
134 struct anv_subpass
*subpass
= &pass
->subpasses
[i
];
136 anv_device_free(device
, subpass
->input_attachments
);
137 anv_device_free(device
, subpass
->color_attachments
);
138 anv_device_free(device
, subpass
->resolve_attachments
);
141 anv_device_free(device
, pass
);
144 void anv_GetRenderAreaGranularity(
146 VkRenderPass renderPass
,
147 VkExtent2D
* pGranularity
)
149 *pGranularity
= (VkExtent2D
) { 1, 1 };