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"
31 #include "util/debug.h"
33 #include "vk_format_info.h"
36 * Exactly one bit must be set in \a aspect.
38 static isl_surf_usage_flags_t
39 choose_isl_surf_usage(VkImageUsageFlags vk_usage
,
40 VkImageAspectFlags aspect
)
42 isl_surf_usage_flags_t isl_usage
= 0;
44 /* FINISHME: Support aux surfaces */
45 isl_usage
|= ISL_SURF_USAGE_DISABLE_AUX_BIT
;
47 if (vk_usage
& VK_IMAGE_USAGE_SAMPLED_BIT
)
48 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
50 if (vk_usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)
51 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
53 if (vk_usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
)
54 isl_usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
56 if (vk_usage
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)
57 isl_usage
|= ISL_SURF_USAGE_CUBE_BIT
;
59 /* Even if we're only using it for transfer operations, clears to depth and
60 * stencil images happen as depth and stencil so they need the right ISL
61 * usage bits or else things will fall apart.
64 case VK_IMAGE_ASPECT_DEPTH_BIT
:
65 isl_usage
&= ~ISL_SURF_USAGE_DISABLE_AUX_BIT
;
66 isl_usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
68 case VK_IMAGE_ASPECT_STENCIL_BIT
:
69 isl_usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
71 case VK_IMAGE_ASPECT_COLOR_BIT
:
74 unreachable("bad VkImageAspect");
77 if (vk_usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
78 /* blorp implements transfers by sampling from the source image. */
79 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
82 if (vk_usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
83 /* blorp implements transfers by rendering into the destination image. */
84 isl_usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
91 * Exactly one bit must be set in \a aspect.
93 static struct anv_surface
*
94 get_surface(struct anv_image
*image
, VkImageAspectFlags aspect
)
98 unreachable("bad VkImageAspect");
99 case VK_IMAGE_ASPECT_COLOR_BIT
:
100 return &image
->color_surface
;
101 case VK_IMAGE_ASPECT_DEPTH_BIT
:
102 return &image
->depth_surface
;
103 case VK_IMAGE_ASPECT_STENCIL_BIT
:
104 return &image
->stencil_surface
;
109 add_surface(struct anv_image
*image
, struct anv_surface
*surf
)
111 assert(surf
->isl
.size
> 0); /* isl surface must be initialized */
113 surf
->offset
= align_u32(image
->size
, surf
->isl
.alignment
);
114 image
->size
= surf
->offset
+ surf
->isl
.size
;
115 image
->alignment
= MAX2(image
->alignment
, surf
->isl
.alignment
);
119 * Initialize the anv_image::*_surface selected by \a aspect. Then update the
120 * image's memory requirements (that is, the image's size and alignment).
122 * Exactly one bit must be set in \a aspect.
125 make_surface(const struct anv_device
*dev
,
126 struct anv_image
*image
,
127 const struct anv_image_create_info
*anv_info
,
128 VkImageAspectFlags aspect
)
130 const VkImageCreateInfo
*vk_info
= anv_info
->vk_info
;
133 static const enum isl_surf_dim vk_to_isl_surf_dim
[] = {
134 [VK_IMAGE_TYPE_1D
] = ISL_SURF_DIM_1D
,
135 [VK_IMAGE_TYPE_2D
] = ISL_SURF_DIM_2D
,
136 [VK_IMAGE_TYPE_3D
] = ISL_SURF_DIM_3D
,
139 /* Translate the Vulkan tiling to an equivalent ISL tiling, then filter the
140 * result with an optionally provided ISL tiling argument.
142 isl_tiling_flags_t tiling_flags
=
143 (vk_info
->tiling
== VK_IMAGE_TILING_LINEAR
) ?
144 ISL_TILING_LINEAR_BIT
: ISL_TILING_ANY_MASK
;
146 if (anv_info
->isl_tiling_flags
)
147 tiling_flags
&= anv_info
->isl_tiling_flags
;
149 assert(tiling_flags
);
151 struct anv_surface
*anv_surf
= get_surface(image
, aspect
);
153 image
->extent
= anv_sanitize_image_extent(vk_info
->imageType
,
156 enum isl_format format
= anv_get_isl_format(&dev
->info
, vk_info
->format
,
157 aspect
, vk_info
->tiling
);
158 assert(format
!= ISL_FORMAT_UNSUPPORTED
);
160 ok
= isl_surf_init(&dev
->isl_dev
, &anv_surf
->isl
,
161 .dim
= vk_to_isl_surf_dim
[vk_info
->imageType
],
163 .width
= image
->extent
.width
,
164 .height
= image
->extent
.height
,
165 .depth
= image
->extent
.depth
,
166 .levels
= vk_info
->mipLevels
,
167 .array_len
= vk_info
->arrayLayers
,
168 .samples
= vk_info
->samples
,
170 .min_pitch
= anv_info
->stride
,
171 .usage
= choose_isl_surf_usage(image
->usage
, aspect
),
172 .tiling_flags
= tiling_flags
);
174 /* isl_surf_init() will fail only if provided invalid input. Invalid input
175 * is illegal in Vulkan.
179 add_surface(image
, anv_surf
);
181 /* Add a HiZ surface to a depth buffer that will be used for rendering.
183 if (aspect
== VK_IMAGE_ASPECT_DEPTH_BIT
&&
184 (image
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
186 /* Allow the user to control HiZ enabling. Disable by default on gen7
187 * because resolves are not currently implemented pre-BDW.
189 if (!env_var_as_boolean("INTEL_VK_HIZ", dev
->info
.gen
>= 8)) {
190 anv_finishme("Implement gen7 HiZ");
191 } else if (vk_info
->mipLevels
> 1) {
192 anv_finishme("Test multi-LOD HiZ");
193 } else if (dev
->info
.gen
== 8 && vk_info
->samples
> 1) {
194 anv_finishme("Test gen8 multisampled HiZ");
196 isl_surf_get_hiz_surf(&dev
->isl_dev
, &image
->depth_surface
.isl
,
197 &image
->hiz_surface
.isl
);
198 add_surface(image
, &image
->hiz_surface
);
206 anv_image_create(VkDevice _device
,
207 const struct anv_image_create_info
*create_info
,
208 const VkAllocationCallbacks
* alloc
,
211 ANV_FROM_HANDLE(anv_device
, device
, _device
);
212 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
213 struct anv_image
*image
= NULL
;
216 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
218 anv_assert(pCreateInfo
->mipLevels
> 0);
219 anv_assert(pCreateInfo
->arrayLayers
> 0);
220 anv_assert(pCreateInfo
->samples
> 0);
221 anv_assert(pCreateInfo
->extent
.width
> 0);
222 anv_assert(pCreateInfo
->extent
.height
> 0);
223 anv_assert(pCreateInfo
->extent
.depth
> 0);
225 image
= vk_alloc2(&device
->alloc
, alloc
, sizeof(*image
), 8,
226 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
228 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
230 memset(image
, 0, sizeof(*image
));
231 image
->type
= pCreateInfo
->imageType
;
232 image
->extent
= pCreateInfo
->extent
;
233 image
->vk_format
= pCreateInfo
->format
;
234 image
->aspects
= vk_format_aspects(image
->vk_format
);
235 image
->levels
= pCreateInfo
->mipLevels
;
236 image
->array_size
= pCreateInfo
->arrayLayers
;
237 image
->samples
= pCreateInfo
->samples
;
238 image
->usage
= pCreateInfo
->usage
;
239 image
->tiling
= pCreateInfo
->tiling
;
242 for_each_bit(b
, image
->aspects
) {
243 r
= make_surface(device
, image
, create_info
, (1 << b
));
248 *pImage
= anv_image_to_handle(image
);
254 vk_free2(&device
->alloc
, alloc
, image
);
260 anv_CreateImage(VkDevice device
,
261 const VkImageCreateInfo
*pCreateInfo
,
262 const VkAllocationCallbacks
*pAllocator
,
265 return anv_image_create(device
,
266 &(struct anv_image_create_info
) {
267 .vk_info
= pCreateInfo
,
274 anv_DestroyImage(VkDevice _device
, VkImage _image
,
275 const VkAllocationCallbacks
*pAllocator
)
277 ANV_FROM_HANDLE(anv_device
, device
, _device
);
279 vk_free2(&device
->alloc
, pAllocator
, anv_image_from_handle(_image
));
282 VkResult
anv_BindImageMemory(
285 VkDeviceMemory _memory
,
286 VkDeviceSize memoryOffset
)
288 ANV_FROM_HANDLE(anv_device
, device
, _device
);
289 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
290 ANV_FROM_HANDLE(anv_image
, image
, _image
);
293 image
->bo
= &mem
->bo
;
294 image
->offset
= memoryOffset
;
300 if (anv_image_has_hiz(image
)) {
302 /* The offset and size must be a multiple of 4K or else the
303 * anv_gem_mmap call below will return NULL.
305 assert((image
->offset
+ image
->hiz_surface
.offset
) % 4096 == 0);
306 assert(image
->hiz_surface
.isl
.size
% 4096 == 0);
308 /* HiZ surfaces need to have their memory cleared to 0 before they
309 * can be used. If we let it have garbage data, it can cause GPU
310 * hangs on some hardware.
312 void *map
= anv_gem_mmap(device
, image
->bo
->gem_handle
,
313 image
->offset
+ image
->hiz_surface
.offset
,
314 image
->hiz_surface
.isl
.size
,
315 device
->info
.has_llc
? 0 : I915_MMAP_WC
);
317 /* If anv_gem_mmap returns NULL, it's likely that the kernel was
318 * not able to find space on the host to create a proper mapping.
321 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
323 memset(map
, 0, image
->hiz_surface
.isl
.size
);
325 anv_gem_munmap(map
, image
->hiz_surface
.isl
.size
);
332 anv_surface_get_subresource_layout(struct anv_image
*image
,
333 struct anv_surface
*surface
,
334 const VkImageSubresource
*subresource
,
335 VkSubresourceLayout
*layout
)
337 /* If we are on a non-zero mip level or array slice, we need to
338 * calculate a real offset.
340 anv_assert(subresource
->mipLevel
== 0);
341 anv_assert(subresource
->arrayLayer
== 0);
343 layout
->offset
= surface
->offset
;
344 layout
->rowPitch
= surface
->isl
.row_pitch
;
345 layout
->depthPitch
= isl_surf_get_array_pitch(&surface
->isl
);
346 layout
->arrayPitch
= isl_surf_get_array_pitch(&surface
->isl
);
347 layout
->size
= surface
->isl
.size
;
350 void anv_GetImageSubresourceLayout(
353 const VkImageSubresource
* pSubresource
,
354 VkSubresourceLayout
* pLayout
)
356 ANV_FROM_HANDLE(anv_image
, image
, _image
);
358 assert(__builtin_popcount(pSubresource
->aspectMask
) == 1);
360 switch (pSubresource
->aspectMask
) {
361 case VK_IMAGE_ASPECT_COLOR_BIT
:
362 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
363 pSubresource
, pLayout
);
365 case VK_IMAGE_ASPECT_DEPTH_BIT
:
366 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
367 pSubresource
, pLayout
);
369 case VK_IMAGE_ASPECT_STENCIL_BIT
:
370 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
371 pSubresource
, pLayout
);
374 assert(!"Invalid image aspect");
378 static struct anv_state
379 alloc_surface_state(struct anv_device
*device
)
381 return anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
384 static enum isl_channel_select
385 remap_swizzle(VkComponentSwizzle swizzle
, VkComponentSwizzle component
,
386 struct isl_swizzle format_swizzle
)
388 if (swizzle
== VK_COMPONENT_SWIZZLE_IDENTITY
)
392 case VK_COMPONENT_SWIZZLE_ZERO
: return ISL_CHANNEL_SELECT_ZERO
;
393 case VK_COMPONENT_SWIZZLE_ONE
: return ISL_CHANNEL_SELECT_ONE
;
394 case VK_COMPONENT_SWIZZLE_R
: return format_swizzle
.r
;
395 case VK_COMPONENT_SWIZZLE_G
: return format_swizzle
.g
;
396 case VK_COMPONENT_SWIZZLE_B
: return format_swizzle
.b
;
397 case VK_COMPONENT_SWIZZLE_A
: return format_swizzle
.a
;
399 unreachable("Invalid swizzle");
405 anv_CreateImageView(VkDevice _device
,
406 const VkImageViewCreateInfo
*pCreateInfo
,
407 const VkAllocationCallbacks
*pAllocator
,
410 ANV_FROM_HANDLE(anv_device
, device
, _device
);
411 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
412 struct anv_image_view
*iview
;
414 iview
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*iview
), 8,
415 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
417 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
419 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
421 assert(range
->layerCount
> 0);
422 assert(range
->baseMipLevel
< image
->levels
);
423 assert(image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
424 VK_IMAGE_USAGE_STORAGE_BIT
|
425 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
426 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
));
428 switch (image
->type
) {
430 unreachable("bad VkImageType");
431 case VK_IMAGE_TYPE_1D
:
432 case VK_IMAGE_TYPE_2D
:
433 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1 <= image
->array_size
);
435 case VK_IMAGE_TYPE_3D
:
436 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1
437 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
441 const struct anv_surface
*surface
=
442 anv_image_get_surface_for_aspect_mask(image
, range
->aspectMask
);
444 iview
->image
= image
;
445 iview
->bo
= image
->bo
;
446 iview
->offset
= image
->offset
+ surface
->offset
;
448 iview
->aspect_mask
= pCreateInfo
->subresourceRange
.aspectMask
;
449 iview
->vk_format
= pCreateInfo
->format
;
451 struct anv_format format
= anv_get_format(&device
->info
, pCreateInfo
->format
,
452 range
->aspectMask
, image
->tiling
);
454 iview
->isl
= (struct isl_view
) {
455 .format
= format
.isl_format
,
456 .base_level
= range
->baseMipLevel
,
457 .levels
= anv_get_levelCount(image
, range
),
458 .base_array_layer
= range
->baseArrayLayer
,
459 .array_len
= anv_get_layerCount(image
, range
),
461 .r
= remap_swizzle(pCreateInfo
->components
.r
,
462 VK_COMPONENT_SWIZZLE_R
, format
.swizzle
),
463 .g
= remap_swizzle(pCreateInfo
->components
.g
,
464 VK_COMPONENT_SWIZZLE_G
, format
.swizzle
),
465 .b
= remap_swizzle(pCreateInfo
->components
.b
,
466 VK_COMPONENT_SWIZZLE_B
, format
.swizzle
),
467 .a
= remap_swizzle(pCreateInfo
->components
.a
,
468 VK_COMPONENT_SWIZZLE_A
, format
.swizzle
),
472 iview
->extent
= (VkExtent3D
) {
473 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
474 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
475 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
478 if (image
->type
== VK_IMAGE_TYPE_3D
) {
479 iview
->isl
.base_array_layer
= 0;
480 iview
->isl
.array_len
= iview
->extent
.depth
;
483 if (pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE
||
484 pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE_ARRAY
) {
485 iview
->isl
.usage
= ISL_SURF_USAGE_CUBE_BIT
;
487 iview
->isl
.usage
= 0;
490 if (image
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
491 iview
->sampler_surface_state
= alloc_surface_state(device
);
493 struct isl_view view
= iview
->isl
;
494 view
.usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
495 isl_surf_fill_state(&device
->isl_dev
,
496 iview
->sampler_surface_state
.map
,
497 .surf
= &surface
->isl
,
499 .mocs
= device
->default_mocs
);
501 if (!device
->info
.has_llc
)
502 anv_state_clflush(iview
->sampler_surface_state
);
504 iview
->sampler_surface_state
.alloc_size
= 0;
507 if (image
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
508 iview
->color_rt_surface_state
= alloc_surface_state(device
);
510 struct isl_view view
= iview
->isl
;
511 view
.usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
512 isl_surf_fill_state(&device
->isl_dev
,
513 iview
->color_rt_surface_state
.map
,
514 .surf
= &surface
->isl
,
516 .mocs
= device
->default_mocs
);
518 if (!device
->info
.has_llc
)
519 anv_state_clflush(iview
->color_rt_surface_state
);
521 iview
->color_rt_surface_state
.alloc_size
= 0;
524 /* NOTE: This one needs to go last since it may stomp isl_view.format */
525 if (image
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
526 iview
->storage_surface_state
= alloc_surface_state(device
);
528 if (isl_has_matching_typed_storage_image_format(&device
->info
,
529 format
.isl_format
)) {
530 struct isl_view view
= iview
->isl
;
531 view
.usage
|= ISL_SURF_USAGE_STORAGE_BIT
;
532 view
.format
= isl_lower_storage_image_format(&device
->info
,
534 isl_surf_fill_state(&device
->isl_dev
,
535 iview
->storage_surface_state
.map
,
536 .surf
= &surface
->isl
,
538 .mocs
= device
->default_mocs
);
540 anv_fill_buffer_surface_state(device
, iview
->storage_surface_state
,
543 iview
->bo
->size
- iview
->offset
, 1);
546 isl_surf_fill_image_param(&device
->isl_dev
,
547 &iview
->storage_image_param
,
548 &surface
->isl
, &iview
->isl
);
550 if (!device
->info
.has_llc
)
551 anv_state_clflush(iview
->storage_surface_state
);
553 iview
->storage_surface_state
.alloc_size
= 0;
556 *pView
= anv_image_view_to_handle(iview
);
562 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
,
563 const VkAllocationCallbacks
*pAllocator
)
565 ANV_FROM_HANDLE(anv_device
, device
, _device
);
566 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
568 if (iview
->color_rt_surface_state
.alloc_size
> 0) {
569 anv_state_pool_free(&device
->surface_state_pool
,
570 iview
->color_rt_surface_state
);
573 if (iview
->sampler_surface_state
.alloc_size
> 0) {
574 anv_state_pool_free(&device
->surface_state_pool
,
575 iview
->sampler_surface_state
);
578 if (iview
->storage_surface_state
.alloc_size
> 0) {
579 anv_state_pool_free(&device
->surface_state_pool
,
580 iview
->storage_surface_state
);
583 vk_free2(&device
->alloc
, pAllocator
, iview
);
588 anv_CreateBufferView(VkDevice _device
,
589 const VkBufferViewCreateInfo
*pCreateInfo
,
590 const VkAllocationCallbacks
*pAllocator
,
593 ANV_FROM_HANDLE(anv_device
, device
, _device
);
594 ANV_FROM_HANDLE(anv_buffer
, buffer
, pCreateInfo
->buffer
);
595 struct anv_buffer_view
*view
;
597 view
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*view
), 8,
598 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
600 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
602 /* TODO: Handle the format swizzle? */
604 view
->format
= anv_get_isl_format(&device
->info
, pCreateInfo
->format
,
605 VK_IMAGE_ASPECT_COLOR_BIT
,
606 VK_IMAGE_TILING_LINEAR
);
607 const uint32_t format_bs
= isl_format_get_layout(view
->format
)->bpb
/ 8;
608 view
->bo
= buffer
->bo
;
609 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
610 view
->range
= pCreateInfo
->range
== VK_WHOLE_SIZE
?
611 buffer
->size
- pCreateInfo
->offset
: pCreateInfo
->range
;
612 view
->range
= align_down_npot_u32(view
->range
, format_bs
);
614 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
) {
615 view
->surface_state
= alloc_surface_state(device
);
617 anv_fill_buffer_surface_state(device
, view
->surface_state
,
619 view
->offset
, view
->range
, format_bs
);
621 view
->surface_state
= (struct anv_state
){ 0 };
624 if (buffer
->usage
& VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
) {
625 view
->storage_surface_state
= alloc_surface_state(device
);
627 enum isl_format storage_format
=
628 isl_has_matching_typed_storage_image_format(&device
->info
,
630 isl_lower_storage_image_format(&device
->info
, view
->format
) :
633 anv_fill_buffer_surface_state(device
, view
->storage_surface_state
,
635 view
->offset
, view
->range
,
636 (storage_format
== ISL_FORMAT_RAW
? 1 :
637 isl_format_get_layout(storage_format
)->bpb
/ 8));
639 isl_buffer_fill_image_param(&device
->isl_dev
,
640 &view
->storage_image_param
,
641 view
->format
, view
->range
);
643 view
->storage_surface_state
= (struct anv_state
){ 0 };
646 *pView
= anv_buffer_view_to_handle(view
);
652 anv_DestroyBufferView(VkDevice _device
, VkBufferView bufferView
,
653 const VkAllocationCallbacks
*pAllocator
)
655 ANV_FROM_HANDLE(anv_device
, device
, _device
);
656 ANV_FROM_HANDLE(anv_buffer_view
, view
, bufferView
);
658 if (view
->surface_state
.alloc_size
> 0)
659 anv_state_pool_free(&device
->surface_state_pool
,
660 view
->surface_state
);
662 if (view
->storage_surface_state
.alloc_size
> 0)
663 anv_state_pool_free(&device
->surface_state_pool
,
664 view
->storage_surface_state
);
666 vk_free2(&device
->alloc
, pAllocator
, view
);
669 const struct anv_surface
*
670 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
671 VkImageAspectFlags aspect_mask
)
673 switch (aspect_mask
) {
674 case VK_IMAGE_ASPECT_COLOR_BIT
:
675 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
676 return &image
->color_surface
;
677 case VK_IMAGE_ASPECT_DEPTH_BIT
:
678 assert(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
);
679 return &image
->depth_surface
;
680 case VK_IMAGE_ASPECT_STENCIL_BIT
:
681 assert(image
->aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
);
682 return &image
->stencil_surface
;
683 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
684 /* FINISHME: The Vulkan spec (git a511ba2) requires support for
685 * combined depth stencil formats. Specifically, it states:
687 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
688 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
690 * Image views with both depth and stencil aspects are only valid for
691 * render target attachments, in which case
692 * cmd_buffer_emit_depth_stencil() will pick out both the depth and
693 * stencil surfaces from the underlying surface.
695 if (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
696 return &image
->depth_surface
;
698 assert(image
->aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
699 return &image
->stencil_surface
;
702 unreachable("image does not have aspect");