[Mesa-dev] [PATCH 11/22] nir: Make image load/store intrinsics variable-width
Jason Ekstrand
jason at jlekstrand.net
Fri Aug 17 20:06:17 UTC 2018
Instead of requiring 4 components, this allows them to potentially use
fewer. Both the SPIR-V and GLSL paths still generate vec4 intrinsics so
drivers which assume 4 components should be safe. However, we want to
be able to shrink them for i965.
---
src/compiler/glsl/glsl_to_nir.cpp | 9 +++++++--
src/compiler/nir/nir_intrinsics.py | 4 ++--
src/compiler/spirv/spirv_to_nir.c | 2 ++
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index b1d1da89111..fbe25dcc5a4 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -883,12 +883,17 @@ nir_visitor::visit(ir_call *ir)
/* Set the intrinsic destination. */
if (ir->return_deref) {
unsigned num_components = ir->return_deref->type->vector_elements;
- if (instr->intrinsic == nir_intrinsic_image_deref_size)
- instr->num_components = num_components;
nir_ssa_dest_init(&instr->instr, &instr->dest,
num_components, 32, NULL);
}
+ if (op == nir_intrinsic_image_deref_size) {
+ instr->num_components = instr->dest.ssa.num_components;
+ } else if (op == nir_intrinsic_image_deref_load ||
+ op == nir_intrinsic_image_deref_store) {
+ instr->num_components = 4;
+ }
+
if (op == nir_intrinsic_image_deref_size ||
op == nir_intrinsic_image_deref_samples) {
nir_builder_instr_insert(&b, &instr->instr);
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
index d688a57181b..63c602c8874 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -296,9 +296,9 @@ atomic3("atomic_counter_comp_swap")
# argument with the value to be written, and image atomic operations take
# either one or two additional scalar arguments with the same meaning as in
# the ARB_shader_image_load_store specification.
-intrinsic("image_deref_load", src_comp=[1, 4, 1], dest_comp=4,
+intrinsic("image_deref_load", src_comp=[1, 4, 1], dest_comp=0,
flags=[CAN_ELIMINATE])
-intrinsic("image_deref_store", src_comp=[1, 4, 1, 4])
+intrinsic("image_deref_store", src_comp=[1, 4, 1, 0])
intrinsic("image_deref_atomic_add", src_comp=[1, 4, 1, 1], dest_comp=1)
intrinsic("image_deref_atomic_min", src_comp=[1, 4, 1, 1], dest_comp=1)
intrinsic("image_deref_atomic_max", src_comp=[1, 4, 1, 1], dest_comp=1)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index b5ec2de7bf9..96224354057 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2467,6 +2467,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
const uint32_t value_id = opcode == SpvOpAtomicStore ? w[4] : w[3];
nir_ssa_def *value = vtn_ssa_value(b, value_id)->def;
/* nir_intrinsic_image_deref_store always takes a vec4 value */
+ assert(op == nir_intrinsic_image_deref_store);
+ intrin->num_components = 4;
intrin->src[3] = nir_src_for_ssa(expand_to_vec4(&b->nb, value));
break;
}
--
2.17.1
More information about the mesa-dev
mailing list