nir: Add a "compact array" flag and IO lowering code.

Certain built-in arrays, such as gl_ClipDistance[], gl_CullDistance[],
gl_TessLevelInner[], and gl_TessLevelOuter[] are specified as scalar
arrays.  Normal scalar arrays are sparse - each array element usually
occupies a whole vec4 slot.  However, most hardware assumes these
built-in arrays are tightly packed.

The new var->data.compact flag indicates that a scalar array should
be tightly packed, so a float[4] array would take up a single vec4
slot, and a float[8] array would take up two slots.

They are still arrays, not vec4s, however.  nir_lower_io will generate
intrinsics using ARB_enhanced_layouts style component qualifiers.

v2: Add nir_validate code to enforce type restrictions.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Kenneth Graunke
2016-10-03 20:32:22 -07:00
parent f395e3445d
commit 663b2e9a92
7 changed files with 67 additions and 18 deletions

View File

@@ -942,6 +942,19 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state)
/* Must have exactly one mode set */
validate_assert(state, util_bitcount(var->data.mode) == 1);
if (var->data.compact) {
/* The "compact" flag is only valid on arrays of scalars. */
assert(glsl_type_is_array(var->type));
const struct glsl_type *type = glsl_get_array_element(var->type);
if (nir_is_per_vertex_io(var, state->shader->stage)) {
assert(glsl_type_is_array(type));
assert(glsl_type_is_scalar(glsl_get_array_element(type)));
} else {
assert(glsl_type_is_scalar(type));
}
}
/*
* TODO validate some things ir_validate.cpp does (requires more GLSL type
* support)