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 | e6162c2 | 2015-06-09 12:11:46 -0700 | [diff] [blame] | 32 | static const uint8_t anv_halign[] = { |
| 33 | [4] = HALIGN4, |
| 34 | [8] = HALIGN8, |
| 35 | [16] = HALIGN16, |
| 36 | }; |
| 37 | |
| 38 | static const uint8_t anv_valign[] = { |
| 39 | [4] = VALIGN4, |
| 40 | [8] = VALIGN8, |
| 41 | [16] = VALIGN16, |
| 42 | }; |
| 43 | |
Chad Versace | cb30aca | 2015-05-28 07:37:59 -0700 | [diff] [blame] | 44 | static const uint8_t anv_surf_type_from_image_type[] = { |
| 45 | [VK_IMAGE_TYPE_1D] = SURFTYPE_1D, |
| 46 | [VK_IMAGE_TYPE_2D] = SURFTYPE_2D, |
| 47 | [VK_IMAGE_TYPE_3D] = SURFTYPE_3D, |
Chad Versace | 69e11ad | 2015-07-06 16:25:59 -0700 | [diff] [blame] | 48 | |
Chad Versace | cb30aca | 2015-05-28 07:37:59 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Chad Versace | 69e11ad | 2015-07-06 16:25:59 -0700 | [diff] [blame] | 51 | static const struct anv_image_view_info |
| 52 | anv_image_view_info_table[] = { |
| 53 | #define INFO(s, ...) { .surface_type = s, __VA_ARGS__ } |
| 54 | [VK_IMAGE_VIEW_TYPE_1D] = INFO(SURFTYPE_1D), |
| 55 | [VK_IMAGE_VIEW_TYPE_2D] = INFO(SURFTYPE_2D), |
| 56 | [VK_IMAGE_VIEW_TYPE_3D] = INFO(SURFTYPE_3D), |
| 57 | [VK_IMAGE_VIEW_TYPE_CUBE] = INFO(SURFTYPE_CUBE, .is_cube = 1), |
| 58 | [VK_IMAGE_VIEW_TYPE_1D_ARRAY] = INFO(SURFTYPE_1D, .is_array = 1), |
| 59 | [VK_IMAGE_VIEW_TYPE_2D_ARRAY] = INFO(SURFTYPE_2D, .is_array = 1), |
| 60 | [VK_IMAGE_VIEW_TYPE_CUBE_ARRAY] = INFO(SURFTYPE_CUBE, .is_array = 1, .is_cube = 1), |
| 61 | #undef INFO |
Chad Versace | cb30aca | 2015-05-28 07:37:59 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
Chad Versace | 8bf021c | 2015-10-05 13:22:44 -0700 | [diff] [blame] | 64 | struct anv_image_view_info |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 65 | anv_image_view_info_for_vk_image_view_type(VkImageViewType type) |
| 66 | { |
Chad Versace | 8bf021c | 2015-10-05 13:22:44 -0700 | [diff] [blame] | 67 | return anv_image_view_info_table[type]; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 70 | static const struct anv_surf_type_limits { |
| 71 | int32_t width; |
| 72 | int32_t height; |
| 73 | int32_t depth; |
| 74 | } anv_surf_type_limits[] = { |
Chad Versace | 622a317 | 2015-09-14 14:37:09 -0700 | [diff] [blame] | 75 | [SURFTYPE_1D] = {16384, 1, 2048}, |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 76 | [SURFTYPE_2D] = {16384, 16384, 2048}, |
| 77 | [SURFTYPE_3D] = {2048, 2048, 2048}, |
| 78 | [SURFTYPE_CUBE] = {16384, 16384, 340}, |
| 79 | [SURFTYPE_BUFFER] = {128, 16384, 64}, |
| 80 | [SURFTYPE_STRBUF] = {128, 16384, 64}, |
| 81 | }; |
| 82 | |
Chad Versace | e6bd568 | 2015-06-09 13:29:08 -0700 | [diff] [blame] | 83 | static const struct anv_tile_info { |
| 84 | uint32_t width; |
| 85 | uint32_t height; |
| 86 | |
| 87 | /** |
| 88 | * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress. |
| 89 | * |
| 90 | * To simplify calculations, the alignments defined in the table are |
| 91 | * sometimes larger than required. For example, Skylake requires that X and |
| 92 | * Y tiled buffers be aligned to 4K, but Broadwell permits smaller |
| 93 | * alignment. We choose 4K to accomodate both chipsets. The alignment of |
| 94 | * a linear buffer depends on its element type and usage. Linear depth |
| 95 | * buffers have the largest alignment, 64B, so we choose that for all linear |
| 96 | * buffers. |
| 97 | */ |
| 98 | uint32_t surface_alignment; |
| 99 | } anv_tile_info_table[] = { |
| 100 | [LINEAR] = { 1, 1, 64 }, |
| 101 | [XMAJOR] = { 512, 8, 4096 }, |
| 102 | [YMAJOR] = { 128, 32, 4096 }, |
| 103 | [WMAJOR] = { 128, 32, 4096 }, |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 106 | /** |
| 107 | * Return -1 on failure. |
| 108 | */ |
| 109 | static int8_t |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 110 | anv_image_choose_tile_mode(const struct anv_image_create_info *anv_info) |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 111 | { |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 112 | if (anv_info->force_tile_mode) |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 113 | return anv_info->tile_mode; |
| 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 | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 121 | if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) { |
| 122 | return -1; |
| 123 | } else { |
| 124 | return LINEAR; |
| 125 | } |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 126 | case VK_IMAGE_TILING_OPTIMAL: |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 127 | if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) { |
| 128 | return WMAJOR; |
| 129 | } else { |
| 130 | return YMAJOR; |
| 131 | } |
Chad Versace | f1db3b3 | 2015-06-09 14:33:05 -0700 | [diff] [blame] | 132 | default: |
| 133 | assert(!"bad VKImageTiling"); |
| 134 | return LINEAR; |
| 135 | } |
| 136 | } |
| 137 | |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * The \a format argument is required and overrides any format in |
| 141 | * struct anv_image_create_info. |
| 142 | */ |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 143 | static VkResult |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 144 | anv_image_make_surface(const struct anv_image_create_info *create_info, |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 145 | const struct anv_format *format, |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 146 | uint64_t *inout_image_size, |
| 147 | uint32_t *inout_image_alignment, |
| 148 | struct anv_surface *out_surface) |
| 149 | { |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 150 | /* See RENDER_SURFACE_STATE.SurfaceQPitch */ |
| 151 | static const uint16_t min_qpitch UNUSED = 0x4; |
| 152 | static const uint16_t max_qpitch UNUSED = 0x1ffc; |
| 153 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 154 | const VkExtent3D *restrict extent = &create_info->vk_info->extent; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 155 | const uint32_t levels = create_info->vk_info->mipLevels; |
| 156 | const uint32_t array_size = create_info->vk_info->arraySize; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 157 | |
Chad Versace | 053d32d | 2015-08-28 08:04:59 -0700 | [diff] [blame] | 158 | const int8_t tile_mode = anv_image_choose_tile_mode(create_info); |
| 159 | if (tile_mode == -1) |
| 160 | return vk_error(VK_ERROR_INVALID_IMAGE); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 161 | |
| 162 | const struct anv_tile_info *tile_info = |
| 163 | &anv_tile_info_table[tile_mode]; |
| 164 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 165 | const uint32_t i = 4; /* FINISHME: Stop hardcoding subimage alignment */ |
| 166 | const uint32_t j = 4; /* FINISHME: Stop hardcoding subimage alignment */ |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 167 | |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 168 | uint16_t qpitch = min_qpitch; |
| 169 | uint32_t mt_width = 0; |
| 170 | uint32_t mt_height = 0; |
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 | switch (create_info->vk_info->imageType) { |
| 173 | case VK_IMAGE_TYPE_1D: |
Chad Versace | 622a317 | 2015-09-14 14:37:09 -0700 | [diff] [blame] | 174 | /* From the Broadwell PRM >> Memory Views >> Common Surface Formats >> |
| 175 | * Surface Layout >> 1D Surfaces: |
| 176 | * |
| 177 | * One-dimensional surfaces are identical to 2D surfaces with height of one. |
| 178 | * |
| 179 | * So fallthrough... |
| 180 | */ |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 181 | case VK_IMAGE_TYPE_2D: { |
| 182 | const uint32_t w0 = align_u32(extent->width, i); |
| 183 | const uint32_t h0 = align_u32(extent->height, j); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 184 | |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 185 | if (levels == 1 && array_size == 1) { |
| 186 | qpitch = min_qpitch; |
| 187 | mt_width = w0; |
| 188 | mt_height = h0; |
| 189 | } else { |
| 190 | uint32_t w1 = align_u32(anv_minify(extent->width, 1), i); |
| 191 | uint32_t h1 = align_u32(anv_minify(extent->height, 1), j); |
| 192 | uint32_t w2 = align_u32(anv_minify(extent->width, 2), i); |
| 193 | |
| 194 | /* The QPitch equation is found in the Broadwell PRM >> Volume 5: Memory |
| 195 | * Views >> Common Surface Formats >> Surface Layout >> 2D Surfaces >> |
| 196 | * Surface Arrays >> For All Surface Other Than Separate Stencil Buffer: |
| 197 | */ |
| 198 | qpitch = h0 + h1 + 11 * j; |
| 199 | mt_width = MAX(w0, w1 + w2); |
| 200 | mt_height = array_size * qpitch; |
| 201 | } |
| 202 | break; |
| 203 | } |
| 204 | case VK_IMAGE_TYPE_3D: |
Chad Versace | eed74e3 | 2015-09-14 11:04:08 -0700 | [diff] [blame] | 205 | /* The layout of 3D surfaces is described by the Broadwell PRM >> |
| 206 | * Volume 5: Memory Views >> Common Surface Formats >> Surface Layout >> |
| 207 | * 3D Surfaces. |
| 208 | */ |
| 209 | for (uint32_t l = 0; l < levels; ++l) { |
| 210 | const uint32_t w_l = align_u32(anv_minify(extent->width, l), i); |
| 211 | const uint32_t h_l = align_u32(anv_minify(extent->height, l), j); |
| 212 | const uint32_t d_l = anv_minify(extent->depth, l); |
| 213 | |
| 214 | const uint32_t max_layers_horiz = MIN(d_l, 1u << l); |
| 215 | const uint32_t max_layers_vert = align_u32(d_l, 1u << l) / (1u << l); |
| 216 | |
| 217 | mt_width = MAX(mt_width, w_l * max_layers_horiz); |
| 218 | mt_height += h_l * max_layers_vert; |
| 219 | } |
Chad Versace | e01d5a0 | 2015-09-14 10:58:43 -0700 | [diff] [blame] | 220 | break; |
| 221 | default: |
| 222 | unreachable(!"bad VkImageType"); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | assert(qpitch >= min_qpitch); |
| 226 | if (qpitch > max_qpitch) { |
| 227 | anv_loge("image qpitch > 0x%x\n", max_qpitch); |
| 228 | return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
| 229 | } |
| 230 | |
| 231 | /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch: |
| 232 | * |
| 233 | * This field must be set an integer multiple of the Surface Vertical |
| 234 | * Alignment. |
| 235 | */ |
| 236 | assert(anv_is_aligned(qpitch, j)); |
| 237 | |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 238 | uint32_t stride = align_u32(mt_width * format->cpp, tile_info->width); |
Kristian Høgsberg Kristensen | 6d09d06 | 2015-08-14 10:02:19 -0700 | [diff] [blame] | 239 | if (create_info->stride > 0) |
| 240 | stride = create_info->stride; |
| 241 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 242 | const uint32_t size = stride * align_u32(mt_height, tile_info->height); |
| 243 | const uint32_t offset = align_u32(*inout_image_size, |
| 244 | tile_info->surface_alignment); |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 245 | |
| 246 | *inout_image_size = offset + size; |
| 247 | *inout_image_alignment = MAX(*inout_image_alignment, |
| 248 | tile_info->surface_alignment); |
| 249 | |
| 250 | *out_surface = (struct anv_surface) { |
| 251 | .offset = offset, |
| 252 | .stride = stride, |
| 253 | .tile_mode = tile_mode, |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 254 | .qpitch = qpitch, |
| 255 | .h_align = i, |
| 256 | .v_align = j, |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 257 | }; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 258 | |
| 259 | return VK_SUCCESS; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 262 | VkResult |
| 263 | anv_image_create(VkDevice _device, |
| 264 | const struct anv_image_create_info *create_info, |
| 265 | VkImage *pImage) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 266 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 267 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 268 | const VkImageCreateInfo *pCreateInfo = create_info->vk_info; |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 269 | const VkExtent3D *restrict extent = &pCreateInfo->extent; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 270 | struct anv_image *image = NULL; |
| 271 | VkResult r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 272 | |
| 273 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO); |
| 274 | |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 275 | anv_assert(pCreateInfo->mipLevels > 0); |
| 276 | anv_assert(pCreateInfo->arraySize > 0); |
Jason Ekstrand | 2a3c296 | 2015-06-10 21:04:51 -0700 | [diff] [blame] | 277 | anv_assert(pCreateInfo->samples == 1); |
Chad Versace | 5d7103e | 2015-06-26 09:05:46 -0700 | [diff] [blame] | 278 | anv_assert(pCreateInfo->extent.width > 0); |
| 279 | anv_assert(pCreateInfo->extent.height > 0); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 280 | anv_assert(pCreateInfo->extent.depth > 0); |
Jason Ekstrand | 2a3c296 | 2015-06-10 21:04:51 -0700 | [diff] [blame] | 281 | |
Chad Versace | 7ea1216 | 2015-05-28 07:45:31 -0700 | [diff] [blame] | 282 | /* TODO(chadv): How should we validate inputs? */ |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 283 | const uint8_t surf_type = |
| 284 | anv_surf_type_from_image_type[pCreateInfo->imageType]; |
Chad Versace | 7ea1216 | 2015-05-28 07:45:31 -0700 | [diff] [blame] | 285 | |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 286 | const struct anv_surf_type_limits *limits = |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 287 | &anv_surf_type_limits[surf_type]; |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 288 | |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 289 | if (extent->width > limits->width || |
| 290 | extent->height > limits->height || |
| 291 | extent->depth > limits->depth) { |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 292 | /* TODO(chadv): What is the correct error? */ |
Kristian Høgsberg Kristensen | c4b30e7 | 2015-08-26 04:03:38 -0700 | [diff] [blame] | 293 | return vk_errorf(VK_ERROR_INVALID_MEMORY_SIZE, "image extent is too large"); |
Chad Versace | fa35296 | 2015-05-28 07:40:22 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 296 | image = anv_device_alloc(device, sizeof(*image), 8, |
| 297 | VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
| 298 | if (!image) |
| 299 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 300 | |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 301 | memset(image, 0, sizeof(*image)); |
| 302 | image->type = pCreateInfo->imageType; |
| 303 | image->extent = pCreateInfo->extent; |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 304 | image->format = anv_format_for_vk_format(pCreateInfo->format); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 305 | image->levels = pCreateInfo->mipLevels; |
| 306 | image->array_size = pCreateInfo->arraySize; |
Chad Versace | c6e76ae | 2015-06-26 18:48:34 -0700 | [diff] [blame] | 307 | image->surf_type = surf_type; |
Chad Versace | 67a7659 | 2015-06-26 09:17:52 -0700 | [diff] [blame] | 308 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 309 | if (likely(anv_format_is_color(image->format))) { |
Chad Versace | 5a6b2e6 | 2015-08-17 13:50:43 -0700 | [diff] [blame] | 310 | r = anv_image_make_surface(create_info, image->format, |
| 311 | &image->size, &image->alignment, |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 312 | &image->color_surface); |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 313 | if (r != VK_SUCCESS) |
| 314 | goto fail; |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 315 | } else { |
| 316 | if (image->format->depth_format) { |
| 317 | r = anv_image_make_surface(create_info, image->format, |
| 318 | &image->size, &image->alignment, |
| 319 | &image->depth_surface); |
| 320 | if (r != VK_SUCCESS) |
| 321 | goto fail; |
| 322 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 323 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 324 | if (image->format->has_stencil) { |
| 325 | r = anv_image_make_surface(create_info, anv_format_s8_uint, |
| 326 | &image->size, &image->alignment, |
| 327 | &image->stencil_surface); |
| 328 | if (r != VK_SUCCESS) |
| 329 | goto fail; |
| 330 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 331 | } |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 332 | |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 333 | *pImage = anv_image_to_handle(image); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 334 | |
| 335 | return VK_SUCCESS; |
Chad Versace | 5b3a1ce | 2015-06-26 21:27:54 -0700 | [diff] [blame] | 336 | |
| 337 | fail: |
| 338 | if (image) |
| 339 | anv_device_free(device, image); |
| 340 | |
| 341 | return r; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 344 | VkResult |
| 345 | anv_CreateImage(VkDevice device, |
| 346 | const VkImageCreateInfo *pCreateInfo, |
| 347 | VkImage *pImage) |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 348 | { |
Chad Versace | fdcd71f | 2015-06-26 20:06:08 -0700 | [diff] [blame] | 349 | return anv_image_create(device, |
| 350 | &(struct anv_image_create_info) { |
| 351 | .vk_info = pCreateInfo, |
| 352 | }, |
| 353 | pImage); |
Kristian Høgsberg | a29df71 | 2015-05-15 22:04:52 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 356 | void |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 357 | anv_DestroyImage(VkDevice _device, VkImage _image) |
| 358 | { |
| 359 | ANV_FROM_HANDLE(anv_device, device, _device); |
| 360 | |
| 361 | anv_device_free(device, anv_image_from_handle(_image)); |
Jason Ekstrand | 8b342b3 | 2015-07-10 12:30:58 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jason Ekstrand | db24afe | 2015-07-07 18:20:18 -0700 | [diff] [blame] | 364 | VkResult anv_GetImageSubresourceLayout( |
| 365 | VkDevice device, |
| 366 | VkImage image, |
| 367 | const VkImageSubresource* pSubresource, |
| 368 | VkSubresourceLayout* pLayout) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 369 | { |
Jason Ekstrand | ffe9f60 | 2015-05-12 13:44:43 -0700 | [diff] [blame] | 370 | stub_return(VK_UNSUPPORTED); |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 373 | VkResult |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 374 | anv_validate_CreateImageView(VkDevice _device, |
| 375 | const VkImageViewCreateInfo *pCreateInfo, |
| 376 | VkImageView *pView) |
| 377 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 378 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 379 | const VkImageSubresourceRange *subresource; |
| 380 | const struct anv_image_view_info *view_info; |
| 381 | const struct anv_format *view_format_info; |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 382 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 383 | /* Validate structure type before dereferencing it. */ |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 384 | assert(pCreateInfo); |
| 385 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 386 | subresource = &pCreateInfo->subresourceRange; |
| 387 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 388 | /* Validate viewType is in range before using it. */ |
| 389 | assert(pCreateInfo->viewType >= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE); |
| 390 | assert(pCreateInfo->viewType <= VK_IMAGE_VIEW_TYPE_END_RANGE); |
| 391 | view_info = &anv_image_view_info_table[pCreateInfo->viewType]; |
| 392 | |
| 393 | /* Validate format is in range before using it. */ |
| 394 | assert(pCreateInfo->format >= VK_FORMAT_BEGIN_RANGE); |
| 395 | assert(pCreateInfo->format <= VK_FORMAT_END_RANGE); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 396 | view_format_info = anv_format_for_vk_format(pCreateInfo->format); |
| 397 | |
| 398 | /* Validate channel swizzles. */ |
| 399 | assert(pCreateInfo->channels.r >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE); |
| 400 | assert(pCreateInfo->channels.r <= VK_CHANNEL_SWIZZLE_END_RANGE); |
| 401 | assert(pCreateInfo->channels.g >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE); |
| 402 | assert(pCreateInfo->channels.g <= VK_CHANNEL_SWIZZLE_END_RANGE); |
| 403 | assert(pCreateInfo->channels.b >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE); |
| 404 | assert(pCreateInfo->channels.b <= VK_CHANNEL_SWIZZLE_END_RANGE); |
| 405 | assert(pCreateInfo->channels.a >= VK_CHANNEL_SWIZZLE_BEGIN_RANGE); |
| 406 | assert(pCreateInfo->channels.a <= VK_CHANNEL_SWIZZLE_END_RANGE); |
| 407 | |
| 408 | /* Validate subresource. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 409 | assert(subresource->aspectMask != 0); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 410 | assert(subresource->mipLevels > 0); |
| 411 | assert(subresource->arraySize > 0); |
| 412 | assert(subresource->baseMipLevel < image->levels); |
| 413 | assert(subresource->baseMipLevel + subresource->mipLevels <= image->levels); |
Jason Ekstrand | 1e4263b | 2015-10-06 10:27:50 -0700 | [diff] [blame] | 414 | assert(subresource->baseArrayLayer < image->array_size); |
| 415 | assert(subresource->baseArrayLayer + subresource->arraySize <= image->array_size); |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 416 | assert(pView); |
| 417 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 418 | if (view_info->is_cube) { |
Jason Ekstrand | 1e4263b | 2015-10-06 10:27:50 -0700 | [diff] [blame] | 419 | assert(subresource->baseArrayLayer % 6 == 0); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 420 | assert(subresource->arraySize % 6 == 0); |
| 421 | } |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 422 | |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 423 | const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT |
| 424 | | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 425 | |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 426 | /* Validate format. */ |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 427 | if (subresource->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { |
| 428 | assert(subresource->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT); |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 429 | assert(!image->format->depth_format); |
| 430 | assert(!image->format->has_stencil); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 431 | assert(!view_format_info->depth_format); |
| 432 | assert(!view_format_info->has_stencil); |
Chad Versace | ded736f | 2015-08-17 13:10:40 -0700 | [diff] [blame] | 433 | assert(view_format_info->cpp == image->format->cpp); |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 434 | } else if (subresource->aspectMask & ds_flags) { |
| 435 | assert((subresource->aspectMask & ~ds_flags) == 0); |
| 436 | |
| 437 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 438 | assert(image->format->depth_format); |
| 439 | assert(view_format_info->depth_format); |
| 440 | assert(view_format_info->cpp == image->format->cpp); |
| 441 | } |
| 442 | |
| 443 | if (subresource->aspectMask & VK_IMAGE_ASPECT_STENCIL) { |
| 444 | /* FINISHME: Is it legal to have an R8 view of S8? */ |
| 445 | assert(image->format->has_stencil); |
| 446 | assert(view_format_info->has_stencil); |
| 447 | } |
| 448 | } else { |
| 449 | assert(!"bad VkImageSubresourceRange::aspectFlags"); |
Chad Versace | 23075bc | 2015-07-06 17:04:13 -0700 | [diff] [blame] | 450 | } |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 451 | |
| 452 | return anv_CreateImageView(_device, pCreateInfo, pView); |
| 453 | } |
| 454 | |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 455 | void |
| 456 | anv_image_view_init(struct anv_image_view *iview, |
| 457 | struct anv_device *device, |
| 458 | const VkImageViewCreateInfo* pCreateInfo, |
| 459 | struct anv_cmd_buffer *cmd_buffer) |
| 460 | { |
| 461 | switch (device->info.gen) { |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 462 | case 7: |
| 463 | gen7_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
| 464 | break; |
Kristian Høgsberg Kristensen | 988341a | 2015-08-19 21:36:57 -0700 | [diff] [blame] | 465 | case 8: |
| 466 | gen8_image_view_init(iview, device, pCreateInfo, cmd_buffer); |
| 467 | break; |
| 468 | default: |
| 469 | unreachable("unsupported gen\n"); |
| 470 | } |
| 471 | } |
| 472 | |
Chad Versace | 5b04db7 | 2015-07-06 16:24:28 -0700 | [diff] [blame] | 473 | VkResult |
Chad Versace | 127cb3f | 2015-06-26 20:12:42 -0700 | [diff] [blame] | 474 | anv_CreateImageView(VkDevice _device, |
| 475 | const VkImageViewCreateInfo *pCreateInfo, |
| 476 | VkImageView *pView) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 477 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 478 | ANV_FROM_HANDLE(anv_device, device, _device); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 479 | struct anv_image_view *view; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 480 | |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 481 | view = anv_device_alloc(device, sizeof(*view), 8, |
| 482 | VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
| 483 | if (view == NULL) |
| 484 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 485 | |
| 486 | anv_image_view_init(view, device, pCreateInfo, NULL); |
| 487 | |
| 488 | *pView = anv_image_view_to_handle(view); |
| 489 | |
| 490 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 493 | void |
Chad Versace | 8213be7 | 2015-07-15 12:00:27 -0700 | [diff] [blame] | 494 | anv_DestroyImageView(VkDevice _device, VkImageView _iview) |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 495 | { |
| 496 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | 8213be7 | 2015-07-15 12:00:27 -0700 | [diff] [blame] | 497 | ANV_FROM_HANDLE(anv_image_view, iview, _iview); |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 498 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 499 | anv_state_pool_free(&device->surface_state_pool, iview->surface_state); |
Chad Versace | 8213be7 | 2015-07-15 12:00:27 -0700 | [diff] [blame] | 500 | anv_device_free(device, iview); |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 503 | static void |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 504 | anv_depth_stencil_view_init(struct anv_image_view *iview, |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 505 | const VkAttachmentViewCreateInfo *pCreateInfo) |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 506 | { |
Jason Ekstrand | a52e208 | 2015-07-09 20:24:07 -0700 | [diff] [blame] | 507 | ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 508 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 509 | iview->image = image; |
| 510 | iview->format = anv_format_for_vk_format(pCreateInfo->format); |
Chad Versace | c6f19b4 | 2015-08-28 07:52:19 -0700 | [diff] [blame] | 511 | |
| 512 | assert(anv_format_is_depth_or_stencil(image->format)); |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 513 | assert(anv_format_is_depth_or_stencil(iview->format)); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 514 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 515 | |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 516 | struct anv_surface * |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 517 | 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] | 518 | { |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 519 | switch (aspect_mask) { |
| 520 | case VK_IMAGE_ASPECT_COLOR_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 521 | assert(anv_format_is_color(image->format)); |
| 522 | return &image->color_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 523 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 524 | assert(image->format->depth_format); |
| 525 | return &image->depth_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 526 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 527 | assert(image->format->has_stencil); |
| 528 | anv_finishme("stencil image views"); |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 529 | return &image->stencil_surface; |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 530 | case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
Chad Versace | 4ffb454 | 2015-10-05 13:17:39 -0700 | [diff] [blame] | 531 | /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined |
| 532 | * depth stencil formats. Specifically, it states: |
| 533 | * |
| 534 | * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or |
| 535 | * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported. |
Chad Versace | 7a089bd | 2015-10-05 06:48:14 -0700 | [diff] [blame] | 536 | */ |
| 537 | anv_finishme("combined depthstencil aspect"); |
| 538 | assert(image->format->depth_format); |
| 539 | return &image->depth_surface; |
Chad Versace | 941b48e | 2015-08-28 07:08:58 -0700 | [diff] [blame] | 540 | default: |
| 541 | unreachable("image does not have aspect"); |
| 542 | return NULL; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** The attachment may be a color view into a non-color image. */ |
| 547 | struct anv_surface * |
| 548 | anv_image_get_surface_for_color_attachment(struct anv_image *image) |
| 549 | { |
| 550 | if (anv_format_is_color(image->format)) { |
| 551 | return &image->color_surface; |
| 552 | } else if (image->format->depth_format) { |
| 553 | return &image->depth_surface; |
| 554 | } else if (image->format->has_stencil) { |
| 555 | return &image->stencil_surface; |
| 556 | } else { |
| 557 | unreachable("image has bad format"); |
| 558 | return NULL; |
| 559 | } |
| 560 | } |
| 561 | |
Kristian Høgsberg Kristensen | f5275f7 | 2015-08-19 22:19:21 -0700 | [diff] [blame] | 562 | void |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 563 | anv_color_attachment_view_init(struct anv_image_view *iview, |
Kristian Høgsberg Kristensen | f5275f7 | 2015-08-19 22:19:21 -0700 | [diff] [blame] | 564 | struct anv_device *device, |
| 565 | const VkAttachmentViewCreateInfo* pCreateInfo, |
| 566 | struct anv_cmd_buffer *cmd_buffer) |
| 567 | { |
| 568 | switch (device->info.gen) { |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 569 | case 7: |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 570 | gen7_color_attachment_view_init(iview, device, pCreateInfo, cmd_buffer); |
Kristian Høgsberg Kristensen | f1455ff | 2015-08-20 22:59:19 -0700 | [diff] [blame] | 571 | break; |
Kristian Høgsberg Kristensen | f5275f7 | 2015-08-19 22:19:21 -0700 | [diff] [blame] | 572 | case 8: |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 573 | gen8_color_attachment_view_init(iview, device, pCreateInfo, cmd_buffer); |
Kristian Høgsberg Kristensen | f5275f7 | 2015-08-19 22:19:21 -0700 | [diff] [blame] | 574 | break; |
| 575 | default: |
| 576 | unreachable("unsupported gen\n"); |
| 577 | } |
| 578 | } |
| 579 | |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 580 | VkResult |
| 581 | anv_CreateAttachmentView(VkDevice _device, |
| 582 | const VkAttachmentViewCreateInfo *pCreateInfo, |
| 583 | VkAttachmentView *pView) |
| 584 | { |
| 585 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 586 | struct anv_image_view *iview; |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 587 | |
| 588 | assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO); |
| 589 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 590 | iview = anv_device_alloc(device, sizeof(*iview), 8, |
Chad Versace | 9357062 | 2015-10-05 17:27:38 -0700 | [diff] [blame] | 591 | VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 592 | if (iview == NULL) |
Chad Versace | 9357062 | 2015-10-05 17:27:38 -0700 | [diff] [blame] | 593 | return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 594 | |
Chad Versace | 6ff95bb | 2015-08-17 14:03:52 -0700 | [diff] [blame] | 595 | const struct anv_format *format = |
| 596 | anv_format_for_vk_format(pCreateInfo->format); |
| 597 | |
| 598 | if (anv_format_is_depth_or_stencil(format)) { |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 599 | anv_depth_stencil_view_init(iview, pCreateInfo); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 600 | } else { |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 601 | anv_color_attachment_view_init(iview, device, pCreateInfo, NULL); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 602 | } |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 603 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 604 | pView->handle = anv_image_view_to_handle(iview).handle; |
Chad Versace | 9357062 | 2015-10-05 17:27:38 -0700 | [diff] [blame] | 605 | |
Kristian Høgsberg | 37743f9 | 2015-05-22 22:59:12 -0700 | [diff] [blame] | 606 | return VK_SUCCESS; |
Kristian Høgsberg | 769785c | 2015-05-08 22:32:37 -0700 | [diff] [blame] | 607 | } |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 608 | |
Jason Ekstrand | 05a26a6 | 2015-10-05 20:50:51 -0700 | [diff] [blame] | 609 | void |
Chad Versace | 74193a8 | 2015-10-05 15:49:10 -0700 | [diff] [blame] | 610 | anv_DestroyAttachmentView(VkDevice _device, VkAttachmentView _aview) |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 611 | { |
| 612 | ANV_FROM_HANDLE(anv_device, device, _device); |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 613 | VkImageView _iview = { .handle = _aview.handle }; |
| 614 | ANV_FROM_HANDLE(anv_image_view, iview, _iview); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 615 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 616 | /* Depth and stencil render targets have no RENDER_SURFACE_STATE. Instead, |
| 617 | * they use 3DSTATE_DEPTH_BUFFER and 3DSTATE_STENCIL_BUFFER. |
| 618 | */ |
| 619 | if (!anv_format_is_depth_or_stencil(iview->format)) { |
| 620 | anv_state_pool_free(&device->surface_state_pool, iview->surface_state); |
Jason Ekstrand | 8478350 | 2015-07-10 20:18:52 -0700 | [diff] [blame] | 621 | } |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 622 | |
Chad Versace | d4446a7 | 2015-10-06 11:42:43 -0700 | [diff] [blame] | 623 | anv_device_free(device, iview); |
Jason Ekstrand | b94b8df | 2015-07-10 12:25:30 -0700 | [diff] [blame] | 624 | } |