[Mesa-dev] [PATCH] st/nir: fix atomic lowering for gallium drivers
Marek Olšák
maraeo at gmail.com
Tue Mar 20 00:45:40 UTC 2018
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Marek
On Mon, Mar 19, 2018 at 8:32 AM, Timothy Arceri <tarceri at itsqueeze.com>
wrote:
> i965 and gallium handle the atomic buffer index differently. It was
> just by luck that the single piglit test for this was passing.
>
> For gallium we use the atomic binding so that we match the handling
> in st_bind_atomics().
>
> On radeonsi this fixes the CTS test:
> KHR-GL43.shader_storage_buffer_object.advanced-write-fragment
>
> It also fixes tressfx hair rendering in Tomb Raider.
> ---
> src/compiler/nir/nir.h | 3 ++-
> src/compiler/nir/nir_lower_atomics.c | 15 ++++++++++-----
> src/mesa/drivers/dri/i965/brw_link.cpp | 2 +-
> src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +-
> 4 files changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index e7a8afcad1..06f8a1076f 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2716,7 +2716,8 @@ typedef struct nir_lower_bitmap_options {
> void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options
> *options);
>
> bool nir_lower_atomics(nir_shader *shader,
> - const struct gl_shader_program *shader_program);
> + const struct gl_shader_program *shader_program,
> + bool use_binding_as_idx);
> bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned ssbo_offset);
> bool nir_lower_to_source_mods(nir_shader *shader);
>
> diff --git a/src/compiler/nir/nir_lower_atomics.c
> b/src/compiler/nir/nir_lower_atomics.c
> index bdab4b8737..6b046bc426 100644
> --- a/src/compiler/nir/nir_lower_atomics.c
> +++ b/src/compiler/nir/nir_lower_atomics.c
> @@ -38,7 +38,7 @@
> static bool
> lower_instr(nir_intrinsic_instr *instr,
> const struct gl_shader_program *shader_program,
> - nir_shader *shader)
> + nir_shader *shader, bool use_binding_as_idx)
> {
> nir_intrinsic_op op;
> switch (instr->intrinsic) {
> @@ -98,9 +98,12 @@ lower_instr(nir_intrinsic_instr *instr,
> void *mem_ctx = ralloc_parent(instr);
> unsigned uniform_loc = instr->variables[0]->var->data.location;
>
> + unsigned idx = use_binding_as_idx ?
> + instr->variables[0]->var->data.binding :
> + shader_program->data->UniformStorage[uniform_loc].
> opaque[shader->info.stage].index;
> +
> nir_intrinsic_instr *new_instr = nir_intrinsic_instr_create(mem_ctx,
> op);
> - nir_intrinsic_set_base(new_instr,
> - shader_program->data->UniformStorage[uniform_loc].
> opaque[shader->info.stage].index);
> + nir_intrinsic_set_base(new_instr, idx);
>
> nir_load_const_instr *offset_const =
> nir_load_const_instr_create(mem_ctx, 1, 32);
> @@ -174,7 +177,8 @@ lower_instr(nir_intrinsic_instr *instr,
>
> bool
> nir_lower_atomics(nir_shader *shader,
> - const struct gl_shader_program *shader_program)
> + const struct gl_shader_program *shader_program,
> + bool use_binding_as_idx)
> {
> bool progress = false;
>
> @@ -184,7 +188,8 @@ nir_lower_atomics(nir_shader *shader,
> nir_foreach_instr_safe(instr, block) {
> if (instr->type == nir_instr_type_intrinsic)
> progress |= lower_instr(nir_instr_as_intrinsic(instr),
> - shader_program, shader);
> + shader_program, shader,
> + use_binding_as_idx);
> }
> }
>
> diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp
> b/src/mesa/drivers/dri/i965/brw_link.cpp
> index b08b56a935..274a738cbb 100644
> --- a/src/mesa/drivers/dri/i965/brw_link.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_link.cpp
> @@ -299,7 +299,7 @@ brw_link_shader(struct gl_context *ctx, struct
> gl_shader_program *shProg)
> brw_shader_gather_info(prog->nir, prog);
>
> NIR_PASS_V(prog->nir, nir_lower_samplers, shProg);
> - NIR_PASS_V(prog->nir, nir_lower_atomics, shProg);
> + NIR_PASS_V(prog->nir, nir_lower_atomics, shProg, false);
> NIR_PASS_V(prog->nir, nir_lower_atomics_to_ssbo,
> prog->nir->info.num_abos);
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp
> b/src/mesa/state_tracker/st_glsl_to_nir.cpp
> index 6f3fa248f1..fb45cf2d5e 100644
> --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
> @@ -428,7 +428,7 @@ st_glsl_to_nir_post_opts(struct st_context *st,
> struct gl_program *prog,
> st_set_prog_affected_state_flags(prog);
>
> NIR_PASS_V(nir, st_nir_lower_builtin);
> - NIR_PASS_V(nir, nir_lower_atomics, shader_program);
> + NIR_PASS_V(nir, nir_lower_atomics, shader_program, true);
>
> if (st->ctx->_Shader->Flags & GLSL_DUMP) {
> _mesa_log("\n");
> --
> 2.14.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180319/725744c8/attachment-0001.html>
More information about the mesa-dev
mailing list