blob: 2a365ea5a74f7ba42d34c492d3d457f08d3afba7 [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,
139 const VkRenderPassCreateInfo *info,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700140 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
150 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700151
Chris Forbesfff9bf42015-06-15 15:26:19 +1200152 rp->colorAttachmentCount = info->colorAttachmentCount;
153 rp->renderArea = info->renderArea;
154 rp->extent = info->extent;
155
156 if (rp->colorAttachmentCount) {
157 memcpy(rp->colorLoadOps, info->pColorLoadOps, rp->colorAttachmentCount * sizeof(rp->colorLoadOps[0]));
158 if (info->pColorLayouts) {
159 memcpy(rp->colorLayouts, info->pColorLayouts, rp->colorAttachmentCount * sizeof(rp->colorLayouts[0]));
160 }
161 if (info->pColorLoadClearValues) {
162 memcpy(rp->colorClearValues, info->pColorLoadClearValues, rp->colorAttachmentCount * sizeof(rp->colorClearValues[0]));
163 }
164 }
165
Chris Forbes4cf9d102015-06-22 18:46:05 +1200166 rp->depthLoadOp = info->depthLoadOp;
167 rp->depthLoadClearValue = info->depthLoadClearValue;
168 rp->stencilLoadOp = info->stencilLoadOp;
169 rp->stencilLoadClearValue = info->stencilLoadClearValue;
170 rp->depthStencilLayout = info->depthStencilLayout;
171 rp->depthStencilFormat = info->depthStencilFormat;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700172
Chia-I Wu1af1a782015-07-09 10:46:39 +0800173 switch (info->depthStencilLayout) {
174 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
175 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
176 rp->optimal_ds = true;
177 break;
178 default:
179 rp->optimal_ds = false;
180 break;
181 }
182
Chris Forbesfff9bf42015-06-15 15:26:19 +1200183 /* TODO: MSAA resolves if/when we support MSAA. */
184 for (i = 0; i < info->colorAttachmentCount; i++)
185 assert(info->pColorStoreOps[i] != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
186 assert(info->depthStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
187 assert(info->stencilStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
188
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700189 *rp_ret = rp;
190
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600191 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700192}
193
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700194void intel_render_pass_destroy(struct intel_render_pass *rp)
195{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700196 intel_base_destroy(&rp->obj.base);
197}
198
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600199ICD_EXPORT VkResult VKAPI vkCreateFramebuffer(
200 VkDevice device,
201 const VkFramebufferCreateInfo* pCreateInfo,
202 VkFramebuffer* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700203{
204 struct intel_dev *dev = intel_dev(device);
205
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700206 return intel_fb_create(dev, pCreateInfo,
207 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700208}
209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210ICD_EXPORT VkResult VKAPI vkCreateRenderPass(
211 VkDevice device,
212 const VkRenderPassCreateInfo* pCreateInfo,
213 VkRenderPass* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700214{
215 struct intel_dev *dev = intel_dev(device);
216
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700217 return intel_render_pass_create(dev, pCreateInfo,
218 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700219}