summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Herbst <kherbst@redhat.com>2019-03-09 20:32:52 +0100
committerKarol Herbst <kherbst@redhat.com>2019-05-04 12:27:51 +0200
commitc91ea6343f6b54d8cd3f8c72708a2425cc94d575 (patch)
treea26dcb5f76fb2e6c3769e5256867cf3c8daacb44
parentc989661985dc67ed3ec31887e37e0ce455b5b381 (diff)
vtn: handle bitcast with pointer src/dest
v2: use vtn_push_ssa and vtn_ssa_value Signed-off-by: Karol Herbst <kherbst@redhat.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
-rw-r--r--src/compiler/spirv/spirv_to_nir.c5
-rw-r--r--src/compiler/spirv/vtn_alu.c66
-rw-r--r--src/compiler/spirv/vtn_private.h3
3 files changed, 45 insertions, 29 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 751ceddaffb..7d2fafe4bde 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -4300,7 +4300,6 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
case SpvOpQuantizeToF16:
case SpvOpPtrCastToGeneric:
case SpvOpGenericCastToPtr:
- case SpvOpBitcast:
case SpvOpIsNan:
case SpvOpIsInf:
case SpvOpIsFinite:
@@ -4385,6 +4384,10 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
vtn_handle_alu(b, opcode, w, count);
break;
+ case SpvOpBitcast:
+ vtn_handle_bitcast(b, w, count);
+ break;
+
case SpvOpVectorExtractDynamic:
case SpvOpVectorInsertDynamic:
case SpvOpVectorShuffle:
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index 6d4347887cd..8f53a7c03e4 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -562,34 +562,6 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
break;
}
- case SpvOpBitcast:
- /* From the definition of OpBitcast in the SPIR-V 1.2 spec:
- *
- * "If Result Type has the same number of components as Operand, they
- * must also have the same component width, and results are computed
- * per component.
- *
- * If Result Type has a different number of components than Operand,
- * the total number of bits in Result Type must equal the total
- * number of bits in Operand. Let L be the type, either Result Type
- * or Operand’s type, that has the larger number of components. Let S
- * be the other type, with the smaller number of components. The
- * number of components in L must be an integer multiple of the
- * number of components in S. The first component (that is, the only
- * or lowest-numbered component) of S maps to the first components of
- * L, and so on, up to the last component of S mapping to the last
- * components of L. Within this mapping, any single component of S
- * (mapping to multiple components of L) maps its lower-ordered bits
- * to the lower-numbered components of L."
- */
- vtn_fail_if(src[0]->num_components * src[0]->bit_size !=
- glsl_get_vector_elements(type) * glsl_get_bit_size(type),
- "Source and destination of OpBitcast must have the same "
- "total number of bits");
- val->ssa->def = nir_bitcast_vector(&b->nb, src[0],
- glsl_get_bit_size(type));
- break;
-
case SpvOpFConvert: {
nir_alu_type src_alu_type = nir_get_nir_type_for_glsl_type(vtn_src[0]->type);
nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(type);
@@ -681,3 +653,41 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
b->nb.exact = b->exact;
}
+
+void
+vtn_handle_bitcast(struct vtn_builder *b, const uint32_t *w, unsigned count)
+{
+ vtn_assert(count == 4);
+ /* From the definition of OpBitcast in the SPIR-V 1.2 spec:
+ *
+ * "If Result Type has the same number of components as Operand, they
+ * must also have the same component width, and results are computed per
+ * component.
+ *
+ * If Result Type has a different number of components than Operand, the
+ * total number of bits in Result Type must equal the total number of
+ * bits in Operand. Let L be the type, either Result Type or Operand’s
+ * type, that has the larger number of components. Let S be the other
+ * type, with the smaller number of components. The number of components
+ * in L must be an integer multiple of the number of components in S.
+ * The first component (that is, the only or lowest-numbered component)
+ * of S maps to the first components of L, and so on, up to the last
+ * component of S mapping to the last components of L. Within this
+ * mapping, any single component of S (mapping to multiple components of
+ * L) maps its lower-ordered bits to the lower-numbered components of L."
+ */
+
+ struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
+ struct vtn_ssa_value *vtn_src = vtn_ssa_value(b, w[3]);
+ struct nir_ssa_def *src = vtn_src->def;
+ struct vtn_ssa_value *val = vtn_create_ssa_value(b, type->type);
+
+ vtn_assert(glsl_type_is_vector_or_scalar(vtn_src->type));
+
+ vtn_fail_if(src->num_components * src->bit_size !=
+ glsl_get_vector_elements(type->type) * glsl_get_bit_size(type->type),
+ "Source and destination of OpBitcast must have the same "
+ "total number of bits");
+ val->def = nir_bitcast_vector(&b->nb, src, glsl_get_bit_size(type->type));
+ vtn_push_ssa(b, w[2], type, val);
+}
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 0fc2bc4da7b..cfe2893e04f 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -777,6 +777,9 @@ nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
void vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
const uint32_t *w, unsigned count);
+void vtn_handle_bitcast(struct vtn_builder *b, const uint32_t *w,
+ unsigned count);
+
void vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
const uint32_t *w, unsigned count);