blob: 3a48c9997ee00562b977fe8c35f4b925af9b9bd1 [file] [log] [blame]
Jon Ashburnc6f4a412014-12-24 12:38:36 -07001/*
2 * XGL
3 *
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
Jon Ashburnc6f4a412014-12-24 12:38:36 -070039XGL_RESULT intel_fb_create(struct intel_dev *dev,
Chia-I Wu4f7730d2015-02-18 15:21:38 -070040 const XGL_FRAMEBUFFER_CREATE_INFO *info,
41 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)
47 return XGL_ERROR_INVALID_VALUE;
48
Chia-I Wu9d748fd2015-02-18 14:46:55 -070049 fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb),
Jon Ashburnc6f4a412014-12-24 12:38:36 -070050 dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0);
51 if (!fb)
52 return XGL_ERROR_OUT_OF_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++) {
Chia-I Wu4f7730d2015-02-18 15:21:38 -070059 const XGL_COLOR_ATTACHMENT_BIND_INFO *att =
60 &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);
73 return XGL_ERROR_INVALID_VALUE;
74 }
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) {
Chia-I Wu4f7730d2015-02-18 15:21:38 -070082 const XGL_DEPTH_STENCIL_BIND_INFO *att =
83 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);
96 return XGL_ERROR_INVALID_VALUE;
97 }
98
Chia-I Wu4f7730d2015-02-18 15:21:38 -070099 fb->ds = ds;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700100 } else {
101 fb->ds = NULL;
102 }
103
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700104 fb->width = width;
105 fb->height = height;
106 fb->array_size = array_size;
107
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600108 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700109 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600110
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700111 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700112
113 *fb_ret = fb;
114
115 return XGL_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700116}
117
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700118void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700119{
120 intel_base_destroy(&fb->obj.base);
121}
122
123static void render_pass_destroy(struct intel_obj *obj)
124{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700125 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700126
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700127 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700128}
129
130XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700131 const XGL_RENDER_PASS_CREATE_INFO *info,
132 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700133{
134 struct intel_render_pass *rp;
Chia-I Wuba627862015-02-18 15:32:06 -0700135 uint32_t i;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700136
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700137 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
138 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
139 if (!rp)
140 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700141
142 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700143
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700144 rp->fb = intel_fb(info->framebuffer);
Chia-I Wuba627862015-02-18 15:32:06 -0700145
146 /* TODO add any clear color ops */
147 for (i = 0; i < info->colorAttachmentCount; i++)
148 assert(info->pColorLoadOps[i] != XGL_ATTACHMENT_LOAD_OP_CLEAR);
149 assert(info->depthLoadOp != XGL_ATTACHMENT_LOAD_OP_CLEAR);
150 assert(info->stencilLoadOp != XGL_ATTACHMENT_LOAD_OP_CLEAR);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700151
152 *rp_ret = rp;
153
154 return XGL_SUCCESS;
155}
156
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700157void intel_render_pass_destroy(struct intel_render_pass *rp)
158{
159 rp->fb = NULL;
160
161 intel_base_destroy(&rp->obj.base);
162}
163
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700164XGL_RESULT XGLAPI xglCreateFramebuffer(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700165 XGL_DEVICE device,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700166 const XGL_FRAMEBUFFER_CREATE_INFO* pCreateInfo,
167 XGL_FRAMEBUFFER* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700168{
169 struct intel_dev *dev = intel_dev(device);
170
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700171 return intel_fb_create(dev, pCreateInfo,
172 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700173}
174
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700175XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700176 XGL_DEVICE device,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700177 const XGL_RENDER_PASS_CREATE_INFO* pCreateInfo,
178 XGL_RENDER_PASS* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700179{
180 struct intel_dev *dev = intel_dev(device);
181
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700182 return intel_render_pass_create(dev, pCreateInfo,
183 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700184}