Fix #1445: MSL: Enclose args when convert distance(a,b) to abs(a-b)

This commit is contained in:
Le Hoang Quyen 2020-08-13 16:57:13 +08:00
parent 82d1c43e40
commit ab8eb70af1
4 changed files with 8 additions and 1 deletions

View File

@ -10,6 +10,7 @@ struct SSBO
float c;
float d;
float e;
float f;
};
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
@ -19,5 +20,6 @@ kernel void main0(device SSBO& _9 [[buffer(0)]])
_9.c = abs(_9.a - _9.b);
_9.d = abs(_9.a);
_9.e = sign(_9.a);
_9.f = abs((_9.a - 1.0) - (_9.b - 2.0));
}

View File

@ -10,6 +10,7 @@ struct SSBO
float c;
float d;
float e;
float f;
};
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
@ -19,5 +20,6 @@ kernel void main0(device SSBO& _9 [[buffer(0)]])
_9.c = abs(_9.a - _9.b);
_9.d = abs(_9.a);
_9.e = sign(_9.a);
_9.f = abs((_9.a - 1.0) - (_9.b - 2.0));
}

View File

@ -8,6 +8,7 @@ layout(std430, set = 0, binding = 0) buffer SSBO
float c;
float d;
float e;
float f;
};
void main()
@ -15,4 +16,5 @@ void main()
c = distance(a, b);
d = length(a);
e = normalize(a);
f = distance(a-1, b-2);
}

View File

@ -7541,7 +7541,8 @@ void CompilerMSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop,
{
// Equivalent to length(a - b) -> abs(a - b).
emit_op(result_type, id,
join("abs(", to_unpacked_expression(args[0]), " - ", to_unpacked_expression(args[1]), ")"),
join("abs(", to_enclosed_unpacked_expression(args[0]), " - ",
to_enclosed_unpacked_expression(args[1]), ")"),
should_forward(args[0]) && should_forward(args[1]));
inherit_expression_dependencies(id, args[0]);
inherit_expression_dependencies(id, args[1]);