summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2016-07-21 12:01:35 -0700
committerEmil Velikov <emil.l.velikov@gmail.com>2017-01-13 05:27:01 +0000
commit70bb67febcb2743bb14fa0f560499f4a90505dcc (patch)
tree9fdd8998d9c57f111d62ab5fc35e35f289746587
parent912647901705d07055d87847d5994b24d1e2bf43 (diff)
nir/spirv: Refactor coordinate handling in handle_texture
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Cc: "12.0" <mesa-dev@lists.freedesktop.org> (cherry picked from commit 36c31b8fa22acee78c26ec9a82fbc13d992d022f)
-rw-r--r--src/compiler/spirv/spirv_to_nir.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 245fca3e03c..5fa1d6a8b5e 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1392,7 +1392,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
unsigned idx = 4;
- bool has_coord = false;
+ struct nir_ssa_def *coord;
+ unsigned coord_components;
switch (opcode) {
case SpvOpImageSampleImplicitLod:
case SpvOpImageSampleExplicitLod:
@@ -1407,15 +1408,37 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
case SpvOpImageDrefGather:
case SpvOpImageQueryLod: {
/* All these types have the coordinate as their first real argument */
- struct vtn_ssa_value *coord = vtn_ssa_value(b, w[idx++]);
- has_coord = true;
- p->src = nir_src_for_ssa(coord->def);
+ switch (sampler_dim) {
+ case GLSL_SAMPLER_DIM_1D:
+ case GLSL_SAMPLER_DIM_BUF:
+ coord_components = 1;
+ break;
+ case GLSL_SAMPLER_DIM_2D:
+ case GLSL_SAMPLER_DIM_RECT:
+ case GLSL_SAMPLER_DIM_MS:
+ coord_components = 2;
+ break;
+ case GLSL_SAMPLER_DIM_3D:
+ case GLSL_SAMPLER_DIM_CUBE:
+ coord_components = 3;
+ break;
+ default:
+ assert("Invalid sampler type");
+ }
+
+ if (is_array && texop != nir_texop_lod)
+ coord_components++;
+
+ coord = vtn_ssa_value(b, w[idx++])->def;
+ p->src = nir_src_for_ssa(coord);
p->src_type = nir_tex_src_coord;
p++;
break;
}
default:
+ coord = NULL;
+ coord_components = 0;
break;
}
@@ -1488,6 +1511,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
memcpy(instr->src, srcs, instr->num_srcs * sizeof(*instr->src));
+ instr->coord_components = coord_components;
instr->sampler_dim = sampler_dim;
instr->is_array = is_array;
instr->is_shadow = is_shadow;
@@ -1495,31 +1519,6 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
is_shadow && glsl_get_components(ret_type->type) == 1;
instr->component = gather_component;
- if (has_coord) {
- switch (instr->sampler_dim) {
- case GLSL_SAMPLER_DIM_1D:
- case GLSL_SAMPLER_DIM_BUF:
- instr->coord_components = 1;
- break;
- case GLSL_SAMPLER_DIM_2D:
- case GLSL_SAMPLER_DIM_RECT:
- case GLSL_SAMPLER_DIM_MS:
- instr->coord_components = 2;
- break;
- case GLSL_SAMPLER_DIM_3D:
- case GLSL_SAMPLER_DIM_CUBE:
- instr->coord_components = 3;
- break;
- default:
- assert("Invalid sampler type");
- }
-
- if (instr->is_array && instr->op != nir_texop_lod)
- instr->coord_components++;
- } else {
- instr->coord_components = 0;
- }
-
switch (glsl_get_sampler_result_type(image_type)) {
case GLSL_TYPE_FLOAT: instr->dest_type = nir_type_float; break;
case GLSL_TYPE_INT: instr->dest_type = nir_type_int; break;