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 | { |
| 35 | struct intel_framebuffer *fb = intel_fb_from_obj(obj); |
| 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, |
| 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame^] | 49 | |
| 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 Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 90 | |
| 91 | *fb_ret = fb; |
| 92 | |
| 93 | return XGL_SUCCESS; |
| 94 | |
| 95 | } |
| 96 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame^] | 97 | void intel_fb_destroy(struct intel_framebuffer *fb) |
| 98 | { |
| 99 | intel_base_destroy(&fb->obj.base); |
| 100 | } |
| 101 | |
| 102 | static void render_pass_destroy(struct intel_obj *obj) |
| 103 | { |
| 104 | struct intel_render_pass *rp = intel_rp_from_obj(obj); |
| 105 | |
| 106 | intel_rp_destroy(rp); |
| 107 | } |
| 108 | |
| 109 | XGL_RESULT intel_render_pass_create(struct intel_dev *dev, |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 110 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame^] | 118 | |
| 119 | rp->obj.destroy = render_pass_destroy; |
| 120 | rp->fb = intel_framebuffer(info->framebuffer); |
| 121 | //TODO add any clear color ops |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 122 | |
| 123 | *rp_ret = rp; |
| 124 | |
| 125 | return XGL_SUCCESS; |
| 126 | } |
| 127 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame^] | 128 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 129 | { |
| 130 | rp->fb = NULL; |
| 131 | |
| 132 | intel_base_destroy(&rp->obj.base); |
| 133 | } |
| 134 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 135 | XGL_RESULT XGLAPI intelCreateFramebuffer( |
| 136 | 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 | |
| 146 | XGL_RESULT XGLAPI intelCreateRenderPass( |
| 147 | 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 Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame^] | 153 | 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] | 154 | } |
| 155 | |
| 156 | |
| 157 | |