break;
case nir_deref_type_ptr_as_array:
if (instr->mode == nir_var_mem_global) {
- unsigned stride = nir_deref_instr_ptr_as_array_stride(instr);
+ unsigned stride = nir_deref_instr_array_stride(instr);
LLVMValueRef index = get_src(ctx, instr->arr.index);
if (LLVMTypeOf(index) != ctx->ac.i64)
bool nir_deref_instr_remove_if_unused(nir_deref_instr *instr);
-unsigned nir_deref_instr_ptr_as_array_stride(nir_deref_instr *instr);
+unsigned nir_deref_instr_array_stride(nir_deref_instr *instr);
typedef struct {
nir_instr instr;
return false;
}
+static unsigned
+type_scalar_size_bytes(const struct glsl_type *type)
+{
+ assert(glsl_type_is_vector_or_scalar(type) ||
+ glsl_type_is_matrix(type));
+ return glsl_type_is_boolean(type) ? 4 : glsl_get_bit_size(type) / 8;
+}
+
unsigned
-nir_deref_instr_ptr_as_array_stride(nir_deref_instr *deref)
+nir_deref_instr_array_stride(nir_deref_instr *deref)
{
switch (deref->deref_type) {
case nir_deref_type_array:
- return glsl_get_explicit_stride(nir_deref_instr_parent(deref)->type);
+ case nir_deref_type_array_wildcard: {
+ const struct glsl_type *arr_type = nir_deref_instr_parent(deref)->type;
+ unsigned stride = glsl_get_explicit_stride(arr_type);
+
+ if ((glsl_type_is_matrix(arr_type) &&
+ glsl_matrix_type_is_row_major(arr_type)) ||
+ (glsl_type_is_vector(arr_type) && stride == 0))
+ stride = type_scalar_size_bytes(arr_type);
+
+ return stride;
+ }
case nir_deref_type_ptr_as_array:
- return nir_deref_instr_ptr_as_array_stride(nir_deref_instr_parent(deref));
+ return nir_deref_instr_array_stride(nir_deref_instr_parent(deref));
case nir_deref_type_cast:
return deref->cast.ptr_stride;
default:
glsl_get_explicit_stride(nir_deref_instr_parent(parent)->type);
} else if (parent->deref_type == nir_deref_type_ptr_as_array) {
return cast->cast.ptr_stride ==
- nir_deref_instr_ptr_as_array_stride(parent);
+ nir_deref_instr_array_stride(parent);
} else {
return false;
}
return build_addr_for_var(b, deref->var, addr_format);
case nir_deref_type_array: {
- nir_deref_instr *parent = nir_deref_instr_parent(deref);
-
- unsigned stride = glsl_get_explicit_stride(parent->type);
- if ((glsl_type_is_matrix(parent->type) &&
- glsl_matrix_type_is_row_major(parent->type)) ||
- (glsl_type_is_vector(parent->type) && stride == 0))
- stride = type_scalar_size_bytes(parent->type);
-
+ unsigned stride = nir_deref_instr_array_stride(deref);
assert(stride > 0);
nir_ssa_def *index = nir_ssa_for_src(b, deref->arr.index, 1);
case nir_deref_type_ptr_as_array: {
nir_ssa_def *index = nir_ssa_for_src(b, deref->arr.index, 1);
index = nir_i2i(b, index, addr_get_offset_bit_size(base_addr, addr_format));
- unsigned stride = nir_deref_instr_ptr_as_array_stride(deref);
+ unsigned stride = nir_deref_instr_array_stride(deref);
return build_addr_iadd(b, base_addr, addr_format,
nir_amul_imm(b, index, stride));
}
return glsl_type_is_boolean(type) ? 4u : glsl_get_bit_size(type) / 8u;
}
-static int
-get_array_stride(const struct glsl_type *type)
-{
- unsigned explicit_stride = glsl_get_explicit_stride(type);
- if ((glsl_type_is_matrix(type) &&
- glsl_matrix_type_is_row_major(type)) ||
- (glsl_type_is_vector(type) && explicit_stride == 0))
- return type_scalar_size_bytes(type);
- return explicit_stride;
-}
-
static uint64_t
mask_sign_extend(uint64_t val, unsigned bit_size)
{
case nir_deref_type_ptr_as_array: {
assert(parent);
nir_ssa_def *index = deref->arr.index.ssa;
- uint32_t stride;
- if (deref->deref_type == nir_deref_type_ptr_as_array)
- stride = nir_deref_instr_ptr_as_array_stride(deref);
- else
- stride = get_array_stride(parent->type);
+ uint32_t stride = nir_deref_instr_array_stride(deref);
nir_ssa_def *base = index;
uint64_t offset = 0, base_mul = 1;
/* avoid adding another deref to the path */
if (deref->deref_type == nir_deref_type_ptr_as_array &&
nir_src_is_const(deref->arr.index) &&
- offset % nir_deref_instr_ptr_as_array_stride(deref) == 0) {
- unsigned stride = nir_deref_instr_ptr_as_array_stride(deref);
+ offset % nir_deref_instr_array_stride(deref) == 0) {
+ unsigned stride = nir_deref_instr_array_stride(deref);
nir_ssa_def *index = nir_imm_intN_t(b, nir_src_as_int(deref->arr.index) - offset / stride,
deref->dest.ssa.bit_size);
return nir_build_deref_ptr_as_array(b, nir_deref_instr_parent(deref), index);
cast->mode = deref->mode;
cast->type = deref->type;
cast->parent = nir_src_for_ssa(block_def);
- cast->cast.ptr_stride = nir_deref_instr_ptr_as_array_stride(deref);
+ cast->cast.ptr_stride = nir_deref_instr_array_stride(deref);
nir_ssa_dest_init(&cast->instr, &cast->dest,
def->num_components, def->bit_size, NULL);
cast->mode = instr->mode;
cast->type = instr->type;
cast->parent = nir_src_for_ssa(&phi->dest.ssa);
- cast->cast.ptr_stride = nir_deref_instr_ptr_as_array_stride(instr);
+ cast->cast.ptr_stride = nir_deref_instr_array_stride(instr);
nir_ssa_dest_init(&cast->instr, &cast->dest,
phi->dest.ssa.num_components,