From 35985be275f3dd9b3692d40e42dbc936bef28033 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 28 Dec 2022 15:43:48 -0500 Subject: [PATCH] panfrost: Handle fixed-point packing in GenXML Minimum/maximum LOD and LOD bias are unsigned and signed fixed point formats respectively. They are not unsigned integers. Introduce fixed-point types into our GenXML and use them in the XML, rather than packing in sidebands. This makes the XML more correct and fixes pretty-printing of texture and sampler descriptors. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 8 +++---- src/panfrost/include/panfrost-job.h | 17 --------------- src/panfrost/lib/genxml/gen_pack.py | 32 ++++++++++++++++++++++++++-- src/panfrost/lib/genxml/v10.xml | 10 ++++----- src/panfrost/lib/genxml/v4.xml | 6 +++--- src/panfrost/lib/genxml/v5.xml | 6 +++--- src/panfrost/lib/genxml/v6.xml | 10 ++++----- src/panfrost/lib/genxml/v7.xml | 10 ++++----- src/panfrost/lib/genxml/v9.xml | 10 ++++----- src/panfrost/lib/pan_texture.c | 7 +++--- src/panfrost/vulkan/panvk_vX_cs.c | 6 +++--- src/panfrost/vulkan/panvk_vX_image.c | 2 +- 12 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 2f567e9..a35d0a5 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -252,9 +252,9 @@ panfrost_create_sampler_state(struct pipe_context *pctx, cfg.minify_nearest = cso->min_img_filter == PIPE_TEX_FILTER_NEAREST; cfg.normalized_coordinates = !cso->unnormalized_coords; - cfg.lod_bias = FIXED_16(cso->lod_bias, true); - cfg.minimum_lod = FIXED_16(cso->min_lod, false); - cfg.maximum_lod = FIXED_16(cso->max_lod, false); + cfg.lod_bias = cso->lod_bias; + cfg.minimum_lod = cso->min_lod; + cfg.maximum_lod = cso->max_lod; cfg.wrap_mode_s = translate_tex_wrap(cso->wrap_s, using_nearest); cfg.wrap_mode_t = translate_tex_wrap(cso->wrap_t, using_nearest); @@ -278,7 +278,7 @@ panfrost_create_sampler_state(struct pipe_context *pctx, /* Emulate disabled mipmapping by clamping the LOD as tight as * possible (from 0 to epsilon = 1/256) */ if (cso->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) - cfg.maximum_lod = cfg.minimum_lod + 1; + cfg.maximum_lod = cfg.minimum_lod + (1.0 / 256.0); #endif } diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 6138ca7..9ddc577 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -56,21 +56,4 @@ typedef uint64_t mali_ptr; */ #define MAX_MIP_LEVELS (14) -/* Used for lod encoding. Thanks @urjaman for pointing out these routines can - * be cleaned up a lot. */ - -#define DECODE_FIXED_16(x) ((float)(x / 256.0)) - -static inline int16_t -FIXED_16(float x, bool allow_negative) -{ - /* Clamp inputs, accounting for float error */ - float max_lod = (32.0 - (1.0 / 512.0)); - float min_lod = allow_negative ? -max_lod : 0.0; - - x = ((x > max_lod) ? max_lod : ((x < min_lod) ? min_lod : x)); - - return (int)(x * 256.0); -} - #endif /* __PANFROST_JOB_H__ */ diff --git a/src/panfrost/lib/genxml/gen_pack.py b/src/panfrost/lib/genxml/gen_pack.py index 434a228..256d2c1 100644 --- a/src/panfrost/lib/genxml/gen_pack.py +++ b/src/panfrost/lib/genxml/gen_pack.py @@ -88,6 +88,22 @@ __gen_unpack_sint(const uint8_t *restrict cl, uint32_t start, uint32_t end) return util_sign_extend(val, size); } +static inline float +__gen_unpack_ulod(const uint8_t *restrict cl, uint32_t start, uint32_t end) +{ + uint32_t u = __gen_unpack_uint(cl, start, end); + + return ((float)u) / 256.0; +} + +static inline float +__gen_unpack_slod(const uint8_t *restrict cl, uint32_t start, uint32_t end) +{ + int32_t u = __gen_unpack_sint(cl, start, end); + + return ((float)u) / 256.0; +} + static inline uint64_t __gen_unpack_padded(const uint8_t *restrict cl, uint32_t start, uint32_t end) { @@ -325,7 +341,7 @@ class Field(object): type = 'uint64_t' elif self.type == 'bool': type = 'bool' - elif self.type == 'float': + elif self.type in ['float', 'ulod', 'slod']: type = 'float' elif self.type in ['uint', 'hex'] and self.end - self.start > 32: type = 'uint64_t' @@ -500,6 +516,14 @@ class Group(object): elif field.type == "float": assert(start == 0 and end == 31) s = "util_bitpack_float({})".format(value) + elif field.type == "ulod": + s = "util_bitpack_ufixed_clamp({}, {}, {}, 8)".format(value, + start, + end) + elif field.type == "slod": + s = "util_bitpack_sfixed_clamp({}, {}, {}, 8)".format(value, + start, + end) else: s = "#error unhandled field {}, type {}".format(contributor.path, field.type) @@ -568,6 +592,10 @@ class Group(object): convert = "__gen_unpack_uint" elif field.type == "float": convert = "__gen_unpack_float" + elif field.type == "ulod": + convert = "__gen_unpack_ulod" + elif field.type == "slod": + convert = "__gen_unpack_slod" else: s = "/* unhandled field %s, type %s */\n" % (field.name, field.type) @@ -606,7 +634,7 @@ class Group(object): print(' fprintf(fp, "%*s{}: %d\\n", indent, "", {});'.format(name, val)) elif field.type == "bool": print(' fprintf(fp, "%*s{}: %s\\n", indent, "", {} ? "true" : "false");'.format(name, val)) - elif field.type == "float": + elif field.type in ["float", "ulod", "slod"]: print(' fprintf(fp, "%*s{}: %f\\n", indent, "", {});'.format(name, val)) elif field.type in ["uint", "hex"] and (field.end - field.start) >= 32: print(' fprintf(fp, "%*s{}: 0x%" PRIx64 "\\n", indent, "", {});'.format(name, val)) diff --git a/src/panfrost/lib/genxml/v10.xml b/src/panfrost/lib/genxml/v10.xml index b528d39..9aa8119 100644 --- a/src/panfrost/lib/genxml/v10.xml +++ b/src/panfrost/lib/genxml/v10.xml @@ -981,10 +981,10 @@ - + - - + + @@ -1164,9 +1164,9 @@ - + - + diff --git a/src/panfrost/lib/genxml/v4.xml b/src/panfrost/lib/genxml/v4.xml index b72fc3e..aecba87 100644 --- a/src/panfrost/lib/genxml/v4.xml +++ b/src/panfrost/lib/genxml/v4.xml @@ -571,9 +571,9 @@ - - - + + + diff --git a/src/panfrost/lib/genxml/v5.xml b/src/panfrost/lib/genxml/v5.xml index f9fc44e..0b1984e 100644 --- a/src/panfrost/lib/genxml/v5.xml +++ b/src/panfrost/lib/genxml/v5.xml @@ -593,9 +593,9 @@ - - - + + + diff --git a/src/panfrost/lib/genxml/v6.xml b/src/panfrost/lib/genxml/v6.xml index 042f1e6..d7031d1 100644 --- a/src/panfrost/lib/genxml/v6.xml +++ b/src/panfrost/lib/genxml/v6.xml @@ -644,10 +644,10 @@ - + - - + + @@ -668,9 +668,9 @@ - + - + diff --git a/src/panfrost/lib/genxml/v7.xml b/src/panfrost/lib/genxml/v7.xml index 3440ee7..95c6757 100644 --- a/src/panfrost/lib/genxml/v7.xml +++ b/src/panfrost/lib/genxml/v7.xml @@ -700,10 +700,10 @@ - + - - + + @@ -724,9 +724,9 @@ - + - + diff --git a/src/panfrost/lib/genxml/v9.xml b/src/panfrost/lib/genxml/v9.xml index 828ff65..493ec24 100644 --- a/src/panfrost/lib/genxml/v9.xml +++ b/src/panfrost/lib/genxml/v9.xml @@ -635,10 +635,10 @@ - + - - + + @@ -818,9 +818,9 @@ - + - + diff --git a/src/panfrost/lib/pan_texture.c b/src/panfrost/lib/pan_texture.c index 19c52c9..ff3d743 100644 --- a/src/panfrost/lib/pan_texture.c +++ b/src/panfrost/lib/pan_texture.c @@ -633,9 +633,10 @@ GENX(panfrost_new_texture)(const struct panfrost_device *dev, cfg.surfaces = payload->gpu; /* We specify API-level LOD clamps in the sampler descriptor - * and use these clamps simply for bounds checking */ - cfg.minimum_lod = FIXED_16(0, false); - cfg.maximum_lod = FIXED_16(cfg.levels - 1, false); + * and use these clamps simply for bounds checking. + */ + cfg.minimum_lod = 0; + cfg.maximum_lod = cfg.levels - 1; #else cfg.manual_stride = true; #endif diff --git a/src/panfrost/vulkan/panvk_vX_cs.c b/src/panfrost/vulkan/panvk_vX_cs.c index f10feaf..35c28f0 100644 --- a/src/panfrost/vulkan/panvk_vX_cs.c +++ b/src/panfrost/vulkan/panvk_vX_cs.c @@ -249,9 +249,9 @@ panvk_per_arch(emit_sampler)(const VkSamplerCreateInfo *pCreateInfo, cfg.mipmap_mode = panvk_translate_sampler_mipmap_mode(pCreateInfo->mipmapMode); cfg.normalized_coordinates = !pCreateInfo->unnormalizedCoordinates; - cfg.lod_bias = FIXED_16(pCreateInfo->mipLodBias, true); - cfg.minimum_lod = FIXED_16(pCreateInfo->minLod, false); - cfg.maximum_lod = FIXED_16(pCreateInfo->maxLod, false); + cfg.lod_bias = pCreateInfo->mipLodBias; + cfg.minimum_lod = pCreateInfo->minLod; + cfg.maximum_lod = pCreateInfo->maxLod; cfg.wrap_mode_s = panvk_translate_sampler_address_mode(pCreateInfo->addressModeU); cfg.wrap_mode_t = panvk_translate_sampler_address_mode(pCreateInfo->addressModeV); cfg.wrap_mode_r = panvk_translate_sampler_address_mode(pCreateInfo->addressModeW); diff --git a/src/panfrost/vulkan/panvk_vX_image.c b/src/panfrost/vulkan/panvk_vX_image.c index 679aed3..505916a 100644 --- a/src/panfrost/vulkan/panvk_vX_image.c +++ b/src/panfrost/vulkan/panvk_vX_image.c @@ -214,7 +214,7 @@ panvk_per_arch(CreateBufferView)(VkDevice _device, cfg.levels = 1; cfg.array_size = 1; cfg.surfaces = view->bo->ptr.gpu; - cfg.maximum_lod = cfg.minimum_lod = FIXED_16(0, false); + cfg.maximum_lod = cfg.minimum_lod = 0; } } -- 2.7.4