summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2011-10-26 16:11:27 -0700
committerEric Anholt <[email protected]>2011-10-28 12:10:01 -0700
commit00d3716f4a91145609f50aa56de53e175d1c8b49 (patch)
tree4fabb91f4d85b00cd3ba4b9d73427a03e457d411 /src/gallium/auxiliary
parentb4d988bc9f36fddbe0cc92ea6e267d307f6d1112 (diff)
u_format: Fix clamping of overflow in 10F_11F_11F_REV to match GL specs.
Fixes the 1000000.0 overflow cases of piglit GL_EXT_packed_float/pack.c Reviewed-by: Marek Ol ák <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/util/u_format_r11g11b10f.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/gallium/auxiliary/util/u_format_r11g11b10f.h b/src/gallium/auxiliary/util/u_format_r11g11b10f.h
index 5c05b7953cc..000a5c25bfc 100644
--- a/src/gallium/auxiliary/util/u_format_r11g11b10f.h
+++ b/src/gallium/auxiliary/util/u_format_r11g11b10f.h
@@ -27,6 +27,7 @@
* below.
*/
+#define UF11(e, m) ((e << 6) | (m))
#define UF11_EXPONENT_BIAS 15
#define UF11_EXPONENT_BITS 0x1F
#define UF11_EXPONENT_SHIFT 6
@@ -34,6 +35,7 @@
#define UF11_MANTISSA_SHIFT (23 - UF11_EXPONENT_SHIFT)
#define UF11_MAX_EXPONENT (UF11_EXPONENT_BITS << UF11_EXPONENT_SHIFT)
+#define UF10(e, m) ((e << 5) | (m))
#define UF10_EXPONENT_BIAS 15
#define UF10_EXPONENT_BITS 0x1F
#define UF10_EXPONENT_SHIFT 5
@@ -64,8 +66,14 @@ static INLINE unsigned f32_to_uf11(float val)
uf11 = UF11_MAX_EXPONENT;
if (mantissa) uf11 |= (mantissa & UF11_MANTISSA_BITS);
}
- else if (exponent > 15) { /* Overflow - flush to Infinity */
- uf11 = UF11_MAX_EXPONENT;
+ else if (val > 65024.0f) {
+ /* From the GL_EXT_packed_float spec:
+ *
+ * "Likewise, finite positive values greater than 65024 (the maximum
+ * finite representable unsigned 11-bit floating-point value) are
+ * converted to 65024."
+ */
+ uf11 = UF11(30, 63);
}
else if (exponent > -15) { /* Representable value */
exponent += UF11_EXPONENT_BIAS;
@@ -134,8 +142,14 @@ static INLINE unsigned f32_to_uf10(float val)
uf10 = UF10_MAX_EXPONENT;
if (mantissa) uf10 |= (mantissa & UF10_MANTISSA_BITS);
}
- else if (exponent > 15) { /* Overflow - flush to Infinity */
- uf10 = UF10_MAX_EXPONENT;
+ else if (val > 64512.0f) { /* Overflow - flush to Infinity */
+ /* From the GL_EXT_packed_float spec:
+ *
+ * "Likewise, finite positive values greater than 64512 (the maximum
+ * finite representable unsigned 10-bit floating-point value) are
+ * converted to 64512."
+ */
+ uf10 = UF10(30, 31);
}
else if (exponent > -15) { /* Representable value */
exponent += UF10_EXPONENT_BIAS;