[Mesa-dev] [PATCH 2/3] llvmpipe: add some scene limit sanity check assertions

Roland Scheidegger sroland at vmware.com
Mon Mar 4 14:54:09 PST 2013


Am 04.03.2013 23:04, schrieb Brian Paul:
> Note: This is a candidate for the stable branches.
> ---
>  src/gallium/drivers/llvmpipe/lp_scene.c |   20 ++++++++++++++++++++
>  1 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c
> index fec2f74..8056906 100644
> --- a/src/gallium/drivers/llvmpipe/lp_scene.c
> +++ b/src/gallium/drivers/llvmpipe/lp_scene.c
> @@ -64,6 +64,26 @@ lp_scene_create( struct pipe_context *pipe )
>  
>     pipe_mutex_init(scene->mutex);
>  
> +   /* Do some scene limit sanity checks here */
> +   {
> +      unsigned maxBins = TILES_X * TILES_Y;
> +      unsigned maxCommandBytes = sizeof(struct cmd_block) * maxBins;
> +      unsigned maxCommandPlusData = maxCommandBytes + DATA_BLOCK_SIZE;
> +      /* We'll need at least one command block per bin.  Make sure that's
> +       * less than the max allowed scene size.
> +       */
> +      assert(maxCommandBytes < LP_SCENE_MAX_SIZE);
> +      /* We'll also need space for at least one other data block */
> +      assert(maxCommandPlusData <= LP_SCENE_MAX_SIZE);
> +
> +      /* Ideally, the size of a cmd_block object will be a power of two
> +       * in order to avoid wasting space when we allocation them from
allocation->allocate

> +       * data blocks (which are power of two also).
> +       */
> +      assert(sizeof(struct cmd_block) ==
> +             util_next_power_of_two(sizeof(struct cmd_block)));
> +   }
I guess that's ok though the waste is not THAT big otherwise (especially
not with the smaller blocks now).

I guess doing STATIC_ASSERT with sizeof() wouldn't be portable? (Of
course it wouldn't work for the last assert.)

>     return scene;
>  }
>  
> 

Series looks good to me otherwise though we probably need to improve
that in the future.

Roland


More information about the mesa-dev mailing list