Commit 9cde974d by Alexis Hetu Committed by Alexis Hétu

Signed and unsigned integer packing and unpacking intrinsic functions

Implementation for packSnorm2x16, unpackSnorm2x16, packUnorm2x16 and unpackUnorm2x16 intrinsic functions. Change-Id: I6b9e2584c1aaad8011f026c217d8ad3f72e9ba45 Reviewed-on: https://swiftshader-review.googlesource.com/5053Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 772d2497
...@@ -228,6 +228,10 @@ namespace sw ...@@ -228,6 +228,10 @@ namespace sw
case Shader::OPCODE_FLOATBITSTOUINT: case Shader::OPCODE_FLOATBITSTOUINT:
case Shader::OPCODE_INTBITSTOFLOAT: case Shader::OPCODE_INTBITSTOFLOAT:
case Shader::OPCODE_UINTBITSTOFLOAT: d = s0; break; case Shader::OPCODE_UINTBITSTOFLOAT: d = s0; break;
case Shader::OPCODE_PACKSNORM2x16: packSnorm2x16(d, s0); break;
case Shader::OPCODE_PACKUNORM2x16: packUnorm2x16(d, s0); break;
case Shader::OPCODE_UNPACKSNORM2x16: unpackSnorm2x16(d, s0); break;
case Shader::OPCODE_UNPACKUNORM2x16: unpackUnorm2x16(d, s0); break;
case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break; case Shader::OPCODE_POWX: powx(d, s0, s1, pp); break;
case Shader::OPCODE_POW: pow(d, s0, s1, pp); break; case Shader::OPCODE_POW: pow(d, s0, s1, pp); break;
case Shader::OPCODE_SGN: sgn(d, s0); break; case Shader::OPCODE_SGN: sgn(d, s0); break;
......
...@@ -1123,6 +1123,34 @@ namespace sw ...@@ -1123,6 +1123,34 @@ namespace sw
Float4 tw = Min(Max((x.w - edge0.w) / (edge1.w - edge0.w), Float4(0.0f)), Float4(1.0f)); dst.w = tw * tw * (Float4(3.0f) - Float4(2.0f) * tw); Float4 tw = Min(Max((x.w - edge0.w) / (edge1.w - edge0.w), Float4(0.0f)), Float4(1.0f)); dst.w = tw * tw * (Float4(3.0f) - Float4(2.0f) * tw);
} }
void ShaderCore::packSnorm2x16(Vector4f &d, const Vector4f &s0)
{
// round(clamp(c, -1.0, 1.0) * 32767.0)
d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) |
((Int4(Round(Min(Max(s0.y, Float4(-1.0f)), Float4(1.0f)) * Float4(32767.0f))) & Int4(0xFFFF)) << 16));
}
void ShaderCore::packUnorm2x16(Vector4f &d, const Vector4f &s0)
{
// round(clamp(c, 0.0, 1.0) * 65535.0)
d.x = As<Float4>((Int4(Round(Min(Max(s0.x, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) |
((Int4(Round(Min(Max(s0.y, Float4(0.0f)), Float4(1.0f)) * Float4(65535.0f))) & Int4(0xFFFF)) << 16));
}
void ShaderCore::unpackSnorm2x16(Vector4f &dst, const Vector4f &s0)
{
// clamp(f / 32727.0, -1.0, 1.0)
dst.x = Min(Max(Float4(As<Int4>((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16)) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
dst.y = Min(Max(Float4(As<Int4>(As<UInt4>(s0.x) & UInt4(0xFFFF0000))) * Float4(1.0f / float(0x7FFF0000)), Float4(-1.0f)), Float4(1.0f));
}
void ShaderCore::unpackUnorm2x16(Vector4f &dst, const Vector4f &s0)
{
// f / 65535.0
dst.x = Float4((As<UInt4>(s0.x) & UInt4(0x0000FFFF)) << 16) * Float4(1.0f / float(0xFFFF0000));
dst.y = Float4(As<UInt4>(s0.x) & UInt4(0xFFFF0000)) * Float4(1.0f / float(0xFFFF0000));
}
void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1) void ShaderCore::det2(Vector4f &dst, const Vector4f &src0, const Vector4f &src1)
{ {
dst.x = src0.x * src1.y - src0.y * src1.x; dst.x = src0.x * src1.y - src0.y * src1.x;
......
...@@ -313,6 +313,10 @@ namespace sw ...@@ -313,6 +313,10 @@ namespace sw
void att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1); void att(Vector4f &dst, const Vector4f &src0, const Vector4f &src1);
void lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2); void lrp(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
void smooth(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2); void smooth(Vector4f &dst, const Vector4f &src0, const Vector4f &src1, const Vector4f &src2);
void packSnorm2x16(Vector4f &dst, const Vector4f &src);
void packUnorm2x16(Vector4f &dst, const Vector4f &src);
void unpackSnorm2x16(Vector4f &dst, const Vector4f &src);
void unpackUnorm2x16(Vector4f &dst, const Vector4f &src);
void frc(Vector4f &dst, const Vector4f &src); void frc(Vector4f &dst, const Vector4f &src);
void trunc(Vector4f &dst, const Vector4f &src); void trunc(Vector4f &dst, const Vector4f &src);
void floor(Vector4f &dst, const Vector4f &src); void floor(Vector4f &dst, const Vector4f &src);
......
...@@ -203,6 +203,10 @@ namespace sw ...@@ -203,6 +203,10 @@ namespace sw
case Shader::OPCODE_FLOATBITSTOUINT: case Shader::OPCODE_FLOATBITSTOUINT:
case Shader::OPCODE_INTBITSTOFLOAT: case Shader::OPCODE_INTBITSTOFLOAT:
case Shader::OPCODE_UINTBITSTOFLOAT: d = s0; break; case Shader::OPCODE_UINTBITSTOFLOAT: d = s0; break;
case Shader::OPCODE_PACKSNORM2x16: packSnorm2x16(d, s0); break;
case Shader::OPCODE_PACKUNORM2x16: packUnorm2x16(d, s0); break;
case Shader::OPCODE_UNPACKSNORM2x16: unpackSnorm2x16(d, s0); break;
case Shader::OPCODE_UNPACKUNORM2x16: unpackUnorm2x16(d, s0); break;
case Shader::OPCODE_M3X2: M3X2(d, s0, src1); break; case Shader::OPCODE_M3X2: M3X2(d, s0, src1); break;
case Shader::OPCODE_M3X3: M3X3(d, s0, src1); break; case Shader::OPCODE_M3X3: M3X3(d, s0, src1); break;
case Shader::OPCODE_M3X4: M3X4(d, s0, src1); break; case Shader::OPCODE_M3X4: M3X4(d, s0, src1); break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment