blob: 804c64d186264371ad0a9739e2def7e67c0d6155 [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{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070035 struct intel_fb *fb = intel_fb_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070036
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,
Chia-I Wu9d748fd2015-02-18 14:46:55 -070042 struct intel_fb ** fb_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -070043{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070044 struct intel_fb *fb;
45 fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb),
Jon Ashburnc6f4a412014-12-24 12:38:36 -070046 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 Lobodzinskie2d07a52015-01-29 08:55:56 -060050 uint32_t width = info->width;
51 uint32_t height = info->height;
52 uint32_t layers = info->layers;
53 uint32_t i;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070054
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
Courtney Goeltzenleuchterda71cc32015-02-05 16:35:53 -070083 if (info->colorAttachmentCount == 0) {
84 width = layout->width0;
85 height = layout->height0;
86 }
87
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070088 if (width > layout->width0)
89 width = layout->width0;
90 if (height > layout->height0)
91 height = layout->height0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060092 if (layers > fb->ds->array_size)
93 layers = fb->ds->array_size;
94
95 if (fb->ds->img->samples != info->sampleCount) {
96 intel_fb_destroy(fb);
97 return XGL_ERROR_INVALID_VALUE;
98 }
99
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700100 } else {
101 fb->ds = NULL;
102 }
103
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600104 /* Behavior is undefined if width,height are larger
105 than an attachment in some direction, but Intel hardware
106 cannot handle this case */
107 fb->width = width;
108 fb->height = height;
109 fb->layer_count = layers;
110 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700111 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600112
113 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700114
115 *fb_ret = fb;
116
117 return XGL_SUCCESS;
118
119}
120
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700121void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700122{
123 intel_base_destroy(&fb->obj.base);
124}
125
126static void render_pass_destroy(struct intel_obj *obj)
127{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700128 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700129
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700130 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700131}
132
133XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700134 const XGL_RENDER_PASS_CREATE_INFO* info,
135 struct intel_render_pass** rp_ret)
136{
137 struct intel_render_pass *rp;
138 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
139 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
140 if (!rp)
141 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700142
143 rp->obj.destroy = render_pass_destroy;
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700144 rp->fb = intel_fb(info->framebuffer);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700145 //TODO add any clear color ops
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700146
147 *rp_ret = rp;
148
149 return XGL_SUCCESS;
150}
151
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700152void intel_render_pass_destroy(struct intel_render_pass *rp)
153{
154 rp->fb = NULL;
155
156 intel_base_destroy(&rp->obj.base);
157}
158
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700159XGL_RESULT XGLAPI xglCreateFramebuffer(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700160 XGL_DEVICE device,
161 const XGL_FRAMEBUFFER_CREATE_INFO* info,
162 XGL_FRAMEBUFFER* fb_ret)
163{
164 struct intel_dev *dev = intel_dev(device);
165
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700166 return intel_fb_create(dev, info, (struct intel_fb **) fb_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700167}
168
169
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700170XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700171 XGL_DEVICE device,
172 const XGL_RENDER_PASS_CREATE_INFO* info,
173 XGL_RENDER_PASS* rp_ret)
174{
175 struct intel_dev *dev = intel_dev(device);
176
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700177 return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700178}