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 | b1dbb37 | 2015-02-02 09:58:11 -0700 | [diff] [blame] | 31 | #include "cmd.h" |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 32 | #include "fb.h" |
| 33 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 34 | static void fb_destroy(struct intel_obj *obj) |
| 35 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 36 | struct intel_fb *fb = intel_fb_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 37 | |
| 38 | intel_fb_destroy(fb); |
| 39 | } |
| 40 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 41 | XGL_RESULT intel_fb_create(struct intel_dev *dev, |
| 42 | const XGL_FRAMEBUFFER_CREATE_INFO* info, |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 43 | struct intel_fb ** fb_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 44 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 45 | struct intel_fb *fb; |
| 46 | fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb), |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 47 | dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0); |
| 48 | if (!fb) |
| 49 | return XGL_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 50 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 51 | uint32_t width = info->width; |
| 52 | uint32_t height = info->height; |
| 53 | uint32_t layers = info->layers; |
| 54 | uint32_t i; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 55 | |
| 56 | for (i = 0; i < info->colorAttachmentCount; i++) { |
| 57 | const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &(info->pColorAttachments[i]); |
| 58 | const struct intel_rt_view *rt = intel_rt_view(att->view); |
| 59 | const struct intel_layout *layout = &rt->img->layout; |
| 60 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 61 | if (width > layout->width0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 62 | width = layout->width0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 63 | if (height > layout->height0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 64 | height = layout->height0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 65 | if (layers > rt->array_size) |
| 66 | layers = rt->array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 67 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 68 | if (rt->img->samples != info->sampleCount) { |
| 69 | intel_fb_destroy(fb); |
| 70 | return XGL_ERROR_INVALID_VALUE; |
| 71 | } |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 72 | fb->rt[i] = rt; |
| 73 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 74 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 75 | fb->rt_count = info->colorAttachmentCount; |
| 76 | |
| 77 | if (info->pDepthStencilAttachment) { |
| 78 | const struct intel_layout *layout; |
| 79 | |
| 80 | fb->ds = intel_ds_view(info->pDepthStencilAttachment->view); |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 81 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 82 | layout = &fb->ds->img->layout; |
| 83 | |
Courtney Goeltzenleuchter | da71cc3 | 2015-02-05 16:35:53 -0700 | [diff] [blame] | 84 | if (info->colorAttachmentCount == 0) { |
| 85 | width = layout->width0; |
| 86 | height = layout->height0; |
| 87 | } |
| 88 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 89 | if (width > layout->width0) |
| 90 | width = layout->width0; |
| 91 | if (height > layout->height0) |
| 92 | height = layout->height0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 93 | if (layers > fb->ds->array_size) |
| 94 | layers = fb->ds->array_size; |
| 95 | |
| 96 | if (fb->ds->img->samples != info->sampleCount) { |
| 97 | intel_fb_destroy(fb); |
| 98 | return XGL_ERROR_INVALID_VALUE; |
| 99 | } |
| 100 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 101 | } else { |
| 102 | fb->ds = NULL; |
| 103 | } |
| 104 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 105 | /* Behavior is undefined if width,height are larger |
| 106 | than an attachment in some direction, but Intel hardware |
| 107 | cannot handle this case */ |
| 108 | fb->width = width; |
| 109 | fb->height = height; |
| 110 | fb->layer_count = layers; |
| 111 | /* This information must match pipeline state */ |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 112 | fb->sample_count = info->sampleCount; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 113 | |
| 114 | fb->obj.destroy = fb_destroy; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 115 | |
| 116 | *fb_ret = fb; |
| 117 | |
| 118 | return XGL_SUCCESS; |
| 119 | |
| 120 | } |
| 121 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 122 | void intel_fb_destroy(struct intel_fb *fb) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 123 | { |
| 124 | intel_base_destroy(&fb->obj.base); |
| 125 | } |
| 126 | |
| 127 | static void render_pass_destroy(struct intel_obj *obj) |
| 128 | { |
| 129 | struct intel_render_pass *rp = intel_rp_from_obj(obj); |
| 130 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 131 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | XGL_RESULT intel_render_pass_create(struct intel_dev *dev, |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 135 | const XGL_RENDER_PASS_CREATE_INFO* info, |
| 136 | struct intel_render_pass** rp_ret) |
| 137 | { |
| 138 | struct intel_render_pass *rp; |
| 139 | rp = (struct intel_render_pass *) intel_base_create(dev, sizeof(*rp), |
| 140 | dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0); |
| 141 | if (!rp) |
| 142 | return XGL_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 143 | |
| 144 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 145 | rp->fb = intel_fb(info->framebuffer); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 146 | //TODO add any clear color ops |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 147 | |
| 148 | *rp_ret = rp; |
| 149 | |
| 150 | return XGL_SUCCESS; |
| 151 | } |
| 152 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 153 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 154 | { |
| 155 | rp->fb = NULL; |
| 156 | |
| 157 | intel_base_destroy(&rp->obj.base); |
| 158 | } |
| 159 | |
Jon Ashburn | b1dbb37 | 2015-02-02 09:58:11 -0700 | [diff] [blame] | 160 | void intel_cmd_begin_render_pass(struct intel_cmd *cmd, |
| 161 | const struct intel_render_pass *rp) |
| 162 | { |
| 163 | cmd->bind.render_pass = (struct intel_render_pass *) rp; |
| 164 | } |
| 165 | |
| 166 | void intel_cmd_end_render_pass(struct intel_cmd *cmd, |
| 167 | const struct intel_render_pass *rp) |
| 168 | { |
| 169 | //note what to do if rp != bound rp |
| 170 | cmd->bind.render_pass = 0; |
| 171 | } |
| 172 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 173 | XGL_RESULT XGLAPI xglCreateFramebuffer( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 174 | XGL_DEVICE device, |
| 175 | const XGL_FRAMEBUFFER_CREATE_INFO* info, |
| 176 | XGL_FRAMEBUFFER* fb_ret) |
| 177 | { |
| 178 | struct intel_dev *dev = intel_dev(device); |
| 179 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame^] | 180 | return intel_fb_create(dev, info, (struct intel_fb **) fb_ret); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 184 | XGL_RESULT XGLAPI xglCreateRenderPass( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 185 | XGL_DEVICE device, |
| 186 | const XGL_RENDER_PASS_CREATE_INFO* info, |
| 187 | XGL_RENDER_PASS* rp_ret) |
| 188 | { |
| 189 | struct intel_dev *dev = intel_dev(device); |
| 190 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 191 | 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] | 192 | } |
| 193 | |
Jon Ashburn | b1dbb37 | 2015-02-02 09:58:11 -0700 | [diff] [blame] | 194 | void XGLAPI xglCmdBeginRenderPass( |
| 195 | XGL_CMD_BUFFER cmdBuffer, |
| 196 | XGL_RENDER_PASS renderPass) |
| 197 | { |
| 198 | struct intel_cmd *cmd = intel_cmd(cmdBuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 199 | |
Jon Ashburn | b1dbb37 | 2015-02-02 09:58:11 -0700 | [diff] [blame] | 200 | intel_cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass); |
| 201 | } |
| 202 | |
| 203 | void XGLAPI xglCmdEndRenderPass( |
| 204 | XGL_CMD_BUFFER cmdBuffer, |
| 205 | XGL_RENDER_PASS renderPass) |
| 206 | { |
| 207 | struct intel_cmd *cmd = intel_cmd(cmdBuffer); |
| 208 | |
| 209 | intel_cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass); |
| 210 | } |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 211 | |