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, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 41 | const XGL_FRAMEBUFFER_CREATE_INFO *info, |
| 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; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 45 | uint32_t width, height, array_size, i; |
| 46 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 47 | fb = (struct intel_fb *) intel_base_create(dev, sizeof(*fb), |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 48 | dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0); |
| 49 | if (!fb) |
| 50 | return XGL_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 51 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 52 | width = info->width; |
| 53 | height = info->height; |
| 54 | array_size = info->layers; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 55 | |
| 56 | for (i = 0; i < info->colorAttachmentCount; i++) { |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 57 | const XGL_COLOR_ATTACHMENT_BIND_INFO *att = |
| 58 | &info->pColorAttachments[i]; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 59 | const struct intel_rt_view *rt = intel_rt_view(att->view); |
| 60 | const struct intel_layout *layout = &rt->img->layout; |
| 61 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 62 | if (width > layout->width0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 63 | width = layout->width0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 64 | if (height > layout->height0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 65 | height = layout->height0; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 66 | if (array_size > rt->array_size) |
| 67 | array_size = rt->array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 68 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 69 | if (rt->img->samples != info->sampleCount) { |
| 70 | intel_fb_destroy(fb); |
| 71 | return XGL_ERROR_INVALID_VALUE; |
| 72 | } |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 73 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 74 | fb->rt[i] = rt; |
| 75 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 76 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 77 | fb->rt_count = info->colorAttachmentCount; |
| 78 | |
| 79 | if (info->pDepthStencilAttachment) { |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 80 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 84 | |
Courtney Goeltzenleuchter | da71cc3 | 2015-02-05 16:35:53 -0700 | [diff] [blame] | 85 | if (info->colorAttachmentCount == 0) { |
| 86 | width = layout->width0; |
| 87 | height = layout->height0; |
| 88 | } |
| 89 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 90 | if (width > layout->width0) |
| 91 | width = layout->width0; |
| 92 | if (height > layout->height0) |
| 93 | height = layout->height0; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 94 | if (array_size > ds->array_size) |
| 95 | array_size = ds->array_size; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 96 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 97 | if (ds->img->samples != info->sampleCount) { |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 98 | intel_fb_destroy(fb); |
| 99 | return XGL_ERROR_INVALID_VALUE; |
| 100 | } |
| 101 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 102 | fb->ds = ds; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 103 | } else { |
| 104 | fb->ds = NULL; |
| 105 | } |
| 106 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 107 | /* 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 Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 110 | fb->width = width; |
| 111 | fb->height = height; |
| 112 | fb->array_size = array_size; |
| 113 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 114 | /* This information must match pipeline state */ |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 115 | fb->sample_count = info->sampleCount; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 116 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 117 | fb->obj.destroy = fb_destroy; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 118 | |
| 119 | *fb_ret = fb; |
| 120 | |
| 121 | return XGL_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 124 | void intel_fb_destroy(struct intel_fb *fb) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 125 | { |
| 126 | intel_base_destroy(&fb->obj.base); |
| 127 | } |
| 128 | |
| 129 | static void render_pass_destroy(struct intel_obj *obj) |
| 130 | { |
Chia-I Wu | 768a14b | 2015-02-18 14:48:21 -0700 | [diff] [blame] | 131 | struct intel_render_pass *rp = intel_render_pass_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 132 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 133 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | XGL_RESULT intel_render_pass_create(struct intel_dev *dev, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 137 | const XGL_RENDER_PASS_CREATE_INFO *info, |
| 138 | struct intel_render_pass **rp_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 139 | { |
| 140 | struct intel_render_pass *rp; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 141 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 142 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 146 | |
| 147 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 148 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 149 | rp->fb = intel_fb(info->framebuffer); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 150 | //TODO add any clear color ops |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 151 | |
| 152 | *rp_ret = rp; |
| 153 | |
| 154 | return XGL_SUCCESS; |
| 155 | } |
| 156 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 157 | void 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 Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 164 | XGL_RESULT XGLAPI xglCreateFramebuffer( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 165 | XGL_DEVICE device, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 166 | const XGL_FRAMEBUFFER_CREATE_INFO* pCreateInfo, |
| 167 | XGL_FRAMEBUFFER* pFramebuffer) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 168 | { |
| 169 | struct intel_dev *dev = intel_dev(device); |
| 170 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 171 | return intel_fb_create(dev, pCreateInfo, |
| 172 | (struct intel_fb **) pFramebuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 175 | XGL_RESULT XGLAPI xglCreateRenderPass( |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 176 | XGL_DEVICE device, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 177 | const XGL_RENDER_PASS_CREATE_INFO* pCreateInfo, |
| 178 | XGL_RENDER_PASS* pRenderPass) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 179 | { |
| 180 | struct intel_dev *dev = intel_dev(device); |
| 181 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame^] | 182 | return intel_render_pass_create(dev, pCreateInfo, |
| 183 | (struct intel_render_pass **) pRenderPass); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 184 | } |