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 | |
Jason Ekstrand | de54b4b | 2015-11-16 12:29:07 -0800 | [diff] [blame] | 32 | /* FIXME: We shouldn't be using the actual hardware enum values here. They |
| 33 | * change across gens. Once we get that fixed, this include needs to go. |
| 34 | */ |
| 35 | #include "gen8_pack.h" |
| 36 | |
Chad Versace | e6162c2 | 2015-06-09 12:11:46 -0700 | [diff] [blame] | 37 | static const uint8_t anv_halign[] = { |
| 38 | [4] = HALIGN4, |
| 39 | [8] = HALIGN8, |
| 40 | [16] = HALIGN16, |
| 41 | }; |
| 42 | |
| 43 | static const uint8_t anv_valign[] = { |
| 44 | [4] = VALIGN4, |
| 45 | [8] = VALIGN8, |
| 46 | [16] = VALIGN16, |
| 47 | }; |
| 48 | |
Chad Versace | cb30aca | 2015-05-28 07:37:59 -0700 | [diff] [blame] | 49 | static const uint8_t anv_surf_type_from_image_type[] = { |
| 50 | [VK_IMAGE_TYPE_1D] = SURFTYPE_1D, |
| 51 | [VK_IMAGE_TYPE_2D] = SURFTYPE_2D, |
| 52 | [VK_IMAGE_TYPE_3D] = SURFTYPE_3D, |
| 53 | }; |
| 54 | |
Chad Versace | 69e11ad | 2015-07-06 16:25:59 -0700 | [diff] [blame] | 55 | static const struct anv_image_view_info |
| 56 | anv_image_view_info_table[] = { |
| 57 | #define INFO(s, ...) { .surface_type = s, __VA_ARGS__ } |
| 58 | [VK_IMAGE_VIEW_TYPE_1D] = INFO(SURFTYPE_1D), |
| 59 | [VK_IMAGE_VIEW_TYPE_2D] = INFO(SURFTYPE_2D), |
| 60 | [VK_IMAGE_VIEW_TYPE_3D] = INFO(SURFTYPE_3D), |
| 61 | [VK_IMAGE_VIEW_TYPE_CUBE] = INFO(SURFTYPE_CUBE, .is_cube = 1), |
| 62 | [VK_IMAGE_VIEW_TYPE_1D_ARRAY] = INFO(SURFTYPE_1D, .is_array = 1), |
| 63 | [VK_IMAGE_VIEW_TYPE_2D_ARRAY] = INFO(SURFTYPE_2D, .is_array = 1), |
| 64 | [VK_IMAGE_VIEW_TYPE_CUBE_ARRAY] = INFO(SURFTYPE_CUBE, .is_array = 1, .is_cube = 1), |
| 65 | #undef INFO |
Chad Versace | cb30aca | 2015-05-28 07:37:59 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Chad Versace | 8bf021c | 2015-10-05 13:22:44 -0700 | [diff] [blame] | 68 | struct anv_image_view_info |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 69 | anv_image_view_info_for_vk_image_view_type(VkImageViewType type) |
| 70 | { |
Chad Versace | 8bf021c | 2015-10-05 13:22:44 -0700 | [diff] [blame] | 71 | return anv_image_view_info_table[type]; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 74 | static const struct anv_surf_type_limits { |
| 75 | int32_t width; |
| 76 | int32_t height; |
| 77 | int32_t depth; |
| 78 | } anv_surf_type_limits[] = { |
Chad Versace | 622a317 | 2015-09-14 14:37:09 -0700 | [diff] [blame] | 79 | [SURFTYPE_1D] = {16384, 1, 2048}, |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 80 | [SURFTYPE_2D] = {16384, 16384, 2048}, |
| 81 | [SURFTYPE_3D] = {2048, 2048, 2048}, |
| 82 | [SURFTYPE_CUBE] = {16384, 16384, 340}, |
| 83 | [SURFTYPE_BUFFER] = {128, 16384, 64}, |
| 84 | [SURFTYPE_STRBUF] = {128, 16384, 64}, |
| 85 | }; |
| 86 | |
Chad Versace | e6bd568 | 2015-06-09 13:29:08 -0700 | [diff] [blame] | 87 | static const struct anv_tile_info { |
Chad Versace | e6bd568 | 2015-06-09 13:29:08 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress. |
| 90 | * |
| 91 | * To simplify calculations, the alignments defined in the table are |
| 92 | * sometimes larger than required. For example, Skylake requires that X and |
| 93 | * Y tiled buffers be aligned to 4K, but Broadwell permits smaller |
| 94 | * alignment. We choose 4K to accomodate both chipsets. The alignment of |
| 95 | * a linear buffer depends on its element type and usage. Linear depth |
| 96 | * buffers have the largest alignment, 64B, so we choose that for all linear |
| 97 | * buffers. |
| 98 | */ |
| 99 | uint32_t surface_alignment; |
| 100 | } anv_tile_info_table[] = { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 101 | [ISL_TILING_LINEAR] = { 64 }, |
| 102 | [ISL_TILING_X] = { 4096 }, |
| 103 | [ISL_TILING_Y] = { 4096 }, |
| 104 | [ISL_TILING_Yf] = { 4096 }, |
| 105 | [ISL_TILING_Ys] = { 4096 }, |
| 106 | [ISL_TILING_W] = { 4096 }, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 109 | static enum isl_tiling |
| 110 | anv_image_choose_tiling(const struct anv_image_create_info *anv_info) |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 111 | { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 112 | if (anv_info->force_tiling) |
| 113 | return anv_info->tiling; |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 114 | |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 115 | /* The Sandybridge PRM says that the stencil buffer "is supported |
| 116 | * only in Tile W memory". |
| 117 | */ |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 118 | |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 119 | switch (anv_info->vk_info->tiling) { |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 120 | case VK_IMAGE_TILING_LINEAR: |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 121 | assert(anv_info->vk_info->format != VK_FORMAT_S8_UINT); |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 122 | return ISL_TILING_LINEAR; |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 123 | case VK_IMAGE_TILING_OPTIMAL: |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 124 | if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 125 | return ISL_TILING_W; |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 126 | } else { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 127 | return ISL_TILING_Y; |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 128 | } |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 129 | default: |
| 130 | assert(!"bad VKImageTiling"); |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 131 | return ISL_TILING_LINEAR; |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * The \a format argument is required and overrides any format in |
| 138 | * struct anv_image_create_info. |
| 139 | */ |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 140 | static VkResult |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 141 | anv_image_make_surface(const struct anv_device *dev, |
| 142 | const struct anv_image_create_info *create_info, |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 143 | const struct anv_format *format, |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 144 | uint64_t *inout_image_size, |
| 145 | uint32_t *inout_image_alignment, |
| 146 | struct anv_surface *out_surface) |
| 147 | { |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 148 | /* See RENDER_SURFACE_STATE.SurfaceQPitch */ |
| 149 | static const uint16_t min_qpitch UNUSED = 0x4; |
| 150 | static const uint16_t max_qpitch UNUSED = 0x1ffc; |
| 151 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 152 | const VkExtent3D *restrict extent = &create_info->vk_info->extent; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 153 | const uint32_t levels = create_info->vk_info->mipLevels; |
| 154 | const uint32_t array_size = create_info->vk_info->arraySize; |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 155 | const enum isl_tiling tiling = anv_image_choose_tiling(create_info); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 156 | |
| 157 | const struct anv_tile_info *tile_info = |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 158 | &anv_tile_info_table[tiling]; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 159 | |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 160 | const uint32_t bs = format->isl_layout->bs; |
| 161 | const uint32_t bw = format->isl_layout->bw; |
| 162 | const uint32_t bh = format->isl_layout->bh; |
| 163 | |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 164 | struct isl_extent2d tile_extent; |
| 165 | isl_tiling_get_extent(&dev->isl_dev, tiling, bs, &tile_extent); |
| 166 | |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 167 | const uint32_t i = MAX(4, bw); /* FINISHME: Stop hardcoding subimage alignment */ |
| 168 | const uint32_t j = MAX(4, bh); /* FINISHME: Stop hardcoding subimage alignment */ |
Nanley Chery | 41cf35d | 2015-10-02 16:11:24 -0700 | [diff] [blame] | 169 | assert(i == 4 || i == 8 || i == 16); |
| 170 | assert(j == 4 || j == 8 || j == 16); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 171 | |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 172 | uint16_t qpitch = min_qpitch; |
| 173 | uint32_t mt_width = 0; |
| 174 | uint32_t mt_height = 0; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 175 | |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 176 | switch (create_info->vk_info->imageType) { |
| 177 | case VK_IMAGE_TYPE_1D: |
Chad Versace | 622a317 | 2015-09-14 14:37:09 -0700 | [diff] [blame] | 178 | /* From the Broadwell PRM >> Memory Views >> Common Surface Formats >> |
| 179 | * Surface Layout >> 1D Surfaces: |
| 180 | * |
| 181 | * One-dimensional surfaces are identical to 2D surfaces with height of one. |
| 182 | * |
| 183 | * So fallthrough... |
| 184 | */ |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 185 | case VK_IMAGE_TYPE_2D: { |
| 186 | const uint32_t w0 = align_u32(extent->width, i); |
| 187 | const uint32_t h0 = align_u32(extent->height, j); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 188 | |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 189 | if (levels == 1 && array_size == 1) { |
| 190 | qpitch = min_qpitch; |
| 191 | mt_width = w0; |
| 192 | mt_height = h0; |
| 193 | } else { |
| 194 | uint32_t w1 = align_u32(anv_minify(extent->width, 1), i); |
| 195 | uint32_t h1 = align_u32(anv_minify(extent->height, 1), j); |
| 196 | uint32_t w2 = align_u32(anv_minify(extent->width, 2), i); |
| 197 | |
| 198 | /* The QPitch equation is found in the Broadwell PRM >> Volume 5: Memory |
| 199 | * Views >> Common Surface Formats >> Surface Layout >> 2D Surfaces >> |
| 200 | * Surface Arrays >> For All Surface Other Than Separate Stencil Buffer: |
| 201 | */ |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 202 | assert(bh ==1 || bh == 4); |
| 203 | qpitch = (h0 + h1 + 11 * j) / bh; |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 204 | mt_width = MAX(w0, w1 + w2); |
| 205 | mt_height = array_size * qpitch; |
| 206 | } |
| 207 | break; |
| 208 | } |
| 209 | case VK_IMAGE_TYPE_3D: |
Chad Versace | eed74e3 | 2015-09-14 11:04:08 -0700 | [diff] [blame] | 210 | /* The layout of 3D surfaces is described by the Broadwell PRM >> |
| 211 | * Volume 5: Memory Views >> Common Surface Formats >> Surface Layout >> |
| 212 | * 3D Surfaces. |
| 213 | */ |
| 214 | for (uint32_t l = 0; l < levels; ++l) { |
| 215 | const uint32_t w_l = align_u32(anv_minify(extent->width, l), i); |
| 216 | const uint32_t h_l = align_u32(anv_minify(extent->height, l), j); |
| 217 | const uint32_t d_l = anv_minify(extent->depth, l); |
| 218 | |
| 219 | const uint32_t max_layers_horiz = MIN(d_l, 1u << l); |
| 220 | const uint32_t max_layers_vert = align_u32(d_l, 1u << l) / (1u << l); |
| 221 | |
| 222 | mt_width = MAX(mt_width, w_l * max_layers_horiz); |
| 223 | mt_height += h_l * max_layers_vert; |
| 224 | } |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 225 | break; |
| 226 | default: |
| 227 | unreachable(!"bad VkImageType"); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | assert(qpitch >= min_qpitch); |
| 231 | if (qpitch > max_qpitch) { |
| 232 | anv_loge("image qpitch > 0x%x\n", max_qpitch); |
| 233 | return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
| 234 | } |
| 235 | |
| 236 | /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch: |
| 237 | * |
| 238 | * This field must be set an integer multiple of the Surface Vertical |
| 239 | * Alignment. |
| 240 | */ |
| 241 | assert(anv_is_aligned(qpitch, j)); |
| 242 | |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 243 | uint32_t stride = align_u32(mt_width * bs / bw, tile_extent.width); |
Kristian Høgsberg Kristensen | 6d09d06 | 2015-08-14 10:02:19 -0700 | [diff] [blame] | 244 | if (create_info->stride > 0) |
| 245 | stride = create_info->stride; |
| 246 | |
Nanley Chery | 381f602 | 2015-10-05 17:27:32 -0700 | [diff] [blame] | 247 | /* The padding requirement is found in the Broadwell PRM >> Volume 5: Memory |
| 248 | * Views >> Common Surface Formats >> Surface Padding Requirements >> |
| 249 | * Sampling Engine Surfaces >> Buffer Padding Requirements: |
| 250 | */ |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 251 | const uint32_t mem_rows = align_u32(mt_height / bh, 2 * bh); |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 252 | const uint32_t size = stride * align_u32(mem_rows, tile_extent.height); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 253 | const uint32_t offset = align_u32(*inout_image_size, |
| 254 | tile_info->surface_alignment); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 255 | |
| 256 | *inout_image_size = offset + size; |
| 257 | *inout_image_alignment = MAX(*inout_image_alignment, |
| 258 | tile_info->surface_alignment); |
| 259 | |
| 260 | *out_surface = (struct anv_surface) { |
| 261 | .offset = offset, |
| 262 | .stride = stride, |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 263 | .tiling = tiling, |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 264 | .qpitch = qpitch, |
| 265 | .h_align = i, |
| 266 | .v_align = j, |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 267 | }; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 268 | |
| 269 | return VK_SUCCESS; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 272 | static VkImageUsageFlags |
| 273 | anv_image_get_full_usage(const VkImageCreateInfo *info) |
| 274 | { |
| 275 | VkImageUsageFlags usage = info->usage; |
| 276 | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 277 | if (usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 278 | /* Meta will transfer from the image by binding it as a texture. */ |
| 279 | usage |= VK_IMAGE_USAGE_SAMPLED_BIT; |
| 280 | } |
| 281 | |
Jason Ekstrand | 6a8a542 | 2015-11-30 11:12:44 -0800 | [diff] [blame] | 282 | if (usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) { |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 283 | /* Meta will transfer to the image by binding it as a color attachment, |
| 284 | * even if the image format is not a color format. |
| 285 | */ |
| 286 | usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 287 | } |
| 288 | |
| 289 | return usage; |
| 290 | } |
| 291 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 292 | VkResult |
| 293 | anv_image_create(VkDevice _device, |
| 294 | const struct anv_image_create_info *create_info, |
| 295 | VkImage *pImage) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 296 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 297 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 298 | const VkImageCreateInfo *pCreateInfo = create_info->vk_info; |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 299 | const VkExtent3D *restrict extent = &pCreateInfo->extent; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 300 | struct anv_image *image = NULL; |
| 301 | VkResult r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 302 | |
| 303 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO); |
| 304 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 305 | anv_assert(pCreateInfo->mipLevels > 0); |
| 306 | anv_assert(pCreateInfo->arraySize > 0); |
Jason Ekstrand | 2a3c296 | 2015-06-10 21:04:51 -0700 | [diff] [blame] | 307 | anv_assert(pCreateInfo->samples == 1); |
Chad Versace | 5d7103e | 2015-06-26 09:05:46 -0700 | [diff] [blame] | 308 | anv_assert(pCreateInfo->extent.width > 0); |
| 309 | anv_assert(pCreateInfo->extent.height > 0); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 310 | anv_assert(pCreateInfo->extent.depth > 0); |
Jason Ekstrand | 2a3c296 | 2015-06-10 21:04:51 -0700 | [diff] [blame] | 311 | |
Chad Versace | 7ea1216 | 2015-05-28 07:45:31 -0700 | [diff] [blame] | 312 | /* TODO(chadv): How should we validate inputs? */ |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 313 | const uint8_t surf_type = |
| 314 | anv_surf_type_from_image_type[pCreateInfo->imageType]; |
Chad Versace | 7ea1216 | 2015-05-28 07:45:31 -0700 | [diff] [blame] | 315 | |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 316 | const struct anv_surf_type_limits *limits = |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 317 | &anv_surf_type_limits[surf_type]; |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 318 | |
Chad Versace | f9c948e | 2015-10-07 11:36:51 -0700 | [diff] [blame] | 319 | /* Errors should be caught by VkImageFormatProperties. */ |
| 320 | assert(extent->width <= limits->width); |
| 321 | assert(extent->height <= limits->height); |
| 322 | assert(extent->depth <= limits->depth); |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 323 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 324 | image = anv_device_alloc(device, sizeof(*image), 8, |
| 325 | VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
| 326 | if (!image) |
| 327 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 328 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 329 | memset(image, 0, sizeof(*image)); |
| 330 | image->type = pCreateInfo->imageType; |
| 331 | image->extent = pCreateInfo->extent; |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 332 | image->format = anv_format_for_vk_format(pCreateInfo->format); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 333 | image->levels = pCreateInfo->mipLevels; |
| 334 | image->array_size = pCreateInfo->arraySize; |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 335 | image->usage = anv_image_get_full_usage(pCreateInfo); |
| 336 | image->surface_type = surf_type; |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 337 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 338 | if (image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | |
| 339 | VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 340 | image->needs_nonrt_surface_state = true; |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 343 | if (image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
| 344 | image->needs_color_rt_surface_state = true; |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 347 | if (likely(anv_format_is_color(image->format))) { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 348 | r = anv_image_make_surface(device, create_info, image->format, |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 349 | &image->size, &image->alignment, |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 350 | &image->color_surface); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 351 | if (r != VK_SUCCESS) |
| 352 | goto fail; |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 353 | } else { |
| 354 | if (image->format->depth_format) { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 355 | r = anv_image_make_surface(device, create_info, image->format, |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 356 | &image->size, &image->alignment, |
| 357 | &image->depth_surface); |
| 358 | if (r != VK_SUCCESS) |
| 359 | goto fail; |
| 360 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 361 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 362 | if (image->format->has_stencil) { |
Chad Versace | ba46746 | 2015-11-13 10:24:57 -0800 | [diff] [blame] | 363 | r = anv_image_make_surface(device, create_info, anv_format_s8_uint, |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 364 | &image->size, &image->alignment, |
| 365 | &image->stencil_surface); |
| 366 | if (r != VK_SUCCESS) |
| 367 | goto fail; |
| 368 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 369 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 370 | |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 371 | *pImage = anv_image_to_handle(image); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 372 | |
| 373 | return VK_SUCCESS; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 374 | |
| 375 | fail: |
| 376 | if (image) |
| 377 | anv_device_free(device, image); |
| 378 | |
| 379 | return r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 382 | VkResult |
| 383 | anv_CreateImage(VkDevice device, |
| 384 | const VkImageCreateInfo *pCreateInfo, |
| 385 | VkImage *pImage) |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 386 | { |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 387 | return anv_image_create(device, |
| 388 | &(struct anv_image_create_info) { |
| 389 | .vk_info = pCreateInfo, |
| 390 | }, |
| 391 | pImage); |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 394 | void |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 395 | anv_DestroyImage(VkDevice _device, VkImage _image) |
| 396 | { |
| 397 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 398 | |
| 399 | anv_device_free(device, anv_image_from_handle(_image)); |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 402 | static void |
| 403 | anv_surface_get_subresource_layout(struct anv_image *image, |
| 404 | struct anv_surface *surface, |
| 405 | const VkImageSubresource *subresource, |
| 406 | VkSubresourceLayout *layout) |
| 407 | { |
| 408 | /* If we are on a non-zero mip level or array slice, we need to |
| 409 | * calculate a real offset. |
| 410 | */ |
| 411 | anv_assert(subresource->mipLevel == 0); |
| 412 | anv_assert(subresource->arrayLayer == 0); |
| 413 | |
| 414 | layout->offset = surface->offset; |
| 415 | layout->rowPitch = surface->stride; |
| 416 | layout->depthPitch = surface->qpitch; |
| 417 | |
| 418 | /* FINISHME: We really shouldn't be doing this calculation here */ |
| 419 | if (image->array_size > 1) |
| 420 | layout->size = surface->qpitch * image->array_size; |
| 421 | else |
| 422 | layout->size = surface->stride * image->extent.height; |
| 423 | } |
| 424 | |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 425 | void anv_GetImageSubresourceLayout( |
Jason Ekstrand | db24afe | 2015-07-07 18:20:18 -0700 | [diff] [blame] | 426 | VkDevice device, |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 427 | VkImage _image, |
Jason Ekstrand | db24afe | 2015-07-07 18:20:18 -0700 | [diff] [blame] | 428 | const VkImageSubresource* pSubresource, |
| 429 | VkSubresourceLayout* pLayout) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 430 | { |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 431 | ANV_FROM_HANDLE(anv_image, image, _image); |
| 432 | |
| 433 | switch (pSubresource->aspect) { |
| 434 | case VK_IMAGE_ASPECT_COLOR: |
| 435 | anv_surface_get_subresource_layout(image, &image->color_surface, |
| 436 | pSubresource, pLayout); |
| 437 | break; |
| 438 | case VK_IMAGE_ASPECT_DEPTH: |
| 439 | anv_surface_get_subresource_layout(image, &image->depth_surface, |
| 440 | pSubresource, pLayout); |
| 441 | break; |
| 442 | case VK_IMAGE_ASPECT_STENCIL: |
| 443 | anv_surface_get_subresource_layout(image, &image->stencil_surface, |
| 444 | pSubresource, pLayout); |
| 445 | break; |
| 446 | default: |
Jason Ekstrand | f1a7c78 | 2015-11-30 12:21:19 -0800 | [diff] [blame] | 447 | assert(!"Invalid image aspect"); |
Jason Ekstrand | db5a5fc | 2015-10-13 15:50:02 -0700 | [diff] [blame] | 448 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 451 | VkResult |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 452 | anv_validate_CreateImageView(VkDevice _device, |
| 453 | const VkImageViewCreateInfo *pCreateInfo, |
| 454 | VkImageView *pView) |
| 455 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 456 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 457 | const VkImageSubresourceRange *subresource; |
| 458 | const struct anv_image_view_info *view_info; |
| 459 | const struct anv_format *view_format_info; |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 460 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 461 | /* Validate structure type before dereferencing it. */ |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 462 | assert(pCreateInfo); |
| 463 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 464 | subresource = &pCreateInfo->subresourceRange; |
| 465 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 466 | /* Validate viewType is in range before using it. */ |
| 467 | assert(pCreateInfo->viewType >= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE); |
| 468 | assert(pCreateInfo->viewType <= VK_IMAGE_VIEW_TYPE_END_RANGE); |
| 469 | view_info = &anv_image_view_info_table[pCreateInfo->viewType]; |
| 470 | |
| 471 | /* Validate format is in range before using it. */ |
| 472 | assert(pCreateInfo->format >= VK_FORMAT_BEGIN_RANGE); |
| 473 | assert(pCreateInfo->format <= VK_FORMAT_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 474 | view_format_info = anv_format_for_vk_format(pCreateInfo->format); |
| 475 | |
| 476 | /* Validate channel swizzles. */ |
Jason Ekstrand | a53f23d | 2015-11-30 13:06:12 -0800 | [diff] [blame^] | 477 | assert(pCreateInfo->components.r >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 478 | assert(pCreateInfo->components.r <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 479 | assert(pCreateInfo->components.g >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 480 | assert(pCreateInfo->components.g <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 481 | assert(pCreateInfo->components.b >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 482 | assert(pCreateInfo->components.b <= VK_COMPONENT_SWIZZLE_END_RANGE); |
| 483 | assert(pCreateInfo->components.a >= VK_COMPONENT_SWIZZLE_BEGIN_RANGE); |
| 484 | assert(pCreateInfo->components.a <= VK_COMPONENT_SWIZZLE_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 485 | |
| 486 | /* Validate subresource. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 487 | assert(subresource->aspectMask != 0); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 488 | assert(subresource->mipLevels > 0); |
| 489 | assert(subresource->arraySize > 0); |
| 490 | assert(subresource->baseMipLevel < image->levels); |
| 491 | assert(subresource->baseMipLevel + subresource->mipLevels <= image->levels); |
Jason Ekstrand | 1e4263b | 2015-10-06 10:27:50 -0700 | [diff] [blame] | 492 | assert(subresource->baseArrayLayer < image->array_size); |
| 493 | assert(subresource->baseArrayLayer + subresource->arraySize <= image->array_size); |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 494 | assert(pView); |
| 495 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 496 | if (view_info->is_cube) { |
Jason Ekstrand | 1e4263b | 2015-10-06 10:27:50 -0700 | [diff] [blame] | 497 | assert(subresource->baseArrayLayer % 6 == 0); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 498 | assert(subresource->arraySize % 6 == 0); |
| 499 | } |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 500 | |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 501 | const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT |
| 502 | | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 503 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 504 | /* Validate format. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 505 | if (subresource->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 506 | assert(subresource->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT); |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 507 | assert(!image->format->depth_format); |
| 508 | assert(!image->format->has_stencil); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 509 | assert(!view_format_info->depth_format); |
| 510 | assert(!view_format_info->has_stencil); |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 511 | assert(view_format_info->isl_layout->bs == |
| 512 | image->format->isl_layout->bs); |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 513 | } else if (subresource->aspectMask & ds_flags) { |
| 514 | assert((subresource->aspectMask & ~ds_flags) == 0); |
| 515 | |
| 516 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 517 | assert(image->format->depth_format); |
| 518 | assert(view_format_info->depth_format); |
Chad Versace | addc2a9 | 2015-11-12 12:14:43 -0800 | [diff] [blame] | 519 | assert(view_format_info->isl_layout->bs == |
| 520 | image->format->isl_layout->bs); |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL) { |
| 524 | /* FINISHME: Is it legal to have an R8 view of S8? */ |
| 525 | assert(image->format->has_stencil); |
| 526 | assert(view_format_info->has_stencil); |
| 527 | } |
| 528 | } else { |
| 529 | assert(!"bad VkImageSubresourceRange::aspectFlags"); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 530 | } |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 531 | |
| 532 | return anv_CreateImageView(_device, pCreateInfo, pView); |
| 533 | } |
| 534 | |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 535 | void |
| 536 | anv_image_view_init(struct anv_image_view *iview, |
| 537 | struct anv_device *device, |
| 538 | const VkImageViewCreateInfo* pCreateInfo, |
| 539 | struct anv_cmd_buffer *cmd_buffer) |
| 540 | { |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 541 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 542 | const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange; |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 543 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 544 | assert(range->arraySize > 0); |
| 545 | assert(range->baseMipLevel < image->levels); |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 546 | assert(image->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 547 | VK_IMAGE_USAGE_STORAGE_BIT | |
| 548 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
Chad Versace | 0ca3c84 | 2015-10-07 11:39:49 -0700 | [diff] [blame] | 549 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)); |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 550 | |
| 551 | switch (image->type) { |
| 552 | default: |
| 553 | unreachable("bad VkImageType"); |
| 554 | case VK_IMAGE_TYPE_1D: |
| 555 | case VK_IMAGE_TYPE_2D: |
| 556 | assert(range->baseArrayLayer + range->arraySize - 1 <= image->array_size); |
| 557 | break; |
| 558 | case VK_IMAGE_TYPE_3D: |
| 559 | assert(range->baseArrayLayer + range->arraySize - 1 |
| 560 | <= anv_minify(image->extent.depth, range->baseMipLevel)); |
| 561 | break; |
| 562 | } |
Chad Versace | 44143a1 | 2015-10-06 18:17:09 -0700 | [diff] [blame] | 563 | |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 564 | switch (device->info.gen) { |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 565 | case 7: |
Jason Ekstrand | f0390bc | 2015-11-17 07:07:02 -0800 | [diff] [blame] | 566 | if (device->info.is_haswell) |
| 567 | gen75_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
| 568 | else |
| 569 | gen7_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 570 | break; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 571 | case 8: |
| 572 | gen8_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
| 573 | break; |
Kristian Høgsberg Kristensen | cd4721c | 2015-11-25 22:27:01 -0800 | [diff] [blame] | 574 | case 9: |
| 575 | gen9_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
| 576 | break; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 577 | default: |
| 578 | unreachable("unsupported gen\n"); |
| 579 | } |
| 580 | } |
| 581 | |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 582 | VkResult |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 583 | anv_CreateImageView(VkDevice _device, |
| 584 | const VkImageViewCreateInfo *pCreateInfo, |
| 585 | VkImageView *pView) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 586 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 587 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 588 | struct anv_image_view *view; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 589 | |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 590 | view = anv_device_alloc(device, sizeof(*view), 8, |
| 591 | VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
| 592 | if (view == NULL) |
| 593 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 594 | |
| 595 | anv_image_view_init(view, device, pCreateInfo, NULL); |
| 596 | |
| 597 | *pView = anv_image_view_to_handle(view); |
| 598 | |
| 599 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 602 | static void |
| 603 | anv_image_view_destroy(struct anv_device *device, |
| 604 | struct anv_image_view *iview) |
| 605 | { |
| 606 | if (iview->image->needs_color_rt_surface_state) { |
| 607 | anv_state_pool_free(&device->surface_state_pool, |
| 608 | iview->color_rt_surface_state); |
| 609 | } |
| 610 | |
| 611 | if (iview->image->needs_nonrt_surface_state) { |
| 612 | anv_state_pool_free(&device->surface_state_pool, |
| 613 | iview->nonrt_surface_state); |
| 614 | } |
| 615 | |
| 616 | anv_device_free(device, iview); |
| 617 | } |
| 618 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 619 | void |
Chad Versace | 8213be7 | 2015-07-15 12:00:27 -0700 | [diff] [blame] | 620 | anv_DestroyImageView(VkDevice _device, VkImageView _iview) |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 621 | { |
| 622 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | 8213be7 | 2015-07-15 12:00:27 -0700 | [diff] [blame] | 623 | ANV_FROM_HANDLE(anv_image_view, iview, _iview); |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 624 | |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 625 | anv_image_view_destroy(device, iview); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 626 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 627 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 628 | struct anv_surface * |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 629 | 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] | 630 | { |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 631 | switch (aspect_mask) { |
| 632 | case VK_IMAGE_ASPECT_COLOR_BIT: |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 633 | /* Dragons will eat you. |
| 634 | * |
| 635 | * Meta attaches all destination surfaces as color render targets. Guess |
| 636 | * what surface the Meta Dragons really want. |
| 637 | */ |
| 638 | if (image->format->depth_format && image->format->has_stencil) { |
| 639 | anv_finishme("combined depth stencil formats"); |
| 640 | return &image->depth_surface; |
| 641 | } else if (image->format->depth_format) { |
| 642 | return &image->depth_surface; |
| 643 | } else if (image->format->has_stencil) { |
| 644 | return &image->stencil_surface; |
| 645 | } else { |
| 646 | return &image->color_surface; |
| 647 | } |
| 648 | break; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 649 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 650 | assert(image->format->depth_format); |
| 651 | return &image->depth_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 652 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 653 | assert(image->format->has_stencil); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 654 | return &image->stencil_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 655 | case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | 03dd722 | 2015-10-07 09:03:47 -0700 | [diff] [blame] | 656 | if (image->format->depth_format && image->format->has_stencil) { |
| 657 | /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined |
| 658 | * depth stencil formats. Specifically, it states: |
| 659 | * |
| 660 | * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or |
| 661 | * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported. |
| 662 | */ |
| 663 | anv_finishme("combined depthstencil aspect"); |
| 664 | return &image->depth_surface; |
| 665 | } else if (image->format->depth_format) { |
| 666 | return &image->depth_surface; |
| 667 | } else if (image->format->has_stencil) { |
| 668 | return &image->stencil_surface; |
| 669 | } |
| 670 | /* fallthrough */ |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 671 | default: |
| 672 | unreachable("image does not have aspect"); |
| 673 | return NULL; |
| 674 | } |
| 675 | } |
| 676 | |
Chad Versace | 6dea1a9 | 2015-10-07 07:30:52 -0700 | [diff] [blame] | 677 | #if 0 |
Chad Versace | 24de3d4 | 2015-10-06 19:11:58 -0700 | [diff] [blame] | 678 | VkImageAspectFlags aspect_mask = 0; |
| 679 | if (format->depth_format) |
| 680 | aspect_mask |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 681 | if (format->has_stencil) |
| 682 | aspect_mask |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 683 | if (!aspect_mask) |
| 684 | aspect_mask |= VK_IMAGE_ASPECT_COLOR_BIT; |
| 685 | |
| 686 | anv_image_view_init(iview, device, |
| 687 | &(VkImageViewCreateInfo) { |
| 688 | .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 689 | .image = info->image, |
| 690 | .viewType = VK_IMAGE_VIEW_TYPE_2D, |
| 691 | .format = info->format, |
| 692 | .channels = { |
| 693 | .r = VK_CHANNEL_SWIZZLE_R, |
| 694 | .g = VK_CHANNEL_SWIZZLE_G, |
| 695 | .b = VK_CHANNEL_SWIZZLE_B, |
| 696 | .a = VK_CHANNEL_SWIZZLE_A, |
| 697 | }, |
| 698 | .subresourceRange = { |
| 699 | .aspectMask = aspect_mask, |
| 700 | .baseMipLevel = info->mipLevel, |
| 701 | .mipLevels = 1, |
| 702 | .baseArrayLayer = info->baseArraySlice, |
| 703 | .arraySize = info->arraySize, |
| 704 | }, |
| 705 | }, |
| 706 | NULL); |
Chad Versace | 6dea1a9 | 2015-10-07 07:30:52 -0700 | [diff] [blame] | 707 | #endif |