blob: a5d1ce787faab892a7e475ec5e572b955f3244a4 [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"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070027#include "mem.h"
Jon Ashburnc6f4a412014-12-24 12:38:36 -070028#include "obj.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070029#include "view.h"
30#include "img.h"
Jon Ashburnb1dbb372015-02-02 09:58:11 -070031#include "cmd.h"
Jon Ashburnc6f4a412014-12-24 12:38:36 -070032#include "fb.h"
33
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070034static void fb_destroy(struct intel_obj *obj)
35{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070036 struct intel_fb *fb = intel_fb_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070037
38 intel_fb_destroy(fb);
39}
40
Jon Ashburnc6f4a412014-12-24 12:38:36 -070041XGL_RESULT intel_fb_create(struct intel_dev *dev,
42 const XGL_FRAMEBUFFER_CREATE_INFO* info,
Chia-I Wu9d748fd2015-02-18 14:46:55 -070043 struct intel_fb ** fb_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -070044{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070045 struct intel_fb *fb;
46 fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb),
Jon Ashburnc6f4a412014-12-24 12:38:36 -070047 dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0);
48 if (!fb)
49 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070050
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060051 uint32_t width = info->width;
52 uint32_t height = info->height;
53 uint32_t layers = info->layers;
54 uint32_t i;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070055
56 for (i = 0; i < info->colorAttachmentCount; i++) {
57 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &(info->pColorAttachments[i]);
58 const struct intel_rt_view *rt = intel_rt_view(att->view);
59 const struct intel_layout *layout = &rt->img->layout;
60
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060061 if (width > layout->width0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070062 width = layout->width0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060063 if (height > layout->height0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070064 height = layout->height0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060065 if (layers > rt->array_size)
66 layers = rt->array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070067
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060068 if (rt->img->samples != info->sampleCount) {
69 intel_fb_destroy(fb);
70 return XGL_ERROR_INVALID_VALUE;
71 }
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070072 fb->rt[i] = rt;
73 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060074
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070075 fb->rt_count = info->colorAttachmentCount;
76
77 if (info->pDepthStencilAttachment) {
78 const struct intel_layout *layout;
79
80 fb->ds = intel_ds_view(info->pDepthStencilAttachment->view);
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060081
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070082 layout = &fb->ds->img->layout;
83
Courtney Goeltzenleuchterda71cc32015-02-05 16:35:53 -070084 if (info->colorAttachmentCount == 0) {
85 width = layout->width0;
86 height = layout->height0;
87 }
88
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070089 if (width > layout->width0)
90 width = layout->width0;
91 if (height > layout->height0)
92 height = layout->height0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060093 if (layers > fb->ds->array_size)
94 layers = fb->ds->array_size;
95
96 if (fb->ds->img->samples != info->sampleCount) {
97 intel_fb_destroy(fb);
98 return XGL_ERROR_INVALID_VALUE;
99 }
100
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700101 } else {
102 fb->ds = NULL;
103 }
104
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600105 /* Behavior is undefined if width,height are larger
106 than an attachment in some direction, but Intel hardware
107 cannot handle this case */
108 fb->width = width;
109 fb->height = height;
110 fb->layer_count = layers;
111 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700112 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600113
114 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700115
116 *fb_ret = fb;
117
118 return XGL_SUCCESS;
119
120}
121
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700122void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700123{
124 intel_base_destroy(&fb->obj.base);
125}
126
127static void render_pass_destroy(struct intel_obj *obj)
128{
129 struct intel_render_pass *rp = intel_rp_from_obj(obj);
130
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700131 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700132}
133
134XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700135 const XGL_RENDER_PASS_CREATE_INFO* info,
136 struct intel_render_pass** rp_ret)
137{
138 struct intel_render_pass *rp;
139 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
140 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
141 if (!rp)
142 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700143
144 rp->obj.destroy = render_pass_destroy;
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700145 rp->fb = intel_fb(info->framebuffer);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700146 //TODO add any clear color ops
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700147
148 *rp_ret = rp;
149
150 return XGL_SUCCESS;
151}
152
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700153void intel_render_pass_destroy(struct intel_render_pass *rp)
154{
155 rp->fb = NULL;
156
157 intel_base_destroy(&rp->obj.base);
158}
159
Jon Ashburnb1dbb372015-02-02 09:58:11 -0700160void intel_cmd_begin_render_pass(struct intel_cmd *cmd,
161 const struct intel_render_pass *rp)
162{
163 cmd->bind.render_pass = (struct intel_render_pass *) rp;
164}
165
166void intel_cmd_end_render_pass(struct intel_cmd *cmd,
167 const struct intel_render_pass *rp)
168{
169 //note what to do if rp != bound rp
170 cmd->bind.render_pass = 0;
171}
172
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700173XGL_RESULT XGLAPI xglCreateFramebuffer(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700174 XGL_DEVICE device,
175 const XGL_FRAMEBUFFER_CREATE_INFO* info,
176 XGL_FRAMEBUFFER* fb_ret)
177{
178 struct intel_dev *dev = intel_dev(device);
179
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700180 return intel_fb_create(dev, info, (struct intel_fb **) fb_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700181}
182
183
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700184XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700185 XGL_DEVICE device,
186 const XGL_RENDER_PASS_CREATE_INFO* info,
187 XGL_RENDER_PASS* rp_ret)
188{
189 struct intel_dev *dev = intel_dev(device);
190
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700191 return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700192}
193
Jon Ashburnb1dbb372015-02-02 09:58:11 -0700194void XGLAPI xglCmdBeginRenderPass(
195 XGL_CMD_BUFFER cmdBuffer,
196 XGL_RENDER_PASS renderPass)
197{
198 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700199
Jon Ashburnb1dbb372015-02-02 09:58:11 -0700200 intel_cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
201}
202
203void XGLAPI xglCmdEndRenderPass(
204 XGL_CMD_BUFFER cmdBuffer,
205 XGL_RENDER_PASS renderPass)
206{
207 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
208
209 intel_cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
210}
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700211