Access chain into packed vectors as arrays.

Cleaner and should be more compatible with storing to packed vector
elements.

Fix CompositeExtract bug with packed vectors on MSL.
This commit is contained in:
Hans-Kristian Arntzen 2018-03-13 12:13:01 +01:00
Родитель a6afda650f
Коммит b46910e9f5
4 изменённых файлов: 16 добавлений и 12 удалений

Просмотреть файл

@ -39,7 +39,7 @@ vertex main0_out main0(constant UBO& _22 [[buffer(0)]])
out.oA = _22.A;
out.oB = float4(_22.B0, _22.B1);
out.oC = float4(_22.C0, _22.C1) + float4(_22.C1.xy, _22.C1.z, _22.C0);
out.oD = float4(_22.D0, _22.D1) + float4(_22.D0.xy, float3(_22.D0).z, _22.D1);
out.oD = float4(_22.D0[0], _22.D0[1], _22.D0[2], _22.D1) + float4(_22.D0[0], _22.D0[1], _22.D0[2u], _22.D1);
out.oE = float4(_22.E0, _22.E1, _22.E2, _22.E3);
out.oF = float4(_22.F0, _22.F1, _22.F2);
return out;

Просмотреть файл

@ -22,7 +22,7 @@ struct main0_out
fragment main0_out main0(constant CB0& _26 [[buffer(0)]], float4 gl_FragCoord [[position]])
{
main0_out out = {};
out._entryPointOutput = float4(_26.CB0[1].position, _26.CB0[1].radius);
out._entryPointOutput = float4(_26.CB0[1].position[0], _26.CB0[1].position[1], _26.CB0[1].position[2], _26.CB0[1].radius);
return out;
}

Просмотреть файл

@ -39,7 +39,7 @@ vertex main0_out main0(constant UBO& _22 [[buffer(0)]])
out.oA = _22.A;
out.oB = float4(_22.B0, _22.B1);
out.oC = float4(_22.C0, _22.C1) + float4(_22.C1.xy, _22.C1.z, _22.C0);
out.oD = float4(_22.D0, _22.D1) + float4(float3(_22.D0).xy, float3(_22.D0).z, _22.D1);
out.oD = float4(_22.D0[0], _22.D0[1], _22.D0[2], _22.D1) + float4(float3(_22.D0).xy, _22.D0[2u], _22.D1);
out.oE = float4(_22.E0, _22.E1, _22.E2, _22.E3);
out.oF = float4(_22.F0, _22.F1, _22.F2);
return out;

Просмотреть файл

@ -4667,7 +4667,7 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
bool access_chain_is_arrayed = false;
bool row_major_matrix_needs_conversion = is_non_native_row_major_matrix(base);
bool is_packed = false;
bool is_packed = has_decoration(base, DecorationCPacked);
bool pending_array_enclose = false;
bool dimension_flatten = false;
@ -4826,23 +4826,22 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
// Vector -> Scalar
else if (type->vecsize > 1)
{
if (is_packed)
{
expr = unpack_expression_type(expr, *type);
is_packed = false;
}
if (index_is_literal)
if (index_is_literal && !is_packed)
{
expr += ".";
expr += index_to_swizzle(index);
}
else if (ids[index].get_type() == TypeConstant)
else if (ids[index].get_type() == TypeConstant && !is_packed)
{
auto &c = get<SPIRConstant>(index);
expr += ".";
expr += index_to_swizzle(c.scalar());
}
else if (index_is_literal)
{
// For packed vectors, we can only access them as an array, not by swizzle.
expr += join("[", index, "]");
}
else
{
expr += "[";
@ -4850,6 +4849,7 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
expr += "]";
}
is_packed = false;
type_id = type->parent_type;
type = &get<SPIRType>(type_id);
}
@ -5993,6 +5993,10 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
if (composite_type.basetype == SPIRType::Struct || !composite_type.array.empty())
allow_base_expression = false;
// Packed expressions cannot be split up.
if (has_decoration(ops[2], DecorationCPacked))
allow_base_expression = false;
// Only apply this optimization if result is scalar.
if (allow_base_expression && should_forward(ops[2]) && type.vecsize == 1 && type.columns == 1 && length == 1)
{