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

@@ -94,8 +94,11 @@ mark_whole_variable(nir_shader *shader, nir_variable *var)
var->data.mode == nir_var_shader_in)
is_vertex_input = true;
set_io_mask(shader, var, 0,
glsl_count_attribute_slots(type, is_vertex_input));
const unsigned slots =
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
: glsl_count_attribute_slots(type, is_vertex_input);
set_io_mask(shader, var, 0, slots);
}
static unsigned
@@ -150,7 +153,7 @@ try_mask_partial_io(nir_shader *shader, nir_deref_var *deref)
* here marking the entire variable as used.
*/
if (!(glsl_type_is_matrix(type) ||
(glsl_type_is_array(type) &&
(glsl_type_is_array(type) && !var->data.compact &&
(glsl_type_is_numeric(glsl_without_array(type)) ||
glsl_type_is_boolean(glsl_without_array(type)))))) {