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 | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 39 | VkResult intel_fb_create(struct intel_dev *dev, |
| 40 | const VkFramebufferCreateInfo *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 | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 50 | sizeof(*fb), dev->base.dbg, VK_OBJECT_TYPE_FRAMEBUFFER, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 51 | if (!fb) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 52 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 53 | |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 54 | fb->view_count = info->colorAttachmentCount; |
| 55 | if (info->pDepthStencilAttachment) |
| 56 | fb->view_count++; |
| 57 | |
| 58 | fb->views = intel_alloc(fb, sizeof(fb->views[0]) * fb->view_count, 0, |
| 59 | VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 60 | if (!fb->views) { |
| 61 | intel_fb_destroy(fb); |
| 62 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 63 | } |
| 64 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 65 | width = info->width; |
| 66 | height = info->height; |
| 67 | array_size = info->layers; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 68 | |
| 69 | for (i = 0; i < info->colorAttachmentCount; i++) { |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 70 | const VkColorAttachmentBindInfo *att = &info->pColorAttachments[i]; |
| 71 | const struct intel_att_view *view = |
| 72 | intel_att_view_from_color(att->view); |
| 73 | const struct intel_layout *layout = &view->img->layout; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 74 | |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 75 | if (width > layout->width0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 76 | width = layout->width0; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 77 | if (height > layout->height0) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 78 | height = layout->height0; |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 79 | if (array_size > view->array_size) |
| 80 | array_size = view->array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 81 | |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 82 | if (view->img->samples != info->sampleCount) { |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 83 | intel_fb_destroy(fb); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | return VK_ERROR_INVALID_VALUE; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 85 | } |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 86 | |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 87 | fb->views[i] = view; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 88 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 89 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 90 | if (info->pDepthStencilAttachment) { |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 91 | const VkDepthStencilBindInfo *att = info->pDepthStencilAttachment; |
| 92 | const struct intel_att_view *view = intel_att_view_from_ds(att->view); |
| 93 | const struct intel_layout *layout = &view->img->layout; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 94 | |
| 95 | if (width > layout->width0) |
| 96 | width = layout->width0; |
| 97 | if (height > layout->height0) |
| 98 | height = layout->height0; |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 99 | if (array_size > view->array_size) |
| 100 | array_size = view->array_size; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 101 | |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 102 | if (view->img->samples != info->sampleCount) { |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 103 | intel_fb_destroy(fb); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | return VK_ERROR_INVALID_VALUE; |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 105 | } |
| 106 | |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 107 | fb->views[info->colorAttachmentCount] = view; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 108 | } |
| 109 | |
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 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | return VK_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 | { |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 126 | if (fb->views) |
| 127 | intel_free(fb, fb->views); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 128 | intel_base_destroy(&fb->obj.base); |
| 129 | } |
| 130 | |
| 131 | static void render_pass_destroy(struct intel_obj *obj) |
| 132 | { |
Chia-I Wu | 768a14b | 2015-02-18 14:48:21 -0700 | [diff] [blame] | 133 | struct intel_render_pass *rp = intel_render_pass_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 134 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 135 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 138 | VkResult intel_render_pass_create(struct intel_dev *dev, |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 139 | const VkRenderPassCreateInfo *info, |
| 140 | struct intel_render_pass **rp_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 141 | { |
| 142 | struct intel_render_pass *rp; |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 143 | uint32_t i; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 144 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 145 | rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 146 | sizeof(*rp), dev->base.dbg, VK_OBJECT_TYPE_RENDER_PASS, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 147 | if (!rp) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 148 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 149 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 150 | rp->attachment_count = info->colorAttachmentCount; |
| 151 | if (info->depthStencilFormat != VK_FORMAT_UNDEFINED) |
| 152 | rp->attachment_count++; |
| 153 | |
| 154 | rp->subpass_count = 1; |
| 155 | |
| 156 | rp->attachments = intel_alloc(rp, |
| 157 | sizeof(rp->attachments[0]) * rp->attachment_count + |
| 158 | sizeof(rp->subpasses[0]) * rp->subpass_count, 0, |
| 159 | VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 160 | if (!rp->attachments) { |
| 161 | intel_render_pass_destroy(rp); |
| 162 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 163 | } |
| 164 | |
| 165 | rp->subpasses = (struct intel_render_pass_subpass *) |
| 166 | (rp->attachments + rp->attachment_count); |
| 167 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 168 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 169 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 170 | for (i = 0; i < info->colorAttachmentCount; i++) { |
| 171 | struct intel_render_pass_attachment *att = &rp->attachments[i]; |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame] | 172 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 173 | att->format = info->pColorFormats[i]; |
| 174 | att->sample_count = info->sampleCount; |
| 175 | att->initial_layout = info->pColorLayouts[i]; |
| 176 | att->final_layout = info->pColorLayouts[i]; |
| 177 | |
| 178 | att->clear_on_load = |
| 179 | (info->pColorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 180 | att->disable_store = |
| 181 | (info->pColorStoreOps[i] == VK_ATTACHMENT_STORE_OP_DONT_CARE); |
| 182 | |
| 183 | att->stencil_clear_on_load = false; |
| 184 | att->stencil_disable_store = true; |
| 185 | |
| 186 | att->clear_val.color = info->pColorLoadClearValues[i]; |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame] | 187 | } |
| 188 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 189 | if (info->depthStencilFormat != VK_FORMAT_UNDEFINED) { |
| 190 | struct intel_render_pass_attachment *att = |
| 191 | &rp->attachments[info->colorAttachmentCount]; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 192 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 193 | att->format = info->depthStencilFormat; |
| 194 | att->sample_count = info->sampleCount; |
| 195 | att->initial_layout = info->depthStencilLayout; |
| 196 | att->final_layout = info->depthStencilLayout; |
| 197 | |
| 198 | att->clear_on_load = |
| 199 | (info->depthLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 200 | att->disable_store = |
| 201 | (info->depthStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE); |
| 202 | |
| 203 | att->stencil_clear_on_load = |
| 204 | (info->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 205 | att->stencil_disable_store = |
| 206 | (info->stencilStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE); |
| 207 | |
| 208 | att->clear_val.ds.depth = info->depthLoadClearValue; |
| 209 | att->clear_val.ds.stencil = info->stencilLoadClearValue; |
Chia-I Wu | 1af1a78 | 2015-07-09 10:46:39 +0800 | [diff] [blame] | 210 | } |
| 211 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 212 | for (i = 0; i < rp->subpass_count; i++) { |
| 213 | struct intel_render_pass_subpass *subpass = &rp->subpasses[i]; |
| 214 | uint32_t j; |
| 215 | |
| 216 | for (j = 0; j < info->colorAttachmentCount; j++) { |
| 217 | subpass->color_indices[j] = j; |
| 218 | subpass->resolve_indices[j] = 0xffffffffu; |
| 219 | subpass->color_layouts[j] = info->pColorLayouts[j]; |
| 220 | } |
| 221 | |
| 222 | subpass->color_count = info->colorAttachmentCount; |
| 223 | |
| 224 | subpass->ds_index = |
| 225 | (info->depthStencilFormat != VK_FORMAT_UNDEFINED) ? |
| 226 | info->colorAttachmentCount : 0xffffffffu; |
| 227 | subpass->ds_layout = info->depthStencilLayout; |
| 228 | |
| 229 | switch (info->depthStencilLayout) { |
| 230 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 231 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 232 | subpass->ds_optimal = true; |
| 233 | break; |
| 234 | default: |
| 235 | subpass->ds_optimal = false; |
| 236 | break; |
| 237 | } |
| 238 | } |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame] | 239 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 240 | *rp_ret = rp; |
| 241 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 242 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 245 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 246 | { |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame^] | 247 | if (rp->attachments) |
| 248 | intel_free(rp, rp->attachments); |
| 249 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 250 | intel_base_destroy(&rp->obj.base); |
| 251 | } |
| 252 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 253 | ICD_EXPORT VkResult VKAPI vkCreateFramebuffer( |
| 254 | VkDevice device, |
| 255 | const VkFramebufferCreateInfo* pCreateInfo, |
| 256 | VkFramebuffer* pFramebuffer) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 257 | { |
| 258 | struct intel_dev *dev = intel_dev(device); |
| 259 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 260 | return intel_fb_create(dev, pCreateInfo, |
| 261 | (struct intel_fb **) pFramebuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 264 | ICD_EXPORT VkResult VKAPI vkCreateRenderPass( |
| 265 | VkDevice device, |
| 266 | const VkRenderPassCreateInfo* pCreateInfo, |
| 267 | VkRenderPass* pRenderPass) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 268 | { |
| 269 | struct intel_dev *dev = intel_dev(device); |
| 270 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 271 | return intel_render_pass_create(dev, pCreateInfo, |
| 272 | (struct intel_render_pass **) pRenderPass); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 273 | } |