summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-03-26 16:46:09 -0700
committerJason Ekstrand <[email protected]>2018-06-22 20:54:00 -0700
commit81f29d6d33b54a8661cf7b3b6a7b930c07232e91 (patch)
tree3290ba54709e8a2d0659cf8e87eef12da8223fcf
parent4b0ea65333b3f81fdc7d5bd2b2cd65a987f61eba (diff)
nir: Remove deref chain support from lower_atomics
Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
-rw-r--r--src/compiler/glsl/gl_nir_lower_atomics.c146
1 files changed, 2 insertions, 144 deletions
diff --git a/src/compiler/glsl/gl_nir_lower_atomics.c b/src/compiler/glsl/gl_nir_lower_atomics.c
index 4d1add47d29..25b2ec82ed3 100644
--- a/src/compiler/glsl/gl_nir_lower_atomics.c
+++ b/src/compiler/glsl/gl_nir_lower_atomics.c
@@ -39,146 +39,6 @@
*/
static bool
-lower_var_instr(nir_intrinsic_instr *instr,
- const struct gl_shader_program *shader_program,
- nir_shader *shader, bool use_binding_as_idx)
-{
- nir_intrinsic_op op;
- switch (instr->intrinsic) {
- case nir_intrinsic_atomic_counter_read_var:
- op = nir_intrinsic_atomic_counter_read;
- break;
-
- case nir_intrinsic_atomic_counter_inc_var:
- op = nir_intrinsic_atomic_counter_inc;
- break;
-
- case nir_intrinsic_atomic_counter_dec_var:
- op = nir_intrinsic_atomic_counter_dec;
- break;
-
- case nir_intrinsic_atomic_counter_add_var:
- op = nir_intrinsic_atomic_counter_add;
- break;
-
- case nir_intrinsic_atomic_counter_min_var:
- op = nir_intrinsic_atomic_counter_min;
- break;
-
- case nir_intrinsic_atomic_counter_max_var:
- op = nir_intrinsic_atomic_counter_max;
- break;
-
- case nir_intrinsic_atomic_counter_and_var:
- op = nir_intrinsic_atomic_counter_and;
- break;
-
- case nir_intrinsic_atomic_counter_or_var:
- op = nir_intrinsic_atomic_counter_or;
- break;
-
- case nir_intrinsic_atomic_counter_xor_var:
- op = nir_intrinsic_atomic_counter_xor;
- break;
-
- case nir_intrinsic_atomic_counter_exchange_var:
- op = nir_intrinsic_atomic_counter_exchange;
- break;
-
- case nir_intrinsic_atomic_counter_comp_swap_var:
- op = nir_intrinsic_atomic_counter_comp_swap;
- break;
-
- default:
- return false;
- }
-
- if (instr->variables[0]->var->data.mode != nir_var_uniform &&
- instr->variables[0]->var->data.mode != nir_var_shader_storage &&
- instr->variables[0]->var->data.mode != nir_var_shared)
- return false; /* atomics passed as function arguments can't be lowered */
-
- 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, idx);
-
- nir_load_const_instr *offset_const =
- nir_load_const_instr_create(mem_ctx, 1, 32);
- offset_const->value.u32[0] = instr->variables[0]->var->data.offset;
-
- nir_instr_insert_before(&instr->instr, &offset_const->instr);
-
- nir_ssa_def *offset_def = &offset_const->def;
-
- nir_deref *tail = &instr->variables[0]->deref;
- while (tail->child != NULL) {
- nir_deref_array *deref_array = nir_deref_as_array(tail->child);
- tail = tail->child;
-
- unsigned child_array_elements = tail->child != NULL ?
- glsl_get_aoa_size(tail->type) : 1;
-
- offset_const->value.u32[0] += deref_array->base_offset *
- child_array_elements * ATOMIC_COUNTER_SIZE;
-
- if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
- nir_load_const_instr *atomic_counter_size =
- nir_load_const_instr_create(mem_ctx, 1, 32);
- atomic_counter_size->value.u32[0] = child_array_elements * ATOMIC_COUNTER_SIZE;
- nir_instr_insert_before(&instr->instr, &atomic_counter_size->instr);
-
- nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);
- nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, 32, NULL);
- mul->dest.write_mask = 0x1;
- nir_src_copy(&mul->src[0].src, &deref_array->indirect, mul);
- mul->src[1].src.is_ssa = true;
- mul->src[1].src.ssa = &atomic_counter_size->def;
- nir_instr_insert_before(&instr->instr, &mul->instr);
-
- nir_alu_instr *add = nir_alu_instr_create(mem_ctx, nir_op_iadd);
- nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, 32, NULL);
- add->dest.write_mask = 0x1;
- add->src[0].src.is_ssa = true;
- add->src[0].src.ssa = &mul->dest.dest.ssa;
- add->src[1].src.is_ssa = true;
- add->src[1].src.ssa = offset_def;
- nir_instr_insert_before(&instr->instr, &add->instr);
-
- offset_def = &add->dest.dest.ssa;
- }
- }
-
- new_instr->src[0].is_ssa = true;
- new_instr->src[0].ssa = offset_def;
-
- /* Copy the other sources, if any, from the original instruction to the new
- * instruction.
- */
- for (unsigned i = 0; i < nir_intrinsic_infos[instr->intrinsic].num_srcs; i++)
- nir_src_copy(&new_instr->src[i + 1], &instr->src[i], new_instr);
-
- if (instr->dest.is_ssa) {
- nir_ssa_dest_init(&new_instr->instr, &new_instr->dest,
- instr->dest.ssa.num_components, 32, NULL);
- nir_ssa_def_rewrite_uses(&instr->dest.ssa,
- nir_src_for_ssa(&new_instr->dest.ssa));
- } else {
- nir_dest_copy(&new_instr->dest, &instr->dest, mem_ctx);
- }
-
- nir_instr_insert_before(&instr->instr, &new_instr->instr);
- nir_instr_remove(&instr->instr);
-
- return true;
-}
-
-static bool
lower_deref_instr(nir_builder *b, nir_intrinsic_instr *instr,
const struct gl_shader_program *shader_program,
nir_shader *shader, bool use_binding_as_idx)
@@ -282,6 +142,8 @@ gl_nir_lower_atomics(nir_shader *shader,
{
bool progress = false;
+ nir_assert_unlowered_derefs(shader, nir_lower_atomic_counter_derefs);
+
nir_foreach_function(function, shader) {
if (!function->impl)
continue;
@@ -296,10 +158,6 @@ gl_nir_lower_atomics(nir_shader *shader,
if (instr->type != nir_instr_type_intrinsic)
continue;
- impl_progress |= lower_var_instr(nir_instr_as_intrinsic(instr),
- shader_program, shader,
- use_binding_as_idx);
-
impl_progress |= lower_deref_instr(&build,
nir_instr_as_intrinsic(instr),
shader_program, shader,