More fixes to handling packing & access elements in an array. Made in two parts. 1. Don't allow AccessChain operations to add duplicated swizzles when accessing packed arrays. 2. Only pack arrays when there is the proper amount of space between members in a struct, otherwise it will definitely be wrong.

This commit is contained in:
Mark Satterthwaite 2019-08-14 11:23:49 -04:00 committed by Lukas Hermanns
parent 564cb3c08d
commit e4c6388571
2 changed files with 11 additions and 3 deletions

View File

@ -7567,7 +7567,7 @@ bool CompilerGLSL::remove_unity_swizzle(uint32_t base, string &op)
auto &type = expression_type(base);
// Sanity checking ...
assert(type.columns == 1 && type.array.empty());
assert(type.columns == 1); // && type.array.empty()
if (type.vecsize == final_swiz.size())
op.erase(pos, string::npos);

View File

@ -8014,7 +8014,7 @@ string CompilerMSL::to_struct_member(const SPIRType &type, uint32_t member_type_
SPIRType row_major_physical_type;
const SPIRType *declared_type = &physical_type;
if (member_is_packed_physical_type(type, index))
if (member_is_packed_physical_type(type, index) && validate_member_packing_rules_msl(type, index))
{
// If we're packing a matrix, output an appropriate typedef
if (physical_type.basetype == SPIRType::Struct)
@ -11941,6 +11941,14 @@ std::string CompilerMSL::access_chain_internal(uint32_t base, const uint32_t *in
else if (ir.meta[base].decoration.builtin_type != BuiltInSampleMask)
/* UE Change End: Sample mask input for Metal is not an array */
{
if (is_packed)
{
if (!remove_duplicate_swizzle(expr))
remove_unity_swizzle(base, expr);
append_index(index);
expr = unpack_expression_type(expr, *type, physical_type, is_packed, true);
}
else
append_index(index);
}