vk: Move all gen8 files to gen8 lib
[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->inputCount;
72 subpass->color_count = desc->colorCount;
73
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);
78
79 for (uint32_t j = 0; j < desc->inputCount; j++) {
80 subpass->input_attachments[j]
81 = desc->pInputAttachments[j].attachment;
82 }
83 }
84
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);
89
90 for (uint32_t j = 0; j < desc->colorCount; j++) {
91 subpass->color_attachments[j]
92 = desc->pColorAttachments[j].attachment;
93 }
94 }
95
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);
100
101 for (uint32_t j = 0; j < desc->colorCount; j++) {
102 subpass->resolve_attachments[j]
103 = desc->pResolveAttachments[j].attachment;
104 }
105 }
106
107 subpass->depth_stencil_attachment = desc->depthStencilAttachment.attachment;
108 }
109
110 *pRenderPass = anv_render_pass_to_handle(pass);
111
112 return VK_SUCCESS;
113 }
114
115 void anv_DestroyRenderPass(
116 VkDevice _device,
117 VkRenderPass _pass)
118 {
119 ANV_FROM_HANDLE(anv_device, device, _device);
120 ANV_FROM_HANDLE(anv_render_pass, pass, _pass);
121
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.
125 */
126 struct anv_subpass *subpass = &pass->subpasses[i];
127
128 anv_device_free(device, subpass->input_attachments);
129 anv_device_free(device, subpass->color_attachments);
130 anv_device_free(device, subpass->resolve_attachments);
131 }
132
133 anv_device_free(device, pass);
134 }
135
136 VkResult anv_GetRenderAreaGranularity(
137 VkDevice device,
138 VkRenderPass renderPass,
139 VkExtent2D* pGranularity)
140 {
141 *pGranularity = (VkExtent2D) { 1, 1 };
142
143 return VK_SUCCESS;
144 }