[Mesa-dev] [RESEND PATCH 1/2] mesa: correctly calculate the storage offset for i915
Timothy Arceri
tarceri at itsqueeze.com
Mon Aug 14 00:41:19 UTC 2017
When generating the storage offset for struct members we need
to skip opaque types as they no longer have backing storage.
Fixes: fcbb93e86024 ("mesa: stop assigning unused storage for non-bindless opaque types")
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101983
---
src/mesa/program/ir_to_mesa.cpp | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index e141ac4b71..626dcadd86 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -492,21 +492,21 @@ ir_to_mesa_visitor::src_reg_for_float(float val)
{
src_reg src(PROGRAM_CONSTANT, -1, NULL);
src.index = _mesa_add_unnamed_constant(this->prog->Parameters,
(const gl_constant_value *)&val, 1, &src.swizzle);
return src;
}
static int
-type_size(const struct glsl_type *type)
+storage_type_size(const struct glsl_type *type, bool bindless)
{
unsigned int i;
int size;
switch (type->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
if (type->is_matrix()) {
@@ -534,46 +534,52 @@ type_size(const struct glsl_type *type)
}
break;
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
if (type->vector_elements > 2)
return 2;
else
return 1;
case GLSL_TYPE_ARRAY:
assert(type->length > 0);
- return type_size(type->fields.array) * type->length;
+ return storage_type_size(type->fields.array, bindless) * type->length;
case GLSL_TYPE_STRUCT:
size = 0;
for (i = 0; i < type->length; i++) {
- size += type_size(type->fields.structure[i].type);
+ size += storage_type_size(type->fields.structure[i].type, bindless);
}
return size;
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
+ if (!bindless)
+ return 0;
+ /* fall through */
case GLSL_TYPE_SUBROUTINE:
- /* Samplers take up one slot in UNIFORMS[], but they're baked in
- * at link time.
- */
return 1;
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_FUNCTION:
assert(!"Invalid type in type_size");
break;
}
return 0;
}
+static int
+type_size(const struct glsl_type *type)
+{
+ return storage_type_size(type, true);
+}
+
/**
* In the initial pass of codegen, we assign temporary numbers to
* intermediate results. (not SSA -- variable assignments will reuse
* storage). Actual register allocation for the Mesa VM occurs in a
* pass over the Mesa IR later.
*/
src_reg
ir_to_mesa_visitor::get_temp(const glsl_type *type)
{
src_reg src;
@@ -1534,21 +1540,27 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
}
this->result = src_reg(entry->file, entry->index, var->type);
}
void
ir_to_mesa_visitor::visit(ir_dereference_array *ir)
{
ir_constant *index;
src_reg src;
- int element_size = type_size(ir->type);
+ ir_variable *var = ir->variable_referenced();
+
+ /* We only need the logic provided by storage_type_size() for arrays of
+ * structs. Indirect sampler and image indexing is handled elsewhere.
+ */
+ int element_size = ir->type->without_array()->is_record() ?
+ storage_type_size(ir->type, var->data.bindless) : type_size(ir->type);
index = ir->array_index->constant_expression_value(ralloc_parent(ir));
ir->array->accept(this);
src = this->result;
if (index) {
src.index += index->value.i[0] * element_size;
} else {
/* Variable index array dereference. It eats the "vec4" of the
@@ -1591,29 +1603,31 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir)
src.swizzle = SWIZZLE_NOOP;
this->result = src;
}
void
ir_to_mesa_visitor::visit(ir_dereference_record *ir)
{
unsigned int i;
const glsl_type *struct_type = ir->record->type;
+ ir_variable *var = ir->record->variable_referenced();
int offset = 0;
ir->record->accept(this);
assert(ir->field_idx >= 0);
for (i = 0; i < struct_type->length; i++) {
if (i == (unsigned) ir->field_idx)
break;
- offset += type_size(struct_type->fields.structure[i].type);
+ offset += storage_type_size(struct_type->fields.structure[i].type,
+ var->data.bindless);
}
/* If the type is smaller than a vec4, replicate the last channel out. */
if (ir->type->is_scalar() || ir->type->is_vector())
this->result.swizzle = swizzle_for_size(ir->type->vector_elements);
else
this->result.swizzle = SWIZZLE_NOOP;
this->result.index += offset;
}
--
2.13.4
More information about the mesa-dev
mailing list