blob: 6ccc3ee74cda35a42eca8f7f74263269d30e03bc [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
50 XGL_UINT width = 0, height = 0;
51 XGL_UINT i;
52
53 for (i = 0; i < info->colorAttachmentCount; i++) {
54 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &(info->pColorAttachments[i]);
55 const struct intel_rt_view *rt = intel_rt_view(att->view);
56 const struct intel_layout *layout = &rt->img->layout;
57
58 if (i == 0) {
59 width = layout->width0;
60 height = layout->height0;
61 } else {
62 if (width > layout->width0)
63 width = layout->width0;
64 if (height > layout->height0)
65 height = layout->height0;
66 }
67
68 fb->rt[i] = rt;
69 }
70 fb->rt_count = info->colorAttachmentCount;
71
72 if (info->pDepthStencilAttachment) {
73 const struct intel_layout *layout;
74
75 fb->ds = intel_ds_view(info->pDepthStencilAttachment->view);
76 layout = &fb->ds->img->layout;
77
78 if (width > layout->width0)
79 width = layout->width0;
80 if (height > layout->height0)
81 height = layout->height0;
82 } else {
83 fb->ds = NULL;
84 }
85
86 fb->sample_count = info->sampleCount;
87 fb->width = width;
88 fb->height = height;
89 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -070090
91 *fb_ret = fb;
92
93 return XGL_SUCCESS;
94
95}
96
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070097void intel_fb_destroy(struct intel_framebuffer *fb)
98{
99 intel_base_destroy(&fb->obj.base);
100}
101
102static void render_pass_destroy(struct intel_obj *obj)
103{
104 struct intel_render_pass *rp = intel_rp_from_obj(obj);
105
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -0700106 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700107}
108
109XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700110 const XGL_RENDER_PASS_CREATE_INFO* info,
111 struct intel_render_pass** rp_ret)
112{
113 struct intel_render_pass *rp;
114 rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp),
115 dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
116 if (!rp)
117 return XGL_ERROR_OUT_OF_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700118
119 rp->obj.destroy = render_pass_destroy;
120 rp->fb = intel_framebuffer(info->framebuffer);
121 //TODO add any clear color ops
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700122
123 *rp_ret = rp;
124
125 return XGL_SUCCESS;
126}
127
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700128void intel_render_pass_destroy(struct intel_render_pass *rp)
129{
130 rp->fb = NULL;
131
132 intel_base_destroy(&rp->obj.base);
133}
134
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700135XGL_RESULT XGLAPI xglCreateFramebuffer(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700136 XGL_DEVICE device,
137 const XGL_FRAMEBUFFER_CREATE_INFO* info,
138 XGL_FRAMEBUFFER* fb_ret)
139{
140 struct intel_dev *dev = intel_dev(device);
141
142 return intel_fb_create(dev, info, (struct intel_framebuffer **) fb_ret);
143}
144
145
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700146XGL_RESULT XGLAPI xglCreateRenderPass(
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700147 XGL_DEVICE device,
148 const XGL_RENDER_PASS_CREATE_INFO* info,
149 XGL_RENDER_PASS* rp_ret)
150{
151 struct intel_dev *dev = intel_dev(device);
152
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700153 return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700154}
155
156
157