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 if (vk_usage
& VK_IMAGE_USAGE_SAMPLED_BIT
)
45 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
47 if (vk_usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)
48 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
50 if (vk_usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
)
51 isl_usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
53 if (vk_usage
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)
54 isl_usage
|= ISL_SURF_USAGE_CUBE_BIT
;
56 /* Even if we're only using it for transfer operations, clears to depth and
57 * stencil images happen as depth and stencil so they need the right ISL
58 * usage bits or else things will fall apart.
61 case VK_IMAGE_ASPECT_DEPTH_BIT
:
62 isl_usage
|= ISL_SURF_USAGE_DEPTH_BIT
;
64 case VK_IMAGE_ASPECT_STENCIL_BIT
:
65 isl_usage
|= ISL_SURF_USAGE_STENCIL_BIT
;
67 case VK_IMAGE_ASPECT_COLOR_BIT
:
70 unreachable("bad VkImageAspect");
73 if (vk_usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
74 /* blorp implements transfers by sampling from the source image. */
75 isl_usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
78 if (vk_usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
79 /* blorp implements transfers by rendering into the destination image. */
80 isl_usage
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
87 * Exactly one bit must be set in \a aspect.
89 static struct anv_surface
*
90 get_surface(struct anv_image
*image
, VkImageAspectFlags aspect
)
94 unreachable("bad VkImageAspect");
95 case VK_IMAGE_ASPECT_COLOR_BIT
:
96 return &image
->color_surface
;
97 case VK_IMAGE_ASPECT_DEPTH_BIT
:
98 return &image
->depth_surface
;
99 case VK_IMAGE_ASPECT_STENCIL_BIT
:
100 return &image
->stencil_surface
;
105 add_surface(struct anv_image
*image
, struct anv_surface
*surf
)
107 assert(surf
->isl
.size
> 0); /* isl surface must be initialized */
109 surf
->offset
= align_u32(image
->size
, surf
->isl
.alignment
);
110 image
->size
= surf
->offset
+ surf
->isl
.size
;
111 image
->alignment
= MAX2(image
->alignment
, surf
->isl
.alignment
);
115 * Initialize the anv_image::*_surface selected by \a aspect. Then update the
116 * image's memory requirements (that is, the image's size and alignment).
118 * Exactly one bit must be set in \a aspect.
121 make_surface(const struct anv_device
*dev
,
122 struct anv_image
*image
,
123 const struct anv_image_create_info
*anv_info
,
124 VkImageAspectFlags aspect
)
126 const VkImageCreateInfo
*vk_info
= anv_info
->vk_info
;
129 static const enum isl_surf_dim vk_to_isl_surf_dim
[] = {
130 [VK_IMAGE_TYPE_1D
] = ISL_SURF_DIM_1D
,
131 [VK_IMAGE_TYPE_2D
] = ISL_SURF_DIM_2D
,
132 [VK_IMAGE_TYPE_3D
] = ISL_SURF_DIM_3D
,
135 /* Translate the Vulkan tiling to an equivalent ISL tiling, then filter the
136 * result with an optionally provided ISL tiling argument.
138 isl_tiling_flags_t tiling_flags
=
139 (vk_info
->tiling
== VK_IMAGE_TILING_LINEAR
) ?
140 ISL_TILING_LINEAR_BIT
: ISL_TILING_ANY_MASK
;
142 if (anv_info
->isl_tiling_flags
)
143 tiling_flags
&= anv_info
->isl_tiling_flags
;
145 assert(tiling_flags
);
147 struct anv_surface
*anv_surf
= get_surface(image
, aspect
);
149 image
->extent
= anv_sanitize_image_extent(vk_info
->imageType
,
152 enum isl_format format
= anv_get_isl_format(&dev
->info
, vk_info
->format
,
153 aspect
, vk_info
->tiling
);
154 assert(format
!= ISL_FORMAT_UNSUPPORTED
);
156 ok
= isl_surf_init(&dev
->isl_dev
, &anv_surf
->isl
,
157 .dim
= vk_to_isl_surf_dim
[vk_info
->imageType
],
159 .width
= image
->extent
.width
,
160 .height
= image
->extent
.height
,
161 .depth
= image
->extent
.depth
,
162 .levels
= vk_info
->mipLevels
,
163 .array_len
= vk_info
->arrayLayers
,
164 .samples
= vk_info
->samples
,
166 .min_pitch
= anv_info
->stride
,
167 .usage
= choose_isl_surf_usage(image
->usage
, aspect
),
168 .tiling_flags
= tiling_flags
);
170 /* isl_surf_init() will fail only if provided invalid input. Invalid input
171 * is illegal in Vulkan.
175 add_surface(image
, anv_surf
);
177 /* Add a HiZ surface to a depth buffer that will be used for rendering.
179 if (aspect
== VK_IMAGE_ASPECT_DEPTH_BIT
) {
180 /* Allow the user to control HiZ enabling. Disable by default on gen7
181 * because resolves are not currently implemented pre-BDW.
183 if (!(image
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
184 /* It will never be used as an attachment, HiZ is pointless. */
185 } else if (!env_var_as_boolean("INTEL_VK_HIZ", dev
->info
.gen
>= 8)) {
186 anv_finishme("Implement gen7 HiZ");
187 } else if (vk_info
->mipLevels
> 1) {
188 anv_finishme("Test multi-LOD HiZ");
189 } else if (dev
->info
.gen
== 8 && vk_info
->samples
> 1) {
190 anv_finishme("Test gen8 multisampled HiZ");
192 assert(image
->aux_surface
.isl
.size
== 0);
193 isl_surf_get_hiz_surf(&dev
->isl_dev
, &image
->depth_surface
.isl
,
194 &image
->aux_surface
.isl
);
195 add_surface(image
, &image
->aux_surface
);
197 } else if (aspect
== VK_IMAGE_ASPECT_COLOR_BIT
&& vk_info
->samples
== 1) {
198 if (!unlikely(INTEL_DEBUG
& DEBUG_NO_RBC
)) {
199 assert(image
->aux_surface
.isl
.size
== 0);
200 ok
= isl_surf_get_ccs_surf(&dev
->isl_dev
, &anv_surf
->isl
,
201 &image
->aux_surface
.isl
);
203 add_surface(image
, &image
->aux_surface
);
205 /* For images created without MUTABLE_FORMAT_BIT set, we know that
206 * they will always be used with the original format. In
207 * particular, they will always be used with a format that
208 * supports color compression. This means that it's safe to just
209 * leave compression on at all times for these formats.
211 if (!(vk_info
->flags
& VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
) &&
212 isl_format_supports_lossless_compression(&dev
->info
, format
)) {
213 if (vk_info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
215 * For now, we leave compression off for anything that may
216 * be used as a storage image. This is because accessing
217 * storage images may involve ccs-incompatible views or even
218 * untyped messages which don't support compression at all.
220 anv_finishme("Enable CCS for storage images");
222 image
->aux_usage
= ISL_AUX_USAGE_CCS_E
;
233 anv_image_create(VkDevice _device
,
234 const struct anv_image_create_info
*create_info
,
235 const VkAllocationCallbacks
* alloc
,
238 ANV_FROM_HANDLE(anv_device
, device
, _device
);
239 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
240 struct anv_image
*image
= NULL
;
243 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
245 anv_assert(pCreateInfo
->mipLevels
> 0);
246 anv_assert(pCreateInfo
->arrayLayers
> 0);
247 anv_assert(pCreateInfo
->samples
> 0);
248 anv_assert(pCreateInfo
->extent
.width
> 0);
249 anv_assert(pCreateInfo
->extent
.height
> 0);
250 anv_assert(pCreateInfo
->extent
.depth
> 0);
252 image
= vk_alloc2(&device
->alloc
, alloc
, sizeof(*image
), 8,
253 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
255 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
257 memset(image
, 0, sizeof(*image
));
258 image
->type
= pCreateInfo
->imageType
;
259 image
->extent
= pCreateInfo
->extent
;
260 image
->vk_format
= pCreateInfo
->format
;
261 image
->aspects
= vk_format_aspects(image
->vk_format
);
262 image
->levels
= pCreateInfo
->mipLevels
;
263 image
->array_size
= pCreateInfo
->arrayLayers
;
264 image
->samples
= pCreateInfo
->samples
;
265 image
->usage
= pCreateInfo
->usage
;
266 image
->tiling
= pCreateInfo
->tiling
;
267 image
->aux_usage
= ISL_AUX_USAGE_NONE
;
270 for_each_bit(b
, image
->aspects
) {
271 r
= make_surface(device
, image
, create_info
, (1 << b
));
276 *pImage
= anv_image_to_handle(image
);
282 vk_free2(&device
->alloc
, alloc
, image
);
288 anv_CreateImage(VkDevice device
,
289 const VkImageCreateInfo
*pCreateInfo
,
290 const VkAllocationCallbacks
*pAllocator
,
293 return anv_image_create(device
,
294 &(struct anv_image_create_info
) {
295 .vk_info
= pCreateInfo
,
302 anv_DestroyImage(VkDevice _device
, VkImage _image
,
303 const VkAllocationCallbacks
*pAllocator
)
305 ANV_FROM_HANDLE(anv_device
, device
, _device
);
306 ANV_FROM_HANDLE(anv_image
, image
, _image
);
311 vk_free2(&device
->alloc
, pAllocator
, image
);
314 VkResult
anv_BindImageMemory(
317 VkDeviceMemory _memory
,
318 VkDeviceSize memoryOffset
)
320 ANV_FROM_HANDLE(anv_device
, device
, _device
);
321 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
322 ANV_FROM_HANDLE(anv_image
, image
, _image
);
325 image
->bo
= &mem
->bo
;
326 image
->offset
= memoryOffset
;
332 if (image
->aux_surface
.isl
.size
> 0) {
334 /* The offset and size must be a multiple of 4K or else the
335 * anv_gem_mmap call below will return NULL.
337 assert((image
->offset
+ image
->aux_surface
.offset
) % 4096 == 0);
338 assert(image
->aux_surface
.isl
.size
% 4096 == 0);
340 /* Auxiliary surfaces need to have their memory cleared to 0 before they
341 * can be used. For CCS surfaces, this puts them in the "resolved"
342 * state so they can be used with CCS enabled before we ever touch it
343 * from the GPU. For HiZ, we need something valid or else we may get
344 * GPU hangs on some hardware and 0 works fine.
346 void *map
= anv_gem_mmap(device
, image
->bo
->gem_handle
,
347 image
->offset
+ image
->aux_surface
.offset
,
348 image
->aux_surface
.isl
.size
,
349 device
->info
.has_llc
? 0 : I915_MMAP_WC
);
351 /* If anv_gem_mmap returns NULL, it's likely that the kernel was
352 * not able to find space on the host to create a proper mapping.
355 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
357 memset(map
, 0, image
->aux_surface
.isl
.size
);
359 anv_gem_munmap(map
, image
->aux_surface
.isl
.size
);
366 anv_surface_get_subresource_layout(struct anv_image
*image
,
367 struct anv_surface
*surface
,
368 const VkImageSubresource
*subresource
,
369 VkSubresourceLayout
*layout
)
371 /* If we are on a non-zero mip level or array slice, we need to
372 * calculate a real offset.
374 anv_assert(subresource
->mipLevel
== 0);
375 anv_assert(subresource
->arrayLayer
== 0);
377 layout
->offset
= surface
->offset
;
378 layout
->rowPitch
= surface
->isl
.row_pitch
;
379 layout
->depthPitch
= isl_surf_get_array_pitch(&surface
->isl
);
380 layout
->arrayPitch
= isl_surf_get_array_pitch(&surface
->isl
);
381 layout
->size
= surface
->isl
.size
;
384 void anv_GetImageSubresourceLayout(
387 const VkImageSubresource
* pSubresource
,
388 VkSubresourceLayout
* pLayout
)
390 ANV_FROM_HANDLE(anv_image
, image
, _image
);
392 assert(__builtin_popcount(pSubresource
->aspectMask
) == 1);
394 switch (pSubresource
->aspectMask
) {
395 case VK_IMAGE_ASPECT_COLOR_BIT
:
396 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
397 pSubresource
, pLayout
);
399 case VK_IMAGE_ASPECT_DEPTH_BIT
:
400 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
401 pSubresource
, pLayout
);
403 case VK_IMAGE_ASPECT_STENCIL_BIT
:
404 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
405 pSubresource
, pLayout
);
408 assert(!"Invalid image aspect");
412 static struct anv_state
413 alloc_surface_state(struct anv_device
*device
)
415 return anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
418 static enum isl_channel_select
419 remap_swizzle(VkComponentSwizzle swizzle
, VkComponentSwizzle component
,
420 struct isl_swizzle format_swizzle
)
422 if (swizzle
== VK_COMPONENT_SWIZZLE_IDENTITY
)
426 case VK_COMPONENT_SWIZZLE_ZERO
: return ISL_CHANNEL_SELECT_ZERO
;
427 case VK_COMPONENT_SWIZZLE_ONE
: return ISL_CHANNEL_SELECT_ONE
;
428 case VK_COMPONENT_SWIZZLE_R
: return format_swizzle
.r
;
429 case VK_COMPONENT_SWIZZLE_G
: return format_swizzle
.g
;
430 case VK_COMPONENT_SWIZZLE_B
: return format_swizzle
.b
;
431 case VK_COMPONENT_SWIZZLE_A
: return format_swizzle
.a
;
433 unreachable("Invalid swizzle");
439 anv_CreateImageView(VkDevice _device
,
440 const VkImageViewCreateInfo
*pCreateInfo
,
441 const VkAllocationCallbacks
*pAllocator
,
444 ANV_FROM_HANDLE(anv_device
, device
, _device
);
445 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
446 struct anv_image_view
*iview
;
448 iview
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*iview
), 8,
449 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
451 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
453 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
455 assert(range
->layerCount
> 0);
456 assert(range
->baseMipLevel
< image
->levels
);
457 assert(image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
458 VK_IMAGE_USAGE_STORAGE_BIT
|
459 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
460 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
));
462 switch (image
->type
) {
464 unreachable("bad VkImageType");
465 case VK_IMAGE_TYPE_1D
:
466 case VK_IMAGE_TYPE_2D
:
467 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1 <= image
->array_size
);
469 case VK_IMAGE_TYPE_3D
:
470 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1
471 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
475 const struct anv_surface
*surface
=
476 anv_image_get_surface_for_aspect_mask(image
, range
->aspectMask
);
478 iview
->image
= image
;
479 iview
->bo
= image
->bo
;
480 iview
->offset
= image
->offset
+ surface
->offset
;
482 iview
->aspect_mask
= pCreateInfo
->subresourceRange
.aspectMask
;
483 iview
->vk_format
= pCreateInfo
->format
;
485 struct anv_format format
= anv_get_format(&device
->info
, pCreateInfo
->format
,
486 range
->aspectMask
, image
->tiling
);
488 iview
->isl
= (struct isl_view
) {
489 .format
= format
.isl_format
,
490 .base_level
= range
->baseMipLevel
,
491 .levels
= anv_get_levelCount(image
, range
),
492 .base_array_layer
= range
->baseArrayLayer
,
493 .array_len
= anv_get_layerCount(image
, range
),
495 .r
= remap_swizzle(pCreateInfo
->components
.r
,
496 VK_COMPONENT_SWIZZLE_R
, format
.swizzle
),
497 .g
= remap_swizzle(pCreateInfo
->components
.g
,
498 VK_COMPONENT_SWIZZLE_G
, format
.swizzle
),
499 .b
= remap_swizzle(pCreateInfo
->components
.b
,
500 VK_COMPONENT_SWIZZLE_B
, format
.swizzle
),
501 .a
= remap_swizzle(pCreateInfo
->components
.a
,
502 VK_COMPONENT_SWIZZLE_A
, format
.swizzle
),
506 iview
->extent
= (VkExtent3D
) {
507 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
508 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
509 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
512 if (image
->type
== VK_IMAGE_TYPE_3D
) {
513 iview
->isl
.base_array_layer
= 0;
514 iview
->isl
.array_len
= iview
->extent
.depth
;
517 if (pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE
||
518 pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE_ARRAY
) {
519 iview
->isl
.usage
= ISL_SURF_USAGE_CUBE_BIT
;
521 iview
->isl
.usage
= 0;
524 /* Input attachment surfaces for color or depth are allocated and filled
525 * out at BeginRenderPass time because they need compression information.
526 * Stencil image do not support compression so we just use the texture
527 * surface from the image view.
529 if (image
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
||
530 (image
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
&&
531 (iview
->aspect_mask
& VK_IMAGE_ASPECT_STENCIL_BIT
))) {
532 iview
->sampler_surface_state
= alloc_surface_state(device
);
534 struct isl_view view
= iview
->isl
;
535 view
.usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
536 isl_surf_fill_state(&device
->isl_dev
,
537 iview
->sampler_surface_state
.map
,
538 .surf
= &surface
->isl
,
540 .aux_surf
= &image
->aux_surface
.isl
,
541 .aux_usage
= image
->aux_usage
,
542 .mocs
= device
->default_mocs
);
544 if (!device
->info
.has_llc
)
545 anv_state_clflush(iview
->sampler_surface_state
);
547 iview
->sampler_surface_state
.alloc_size
= 0;
550 /* NOTE: This one needs to go last since it may stomp isl_view.format */
551 if (image
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
552 iview
->storage_surface_state
= alloc_surface_state(device
);
554 if (isl_has_matching_typed_storage_image_format(&device
->info
,
555 format
.isl_format
)) {
556 struct isl_view view
= iview
->isl
;
557 view
.usage
|= ISL_SURF_USAGE_STORAGE_BIT
;
558 view
.format
= isl_lower_storage_image_format(&device
->info
,
560 isl_surf_fill_state(&device
->isl_dev
,
561 iview
->storage_surface_state
.map
,
562 .surf
= &surface
->isl
,
564 .aux_surf
= &image
->aux_surface
.isl
,
565 .aux_usage
= image
->aux_usage
,
566 .mocs
= device
->default_mocs
);
568 anv_fill_buffer_surface_state(device
, iview
->storage_surface_state
,
571 iview
->bo
->size
- iview
->offset
, 1);
574 isl_surf_fill_image_param(&device
->isl_dev
,
575 &iview
->storage_image_param
,
576 &surface
->isl
, &iview
->isl
);
578 if (!device
->info
.has_llc
)
579 anv_state_clflush(iview
->storage_surface_state
);
581 iview
->storage_surface_state
.alloc_size
= 0;
584 *pView
= anv_image_view_to_handle(iview
);
590 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
,
591 const VkAllocationCallbacks
*pAllocator
)
593 ANV_FROM_HANDLE(anv_device
, device
, _device
);
594 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
599 if (iview
->sampler_surface_state
.alloc_size
> 0) {
600 anv_state_pool_free(&device
->surface_state_pool
,
601 iview
->sampler_surface_state
);
604 if (iview
->storage_surface_state
.alloc_size
> 0) {
605 anv_state_pool_free(&device
->surface_state_pool
,
606 iview
->storage_surface_state
);
609 vk_free2(&device
->alloc
, pAllocator
, iview
);
614 anv_CreateBufferView(VkDevice _device
,
615 const VkBufferViewCreateInfo
*pCreateInfo
,
616 const VkAllocationCallbacks
*pAllocator
,
619 ANV_FROM_HANDLE(anv_device
, device
, _device
);
620 ANV_FROM_HANDLE(anv_buffer
, buffer
, pCreateInfo
->buffer
);
621 struct anv_buffer_view
*view
;
623 view
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*view
), 8,
624 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
626 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
628 /* TODO: Handle the format swizzle? */
630 view
->format
= anv_get_isl_format(&device
->info
, pCreateInfo
->format
,
631 VK_IMAGE_ASPECT_COLOR_BIT
,
632 VK_IMAGE_TILING_LINEAR
);
633 const uint32_t format_bs
= isl_format_get_layout(view
->format
)->bpb
/ 8;
634 view
->bo
= buffer
->bo
;
635 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
636 view
->range
= pCreateInfo
->range
== VK_WHOLE_SIZE
?
637 buffer
->size
- pCreateInfo
->offset
: pCreateInfo
->range
;
638 view
->range
= align_down_npot_u32(view
->range
, format_bs
);
640 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
) {
641 view
->surface_state
= alloc_surface_state(device
);
643 anv_fill_buffer_surface_state(device
, view
->surface_state
,
645 view
->offset
, view
->range
, format_bs
);
647 view
->surface_state
= (struct anv_state
){ 0 };
650 if (buffer
->usage
& VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
) {
651 view
->storage_surface_state
= alloc_surface_state(device
);
653 enum isl_format storage_format
=
654 isl_has_matching_typed_storage_image_format(&device
->info
,
656 isl_lower_storage_image_format(&device
->info
, view
->format
) :
659 anv_fill_buffer_surface_state(device
, view
->storage_surface_state
,
661 view
->offset
, view
->range
,
662 (storage_format
== ISL_FORMAT_RAW
? 1 :
663 isl_format_get_layout(storage_format
)->bpb
/ 8));
665 isl_buffer_fill_image_param(&device
->isl_dev
,
666 &view
->storage_image_param
,
667 view
->format
, view
->range
);
669 view
->storage_surface_state
= (struct anv_state
){ 0 };
672 *pView
= anv_buffer_view_to_handle(view
);
678 anv_DestroyBufferView(VkDevice _device
, VkBufferView bufferView
,
679 const VkAllocationCallbacks
*pAllocator
)
681 ANV_FROM_HANDLE(anv_device
, device
, _device
);
682 ANV_FROM_HANDLE(anv_buffer_view
, view
, bufferView
);
687 if (view
->surface_state
.alloc_size
> 0)
688 anv_state_pool_free(&device
->surface_state_pool
,
689 view
->surface_state
);
691 if (view
->storage_surface_state
.alloc_size
> 0)
692 anv_state_pool_free(&device
->surface_state_pool
,
693 view
->storage_surface_state
);
695 vk_free2(&device
->alloc
, pAllocator
, view
);
698 const struct anv_surface
*
699 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
700 VkImageAspectFlags aspect_mask
)
702 switch (aspect_mask
) {
703 case VK_IMAGE_ASPECT_COLOR_BIT
:
704 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
705 return &image
->color_surface
;
706 case VK_IMAGE_ASPECT_DEPTH_BIT
:
707 assert(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
);
708 return &image
->depth_surface
;
709 case VK_IMAGE_ASPECT_STENCIL_BIT
:
710 assert(image
->aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
);
711 return &image
->stencil_surface
;
712 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
713 /* FINISHME: The Vulkan spec (git a511ba2) requires support for
714 * combined depth stencil formats. Specifically, it states:
716 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
717 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
719 * Image views with both depth and stencil aspects are only valid for
720 * render target attachments, in which case
721 * cmd_buffer_emit_depth_stencil() will pick out both the depth and
722 * stencil surfaces from the underlying surface.
724 if (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
725 return &image
->depth_surface
;
727 assert(image
->aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
728 return &image
->stencil_surface
;
731 unreachable("image does not have aspect");