util+tu: Add util_format_is_float16()

Extract out a helper to check for f16 formats from turnip so it can be
used elsewhere.

Signed-off-by: Rob Clark <rob.clark@oss.qualcomm.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35589>
This commit is contained in:
Rob Clark 2025-06-17 08:46:28 -07:00 committed by Marge Bot
parent 0273f1f504
commit 9e07f38b91
4 changed files with 21 additions and 17 deletions

View file

@ -1600,7 +1600,7 @@ r3d_setup(struct tu_cmd_buffer *cmd,
enum r3d_type type;
if (clear) {
type = R3D_CLEAR;
} else if ((blit_param & R3D_COPY) && tu_pipe_format_is_float16(src_format)) {
} else if ((blit_param & R3D_COPY) && util_format_is_float16(src_format)) {
/* Avoid canonicalizing NaNs in copies by using the special half-float
* path that uses half regs.
*/
@ -2446,7 +2446,7 @@ tu_copy_buffer_to_image(struct tu_cmd_buffer *cmd,
bool has_unaligned = CHIP >= A7XX; /* If unaligned buffer copies are supported. */
unsigned blit_param = 0;
if (src_format == PIPE_FORMAT_Y8_UNORM ||
tu_pipe_format_is_float16(src_format)) {
util_format_is_float16(src_format)) {
ops = &r3d_ops<CHIP>;
blit_param = R3D_COPY;
has_unaligned = false;
@ -2643,7 +2643,7 @@ tu_copy_image_to_buffer(struct tu_cmd_buffer *cmd,
/* note: could use "R8_UNORM" when no UBWC */
unsigned blit_param = 0;
if (dst_format == PIPE_FORMAT_Y8_UNORM ||
tu_pipe_format_is_float16(src_format)) {
util_format_is_float16(src_format)) {
ops = &r3d_ops<CHIP>;
blit_param = R3D_COPY;
}
@ -2873,8 +2873,8 @@ tu_copy_image_to_image(struct tu_cmd_buffer *cmd,
unsigned blit_param = 0;
if (dst_format == PIPE_FORMAT_Y8_UNORM ||
src_format == PIPE_FORMAT_Y8_UNORM ||
tu_pipe_format_is_float16(src_format) ||
tu_pipe_format_is_float16(dst_format)) {
util_format_is_float16(src_format) ||
util_format_is_float16(dst_format)) {
ops = &r3d_ops<CHIP>;
blit_param = R3D_COPY;
}

View file

@ -18,18 +18,6 @@ struct tu_native_format
enum a3xx_color_swap swap : 8;
};
static inline bool
tu_pipe_format_is_float16(enum pipe_format format)
{
const struct util_format_description *desc =
util_format_description(format);
const int c = util_format_get_first_non_void_channel(format);
if (c < 0)
return false;
return desc->channel[c].type == UTIL_FORMAT_TYPE_FLOAT && desc->channel[c].size == 16;
}
struct tu_native_format tu6_format_vtx(enum pipe_format format);
struct tu_native_format tu6_format_color(enum pipe_format format, enum a6xx_tile_mode tile_mode,
bool is_mutable);

View file

@ -365,6 +365,18 @@ util_format_is_subsampled_422(enum pipe_format format)
desc->block.bits == 32;
}
bool
util_format_is_float16(enum pipe_format format)
{
const struct util_format_description *desc =
util_format_description(format);
const int c = util_format_get_first_non_void_channel(format);
if (c < 0)
return false;
return desc->channel[c].type == UTIL_FORMAT_TYPE_FLOAT && desc->channel[c].size == 16;
}
/**
* Calculates the MRD for the depth format. MRD is used in depth bias
* for UNORM and unbound depth buffers. When the depth buffer is floating

View file

@ -822,6 +822,10 @@ util_format_is_snorm8(enum pipe_format format) ATTRIBUTE_CONST;
bool
util_format_is_scaled(enum pipe_format format) ATTRIBUTE_CONST;
bool
util_format_is_float16(enum pipe_format format) ATTRIBUTE_CONST;
/**
* Check if the src format can be blitted to the destination format with
* a simple memcpy. For example, blitting from RGBA to RGBx is OK, but not