From 9e07f38b91d7507d472aac60e678609f7f3d2a34 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Tue, 17 Jun 2025 08:46:28 -0700 Subject: [PATCH] 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 Reviewed-by: Alyssa Rosenzweig Part-of: --- src/freedreno/vulkan/tu_clear_blit.cc | 10 +++++----- src/freedreno/vulkan/tu_formats.h | 12 ------------ src/util/format/u_format.c | 12 ++++++++++++ src/util/format/u_format.h | 4 ++++ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/freedreno/vulkan/tu_clear_blit.cc b/src/freedreno/vulkan/tu_clear_blit.cc index 69e8add846c..e064898443c 100644 --- a/src/freedreno/vulkan/tu_clear_blit.cc +++ b/src/freedreno/vulkan/tu_clear_blit.cc @@ -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; 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; 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; blit_param = R3D_COPY; } diff --git a/src/freedreno/vulkan/tu_formats.h b/src/freedreno/vulkan/tu_formats.h index f9d763fd29a..81892b9fac8 100644 --- a/src/freedreno/vulkan/tu_formats.h +++ b/src/freedreno/vulkan/tu_formats.h @@ -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); diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index c427e08e788..fd6c868cd31 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -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 diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index ceb66a5adb3..2f8cd864a95 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -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