aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-09-26 11:56:48 -0500
committerJason Ekstrand <[email protected]>2019-11-09 15:29:01 +0000
commit9e440b8d0b982933650c7b600de1e4b6e33f9c7d (patch)
treeaace3a789f21c83811d6e03c0cf94c5d3060d20f /src
parent9cc4c2c91649be6eb0b0a3f56eeb4ce3696a79a3 (diff)
spirv: Sort out the mess that is sampled image
This commit makes two major changes. First, we add a second case to OpLoad for sampled images which constructs a vtn_sampled_image and stashes that rather than stashing a pointer to the combined image sampler like we do for bare samplers and images. This should be more in line with how SPIR-V is intended to work and hopefully doesn't cause any weird problems. The second is a rework of vtn_handle_texture to assume that everything has an image but not everything has a sampler. We also add a vtn_fail_if for the case where a texture instructions require a sampler but none is provided. Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c28
-rw-r--r--src/compiler/spirv/vtn_variables.c11
2 files changed, 24 insertions, 15 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 013805b842a..d0dc40aff92 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2264,16 +2264,20 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
struct vtn_type *ret_type = vtn_value(b, w[1], vtn_value_type_type)->type;
- struct vtn_sampled_image sampled;
+ struct vtn_pointer *image = NULL, *sampler = NULL;
struct vtn_value *sampled_val = vtn_untyped_value(b, w[3]);
if (sampled_val->value_type == vtn_value_type_sampled_image) {
- sampled = *sampled_val->sampled_image;
+ image = sampled_val->sampled_image->image;
+ sampler = sampled_val->sampled_image->sampler;
} else {
vtn_assert(sampled_val->value_type == vtn_value_type_pointer);
- sampled.image = NULL;
- sampled.sampler = sampled_val->pointer;
+ image = sampled_val->pointer;
}
+ nir_deref_instr *image_deref = vtn_pointer_to_deref(b, image);
+ nir_deref_instr *sampler_deref =
+ sampler ? vtn_pointer_to_deref(b, sampler) : NULL;
+
const struct glsl_type *image_type = sampled_val->type->type;
const enum glsl_sampler_dim sampler_dim = glsl_get_sampler_dim(image_type);
const bool is_array = glsl_sampler_type_is_array(image_type);
@@ -2337,11 +2341,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
nir_tex_src srcs[10]; /* 10 should be enough */
nir_tex_src *p = srcs;
- nir_deref_instr *sampler = vtn_pointer_to_deref(b, sampled.sampler);
- nir_deref_instr *texture =
- sampled.image ? vtn_pointer_to_deref(b, sampled.image) : sampler;
-
- p->src = nir_src_for_ssa(&texture->dest.ssa);
+ p->src = nir_src_for_ssa(&image_deref->dest.ssa);
p->src_type = nir_tex_src_texture_deref;
p++;
@@ -2352,8 +2352,10 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
case nir_texop_txd:
case nir_texop_tg4:
case nir_texop_lod:
- /* These operations require a sampler */
- p->src = nir_src_for_ssa(&sampler->dest.ssa);
+ vtn_fail_if(sampler == NULL,
+ "%s requires an image of type OpTypeSampledImage",
+ spirv_op_to_string(opcode));
+ p->src = nir_src_for_ssa(&sampler_deref->dest.ssa);
p->src_type = nir_tex_src_sampler_deref;
p++;
break;
@@ -2554,10 +2556,10 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
is_shadow && glsl_get_components(ret_type->type) == 1;
instr->component = gather_component;
- if (sampled.image && (sampled.image->access & ACCESS_NON_UNIFORM))
+ if (image && (image->access & ACCESS_NON_UNIFORM))
instr->texture_non_uniform = true;
- if (sampled.sampler && (sampled.sampler->access & ACCESS_NON_UNIFORM))
+ if (sampler && (sampler->access & ACCESS_NON_UNIFORM))
instr->sampler_non_uniform = true;
/* for non-query ops, get dest_type from sampler type */
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 0603e9d0c84..944d1f006d6 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -2541,10 +2541,17 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
vtn_assert_types_equal(b, opcode, res_type, src_val->type->deref);
- if (glsl_type_is_image(res_type->type) ||
- glsl_type_is_sampler(res_type->type)) {
+ if (res_type->base_type == vtn_base_type_image ||
+ res_type->base_type == vtn_base_type_sampler) {
vtn_push_value_pointer(b, w[2], src);
return;
+ } else if (res_type->base_type == vtn_base_type_sampled_image) {
+ struct vtn_value *val =
+ vtn_push_value(b, w[2], vtn_value_type_sampled_image);
+ val->sampled_image = ralloc(b, struct vtn_sampled_image);
+ val->sampled_image->image = val->sampled_image->sampler =
+ vtn_decorate_pointer(b, val, src);
+ return;
}
if (count > 4) {