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"
33 * The \a format argument is required and overrides any format found in struct
34 * anv_image_create_info. Exactly one bit must be set in \a aspect.
36 static isl_surf_usage_flags_t
37 choose_isl_surf_usage(const struct anv_image_create_info
*info
,
38 VkImageAspectFlags aspect
)
40 const VkImageCreateInfo
*vk_info
= info
->vk_info
;
41 isl_surf_usage_flags_t isl_flags
= 0;
43 /* FINISHME: Support aux surfaces */
44 isl_flags
|= ISL_SURF_USAGE_DISABLE_AUX_BIT
;
46 if (vk_info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
)
47 isl_flags
|= ISL_SURF_USAGE_TEXTURE_BIT
;
49 if (vk_info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)
50 isl_flags
|= ISL_SURF_USAGE_TEXTURE_BIT
;
52 if (vk_info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
)
53 isl_flags
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
55 if (vk_info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)
56 isl_flags
|= ISL_SURF_USAGE_CUBE_BIT
;
58 if (vk_info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
61 unreachable("bad VkImageAspect");
62 case VK_IMAGE_ASPECT_DEPTH_BIT
:
63 isl_flags
|= ISL_SURF_USAGE_DEPTH_BIT
;
65 case VK_IMAGE_ASPECT_STENCIL_BIT
:
66 isl_flags
|= ISL_SURF_USAGE_STENCIL_BIT
;
71 if (vk_info
->usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
72 /* Meta implements transfers by sampling from the source image. */
73 isl_flags
|= ISL_SURF_USAGE_TEXTURE_BIT
;
76 if (vk_info
->usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
77 /* Meta implements transfers by rendering into the destination image. */
78 isl_flags
|= ISL_SURF_USAGE_RENDER_TARGET_BIT
;
85 * Exactly one bit must be set in \a aspect.
87 static struct anv_surface
*
88 get_surface(struct anv_image
*image
, VkImageAspectFlags aspect
)
92 unreachable("bad VkImageAspect");
93 case VK_IMAGE_ASPECT_COLOR_BIT
:
94 return &image
->color_surface
;
95 case VK_IMAGE_ASPECT_DEPTH_BIT
:
96 return &image
->depth_surface
;
97 case VK_IMAGE_ASPECT_STENCIL_BIT
:
98 return &image
->stencil_surface
;
103 * Initialize the anv_image::*_surface selected by \a aspect. Then update the
104 * image's memory requirements (that is, the image's size and alignment).
106 * Exactly one bit must be set in \a aspect.
109 make_surface(const struct anv_device
*dev
,
110 struct anv_image
*image
,
111 const struct anv_image_create_info
*anv_info
,
112 VkImageAspectFlags aspect
)
114 const VkImageCreateInfo
*vk_info
= anv_info
->vk_info
;
117 static const enum isl_surf_dim vk_to_isl_surf_dim
[] = {
118 [VK_IMAGE_TYPE_1D
] = ISL_SURF_DIM_1D
,
119 [VK_IMAGE_TYPE_2D
] = ISL_SURF_DIM_2D
,
120 [VK_IMAGE_TYPE_3D
] = ISL_SURF_DIM_3D
,
123 isl_tiling_flags_t tiling_flags
= anv_info
->isl_tiling_flags
;
124 if (vk_info
->tiling
== VK_IMAGE_TILING_LINEAR
)
125 tiling_flags
&= ISL_TILING_LINEAR_BIT
;
127 struct anv_surface
*anv_surf
= get_surface(image
, aspect
);
129 ok
= isl_surf_init(&dev
->isl_dev
, &anv_surf
->isl
,
130 .dim
= vk_to_isl_surf_dim
[vk_info
->imageType
],
131 .format
= anv_get_isl_format(vk_info
->format
, aspect
, vk_info
->tiling
),
132 .width
= vk_info
->extent
.width
,
133 .height
= vk_info
->extent
.height
,
134 .depth
= vk_info
->extent
.depth
,
135 .levels
= vk_info
->mipLevels
,
136 .array_len
= vk_info
->arrayLayers
,
137 .samples
= vk_info
->samples
,
140 .usage
= choose_isl_surf_usage(anv_info
, aspect
),
141 .tiling_flags
= tiling_flags
);
143 /* isl_surf_init() will fail only if provided invalid input. Invalid input
144 * is illegal in Vulkan.
148 anv_surf
->offset
= align_u32(image
->size
, anv_surf
->isl
.alignment
);
149 image
->size
= anv_surf
->offset
+ anv_surf
->isl
.size
;
150 image
->alignment
= MAX(image
->alignment
, anv_surf
->isl
.alignment
);
155 static VkImageUsageFlags
156 anv_image_get_full_usage(const VkImageCreateInfo
*info
)
158 VkImageUsageFlags usage
= info
->usage
;
160 if (usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
161 /* Meta will transfer from the image by binding it as a texture. */
162 usage
|= VK_IMAGE_USAGE_SAMPLED_BIT
;
165 if (usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
166 /* Meta will transfer to the image by binding it as a color attachment,
167 * even if the image format is not a color format.
169 usage
|= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
176 anv_image_create(VkDevice _device
,
177 const struct anv_image_create_info
*create_info
,
178 const VkAllocationCallbacks
* alloc
,
181 ANV_FROM_HANDLE(anv_device
, device
, _device
);
182 const VkImageCreateInfo
*pCreateInfo
= create_info
->vk_info
;
183 struct anv_image
*image
= NULL
;
186 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
);
188 anv_assert(pCreateInfo
->mipLevels
> 0);
189 anv_assert(pCreateInfo
->arrayLayers
> 0);
190 anv_assert(pCreateInfo
->samples
== VK_SAMPLE_COUNT_1_BIT
);
191 anv_assert(pCreateInfo
->extent
.width
> 0);
192 anv_assert(pCreateInfo
->extent
.height
> 0);
193 anv_assert(pCreateInfo
->extent
.depth
> 0);
195 image
= anv_alloc2(&device
->alloc
, alloc
, sizeof(*image
), 8,
196 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
198 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
200 memset(image
, 0, sizeof(*image
));
201 image
->type
= pCreateInfo
->imageType
;
202 image
->extent
= pCreateInfo
->extent
;
203 image
->vk_format
= pCreateInfo
->format
;
204 image
->format
= anv_format_for_vk_format(pCreateInfo
->format
);
205 image
->levels
= pCreateInfo
->mipLevels
;
206 image
->array_size
= pCreateInfo
->arrayLayers
;
207 image
->samples
= pCreateInfo
->samples
;
208 image
->usage
= anv_image_get_full_usage(pCreateInfo
);
209 image
->tiling
= pCreateInfo
->tiling
;
211 if (image
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
212 image
->needs_nonrt_surface_state
= true;
215 if (image
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
216 image
->needs_color_rt_surface_state
= true;
219 if (image
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
220 image
->needs_storage_surface_state
= true;
223 if (likely(anv_format_is_color(image
->format
))) {
224 r
= make_surface(device
, image
, create_info
,
225 VK_IMAGE_ASPECT_COLOR_BIT
);
229 if (image
->format
->depth_format
) {
230 r
= make_surface(device
, image
, create_info
,
231 VK_IMAGE_ASPECT_DEPTH_BIT
);
236 if (image
->format
->has_stencil
) {
237 r
= make_surface(device
, image
, create_info
,
238 VK_IMAGE_ASPECT_STENCIL_BIT
);
244 *pImage
= anv_image_to_handle(image
);
250 anv_free2(&device
->alloc
, alloc
, image
);
256 anv_CreateImage(VkDevice device
,
257 const VkImageCreateInfo
*pCreateInfo
,
258 const VkAllocationCallbacks
*pAllocator
,
261 return anv_image_create(device
,
262 &(struct anv_image_create_info
) {
263 .vk_info
= pCreateInfo
,
264 .isl_tiling_flags
= ISL_TILING_ANY_MASK
,
271 anv_DestroyImage(VkDevice _device
, VkImage _image
,
272 const VkAllocationCallbacks
*pAllocator
)
274 ANV_FROM_HANDLE(anv_device
, device
, _device
);
276 anv_free2(&device
->alloc
, pAllocator
, anv_image_from_handle(_image
));
280 anv_surface_get_subresource_layout(struct anv_image
*image
,
281 struct anv_surface
*surface
,
282 const VkImageSubresource
*subresource
,
283 VkSubresourceLayout
*layout
)
285 /* If we are on a non-zero mip level or array slice, we need to
286 * calculate a real offset.
288 anv_assert(subresource
->mipLevel
== 0);
289 anv_assert(subresource
->arrayLayer
== 0);
291 layout
->offset
= surface
->offset
;
292 layout
->rowPitch
= surface
->isl
.row_pitch
;
293 layout
->depthPitch
= isl_surf_get_array_pitch(&surface
->isl
);
294 layout
->arrayPitch
= isl_surf_get_array_pitch(&surface
->isl
);
295 layout
->size
= surface
->isl
.size
;
298 void anv_GetImageSubresourceLayout(
301 const VkImageSubresource
* pSubresource
,
302 VkSubresourceLayout
* pLayout
)
304 ANV_FROM_HANDLE(anv_image
, image
, _image
);
306 assert(__builtin_popcount(pSubresource
->aspectMask
) == 1);
308 switch (pSubresource
->aspectMask
) {
309 case VK_IMAGE_ASPECT_COLOR_BIT
:
310 anv_surface_get_subresource_layout(image
, &image
->color_surface
,
311 pSubresource
, pLayout
);
313 case VK_IMAGE_ASPECT_DEPTH_BIT
:
314 anv_surface_get_subresource_layout(image
, &image
->depth_surface
,
315 pSubresource
, pLayout
);
317 case VK_IMAGE_ASPECT_STENCIL_BIT
:
318 anv_surface_get_subresource_layout(image
, &image
->stencil_surface
,
319 pSubresource
, pLayout
);
322 assert(!"Invalid image aspect");
327 anv_validate_CreateImageView(VkDevice _device
,
328 const VkImageViewCreateInfo
*pCreateInfo
,
329 const VkAllocationCallbacks
*pAllocator
,
332 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
333 const VkImageSubresourceRange
*subresource
;
334 const struct anv_format
*view_format_info
;
336 /* Validate structure type before dereferencing it. */
338 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
);
339 subresource
= &pCreateInfo
->subresourceRange
;
341 /* Validate viewType is in range before using it. */
342 assert(pCreateInfo
->viewType
>= VK_IMAGE_VIEW_TYPE_BEGIN_RANGE
);
343 assert(pCreateInfo
->viewType
<= VK_IMAGE_VIEW_TYPE_END_RANGE
);
345 /* Validate format is in range before using it. */
346 assert(pCreateInfo
->format
>= VK_FORMAT_BEGIN_RANGE
);
347 assert(pCreateInfo
->format
<= VK_FORMAT_END_RANGE
);
348 view_format_info
= anv_format_for_vk_format(pCreateInfo
->format
);
350 /* Validate channel swizzles. */
351 assert(pCreateInfo
->components
.r
>= VK_COMPONENT_SWIZZLE_BEGIN_RANGE
);
352 assert(pCreateInfo
->components
.r
<= VK_COMPONENT_SWIZZLE_END_RANGE
);
353 assert(pCreateInfo
->components
.g
>= VK_COMPONENT_SWIZZLE_BEGIN_RANGE
);
354 assert(pCreateInfo
->components
.g
<= VK_COMPONENT_SWIZZLE_END_RANGE
);
355 assert(pCreateInfo
->components
.b
>= VK_COMPONENT_SWIZZLE_BEGIN_RANGE
);
356 assert(pCreateInfo
->components
.b
<= VK_COMPONENT_SWIZZLE_END_RANGE
);
357 assert(pCreateInfo
->components
.a
>= VK_COMPONENT_SWIZZLE_BEGIN_RANGE
);
358 assert(pCreateInfo
->components
.a
<= VK_COMPONENT_SWIZZLE_END_RANGE
);
360 /* Validate subresource. */
361 assert(subresource
->aspectMask
!= 0);
362 assert(subresource
->levelCount
> 0);
363 assert(subresource
->layerCount
> 0);
364 assert(subresource
->baseMipLevel
< image
->levels
);
365 assert(subresource
->baseMipLevel
+ subresource
->levelCount
<= image
->levels
);
366 assert(subresource
->baseArrayLayer
< image
->array_size
);
367 assert(subresource
->baseArrayLayer
+ subresource
->layerCount
<= image
->array_size
);
370 const VkImageAspectFlags ds_flags
= VK_IMAGE_ASPECT_DEPTH_BIT
371 | VK_IMAGE_ASPECT_STENCIL_BIT
;
373 /* Validate format. */
374 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
375 assert(subresource
->aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
376 assert(!image
->format
->depth_format
);
377 assert(!image
->format
->has_stencil
);
378 assert(!view_format_info
->depth_format
);
379 assert(!view_format_info
->has_stencil
);
380 assert(view_format_info
->isl_layout
->bs
==
381 image
->format
->isl_layout
->bs
);
382 } else if (subresource
->aspectMask
& ds_flags
) {
383 assert((subresource
->aspectMask
& ~ds_flags
) == 0);
385 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
386 assert(image
->format
->depth_format
);
387 assert(view_format_info
->depth_format
);
388 assert(view_format_info
->isl_layout
->bs
==
389 image
->format
->isl_layout
->bs
);
392 if (subresource
->aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
393 /* FINISHME: Is it legal to have an R8 view of S8? */
394 assert(image
->format
->has_stencil
);
395 assert(view_format_info
->has_stencil
);
398 assert(!"bad VkImageSubresourceRange::aspectFlags");
401 return anv_CreateImageView(_device
, pCreateInfo
, pAllocator
, pView
);
405 anv_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
406 struct anv_image_view
*iview
,
407 const VkImageViewCreateInfo
*pCreateInfo
,
408 VkImageUsageFlagBits usage
)
410 switch (device
->info
.gen
) {
412 if (device
->info
.is_haswell
)
413 gen75_fill_image_surface_state(device
, state_map
, iview
,
416 gen7_fill_image_surface_state(device
, state_map
, iview
,
420 gen8_fill_image_surface_state(device
, state_map
, iview
,
424 gen9_fill_image_surface_state(device
, state_map
, iview
,
428 unreachable("unsupported gen\n");
431 if (!device
->info
.has_llc
)
432 anv_state_clflush(iview
->nonrt_surface_state
);
435 static struct anv_state
436 alloc_surface_state(struct anv_device
*device
,
437 struct anv_cmd_buffer
*cmd_buffer
)
440 return anv_cmd_buffer_alloc_surface_state(cmd_buffer
);
442 return anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
447 anv_image_view_init(struct anv_image_view
*iview
,
448 struct anv_device
*device
,
449 const VkImageViewCreateInfo
* pCreateInfo
,
450 struct anv_cmd_buffer
*cmd_buffer
)
452 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
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
+ range
->layerCount
- 1 <= image
->array_size
);
469 case VK_IMAGE_TYPE_3D
:
470 assert(range
->baseArrayLayer
+ range
->layerCount
- 1
471 <= anv_minify(image
->extent
.depth
, range
->baseMipLevel
));
475 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
;
484 iview
->format
= anv_get_isl_format(pCreateInfo
->format
, iview
->aspect_mask
,
487 iview
->extent
= (VkExtent3D
) {
488 .width
= anv_minify(image
->extent
.width
, range
->baseMipLevel
),
489 .height
= anv_minify(image
->extent
.height
, range
->baseMipLevel
),
490 .depth
= anv_minify(image
->extent
.depth
, range
->baseMipLevel
),
493 if (image
->needs_nonrt_surface_state
) {
494 iview
->nonrt_surface_state
= alloc_surface_state(device
, cmd_buffer
);
496 anv_fill_image_surface_state(device
, iview
->nonrt_surface_state
.map
,
498 VK_IMAGE_USAGE_SAMPLED_BIT
);
500 iview
->nonrt_surface_state
.alloc_size
= 0;
503 if (image
->needs_color_rt_surface_state
) {
504 iview
->color_rt_surface_state
= alloc_surface_state(device
, cmd_buffer
);
506 anv_fill_image_surface_state(device
, iview
->color_rt_surface_state
.map
,
508 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
);
510 iview
->color_rt_surface_state
.alloc_size
= 0;
513 if (image
->needs_storage_surface_state
) {
514 iview
->storage_surface_state
= alloc_surface_state(device
, cmd_buffer
);
516 anv_fill_image_surface_state(device
, iview
->storage_surface_state
.map
,
518 VK_IMAGE_USAGE_STORAGE_BIT
);
520 iview
->storage_surface_state
.alloc_size
= 0;
525 anv_CreateImageView(VkDevice _device
,
526 const VkImageViewCreateInfo
*pCreateInfo
,
527 const VkAllocationCallbacks
*pAllocator
,
530 ANV_FROM_HANDLE(anv_device
, device
, _device
);
531 struct anv_image_view
*view
;
533 view
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*view
), 8,
534 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
536 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
538 anv_image_view_init(view
, device
, pCreateInfo
, NULL
);
540 *pView
= anv_image_view_to_handle(view
);
546 anv_DestroyImageView(VkDevice _device
, VkImageView _iview
,
547 const VkAllocationCallbacks
*pAllocator
)
549 ANV_FROM_HANDLE(anv_device
, device
, _device
);
550 ANV_FROM_HANDLE(anv_image_view
, iview
, _iview
);
552 if (iview
->image
->needs_color_rt_surface_state
) {
553 anv_state_pool_free(&device
->surface_state_pool
,
554 iview
->color_rt_surface_state
);
557 if (iview
->image
->needs_nonrt_surface_state
) {
558 anv_state_pool_free(&device
->surface_state_pool
,
559 iview
->nonrt_surface_state
);
562 if (iview
->image
->needs_storage_surface_state
) {
563 anv_state_pool_free(&device
->surface_state_pool
,
564 iview
->storage_surface_state
);
567 anv_free2(&device
->alloc
, pAllocator
, iview
);
571 anv_CreateBufferView(VkDevice _device
,
572 const VkBufferViewCreateInfo
*pCreateInfo
,
573 const VkAllocationCallbacks
*pAllocator
,
576 ANV_FROM_HANDLE(anv_device
, device
, _device
);
577 ANV_FROM_HANDLE(anv_buffer
, buffer
, pCreateInfo
->buffer
);
578 struct anv_buffer_view
*view
;
580 view
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*view
), 8,
581 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
583 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
585 const struct anv_format
*format
=
586 anv_format_for_vk_format(pCreateInfo
->format
);
588 view
->format
= format
->surface_format
;
589 view
->bo
= buffer
->bo
;
590 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
591 view
->range
= pCreateInfo
->range
== VK_WHOLE_SIZE
?
592 buffer
->size
- view
->offset
: pCreateInfo
->range
;
594 if (buffer
->usage
& VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
) {
595 view
->surface_state
=
596 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
598 anv_fill_buffer_surface_state(device
, view
->surface_state
.map
,
600 view
->offset
, view
->range
,
601 format
->isl_layout
->bs
);
603 view
->surface_state
= (struct anv_state
){ 0 };
606 if (buffer
->usage
& VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
) {
607 view
->storage_surface_state
=
608 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
610 enum isl_format storage_format
=
611 isl_lower_storage_image_format(&device
->isl_dev
, view
->format
);
613 anv_fill_buffer_surface_state(device
, view
->storage_surface_state
.map
,
615 view
->offset
, view
->range
,
616 format
->isl_layout
->bs
);
618 view
->storage_surface_state
= (struct anv_state
){ 0 };
621 *pView
= anv_buffer_view_to_handle(view
);
627 anv_DestroyBufferView(VkDevice _device
, VkBufferView bufferView
,
628 const VkAllocationCallbacks
*pAllocator
)
630 ANV_FROM_HANDLE(anv_device
, device
, _device
);
631 ANV_FROM_HANDLE(anv_buffer_view
, view
, bufferView
);
633 if (view
->surface_state
.alloc_size
> 0)
634 anv_state_pool_free(&device
->surface_state_pool
,
635 view
->surface_state
);
637 if (view
->storage_surface_state
.alloc_size
> 0)
638 anv_state_pool_free(&device
->surface_state_pool
,
639 view
->storage_surface_state
);
641 anv_free2(&device
->alloc
, pAllocator
, view
);
645 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
, VkImageAspectFlags aspect_mask
)
647 switch (aspect_mask
) {
648 case VK_IMAGE_ASPECT_COLOR_BIT
:
649 /* Dragons will eat you.
651 * Meta attaches all destination surfaces as color render targets. Guess
652 * what surface the Meta Dragons really want.
654 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
655 anv_finishme("combined depth stencil formats");
656 return &image
->depth_surface
;
657 } else if (image
->format
->depth_format
) {
658 return &image
->depth_surface
;
659 } else if (image
->format
->has_stencil
) {
660 return &image
->stencil_surface
;
662 return &image
->color_surface
;
665 case VK_IMAGE_ASPECT_DEPTH_BIT
:
666 assert(image
->format
->depth_format
);
667 return &image
->depth_surface
;
668 case VK_IMAGE_ASPECT_STENCIL_BIT
:
669 assert(image
->format
->has_stencil
);
670 return &image
->stencil_surface
;
671 case VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
:
672 if (image
->format
->depth_format
&& image
->format
->has_stencil
) {
673 /* FINISHME: The Vulkan spec (git a511ba2) requires support for combined
674 * depth stencil formats. Specifically, it states:
676 * At least one of ename:VK_FORMAT_D24_UNORM_S8_UINT or
677 * ename:VK_FORMAT_D32_SFLOAT_S8_UINT must be supported.
679 anv_finishme("combined depthstencil aspect");
680 return &image
->depth_surface
;
681 } else if (image
->format
->depth_format
) {
682 return &image
->depth_surface
;
683 } else if (image
->format
->has_stencil
) {
684 return &image
->stencil_surface
;
688 unreachable("image does not have aspect");
694 anv_image_view_fill_image_param(struct anv_device
*device
,
695 struct anv_image_view
*view
,
696 struct brw_image_param
*param
)
698 memset(param
, 0, sizeof *param
);
699 anv_finishme("Actually fill out brw_image_param");
703 anv_buffer_view_fill_image_param(struct anv_device
*device
,
704 struct anv_buffer_view
*view
,
705 struct brw_image_param
*param
)
707 /* Set the swizzling shifts to all-ones to effectively disable swizzling --
708 * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
709 * detailed explanation of these parameters.
711 param
->swizzling
[0] = 0xff;
712 param
->swizzling
[1] = 0xff;
714 param
->stride
[0] = isl_format_layouts
[view
->format
].bs
;
715 param
->size
[0] = view
->range
/ param
->stride
[0];