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 | 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) |
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 | 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 | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 59 | const VkColorAttachmentBindInfo *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 | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 82 | const VkDepthStencilBindInfo *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 | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 141 | VkResult intel_render_pass_create(struct intel_dev *dev, |
| 142 | const VkRenderPassCreateInfo *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) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 151 | return VK_ERROR_OUT_OF_HOST_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 | |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame^] | 155 | rp->colorAttachmentCount = info->colorAttachmentCount; |
| 156 | rp->renderArea = info->renderArea; |
| 157 | rp->extent = info->extent; |
| 158 | |
| 159 | if (rp->colorAttachmentCount) { |
| 160 | memcpy(rp->colorLoadOps, info->pColorLoadOps, rp->colorAttachmentCount * sizeof(rp->colorLoadOps[0])); |
| 161 | if (info->pColorLayouts) { |
| 162 | memcpy(rp->colorLayouts, info->pColorLayouts, rp->colorAttachmentCount * sizeof(rp->colorLayouts[0])); |
| 163 | } |
| 164 | if (info->pColorLoadClearValues) { |
| 165 | memcpy(rp->colorClearValues, info->pColorLoadClearValues, rp->colorAttachmentCount * sizeof(rp->colorClearValues[0])); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* TODO: depth/stencil clear load ops */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 170 | assert(info->depthLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR); |
| 171 | assert(info->stencilLoadOp != VK_ATTACHMENT_LOAD_OP_CLEAR); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 172 | |
Chris Forbes | fff9bf4 | 2015-06-15 15:26:19 +1200 | [diff] [blame^] | 173 | /* TODO: MSAA resolves if/when we support MSAA. */ |
| 174 | for (i = 0; i < info->colorAttachmentCount; i++) |
| 175 | assert(info->pColorStoreOps[i] != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA); |
| 176 | assert(info->depthStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA); |
| 177 | assert(info->stencilStoreOp != VK_ATTACHMENT_STORE_OP_RESOLVE_MSAA); |
| 178 | |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 179 | *rp_ret = rp; |
| 180 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 181 | return VK_SUCCESS; |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 184 | void intel_render_pass_destroy(struct intel_render_pass *rp) |
| 185 | { |
Jon Ashburn | c04b4dc | 2015-01-08 18:48:10 -0700 | [diff] [blame] | 186 | intel_base_destroy(&rp->obj.base); |
| 187 | } |
| 188 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 189 | ICD_EXPORT VkResult VKAPI vkCreateFramebuffer( |
| 190 | VkDevice device, |
| 191 | const VkFramebufferCreateInfo* pCreateInfo, |
| 192 | VkFramebuffer* pFramebuffer) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 193 | { |
| 194 | struct intel_dev *dev = intel_dev(device); |
| 195 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 196 | return intel_fb_create(dev, pCreateInfo, |
| 197 | (struct intel_fb **) pFramebuffer); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 200 | ICD_EXPORT VkResult VKAPI vkCreateRenderPass( |
| 201 | VkDevice device, |
| 202 | const VkRenderPassCreateInfo* pCreateInfo, |
| 203 | VkRenderPass* pRenderPass) |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 204 | { |
| 205 | struct intel_dev *dev = intel_dev(device); |
| 206 | |
Chia-I Wu | 4f7730d | 2015-02-18 15:21:38 -0700 | [diff] [blame] | 207 | return intel_render_pass_create(dev, pCreateInfo, |
| 208 | (struct intel_render_pass **) pRenderPass); |
Jon Ashburn | c6f4a41 | 2014-12-24 12:38:36 -0700 | [diff] [blame] | 209 | } |