Do not unpack transposed matrices.

This commit is contained in:
Hans-Kristian Arntzen 2018-06-12 09:36:13 +02:00
Родитель 192a882df3
Коммит 58fab58e5e
6 изменённых файлов: 21 добавлений и 6 удалений

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

@ -121,6 +121,6 @@ kernel void main0(device SSBO0& ssbo_140 [[buffer(0)]], device SSBO1& ssbo_430 [
ssbo_430.content.m3s[5].c = _60.m3s[5].c;
ssbo_430.content.m3s[6].c = _60.m3s[6].c;
ssbo_430.content.m3s[7].c = _60.m3s[7].c;
ssbo_430.content.m1.a = ssbo_430.content.m3.a * float2x3(ssbo_430.m6[1][1]);
ssbo_430.content.m1.a = ssbo_430.content.m3.a * ssbo_430.m6[1][1];
}

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

@ -41,7 +41,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant _42& _44 [[buffer(12)]
{
main0_out out = {};
float4 _70 = _44._m0 * float4(float3(_44._m3) + (in.m_25.xyz * (_44._m6 + _44._m7)), 1.0);
out.m_72 = normalize(float4(in.m_25.xyz, 0.0) * float4x3(_17._m1));
out.m_72 = normalize(float4(in.m_25.xyz, 0.0) * _17._m1);
float4 _95 = _70;
_95.y = -_70.y;
out.gl_Position = _95;

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

@ -144,6 +144,6 @@ kernel void main0(device SSBO0& ssbo_140 [[buffer(0)]], device SSBO1& ssbo_430 [
ssbo_430.content.m3s[5].c = _60.m3s[5].c;
ssbo_430.content.m3s[6].c = _60.m3s[6].c;
ssbo_430.content.m3s[7].c = _60.m3s[7].c;
ssbo_430.content.m1.a = ssbo_430.content.m3.a * float2x3(ssbo_430.m6[1][1]);
ssbo_430.content.m1.a = ssbo_430.content.m3.a * ssbo_430.m6[1][1];
}

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

@ -44,7 +44,7 @@ vertex main0_out main0(main0_in in [[stage_in]], constant _42& _44 [[buffer(12)]
float3 _13;
do
{
_13 = normalize(float4(in.m_25.xyz, 0.0) * float4x3(_17._m1));
_13 = normalize(float4(in.m_25.xyz, 0.0) * _17._m1);
break;
} while (false);
float4 _39 = _44._m0 * float4(float3(_44._m3) + (in.m_25.xyz * (_44._m6 + _44._m7)), 1.0);

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

@ -2375,7 +2375,10 @@ string CompilerGLSL::to_enclosed_expression(uint32_t id)
string CompilerGLSL::to_unpacked_expression(uint32_t id)
{
if (has_decoration(id, DecorationCPacked))
// If we need to transpose, it will also take care of unpacking rules.
auto *e = maybe_get<SPIRExpression>(id);
bool need_transpose = e && e->need_transpose;
if (!need_transpose && has_decoration(id, DecorationCPacked))
return unpack_expression_type(to_expression(id), expression_type(id));
else
return to_expression(id);
@ -2383,7 +2386,10 @@ string CompilerGLSL::to_unpacked_expression(uint32_t id)
string CompilerGLSL::to_enclosed_unpacked_expression(uint32_t id)
{
if (has_decoration(id, DecorationCPacked))
// If we need to transpose, it will also take care of unpacking rules.
auto *e = maybe_get<SPIRExpression>(id);
bool need_transpose = e && e->need_transpose;
if (!need_transpose && has_decoration(id, DecorationCPacked))
return unpack_expression_type(to_expression(id), expression_type(id));
else
return to_enclosed_expression(id);

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

@ -2042,7 +2042,16 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
if (e && e->need_transpose && (t.columns == t.vecsize || is_packed))
{
e->need_transpose = false;
// This is important for matrices. Packed matrices
// are generally transposed, so unpacking using a constructor argument
// will result in an error.
// The simplest solution for now is to just avoid unpacking the matrix in this operation.
unset_decoration(mtx_id, DecorationCPacked);
emit_binary_op(ops[0], ops[1], ops[3], ops[2], "*");
if (is_packed)
set_decoration(mtx_id, DecorationCPacked);
e->need_transpose = true;
}
else