blob: 2b4925babfc2944b134f16b00b4bc1c8bdd56603 [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 Ashburnc6f4a412014-12-24 12:38:36 -070031#include "fb.h"
32
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070033static void fb_destroy(struct intel_obj *obj)
34{
35 struct intel_framebuffer *fb = intel_fb_from_obj(obj);
36
37 intel_fb_destroy(fb);
38}
39
Jon Ashburnc6f4a412014-12-24 12:38:36 -070040XGL_RESULT intel_fb_create(struct intel_dev *dev,
41 const XGL_FRAMEBUFFER_CREATE_INFO* info,
42 struct intel_framebuffer ** fb_ret)
43{
44 struct intel_framebuffer *fb;
45 fb = (struct intel_framebuffer *) intel_base_create(dev, sizeof(*fb),
46 dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0);
47 if (!fb)
48 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070049
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060050 XGL_UINT width = info->width;
51 XGL_UINT height = info->height;
52 XGL_UINT layers = info->layers;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070053 XGL_UINT i;
54
55 for (i = 0; i < info->colorAttachmentCount; i++) {
56 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &(info->pColorAttachments[i]);
57 const struct intel_rt_view *rt = intel_rt_view(att->view);
58 const struct intel_layout *layout = &rt->img->layout;
59
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060060 if (width > layout->width0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070061 width = layout->width0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060062 if (height > layout->height0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070063 height = layout->height0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060064 if (layers > rt->array_size)
65 layers = rt->array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070066
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060067 if (rt->img->samples != info->sampleCount) {
68 intel_fb_destroy(fb);
69 return XGL_ERROR_INVALID_VALUE;
70 }
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070071 fb->rt[i] = rt;
72 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060073
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070074 fb->rt_count = info->colorAttachmentCount;
75
76 if (info->pDepthStencilAttachment) {
77 const struct intel_layout *layout;
78
79 fb->ds = intel_ds_view(info->pDepthStencilAttachment->view);
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060080
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070081 layout = &fb->ds->img->layout;
82
83 if (width > layout->width0)
84 width = layout->width0;
85 if (height > layout->height0)
86 height = layout->height0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060087 if (layers > fb->ds->array_size)
88 layers = fb->ds->array_size;
89
90 if (fb->ds->img->samples != info->sampleCount) {
91 intel_fb_destroy(fb);
92 return XGL_ERROR_INVALID_VALUE;
93 }
94
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070095 } else {
96 fb->ds = NULL;
97 }
98
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060099 /* Behavior is undefined if width,height are larger
100 than an attachment in some direction, but Intel hardware
101 cannot handle this case */
102 fb->width = width;
103 fb->height = height;
104 fb->layer_count = layers;
105 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700106 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600107
108 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700109
110 *fb_ret = fb;
111
112 return XGL_SUCCESS;
113
114}
115
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700116void intel_fb_destroy(struct intel_framebuffer *fb)
117{
118 intel_base_destroy(&fb->obj.base);
119}
120
121static void render_pass_destroy(struct intel_obj *obj)
122{
123 struct intel_render_pass *rp = intel_rp_from_obj(obj);
124
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700125 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700126}
127
128XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700129 const XGL_RENDER_PASS_CREATE_INFO* info,
130 struct intel_render_pass** rp_ret)
131{
132 struct intel_render_pass *rp;
133 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
134 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
135 if (!rp)
136 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700137
138 rp->obj.destroy = render_pass_destroy;
139 rp->fb = intel_framebuffer(info->framebuffer);
140 //TODO add any clear color ops
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700141
142 *rp_ret = rp;
143
144 return XGL_SUCCESS;
145}
146
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700147void intel_render_pass_destroy(struct intel_render_pass *rp)
148{
149 rp->fb = NULL;
150
151 intel_base_destroy(&rp->obj.base);
152}
153
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700154XGL_RESULT XGLAPI xglCreateFramebuffer(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700155 XGL_DEVICE device,
156 const XGL_FRAMEBUFFER_CREATE_INFO* info,
157 XGL_FRAMEBUFFER* fb_ret)
158{
159 struct intel_dev *dev = intel_dev(device);
160
161 return intel_fb_create(dev, info, (struct intel_framebuffer **) fb_ret);
162}
163
164
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700165XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700166 XGL_DEVICE device,
167 const XGL_RENDER_PASS_CREATE_INFO* info,
168 XGL_RENDER_PASS* rp_ret)
169{
170 struct intel_dev *dev = intel_dev(device);
171
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700172 return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700173}
174
175
176