Kristian Høgsberg Kristensen <k...@bitplanet.net> writes:

> This function computes the next power of two, but at least 1024. We can
> do that by bitwise or'ing in 1023 and calling util_next_power_of_two().
>
> We use brw_get_scratch_size() from the compiler so we need it out of
> brw_program.c. We could move it to brw_shader.cpp, but let's make it a
> small inline function instead.
>
> Signed-off-by: Kristian Høgsberg Kristensen <k...@bitplanet.net>
> ---
>  src/mesa/drivers/dri/i965/brw_context.h |  7 ++++++-
>  src/mesa/drivers/dri/i965/brw_program.c | 12 ------------
>  2 files changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
> b/src/mesa/drivers/dri/i965/brw_context.h
> index 1869f28..aa1284d 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.h
> +++ b/src/mesa/drivers/dri/i965/brw_context.h
> @@ -1723,7 +1723,12 @@ void brw_validate_textures( struct brw_context *brw );
>   */
>  void brwInitFragProgFuncs( struct dd_function_table *functions );
>  
> -int brw_get_scratch_size(int size);
> +/* Per-thread scratch space is a power-of-two multiple of 1KB. */
> +static inline int
> +brw_get_scratch_size(int size)
> +{
> +   return util_next_power_of_two(size | 1023);
> +}

This will incorrectly overallocate scratch space if size is already a
power of two greater than 1024.  I suggest you do "MAX2(1024,
util_next_power_of_two(size))" instead which is also trivial enough that
you might want to open-code it in its only use rather than defining a
one-line function for it.

>  void brw_get_scratch_bo(struct brw_context *brw,
>                       drm_intel_bo **scratch_bo, int size);
>  void brw_init_shader_time(struct brw_context *brw);
> diff --git a/src/mesa/drivers/dri/i965/brw_program.c 
> b/src/mesa/drivers/dri/i965/brw_program.c
> index 108eb34..69ecc36 100644
> --- a/src/mesa/drivers/dri/i965/brw_program.c
> +++ b/src/mesa/drivers/dri/i965/brw_program.c
> @@ -242,18 +242,6 @@ brw_add_texrect_params(struct gl_program *prog)
>     }
>  }
>  
> -/* Per-thread scratch space is a power-of-two multiple of 1KB. */
> -int
> -brw_get_scratch_size(int size)
> -{
> -   int i;
> -
> -   for (i = 1024; i < size; i *= 2)
> -      ;
> -
> -   return i;
> -}
> -
>  void
>  brw_get_scratch_bo(struct brw_context *brw,
>                  drm_intel_bo **scratch_bo, int size)
> -- 
> 2.4.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Attachment: signature.asc
Description: PGP signature

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to