summaryrefslogtreecommitdiff
path: root/src/mesa/drivers
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2017-06-16 00:13:45 -0700
committerAndres Gomez <agomez@igalia.com>2017-06-28 20:15:05 +0300
commit8b7ba85705d2a895aca0a5a2113200154c485a68 (patch)
tree9ee1437da43d7e2024b816584f40e6a5e9b8b505 /src/mesa/drivers
parentccf9de7a59cd709e05800f433d1820705a7a5959 (diff)
i965: Clamp clear colors to the representable range
Starting with Sky Lake, we can clear to arbitrary floats or integers. Unfortunately, the hardware isn't particularly smart when it comes sampling from that clear color. If the clear color is out of range for the surface format, it will happily return whatever we put in the surface state packet unmodified. In order to avoid returning bogus values for surfaces with a limited range, we need to do some clamping. Cc: "17.1" <mesa-stable@lists.freedesktop.org> Reviewed-by: Chad Versace <chadversary@chromium.org> (cherry picked from commit f1fa4be871e13c68b50685aaf64dc095b49ed0b5) [Andres Gomez: override_color still a gl_color_union] Signed-off-by: Andres Gomez <agomez@igalia.com> Conflicts: src/mesa/drivers/dri/i965/brw_meta_util.c
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r--src/mesa/drivers/dri/i965/brw_meta_util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_meta_util.c b/src/mesa/drivers/dri/i965/brw_meta_util.c
index cbc2dedde83..1b47c60958b 100644
--- a/src/mesa/drivers/dri/i965/brw_meta_util.c
+++ b/src/mesa/drivers/dri/i965/brw_meta_util.c
@@ -357,6 +357,46 @@ brw_meta_convert_fast_clear_color(const struct brw_context *brw,
break;
}
+ switch (_mesa_get_format_datatype(mt->format)) {
+ case GL_UNSIGNED_NORMALIZED:
+ for (int i = 0; i < 4; i++)
+ override_color.f[i] = CLAMP(override_color.f[i], 0.0f, 1.0f);
+ break;
+
+ case GL_SIGNED_NORMALIZED:
+ for (int i = 0; i < 4; i++)
+ override_color.f[i] = CLAMP(override_color.f[i], -1.0f, 1.0f);
+ break;
+
+ case GL_UNSIGNED_INT:
+ for (int i = 0; i < 4; i++) {
+ unsigned bits = _mesa_get_format_bits(mt->format, GL_RED_BITS + i);
+ if (bits < 32) {
+ uint32_t max = (1u << bits) - 1;
+ override_color.ui[i] = MIN2(override_color.ui[i], max);
+ }
+ }
+ break;
+
+ case GL_INT:
+ for (int i = 0; i < 4; i++) {
+ unsigned bits = _mesa_get_format_bits(mt->format, GL_RED_BITS + i);
+ if (bits < 32) {
+ int32_t max = (1 << (bits - 1)) - 1;
+ int32_t min = -(1 << (bits - 1));
+ override_color.i[i] = CLAMP(override_color.i[i], min, max);
+ }
+ }
+ break;
+
+ case GL_FLOAT:
+ if (!_mesa_is_format_signed(mt->format)) {
+ for (int i = 0; i < 4; i++)
+ override_color.f[i] = MAX2(override_color.f[i], 0.0f);
+ }
+ break;
+ }
+
if (!_mesa_format_has_color_component(mt->format, 3)) {
if (_mesa_is_format_integer_color(mt->format))
override_color.ui[3] = 1;