Fix sRGB color clear
According to the Vulkan spec:
2.9.2. Conversion from Floating-Point to Normalized Fixed-Point
"The conversion from a floating-point value f to the corresponding
unsigned normalized fixed-point value c is defined by first
clamping f to the range [0,1], then computing ..."
Also, in section 18.3. Clear Values:
"float32 are the color clear values when the format of the image or
attachment is one of the formats in the Interpretation of Numeric
Format table other than signed integer (SINT) or unsigned integer
(UINT). Floating point values are automatically converted to the
format of the image, with the clear value being treated as linear
if the image is sRGB"
Added a clamp to sRGB values to avoid getting out of bound values
for the sRGB color space.
Bug: b/151469361
Change-Id: I22615b807384904ca4fa887e93529d5a4b185d04
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/45090
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index a7d1256..77ad72f 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -58,7 +58,7 @@
}
float *pPixel = static_cast<float *>(pixel);
- if(viewFormat.isUnsignedNormalized())
+ if(viewFormat.isUnsignedNormalized() || viewFormat.isSRGBformat())
{
pPixel[0] = sw::clamp(pPixel[0], 0.0f, 1.0f);
pPixel[1] = sw::clamp(pPixel[1], 0.0f, 1.0f);