blob: 84905db642f032b5b409d529d721b04a096aa616 [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,
Chia-I Wu4f7730d2015-02-18 15:21:38 -070041 const XGL_FRAMEBUFFER_CREATE_INFO *info,
42 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;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070045 uint32_t width, height, array_size, i;
46
Chia-I Wu9d748fd2015-02-18 14:46:55 -070047 fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb),
Jon Ashburnc6f4a412014-12-24 12:38:36 -070048 dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0);
49 if (!fb)
50 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070051
Chia-I Wu4f7730d2015-02-18 15:21:38 -070052 width = info->width;
53 height = info->height;
54 array_size = info->layers;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070055
56 for (i = 0; i < info->colorAttachmentCount; i++) {
Chia-I Wu4f7730d2015-02-18 15:21:38 -070057 const XGL_COLOR_ATTACHMENT_BIND_INFO *att =
58 &info->pColorAttachments[i];
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070059 const struct intel_rt_view *rt = intel_rt_view(att->view);
60 const struct intel_layout *layout = &rt->img->layout;
61
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060062 if (width > layout->width0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070063 width = layout->width0;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060064 if (height > layout->height0)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070065 height = layout->height0;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070066 if (array_size > rt->array_size)
67 array_size = rt->array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070068
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060069 if (rt->img->samples != info->sampleCount) {
70 intel_fb_destroy(fb);
71 return XGL_ERROR_INVALID_VALUE;
72 }
Chia-I Wu4f7730d2015-02-18 15:21:38 -070073
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070074 fb->rt[i] = rt;
75 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060076
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070077 fb->rt_count = info->colorAttachmentCount;
78
79 if (info->pDepthStencilAttachment) {
Chia-I Wu4f7730d2015-02-18 15:21:38 -070080 const XGL_DEPTH_STENCIL_BIND_INFO *att =
81 info->pDepthStencilAttachment;
82 const struct intel_ds_view *ds = intel_ds_view(att->view);
83 const struct intel_layout *layout = &ds->img->layout;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070084
85 if (width > layout->width0)
86 width = layout->width0;
87 if (height > layout->height0)
88 height = layout->height0;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070089 if (array_size > ds->array_size)
90 array_size = ds->array_size;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060091
Chia-I Wu4f7730d2015-02-18 15:21:38 -070092 if (ds->img->samples != info->sampleCount) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060093 intel_fb_destroy(fb);
94 return XGL_ERROR_INVALID_VALUE;
95 }
96
Chia-I Wu4f7730d2015-02-18 15:21:38 -070097 fb->ds = ds;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070098 } else {
99 fb->ds = NULL;
100 }
101
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600102 /* Behavior is undefined if width,height are larger
103 than an attachment in some direction, but Intel hardware
104 cannot handle this case */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700105 fb->width = width;
106 fb->height = height;
107 fb->array_size = array_size;
108
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600109 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700110 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600111
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700112 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700113
114 *fb_ret = fb;
115
116 return XGL_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700117}
118
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700119void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700120{
121 intel_base_destroy(&fb->obj.base);
122}
123
124static void render_pass_destroy(struct intel_obj *obj)
125{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700126 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700127
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700128 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700129}
130
131XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700132 const XGL_RENDER_PASS_CREATE_INFO *info,
133 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700134{
135 struct intel_render_pass *rp;
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);
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,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700161 const XGL_FRAMEBUFFER_CREATE_INFO* pCreateInfo,
162 XGL_FRAMEBUFFER* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700163{
164 struct intel_dev *dev = intel_dev(device);
165
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700166 return intel_fb_create(dev, pCreateInfo,
167 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700168}
169
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700170XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700171 XGL_DEVICE device,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700172 const XGL_RENDER_PASS_CREATE_INFO* pCreateInfo,
173 XGL_RENDER_PASS* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700174{
175 struct intel_dev *dev = intel_dev(device);
176
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700177 return intel_render_pass_create(dev, pCreateInfo,
178 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700179}