Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 2 | * Vulkan |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 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" |
| 27 | #include "obj.h" |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 28 | #include "view.h" |
| 29 | #include "img.h" |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 30 | #include "fb.h" |
| 31 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 32 | static void fb_destroy(struct intel_obj *obj) |
| 33 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 34 | struct intel_fb *fb = intel_fb_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 35 | |
| 36 | intel_fb_destroy(fb); |
| 37 | } |
| 38 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 39 | VK_RESULT intel_fb_create(struct intel_dev *dev, |
| 40 | const VK_FRAMEBUFFER_CREATE_INFO *info, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 41 | struct intel_fb **fb_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 42 | { |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 43 | struct intel_fb *fb; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 44 | uint32_t width, height, array_size, i; |
| 45 | |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 46 | if (info->colorAttachmentCount > INTEL_MAX_RENDER_TARGETS) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 47 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 48 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 49 | fb = (struct intel_fb *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 50 | sizeof(*fb), dev->base.dbg, VK_DBG_OBJECT_FRAMEBUFFER, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 51 | if (!fb) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 52 | return VK_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 53 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 54 | width = info->width; |
| 55 | height = info->height; |
| 56 | array_size = info->layers; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 57 | |
| 58 | for (i = 0; i < info->colorAttachmentCount; i++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 59 | const VK_COLOR_ATTACHMENT_BIND_INFO *att = |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 60 | &info->pColorAttachments[i]; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 61 | const struct intel_rt_view *rt = intel_rt_view(att->view); |
| 62 | const struct intel_layout *layout = &rt->img->layout; |
| 63 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 64 | if (width > layout->width0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 65 | width = layout->width0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 66 | if (height > layout->height0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 67 | height = layout->height0; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 68 | if (array_size > rt->array_size) |
| 69 | array_size = rt->array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 70 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 71 | if (rt->img->samples != info->sampleCount) { |
| 72 | intel_fb_destroy(fb); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 73 | return VK_ERROR_INVALID_VALUE; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 74 | } |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 75 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 76 | fb->rt[i] = rt; |
| 77 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 78 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 79 | fb->rt_count = info->colorAttachmentCount; |
| 80 | |
| 81 | if (info->pDepthStencilAttachment) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 82 | const VK_DEPTH_STENCIL_BIND_INFO *att = |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 83 | info->pDepthStencilAttachment; |
| 84 | const struct intel_ds_view *ds = intel_ds_view(att->view); |
| 85 | const struct intel_layout *layout = &ds->img->layout; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 86 | |
| 87 | if (width > layout->width0) |
| 88 | width = layout->width0; |
| 89 | if (height > layout->height0) |
| 90 | height = layout->height0; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 91 | if (array_size > ds->array_size) |
| 92 | array_size = ds->array_size; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 93 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 94 | if (ds->img->samples != info->sampleCount) { |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 95 | intel_fb_destroy(fb); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 96 | return VK_ERROR_INVALID_VALUE; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 97 | } |
| 98 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 99 | fb->ds = ds; |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 100 | |
| 101 | switch (att->layout) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 102 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 103 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 104 | fb->optimal_ds = true; |
| 105 | break; |
| 106 | default: |
| 107 | fb->optimal_ds = false; |
| 108 | break; |
| 109 | } |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 110 | } else { |
| 111 | fb->ds = NULL; |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 112 | fb->optimal_ds = false; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 115 | fb->width = width; |
| 116 | fb->height = height; |
| 117 | fb->array_size = array_size; |
| 118 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 119 | /* This information must match pipeline state */ |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 120 | fb->sample_count = info->sampleCount; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 121 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 122 | fb->obj.destroy = fb_destroy; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 123 | |
| 124 | *fb_ret = fb; |
| 125 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 126 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 129 | void intel_fb_destroy(struct intel_fb *fb) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 130 | { |
| 131 | intel_base_destroy(&fb->obj.base); |
| 132 | } |
| 133 | |
| 134 | static void render_pass_destroy(struct intel_obj *obj) |
| 135 | { |
Chia-I Wu | 768a14b | 2015-02-18 14:48:21 -0700 | [diff] [blame] | 136 | struct intel_render_pass *rp = intel_render_pass_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 137 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 138 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 141 | VK_RESULT intel_render_pass_create(struct intel_dev *dev, |
| 142 | const VK_RENDER_PASS_CREATE_INFO *info, |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 143 | struct intel_render_pass **rp_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 144 | { |
| 145 | struct intel_render_pass *rp; |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 146 | uint32_t i; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 147 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 148 | rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 149 | sizeof(*rp), dev->base.dbg, VK_DBG_OBJECT_RENDER_PASS, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 150 | if (!rp) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 151 | return VK_ERROR_OUT_OF_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 152 | |
| 153 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 154 | |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 155 | /* TODO add any clear color ops */ |
| 156 | for (i = 0; i < info->colorAttachmentCount; i++) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 157 | assert(info->pColorLoadOps[i] != VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 158 | assert(info->depthLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 159 | assert(info->stencilLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 160 | |
| 161 | *rp_ret = rp; |
| 162 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 163 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 166 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 167 | { |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 168 | intel_base_destroy(&rp->obj.base); |
| 169 | } |
| 170 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 171 | ICD_EXPORT VK_RESULT VKAPI vkCreateFramebuffer( |
| 172 | VK_DEVICE device, |
| 173 | const VK_FRAMEBUFFER_CREATE_INFO* pCreateInfo, |
| 174 | VK_FRAMEBUFFER* pFramebuffer) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 175 | { |
| 176 | struct intel_dev *dev = intel_dev(device); |
| 177 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 178 | return intel_fb_create(dev, pCreateInfo, |
| 179 | (struct intel_fb **) pFramebuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 182 | ICD_EXPORT VK_RESULT VKAPI vkCreateRenderPass( |
| 183 | VK_DEVICE device, |
| 184 | const VK_RENDER_PASS_CREATE_INFO* pCreateInfo, |
| 185 | VK_RENDER_PASS* pRenderPass) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 186 | { |
| 187 | struct intel_dev *dev = intel_dev(device); |
| 188 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 189 | return intel_render_pass_create(dev, pCreateInfo, |
| 190 | (struct intel_render_pass **) pRenderPass); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 191 | } |