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