vk/0.210.0: Rework render pass description structures
[mesa.git] / src / vulkan / anv_pass.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include "anv_private.h"
25
26 VkResult anv_CreateRenderPass(
27 VkDevice _device,
28 const VkRenderPassCreateInfo* pCreateInfo,
29 VkRenderPass* pRenderPass)
30 {
31 ANV_FROM_HANDLE(anv_device, device, _device);
32 struct anv_render_pass *pass;
33 size_t size;
34 size_t attachments_offset;
35
36 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO);
37
38 size = sizeof(*pass);
39 size += pCreateInfo->subpassCount * sizeof(pass->subpasses[0]);
40 attachments_offset = size;
41 size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]);
42
43 pass = anv_device_alloc(device, size, 8,
44 VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
45 if (pass == NULL)
46 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
47
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.
50 */
51 memset(pass, 0, size);
52 pass->attachment_count = pCreateInfo->attachmentCount;
53 pass->subpass_count = pCreateInfo->subpassCount;
54 pass->attachments = (void *) pass + attachments_offset;
55
56 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
57 struct anv_render_pass_attachment *att = &pass->attachments[i];
58
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;
65 }
66
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];
70
71 subpass->input_count = desc->inputAttachmentCount;
72 subpass->color_count = desc->colorAttachmentCount;
73
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);
79
80 for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
81 subpass->input_attachments[j]
82 = desc->pInputAttachments[j].attachment;
83 }
84 }
85
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);
91
92 for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
93 subpass->color_attachments[j]
94 = desc->pColorAttachments[j].attachment;
95 }
96 }
97
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);
103
104 for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
105 subpass->resolve_attachments[j]
106 = desc->pResolveAttachments[j].attachment;
107 }
108 }
109
110 if (desc->pDepthStencilAttachment) {
111 subpass->depth_stencil_attachment =
112 desc->pDepthStencilAttachment->attachment;
113 } else {
114 subpass->depth_stencil_attachment = VK_ATTACHMENT_UNUSED;
115 }
116 }
117
118 *pRenderPass = anv_render_pass_to_handle(pass);
119
120 return VK_SUCCESS;
121 }
122
123 void anv_DestroyRenderPass(
124 VkDevice _device,
125 VkRenderPass _pass)
126 {
127 ANV_FROM_HANDLE(anv_device, device, _device);
128 ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
129
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.
133 */
134 struct anv_subpass *subpass = &pass->subpasses[i];
135
136 anv_device_free(device, subpass->input_attachments);
137 anv_device_free(device, subpass->color_attachments);
138 anv_device_free(device, subpass->resolve_attachments);
139 }
140
141 anv_device_free(device, pass);
142 }
143
144 void anv_GetRenderAreaGranularity(
145 VkDevice device,
146 VkRenderPass renderPass,
147 VkExtent2D* pGranularity)
148 {
149 *pGranularity = (VkExtent2D) { 1, 1 };
150 }