Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/hlsl.y:
return !!add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_ABS, params->args[0], loc);
}
+/*
- Based on Microsoft's D3D compiler's output.
- Approximate `acos(|x|) / sqrt(1 - |x|))` using a cubic, then correct
- by multiplying sqrt(1 - |x|) and flipping across pi if x<0.
- acos has a slope of -infinity around 1,
- which polynomial approximations can't do very well.
- 1/sqrt(1-x) has a slope of infinity around 1,
- so multiplying the two ends up with a reasonably flat slope
- that a polynomial can approximate.
+*/
This comment doesn't look very useful to me: virtually everything in the HLSL compiler is based on the Microsoft compiler, since the point of our HLSL compiler is to be a drop-in replacement of native. Given that, there is little point in justifying the numerical algorithm: we're just replicating what the native compiler does, but we're not really interested in justifying this kind of detail.