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 (dev
->info
.gen
>= 9 && !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
);
211 anv_image_create(VkDevice _device
,
212 const struct anv_image_create_info
*create_info
,
213 const VkAllocationCallbacks
* alloc
,
216 ANV_FROM_HANDLE(anv_device
, device
, _device
);
217 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
218 struct anv_image
*image
= NULL
;
221 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
223 anv_assert(pCreateInfo
->mipLevels
> 0);
224 anv_assert(pCreateInfo
->arrayLayers
> 0);
225 anv_assert(pCreateInfo
->samples
> 0);
226 anv_assert(pCreateInfo
->extent
.width
> 0);
227 anv_assert(pCreateInfo
->extent
.height
> 0);
228 anv_assert(pCreateInfo
->extent
.depth
> 0);
230 image
= vk_alloc2(&device
->alloc
, alloc
, sizeof(*image
), 8,
231 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
233 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
235 memset(image
, 0, sizeof(*image
));
236 image
->type
= pCreateInfo
->imageType
;
237 image
->extent
= pCreateInfo
->extent
;
238 image
->vk_format
= pCreateInfo
->format
;
239 image
->aspects
= vk_format_aspects(image
->vk_format
);
240 image
->levels
= pCreateInfo
->mipLevels
;
241 image
->array_size
= pCreateInfo
->arrayLayers
;
242 image
->samples
= pCreateInfo
->samples
;
243 image
->usage
= pCreateInfo
->usage
;
244 image
->tiling
= pCreateInfo
->tiling
;
247 for_each_bit(b
, image
->aspects
) {
248 r
= make_surface(device
, image
, create_info
, (1 << b
));
253 *pImage
= anv_image_to_handle(image
);
259 vk_free2(&device
->alloc
, alloc
, image
);
265 anv_CreateImage(VkDevice device
,
266 const VkImageCreateInfo
*pCreateInfo
,
267 const VkAllocationCallbacks
*pAllocator
,
270 return anv_image_create(device
,
271 &(struct anv_image_create_info
) {
272 .vk_info
= pCreateInfo
,
279 anv_DestroyImage(VkDevice _device
, VkImage _image
,
280 const VkAllocationCallbacks
*pAllocator
)
282 ANV_FROM_HANDLE(anv_device
, device
, _device
);
283 ANV_FROM_HANDLE(anv_image
, image
, _image
);
288 vk_free2(&device
->alloc
, pAllocator
, image
);
291 VkResult
anv_BindImageMemory(
294 VkDeviceMemory _memory
,
295 VkDeviceSize memoryOffset
)
297 ANV_FROM_HANDLE(anv_device
, device
, _device
);
298 ANV_FROM_HANDLE(anv_device_memory
, mem
, _memory
);
299 ANV_FROM_HANDLE(anv_image
, image
, _image
);
302 image
->bo
= &mem
->bo
;
303 image
->offset
= memoryOffset
;
309 if (image
->aux_surface
.isl
.size
> 0) {
311 /* The offset and size must be a multiple of 4K or else the
312 * anv_gem_mmap call below will return NULL.
314 assert((image
->offset
+ image
->aux_surface
.offset
) % 4096 == 0);
315 assert(image
->aux_surface
.isl
.size
% 4096 == 0);
317 /* Auxiliary surfaces need to have their memory cleared to 0 before they
318 * can be used. For CCS surfaces, this puts them in the "resolved"
319 * state so they can be used with CCS enabled before we ever touch it
320 * from the GPU. For HiZ, we need something valid or else we may get
321 * GPU hangs on some hardware and 0 works fine.
323 void *map
= anv_gem_mmap(device
, image
->bo
->gem_handle
,
324 image
->offset
+ image
->aux_surface
.offset
,
325 image
->aux_surface
.isl
.size
,
326 device
->info
.has_llc
? 0 : I915_MMAP_WC
);
328 /* If anv_gem_mmap returns NULL, it's likely that the kernel was
329 * not able to find space on the host to create a proper mapping.
332 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
334 memset(map
, 0, image
->aux_surface
.isl
.size
);
336 anv_gem_munmap(map
, image
->aux_surface
.isl
.size
);
343 anv_surface_get_subresource_layout(struct anv_image
*image
,
344 struct anv_surface
*surface
,
345 const VkImageSubresource
*subresource
,
346 VkSubresourceLayout
*layout
)
348 /* If we are on a non-zero mip level or array slice, we need to
349 * calculate a real offset.
351 anv_assert(subresource
->mipLevel
== 0);
352 anv_assert(subresource
->arrayLayer
== 0);
354 layout
->offset
= surface
->offset
;
355 layout
->rowPitch
= surface
->isl
.row_pitch
;
356 layout
->depthPitch
= isl_surf_get_array_pitch(&surface
->isl
);
357 layout
->arrayPitch
= isl_surf_get_array_pitch(&surface
->isl
);
358 layout
->size
= surface
->isl
.size
;
361 void anv_GetImageSubresourceLayout(
364 const VkImageSubresource
* pSubresource
,
365 VkSubresourceLayout
* pLayout
)
367 ANV_FROM_HANDLE(anv_image
, image
, _image
);
369 assert(__builtin_popcount(pSubresource
->aspectMask
) == 1);
371 switch (pSubresource
->aspectMask
) {
372 case VK_IMAGE_ASPECT_COLOR_BIT
:
373 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
374 pSubresource
, pLayout
);
376 case VK_IMAGE_ASPECT_DEPTH_BIT
:
377 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
378 pSubresource
, pLayout
);
380 case VK_IMAGE_ASPECT_STENCIL_BIT
:
381 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
382 pSubresource
, pLayout
);
385 assert(!"Invalid image aspect");
389 static struct anv_state
390 alloc_surface_state(struct anv_device
*device
)
392 return anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
395 static enum isl_channel_select
396 remap_swizzle(VkComponentSwizzle swizzle
, VkComponentSwizzle component
,
397 struct isl_swizzle format_swizzle
)
399 if (swizzle
== VK_COMPONENT_SWIZZLE_IDENTITY
)
403 case VK_COMPONENT_SWIZZLE_ZERO
: return ISL_CHANNEL_SELECT_ZERO
;
404 case VK_COMPONENT_SWIZZLE_ONE
: return ISL_CHANNEL_SELECT_ONE
;
405 case VK_COMPONENT_SWIZZLE_R
: return format_swizzle
.r
;
406 case VK_COMPONENT_SWIZZLE_G
: return format_swizzle
.g
;
407 case VK_COMPONENT_SWIZZLE_B
: return format_swizzle
.b
;
408 case VK_COMPONENT_SWIZZLE_A
: return format_swizzle
.a
;
410 unreachable("Invalid swizzle");
416 anv_CreateImageView(VkDevice _device
,
417 const VkImageViewCreateInfo
*pCreateInfo
,
418 const VkAllocationCallbacks
*pAllocator
,
421 ANV_FROM_HANDLE(anv_device
, device
, _device
);
422 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
423 struct anv_image_view
*iview
;
425 iview
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*iview
), 8,
426 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
428 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
430 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
432 assert(range
->layerCount
> 0);
433 assert(range
->baseMipLevel
< image
->levels
);
434 assert(image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
435 VK_IMAGE_USAGE_STORAGE_BIT
|
436 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
437 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
));
439 switch (image
->type
) {
441 unreachable("bad VkImageType");
442 case VK_IMAGE_TYPE_1D
:
443 case VK_IMAGE_TYPE_2D
:
444 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1 <= image
->array_size
);
446 case VK_IMAGE_TYPE_3D
:
447 assert(range
->baseArrayLayer
+ anv_get_layerCount(image
, range
) - 1
448 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
452 const struct anv_surface
*surface
=
453 anv_image_get_surface_for_aspect_mask(image
, range
->aspectMask
);
455 iview
->image
= image
;
456 iview
->bo
= image
->bo
;
457 iview
->offset
= image
->offset
+ surface
->offset
;
459 iview
->aspect_mask
= pCreateInfo
->subresourceRange
.aspectMask
;
460 iview
->vk_format
= pCreateInfo
->format
;
462 struct anv_format format
= anv_get_format(&device
->info
, pCreateInfo
->format
,
463 range
->aspectMask
, image
->tiling
);
465 iview
->isl
= (struct isl_view
) {
466 .format
= format
.isl_format
,
467 .base_level
= range
->baseMipLevel
,
468 .levels
= anv_get_levelCount(image
, range
),
469 .base_array_layer
= range
->baseArrayLayer
,
470 .array_len
= anv_get_layerCount(image
, range
),
472 .r
= remap_swizzle(pCreateInfo
->components
.r
,
473 VK_COMPONENT_SWIZZLE_R
, format
.swizzle
),
474 .g
= remap_swizzle(pCreateInfo
->components
.g
,
475 VK_COMPONENT_SWIZZLE_G
, format
.swizzle
),
476 .b
= remap_swizzle(pCreateInfo
->components
.b
,
477 VK_COMPONENT_SWIZZLE_B
, format
.swizzle
),
478 .a
= remap_swizzle(pCreateInfo
->components
.a
,
479 VK_COMPONENT_SWIZZLE_A
, format
.swizzle
),
483 iview
->extent
= (VkExtent3D
) {
484 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
485 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
486 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
489 if (image
->type
== VK_IMAGE_TYPE_3D
) {
490 iview
->isl
.base_array_layer
= 0;
491 iview
->isl
.array_len
= iview
->extent
.depth
;
494 if (pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE
||
495 pCreateInfo
->viewType
== VK_IMAGE_VIEW_TYPE_CUBE_ARRAY
) {
496 iview
->isl
.usage
= ISL_SURF_USAGE_CUBE_BIT
;
498 iview
->isl
.usage
= 0;
501 if (image
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
502 iview
->sampler_surface_state
= alloc_surface_state(device
);
504 struct isl_view view
= iview
->isl
;
505 view
.usage
|= ISL_SURF_USAGE_TEXTURE_BIT
;
506 isl_surf_fill_state(&device
->isl_dev
,
507 iview
->sampler_surface_state
.map
,
508 .surf
= &surface
->isl
,
510 .mocs
= device
->default_mocs
);
512 if (!device
->info
.has_llc
)
513 anv_state_clflush(iview
->sampler_surface_state
);
515 iview
->sampler_surface_state
.alloc_size
= 0;
518 /* NOTE: This one needs to go last since it may stomp isl_view.format */
519 if (image
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
520 iview
->storage_surface_state
= alloc_surface_state(device
);
522 if (isl_has_matching_typed_storage_image_format(&device
->info
,
523 format
.isl_format
)) {
524 struct isl_view view
= iview
->isl
;
525 view
.usage
|= ISL_SURF_USAGE_STORAGE_BIT
;
526 view
.format
= isl_lower_storage_image_format(&device
->info
,
528 isl_surf_fill_state(&device
->isl_dev
,
529 iview
->storage_surface_state
.map
,
530 .surf
= &surface
->isl
,
532 .mocs
= device
->default_mocs
);
534 anv_fill_buffer_surface_state(device
, iview
->storage_surface_state
,
537 iview
->bo
->size
- iview
->offset
, 1);
540 isl_surf_fill_image_param(&device
->isl_dev
,
541 &iview
->storage_image_param
,
542 &surface
->isl
, &iview
->isl
);
544 if (!device
->info
.has_llc
)
545 anv_state_clflush(iview
->storage_surface_state
);
547 iview
->storage_surface_state
.alloc_size
= 0;
550 *pView
= anv_image_view_to_handle(iview
);
556 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
,
557 const VkAllocationCallbacks
*pAllocator
)
559 ANV_FROM_HANDLE(anv_device
, device
, _device
);
560 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
565 if (iview
->sampler_surface_state
.alloc_size
> 0) {
566 anv_state_pool_free(&device
->surface_state_pool
,
567 iview
->sampler_surface_state
);
570 if (iview
->storage_surface_state
.alloc_size
> 0) {
571 anv_state_pool_free(&device
->surface_state_pool
,
572 iview
->storage_surface_state
);
575 vk_free2(&device
->alloc
, pAllocator
, iview
);
580 anv_CreateBufferView(VkDevice _device
,
581 const VkBufferViewCreateInfo
*pCreateInfo
,
582 const VkAllocationCallbacks
*pAllocator
,
585 ANV_FROM_HANDLE(anv_device
, device
, _device
);
586 ANV_FROM_HANDLE(anv_buffer
, buffer
, pCreateInfo
->buffer
);
587 struct anv_buffer_view
*view
;
589 view
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*view
), 8,
590 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
592 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
594 /* TODO: Handle the format swizzle? */
596 view
->format
= anv_get_isl_format(&device
->info
, pCreateInfo
->format
,
597 VK_IMAGE_ASPECT_COLOR_BIT
,
598 VK_IMAGE_TILING_LINEAR
);
599 const uint32_t format_bs
= isl_format_get_layout(view
->format
)->bpb
/ 8;
600 view
->bo
= buffer
->bo
;
601 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
602 view
->range
= pCreateInfo
->range
== VK_WHOLE_SIZE
?
603 buffer
->size
- pCreateInfo
->offset
: pCreateInfo
->range
;
604 view
->range
= align_down_npot_u32(view
->range
, format_bs
);
606 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
) {
607 view
->surface_state
= alloc_surface_state(device
);
609 anv_fill_buffer_surface_state(device
, view
->surface_state
,
611 view
->offset
, view
->range
, format_bs
);
613 view
->surface_state
= (struct anv_state
){ 0 };
616 if (buffer
->usage
& VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
) {
617 view
->storage_surface_state
= alloc_surface_state(device
);
619 enum isl_format storage_format
=
620 isl_has_matching_typed_storage_image_format(&device
->info
,
622 isl_lower_storage_image_format(&device
->info
, view
->format
) :
625 anv_fill_buffer_surface_state(device
, view
->storage_surface_state
,
627 view
->offset
, view
->range
,
628 (storage_format
== ISL_FORMAT_RAW
? 1 :
629 isl_format_get_layout(storage_format
)->bpb
/ 8));
631 isl_buffer_fill_image_param(&device
->isl_dev
,
632 &view
->storage_image_param
,
633 view
->format
, view
->range
);
635 view
->storage_surface_state
= (struct anv_state
){ 0 };
638 *pView
= anv_buffer_view_to_handle(view
);
644 anv_DestroyBufferView(VkDevice _device
, VkBufferView bufferView
,
645 const VkAllocationCallbacks
*pAllocator
)
647 ANV_FROM_HANDLE(anv_device
, device
, _device
);
648 ANV_FROM_HANDLE(anv_buffer_view
, view
, bufferView
);
653 if (view
->surface_state
.alloc_size
> 0)
654 anv_state_pool_free(&device
->surface_state_pool
,
655 view
->surface_state
);
657 if (view
->storage_surface_state
.alloc_size
> 0)
658 anv_state_pool_free(&device
->surface_state_pool
,
659 view
->storage_surface_state
);
661 vk_free2(&device
->alloc
, pAllocator
, view
);
664 const struct anv_surface
*
665 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
666 VkImageAspectFlags aspect_mask
)
668 switch (aspect_mask
) {
669 case VK_IMAGE_ASPECT_COLOR_BIT
:
670 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
671 return &image
->color_surface
;
672 case VK_IMAGE_ASPECT_DEPTH_BIT
:
673 assert(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
);
674 return &image
->depth_surface
;
675 case VK_IMAGE_ASPECT_STENCIL_BIT
:
676 assert(image
->aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
);
677 return &image
->stencil_surface
;
678 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
679 /* FINISHME: The Vulkan spec (git a511ba2) requires support for
680 * combined depth stencil formats. Specifically, it states:
682 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
683 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
685 * Image views with both depth and stencil aspects are only valid for
686 * render target attachments, in which case
687 * cmd_buffer_emit_depth_stencil() will pick out both the depth and
688 * stencil surfaces from the underlying surface.
690 if (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
691 return &image
->depth_surface
;
693 assert(image
->aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
694 return &image
->stencil_surface
;
697 unreachable("image does not have aspect");