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
{
87 * Alignment for RENDER_SURFACE_STATE.SurfaceBaseAddress.
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
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 },
106 anv_image_choose_tile_mode(const struct anv_image_create_info
*anv_info
)
108 if (anv_info
->force_tile_mode
)
109 return anv_info
->tile_mode
;
111 /* The Sandybridge PRM says that the stencil buffer "is supported
112 * only in Tile W memory".
115 switch (anv_info
->vk_info
->tiling
) {
116 case VK_IMAGE_TILING_LINEAR
:
117 assert(anv_info
->vk_info
->format
!= VK_FORMAT_S8_UINT
);
119 case VK_IMAGE_TILING_OPTIMAL
:
120 if (unlikely(anv_info
->vk_info
->format
== VK_FORMAT_S8_UINT
)) {
126 assert(!"bad VKImageTiling");
133 * The \a format argument is required and overrides any format in
134 * struct anv_image_create_info.
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
)
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 uint8_t tile_mode
= anv_image_choose_tile_mode(create_info
);
152 const struct anv_tile_info
*tile_info
=
153 &anv_tile_info_table
[tile_mode
];
155 const uint32_t i
= 4; /* FINISHME: Stop hardcoding subimage alignment */
156 const uint32_t j
= 4; /* FINISHME: Stop hardcoding subimage alignment */
158 uint16_t qpitch
= min_qpitch
;
159 uint32_t mt_width
= 0;
160 uint32_t mt_height
= 0;
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:
167 * One-dimensional surfaces are identical to 2D surfaces with height of one.
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
);
175 if (levels
== 1 && array_size
== 1) {
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
);
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:
188 qpitch
= h0
+ h1
+ 11 * j
;
189 mt_width
= MAX(w0
, w1
+ w2
);
190 mt_height
= array_size
* qpitch
;
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 >>
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
);
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
);
207 mt_width
= MAX(mt_width
, w_l
* max_layers_horiz
);
208 mt_height
+= h_l
* max_layers_vert
;
212 unreachable(!"bad VkImageType");
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
);
221 /* From the Broadwell PRM, RENDER_SURFACE_STATE.SurfaceQpitch:
223 * This field must be set an integer multiple of the Surface Vertical
226 assert(anv_is_aligned(qpitch
, j
));
228 uint32_t stride
= align_u32(mt_width
* format
->bs
/ format
->bw
,
230 if (create_info
->stride
> 0)
231 stride
= create_info
->stride
;
233 const uint32_t size
= stride
* align_u32(mt_height
/ format
->bh
,
235 const uint32_t offset
= align_u32(*inout_image_size
,
236 tile_info
->surface_alignment
);
238 *inout_image_size
= offset
+ size
;
239 *inout_image_alignment
= MAX(*inout_image_alignment
,
240 tile_info
->surface_alignment
);
242 *out_surface
= (struct anv_surface
) {
245 .tile_mode
= tile_mode
,
254 static VkImageUsageFlags
255 anv_image_get_full_usage(const VkImageCreateInfo
*info
)
257 VkImageUsageFlags usage
= info
->usage
;
259 if (usage
& VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT
) {
260 /* Meta will transfer from the image by binding it as a texture. */
261 usage
|= VK_IMAGE_USAGE_SAMPLED_BIT
;
264 if (usage
& VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT
) {
265 /* Meta will transfer to the image by binding it as a color attachment,
266 * even if the image format is not a color format.
268 usage
|= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
275 anv_image_create(VkDevice _device
,
276 const struct anv_image_create_info
*create_info
,
279 ANV_FROM_HANDLE(anv_device
, device
, _device
);
280 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
281 const VkExtent3D
*restrict extent
= &pCreateInfo
->extent
;
282 struct anv_image
*image
= NULL
;
285 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
287 anv_assert(pCreateInfo
->mipLevels
> 0);
288 anv_assert(pCreateInfo
->arraySize
> 0);
289 anv_assert(pCreateInfo
->samples
== 1);
290 anv_assert(pCreateInfo
->extent
.width
> 0);
291 anv_assert(pCreateInfo
->extent
.height
> 0);
292 anv_assert(pCreateInfo
->extent
.depth
> 0);
294 /* TODO(chadv): How should we validate inputs? */
295 const uint8_t surf_type
=
296 anv_surf_type_from_image_type
[pCreateInfo
->imageType
];
298 const struct anv_surf_type_limits
*limits
=
299 &anv_surf_type_limits
[surf_type
];
301 /* Errors should be caught by VkImageFormatProperties. */
302 assert(extent
->width
<= limits
->width
);
303 assert(extent
->height
<= limits
->height
);
304 assert(extent
->depth
<= limits
->depth
);
306 image
= anv_device_alloc(device
, sizeof(*image
), 8,
307 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
309 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
311 memset(image
, 0, sizeof(*image
));
312 image
->type
= pCreateInfo
->imageType
;
313 image
->extent
= pCreateInfo
->extent
;
314 image
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
315 image
->levels
= pCreateInfo
->mipLevels
;
316 image
->array_size
= pCreateInfo
->arraySize
;
317 image
->usage
= anv_image_get_full_usage(pCreateInfo
);
318 image
->surface_type
= surf_type
;
320 if (image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
321 VK_IMAGE_USAGE_STORAGE_BIT
)) {
322 image
->needs_nonrt_surface_state
= true;
325 if (image
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
326 image
->needs_color_rt_surface_state
= true;
329 if (likely(anv_format_is_color(image
->format
))) {
330 r
= anv_image_make_surface(create_info
, image
->format
,
331 &image
->size
, &image
->alignment
,
332 &image
->color_surface
);
336 if (image
->format
->depth_format
) {
337 r
= anv_image_make_surface(create_info
, image
->format
,
338 &image
->size
, &image
->alignment
,
339 &image
->depth_surface
);
344 if (image
->format
->has_stencil
) {
345 r
= anv_image_make_surface(create_info
, anv_format_s8_uint
,
346 &image
->size
, &image
->alignment
,
347 &image
->stencil_surface
);
353 *pImage
= anv_image_to_handle(image
);
359 anv_device_free(device
, image
);
365 anv_CreateImage(VkDevice device
,
366 const VkImageCreateInfo
*pCreateInfo
,
369 return anv_image_create(device
,
370 &(struct anv_image_create_info
) {
371 .vk_info
= pCreateInfo
,
377 anv_DestroyImage(VkDevice _device
, VkImage _image
)
379 ANV_FROM_HANDLE(anv_device
, device
, _device
);
381 anv_device_free(device
, anv_image_from_handle(_image
));
385 anv_surface_get_subresource_layout(struct anv_image
*image
,
386 struct anv_surface
*surface
,
387 const VkImageSubresource
*subresource
,
388 VkSubresourceLayout
*layout
)
390 /* If we are on a non-zero mip level or array slice, we need to
391 * calculate a real offset.
393 anv_assert(subresource
->mipLevel
== 0);
394 anv_assert(subresource
->arrayLayer
== 0);
396 layout
->offset
= surface
->offset
;
397 layout
->rowPitch
= surface
->stride
;
398 layout
->depthPitch
= surface
->qpitch
;
400 /* FINISHME: We really shouldn't be doing this calculation here */
401 if (image
->array_size
> 1)
402 layout
->size
= surface
->qpitch
* image
->array_size
;
404 layout
->size
= surface
->stride
* image
->extent
.height
;
407 VkResult
anv_GetImageSubresourceLayout(
410 const VkImageSubresource
* pSubresource
,
411 VkSubresourceLayout
* pLayout
)
413 ANV_FROM_HANDLE(anv_image
, image
, _image
);
415 switch (pSubresource
->aspect
) {
416 case VK_IMAGE_ASPECT_COLOR
:
417 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
418 pSubresource
, pLayout
);
420 case VK_IMAGE_ASPECT_DEPTH
:
421 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
422 pSubresource
, pLayout
);
424 case VK_IMAGE_ASPECT_STENCIL
:
425 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
426 pSubresource
, pLayout
);
429 return vk_error(VK_UNSUPPORTED
);
436 anv_validate_CreateImageView(VkDevice _device
,
437 const VkImageViewCreateInfo
*pCreateInfo
,
440 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
441 const VkImageSubresourceRange
*subresource
;
442 const struct anv_image_view_info
*view_info
;
443 const struct anv_format
*view_format_info
;
445 /* Validate structure type before dereferencing it. */
447 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
448 subresource
= &pCreateInfo
->subresourceRange
;
450 /* Validate viewType is in range before using it. */
451 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
452 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
453 view_info
= &anv_image_view_info_table
[pCreateInfo
->viewType
];
455 /* Validate format is in range before using it. */
456 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
457 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
458 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
460 /* Validate channel swizzles. */
461 assert(pCreateInfo
->channels
.r
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
462 assert(pCreateInfo
->channels
.r
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
463 assert(pCreateInfo
->channels
.g
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
464 assert(pCreateInfo
->channels
.g
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
465 assert(pCreateInfo
->channels
.b
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
466 assert(pCreateInfo
->channels
.b
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
467 assert(pCreateInfo
->channels
.a
>= VK_CHANNEL_SWIZZLE_BEGIN_RANGE
);
468 assert(pCreateInfo
->channels
.a
<= VK_CHANNEL_SWIZZLE_END_RANGE
);
470 /* Validate subresource. */
471 assert(subresource
->aspectMask
!= 0);
472 assert(subresource
->mipLevels
> 0);
473 assert(subresource
->arraySize
> 0);
474 assert(subresource
->baseMipLevel
< image
->levels
);
475 assert(subresource
->baseMipLevel
+ subresource
->mipLevels
<= image
->levels
);
476 assert(subresource
->baseArrayLayer
< image
->array_size
);
477 assert(subresource
->baseArrayLayer
+ subresource
->arraySize
<= image
->array_size
);
480 if (view_info
->is_cube
) {
481 assert(subresource
->baseArrayLayer
% 6 == 0);
482 assert(subresource
->arraySize
% 6 == 0);
485 const VkImageAspectFlags ds_flags
= VK_IMAGE_ASPECT_DEPTH_BIT
486 | VK_IMAGE_ASPECT_STENCIL_BIT
;
488 /* Validate format. */
489 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
490 assert(subresource
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
491 assert(!image
->format
->depth_format
);
492 assert(!image
->format
->has_stencil
);
493 assert(!view_format_info
->depth_format
);
494 assert(!view_format_info
->has_stencil
);
495 assert(view_format_info
->bs
== image
->format
->bs
);
496 } else if (subresource
->aspectMask
& ds_flags
) {
497 assert((subresource
->aspectMask
& ~ds_flags
) == 0);
499 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
500 assert(image
->format
->depth_format
);
501 assert(view_format_info
->depth_format
);
502 assert(view_format_info
->bs
== image
->format
->bs
);
505 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL
) {
506 /* FINISHME: Is it legal to have an R8 view of S8? */
507 assert(image
->format
->has_stencil
);
508 assert(view_format_info
->has_stencil
);
511 assert(!"bad VkImageSubresourceRange::aspectFlags");
514 return anv_CreateImageView(_device
, pCreateInfo
, pView
);
518 anv_image_view_init(struct anv_image_view
*iview
,
519 struct anv_device
*device
,
520 const VkImageViewCreateInfo
* pCreateInfo
,
521 struct anv_cmd_buffer
*cmd_buffer
)
523 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
524 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
526 assert(range
->arraySize
> 0);
527 assert(range
->baseMipLevel
< image
->levels
);
528 assert(image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
529 VK_IMAGE_USAGE_STORAGE_BIT
|
530 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
531 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
));
533 switch (image
->type
) {
535 unreachable("bad VkImageType");
536 case VK_IMAGE_TYPE_1D
:
537 case VK_IMAGE_TYPE_2D
:
538 assert(range
->baseArrayLayer
+ range
->arraySize
- 1 <= image
->array_size
);
540 case VK_IMAGE_TYPE_3D
:
541 assert(range
->baseArrayLayer
+ range
->arraySize
- 1
542 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
546 switch (device
->info
.gen
) {
548 gen7_image_view_init(iview
, device
, pCreateInfo
, cmd_buffer
);
551 gen8_image_view_init(iview
, device
, pCreateInfo
, cmd_buffer
);
554 unreachable("unsupported gen\n");
559 anv_CreateImageView(VkDevice _device
,
560 const VkImageViewCreateInfo
*pCreateInfo
,
563 ANV_FROM_HANDLE(anv_device
, device
, _device
);
564 struct anv_image_view
*view
;
566 view
= anv_device_alloc(device
, sizeof(*view
), 8,
567 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
569 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
571 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
573 *pView
= anv_image_view_to_handle(view
);
579 anv_image_view_destroy(struct anv_device
*device
,
580 struct anv_image_view
*iview
)
582 if (iview
->image
->needs_color_rt_surface_state
) {
583 anv_state_pool_free(&device
->surface_state_pool
,
584 iview
->color_rt_surface_state
);
587 if (iview
->image
->needs_nonrt_surface_state
) {
588 anv_state_pool_free(&device
->surface_state_pool
,
589 iview
->nonrt_surface_state
);
592 anv_device_free(device
, iview
);
596 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
)
598 ANV_FROM_HANDLE(anv_device
, device
, _device
);
599 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
601 anv_image_view_destroy(device
, iview
);
605 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
, VkImageAspectFlags aspect_mask
)
607 switch (aspect_mask
) {
608 case VK_IMAGE_ASPECT_COLOR_BIT
:
609 /* Dragons will eat you.
611 * Meta attaches all destination surfaces as color render targets. Guess
612 * what surface the Meta Dragons really want.
614 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
615 anv_finishme("combined depth stencil formats");
616 return &image
->depth_surface
;
617 } else if (image
->format
->depth_format
) {
618 return &image
->depth_surface
;
619 } else if (image
->format
->has_stencil
) {
620 return &image
->stencil_surface
;
622 return &image
->color_surface
;
625 case VK_IMAGE_ASPECT_DEPTH_BIT
:
626 assert(image
->format
->depth_format
);
627 return &image
->depth_surface
;
628 case VK_IMAGE_ASPECT_STENCIL_BIT
:
629 assert(image
->format
->has_stencil
);
630 return &image
->stencil_surface
;
631 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
632 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
633 /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined
634 * depth stencil formats. Specifically, it states:
636 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
637 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
639 anv_finishme("combined depthstencil aspect");
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
;
648 unreachable("image does not have aspect");
654 VkImageAspectFlags aspect_mask
= 0;
655 if (format
->depth_format
)
656 aspect_mask
|= VK_IMAGE_ASPECT_DEPTH_BIT
;
657 if (format
->has_stencil
)
658 aspect_mask
|= VK_IMAGE_ASPECT_STENCIL_BIT
;
660 aspect_mask
|= VK_IMAGE_ASPECT_COLOR_BIT
;
662 anv_image_view_init(iview
, device
,
663 &(VkImageViewCreateInfo
) {
664 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
665 .image
= info
->image
,
666 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
667 .format
= info
->format
,
669 .r
= VK_CHANNEL_SWIZZLE_R
,
670 .g
= VK_CHANNEL_SWIZZLE_G
,
671 .b
= VK_CHANNEL_SWIZZLE_B
,
672 .a
= VK_CHANNEL_SWIZZLE_A
,
674 .subresourceRange
= {
675 .aspectMask
= aspect_mask
,
676 .baseMipLevel
= info
->mipLevel
,
678 .baseArrayLayer
= info
->baseArraySlice
,
679 .arraySize
= info
->arraySize
,