blob: 470b01e592160275d54ee11193bf07c9ba820775 [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 Wu4f7730d2015-02-18 15:21:38 -070054 width = info->width;
55 height = info->height;
56 array_size = info->layers;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070057
58 for (i = 0; i < info->colorAttachmentCount; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060059 const VkColorAttachmentBindInfo *att =
Chia-I Wu4f7730d2015-02-18 15:21:38 -070060 &info->pColorAttachments[i];
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070061 const struct intel_rt_view *rt = intel_rt_view(att->view);
62 const struct intel_layout *layout = &rt->img->layout;
63
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060064 if (width > layout->width0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070065 width = layout->width0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060066 if (height > layout->height0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070067 height = layout->height0;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070068 if (array_size > rt->array_size)
69 array_size = rt->array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070070
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060071 if (rt->img->samples != info->sampleCount) {
72 intel_fb_destroy(fb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060073 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060074 }
Chia-I Wu4f7730d2015-02-18 15:21:38 -070075
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070076 fb->rt[i] = rt;
77 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060078
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070079 fb->rt_count = info->colorAttachmentCount;
80
81 if (info->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060082 const VkDepthStencilBindInfo *att =
Chia-I Wu4f7730d2015-02-18 15:21:38 -070083 info->pDepthStencilAttachment;
84 const struct intel_ds_view *ds = intel_ds_view(att->view);
85 const struct intel_layout *layout = &ds->img->layout;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070086
87 if (width > layout->width0)
88 width = layout->width0;
89 if (height > layout->height0)
90 height = layout->height0;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070091 if (array_size > ds->array_size)
92 array_size = ds->array_size;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060093
Chia-I Wu4f7730d2015-02-18 15:21:38 -070094 if (ds->img->samples != info->sampleCount) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060095 intel_fb_destroy(fb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060097 }
98
Chia-I Wu4f7730d2015-02-18 15:21:38 -070099 fb->ds = ds;
Chia-I Wuc45db532015-02-19 11:20:38 -0700100
101 switch (att->layout) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
103 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
Chia-I Wuc45db532015-02-19 11:20:38 -0700104 fb->optimal_ds = true;
105 break;
106 default:
107 fb->optimal_ds = false;
108 break;
109 }
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700110 } else {
111 fb->ds = NULL;
Chia-I Wuc45db532015-02-19 11:20:38 -0700112 fb->optimal_ds = false;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700113 }
114
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700115 fb->width = width;
116 fb->height = height;
117 fb->array_size = array_size;
118
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600119 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700120 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600121
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700122 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700123
124 *fb_ret = fb;
125
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600126 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700127}
128
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700129void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700130{
131 intel_base_destroy(&fb->obj.base);
132}
133
134static void render_pass_destroy(struct intel_obj *obj)
135{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700136 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700137
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700138 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700139}
140
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141VkResult intel_render_pass_create(struct intel_dev *dev,
142 const VkRenderPassCreateInfo *info,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700143 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700144{
145 struct intel_render_pass *rp;
Chia-I Wuba627862015-02-18 15:32:06 -0700146 uint32_t i;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700147
Chia-I Wu545c2e12015-02-22 13:19:54 +0800148 rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600149 sizeof(*rp), dev->base.dbg, VK_OBJECT_TYPE_RENDER_PASS, info, 0);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700150 if (!rp)
Tony Barbour8205d902015-04-16 15:59:00 -0600151 return VK_ERROR_OUT_OF_HOST_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700152
153 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700154
Chris Forbesfff9bf42015-06-15 15:26:19 +1200155 rp->colorAttachmentCount = info->colorAttachmentCount;
156 rp->renderArea = info->renderArea;
157 rp->extent = info->extent;
158
159 if (rp->colorAttachmentCount) {
160 memcpy(rp->colorLoadOps, info->pColorLoadOps, rp->colorAttachmentCount * sizeof(rp->colorLoadOps[0]));
161 if (info->pColorLayouts) {
162 memcpy(rp->colorLayouts, info->pColorLayouts, rp->colorAttachmentCount * sizeof(rp->colorLayouts[0]));
163 }
164 if (info->pColorLoadClearValues) {
165 memcpy(rp->colorClearValues, info->pColorLoadClearValues, rp->colorAttachmentCount * sizeof(rp->colorClearValues[0]));
166 }
167 }
168
169 /* TODO: depth/stencil clear load ops */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600170 assert(info->depthLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR);
171 assert(info->stencilLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700172
Chris Forbesfff9bf42015-06-15 15:26:19 +1200173 /* TODO: MSAA resolves if/when we support MSAA. */
174 for (i = 0; i < info->colorAttachmentCount; i++)
175 assert(info->pColorStoreOps[i] != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
176 assert(info->depthStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
177 assert(info->stencilStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA);
178
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700179 *rp_ret = rp;
180
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600181 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700182}
183
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700184void intel_render_pass_destroy(struct intel_render_pass *rp)
185{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700186 intel_base_destroy(&rp->obj.base);
187}
188
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600189ICD_EXPORT VkResult VKAPI vkCreateFramebuffer(
190 VkDevice device,
191 const VkFramebufferCreateInfo* pCreateInfo,
192 VkFramebuffer* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700193{
194 struct intel_dev *dev = intel_dev(device);
195
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700196 return intel_fb_create(dev, pCreateInfo,
197 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700198}
199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200ICD_EXPORT VkResult VKAPI vkCreateRenderPass(
201 VkDevice device,
202 const VkRenderPassCreateInfo* pCreateInfo,
203 VkRenderPass* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700204{
205 struct intel_dev *dev = intel_dev(device);
206
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700207 return intel_render_pass_create(dev, pCreateInfo,
208 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700209}