[Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
A few inline asserts in anv assume alignments are power of 2, but with formats like R8G8B8 we have odd alignments. v2: round up to power of 2 (Ilia) v3: reuse util_next_power_of_two() from gallium/aux/util/u_math.h (Ilia) Signed-off-by: Lionel LandwerlinCc: Ilia Mirkin Cc: Jason Ekstrand --- src/intel/isl/isl.c | 1 + src/intel/isl/isl_priv.h | 9 + 2 files changed, 10 insertions(+) diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c index 18e95e2..ae7b9af 100644 --- a/src/intel/isl/isl.c +++ b/src/intel/isl/isl.c @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, base_alignment = MAX(base_alignment, fmtl->bpb / 8); } } + base_alignment = isl_round_up_to_power_of_two(base_alignment); } else { assert(phys_slice0_sa.w % fmtl->bw == 0); const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h index 3a7af1a..9867e22 100644 --- a/src/intel/isl/isl_priv.h +++ b/src/intel/isl/isl_priv.h @@ -99,6 +99,15 @@ isl_log2u(uint32_t n) } static inline uint32_t +isl_round_up_to_power_of_two(uint32_t value) +{ + if (value <= 1) + return value; + + return 1 << (32 - __builtin_clz(value - 1)); +} + +static inline uint32_t isl_minify(uint32_t n, uint32_t levels) { if (unlikely(n == 0)) -- 2.9.3 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
You may be interested in the implementation in gallium/aux/util/u_math.h: /** * Returns the smallest power of two >= x */ static inline unsigned util_next_power_of_two(unsigned x) { #if defined(HAVE___BUILTIN_CLZ) if (x <= 1) return 1; return (1 << ((sizeof(unsigned) * 8) - __builtin_clz(x - 1))); #else I believe that ends up in fewer operations. Your call. -ilia On Wed, Aug 24, 2016 at 5:37 AM, Lionel Landwerlinwrote: > A few inline asserts in anv assume alignments are power of 2, but with > formats like R8G8B8 we have odd alignments. > > v2: round up to power of 2 (Ilia) > > Signed-off-by: Lionel Landwerlin > Cc: Ilia Mirkin > Cc: Jason Ekstrand > --- > src/intel/isl/isl.c | 1 + > src/intel/isl/isl_priv.h | 10 ++ > 2 files changed, 11 insertions(+) > > diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c > index 18e95e2..ae7b9af 100644 > --- a/src/intel/isl/isl.c > +++ b/src/intel/isl/isl.c > @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, > base_alignment = MAX(base_alignment, fmtl->bpb / 8); > } >} > + base_alignment = isl_round_up_to_power_of_two(base_alignment); > } else { >assert(phys_slice0_sa.w % fmtl->bw == 0); >const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; > diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h > index 3a7af1a..19b5176 100644 > --- a/src/intel/isl/isl_priv.h > +++ b/src/intel/isl/isl_priv.h > @@ -99,6 +99,16 @@ isl_log2u(uint32_t n) > } > > static inline uint32_t > +isl_round_up_to_power_of_two(uint32_t value) > +{ > + uint32_t r = 1 << isl_log2u(value); > + > + if ((~r & value) != 0) > + return r << 1; > + return r; > +} > + > +static inline uint32_t > isl_minify(uint32_t n, uint32_t levels) > { > if (unlikely(n == 0)) > -- > 2.9.3 > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
A few inline asserts in anv assume alignments are power of 2, but with formats like R8G8B8 we have odd alignments. v2: round up to power of 2 (Ilia) Signed-off-by: Lionel LandwerlinCc: Ilia Mirkin Cc: Jason Ekstrand --- src/intel/isl/isl.c | 1 + src/intel/isl/isl_priv.h | 10 ++ 2 files changed, 11 insertions(+) diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c index 18e95e2..ae7b9af 100644 --- a/src/intel/isl/isl.c +++ b/src/intel/isl/isl.c @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, base_alignment = MAX(base_alignment, fmtl->bpb / 8); } } + base_alignment = isl_round_up_to_power_of_two(base_alignment); } else { assert(phys_slice0_sa.w % fmtl->bw == 0); const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h index 3a7af1a..19b5176 100644 --- a/src/intel/isl/isl_priv.h +++ b/src/intel/isl/isl_priv.h @@ -99,6 +99,16 @@ isl_log2u(uint32_t n) } static inline uint32_t +isl_round_up_to_power_of_two(uint32_t value) +{ + uint32_t r = 1 << isl_log2u(value); + + if ((~r & value) != 0) + return r << 1; + return r; +} + +static inline uint32_t isl_minify(uint32_t n, uint32_t levels) { if (unlikely(n == 0)) -- 2.9.3 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
On Tue, Aug 23, 2016 at 5:41 PM, Ilia Mirkinwrote: > On Fri, Aug 19, 2016 at 7:44 PM, Lionel Landwerlin > wrote: > > A few inline asserts in anv assume alignments are power of 2, but with > > formats like R8G8B8 we have odd alignments. > > > > Signed-off-by: Lionel Landwerlin > > --- > > src/intel/isl/isl.c | 1 + > > src/intel/isl/isl_priv.h | 6 ++ > > 2 files changed, 7 insertions(+) > > > > diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c > > index 18e95e2..dfe0fc1 100644 > > --- a/src/intel/isl/isl.c > > +++ b/src/intel/isl/isl.c > > @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, > > base_alignment = MAX(base_alignment, fmtl->bpb / 8); > > } > >} > > + base_alignment = isl_round_to_power_of_two(base_alignment); > > } else { > >assert(phys_slice0_sa.w % fmtl->bw == 0); > >const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; > > diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h > > index 3a7af1a..cc9991c 100644 > > --- a/src/intel/isl/isl_priv.h > > +++ b/src/intel/isl/isl_priv.h > > @@ -99,6 +99,12 @@ isl_log2u(uint32_t n) > > } > > > > static inline uint32_t > > +isl_round_to_power_of_two(uint32_t value) > > +{ > > + return 1 << isl_log2u(value); > > This will round down. Is that desired? (Don't know, just asking... I > kind of assumed you'd want to round up to the nearest power of two, > but perhaps not.) > You're right! R-B recinded. If you rounded up to a power of two, that would work fine. > > +} > > + > > +static inline uint32_t > > isl_minify(uint32_t n, uint32_t levels) > > { > > if (unlikely(n == 0)) > > -- > > 2.9.3 > > > > ___ > > mesa-dev mailing list > > mesa-dev@lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/mesa-dev > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
On Fri, Aug 19, 2016 at 7:44 PM, Lionel Landwerlinwrote: > A few inline asserts in anv assume alignments are power of 2, but with > formats like R8G8B8 we have odd alignments. > > Signed-off-by: Lionel Landwerlin > --- > src/intel/isl/isl.c | 1 + > src/intel/isl/isl_priv.h | 6 ++ > 2 files changed, 7 insertions(+) > > diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c > index 18e95e2..dfe0fc1 100644 > --- a/src/intel/isl/isl.c > +++ b/src/intel/isl/isl.c > @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, > base_alignment = MAX(base_alignment, fmtl->bpb / 8); > } >} > + base_alignment = isl_round_to_power_of_two(base_alignment); > } else { >assert(phys_slice0_sa.w % fmtl->bw == 0); >const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; > diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h > index 3a7af1a..cc9991c 100644 > --- a/src/intel/isl/isl_priv.h > +++ b/src/intel/isl/isl_priv.h > @@ -99,6 +99,12 @@ isl_log2u(uint32_t n) > } > > static inline uint32_t > +isl_round_to_power_of_two(uint32_t value) > +{ > + return 1 << isl_log2u(value); This will round down. Is that desired? (Don't know, just asking... I kind of assumed you'd want to round up to the nearest power of two, but perhaps not.) > +} > + > +static inline uint32_t > isl_minify(uint32_t n, uint32_t levels) > { > if (unlikely(n == 0)) > -- > 2.9.3 > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
This seems perfectly reasonable. I don't think rounding up to a power of two can hurt. Reviewed-by: Jason EkstrandOn Mon, Aug 22, 2016 at 10:46 AM, Lionel Landwerlin < lionel.g.landwer...@intel.com> wrote: > The one I actually wanted to Cc you on :) > > > On 20/08/16 00:44, Lionel Landwerlin wrote: > >> A few inline asserts in anv assume alignments are power of 2, but with >> formats like R8G8B8 we have odd alignments. >> >> Signed-off-by: Lionel Landwerlin >> --- >> src/intel/isl/isl.c | 1 + >> src/intel/isl/isl_priv.h | 6 ++ >> 2 files changed, 7 insertions(+) >> >> diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c >> index 18e95e2..dfe0fc1 100644 >> --- a/src/intel/isl/isl.c >> +++ b/src/intel/isl/isl.c >> @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, >> base_alignment = MAX(base_alignment, fmtl->bpb / 8); >>} >> } >> + base_alignment = isl_round_to_power_of_two(base_alignment); >> } else { >> assert(phys_slice0_sa.w % fmtl->bw == 0); >> const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; >> diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h >> index 3a7af1a..cc9991c 100644 >> --- a/src/intel/isl/isl_priv.h >> +++ b/src/intel/isl/isl_priv.h >> @@ -99,6 +99,12 @@ isl_log2u(uint32_t n) >> } >> static inline uint32_t >> +isl_round_to_power_of_two(uint32_t value) >> +{ >> + return 1 << isl_log2u(value); >> +} >> + >> +static inline uint32_t >> isl_minify(uint32_t n, uint32_t levels) >> { >> if (unlikely(n == 0)) >> > > > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
The one I actually wanted to Cc you on :) On 20/08/16 00:44, Lionel Landwerlin wrote: A few inline asserts in anv assume alignments are power of 2, but with formats like R8G8B8 we have odd alignments. Signed-off-by: Lionel Landwerlin--- src/intel/isl/isl.c | 1 + src/intel/isl/isl_priv.h | 6 ++ 2 files changed, 7 insertions(+) diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c index 18e95e2..dfe0fc1 100644 --- a/src/intel/isl/isl.c +++ b/src/intel/isl/isl.c @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, base_alignment = MAX(base_alignment, fmtl->bpb / 8); } } + base_alignment = isl_round_to_power_of_two(base_alignment); } else { assert(phys_slice0_sa.w % fmtl->bw == 0); const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h index 3a7af1a..cc9991c 100644 --- a/src/intel/isl/isl_priv.h +++ b/src/intel/isl/isl_priv.h @@ -99,6 +99,12 @@ isl_log2u(uint32_t n) } static inline uint32_t +isl_round_to_power_of_two(uint32_t value) +{ + return 1 << isl_log2u(value); +} + +static inline uint32_t isl_minify(uint32_t n, uint32_t levels) { if (unlikely(n == 0)) ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] isl: round format alignment to nearest power of 2
A few inline asserts in anv assume alignments are power of 2, but with formats like R8G8B8 we have odd alignments. Signed-off-by: Lionel Landwerlin--- src/intel/isl/isl.c | 1 + src/intel/isl/isl_priv.h | 6 ++ 2 files changed, 7 insertions(+) diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c index 18e95e2..dfe0fc1 100644 --- a/src/intel/isl/isl.c +++ b/src/intel/isl/isl.c @@ -1182,6 +1182,7 @@ isl_surf_init_s(const struct isl_device *dev, base_alignment = MAX(base_alignment, fmtl->bpb / 8); } } + base_alignment = isl_round_to_power_of_two(base_alignment); } else { assert(phys_slice0_sa.w % fmtl->bw == 0); const uint32_t total_w_el = phys_slice0_sa.width / fmtl->bw; diff --git a/src/intel/isl/isl_priv.h b/src/intel/isl/isl_priv.h index 3a7af1a..cc9991c 100644 --- a/src/intel/isl/isl_priv.h +++ b/src/intel/isl/isl_priv.h @@ -99,6 +99,12 @@ isl_log2u(uint32_t n) } static inline uint32_t +isl_round_to_power_of_two(uint32_t value) +{ + return 1 << isl_log2u(value); +} + +static inline uint32_t isl_minify(uint32_t n, uint32_t levels) { if (unlikely(n == 0)) -- 2.9.3 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev