switch (dec->decoration) {
case SpvDecorationArrayStride:
assert(type->base_type == vtn_base_type_matrix ||
- type->base_type == vtn_base_type_array);
+ type->base_type == vtn_base_type_array ||
+ type->base_type == vtn_base_type_pointer);
type->stride = dec->literals[0];
break;
case SpvDecorationBlock:
case SpvOpCopyMemory:
case SpvOpCopyMemorySized:
case SpvOpAccessChain:
+ case SpvOpPtrAccessChain:
case SpvOpInBoundsAccessChain:
case SpvOpArrayLength:
vtn_handle_variables(b, opcode, w, count);
/* Specifies the length of complex types. */
unsigned length;
+ /* for arrays, matrices and pointers, the array stride */
+ unsigned stride;
+
union {
/* Members for scalar, vector, and array-like types */
struct {
/* for arrays, the vtn_type for the elements of the array */
struct vtn_type *array_element;
- /* for arrays and matrices, the array stride */
- unsigned stride;
-
/* for matrices, whether the matrix is stored row-major */
bool row_major:1;
struct vtn_access_chain {
uint32_t length;
+ /** Whether or not to treat the base pointer as an array. This is only
+ * true if this access chain came from an OpPtrAccessChain.
+ */
+ bool ptr_as_array;
+
/** Struct elements and array offsets.
*
* This is an array of 1 so that it can conveniently be created on the
vtn_access_chain_extend(b, base->chain, deref_chain->length);
struct vtn_type *type = base->type;
+ /* OpPtrAccessChain is only allowed on things which support variable
+ * pointers. For everything else, the client is expected to just pass us
+ * the right access chain.
+ */
+ assert(!deref_chain->ptr_as_array);
+
unsigned start = base->chain ? base->chain->length : 0;
for (unsigned i = 0; i < deref_chain->length; i++) {
chain->link[start + i] = deref_chain->link[i];
struct vtn_type *type = base->type;
unsigned idx = 0;
+ if (deref_chain->ptr_as_array) {
+ /* We need ptr_type for the stride */
+ assert(base->ptr_type);
+ /* This must be a pointer to an actual element somewhere */
+ assert(block_index && offset);
+ /* We need at least one element in the chain */
+ assert(deref_chain->length >= 1);
+
+ nir_ssa_def *elem_offset =
+ vtn_access_link_as_ssa(b, deref_chain->link[idx],
+ base->ptr_type->stride);
+ offset = nir_iadd(&b->nb, offset, elem_offset);
+ idx++;
+ }
+
if (!block_index) {
assert(base->var);
if (glsl_type_is_array(type->type)) {
}
case SpvOpAccessChain:
+ case SpvOpPtrAccessChain:
case SpvOpInBoundsAccessChain: {
struct vtn_access_chain *chain = vtn_access_chain_create(b, count - 4);
+ chain->ptr_as_array = (opcode == SpvOpPtrAccessChain);
unsigned idx = 0;
for (int i = 4; i < count; i++) {