From f2f12776248874b2a689cbba8faeb6e4e2144354 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Thu, 9 Jan 2020 15:13:58 +1300 Subject: [PATCH] panfrost: Add negative lod bias support Reviewed-by: Alyssa Rosenzweig --- src/gallium/drivers/panfrost/pan_context.c | 6 +++--- src/panfrost/include/panfrost-job.h | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 647aa704ed3..d65d2863334 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -1801,9 +1801,9 @@ panfrost_create_sampler_state( cso->border_color.f[2], cso->border_color.f[3] }, - .min_lod = FIXED_16(cso->min_lod), - .max_lod = FIXED_16(cso->max_lod), - .lod_bias = FIXED_16(cso->lod_bias), + .min_lod = FIXED_16(cso->min_lod, false), /* clamp at 0 */ + .max_lod = FIXED_16(cso->max_lod, false), + .lod_bias = FIXED_16(cso->lod_bias, true), /* can be negative */ .seamless_cube_map = cso->seamless_cube_map, }; diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 49c55f1f93e..dfc5d83a80d 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -29,6 +29,7 @@ #define __PANFROST_JOB_H__ #include +#include #include enum mali_job_type { @@ -1253,13 +1254,14 @@ struct mali_texture_descriptor { #define DECODE_FIXED_16(x) ((float) (x / 256.0)) -static inline uint16_t -FIXED_16(float x) +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 < 0.0) ? 0.0 : x)); + x = ((x > max_lod) ? max_lod : ((x < min_lod) ? min_lod : x)); return (int) (x * 256.0); } @@ -1267,13 +1269,13 @@ FIXED_16(float x) struct mali_sampler_descriptor { uint16_t filter_mode; - /* Fixed point. Upper 8-bits is before the decimal point, although it - * caps [0-31]. Lower 8-bits is after the decimal point: int(round(x * - * 256)) */ + /* Fixed point, signed. + * Upper 7 bits before the decimal point, although it caps [0-31]. + * Lower 8 bits after the decimal point: int(round(x * 256)) */ - uint16_t lod_bias; - uint16_t min_lod; - uint16_t max_lod; + int16_t lod_bias; + int16_t min_lod; + int16_t max_lod; /* All one word in reality, but packed a bit. Comparisons are flipped * from OpenGL. */ -- 2.30.2