blob: 0b0f934cbc95b6e6b7056650ef2493b97cb9b354 [file] [log] [blame]
Jon Ashburnc6f4a412014-12-24 12:38:36 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburnc6f4a412014-12-24 12:38:36 -07003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26#include "dev.h"
27#include "obj.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070028#include "view.h"
29#include "img.h"
Jon Ashburnc6f4a412014-12-24 12:38:36 -070030#include "fb.h"
31
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070032static void fb_destroy(struct intel_obj *obj)
33{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070034 struct intel_fb *fb = intel_fb_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070035
36 intel_fb_destroy(fb);
37}
38
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060039VkResult intel_fb_create(struct intel_dev *dev,
40 const VkFramebufferCreateInfo *info,
Chia-I Wu4f7730d2015-02-18 15:21:38 -070041 struct intel_fb **fb_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -070042{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070043 struct intel_fb *fb;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070044 uint32_t width, height, array_size, i;
45
Chia-I Wuba627862015-02-18 15:32:06 -070046 if (info->colorAttachmentCount > INTEL_MAX_RENDER_TARGETS)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060047 return VK_ERROR_INVALID_VALUE;
Chia-I Wuba627862015-02-18 15:32:06 -070048
Chia-I Wu545c2e12015-02-22 13:19:54 +080049 fb = (struct intel_fb *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060050 sizeof(*fb), dev->base.dbg, VK_OBJECT_TYPE_FRAMEBUFFER, info, 0);
Jon Ashburnc6f4a412014-12-24 12:38:36 -070051 if (!fb)
Tony Barbour8205d902015-04-16 15:59:00 -060052 return VK_ERROR_OUT_OF_HOST_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070053
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080054 fb->view_count = info->colorAttachmentCount;
55 if (info->pDepthStencilAttachment)
56 fb->view_count++;
57
58 fb->views = intel_alloc(fb, sizeof(fb->views[0]) * fb->view_count, 0,
59 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
60 if (!fb->views) {
61 intel_fb_destroy(fb);
62 return VK_ERROR_OUT_OF_HOST_MEMORY;
63 }
64
Chia-I Wu4f7730d2015-02-18 15:21:38 -070065 width = info->width;
66 height = info->height;
67 array_size = info->layers;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070068
69 for (i = 0; i < info->colorAttachmentCount; i++) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080070 const VkColorAttachmentBindInfo *att = &info->pColorAttachments[i];
71 const struct intel_att_view *view =
72 intel_att_view_from_color(att->view);
73 const struct intel_layout *layout = &view->img->layout;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070074
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060075 if (width > layout->width0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070076 width = layout->width0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060077 if (height > layout->height0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070078 height = layout->height0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080079 if (array_size > view->array_size)
80 array_size = view->array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070081
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080082 if (view->img->samples != info->sampleCount) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060083 intel_fb_destroy(fb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060084 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060085 }
Chia-I Wu4f7730d2015-02-18 15:21:38 -070086
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080087 fb->views[i] = view;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070088 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060089
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070090 if (info->pDepthStencilAttachment) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080091 const VkDepthStencilBindInfo *att = info->pDepthStencilAttachment;
92 const struct intel_att_view *view = intel_att_view_from_ds(att->view);
93 const struct intel_layout *layout = &view->img->layout;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070094
95 if (width > layout->width0)
96 width = layout->width0;
97 if (height > layout->height0)
98 height = layout->height0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080099 if (array_size > view->array_size)
100 array_size = view->array_size;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600101
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800102 if (view->img->samples != info->sampleCount) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600103 intel_fb_destroy(fb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600104 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600105 }
106
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800107 fb->views[info->colorAttachmentCount] = view;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700108 }
109
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700110 fb->width = width;
111 fb->height = height;
112 fb->array_size = array_size;
113
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600114 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700115 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600116
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700117 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700118
119 *fb_ret = fb;
120
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600121 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700122}
123
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700124void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700125{
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800126 if (fb->views)
127 intel_free(fb, fb->views);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700128 intel_base_destroy(&fb->obj.base);
129}
130
131static void render_pass_destroy(struct intel_obj *obj)
132{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700133 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700134
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700135 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700136}
137
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600138VkResult intel_render_pass_create(struct intel_dev *dev,
Chia-I Wubdeed152015-07-09 12:16:29 +0800139 const VkRenderPassCreateInfo *info,
140 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700141{
142 struct intel_render_pass *rp;
Chia-I Wuba627862015-02-18 15:32:06 -0700143 uint32_t i;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700144
Chia-I Wu545c2e12015-02-22 13:19:54 +0800145 rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600146 sizeof(*rp), dev->base.dbg, VK_OBJECT_TYPE_RENDER_PASS, info, 0);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700147 if (!rp)
Tony Barbour8205d902015-04-16 15:59:00 -0600148 return VK_ERROR_OUT_OF_HOST_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700149
Chia-I Wubdeed152015-07-09 12:16:29 +0800150 rp->attachment_count = info->colorAttachmentCount;
151 if (info->depthStencilFormat != VK_FORMAT_UNDEFINED)
152 rp->attachment_count++;
153
154 rp->subpass_count = 1;
155
156 rp->attachments = intel_alloc(rp,
157 sizeof(rp->attachments[0]) * rp->attachment_count +
158 sizeof(rp->subpasses[0]) * rp->subpass_count, 0,
159 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
160 if (!rp->attachments) {
161 intel_render_pass_destroy(rp);
162 return VK_ERROR_OUT_OF_HOST_MEMORY;
163 }
164
165 rp->subpasses = (struct intel_render_pass_subpass *)
166 (rp->attachments + rp->attachment_count);
167
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700168 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700169
Chia-I Wubdeed152015-07-09 12:16:29 +0800170 for (i = 0; i < info->colorAttachmentCount; i++) {
171 struct intel_render_pass_attachment *att = &rp->attachments[i];
Chris Forbesfff9bf42015-06-15 15:26:19 +1200172
Chia-I Wubdeed152015-07-09 12:16:29 +0800173 att->format = info->pColorFormats[i];
174 att->sample_count = info->sampleCount;
175 att->initial_layout = info->pColorLayouts[i];
176 att->final_layout = info->pColorLayouts[i];
177
178 att->clear_on_load =
179 (info->pColorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR);
180 att->disable_store =
181 (info->pColorStoreOps[i] == VK_ATTACHMENT_STORE_OP_DONT_CARE);
182
183 att->stencil_clear_on_load = false;
184 att->stencil_disable_store = true;
185
186 att->clear_val.color = info->pColorLoadClearValues[i];
Chris Forbesfff9bf42015-06-15 15:26:19 +1200187 }
188
Chia-I Wubdeed152015-07-09 12:16:29 +0800189 if (info->depthStencilFormat != VK_FORMAT_UNDEFINED) {
190 struct intel_render_pass_attachment *att =
191 &rp->attachments[info->colorAttachmentCount];
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700192
Chia-I Wubdeed152015-07-09 12:16:29 +0800193 att->format = info->depthStencilFormat;
194 att->sample_count = info->sampleCount;
195 att->initial_layout = info->depthStencilLayout;
196 att->final_layout = info->depthStencilLayout;
197
198 att->clear_on_load =
199 (info->depthLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR);
200 att->disable_store =
201 (info->depthStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE);
202
203 att->stencil_clear_on_load =
204 (info->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR);
205 att->stencil_disable_store =
206 (info->stencilStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE);
207
208 att->clear_val.ds.depth = info->depthLoadClearValue;
209 att->clear_val.ds.stencil = info->stencilLoadClearValue;
Chia-I Wu1af1a782015-07-09 10:46:39 +0800210 }
211
Chia-I Wubdeed152015-07-09 12:16:29 +0800212 for (i = 0; i < rp->subpass_count; i++) {
213 struct intel_render_pass_subpass *subpass = &rp->subpasses[i];
214 uint32_t j;
215
216 for (j = 0; j < info->colorAttachmentCount; j++) {
217 subpass->color_indices[j] = j;
218 subpass->resolve_indices[j] = 0xffffffffu;
219 subpass->color_layouts[j] = info->pColorLayouts[j];
220 }
221
222 subpass->color_count = info->colorAttachmentCount;
223
224 subpass->ds_index =
225 (info->depthStencilFormat != VK_FORMAT_UNDEFINED) ?
226 info->colorAttachmentCount : 0xffffffffu;
227 subpass->ds_layout = info->depthStencilLayout;
228
229 switch (info->depthStencilLayout) {
230 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
231 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
232 subpass->ds_optimal = true;
233 break;
234 default:
235 subpass->ds_optimal = false;
236 break;
237 }
238 }
Chris Forbesfff9bf42015-06-15 15:26:19 +1200239
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700240 *rp_ret = rp;
241
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700243}
244
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700245void intel_render_pass_destroy(struct intel_render_pass *rp)
246{
Chia-I Wubdeed152015-07-09 12:16:29 +0800247 if (rp->attachments)
248 intel_free(rp, rp->attachments);
249
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700250 intel_base_destroy(&rp->obj.base);
251}
252
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600253ICD_EXPORT VkResult VKAPI vkCreateFramebuffer(
254 VkDevice device,
255 const VkFramebufferCreateInfo* pCreateInfo,
256 VkFramebuffer* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700257{
258 struct intel_dev *dev = intel_dev(device);
259
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700260 return intel_fb_create(dev, pCreateInfo,
261 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700262}
263
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600264ICD_EXPORT VkResult VKAPI vkCreateRenderPass(
265 VkDevice device,
266 const VkRenderPassCreateInfo* pCreateInfo,
267 VkRenderPass* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700268{
269 struct intel_dev *dev = intel_dev(device);
270
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700271 return intel_render_pass_create(dev, pCreateInfo,
272 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700273}