blob: 9092080cb4da80037d07bb8c4026177a918486cd [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
Courtney Goeltzenleuchterda71cc32015-02-05 16:35:53 -070085 if (info->colorAttachmentCount == 0) {
86 width = layout->width0;
87 height = layout->height0;
88 }
89
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070090 if (width > layout->width0)
91 width = layout->width0;
92 if (height > layout->height0)
93 height = layout->height0;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070094 if (array_size > ds->array_size)
95 array_size = ds->array_size;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060096
Chia-I Wu4f7730d2015-02-18 15:21:38 -070097 if (ds->img->samples != info->sampleCount) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060098 intel_fb_destroy(fb);
99 return XGL_ERROR_INVALID_VALUE;
100 }
101
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700102 fb->ds = ds;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700103 } else {
104 fb->ds = NULL;
105 }
106
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600107 /* Behavior is undefined if width,height are larger
108 than an attachment in some direction, but Intel hardware
109 cannot handle this case */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700110 fb->width = width;
111 fb->height = height;
112 fb->array_size = array_size;
113
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600114 /* This information must match pipeline state */
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700115 fb->sample_count = info->sampleCount;
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600116
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700117 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700118
119 *fb_ret = fb;
120
121 return XGL_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700122}
123
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700124void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700125{
126 intel_base_destroy(&fb->obj.base);
127}
128
129static void render_pass_destroy(struct intel_obj *obj)
130{
Chia-I Wu768a14b2015-02-18 14:48:21 -0700131 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700132
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700133 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700134}
135
136XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700137 const XGL_RENDER_PASS_CREATE_INFO *info,
138 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700139{
140 struct intel_render_pass *rp;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700141
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700142 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
143 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
144 if (!rp)
145 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700146
147 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700148
Chia-I Wu9d748fd2015-02-18 14:46:55 -0700149 rp->fb = intel_fb(info->framebuffer);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700150 //TODO add any clear color ops
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}