Mesa (master): nir: use intrinsic builders
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Nov 26 18:11:47 UTC 2020
Module: Mesa
Branch: master
Commit: 9b040737d309698df9d1e94b24205ae133048621
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9b040737d309698df9d1e94b24205ae133048621
Author: Rhys Perry <pendingchaos02 at gmail.com>
Date: Thu Sep 3 17:20:17 2020 +0100
nir: use intrinsic builders
Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6587>
---
src/compiler/nir/nir_inline_functions.c | 4 +-
src/compiler/nir/nir_lower_bitmap.c | 5 +-
src/compiler/nir/nir_lower_gs_intrinsics.c | 25 ++--------
src/compiler/nir/nir_lower_io.c | 8 +--
src/compiler/nir/nir_lower_scratch.c | 23 ++-------
src/compiler/nir/nir_lower_subgroups.c | 43 +++-------------
src/compiler/nir/nir_opt_uniform_atomics.c | 57 +++++-----------------
.../nir/tests/load_store_vectorizer_tests.cpp | 2 +-
8 files changed, 31 insertions(+), 136 deletions(-)
diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c
index 936cfac1709..c81c6c4e9a8 100644
--- a/src/compiler/nir/nir_inline_functions.c
+++ b/src/compiler/nir/nir_inline_functions.c
@@ -36,9 +36,7 @@ void nir_inline_function_impl(struct nir_builder *b,
/* Insert a nop at the cursor so we can keep track of where things are as
* we add/remove stuff from the CFG.
*/
- nir_intrinsic_instr *nop =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_nop);
- nir_builder_instr_insert(b, &nop->instr);
+ nir_intrinsic_instr *nop = nir_nop(b);
exec_list_append(&b->impl->locals, ©->locals);
exec_list_append(&b->impl->registers, ©->registers);
diff --git a/src/compiler/nir/nir_lower_bitmap.c b/src/compiler/nir/nir_lower_bitmap.c
index 4d361f5e2df..3b806bc53ff 100644
--- a/src/compiler/nir/nir_lower_bitmap.c
+++ b/src/compiler/nir/nir_lower_bitmap.c
@@ -77,7 +77,6 @@ lower_bitmap(nir_shader *shader, nir_builder *b,
nir_ssa_def *texcoord;
nir_tex_instr *tex;
nir_ssa_def *cond;
- nir_intrinsic_instr *discard;
texcoord = nir_load_var(b, get_texcoord(shader));
@@ -113,9 +112,7 @@ lower_bitmap(nir_shader *shader, nir_builder *b,
cond = nir_f2b(b, nir_channel(b, &tex->dest.ssa,
options->swizzle_xxxx ? 0 : 3));
- discard = nir_intrinsic_instr_create(shader, nir_intrinsic_discard_if);
- discard->src[0] = nir_src_for_ssa(cond);
- nir_builder_instr_insert(b, &discard->instr);
+ nir_discard_if(b, cond);
shader->info.fs.uses_discard = true;
}
diff --git a/src/compiler/nir/nir_lower_gs_intrinsics.c b/src/compiler/nir/nir_lower_gs_intrinsics.c
index d170f7b0f6c..33fff69ae7c 100644
--- a/src/compiler/nir/nir_lower_gs_intrinsics.c
+++ b/src/compiler/nir/nir_lower_gs_intrinsics.c
@@ -102,13 +102,7 @@ rewrite_emit_vertex(nir_intrinsic_instr *intrin, struct state *state)
*/
nir_push_if(b, nir_ilt(b, count, max_vertices));
- nir_intrinsic_instr *lowered =
- nir_intrinsic_instr_create(b->shader,
- nir_intrinsic_emit_vertex_with_counter);
- nir_intrinsic_set_stream_id(lowered, stream);
- lowered->src[0] = nir_src_for_ssa(count);
- lowered->src[1] = nir_src_for_ssa(count_per_primitive);
- nir_builder_instr_insert(b, &lowered->instr);
+ nir_emit_vertex_with_counter(b, count, count_per_primitive, stream);
/* Increment the vertex count by 1 */
nir_store_var(b, state->vertex_count_vars[stream],
@@ -217,13 +211,7 @@ rewrite_end_primitive(nir_intrinsic_instr *intrin, struct state *state)
else
count_per_primitive = nir_ssa_undef(b, count->num_components, count->bit_size);
- nir_intrinsic_instr *lowered =
- nir_intrinsic_instr_create(b->shader,
- nir_intrinsic_end_primitive_with_counter);
- nir_intrinsic_set_stream_id(lowered, stream);
- lowered->src[0] = nir_src_for_ssa(count);
- lowered->src[1] = nir_src_for_ssa(count_per_primitive);
- nir_builder_instr_insert(b, &lowered->instr);
+ nir_end_primitive_with_counter(b, count, count_per_primitive, stream);
if (state->count_prims) {
/* Increment the primitive count by 1 */
@@ -313,14 +301,7 @@ append_set_vertex_and_primitive_count(nir_block *end_block, struct state *state)
: nir_ssa_undef(b, 1, 32);
}
- nir_intrinsic_instr *set_cnt_intrin =
- nir_intrinsic_instr_create(shader,
- nir_intrinsic_set_vertex_and_primitive_count);
-
- nir_intrinsic_set_stream_id(set_cnt_intrin, stream);
- set_cnt_intrin->src[0] = nir_src_for_ssa(vtx_cnt);
- set_cnt_intrin->src[1] = nir_src_for_ssa(prim_cnt);
- nir_builder_instr_insert(b, &set_cnt_intrin->instr);
+ nir_set_vertex_and_primitive_count(b, vtx_cnt, prim_cnt, stream);
}
}
}
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 1c5a52b66bf..0eb4348286d 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -1992,14 +1992,8 @@ lower_explicit_io_array_length(nir_builder *b, nir_intrinsic_instr *intrin,
nir_ssa_def *index = addr_to_index(b, addr, addr_format);
nir_ssa_def *offset = addr_to_offset(b, addr, addr_format);
- nir_intrinsic_instr *bsize =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_get_ssbo_size);
- bsize->src[0] = nir_src_for_ssa(index);
- nir_ssa_dest_init(&bsize->instr, &bsize->dest, 1, 32, NULL);
- nir_builder_instr_insert(b, &bsize->instr);
-
nir_ssa_def *arr_size =
- nir_idiv(b, nir_isub(b, &bsize->dest.ssa, offset),
+ nir_idiv(b, nir_isub(b, nir_get_ssbo_size(b, index), offset),
nir_imm_int(b, stride));
nir_ssa_def_rewrite_uses(&intrin->dest.ssa, nir_src_for_ssa(arr_size));
diff --git a/src/compiler/nir/nir_lower_scratch.c b/src/compiler/nir/nir_lower_scratch.c
index bef729a47fb..1a82a07b996 100644
--- a/src/compiler/nir/nir_lower_scratch.c
+++ b/src/compiler/nir/nir_lower_scratch.c
@@ -52,18 +52,9 @@ lower_load_store(nir_builder *b,
size_align(deref->type, &size, &align);
if (intrin->intrinsic == nir_intrinsic_load_deref) {
- nir_intrinsic_instr *load =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_scratch);
- load->num_components = intrin->num_components;
- load->src[0] = nir_src_for_ssa(offset);
- nir_intrinsic_set_align(load, align, 0);
unsigned bit_size = intrin->dest.ssa.bit_size;
- nir_ssa_dest_init(&load->instr, &load->dest,
- intrin->dest.ssa.num_components,
- bit_size == 1 ? 32 : bit_size, NULL);
- nir_builder_instr_insert(b, &load->instr);
-
- nir_ssa_def *value = &load->dest.ssa;
+ nir_ssa_def *value = nir_load_scratch(
+ b, intrin->num_components, bit_size == 1 ? 32 : bit_size, offset, .align_mul=align);
if (bit_size == 1)
value = nir_b2b1(b, value);
@@ -77,14 +68,8 @@ lower_load_store(nir_builder *b,
if (value->bit_size == 1)
value = nir_b2b32(b, value);
- nir_intrinsic_instr *store =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_scratch);
- store->num_components = intrin->num_components;
- store->src[0] = nir_src_for_ssa(value);
- store->src[1] = nir_src_for_ssa(offset);
- nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(intrin));
- nir_intrinsic_set_align(store, align, 0);
- nir_builder_instr_insert(b, &store->instr);
+ nir_store_scratch(b, value, offset, .align_mul=align,
+ .write_mask=nir_intrinsic_write_mask(intrin));
}
nir_instr_remove(&intrin->instr);
diff --git a/src/compiler/nir/nir_lower_subgroups.c b/src/compiler/nir/nir_lower_subgroups.c
index ecd3d03a192..b0703bc94df 100644
--- a/src/compiler/nir/nir_lower_subgroups.c
+++ b/src/compiler/nir/nir_lower_subgroups.c
@@ -187,20 +187,13 @@ lower_vote_eq_to_ballot(nir_builder *b, nir_intrinsic_instr *intrin,
/* We have to implicitly lower to scalar */
nir_ssa_def *all_eq = NULL;
for (unsigned i = 0; i < intrin->num_components; i++) {
- nir_intrinsic_instr *rfi =
- nir_intrinsic_instr_create(b->shader,
- nir_intrinsic_read_first_invocation);
- nir_ssa_dest_init(&rfi->instr, &rfi->dest,
- 1, value->bit_size, NULL);
- rfi->num_components = 1;
- rfi->src[0] = nir_src_for_ssa(nir_channel(b, value, i));
- nir_builder_instr_insert(b, &rfi->instr);
+ nir_ssa_def *rfi = nir_read_first_invocation(b, nir_channel(b, value, i));
nir_ssa_def *is_eq;
if (intrin->intrinsic == nir_intrinsic_vote_feq) {
- is_eq = nir_feq(b, &rfi->dest.ssa, nir_channel(b, value, i));
+ is_eq = nir_feq(b, rfi, nir_channel(b, value, i));
} else {
- is_eq = nir_ieq(b, &rfi->dest.ssa, nir_channel(b, value, i));
+ is_eq = nir_ieq(b, rfi, nir_channel(b, value, i));
}
if (all_eq == NULL) {
@@ -210,16 +203,8 @@ lower_vote_eq_to_ballot(nir_builder *b, nir_intrinsic_instr *intrin,
}
}
- nir_intrinsic_instr *ballot =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_ballot);
- nir_ssa_dest_init(&ballot->instr, &ballot->dest,
- 1, options->ballot_bit_size, NULL);
- ballot->num_components = 1;
- ballot->src[0] = nir_src_for_ssa(nir_inot(b, all_eq));
- nir_builder_instr_insert(b, &ballot->instr);
-
- return nir_ieq(b, &ballot->dest.ssa,
- nir_imm_intN_t(b, 0, options->ballot_bit_size));
+ nir_ssa_def *ballot = nir_ballot(b, 1, options->ballot_bit_size, nir_inot(b, all_eq));
+ return nir_ieq(b, ballot, nir_imm_intN_t(b, 0, options->ballot_bit_size));
}
static nir_ssa_def *
@@ -468,15 +453,9 @@ lower_subgroups_instr(nir_builder *b, nir_instr *instr, void *_options)
intrin->dest.ssa.bit_size == options->ballot_bit_size)
return NULL;
- nir_intrinsic_instr *ballot =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_ballot);
- ballot->num_components = 1;
- nir_ssa_dest_init(&ballot->instr, &ballot->dest,
- 1, options->ballot_bit_size, NULL);
- nir_src_copy(&ballot->src[0], &intrin->src[0], ballot);
- nir_builder_instr_insert(b, &ballot->instr);
+ nir_ssa_def *ballot = nir_ballot(b, 1, options->ballot_bit_size, intrin->src[0].ssa);
- return uint_to_ballot_type(b, &ballot->dest.ssa,
+ return uint_to_ballot_type(b, ballot,
intrin->dest.ssa.num_components,
intrin->dest.ssa.bit_size);
}
@@ -553,13 +532,7 @@ lower_subgroups_instr(nir_builder *b, nir_instr *instr, void *_options)
if (!options->lower_elect)
return NULL;
- nir_intrinsic_instr *first =
- nir_intrinsic_instr_create(b->shader,
- nir_intrinsic_first_invocation);
- nir_ssa_dest_init(&first->instr, &first->dest, 1, 32, NULL);
- nir_builder_instr_insert(b, &first->instr);
-
- return nir_ieq(b, nir_load_subgroup_invocation(b), &first->dest.ssa);
+ return nir_ieq(b, nir_load_subgroup_invocation(b), nir_first_invocation(b));
}
case nir_intrinsic_shuffle:
diff --git a/src/compiler/nir/nir_opt_uniform_atomics.c b/src/compiler/nir/nir_opt_uniform_atomics.c
index 26ca78c8b89..ce5090b0d83 100644
--- a/src/compiler/nir/nir_opt_uniform_atomics.c
+++ b/src/compiler/nir/nir_opt_uniform_atomics.c
@@ -153,53 +153,20 @@ is_atomic_already_optimized(nir_shader *shader, nir_intrinsic_instr *instr)
return (dims & dims_needed) == dims_needed || dims & 0x8;
}
-static nir_ssa_def *
-emit_scalar_intrinsic(nir_builder *b, nir_intrinsic_op op, unsigned bit_size)
-{
- nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
- nir_ssa_dest_init(&intrin->instr, &intrin->dest, 1, bit_size, NULL);
- nir_builder_instr_insert(b, &intrin->instr);
- return &intrin->dest.ssa;
-}
-
-static nir_ssa_def *
-emit_read_invocation(nir_builder *b, nir_ssa_def *data, nir_ssa_def *lane)
-{
- nir_intrinsic_instr *ri = nir_intrinsic_instr_create(
- b->shader, lane ? nir_intrinsic_read_invocation : nir_intrinsic_read_first_invocation);
- nir_ssa_dest_init(&ri->instr, &ri->dest, 1, data->bit_size, NULL);
- ri->num_components = 1;
- ri->src[0] = nir_src_for_ssa(data);
- if (lane)
- ri->src[1] = nir_src_for_ssa(lane);
- nir_builder_instr_insert(b, &ri->instr);
- return &ri->dest.ssa;
-}
-
/* Perform a reduction and/or exclusive scan. */
static void
reduce_data(nir_builder *b, nir_op op, nir_ssa_def *data,
nir_ssa_def **reduce, nir_ssa_def **scan)
{
- nir_intrinsic_op intrin_op = scan ? nir_intrinsic_exclusive_scan : nir_intrinsic_reduce;
- nir_intrinsic_instr *intrin =
- nir_intrinsic_instr_create(b->shader, intrin_op);
- intrin->num_components = 1;
- intrin->src[0] = nir_src_for_ssa(data);
- nir_intrinsic_set_reduction_op(intrin, op);
- nir_ssa_dest_init(&intrin->instr, &intrin->dest, 1, data->bit_size, NULL);
- nir_builder_instr_insert(b, &intrin->instr);
-
- if (scan)
- *scan = &intrin->dest.ssa;
-
- if (scan && reduce) {
- *scan = &intrin->dest.ssa;
- nir_ssa_def *last_lane = emit_scalar_intrinsic(b, nir_intrinsic_last_invocation, 32);
- nir_ssa_def *res = nir_build_alu(b, op, *scan, data, NULL, NULL);
- *reduce = emit_read_invocation(b, res, last_lane);
- } else if (reduce) {
- *reduce = &intrin->dest.ssa;
+ if (scan) {
+ *scan = nir_exclusive_scan(b, data, .reduction_op=op);
+ if (reduce) {
+ nir_ssa_def *last_lane = nir_last_invocation(b);
+ nir_ssa_def *res = nir_build_alu(b, op, *scan, data, NULL, NULL);
+ *reduce = nir_read_invocation(b, res, last_lane);
+ }
+ } else {
+ *reduce = nir_reduce(b, data, .reduction_op=op);
}
}
@@ -218,7 +185,7 @@ optimize_atomic(nir_builder *b, nir_intrinsic_instr *intrin, bool return_prev)
nir_instr_rewrite_src(&intrin->instr, &intrin->src[data_src], nir_src_for_ssa(reduce));
nir_update_instr_divergence(b->shader, &intrin->instr);
- nir_ssa_def *cond = emit_scalar_intrinsic(b, nir_intrinsic_elect, 1);
+ nir_ssa_def *cond = nir_elect(b, 1);
nir_if *nif = nir_push_if(b, cond);
@@ -232,7 +199,7 @@ optimize_atomic(nir_builder *b, nir_intrinsic_instr *intrin, bool return_prev)
nir_pop_if(b, nif);
nir_ssa_def *result = nir_if_phi(b, &intrin->dest.ssa, undef);
- result = emit_read_invocation(b, result, NULL);
+ result = nir_read_first_invocation(b, result);
if (!combined_scan_reduce)
reduce_data(b, op, data, NULL, &scan);
@@ -249,7 +216,7 @@ optimize_and_rewrite_atomic(nir_builder *b, nir_intrinsic_instr *intrin)
{
nir_if *helper_nif = NULL;
if (b->shader->info.stage == MESA_SHADER_FRAGMENT) {
- nir_ssa_def *helper = emit_scalar_intrinsic(b, nir_intrinsic_is_helper_invocation, 1);
+ nir_ssa_def *helper = nir_is_helper_invocation(b, 1);
helper_nif = nir_push_if(b, nir_inot(b, helper));
}
diff --git a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
index 39874070153..250401a0c79 100644
--- a/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
+++ b/src/compiler/nir/tests/load_store_vectorizer_tests.cpp
@@ -837,7 +837,7 @@ TEST_F(nir_load_store_vectorize_test, ssbo_load_adjacent_memory_barrier)
TEST_F(nir_load_store_vectorize_test, ssbo_load_adjacent_barrier)
{
create_load(nir_var_mem_ssbo, 0, 0, 0x1);
- nir_builder_instr_insert(b, &nir_intrinsic_instr_create(b->shader, nir_intrinsic_control_barrier)->instr);
+ nir_control_barrier(b);
create_load(nir_var_mem_ssbo, 0, 4, 0x2);
nir_validate_shader(b->shader, NULL);
More information about the mesa-commit
mailing list