summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2018-03-28 08:32:10 -0400
committerRob Clark <[email protected]>2018-04-03 06:08:56 -0400
commit51888bf07dd2f9942708f9a265b18a129ee625f1 (patch)
tree980aa77e4a11fc7360cb734cd252a62fa13c8787
parent91f9450b3222469d93c270b8ca5fb4bf2ef584f2 (diff)
nir+drivers: add helpers to get # of src/dest components
Add helpers to get the number of src/dest components for an intrinsic, and update spots that were open-coding this logic to use the helpers instead. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
-rw-r--r--src/compiler/nir/nir.h22
-rw-r--r--src/compiler/nir/nir_opt_copy_propagate.c5
-rw-r--r--src/compiler/nir/nir_validate.c10
-rw-r--r--src/compiler/spirv/spirv_to_nir.c3
-rw-r--r--src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c6
-rw-r--r--src/intel/compiler/brw_fs_nir.cpp11
6 files changed, 32 insertions, 25 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index cc7c401b40e..f33049d7134 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1146,6 +1146,28 @@ typedef struct {
extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
+static inline unsigned
+nir_intrinsic_src_components(nir_intrinsic_instr *intr, unsigned srcn)
+{
+ const nir_intrinsic_info *info = &nir_intrinsic_infos[intr->intrinsic];
+ assert(srcn < info->num_srcs);
+ if (info->src_components[srcn])
+ return info->src_components[srcn];
+ else
+ return intr->num_components;
+}
+
+static inline unsigned
+nir_intrinsic_dest_components(nir_intrinsic_instr *intr)
+{
+ const nir_intrinsic_info *info = &nir_intrinsic_infos[intr->intrinsic];
+ if (!info->has_dest)
+ return 0;
+ else if (info->dest_components)
+ return info->dest_components;
+ else
+ return intr->num_components;
+}
#define INTRINSIC_IDX_ACCESSORS(name, flag, type) \
static inline type \
diff --git a/src/compiler/nir/nir_opt_copy_propagate.c b/src/compiler/nir/nir_opt_copy_propagate.c
index c4001fa73f5..3cd476a1b97 100644
--- a/src/compiler/nir/nir_opt_copy_propagate.c
+++ b/src/compiler/nir/nir_opt_copy_propagate.c
@@ -257,10 +257,7 @@ copy_prop_instr(nir_instr *instr)
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
for (unsigned i = 0;
i < nir_intrinsic_infos[intrin->intrinsic].num_srcs; i++) {
- unsigned num_components =
- nir_intrinsic_infos[intrin->intrinsic].src_components[i];
- if (!num_components)
- num_components = intrin->num_components;
+ unsigned num_components = nir_intrinsic_src_components(intrin, i);
while (copy_prop_src(&intrin->src[i], instr, NULL, num_components))
progress = true;
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 5566ceb2985..eee737e8069 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -483,10 +483,7 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state)
unsigned num_srcs = nir_intrinsic_infos[instr->intrinsic].num_srcs;
for (unsigned i = 0; i < num_srcs; i++) {
- unsigned components_read =
- nir_intrinsic_infos[instr->intrinsic].src_components[i];
- if (components_read == 0)
- components_read = instr->num_components;
+ unsigned components_read = nir_intrinsic_src_components(instr, i);
validate_assert(state, components_read > 0);
@@ -499,10 +496,7 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state)
}
if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
- unsigned components_written =
- nir_intrinsic_infos[instr->intrinsic].dest_components;
- if (components_written == 0)
- components_written = instr->num_components;
+ unsigned components_written = nir_intrinsic_dest_components(instr);
validate_assert(state, components_written > 0);
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 72ab426e805..b7c07064d9d 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2434,8 +2434,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
- unsigned dest_components =
- nir_intrinsic_infos[intrin->intrinsic].dest_components;
+ unsigned dest_components = nir_intrinsic_dest_components(intrin);
if (intrin->intrinsic == nir_intrinsic_image_var_size) {
dest_components = intrin->num_components =
glsl_get_vector_elements(type->type);
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
index 3d3c85dd03b..174141b7fec 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
@@ -2044,11 +2044,7 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr)
int idx, comp;
if (info->has_dest) {
- unsigned n;
- if (info->dest_components)
- n = info->dest_components;
- else
- n = intr->num_components;
+ unsigned n = nir_intrinsic_dest_components(intr);
dst = get_dst(ctx, &intr->dest, n);
} else {
dst = NULL;
diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp
index 197d41062e3..6c4bcd1c113 100644
--- a/src/intel/compiler/brw_fs_nir.cpp
+++ b/src/intel/compiler/brw_fs_nir.cpp
@@ -3821,6 +3821,7 @@ fs_visitor::nir_emit_intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr
const unsigned arr_dims = type->sampler_array ? 1 : 0;
const unsigned surf_dims = type->coordinate_components() - arr_dims;
const unsigned format = var->data.image.format;
+ const unsigned dest_components = nir_intrinsic_dest_components(instr);
/* Get the arguments of the image intrinsic. */
const fs_reg image = get_nir_image_deref(instr->variables[0]);
@@ -3844,15 +3845,13 @@ fs_visitor::nir_emit_intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr
else
tmp = emit_image_atomic(bld, image, addr, src0, src1,
- surf_dims, arr_dims, info->dest_components,
+ surf_dims, arr_dims, dest_components,
get_image_atomic_op(instr->intrinsic, type));
/* Assign the result. */
- if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
- for (unsigned c = 0; c < info->dest_components; ++c) {
- bld.MOV(offset(retype(dest, base_type), bld, c),
- offset(tmp, bld, c));
- }
+ for (unsigned c = 0; c < dest_components; ++c) {
+ bld.MOV(offset(retype(dest, base_type), bld, c),
+ offset(tmp, bld, c));
}
break;
}