From eb61a607d87d5bf9adddb24a92317873c517e0cb Mon Sep 17 00:00:00 2001 From: sarbes Date: Sat, 24 May 2025 01:57:57 +0200 Subject: [PATCH] lima: add 'unorm8' format to genxml This MR allows packing of (normalized) floats into an 8 bit field. v2: - removed default attribute Reviewed-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/genxml/gen_pack.py | 9 +++++++-- src/gallium/drivers/lima/genxml/lima_pack_header.h | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/lima/genxml/gen_pack.py b/src/gallium/drivers/lima/genxml/gen_pack.py index 992e1ff1c03..9cb502e9416 100644 --- a/src/gallium/drivers/lima/genxml/gen_pack.py +++ b/src/gallium/drivers/lima/genxml/gen_pack.py @@ -138,7 +138,7 @@ class Field(object): type = 'uint64_t' elif self.type == 'bool': type = 'bool' - elif self.type in ['float', 'half', 'unorm16', 'ulod', 'slod']: + elif self.type in ['float', 'half', 'unorm16', 'unorm8', 'ulod', 'slod']: type = 'float' elif self.type in ['uint', 'hex'] and self.end - self.start > 32: type = 'uint64_t' @@ -340,6 +340,9 @@ class Group(object): elif field.type == "unorm16": assert(end - start + 1 == 16) s = "__gen_pack_unorm16(%s, %d, %d)" % (value, start, end) + elif field.type == "unorm8": + assert(end - start + 1 == 8) + s = "__gen_pack_unorm8(%s, %d, %d)" % (value, start, end) elif field.type == "ulod": s = "util_bitpack_ufixed_clamp({}, {}, {}, 4)".format(value, start, @@ -420,6 +423,8 @@ class Group(object): convert = "__gen_unpack_half" elif field.type == "unorm16": convert = "__gen_unpack_unorm16" + elif field.type == "unorm8": + convert = "__gen_unpack_unorm8" elif field.type == "ulod": convert = "__gen_unpack_ulod" elif field.type == "slod": @@ -491,7 +496,7 @@ class Group(object): print(f' fprintf(fp, "%*s{name}: %d\\n", indent, "", {val});') elif field.type == "bool": print(f' fprintf(fp, "%*s{name}: %s\\n", indent, "", {val} ? "true" : "false");') - elif field.type in ["float", "unorm16", "ulod", "slod", "half"]: + elif field.type in ["float", "unorm16", "unorm8", "ulod", "slod", "half"]: print(f' fprintf(fp, "%*s{name}: %f\\n", indent, "", {val});') elif field.type in ["uint", "hex"] and (field.end - field.start) >= 32: print(f' fprintf(fp, "%*s{name}: 0x%" PRIx64 "\\n", indent, "", {val});') diff --git a/src/gallium/drivers/lima/genxml/lima_pack_header.h b/src/gallium/drivers/lima/genxml/lima_pack_header.h index 86ef081f50e..559769b8806 100644 --- a/src/gallium/drivers/lima/genxml/lima_pack_header.h +++ b/src/gallium/drivers/lima/genxml/lima_pack_header.h @@ -48,6 +48,18 @@ __gen_unpack_unorm16(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t e return ushort_to_float(__gen_unpack_uint(cl, start, end)); } +static inline uint64_t +__gen_pack_unorm8(float f, uint32_t start, uint32_t end) +{ + return util_bitpack_uint(float_to_ubyte(f), start, end); +} + +static inline float +__gen_unpack_unorm8(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t end) +{ + return ubyte_to_float(__gen_unpack_uint(cl, start, end)); +} + static inline uint64_t __gen_unpack_sint(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t end) {