Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <assert.h> |
| 25 | #include <stdbool.h> |
| 26 | #include <string.h> |
| 27 | #include <unistd.h> |
| 28 | #include <fcntl.h> |
| 29 | |
Chad Versace | 2c2233e | 2015-07-17 15:04:27 -0700 | [diff] [blame] | 30 | #include "anv_private.h" |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 31 | |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 32 | /** |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 33 | * Exactly one bit must be set in \a aspect. |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 34 | */ |
| 35 | static isl_surf_usage_flags_t |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 36 | choose_isl_surf_usage(VkImageUsageFlags vk_usage, |
Chad Versace | 2f270f0 | 2015-12-04 16:29:25 -0800 | [diff] [blame] | 37 | VkImageAspectFlags aspect) |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 38 | { |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 39 | isl_surf_usage_flags_t isl_usage = 0; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 40 | |
| 41 | /* FINISHME: Support aux surfaces */ |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 42 | isl_usage |= ISL_SURF_USAGE_DISABLE_AUX_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 43 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 44 | if (vk_usage & VK_IMAGE_USAGE_SAMPLED_BIT) |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 45 | isl_usage |= ISL_SURF_USAGE_TEXTURE_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 46 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 47 | if (vk_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 48 | isl_usage |= ISL_SURF_USAGE_TEXTURE_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 49 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 50 | if (vk_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 51 | isl_usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 52 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 53 | if (vk_usage & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 54 | isl_usage |= ISL_SURF_USAGE_CUBE_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 55 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 56 | if (vk_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { |
Chad Versace | 2f270f0 | 2015-12-04 16:29:25 -0800 | [diff] [blame] | 57 | switch (aspect) { |
| 58 | default: |
| 59 | unreachable("bad VkImageAspect"); |
| 60 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 61 | isl_usage |= ISL_SURF_USAGE_DEPTH_BIT; |
Chad Versace | 2f270f0 | 2015-12-04 16:29:25 -0800 | [diff] [blame] | 62 | break; |
| 63 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 64 | isl_usage |= ISL_SURF_USAGE_STENCIL_BIT; |
Chad Versace | 2f270f0 | 2015-12-04 16:29:25 -0800 | [diff] [blame] | 65 | break; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 69 | if (vk_usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) { |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 70 | /* Meta implements transfers by sampling from the source image. */ |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 71 | isl_usage |= ISL_SURF_USAGE_TEXTURE_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 74 | if (vk_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) { |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 75 | /* Meta implements transfers by rendering into the destination image. */ |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 76 | isl_usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Chad Versace | c5e521f | 2016-02-09 12:36:54 -0800 | [diff] [blame] | 79 | return isl_usage; |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 80 | } |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 83 | * Exactly one bit must be set in \a aspect. |
| 84 | */ |
| 85 | static struct anv_surface * |
| 86 | get_surface(struct anv_image *image, VkImageAspectFlags aspect) |
| 87 | { |
| 88 | switch (aspect) { |
| 89 | default: |
| 90 | unreachable("bad VkImageAspect"); |
| 91 | case VK_IMAGE_ASPECT_COLOR_BIT: |
| 92 | return &image->color_surface; |
| 93 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
| 94 | return &image->depth_surface; |
| 95 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
| 96 | return &image->stencil_surface; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Initialize the anv_image::*_surface selected by \a aspect. Then update the |
| 102 | * image's memory requirements (that is, the image's size and alignment). |
| 103 | * |
| 104 | * Exactly one bit must be set in \a aspect. |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 105 | */ |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 106 | static VkResult |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 107 | make_surface(const struct anv_device *dev, |
| 108 | struct anv_image *image, |
| 109 | const struct anv_image_create_info *anv_info, |
| 110 | VkImageAspectFlags aspect) |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 111 | { |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 112 | const VkImageCreateInfo *vk_info = anv_info->vk_info; |
Chad Versace | 3d85a28 | 2015-12-07 08:53:43 -0800 | [diff] [blame] | 113 | bool ok UNUSED; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 114 | |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 115 | static const enum isl_surf_dim vk_to_isl_surf_dim[] = { |
| 116 | [VK_IMAGE_TYPE_1D] = ISL_SURF_DIM_1D, |
| 117 | [VK_IMAGE_TYPE_2D] = ISL_SURF_DIM_2D, |
| 118 | [VK_IMAGE_TYPE_3D] = ISL_SURF_DIM_3D, |
| 119 | }; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 120 | |
Chad Versace | 64e8af6 | 2015-12-07 08:50:28 -0800 | [diff] [blame] | 121 | isl_tiling_flags_t tiling_flags = anv_info->isl_tiling_flags; |
| 122 | if (vk_info->tiling == VK_IMAGE_TILING_LINEAR) |
Nanley Chery | 1d9d90d | 2016-03-02 09:44:48 -0800 | [diff] [blame] | 123 | tiling_flags = ISL_TILING_LINEAR_BIT; |
Chad Versace | 64e8af6 | 2015-12-07 08:50:28 -0800 | [diff] [blame] | 124 | |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 125 | struct anv_surface *anv_surf = get_surface(image, aspect); |
| 126 | |
Nanley Chery | a5dc3c0 | 2016-03-22 10:53:37 -0700 | [diff] [blame^] | 127 | image->extent = anv_sanitize_image_extent(vk_info->imageType, |
| 128 | vk_info->extent); |
Nanley Chery | 9963af8 | 2016-02-17 17:20:03 -0800 | [diff] [blame] | 129 | |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 130 | ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl, |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 131 | .dim = vk_to_isl_surf_dim[vk_info->imageType], |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 132 | .format = anv_get_isl_format(vk_info->format, aspect, |
| 133 | vk_info->tiling, NULL), |
Nanley Chery | a5dc3c0 | 2016-03-22 10:53:37 -0700 | [diff] [blame^] | 134 | .width = image->extent.width, |
| 135 | .height = image->extent.height, |
| 136 | .depth = image->extent.depth, |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 137 | .levels = vk_info->mipLevels, |
| 138 | .array_len = vk_info->arrayLayers, |
| 139 | .samples = vk_info->samples, |
| 140 | .min_alignment = 0, |
| 141 | .min_pitch = 0, |
Chad Versace | 2f4bb00 | 2016-02-09 12:35:39 -0800 | [diff] [blame] | 142 | .usage = choose_isl_surf_usage(image->usage, aspect), |
Chad Versace | 64e8af6 | 2015-12-07 08:50:28 -0800 | [diff] [blame] | 143 | .tiling_flags = tiling_flags); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 144 | |
Chad Versace | 3d85a28 | 2015-12-07 08:53:43 -0800 | [diff] [blame] | 145 | /* isl_surf_init() will fail only if provided invalid input. Invalid input |
| 146 | * is illegal in Vulkan. |
| 147 | */ |
| 148 | assert(ok); |
| 149 | |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 150 | anv_surf->offset = align_u32(image->size, anv_surf->isl.alignment); |
| 151 | image->size = anv_surf->offset + anv_surf->isl.size; |
| 152 | image->alignment = MAX(image->alignment, anv_surf->isl.alignment); |
Chad Versace | b369389 | 2015-12-02 16:46:16 -0800 | [diff] [blame] | 153 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 154 | return VK_SUCCESS; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 157 | /** |
| 158 | * Parameter @a format is required and overrides VkImageCreateInfo::format. |
| 159 | */ |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 160 | static VkImageUsageFlags |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 161 | anv_image_get_full_usage(const VkImageCreateInfo *info, |
| 162 | const struct anv_format *format) |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 163 | { |
| 164 | VkImageUsageFlags usage = info->usage; |
| 165 | |
Chad Versace | 2bab3cd | 2016-01-28 06:28:01 -0800 | [diff] [blame] | 166 | if (info->samples > 1 && |
| 167 | (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) { |
| 168 | /* Meta will resolve the image by binding it as a texture. */ |
| 169 | usage |= VK_IMAGE_USAGE_SAMPLED_BIT; |
| 170 | } |
| 171 | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 172 | if (usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 173 | /* Meta will transfer from the image by binding it as a texture. */ |
| 174 | usage |= VK_IMAGE_USAGE_SAMPLED_BIT; |
| 175 | } |
| 176 | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 177 | if (usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) { |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 178 | /* For non-clear transfer operations, meta will transfer to the image by |
| 179 | * binding it as a color attachment, even if the image format is not |
| 180 | * a color format. |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 181 | */ |
| 182 | usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 183 | |
| 184 | if (anv_format_is_depth_or_stencil(format)) { |
| 185 | /* vkCmdClearDepthStencilImage() only requires that |
| 186 | * VK_IMAGE_USAGE_TRANSFER_SRC_BIT be set. In particular, it does |
| 187 | * not require VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT. Meta |
| 188 | * clears the image, though, by binding it as a depthstencil |
| 189 | * attachment. |
| 190 | */ |
| 191 | usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 192 | } |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | return usage; |
| 196 | } |
| 197 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 198 | VkResult |
| 199 | anv_image_create(VkDevice _device, |
| 200 | const struct anv_image_create_info *create_info, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 201 | const VkAllocationCallbacks* alloc, |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 202 | VkImage *pImage) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 203 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 204 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 205 | const VkImageCreateInfo *pCreateInfo = create_info->vk_info; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 206 | struct anv_image *image = NULL; |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 207 | const struct anv_format *format = anv_format_for_vk_format(pCreateInfo->format); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 208 | VkResult r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 209 | |
| 210 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO); |
| 211 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 212 | anv_assert(pCreateInfo->mipLevels > 0); |
Jason Ekstrand | 299f8f1 | 2015-12-01 12:52:56 -0800 | [diff] [blame] | 213 | anv_assert(pCreateInfo->arrayLayers > 0); |
Chad Versace | d96d78c | 2016-01-22 17:16:20 -0800 | [diff] [blame] | 214 | anv_assert(pCreateInfo->samples > 0); |
Chad Versace | 5d7103e | 2015-06-26 09:05:46 -0700 | [diff] [blame] | 215 | anv_assert(pCreateInfo->extent.width > 0); |
| 216 | anv_assert(pCreateInfo->extent.height > 0); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 217 | anv_assert(pCreateInfo->extent.depth > 0); |
Jason Ekstrand | 2a3c296 | 2015-06-10 21:04:51 -0700 | [diff] [blame] | 218 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 219 | image = anv_alloc2(&device->alloc, alloc, sizeof(*image), 8, |
| 220 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 221 | if (!image) |
| 222 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 223 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 224 | memset(image, 0, sizeof(*image)); |
| 225 | image->type = pCreateInfo->imageType; |
| 226 | image->extent = pCreateInfo->extent; |
Jason Ekstrand | 3200a81 | 2015-12-31 12:39:34 -0800 | [diff] [blame] | 227 | image->vk_format = pCreateInfo->format; |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 228 | image->format = format; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 229 | image->levels = pCreateInfo->mipLevels; |
Jason Ekstrand | 299f8f1 | 2015-12-01 12:52:56 -0800 | [diff] [blame] | 230 | image->array_size = pCreateInfo->arrayLayers; |
Chad Versace | dfcb4ee | 2016-01-20 16:34:23 -0800 | [diff] [blame] | 231 | image->samples = pCreateInfo->samples; |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 232 | image->usage = anv_image_get_full_usage(pCreateInfo, format); |
Jason Ekstrand | f665fdf | 2016-01-01 14:09:17 -0800 | [diff] [blame] | 233 | image->tiling = pCreateInfo->tiling; |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 234 | |
Chad Versace | 4c5dccc | 2016-02-09 12:41:08 -0800 | [diff] [blame] | 235 | if (likely(anv_format_is_color(format))) { |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 236 | r = make_surface(device, image, create_info, |
| 237 | VK_IMAGE_ASPECT_COLOR_BIT); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 238 | if (r != VK_SUCCESS) |
| 239 | goto fail; |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 240 | } else { |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 241 | if (image->format->has_depth) { |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 242 | r = make_surface(device, image, create_info, |
| 243 | VK_IMAGE_ASPECT_DEPTH_BIT); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 244 | if (r != VK_SUCCESS) |
| 245 | goto fail; |
| 246 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 247 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 248 | if (image->format->has_stencil) { |
Chad Versace | 9098e0f | 2015-12-07 09:22:49 -0800 | [diff] [blame] | 249 | r = make_surface(device, image, create_info, |
| 250 | VK_IMAGE_ASPECT_STENCIL_BIT); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 251 | if (r != VK_SUCCESS) |
| 252 | goto fail; |
| 253 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 254 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 255 | |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 256 | *pImage = anv_image_to_handle(image); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 257 | |
| 258 | return VK_SUCCESS; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 259 | |
| 260 | fail: |
| 261 | if (image) |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 262 | anv_free2(&device->alloc, alloc, image); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 263 | |
| 264 | return r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 267 | VkResult |
| 268 | anv_CreateImage(VkDevice device, |
| 269 | const VkImageCreateInfo *pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 270 | const VkAllocationCallbacks *pAllocator, |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 271 | VkImage *pImage) |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 272 | { |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 273 | return anv_image_create(device, |
| 274 | &(struct anv_image_create_info) { |
| 275 | .vk_info = pCreateInfo, |
Chad Versace | 64e8af6 | 2015-12-07 08:50:28 -0800 | [diff] [blame] | 276 | .isl_tiling_flags = ISL_TILING_ANY_MASK, |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 277 | }, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 278 | pAllocator, |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 279 | pImage); |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 282 | void |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 283 | anv_DestroyImage(VkDevice _device, VkImage _image, |
| 284 | const VkAllocationCallbacks *pAllocator) |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 285 | { |
| 286 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 287 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 288 | anv_free2(&device->alloc, pAllocator, anv_image_from_handle(_image)); |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 291 | static void |
| 292 | anv_surface_get_subresource_layout(struct anv_image *image, |
| 293 | struct anv_surface *surface, |
| 294 | const VkImageSubresource *subresource, |
| 295 | VkSubresourceLayout *layout) |
| 296 | { |
| 297 | /* If we are on a non-zero mip level or array slice, we need to |
| 298 | * calculate a real offset. |
| 299 | */ |
| 300 | anv_assert(subresource->mipLevel == 0); |
| 301 | anv_assert(subresource->arrayLayer == 0); |
| 302 | |
| 303 | layout->offset = surface->offset; |
Chad Versace | 981ef2f | 2015-12-03 08:40:47 -0800 | [diff] [blame] | 304 | layout->rowPitch = surface->isl.row_pitch; |
| 305 | layout->depthPitch = isl_surf_get_array_pitch(&surface->isl); |
Jason Ekstrand | 8a81d13 | 2016-01-06 19:27:10 -0800 | [diff] [blame] | 306 | layout->arrayPitch = isl_surf_get_array_pitch(&surface->isl); |
Chad Versace | 981ef2f | 2015-12-03 08:40:47 -0800 | [diff] [blame] | 307 | layout->size = surface->isl.size; |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 310 | void anv_GetImageSubresourceLayout( |
Jason Ekstrand | db24afe | 2015-07-07 18:20:18 -0700 | [diff] [blame] | 311 | VkDevice device, |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 312 | VkImage _image, |
Jason Ekstrand | db24afe | 2015-07-07 18:20:18 -0700 | [diff] [blame] | 313 | const VkImageSubresource* pSubresource, |
| 314 | VkSubresourceLayout* pLayout) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 315 | { |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 316 | ANV_FROM_HANDLE(anv_image, image, _image); |
| 317 | |
Jason Ekstrand | 407b8cc | 2015-12-01 12:19:11 -0800 | [diff] [blame] | 318 | assert(__builtin_popcount(pSubresource->aspectMask) == 1); |
| 319 | |
| 320 | switch (pSubresource->aspectMask) { |
| 321 | case VK_IMAGE_ASPECT_COLOR_BIT: |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 322 | anv_surface_get_subresource_layout(image, &image->color_surface, |
| 323 | pSubresource, pLayout); |
| 324 | break; |
Jason Ekstrand | 407b8cc | 2015-12-01 12:19:11 -0800 | [diff] [blame] | 325 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 326 | anv_surface_get_subresource_layout(image, &image->depth_surface, |
| 327 | pSubresource, pLayout); |
| 328 | break; |
Jason Ekstrand | 407b8cc | 2015-12-01 12:19:11 -0800 | [diff] [blame] | 329 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 330 | anv_surface_get_subresource_layout(image, &image->stencil_surface, |
| 331 | pSubresource, pLayout); |
| 332 | break; |
| 333 | default: |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 334 | assert(!"Invalid image aspect"); |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 335 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 338 | VkResult |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 339 | anv_validate_CreateImageView(VkDevice _device, |
| 340 | const VkImageViewCreateInfo *pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 341 | const VkAllocationCallbacks *pAllocator, |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 342 | VkImageView *pView) |
| 343 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 344 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 345 | const VkImageSubresourceRange *subresource; |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 346 | const struct anv_format *view_format_info; |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 347 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 348 | /* Validate structure type before dereferencing it. */ |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 349 | assert(pCreateInfo); |
| 350 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 351 | subresource = &pCreateInfo->subresourceRange; |
| 352 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 353 | /* Validate viewType is in range before using it. */ |
| 354 | assert(pCreateInfo->viewType >= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE); |
| 355 | assert(pCreateInfo->viewType <= VK_IMAGE_VIEW_TYPE_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 356 | |
| 357 | /* Validate format is in range before using it. */ |
| 358 | assert(pCreateInfo->format >= VK_FORMAT_BEGIN_RANGE); |
| 359 | assert(pCreateInfo->format <= VK_FORMAT_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 360 | view_format_info = anv_format_for_vk_format(pCreateInfo->format); |
| 361 | |
| 362 | /* Validate channel swizzles. */ |
Jason Ekstrand | a53f23d | 2015-11-30 13:06:12 -0800 | [diff] [blame] | 363 | assert(pCreateInfo->components.r >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 364 | assert(pCreateInfo->components.r <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 365 | assert(pCreateInfo->components.g >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 366 | assert(pCreateInfo->components.g <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 367 | assert(pCreateInfo->components.b >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 368 | assert(pCreateInfo->components.b <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 369 | assert(pCreateInfo->components.a >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 370 | assert(pCreateInfo->components.a <= VK_COMPONENT_SWIZZLE_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 371 | |
| 372 | /* Validate subresource. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 373 | assert(subresource->aspectMask != 0); |
Jason Ekstrand | 299f8f1 | 2015-12-01 12:52:56 -0800 | [diff] [blame] | 374 | assert(subresource->levelCount > 0); |
| 375 | assert(subresource->layerCount > 0); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 376 | assert(subresource->baseMipLevel < image->levels); |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 377 | assert(subresource->baseMipLevel + anv_get_levelCount(image, subresource) <= image->levels); |
Jason Ekstrand | 1e4263b | 2015-10-06 10:27:50 -0700 | [diff] [blame] | 378 | assert(subresource->baseArrayLayer < image->array_size); |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 379 | assert(subresource->baseArrayLayer + anv_get_layerCount(image, subresource) <= image->array_size); |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 380 | assert(pView); |
| 381 | |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 382 | const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT |
| 383 | | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 384 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 385 | /* Validate format. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 386 | if (subresource->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 387 | assert(subresource->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT); |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 388 | assert(!image->format->has_depth); |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 389 | assert(!image->format->has_stencil); |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 390 | assert(!view_format_info->has_depth); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 391 | assert(!view_format_info->has_stencil); |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 392 | assert(view_format_info->isl_layout->bs == |
| 393 | image->format->isl_layout->bs); |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 394 | } else if (subresource->aspectMask & ds_flags) { |
| 395 | assert((subresource->aspectMask & ~ds_flags) == 0); |
| 396 | |
| 397 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 398 | assert(image->format->has_depth); |
| 399 | assert(view_format_info->has_depth); |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 400 | assert(view_format_info->isl_layout->bs == |
| 401 | image->format->isl_layout->bs); |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jason Ekstrand | 407b8cc | 2015-12-01 12:19:11 -0800 | [diff] [blame] | 404 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 405 | /* FINISHME: Is it legal to have an R8 view of S8? */ |
| 406 | assert(image->format->has_stencil); |
| 407 | assert(view_format_info->has_stencil); |
| 408 | } |
| 409 | } else { |
| 410 | assert(!"bad VkImageSubresourceRange::aspectFlags"); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 411 | } |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 412 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 413 | return anv_CreateImageView(_device, pCreateInfo, pAllocator, pView); |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 416 | static struct anv_state |
| 417 | alloc_surface_state(struct anv_device *device, |
| 418 | struct anv_cmd_buffer *cmd_buffer) |
| 419 | { |
| 420 | if (cmd_buffer) { |
| 421 | return anv_cmd_buffer_alloc_surface_state(cmd_buffer); |
| 422 | } else { |
| 423 | return anv_state_pool_alloc(&device->surface_state_pool, 64, 64); |
| 424 | } |
| 425 | } |
| 426 | |
Francisco Jerez | a50dc70 | 2016-01-26 12:23:08 -0800 | [diff] [blame] | 427 | static bool |
| 428 | has_matching_storage_typed_format(const struct anv_device *device, |
| 429 | enum isl_format format) |
| 430 | { |
| 431 | return (isl_format_get_layout(format)->bs <= 4 || |
| 432 | (isl_format_get_layout(format)->bs <= 8 && |
| 433 | (device->info.gen >= 8 || device->info.is_haswell)) || |
| 434 | device->info.gen >= 9); |
| 435 | } |
| 436 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 437 | static enum isl_channel_select |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 438 | remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component, |
| 439 | struct anv_format_swizzle format_swizzle) |
Jason Ekstrand | 9bc72a9 | 2016-01-26 20:16:43 -0800 | [diff] [blame] | 440 | { |
| 441 | if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY) |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 442 | swizzle = component; |
| 443 | |
| 444 | switch (swizzle) { |
| 445 | case VK_COMPONENT_SWIZZLE_ZERO: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 446 | return ISL_CHANNEL_SELECT_ZERO; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 447 | case VK_COMPONENT_SWIZZLE_ONE: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 448 | return ISL_CHANNEL_SELECT_ONE; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 449 | case VK_COMPONENT_SWIZZLE_R: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 450 | return ISL_CHANNEL_SELECT_RED + format_swizzle.r; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 451 | case VK_COMPONENT_SWIZZLE_G: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 452 | return ISL_CHANNEL_SELECT_RED + format_swizzle.g; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 453 | case VK_COMPONENT_SWIZZLE_B: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 454 | return ISL_CHANNEL_SELECT_RED + format_swizzle.b; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 455 | case VK_COMPONENT_SWIZZLE_A: |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 456 | return ISL_CHANNEL_SELECT_RED + format_swizzle.a; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 457 | default: |
| 458 | unreachable("Invalid swizzle"); |
| 459 | } |
Jason Ekstrand | 9bc72a9 | 2016-01-26 20:16:43 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 462 | void |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 463 | anv_image_view_init(struct anv_image_view *iview, |
| 464 | struct anv_device *device, |
| 465 | const VkImageViewCreateInfo* pCreateInfo, |
Nanley Chery | 6a579de | 2016-01-26 18:53:21 -0800 | [diff] [blame] | 466 | struct anv_cmd_buffer *cmd_buffer, |
Jason Ekstrand | e9d126f | 2016-02-24 19:49:12 -0800 | [diff] [blame] | 467 | uint32_t offset, |
| 468 | VkImageUsageFlags usage_mask) |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 469 | { |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 470 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 471 | const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange; |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 472 | |
Jason Ekstrand | 299f8f1 | 2015-12-01 12:52:56 -0800 | [diff] [blame] | 473 | assert(range->layerCount > 0); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 474 | assert(range->baseMipLevel < image->levels); |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 475 | assert(image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 476 | VK_IMAGE_USAGE_STORAGE_BIT | |
| 477 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
Chad Versace | 0ca3c84 | 2015-10-07 11:39:49 -0700 | [diff] [blame] | 478 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 479 | |
| 480 | switch (image->type) { |
| 481 | default: |
| 482 | unreachable("bad VkImageType"); |
| 483 | case VK_IMAGE_TYPE_1D: |
| 484 | case VK_IMAGE_TYPE_2D: |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 485 | assert(range->baseArrayLayer + anv_get_layerCount(image, range) - 1 <= image->array_size); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 486 | break; |
| 487 | case VK_IMAGE_TYPE_3D: |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 488 | assert(range->baseArrayLayer + anv_get_layerCount(image, range) - 1 |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 489 | <= anv_minify(image->extent.depth, range->baseMipLevel)); |
| 490 | break; |
| 491 | } |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 492 | |
Jason Ekstrand | a7cc129 | 2016-01-01 13:47:18 -0800 | [diff] [blame] | 493 | struct anv_surface *surface = |
| 494 | anv_image_get_surface_for_aspect_mask(image, range->aspectMask); |
| 495 | |
| 496 | iview->image = image; |
| 497 | iview->bo = image->bo; |
Nanley Chery | 6a579de | 2016-01-26 18:53:21 -0800 | [diff] [blame] | 498 | iview->offset = image->offset + surface->offset + offset; |
Jason Ekstrand | a7cc129 | 2016-01-01 13:47:18 -0800 | [diff] [blame] | 499 | |
| 500 | iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask; |
Jason Ekstrand | f665fdf | 2016-01-01 14:09:17 -0800 | [diff] [blame] | 501 | iview->vk_format = pCreateInfo->format; |
Jordan Justen | c20f78d | 2016-01-26 11:10:56 -0800 | [diff] [blame] | 502 | |
| 503 | struct anv_format_swizzle swizzle; |
Jason Ekstrand | 9d5b8f7 | 2016-02-20 21:40:25 -0800 | [diff] [blame] | 504 | enum isl_format format = anv_get_isl_format(pCreateInfo->format, |
| 505 | range->aspectMask, |
| 506 | image->tiling, &swizzle); |
Jason Ekstrand | a7cc129 | 2016-01-01 13:47:18 -0800 | [diff] [blame] | 507 | |
Jason Ekstrand | aa9987a | 2016-01-05 13:54:02 -0800 | [diff] [blame] | 508 | iview->base_layer = range->baseArrayLayer; |
| 509 | iview->base_mip = range->baseMipLevel; |
Nanley Chery | 3f01bbe | 2016-01-04 12:41:22 -0800 | [diff] [blame] | 510 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 511 | struct isl_view isl_view = { |
Jason Ekstrand | 9d5b8f7 | 2016-02-20 21:40:25 -0800 | [diff] [blame] | 512 | .format = format, |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 513 | .base_level = range->baseMipLevel, |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 514 | .levels = anv_get_levelCount(image, range), |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 515 | .base_array_layer = range->baseArrayLayer, |
Nanley Chery | 4e75f9b | 2016-03-04 20:41:05 -0800 | [diff] [blame] | 516 | .array_len = anv_get_layerCount(image, range), |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 517 | .channel_select = { |
| 518 | remap_swizzle(pCreateInfo->components.r, |
| 519 | VK_COMPONENT_SWIZZLE_R, swizzle), |
| 520 | remap_swizzle(pCreateInfo->components.g, |
| 521 | VK_COMPONENT_SWIZZLE_G, swizzle), |
| 522 | remap_swizzle(pCreateInfo->components.b, |
| 523 | VK_COMPONENT_SWIZZLE_B, swizzle), |
| 524 | remap_swizzle(pCreateInfo->components.a, |
| 525 | VK_COMPONENT_SWIZZLE_A, swizzle), |
| 526 | }, |
| 527 | }; |
| 528 | |
Jason Ekstrand | a7cc129 | 2016-01-01 13:47:18 -0800 | [diff] [blame] | 529 | iview->extent = (VkExtent3D) { |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 530 | .width = anv_minify(image->extent.width , range->baseMipLevel), |
| 531 | .height = anv_minify(image->extent.height, range->baseMipLevel), |
| 532 | .depth = anv_minify(image->extent.depth , range->baseMipLevel), |
Jason Ekstrand | a7cc129 | 2016-01-01 13:47:18 -0800 | [diff] [blame] | 533 | }; |
| 534 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 535 | isl_surf_usage_flags_t cube_usage; |
| 536 | if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE || |
| 537 | pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { |
| 538 | cube_usage = ISL_SURF_USAGE_CUBE_BIT; |
| 539 | } else { |
| 540 | cube_usage = 0; |
| 541 | } |
| 542 | |
Jason Ekstrand | e9d126f | 2016-02-24 19:49:12 -0800 | [diff] [blame] | 543 | if (image->usage & usage_mask & VK_IMAGE_USAGE_SAMPLED_BIT) { |
Chad Versace | 42b9320 | 2016-02-04 11:41:59 -0800 | [diff] [blame] | 544 | iview->sampler_surface_state = alloc_surface_state(device, cmd_buffer); |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 545 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 546 | isl_view.usage = cube_usage | ISL_SURF_USAGE_TEXTURE_BIT; |
| 547 | isl_surf_fill_state(&device->isl_dev, |
| 548 | iview->sampler_surface_state.map, |
| 549 | .surf = &surface->isl, |
| 550 | .view = &isl_view, |
Nanley Chery | b80c8eb | 2016-03-03 15:40:13 -0800 | [diff] [blame] | 551 | .mocs = device->default_mocs); |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 552 | |
| 553 | if (!device->info.has_llc) |
| 554 | anv_state_clflush(iview->sampler_surface_state); |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 555 | } else { |
Chad Versace | 42b9320 | 2016-02-04 11:41:59 -0800 | [diff] [blame] | 556 | iview->sampler_surface_state.alloc_size = 0; |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Jason Ekstrand | e9d126f | 2016-02-24 19:49:12 -0800 | [diff] [blame] | 559 | if (image->usage & usage_mask & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 560 | iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer); |
| 561 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 562 | isl_view.usage = cube_usage | ISL_SURF_USAGE_RENDER_TARGET_BIT; |
| 563 | isl_surf_fill_state(&device->isl_dev, |
| 564 | iview->color_rt_surface_state.map, |
| 565 | .surf = &surface->isl, |
| 566 | .view = &isl_view, |
Nanley Chery | b80c8eb | 2016-03-03 15:40:13 -0800 | [diff] [blame] | 567 | .mocs = device->default_mocs); |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 568 | |
| 569 | if (!device->info.has_llc) |
| 570 | anv_state_clflush(iview->color_rt_surface_state); |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 571 | } else { |
| 572 | iview->color_rt_surface_state.alloc_size = 0; |
| 573 | } |
| 574 | |
Jason Ekstrand | e9d126f | 2016-02-24 19:49:12 -0800 | [diff] [blame] | 575 | if (image->usage & usage_mask & VK_IMAGE_USAGE_STORAGE_BIT) { |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 576 | iview->storage_surface_state = alloc_surface_state(device, cmd_buffer); |
| 577 | |
Jason Ekstrand | 9d5b8f7 | 2016-02-20 21:40:25 -0800 | [diff] [blame] | 578 | if (has_matching_storage_typed_format(device, format)) { |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 579 | isl_view.usage = cube_usage | ISL_SURF_USAGE_STORAGE_BIT; |
| 580 | isl_surf_fill_state(&device->isl_dev, |
| 581 | iview->storage_surface_state.map, |
| 582 | .surf = &surface->isl, |
| 583 | .view = &isl_view, |
Nanley Chery | b80c8eb | 2016-03-03 15:40:13 -0800 | [diff] [blame] | 584 | .mocs = device->default_mocs); |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 585 | } else { |
Francisco Jerez | 6840cc1 | 2016-01-26 14:50:52 -0800 | [diff] [blame] | 586 | anv_fill_buffer_surface_state(device, iview->storage_surface_state, |
Francisco Jerez | a50dc70 | 2016-01-26 12:23:08 -0800 | [diff] [blame] | 587 | ISL_FORMAT_RAW, |
| 588 | iview->offset, |
| 589 | iview->bo->size - iview->offset, 1); |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 590 | } |
Francisco Jerez | a50dc70 | 2016-01-26 12:23:08 -0800 | [diff] [blame] | 591 | |
Jason Ekstrand | 4b34f2c | 2016-02-24 12:50:31 -0800 | [diff] [blame] | 592 | isl_surf_fill_image_param(&device->isl_dev, |
| 593 | &iview->storage_image_param, |
| 594 | &surface->isl, &isl_view); |
Jason Ekstrand | 7363024 | 2016-02-24 11:38:14 -0800 | [diff] [blame] | 595 | |
Jason Ekstrand | ded57c3 | 2016-02-20 11:45:50 -0800 | [diff] [blame] | 596 | if (!device->info.has_llc) |
| 597 | anv_state_clflush(iview->storage_surface_state); |
Jason Ekstrand | e5558ff | 2016-01-22 11:57:01 -0800 | [diff] [blame] | 598 | } else { |
| 599 | iview->storage_surface_state.alloc_size = 0; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 603 | VkResult |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 604 | anv_CreateImageView(VkDevice _device, |
| 605 | const VkImageViewCreateInfo *pCreateInfo, |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 606 | const VkAllocationCallbacks *pAllocator, |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 607 | VkImageView *pView) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 608 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 609 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 610 | struct anv_image_view *view; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 611 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 612 | view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, |
| 613 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 614 | if (view == NULL) |
| 615 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 616 | |
Jason Ekstrand | e9d126f | 2016-02-24 19:49:12 -0800 | [diff] [blame] | 617 | anv_image_view_init(view, device, pCreateInfo, NULL, 0, ~0); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 618 | |
| 619 | *pView = anv_image_view_to_handle(view); |
| 620 | |
| 621 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 624 | void |
| 625 | anv_DestroyImageView(VkDevice _device, VkImageView _iview, |
| 626 | const VkAllocationCallbacks *pAllocator) |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 627 | { |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 628 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 629 | ANV_FROM_HANDLE(anv_image_view, iview, _iview); |
| 630 | |
Chad Versace | 3eebf36 | 2016-02-04 11:58:05 -0800 | [diff] [blame] | 631 | if (iview->color_rt_surface_state.alloc_size > 0) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 632 | anv_state_pool_free(&device->surface_state_pool, |
| 633 | iview->color_rt_surface_state); |
| 634 | } |
| 635 | |
Chad Versace | 3eebf36 | 2016-02-04 11:58:05 -0800 | [diff] [blame] | 636 | if (iview->sampler_surface_state.alloc_size > 0) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 637 | anv_state_pool_free(&device->surface_state_pool, |
Chad Versace | 42b9320 | 2016-02-04 11:41:59 -0800 | [diff] [blame] | 638 | iview->sampler_surface_state); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Chad Versace | 3eebf36 | 2016-02-04 11:58:05 -0800 | [diff] [blame] | 641 | if (iview->storage_surface_state.alloc_size > 0) { |
Jason Ekstrand | ff05f63 | 2015-12-07 17:17:30 -0800 | [diff] [blame] | 642 | anv_state_pool_free(&device->surface_state_pool, |
| 643 | iview->storage_surface_state); |
| 644 | } |
| 645 | |
Jason Ekstrand | fcfb404 | 2015-12-02 03:28:27 -0800 | [diff] [blame] | 646 | anv_free2(&device->alloc, pAllocator, iview); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 647 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 648 | |
Jason Ekstrand | c561860 | 2015-12-12 16:11:23 -0800 | [diff] [blame] | 649 | VkResult |
| 650 | anv_CreateBufferView(VkDevice _device, |
| 651 | const VkBufferViewCreateInfo *pCreateInfo, |
| 652 | const VkAllocationCallbacks *pAllocator, |
| 653 | VkBufferView *pView) |
| 654 | { |
| 655 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 656 | ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer); |
| 657 | struct anv_buffer_view *view; |
| 658 | |
Jason Ekstrand | c561860 | 2015-12-12 16:11:23 -0800 | [diff] [blame] | 659 | view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8, |
| 660 | VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 661 | if (!view) |
| 662 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 663 | |
Jason Ekstrand | c561860 | 2015-12-12 16:11:23 -0800 | [diff] [blame] | 664 | const struct anv_format *format = |
| 665 | anv_format_for_vk_format(pCreateInfo->format); |
| 666 | |
Chad Versace | 4d037b5 | 2016-02-08 18:51:52 -0800 | [diff] [blame] | 667 | view->format = format->isl_format; |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 668 | view->bo = buffer->bo; |
| 669 | view->offset = buffer->offset + pCreateInfo->offset; |
Jason Ekstrand | 56dbf13 | 2016-01-19 15:01:10 -0800 | [diff] [blame] | 670 | view->range = pCreateInfo->range == VK_WHOLE_SIZE ? |
| 671 | buffer->size - view->offset : pCreateInfo->range; |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 672 | |
| 673 | if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) { |
| 674 | view->surface_state = |
| 675 | anv_state_pool_alloc(&device->surface_state_pool, 64, 64); |
| 676 | |
Francisco Jerez | 6840cc1 | 2016-01-26 14:50:52 -0800 | [diff] [blame] | 677 | anv_fill_buffer_surface_state(device, view->surface_state, |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 678 | view->format, |
Jason Ekstrand | 56dbf13 | 2016-01-19 15:01:10 -0800 | [diff] [blame] | 679 | view->offset, view->range, |
Chad Versace | 89b68dc | 2016-01-05 09:59:07 -0800 | [diff] [blame] | 680 | format->isl_layout->bs); |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 681 | } else { |
| 682 | view->surface_state = (struct anv_state){ 0 }; |
| 683 | } |
| 684 | |
| 685 | if (buffer->usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) { |
| 686 | view->storage_surface_state = |
| 687 | anv_state_pool_alloc(&device->surface_state_pool, 64, 64); |
| 688 | |
| 689 | enum isl_format storage_format = |
Francisco Jerez | a50dc70 | 2016-01-26 12:23:08 -0800 | [diff] [blame] | 690 | has_matching_storage_typed_format(device, view->format) ? |
| 691 | isl_lower_storage_image_format(&device->isl_dev, view->format) : |
| 692 | ISL_FORMAT_RAW; |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 693 | |
Francisco Jerez | 6840cc1 | 2016-01-26 14:50:52 -0800 | [diff] [blame] | 694 | anv_fill_buffer_surface_state(device, view->storage_surface_state, |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 695 | storage_format, |
Jason Ekstrand | 56dbf13 | 2016-01-19 15:01:10 -0800 | [diff] [blame] | 696 | view->offset, view->range, |
Francisco Jerez | a50dc70 | 2016-01-26 12:23:08 -0800 | [diff] [blame] | 697 | (storage_format == ISL_FORMAT_RAW ? 1 : |
| 698 | format->isl_layout->bs)); |
| 699 | |
Jason Ekstrand | 4b34f2c | 2016-02-24 12:50:31 -0800 | [diff] [blame] | 700 | isl_buffer_fill_image_param(&device->isl_dev, |
| 701 | &view->storage_image_param, |
| 702 | view->format, view->range); |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 703 | } else { |
| 704 | view->storage_surface_state = (struct anv_state){ 0 }; |
| 705 | } |
Jason Ekstrand | c561860 | 2015-12-12 16:11:23 -0800 | [diff] [blame] | 706 | |
| 707 | *pView = anv_buffer_view_to_handle(view); |
| 708 | |
| 709 | return VK_SUCCESS; |
| 710 | } |
| 711 | |
| 712 | void |
| 713 | anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView, |
| 714 | const VkAllocationCallbacks *pAllocator) |
| 715 | { |
| 716 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 717 | ANV_FROM_HANDLE(anv_buffer_view, view, bufferView); |
| 718 | |
Jason Ekstrand | 783a211 | 2015-12-14 16:51:12 -0800 | [diff] [blame] | 719 | if (view->surface_state.alloc_size > 0) |
| 720 | anv_state_pool_free(&device->surface_state_pool, |
| 721 | view->surface_state); |
| 722 | |
| 723 | if (view->storage_surface_state.alloc_size > 0) |
| 724 | anv_state_pool_free(&device->surface_state_pool, |
| 725 | view->storage_surface_state); |
| 726 | |
Jason Ekstrand | c561860 | 2015-12-12 16:11:23 -0800 | [diff] [blame] | 727 | anv_free2(&device->alloc, pAllocator, view); |
| 728 | } |
| 729 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 730 | struct anv_surface * |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 731 | anv_image_get_surface_for_aspect_mask(struct anv_image *image, VkImageAspectFlags aspect_mask) |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 732 | { |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 733 | switch (aspect_mask) { |
| 734 | case VK_IMAGE_ASPECT_COLOR_BIT: |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 735 | /* Dragons will eat you. |
| 736 | * |
| 737 | * Meta attaches all destination surfaces as color render targets. Guess |
| 738 | * what surface the Meta Dragons really want. |
| 739 | */ |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 740 | if (image->format->has_depth && image->format->has_stencil) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 741 | return &image->depth_surface; |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 742 | } else if (image->format->has_depth) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 743 | return &image->depth_surface; |
| 744 | } else if (image->format->has_stencil) { |
| 745 | return &image->stencil_surface; |
| 746 | } else { |
| 747 | return &image->color_surface; |
| 748 | } |
| 749 | break; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 750 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 751 | assert(image->format->has_depth); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 752 | return &image->depth_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 753 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 754 | assert(image->format->has_stencil); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 755 | return &image->stencil_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 756 | case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 757 | if (image->format->has_depth && image->format->has_stencil) { |
Kristian Høgsberg Kristensen | 8e07f79 | 2016-01-25 15:14:47 -0800 | [diff] [blame] | 758 | /* FINISHME: The Vulkan spec (git a511ba2) requires support for |
| 759 | * combined depth stencil formats. Specifically, it states: |
Chad Versace | 03dd722 | 2015-10-07 09:03:47 -0700 | [diff] [blame] | 760 | * |
| 761 | * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or |
| 762 | * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported. |
Kristian Høgsberg Kristensen | 8e07f79 | 2016-01-25 15:14:47 -0800 | [diff] [blame] | 763 | * |
| 764 | * Image views with both depth and stencil aspects are only valid for |
| 765 | * render target attachments, in which case |
| 766 | * cmd_buffer_emit_depth_stencil() will pick out both the depth and |
| 767 | * stencil surfaces from the underlying surface. |
Chad Versace | 03dd722 | 2015-10-07 09:03:47 -0700 | [diff] [blame] | 768 | */ |
Chad Versace | 03dd722 | 2015-10-07 09:03:47 -0700 | [diff] [blame] | 769 | return &image->depth_surface; |
Chad Versace | e6d3432 | 2016-02-08 19:07:10 -0800 | [diff] [blame] | 770 | } else if (image->format->has_depth) { |
Chad Versace | 03dd722 | 2015-10-07 09:03:47 -0700 | [diff] [blame] | 771 | return &image->depth_surface; |
| 772 | } else if (image->format->has_stencil) { |
| 773 | return &image->stencil_surface; |
| 774 | } |
| 775 | /* fallthrough */ |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 776 | default: |
| 777 | unreachable("image does not have aspect"); |
| 778 | return NULL; |
| 779 | } |
| 780 | } |