glsl: Pack flat "varyings" of mixed types together.

This patch enhances the varying packing code so that flat varyings of
uint, int, and float types can be packed together.

We accomplish this in lower_packed_varyings.cpp by making the type of
all flat varyings ivec4, and then using information-preserving type
conversions (e.g. ir_unop_bitcast_f2i) to convert all other types to
ints.

The varying_matches::compute_packing_class() function is updated to
reflect the fact that varying packing no longer needs to segregate
varyings of different base types.

Fixes piglit test varying-packing-mixed-types.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>

v2: Split lower_packed_varyings_visitor::bitwise_assign into
pack/unpack variants.
This commit is contained in:
Paul Berry
2012-12-18 16:37:52 -08:00
parent 18720555dd
commit c35abcd1b0
2 changed files with 101 additions and 14 deletions

View File

@@ -777,17 +777,25 @@ varying_matches::store_locations(unsigned producer_base,
unsigned
varying_matches::compute_packing_class(ir_variable *var)
{
/* In this initial implementation we conservatively assume that variables
* can only be packed if their base type (float/int/uint/bool) matches and
* their interpolation and centroid qualifiers match.
/* Without help from the back-end, there is no way to pack together
* variables with different interpolation types, because
* lower_packed_varyings must choose exactly one interpolation type for
* each packed varying it creates.
*
* TODO: relax these restrictions when the driver back-end permits.
* However, we can safely pack together floats, ints, and uints, because:
*
* - varyings of base type "int" and "uint" must use the "flat"
* interpolation type, which can only occur in GLSL 1.30 and above.
*
* - On platforms that support GLSL 1.30 and above, lower_packed_varyings
* can store flat floats as ints without losing any information (using
* the ir_unop_bitcast_* opcodes).
*
* Therefore, the packing class depends only on the interpolation type.
*/
unsigned packing_class = var->centroid ? 1 : 0;
packing_class *= 4;
packing_class += var->interpolation;
packing_class *= GLSL_TYPE_ERROR;
packing_class += var->type->get_scalar_type()->base_type;
return packing_class;
}