[Mesa-dev] [PATCH 5/9] st/mesa: start adding support for hw atomics atom. (v2)

Marek Olšák maraeo at gmail.com
Thu Nov 9 16:40:32 UTC 2017


On Thu, Nov 9, 2017 at 2:54 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.
>
> v2: fixup bindings for sparse buffers. (mareko/nha)
> don't bind buffer atomics when hw atomics are enabled.
> use NewAtomicBuffer (mareko)
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/mesa/state_tracker/st_atom_atomicbuf.c   | 41 ++++++++++++++++++++++++++--
>  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, 51 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_atomicbuf.c b/src/mesa/state_tracker/st_atom_atomicbuf.c
> index ee5944f..c502ba6 100644
> --- a/src/mesa/state_tracker/st_atom_atomicbuf.c
> +++ b/src/mesa/state_tracker/st_atom_atomicbuf.c
> @@ -46,7 +46,7 @@ st_bind_atomics(struct st_context *st, struct gl_program *prog,
>  {
>     unsigned i;
>
> -   if (!prog || !st->pipe->set_shader_buffers)
> +   if (!prog || !st->pipe->set_shader_buffers || st->has_hw_atomics)
>        return;
>
>     for (i = 0; i < prog->sh.data->NumAtomicBuffers; i++) {
> @@ -63,7 +63,7 @@ st_bind_atomics(struct st_context *st, struct gl_program *prog,
>           sb.buffer_offset = binding->Offset;
>           sb.buffer_size = st_obj->buffer->width0 - binding->Offset;
>
> -        /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
> +         /* AutomaticSize is FALSE if the buffer was set with BindBufferRange.
>            * Take the minimum just to be sure.
>            */
>           if (!binding->AutomaticSize)
> @@ -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 < st->ctx->Const.MaxAtomicBufferBindings; 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);
> +      } else {
> +        sb->buffer = NULL;
> +        sb->buffer_offset = 0;
> +        sb->buffer_size = 0;
> +      }
> +      num_buffers++;
> +   }
> +
> +   st->pipe->set_hw_atomic_buffers(st->pipe, 0, num_buffers,
> +                                   buffers);

num_buffers is always equal to st->ctx->Const.MaxAtomicBufferBindings.
Is that intentional? In any case:

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek


More information about the mesa-dev mailing list