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, |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 40 | const VkFramebufferCreateInfo *info, |
| 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 | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 46 | fb = (struct intel_fb *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 47 | sizeof(*fb), dev->base.dbg, VK_OBJECT_TYPE_FRAMEBUFFER, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 48 | if (!fb) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 49 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 50 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 51 | fb->view_count = info->attachmentCount; |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 52 | fb->views = intel_alloc(fb, sizeof(fb->views[0]) * fb->view_count, 0, |
| 53 | VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 54 | if (!fb->views) { |
| 55 | intel_fb_destroy(fb); |
| 56 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 57 | } |
| 58 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 59 | width = info->width; |
| 60 | height = info->height; |
| 61 | array_size = info->layers; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 62 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 63 | for (i = 0; i < info->attachmentCount; i++) { |
Courtney Goeltzenleuchter | 1856d6f | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 64 | const VkImageView *att = &info->pAttachments[i]; |
| 65 | const struct intel_img_view *view = intel_img_view(*att); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 66 | |
Courtney Goeltzenleuchter | 1856d6f | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 67 | if (array_size > view->att_view.array_size) |
| 68 | array_size = view->att_view.array_size; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 69 | |
Courtney Goeltzenleuchter | 1856d6f | 2015-09-01 17:30:39 -0600 | [diff] [blame] | 70 | fb->views[i] = &view->att_view; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 71 | } |
Mark Lobodzinski | 71fcc2d | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 72 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 73 | fb->width = width; |
| 74 | fb->height = height; |
| 75 | fb->array_size = array_size; |
| 76 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 77 | fb->obj.destroy = fb_destroy; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 78 | |
| 79 | *fb_ret = fb; |
| 80 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Chia-I Wu | 9d748fd | 2015-02-18 14:46:55 -0700 | [diff] [blame] | 84 | void intel_fb_destroy(struct intel_fb *fb) |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 85 | { |
Chia-I Wu | 3d4d4a6 | 2015-07-09 10:34:10 +0800 | [diff] [blame] | 86 | if (fb->views) |
| 87 | intel_free(fb, fb->views); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 88 | intel_base_destroy(&fb->obj.base); |
| 89 | } |
| 90 | |
| 91 | static void render_pass_destroy(struct intel_obj *obj) |
| 92 | { |
Chia-I Wu | 768a14b | 2015-02-18 14:48:21 -0700 | [diff] [blame] | 93 | struct intel_render_pass *rp = intel_render_pass_from_obj(obj); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 94 | |
Courtney Goeltzenleuchter | 5f5a618 | 2015-01-23 14:27:58 -0700 | [diff] [blame] | 95 | intel_render_pass_destroy(rp); |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 98 | VkResult intel_render_pass_create(struct intel_dev *dev, |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 99 | const VkRenderPassCreateInfo *info, |
| 100 | struct intel_render_pass **rp_ret) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 101 | { |
| 102 | struct intel_render_pass *rp; |
Chia-I Wu | ba62786 | 2015-02-18 15:32:06 -0700 | [diff] [blame] | 103 | uint32_t i; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 104 | |
Courtney Goeltzenleuchter | a54b76a | 2015-09-04 13:39:59 -0600 | [diff] [blame] | 105 | /* TODOVV: Move to validation layer */ |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 106 | if (info->dependencyCount) |
| 107 | return VK_ERROR_UNKNOWN; |
| 108 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 109 | rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 110 | sizeof(*rp), dev->base.dbg, VK_OBJECT_TYPE_RENDER_PASS, info, 0); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 111 | if (!rp) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 112 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 113 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 114 | rp->attachment_count = info->attachmentCount; |
| 115 | rp->subpass_count = info->subpassCount; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 116 | |
| 117 | rp->attachments = intel_alloc(rp, |
| 118 | sizeof(rp->attachments[0]) * rp->attachment_count + |
| 119 | sizeof(rp->subpasses[0]) * rp->subpass_count, 0, |
| 120 | VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 121 | if (!rp->attachments) { |
| 122 | intel_render_pass_destroy(rp); |
| 123 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 124 | } |
| 125 | |
| 126 | rp->subpasses = (struct intel_render_pass_subpass *) |
| 127 | (rp->attachments + rp->attachment_count); |
| 128 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 129 | rp->obj.destroy = render_pass_destroy; |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 130 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 131 | for (i = 0; i < info->attachmentCount; i++) { |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 132 | struct intel_render_pass_attachment *att = &rp->attachments[i]; |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame] | 133 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 134 | att->format = info->pAttachments[i].format; |
| 135 | att->sample_count = info->pAttachments[i].samples; |
| 136 | att->initial_layout = info->pAttachments[i].initialLayout; |
| 137 | att->final_layout = info->pAttachments[i].finalLayout; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 138 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 139 | att->clear_on_load = (info->pAttachments[i].loadOp == |
| 140 | VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 141 | att->disable_store = (info->pAttachments[i].storeOp == |
| 142 | VK_ATTACHMENT_STORE_OP_DONT_CARE); |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 143 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 144 | att->stencil_clear_on_load = (info->pAttachments[i].stencilLoadOp == |
| 145 | VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 146 | att->stencil_disable_store = (info->pAttachments[i].stencilStoreOp == |
| 147 | VK_ATTACHMENT_STORE_OP_DONT_CARE); |
Chia-I Wu | 1af1a78 | 2015-07-09 10:46:39 +0800 | [diff] [blame] | 148 | } |
| 149 | |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 150 | for (i = 0; i < rp->subpass_count; i++) { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 151 | const VkSubpassDescription *subpass_info = &info->pSubpasses[i]; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 152 | struct intel_render_pass_subpass *subpass = &rp->subpasses[i]; |
| 153 | uint32_t j; |
| 154 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 155 | /* missing SPIR support? */ |
| 156 | if (subpass_info->inputCount) { |
| 157 | intel_render_pass_destroy(rp); |
| 158 | return VK_ERROR_UNKNOWN; |
| 159 | } |
| 160 | |
| 161 | for (j = 0; j < subpass_info->colorCount; j++) { |
| 162 | const VkAttachmentReference *color_ref = |
Cody Northrop | 6de6b0b | 2015-08-04 11:16:41 -0600 | [diff] [blame] | 163 | &subpass_info->pColorAttachments[j]; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 164 | const VkAttachmentReference *resolve_ref = |
Cody Northrop | 6de6b0b | 2015-08-04 11:16:41 -0600 | [diff] [blame] | 165 | (subpass_info->pResolveAttachments) ? |
| 166 | &subpass_info->pResolveAttachments[j] : NULL; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 167 | |
| 168 | subpass->color_indices[j] = color_ref->attachment; |
| 169 | subpass->resolve_indices[j] = (resolve_ref) ? |
| 170 | resolve_ref->attachment : VK_ATTACHMENT_UNUSED; |
| 171 | subpass->color_layouts[j] = color_ref->layout; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 174 | subpass->color_count = subpass_info->colorCount; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 175 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 176 | subpass->ds_index = subpass_info->depthStencilAttachment.attachment; |
| 177 | subpass->ds_layout = subpass_info->depthStencilAttachment.layout; |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 178 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 179 | switch (subpass->ds_layout) { |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 180 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 181 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 182 | subpass->ds_optimal = true; |
| 183 | break; |
| 184 | default: |
| 185 | subpass->ds_optimal = false; |
| 186 | break; |
| 187 | } |
| 188 | } |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame] | 189 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 190 | *rp_ret = rp; |
| 191 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 195 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 196 | { |
Chia-I Wu | bdeed15 | 2015-07-09 12:16:29 +0800 | [diff] [blame] | 197 | if (rp->attachments) |
| 198 | intel_free(rp, rp->attachments); |
| 199 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 200 | intel_base_destroy(&rp->obj.base); |
| 201 | } |
| 202 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 203 | ICD_EXPORT VkResult VKAPI vkCreateFramebuffer( |
| 204 | VkDevice device, |
| 205 | const VkFramebufferCreateInfo* pCreateInfo, |
| 206 | VkFramebuffer* pFramebuffer) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 207 | { |
| 208 | struct intel_dev *dev = intel_dev(device); |
| 209 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 210 | return intel_fb_create(dev, pCreateInfo, |
| 211 | (struct intel_fb **) pFramebuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame^] | 214 | ICD_EXPORT void VKAPI vkDestroyFramebuffer( |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 215 | VkDevice device, |
| 216 | VkFramebuffer framebuffer) |
| 217 | |
| 218 | { |
| 219 | struct intel_obj *obj = intel_obj(framebuffer.handle); |
| 220 | |
| 221 | obj->destroy(obj); |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 222 | } |
| 223 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 224 | ICD_EXPORT VkResult VKAPI vkCreateRenderPass( |
| 225 | VkDevice device, |
| 226 | const VkRenderPassCreateInfo* pCreateInfo, |
| 227 | VkRenderPass* pRenderPass) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 228 | { |
| 229 | struct intel_dev *dev = intel_dev(device); |
| 230 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 231 | return intel_render_pass_create(dev, pCreateInfo, |
| 232 | (struct intel_render_pass **) pRenderPass); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 233 | } |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 234 | |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame^] | 235 | ICD_EXPORT void VKAPI vkDestroyRenderPass( |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 236 | VkDevice device, |
| 237 | VkRenderPass renderPass) |
| 238 | |
| 239 | { |
| 240 | struct intel_obj *obj = intel_obj(renderPass.handle); |
| 241 | |
| 242 | obj->destroy(obj); |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 243 | } |