ec054dad7f
Emit synthetic functions before function constants. Support use of spvQuantizeToF16() in function constants for numerical behavior consistency with the op code. Ensure subnormal results from OpQuantizeToF16 are flushed to zero per SPIR-V spec. Adjust SPIRV-Cross unit test reference shaders to accommodate these changes. Any MSL reference shader that inclues a synthetic function is affected, since the location it is emitted has changed.
54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
|
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using namespace metal;
|
|
|
|
// Implementation of the GLSL findLSB() function
|
|
template<typename T>
|
|
inline T spvFindLSB(T x)
|
|
{
|
|
return select(ctz(x), T(-1), x == T(0));
|
|
}
|
|
|
|
// Implementation of the signed GLSL findMSB() function
|
|
template<typename T>
|
|
inline T spvFindSMSB(T x)
|
|
{
|
|
T v = select(x, T(-1) - x, x < T(0));
|
|
return select(clz(T(0)) - (clz(v) + T(1)), T(-1), v == T(0));
|
|
}
|
|
|
|
// Implementation of the unsigned GLSL findMSB() function
|
|
template<typename T>
|
|
inline T spvFindUMSB(T x)
|
|
{
|
|
return select(clz(T(0)) - (clz(x) + T(1)), T(-1), x == T(0));
|
|
}
|
|
|
|
struct SSBO
|
|
{
|
|
uint4 u;
|
|
int4 i;
|
|
};
|
|
|
|
kernel void main0(device SSBO& _4 [[buffer(0)]])
|
|
{
|
|
uint4 _19 = _4.u;
|
|
int4 _20 = _4.i;
|
|
_4.u = spvFindLSB(_19);
|
|
_4.i = int4(spvFindLSB(_19));
|
|
_4.u = uint4(spvFindLSB(_20));
|
|
_4.i = spvFindLSB(_20);
|
|
_4.u = spvFindUMSB(_19);
|
|
_4.i = int4(spvFindUMSB(_19));
|
|
_4.u = spvFindUMSB(uint4(_20));
|
|
_4.i = int4(spvFindUMSB(uint4(_20)));
|
|
_4.u = uint4(spvFindSMSB(int4(_19)));
|
|
_4.i = spvFindSMSB(int4(_19));
|
|
_4.u = uint4(spvFindSMSB(_20));
|
|
_4.i = spvFindSMSB(_20);
|
|
}
|
|
|