struct vtn_type *type = val->type;
if (dec->decoration == SpvDecorationArrayStride) {
- vtn_fail_if(dec->operands[0] == 0, "ArrayStride must be non-zero");
- type->stride = dec->operands[0];
+ if (vtn_type_contains_block(b, type)) {
+ vtn_warn("The ArrayStride decoration cannot be applied to an array "
+ "type which contains a structure type decorated Block "
+ "or BufferBlock");
+ /* Ignore the decoration */
+ } else {
+ vtn_fail_if(dec->operands[0] == 0, "ArrayStride must be non-zero");
+ type->stride = dec->operands[0];
+ }
}
}
val->type->deref = vtn_value(b, w[3], vtn_value_type_type)->type;
- vtn_foreach_decoration(b, val, array_stride_decoration_cb, NULL);
+ /* Only certain storage classes use ArrayStride. The others (in
+ * particular Workgroup) are expected to be laid out by the driver.
+ */
+ switch (storage_class) {
+ case SpvStorageClassUniform:
+ case SpvStorageClassPushConstant:
+ case SpvStorageClassStorageBuffer:
+ case SpvStorageClassPhysicalStorageBufferEXT:
+ vtn_foreach_decoration(b, val, array_stride_decoration_cb, NULL);
+ break;
+ default:
+ /* Nothing to do. */
+ break;
+ }
if (b->physical_ptrs) {
switch (storage_class) {
default:
break;
}
- }
-
- if (storage_class == SpvStorageClassWorkgroup &&
- b->options->lower_workgroup_access_to_offsets) {
+ } else if (storage_class == SpvStorageClassWorkgroup &&
+ b->options->lower_workgroup_access_to_offsets) {
+ /* Lay out Workgroup types so it can be lowered to offsets during
+ * SPIR-V to NIR conversion. When not lowering to offsets, the
+ * stride will be calculated by the driver.
+ */
uint32_t size, align;
val->type->deref = vtn_type_layout_std430(b, val->type->deref,
&size, &align);
val->type->length = size;
val->type->align = align;
+ val->type->stride = vtn_align_u32(size, align);
}
}
break;
vtn_value(b, w[4], vtn_value_type_pointer)->pointer;
return;
} else if (opcode == SpvOpImage) {
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
struct vtn_value *src_val = vtn_untyped_value(b, w[3]);
if (src_val->value_type == vtn_value_type_sampled_image) {
- val->pointer = src_val->sampled_image->image;
+ vtn_push_value_pointer(b, w[2], src_val->sampled_image->image);
} else {
vtn_assert(src_val->value_type == vtn_value_type_pointer);
- val->pointer = src_val->pointer;
+ vtn_push_value_pointer(b, w[2], src_val->pointer);
}
return;
}
struct vtn_type *ret_type = vtn_value(b, w[1], vtn_value_type_type)->type;
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
struct vtn_sampled_image sampled;
struct vtn_value *sampled_val = vtn_untyped_value(b, w[3]);
}
}
- val->ssa = vtn_create_ssa_value(b, ret_type->type);
- val->ssa->def = &instr->dest.ssa;
+ struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, ret_type->type);
+ ssa->def = &instr->dest.ssa;
+ vtn_push_ssa(b, w[2], ret_type, ssa);
nir_builder_instr_insert(&b->nb, &instr->instr);
}
}
if (opcode != SpvOpImageWrite && opcode != SpvOpAtomicStore) {
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
unsigned dest_components = glsl_get_vector_elements(type->type);
if (intrin->num_components != dest_components)
result = nir_channels(&b->nb, result, (1 << dest_components) - 1);
- val->ssa = vtn_create_ssa_value(b, type->type);
+ struct vtn_value *val =
+ vtn_push_ssa(b, w[2], type, vtn_create_ssa_value(b, type->type));
val->ssa->def = result;
} else {
nir_builder_instr_insert(&b->nb, &intrin->instr);
glsl_get_vector_elements(type->type),
glsl_get_bit_size(type->type), NULL);
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = rzalloc(b, struct vtn_ssa_value);
- val->ssa->def = &atomic->dest.ssa;
- val->ssa->type = type->type;
+ struct vtn_ssa_value *ssa = rzalloc(b, struct vtn_ssa_value);
+ ssa->def = &atomic->dest.ssa;
+ ssa->type = type->type;
+ vtn_push_ssa(b, w[2], type, ssa);
}
nir_builder_instr_insert(&b->nb, &atomic->instr);
vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
const uint32_t *w, unsigned count)
{
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- const struct glsl_type *type =
- vtn_value(b, w[1], vtn_value_type_type)->type->type;
- val->ssa = vtn_create_ssa_value(b, type);
+ struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
+ struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, type->type);
switch (opcode) {
case SpvOpVectorExtractDynamic:
- val->ssa->def = vtn_vector_extract_dynamic(b, vtn_ssa_value(b, w[3])->def,
- vtn_ssa_value(b, w[4])->def);
+ ssa->def = vtn_vector_extract_dynamic(b, vtn_ssa_value(b, w[3])->def,
+ vtn_ssa_value(b, w[4])->def);
break;
case SpvOpVectorInsertDynamic:
- val->ssa->def = vtn_vector_insert_dynamic(b, vtn_ssa_value(b, w[3])->def,
- vtn_ssa_value(b, w[4])->def,
- vtn_ssa_value(b, w[5])->def);
+ ssa->def = vtn_vector_insert_dynamic(b, vtn_ssa_value(b, w[3])->def,
+ vtn_ssa_value(b, w[4])->def,
+ vtn_ssa_value(b, w[5])->def);
break;
case SpvOpVectorShuffle:
- val->ssa->def = vtn_vector_shuffle(b, glsl_get_vector_elements(type),
- vtn_ssa_value(b, w[3])->def,
- vtn_ssa_value(b, w[4])->def,
- w + 5);
+ ssa->def = vtn_vector_shuffle(b, glsl_get_vector_elements(type->type),
+ vtn_ssa_value(b, w[3])->def,
+ vtn_ssa_value(b, w[4])->def,
+ w + 5);
break;
case SpvOpCompositeConstruct: {
unsigned elems = count - 3;
assume(elems >= 1);
- if (glsl_type_is_vector_or_scalar(type)) {
+ if (glsl_type_is_vector_or_scalar(type->type)) {
nir_ssa_def *srcs[NIR_MAX_VEC_COMPONENTS];
for (unsigned i = 0; i < elems; i++)
srcs[i] = vtn_ssa_value(b, w[3 + i])->def;
- val->ssa->def =
- vtn_vector_construct(b, glsl_get_vector_elements(type),
+ ssa->def =
+ vtn_vector_construct(b, glsl_get_vector_elements(type->type),
elems, srcs);
} else {
- val->ssa->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
+ ssa->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
for (unsigned i = 0; i < elems; i++)
- val->ssa->elems[i] = vtn_ssa_value(b, w[3 + i]);
+ ssa->elems[i] = vtn_ssa_value(b, w[3 + i]);
}
break;
}
case SpvOpCompositeExtract:
- val->ssa = vtn_composite_extract(b, vtn_ssa_value(b, w[3]),
- w + 4, count - 4);
+ ssa = vtn_composite_extract(b, vtn_ssa_value(b, w[3]),
+ w + 4, count - 4);
break;
case SpvOpCompositeInsert:
- val->ssa = vtn_composite_insert(b, vtn_ssa_value(b, w[4]),
- vtn_ssa_value(b, w[3]),
- w + 5, count - 5);
+ ssa = vtn_composite_insert(b, vtn_ssa_value(b, w[4]),
+ vtn_ssa_value(b, w[3]),
+ w + 5, count - 5);
break;
case SpvOpCopyLogical:
case SpvOpCopyObject:
- val->ssa = vtn_composite_copy(b, vtn_ssa_value(b, w[3]));
+ ssa = vtn_composite_copy(b, vtn_ssa_value(b, w[3]));
break;
default:
vtn_fail_with_opcode("unknown composite operation", opcode);
}
+
+ vtn_push_ssa(b, w[2], type, ssa);
}
static void
}
case SpvOpControlBarrier: {
- SpvScope execution_scope = vtn_constant_uint(b, w[1]);
- if (execution_scope == SpvScopeWorkgroup)
- vtn_emit_barrier(b, nir_intrinsic_barrier);
-
SpvScope memory_scope = vtn_constant_uint(b, w[2]);
SpvMemorySemanticsMask memory_semantics = vtn_constant_uint(b, w[3]);
vtn_emit_memory_barrier(b, memory_scope, memory_semantics);
+
+ SpvScope execution_scope = vtn_constant_uint(b, w[1]);
+ if (execution_scope == SpvScopeWorkgroup)
+ vtn_emit_barrier(b, nir_intrinsic_barrier);
break;
}
spv_check_supported(fragment_shader_pixel_interlock, cap);
break;
+ case SpvCapabilityDemoteToHelperInvocationEXT:
+ spv_check_supported(demote_to_helper_invocation, cap);
+ break;
+
default:
vtn_fail("Unhandled capability: %s (%u)",
spirv_capability_to_string(cap), cap);
"%s operands must have the same storage class",
spirv_op_to_string(opcode));
- const struct glsl_type *type =
- vtn_value(b, w[1], vtn_value_type_type)->type->type;
+ struct vtn_type *vtn_type =
+ vtn_value(b, w[1], vtn_value_type_type)->type;
+ const struct glsl_type *type = vtn_type->type;
nir_address_format addr_format = vtn_mode_to_address_format(
b, vtn_storage_class_to_mode(b, type1->storage_class, NULL, NULL));
unreachable("Invalid ptr operation");
}
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = vtn_create_ssa_value(b, type);
- val->ssa->def = def;
+ struct vtn_ssa_value *ssa_value = vtn_create_ssa_value(b, type);
+ ssa_value->def = def;
+ vtn_push_ssa(b, w[2], vtn_type, ssa_value);
}
static bool
vtn_emit_barrier(b, nir_intrinsic_end_invocation_interlock);
break;
+ case SpvOpDemoteToHelperInvocationEXT: {
+ nir_intrinsic_instr *intrin =
+ nir_intrinsic_instr_create(b->shader, nir_intrinsic_demote);
+ nir_builder_instr_insert(&b->nb, &intrin->instr);
+ break;
+ }
+
+ case SpvOpIsHelperInvocationEXT: {
+ nir_intrinsic_instr *intrin =
+ nir_intrinsic_instr_create(b->shader, nir_intrinsic_is_helper_invocation);
+ nir_ssa_dest_init(&intrin->instr, &intrin->dest, 1, 1, NULL);
+ nir_builder_instr_insert(&b->nb, &intrin->instr);
+
+ struct vtn_type *res_type =
+ vtn_value(b, w[1], vtn_value_type_type)->type;
+ struct vtn_ssa_value *val = vtn_create_ssa_value(b, res_type->type);
+ val->def = &intrin->dest.ssa;
+
+ vtn_push_ssa(b, w[2], res_type, val);
+ break;
+ }
+
default:
vtn_fail_with_opcode("Unhandled opcode", opcode);
}