[Mesa-dev] [PATCH 5/8] st/mesa: start adding support for hw atomics atom.

Marek Olšák maraeo at gmail.com
Tue Nov 7 15:49:15 UTC 2017


On Tue, Nov 7, 2017 at 7:31 AM, Dave Airlie <airlied at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> This adds a new atom that calls the new driver API to
> bind buffers containing hw atomics.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/mesa/state_tracker/st_atom_atomicbuf.c   | 37 ++++++++++++++++++++++++++++
>  src/mesa/state_tracker/st_atom_list.h        |  2 ++
>  src/mesa/state_tracker/st_cb_bufferobjects.c |  2 +-
>  src/mesa/state_tracker/st_context.c          |  9 ++++++-
>  src/mesa/state_tracker/st_context.h          |  1 +
>  5 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_atomicbuf.c b/src/mesa/state_tracker/st_atom_atomicbuf.c
> index ee5944f..9c518a0 100644
> --- a/src/mesa/state_tracker/st_atom_atomicbuf.c
> +++ b/src/mesa/state_tracker/st_atom_atomicbuf.c
> @@ -128,3 +128,40 @@ st_bind_cs_atomics(struct st_context *st)
>
>     st_bind_atomics(st, prog, PIPE_SHADER_COMPUTE);
>  }
> +
> +void
> +st_bind_hw_atomic_buffers(struct st_context *st)
> +{
> +   struct pipe_shader_buffer buffers[PIPE_MAX_HW_ATOMIC_BUFFERS];
> +   int i;
> +   int num_buffers = 0;
> +
> +   if (!st->has_hw_atomics)
> +      return;
> +
> +   for (i = 0; i < MAX_COMBINED_ATOMIC_BUFFERS; i++) {
> +      struct gl_buffer_binding *binding = &st->ctx->AtomicBufferBindings[i];
> +      struct st_buffer_object *st_obj = st_buffer_object(binding->BufferObject);
> +      struct pipe_shader_buffer *sb = &buffers[num_buffers];
> +
> +      if (st_obj && st_obj->buffer) {
> +        sb->buffer = st_obj->buffer;
> +        sb->buffer_offset = binding->Offset;
> +        sb->buffer_size = st_obj->buffer->width0 - binding->Offset;
> +
> +        /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
> +         * Take the minimum just to be sure.
> +         */
> +        if (!binding->AutomaticSize)
> +          sb->buffer_size = MIN2(sb->buffer_size, (unsigned) binding->Size);
> +        num_buffers++;

What if a shader uses slots 0 and 2? This will bind slot 2 to slot 1,
which might be problematic. Also, it should be possible to bind NULL
to slot 0, only leaving slot 2 enabled.

> +      } else {
> +        sb->buffer = NULL;
> +        sb->buffer_offset = 0;
> +        sb->buffer_size = 0;
> +      }
> +   }
> +
> +   st->pipe->set_hw_atomic_buffers(st->pipe, 0, num_buffers,
> +                                   buffers);
> +}
> diff --git a/src/mesa/state_tracker/st_atom_list.h b/src/mesa/state_tracker/st_atom_list.h
> index b76854e..8f50a72 100644
> --- a/src/mesa/state_tracker/st_atom_list.h
> +++ b/src/mesa/state_tracker/st_atom_list.h
> @@ -66,6 +66,8 @@ ST_STATE(ST_NEW_GS_SSBOS, st_bind_gs_ssbos)
>  ST_STATE(ST_NEW_PIXEL_TRANSFER, st_update_pixel_transfer)
>  ST_STATE(ST_NEW_TESS_STATE, st_update_tess)
>
> +ST_STATE(ST_NEW_HW_ATOMICS, st_bind_hw_atomic_buffers)
> +
>  /* this must be done after the vertex program update */
>  ST_STATE(ST_NEW_VERTEX_ARRAYS, st_update_array)
>
> diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
> index 86ebfc6..03fae95 100644
> --- a/src/mesa/state_tracker/st_cb_bufferobjects.c
> +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
> @@ -348,7 +348,7 @@ bufferobj_data(struct gl_context *ctx,
>     if (st_obj->Base.UsageHistory & USAGE_TEXTURE_BUFFER)
>        ctx->NewDriverState |= ST_NEW_SAMPLER_VIEWS | ST_NEW_IMAGE_UNITS;
>     if (st_obj->Base.UsageHistory & USAGE_ATOMIC_COUNTER_BUFFER)
> -      ctx->NewDriverState |= ST_NEW_ATOMIC_BUFFER;
> +      ctx->NewDriverState |= st->has_hw_atomics ? ST_NEW_HW_ATOMICS : ST_NEW_ATOMIC_BUFFER;

You can use NewAtomicBuffer here.

Marek


More information about the mesa-dev mailing list