Refactor float to fixed-point conversion
convertFixed16() and convertFloat32() are relics from when SwiftShader
had both a programmable floating-point fragment pipeline and a fixed-
function pipeline. Back then it made sense to abstract these common
conversions, but more recently it was no longer used for the same
purpose and it obscured important information like the actual
normalization factor. So this change eliminates them and performs the
conversions explicitly in the few remaining places where these functions
were still being used.
Also, 0xFFFFu has been replaced with 0xFFFF where the (un)signedness
has no effect. The latter is slightly easier on the eyes to parse.
Bug: b/204919030
Change-Id: Ie822319b687555baefbb11a7120a422c5653e28d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/67048
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Sean Risser <srisser@google.com>
diff --git a/src/Pipeline/PixelProgram.cpp b/src/Pipeline/PixelProgram.cpp
index 6eb60b0..9933839 100644
--- a/src/Pipeline/PixelProgram.cpp
+++ b/src/Pipeline/PixelProgram.cpp
@@ -306,10 +306,10 @@
ASSERT(SIMD::Width == 4);
Vector4s color;
- color.x = convertFixed16(Extract128(colorf.x, 0), true);
- color.y = convertFixed16(Extract128(colorf.y, 0), true);
- color.z = convertFixed16(Extract128(colorf.z, 0), true);
- color.w = convertFixed16(Extract128(colorf.w, 0), true);
+ color.x = UShort4(Extract128(colorf.x, 0) * 0xFFFF, true); // Saturating
+ color.y = UShort4(Extract128(colorf.y, 0) * 0xFFFF, true); // Saturating
+ color.z = UShort4(Extract128(colorf.z, 0) * 0xFFFF, true); // Saturating
+ color.w = UShort4(Extract128(colorf.w, 0) * 0xFFFF, true); // Saturating
writeColor(index, buffer, x, color, sMask[q], zMask[q], cMask[q]);
}
break;