aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2020-04-09 17:03:37 -0500
committerMarge Bot <[email protected]>2020-04-17 19:21:44 +0000
commitfeca4396974feb0e94603151eaebb6a7a6a22ce3 (patch)
treefa9cf990c7a7beaa1041b2ce22a8769fe9176297 /src/compiler
parentacaccff4d331ecc4b2794fef3f4b117abdd15abf (diff)
spirv: Call nir_builder directly for vector_extract
The nir_builder helper already handles checking if the component selector is an immediate and returns an undef in the OOB case. Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4495>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c22
-rw-r--r--src/compiler/spirv/vtn_amd.c9
-rw-r--r--src/compiler/spirv/vtn_glsl450.c9
-rw-r--r--src/compiler/spirv/vtn_opencl.c2
-rw-r--r--src/compiler/spirv/vtn_private.h4
-rw-r--r--src/compiler/spirv/vtn_variables.c6
6 files changed, 9 insertions, 43 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index a4f8ce27987..2cc8f2570c7 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3312,15 +3312,6 @@ vtn_ssa_transpose(struct vtn_builder *b, struct vtn_ssa_value *src)
}
nir_ssa_def *
-vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src, unsigned index)
-{
- if (index > src->num_components)
- return nir_ssa_undef(&b->nb, src->num_components, src->bit_size);
- else
- return nir_channel(&b->nb, src, index);
-}
-
-nir_ssa_def *
vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
unsigned index)
{
@@ -3342,13 +3333,6 @@ vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
}
nir_ssa_def *
-vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
- nir_ssa_def *index)
-{
- return nir_vector_extract(&b->nb, src, nir_i2i(&b->nb, index, 32));
-}
-
-nir_ssa_def *
vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
nir_ssa_def *insert, nir_ssa_def *index)
{
@@ -3506,7 +3490,7 @@ vtn_composite_extract(struct vtn_builder *b, struct vtn_ssa_value *src,
struct vtn_ssa_value *ret = rzalloc(b, struct vtn_ssa_value);
ret->type = glsl_scalar_type(glsl_get_base_type(cur->type));
- ret->def = vtn_vector_extract(b, cur->def, indices[i]);
+ ret->def = nir_channel(&b->nb, cur->def, indices[i]);
return ret;
} else {
vtn_fail_if(indices[i] >= glsl_get_length(cur->type),
@@ -3527,8 +3511,8 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
switch (opcode) {
case SpvOpVectorExtractDynamic:
- ssa->def = vtn_vector_extract_dynamic(b, vtn_ssa_value(b, w[3])->def,
- vtn_ssa_value(b, w[4])->def);
+ ssa->def = nir_vector_extract(&b->nb, vtn_ssa_value(b, w[3])->def,
+ vtn_ssa_value(b, w[4])->def);
break;
case SpvOpVectorInsertDynamic:
diff --git a/src/compiler/spirv/vtn_amd.c b/src/compiler/spirv/vtn_amd.c
index 55f87c2f98e..195baef9c00 100644
--- a/src/compiler/spirv/vtn_amd.c
+++ b/src/compiler/spirv/vtn_amd.c
@@ -219,13 +219,8 @@ vtn_handle_amd_shader_explicit_vertex_parameter_instruction(struct vtn_builder *
if (vec_array_deref) {
assert(vec_deref);
- if (nir_src_is_const(vec_deref->arr.index)) {
- val->ssa->def = vtn_vector_extract(b, &intrin->dest.ssa,
- nir_src_as_uint(vec_deref->arr.index));
- } else {
- val->ssa->def = vtn_vector_extract_dynamic(b, &intrin->dest.ssa,
- vec_deref->arr.index.ssa);
- }
+ val->ssa->def = nir_vector_extract(&b->nb, &intrin->dest.ssa,
+ vec_deref->arr.index.ssa);
} else {
val->ssa->def = &intrin->dest.ssa;
}
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c
index 2ecd0295bc8..2d4743d59f0 100644
--- a/src/compiler/spirv/vtn_glsl450.c
+++ b/src/compiler/spirv/vtn_glsl450.c
@@ -591,13 +591,8 @@ handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,
if (vec_array_deref) {
assert(vec_deref);
- if (nir_src_is_const(vec_deref->arr.index)) {
- val->ssa->def = vtn_vector_extract(b, &intrin->dest.ssa,
- nir_src_as_uint(vec_deref->arr.index));
- } else {
- val->ssa->def = vtn_vector_extract_dynamic(b, &intrin->dest.ssa,
- vec_deref->arr.index.ssa);
- }
+ val->ssa->def = nir_vector_extract(&b->nb, &intrin->dest.ssa,
+ vec_deref->arr.index.ssa);
} else {
val->ssa->def = &intrin->dest.ssa;
}
diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c
index da191f2b80a..eb8aaac7d1c 100644
--- a/src/compiler/spirv/vtn_opencl.c
+++ b/src/compiler/spirv/vtn_opencl.c
@@ -243,7 +243,7 @@ _handle_v_load_store(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
} else {
struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, glsl_scalar_type(glsl_get_base_type(dest_type)));
struct vtn_ssa_value *val = vtn_ssa_value(b, w[5]);
- ssa->def = vtn_vector_extract(b, val->def, i);
+ ssa->def = nir_channel(&b->nb, val->def, i);
vtn_local_store(b, ssa, arr_deref, p->type->access);
}
}
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index b7eb31089cd..3624ac3fa7e 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -797,10 +797,6 @@ struct vtn_ssa_value *vtn_create_ssa_value(struct vtn_builder *b,
struct vtn_ssa_value *vtn_ssa_transpose(struct vtn_builder *b,
struct vtn_ssa_value *src);
-nir_ssa_def *vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src,
- unsigned index);
-nir_ssa_def *vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
- nir_ssa_def *index);
nir_ssa_def *vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src,
nir_ssa_def *insert, unsigned index);
nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 1bb48642b3f..8bb00a5dd40 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -735,11 +735,7 @@ vtn_local_load(struct vtn_builder *b, nir_deref_instr *src,
if (src_tail != src) {
val->type = src->type;
- if (nir_src_is_const(src->arr.index))
- val->def = vtn_vector_extract(b, val->def,
- nir_src_as_uint(src->arr.index));
- else
- val->def = vtn_vector_extract_dynamic(b, val->def, src->arr.index.ssa);
+ val->def = nir_vector_extract(&b->nb, val->def, src->arr.index.ssa);
}
return val;