[Mesa-dev] [PATCH] mesa/state_tracker: Added atomic buffer counter bindings to shaders in mesa state tracker
Ilia Mirkin
imirkin at alum.mit.edu
Fri Oct 24 22:49:39 PDT 2014
Aditya,
If you're interested, this is my attempt at making atomic counters
work in mesa/st: https://github.com/imirkin/mesa/commits/atomic
There are still some questions in my mind about how the load/store
instructions should work exactly, but I haven't brought them up
on-list yet. I've had a lot of trouble getting the nvc0 code to work,
I think I was missing a shader header bit, which I found, but have
since lost again :)
-ilia
On Sat, Oct 25, 2014 at 12:27 AM, adityaatluri <adityaavinash1 at gmail.com> wrote:
> ---
> src/mesa/main/mtypes.h | 34 +++++++++++
> src/mesa/state_tracker/st_atom.c | 3 +
> src/mesa/state_tracker/st_atom.h | 3 +
> src/mesa/state_tracker/st_atom_constbuf.c | 96 +++++++++++++++++++++++++++++++
> 4 files changed, 136 insertions(+)
>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index e1f1f1d..5ac844b 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -2572,6 +2572,9 @@ struct gl_shader
> struct gl_uniform_block *UniformBlocks;
> unsigned NumUniformBlocks;
>
> + struct gl_atomic_block *AtomicBlocks;
> + unsigned NumAtomicBlocks;
> +
> struct exec_list *ir;
> struct glsl_symbol_table *symbols;
>
> @@ -2709,6 +2712,37 @@ struct gl_uniform_block
> enum gl_uniform_block_packing _Packing;
> };
>
> +struct gl_atomic_buffer_variable
> +{
> + char *Name;
> +
> + char *IndexName;
> +
> + const struct glsl_type *Type;
> + unsigned int Offset;
> + GLboolean RowMajor;
> +};
> +
> +enum gl_atomic_block_packing
> +{
> + abc_packing_std140,
> + abc_packing_shared,
> + abc_packing_packed
> +};
> +
> +struct gl_atomic_block{
> + char *Name;
> +
> + struct gl_atomic_buffer_variable *Atomic;
> + GLuint NumAtomics;
> +
> + GLuint Binding;
> +
> + GLuint AtomicBufferSize;
> +
> + enum gl_atomic_block_packing _Packing;
> +};
> +
> /**
> * Structure that represents a reference to an atomic buffer from some
> * shader program.
> diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
> index 625ea29..e7d0060 100644
> --- a/src/mesa/state_tracker/st_atom.c
> +++ b/src/mesa/state_tracker/st_atom.c
> @@ -68,6 +68,9 @@ static const struct st_tracked_state *atoms[] =
> &st_bind_vs_ubos,
> &st_bind_fs_ubos,
> &st_bind_gs_ubos,
> + &st_bind_vs_abcs,
> + &st_bind_fs_abcs,
> + &st_bind_gs_abcs,
> &st_update_pixel_transfer,
>
> /* this must be done after the vertex program update */
> diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
> index c50111d..69f82b9 100644
> --- a/src/mesa/state_tracker/st_atom.h
> +++ b/src/mesa/state_tracker/st_atom.h
> @@ -71,6 +71,9 @@ extern const struct st_tracked_state st_update_vs_constants;
> extern const struct st_tracked_state st_bind_fs_ubos;
> extern const struct st_tracked_state st_bind_vs_ubos;
> extern const struct st_tracked_state st_bind_gs_ubos;
> +extern const struct st_tracked_state st_bind_fs_abcs;
> +extern const struct st_tracked_state st_bind_vs_abcs;
> +extern const struct st_tracked_state st_bind_gs_abcs;
> extern const struct st_tracked_state st_update_pixel_transfer;
>
>
> diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
> index 7984bf7..afd33a1 100644
> --- a/src/mesa/state_tracker/st_atom_constbuf.c
> +++ b/src/mesa/state_tracker/st_atom_constbuf.c
> @@ -275,3 +275,99 @@ const struct st_tracked_state st_bind_gs_ubos = {
> },
> bind_gs_ubos
> };
> +
> +// Binding State with Atomic Buffer Counters
> +
> +static void st_bind_abcs(struct st_context *st,
> + struct gl_shader *shader,
> + unsigned shader_type)
> +{
> + unsigned i;
> + struct pipe_constant_buffer cb = { 0 };
> +
> + if (!shader)
> + return;
> +
> + for (i=0;i < shader->NumAtomicBlocks; i++){
> + struct gl_atomic_buffer_binding *binding;
> + struct st_buffer_object *st_obj;
> +
> + binding = &st->ctx->AtomicBufferBindings[shader->AtomicBlocks[i].Binding];
> + st_obj = st_buffer_object(binding->BufferObject);
> +
> + cb.buffer = st_obj->buffer;
> +
> + if (cb.buffer) {
> + cb.buffer_offset = binding->Offset;
> + cb.buffer_size = cb.buffer->width0 - binding->Offset;
> +
> + if (!binding->AutomaticSize)
> + cb.buffer_size = MIN2(cb.buffer_size, (unsigned) binding->Size);
> + }
> + else{
> + cb.buffer_offset = 0;
> + cb.buffer_size = 0;
> + }
> + cso_set_constant_buffer(st->cso_context, shader_type, 1+i, &cb);
> + }
> +}
> +
> +static void bind_vs_abcs(struct st_context *st)
> +{
> + struct gl_shader_program *prog =
> + st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
> +
> + if (!prog)
> + return;
> +
> + st_bind_abcs(st, prog->_LinkedShaders[MESA_SHADER_VERTEX], PIPE_SHADER_VERTEX);
> +}
> +
> +const struct st_tracked_state st_bind_vs_abcs = {
> + "st_bind_vs_abcs",
> + {
> + 0,
> + ST_NEW_VERTEX_PROGRAM | ST_NEW_ATOMIC_BUFFER,
> + },
> + bind_vs_abcs
> +};
> +
> +static void bind_fs_abcs(struct st_context *st)
> +{
> + struct gl_shader_program *prog =
> + st->ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
> +
> + if (!prog)
> + return;
> +
> + st_bind_abcs(st, prog->_LinkedShaders[MESA_SHADER_FRAGMENT], PIPE_SHADER_FRAGMENT);
> +}
> +
> +const struct st_tracked_state st_bind_fs_abcs = {
> + "st_bind_fs_abcs",
> + {
> + 0,
> + ST_NEW_FRAGMENT_PROGRAM | ST_NEW_ATOMIC_BUFFER;
> + },
> + bind_fs_abcs
> +};
> +
> +static void bind_gs_abcs(struct st_context *st)
> +{
> + struct gl_shader_program *prog =
> + st->ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
> +
> + if (!prog)
> + return;
> +
> + st_bind_abcs(st, prog->_LinkedShaders[MESA_SHADER_GEOMETRY], PIPE_SHADER_GEOMETRY)
> +}
> +
> +const st_tracked_state st_bind_gs_abcs = {
> + "st_bind_gs_abcs",
> + {
> + 0,
> + ST_NEW_GEOMETRY_PROGRAM | ST_NEW_ATOMIC_BUFFER,
> + },
> + bind_gs_abcs
> +};
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list