anv: Rework our aspect/plane helpers
The new versions should have identical output, just a simpler (and probably faster) implementation and more/better asserts. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12141>
This commit is contained in:
parent
0a93c0364c
commit
e37c2d923a
|
@ -2644,23 +2644,8 @@ anv_image_fill_surface_state(struct anv_device *device,
|
||||||
static uint32_t
|
static uint32_t
|
||||||
anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask)
|
anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask)
|
||||||
{
|
{
|
||||||
uint32_t planes = 0;
|
anv_assert_valid_aspect_set(aspect_mask);
|
||||||
|
return util_bitcount(aspect_mask);
|
||||||
if (aspect_mask & (VK_IMAGE_ASPECT_COLOR_BIT |
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT |
|
|
||||||
VK_IMAGE_ASPECT_STENCIL_BIT |
|
|
||||||
VK_IMAGE_ASPECT_PLANE_0_BIT))
|
|
||||||
planes++;
|
|
||||||
if (aspect_mask & VK_IMAGE_ASPECT_PLANE_1_BIT)
|
|
||||||
planes++;
|
|
||||||
if (aspect_mask & VK_IMAGE_ASPECT_PLANE_2_BIT)
|
|
||||||
planes++;
|
|
||||||
|
|
||||||
if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0 &&
|
|
||||||
(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0)
|
|
||||||
planes++;
|
|
||||||
|
|
||||||
return planes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
|
|
|
@ -3780,6 +3780,29 @@ struct anv_format {
|
||||||
bool can_ycbcr;
|
bool can_ycbcr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
anv_assert_valid_aspect_set(VkImageAspectFlags aspects)
|
||||||
|
{
|
||||||
|
if (util_bitcount(aspects) == 1) {
|
||||||
|
assert(aspects & (VK_IMAGE_ASPECT_COLOR_BIT |
|
||||||
|
VK_IMAGE_ASPECT_DEPTH_BIT |
|
||||||
|
VK_IMAGE_ASPECT_STENCIL_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_0_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_1_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_2_BIT));
|
||||||
|
} else if (aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) {
|
||||||
|
assert(aspects == VK_IMAGE_ASPECT_PLANE_0_BIT ||
|
||||||
|
aspects == (VK_IMAGE_ASPECT_PLANE_0_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_1_BIT) ||
|
||||||
|
aspects == (VK_IMAGE_ASPECT_PLANE_0_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_1_BIT |
|
||||||
|
VK_IMAGE_ASPECT_PLANE_2_BIT));
|
||||||
|
} else {
|
||||||
|
assert(aspects == (VK_IMAGE_ASPECT_DEPTH_BIT |
|
||||||
|
VK_IMAGE_ASPECT_STENCIL_BIT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the aspect's plane relative to all_aspects. For an image, for
|
* Return the aspect's plane relative to all_aspects. For an image, for
|
||||||
* instance, all_aspects would be the set of aspects in the image. For
|
* instance, all_aspects would be the set of aspects in the image. For
|
||||||
|
@ -3795,27 +3818,14 @@ static inline uint32_t
|
||||||
anv_image_aspect_to_plane(VkImageAspectFlags all_aspects,
|
anv_image_aspect_to_plane(VkImageAspectFlags all_aspects,
|
||||||
VkImageAspectFlagBits aspect)
|
VkImageAspectFlagBits aspect)
|
||||||
{
|
{
|
||||||
|
anv_assert_valid_aspect_set(all_aspects);
|
||||||
assert(util_bitcount(aspect) == 1);
|
assert(util_bitcount(aspect) == 1);
|
||||||
if (util_bitcount(all_aspects) == 1)
|
assert(!(aspect & ~all_aspects));
|
||||||
return 0;
|
|
||||||
|
|
||||||
switch (aspect) {
|
/* Because we always put image and view planes in aspect-bit-order, the
|
||||||
case VK_IMAGE_ASPECT_COLOR_BIT:
|
* plane index is the number of bits in all_aspects before aspect.
|
||||||
case VK_IMAGE_ASPECT_DEPTH_BIT:
|
*/
|
||||||
case VK_IMAGE_ASPECT_PLANE_0_BIT:
|
return util_bitcount(all_aspects & (aspect - 1));
|
||||||
return 0;
|
|
||||||
case VK_IMAGE_ASPECT_STENCIL_BIT:
|
|
||||||
if ((all_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) == 0)
|
|
||||||
return 0;
|
|
||||||
FALLTHROUGH;
|
|
||||||
case VK_IMAGE_ASPECT_PLANE_1_BIT:
|
|
||||||
return 1;
|
|
||||||
case VK_IMAGE_ASPECT_PLANE_2_BIT:
|
|
||||||
return 2;
|
|
||||||
default:
|
|
||||||
/* Purposefully assert with depth/stencil aspects. */
|
|
||||||
unreachable("invalid image aspect");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define anv_foreach_image_aspect_bit(b, image, aspects) \
|
#define anv_foreach_image_aspect_bit(b, image, aspects) \
|
||||||
|
|
Loading…
Reference in New Issue