Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 27 | #include "mem.h" |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 28 | #include "obj.h" |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 29 | #include "view.h" |
| 30 | #include "img.h" |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 31 | #include "fb.h" |
| 32 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 33 | static void fb_destroy(struct intel_obj *obj) |
| 34 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 35 | struct intel_fb *fb = intel_fb_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 36 | |
| 37 | intel_fb_destroy(fb); |
| 38 | } |
| 39 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 40 | XGL_RESULT intel_fb_create(struct intel_dev *dev, |
| 41 | const XGL_FRAMEBUFFER_CREATE_INFO* info, |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 42 | struct intel_fb ** fb_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 43 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 44 | struct intel_fb *fb; |
| 45 | fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb), |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 46 | dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0); |
| 47 | if (!fb) |
| 48 | return XGL_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 49 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 50 | uint32_t width = info->width; |
| 51 | uint32_t height = info->height; |
| 52 | uint32_t layers = info->layers; |
| 53 | uint32_t i; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 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 Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 60 | if (width > layout->width0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 61 | width = layout->width0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 62 | if (height > layout->height0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 63 | height = layout->height0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 64 | if (layers > rt->array_size) |
| 65 | layers = rt->array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 66 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 67 | if (rt->img->samples != info->sampleCount) { |
| 68 | intel_fb_destroy(fb); |
| 69 | return XGL_ERROR_INVALID_VALUE; |
| 70 | } |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 71 | fb->rt[i] = rt; |
| 72 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 73 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 74 | 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 Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 80 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 81 | layout = &fb->ds->img->layout; |
| 82 | |
Courtney Goeltzenleuchter | da71cc3 | 2015-02-05 16:35:53 -0700 | [diff] [blame] | 83 | if (info->colorAttachmentCount == 0) { |
| 84 | width = layout->width0; |
| 85 | height = layout->height0; |
| 86 | } |
| 87 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 88 | if (width > layout->width0) |
| 89 | width = layout->width0; |
| 90 | if (height > layout->height0) |
| 91 | height = layout->height0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 92 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 100 | } else { |
| 101 | fb->ds = NULL; |
| 102 | } |
| 103 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 104 | /* 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 111 | fb->sample_count = info->sampleCount; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 112 | |
| 113 | fb->obj.destroy = fb_destroy; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 114 | |
| 115 | *fb_ret = fb; |
| 116 | |
| 117 | return XGL_SUCCESS; |
| 118 | |
| 119 | } |
| 120 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 121 | void intel_fb_destroy(struct intel_fb *fb) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 122 | { |
| 123 | intel_base_destroy(&fb->obj.base); |
| 124 | } |
| 125 | |
| 126 | static void render_pass_destroy(struct intel_obj *obj) |
| 127 | { |
Chia-I Wu | 768a14b | 2015-02-18 14:48:21 -0700 | [diff] [blame] | 128 | struct intel_render_pass *rp = intel_render_pass_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 129 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 130 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | XGL_RESULT intel_render_pass_create(struct intel_dev *dev, |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 134 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 142 | |
| 143 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 144 | rp->fb = intel_fb(info->framebuffer); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 145 | //TODO add any clear color ops |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 146 | |
| 147 | *rp_ret = rp; |
| 148 | |
| 149 | return XGL_SUCCESS; |
| 150 | } |
| 151 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 152 | void 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 Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 159 | XGL_RESULT XGLAPI xglCreateFramebuffer( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 160 | 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 Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 166 | return intel_fb_create(dev, info, (struct intel_fb **) fb_ret); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 170 | XGL_RESULT XGLAPI xglCreateRenderPass( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 171 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 177 | return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 178 | } |