Clamp float values to correct range before conversion to normalized
Per Vulkan spec 2.9.2, when converting from a floating point value to
unsigned normalized, we must first clamp to [0,1]. When converting from
a floating point value to signed normalized, we must first clamp to
[-1,1]. This wasn't done to clear values.
Test: dEQP-VK.rasterization.provoking_vertex.*
Bug: b/140203285
Change-Id: I3f8c421b187b6a7e8bcb22d45142dc1664221605
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35668
Tested-by: Chris Forbes <chrisforbes@google.com>
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index c8298ed..b366b72 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -47,6 +47,22 @@
return;
}
+ float *pPixel = static_cast<float *>(pixel);
+ if (viewFormat.isUnsignedNormalized())
+ {
+ pPixel[0] = sw::clamp(pPixel[0], 0.0f, 1.0f);
+ pPixel[1] = sw::clamp(pPixel[1], 0.0f, 1.0f);
+ pPixel[2] = sw::clamp(pPixel[2], 0.0f, 1.0f);
+ pPixel[3] = sw::clamp(pPixel[3], 0.0f, 1.0f);
+ }
+ else if (viewFormat.isSignedNormalized())
+ {
+ pPixel[0] = sw::clamp(pPixel[0], -1.0f, 1.0f);
+ pPixel[1] = sw::clamp(pPixel[1], -1.0f, 1.0f);
+ pPixel[2] = sw::clamp(pPixel[2], -1.0f, 1.0f);
+ pPixel[3] = sw::clamp(pPixel[3], -1.0f, 1.0f);
+ }
+
if(fastClear(pixel, format, dest, dstFormat, subresourceRange, renderArea))
{
return;