2 * Copyright © 2015 Intel Corporation
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:
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
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
30 #include "anv_private.h"
32 static const uint8_t anv_halign
[] = {
38 static const uint8_t anv_valign
[] = {
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
,
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),
63 struct anv_image_view_info
64 anv_image_view_info_for_vk_image_view_type(VkImageViewType type
)
66 return anv_image_view_info_table
[type
];
69 static const struct anv_surf_type_limits
{
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},
82 static const struct anv_tile_info
{
84 * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress.
86 * To simplify calculations, the alignments defined in the table are
87 * sometimes larger than required. For example, Skylake requires that X and
88 * Y tiled buffers be aligned to 4K, but Broadwell permits smaller
89 * alignment. We choose 4K to accomodate both chipsets. The alignment of
90 * a linear buffer depends on its element type and usage. Linear depth
91 * buffers have the largest alignment, 64B, so we choose that for all linear
94 uint32_t surface_alignment
;
95 } anv_tile_info_table
[] = {
96 [ISL_TILING_LINEAR
] = { 64 },
97 [ISL_TILING_X
] = { 4096 },
98 [ISL_TILING_Y
] = { 4096 },
99 [ISL_TILING_Yf
] = { 4096 },
100 [ISL_TILING_Ys
] = { 4096 },
101 [ISL_TILING_W
] = { 4096 },
104 static enum isl_tiling
105 anv_image_choose_tiling(const struct anv_image_create_info
*anv_info
)
107 if (anv_info
->force_tiling
)
108 return anv_info
->tiling
;
110 /* The Sandybridge PRM says that the stencil buffer "is supported
111 * only in Tile W memory".
114 switch (anv_info
->vk_info
->tiling
) {
115 case VK_IMAGE_TILING_LINEAR
:
116 assert(anv_info
->vk_info
->format
!= VK_FORMAT_S8_UINT
);
117 return ISL_TILING_LINEAR
;
118 case VK_IMAGE_TILING_OPTIMAL
:
119 if (unlikely(anv_info
->vk_info
->format
== VK_FORMAT_S8_UINT
)) {
125 assert(!"bad VKImageTiling");
126 return ISL_TILING_LINEAR
;
132 * The \a format argument is required and overrides any format in
133 * struct anv_image_create_info.
136 anv_image_make_surface(const struct anv_device
*dev
,
137 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
)
143 /* See RENDER_SURFACE_STATE.SurfaceQPitch */
144 static const uint16_t min_qpitch UNUSED
= 0x4;
145 static const uint16_t max_qpitch UNUSED
= 0x1ffc;
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 enum isl_tiling tiling
= anv_image_choose_tiling(create_info
);
152 const struct anv_tile_info
*tile_info
=
153 &anv_tile_info_table
[tiling
];
155 const uint32_t bs
= format
->isl_layout
->bs
;
156 const uint32_t bw
= format
->isl_layout
->bw
;
157 const uint32_t bh
= format
->isl_layout
->bh
;
159 struct isl_extent2d tile_extent
;
160 isl_tiling_get_extent(&dev
->isl_dev
, tiling
, bs
, &tile_extent
);
162 const uint32_t i
= MAX(4, bw
); /* FINISHME: Stop hardcoding subimage alignment */
163 const uint32_t j
= MAX(4, bh
); /* FINISHME: Stop hardcoding subimage alignment */
164 assert(i
== 4 || i
== 8 || i
== 16);
165 assert(j
== 4 || j
== 8 || j
== 16);
167 uint16_t qpitch
= min_qpitch
;
168 uint32_t mt_width
= 0;
169 uint32_t mt_height
= 0;
171 switch (create_info
->vk_info
->imageType
) {
172 case VK_IMAGE_TYPE_1D
:
173 /* From the Broadwell PRM >> Memory Views >> Common Surface Formats >>
174 * Surface Layout >> 1D Surfaces:
176 * One-dimensional surfaces are identical to 2D surfaces with height of one.
180 case VK_IMAGE_TYPE_2D
: {
181 const uint32_t w0
= align_u32(extent
->width
, i
);
182 const uint32_t h0
= align_u32(extent
->height
, j
);
184 if (levels
== 1 && array_size
== 1) {
189 uint32_t w1
= align_u32(anv_minify(extent
->width
, 1), i
);
190 uint32_t h1
= align_u32(anv_minify(extent
->height
, 1), j
);
191 uint32_t w2
= align_u32(anv_minify(extent
->width
, 2), i
);
193 /* The QPitch equation is found in the Broadwell PRM >> Volume 5: Memory
194 * Views >> Common Surface Formats >> Surface Layout >> 2D Surfaces >>
195 * Surface Arrays >> For All Surface Other Than Separate Stencil Buffer:
197 assert(bh
==1 || bh
== 4);
198 qpitch
= (h0
+ h1
+ 11 * j
) / bh
;
199 mt_width
= MAX(w0
, w1
+ w2
);
200 mt_height
= array_size
* qpitch
;
204 case VK_IMAGE_TYPE_3D
:
205 /* The layout of 3D surfaces is described by the Broadwell PRM >>
206 * Volume 5: Memory Views >> Common Surface Formats >> Surface Layout >>
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
);
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
);
217 mt_width
= MAX(mt_width
, w_l
* max_layers_horiz
);
218 mt_height
+= h_l
* max_layers_vert
;
222 unreachable(!"bad VkImageType");
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
);
231 /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch:
233 * This field must be set an integer multiple of the Surface Vertical
236 assert(anv_is_aligned(qpitch
, j
));
238 uint32_t stride
= align_u32(mt_width
* bs
/ bw
, tile_extent
.width
);
239 if (create_info
->stride
> 0)
240 stride
= create_info
->stride
;
242 /* The padding requirement is found in the Broadwell PRM >> Volume 5: Memory
243 * Views >> Common Surface Formats >> Surface Padding Requirements >>
244 * Sampling Engine Surfaces >> Buffer Padding Requirements:
246 const uint32_t mem_rows
= align_u32(mt_height
/ bh
, 2 * bh
);
247 const uint32_t size
= stride
* align_u32(mem_rows
, tile_extent
.height
);
248 const uint32_t offset
= align_u32(*inout_image_size
,
249 tile_info
->surface_alignment
);
251 *inout_image_size
= offset
+ size
;
252 *inout_image_alignment
= MAX(*inout_image_alignment
,
253 tile_info
->surface_alignment
);
255 *out_surface
= (struct anv_surface
) {
267 static VkImageUsageFlags
268 anv_image_get_full_usage(const VkImageCreateInfo
*info
)
270 VkImageUsageFlags usage
= info
->usage
;
272 if (usage
& VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT
) {
273 /* Meta will transfer from the image by binding it as a texture. */
274 usage
|= VK_IMAGE_USAGE_SAMPLED_BIT
;
277 if (usage
& VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT
) {
278 /* Meta will transfer to the image by binding it as a color attachment,
279 * even if the image format is not a color format.
281 usage
|= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
288 anv_image_create(VkDevice _device
,
289 const struct anv_image_create_info
*create_info
,
292 ANV_FROM_HANDLE(anv_device
, device
, _device
);
293 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
294 const VkExtent3D
*restrict extent
= &pCreateInfo
->extent
;
295 struct anv_image
*image
= NULL
;
298 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
300 anv_assert(pCreateInfo
->mipLevels
> 0);
301 anv_assert(pCreateInfo
->arraySize
> 0);
302 anv_assert(pCreateInfo
->samples
== 1);
303 anv_assert(pCreateInfo
->extent
.width
> 0);
304 anv_assert(pCreateInfo
->extent
.height
> 0);
305 anv_assert(pCreateInfo
->extent
.depth
> 0);
307 /* TODO(chadv): How should we validate inputs? */
308 const uint8_t surf_type
=
309 anv_surf_type_from_image_type
[pCreateInfo
->imageType
];
311 const struct anv_surf_type_limits
*limits
=
312 &anv_surf_type_limits
[surf_type
];
314 /* Errors should be caught by VkImageFormatProperties. */
315 assert(extent
->width
<= limits
->width
);
316 assert(extent
->height
<= limits
->height
);
317 assert(extent
->depth
<= limits
->depth
);
319 image
= anv_device_alloc(device
, sizeof(*image
), 8,
320 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
322 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
324 memset(image
, 0, sizeof(*image
));
325 image
->type
= pCreateInfo
->imageType
;
326 image
->extent
= pCreateInfo
->extent
;
327 image
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
328 image
->levels
= pCreateInfo
->mipLevels
;
329 image
->array_size
= pCreateInfo
->arraySize
;
330 image
->usage
= anv_image_get_full_usage(pCreateInfo
);
331 image
->surface_type
= surf_type
;
333 if (image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
334 VK_IMAGE_USAGE_STORAGE_BIT
)) {
335 image
->needs_nonrt_surface_state
= true;
338 if (image
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
339 image
->needs_color_rt_surface_state
= true;
342 if (likely(anv_format_is_color(image
->format
))) {
343 r
= anv_image_make_surface(device
, create_info
, image
->format
,
344 &image
->size
, &image
->alignment
,
345 &image
->color_surface
);
349 if (image
->format
->depth_format
) {
350 r
= anv_image_make_surface(device
, create_info
, image
->format
,
351 &image
->size
, &image
->alignment
,
352 &image
->depth_surface
);
357 if (image
->format
->has_stencil
) {
358 r
= anv_image_make_surface(device
, create_info
, anv_format_s8_uint
,
359 &image
->size
, &image
->alignment
,
360 &image
->stencil_surface
);
366 *pImage
= anv_image_to_handle(image
);
372 anv_device_free(device
, image
);
378 anv_CreateImage(VkDevice device
,
379 const VkImageCreateInfo
*pCreateInfo
,
382 return anv_image_create(device
,
383 &(struct anv_image_create_info
) {
384 .vk_info
= pCreateInfo
,
390 anv_DestroyImage(VkDevice _device
, VkImage _image
)
392 ANV_FROM_HANDLE(anv_device
, device
, _device
);
394 anv_device_free(device
, anv_image_from_handle(_image
));
398 anv_surface_get_subresource_layout(struct anv_image
*image
,
399 struct anv_surface
*surface
,
400 const VkImageSubresource
*subresource
,
401 VkSubresourceLayout
*layout
)
403 /* If we are on a non-zero mip level or array slice, we need to
404 * calculate a real offset.
406 anv_assert(subresource
->mipLevel
== 0);
407 anv_assert(subresource
->arrayLayer
== 0);
409 layout
->offset
= surface
->offset
;
410 layout
->rowPitch
= surface
->stride
;
411 layout
->depthPitch
= surface
->qpitch
;
413 /* FINISHME: We really shouldn't be doing this calculation here */
414 if (image
->array_size
> 1)
415 layout
->size
= surface
->qpitch
* image
->array_size
;
417 layout
->size
= surface
->stride
* image
->extent
.height
;
420 VkResult
anv_GetImageSubresourceLayout(
423 const VkImageSubresource
* pSubresource
,
424 VkSubresourceLayout
* pLayout
)
426 ANV_FROM_HANDLE(anv_image
, image
, _image
);
428 switch (pSubresource
->aspect
) {
429 case VK_IMAGE_ASPECT_COLOR
:
430 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
431 pSubresource
, pLayout
);
433 case VK_IMAGE_ASPECT_DEPTH
:
434 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
435 pSubresource
, pLayout
);
437 case VK_IMAGE_ASPECT_STENCIL
:
438 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
439 pSubresource
, pLayout
);
442 return vk_error(VK_UNSUPPORTED
);
449 anv_validate_CreateImageView(VkDevice _device
,
450 const VkImageViewCreateInfo
*pCreateInfo
,
453 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
454 const VkImageSubresourceRange
*subresource
;
455 const struct anv_image_view_info
*view_info
;
456 const struct anv_format
*view_format_info
;
458 /* Validate structure type before dereferencing it. */
460 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
461 subresource
= &pCreateInfo
->subresourceRange
;
463 /* Validate viewType is in range before using it. */
464 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
465 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
466 view_info
= &anv_image_view_info_table
[pCreateInfo
->viewType
];
468 /* Validate format is in range before using it. */
469 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
470 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
471 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
473 /* Validate channel swizzles. */
474 assert(pCreateInfo
->channels
.r
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
475 assert(pCreateInfo
->channels
.r
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
476 assert(pCreateInfo
->channels
.g
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
477 assert(pCreateInfo
->channels
.g
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
478 assert(pCreateInfo
->channels
.b
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
479 assert(pCreateInfo
->channels
.b
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
480 assert(pCreateInfo
->channels
.a
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
481 assert(pCreateInfo
->channels
.a
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
483 /* Validate subresource. */
484 assert(subresource
->aspectMask
!= 0);
485 assert(subresource
->mipLevels
> 0);
486 assert(subresource
->arraySize
> 0);
487 assert(subresource
->baseMipLevel
< image
->levels
);
488 assert(subresource
->baseMipLevel
+ subresource
->mipLevels
<= image
->levels
);
489 assert(subresource
->baseArrayLayer
< image
->array_size
);
490 assert(subresource
->baseArrayLayer
+ subresource
->arraySize
<= image
->array_size
);
493 if (view_info
->is_cube
) {
494 assert(subresource
->baseArrayLayer
% 6 == 0);
495 assert(subresource
->arraySize
% 6 == 0);
498 const VkImageAspectFlags ds_flags
= VK_IMAGE_ASPECT_DEPTH_BIT
499 | VK_IMAGE_ASPECT_STENCIL_BIT
;
501 /* Validate format. */
502 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
503 assert(subresource
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
504 assert(!image
->format
->depth_format
);
505 assert(!image
->format
->has_stencil
);
506 assert(!view_format_info
->depth_format
);
507 assert(!view_format_info
->has_stencil
);
508 assert(view_format_info
->isl_layout
->bs
==
509 image
->format
->isl_layout
->bs
);
510 } else if (subresource
->aspectMask
& ds_flags
) {
511 assert((subresource
->aspectMask
& ~ds_flags
) == 0);
513 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
514 assert(image
->format
->depth_format
);
515 assert(view_format_info
->depth_format
);
516 assert(view_format_info
->isl_layout
->bs
==
517 image
->format
->isl_layout
->bs
);
520 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL
) {
521 /* FINISHME: Is it legal to have an R8 view of S8? */
522 assert(image
->format
->has_stencil
);
523 assert(view_format_info
->has_stencil
);
526 assert(!"bad VkImageSubresourceRange::aspectFlags");
529 return anv_CreateImageView(_device
, pCreateInfo
, pView
);
533 anv_image_view_init(struct anv_image_view
*iview
,
534 struct anv_device
*device
,
535 const VkImageViewCreateInfo
* pCreateInfo
,
536 struct anv_cmd_buffer
*cmd_buffer
)
538 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
539 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
541 assert(range
->arraySize
> 0);
542 assert(range
->baseMipLevel
< image
->levels
);
543 assert(image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
544 VK_IMAGE_USAGE_STORAGE_BIT
|
545 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
546 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
));
548 switch (image
->type
) {
550 unreachable("bad VkImageType");
551 case VK_IMAGE_TYPE_1D
:
552 case VK_IMAGE_TYPE_2D
:
553 assert(range
->baseArrayLayer
+ range
->arraySize
- 1 <= image
->array_size
);
555 case VK_IMAGE_TYPE_3D
:
556 assert(range
->baseArrayLayer
+ range
->arraySize
- 1
557 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
561 switch (device
->info
.gen
) {
563 gen7_image_view_init(iview
, device
, pCreateInfo
, cmd_buffer
);
566 gen8_image_view_init(iview
, device
, pCreateInfo
, cmd_buffer
);
569 unreachable("unsupported gen\n");
574 anv_CreateImageView(VkDevice _device
,
575 const VkImageViewCreateInfo
*pCreateInfo
,
578 ANV_FROM_HANDLE(anv_device
, device
, _device
);
579 struct anv_image_view
*view
;
581 view
= anv_device_alloc(device
, sizeof(*view
), 8,
582 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
584 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
586 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
588 *pView
= anv_image_view_to_handle(view
);
594 anv_image_view_destroy(struct anv_device
*device
,
595 struct anv_image_view
*iview
)
597 if (iview
->image
->needs_color_rt_surface_state
) {
598 anv_state_pool_free(&device
->surface_state_pool
,
599 iview
->color_rt_surface_state
);
602 if (iview
->image
->needs_nonrt_surface_state
) {
603 anv_state_pool_free(&device
->surface_state_pool
,
604 iview
->nonrt_surface_state
);
607 anv_device_free(device
, iview
);
611 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
)
613 ANV_FROM_HANDLE(anv_device
, device
, _device
);
614 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
616 anv_image_view_destroy(device
, iview
);
620 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
, VkImageAspectFlags aspect_mask
)
622 switch (aspect_mask
) {
623 case VK_IMAGE_ASPECT_COLOR_BIT
:
624 /* Dragons will eat you.
626 * Meta attaches all destination surfaces as color render targets. Guess
627 * what surface the Meta Dragons really want.
629 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
630 anv_finishme("combined depth stencil formats");
631 return &image
->depth_surface
;
632 } else if (image
->format
->depth_format
) {
633 return &image
->depth_surface
;
634 } else if (image
->format
->has_stencil
) {
635 return &image
->stencil_surface
;
637 return &image
->color_surface
;
640 case VK_IMAGE_ASPECT_DEPTH_BIT
:
641 assert(image
->format
->depth_format
);
642 return &image
->depth_surface
;
643 case VK_IMAGE_ASPECT_STENCIL_BIT
:
644 assert(image
->format
->has_stencil
);
645 return &image
->stencil_surface
;
646 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
647 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
648 /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined
649 * depth stencil formats. Specifically, it states:
651 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
652 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
654 anv_finishme("combined depthstencil aspect");
655 return &image
->depth_surface
;
656 } else if (image
->format
->depth_format
) {
657 return &image
->depth_surface
;
658 } else if (image
->format
->has_stencil
) {
659 return &image
->stencil_surface
;
663 unreachable("image does not have aspect");
669 VkImageAspectFlags aspect_mask
= 0;
670 if (format
->depth_format
)
671 aspect_mask
|= VK_IMAGE_ASPECT_DEPTH_BIT
;
672 if (format
->has_stencil
)
673 aspect_mask
|= VK_IMAGE_ASPECT_STENCIL_BIT
;
675 aspect_mask
|= VK_IMAGE_ASPECT_COLOR_BIT
;
677 anv_image_view_init(iview
, device
,
678 &(VkImageViewCreateInfo
) {
679 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
680 .image
= info
->image
,
681 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
682 .format
= info
->format
,
684 .r
= VK_CHANNEL_SWIZZLE_R
,
685 .g
= VK_CHANNEL_SWIZZLE_G
,
686 .b
= VK_CHANNEL_SWIZZLE_B
,
687 .a
= VK_CHANNEL_SWIZZLE_A
,
689 .subresourceRange
= {
690 .aspectMask
= aspect_mask
,
691 .baseMipLevel
= info
->mipLevel
,
693 .baseArrayLayer
= info
->baseArraySlice
,
694 .arraySize
= info
->arraySize
,