Avoid clamping uninitialized values when clearing depth images
The Blitter was always clamping the input clear values for
normalized formats as if they were always used for clearing
a color image, but VK_FORMAT_D16_UNORM is also a normalized
format, so this code was also reached in this case.
This CL adds a check for which aspect of the image is getting
cleared, in order to avoid clamping uninitialized values.
Bug: chromium:1336057
Change-Id: I423f14ff333382275b0882933b3b134c7980c0ba
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/66513
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index 1c18a23..41c7d65 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -61,16 +61,28 @@
return;
}
- VkClearColorValue clampedPixel;
+ VkClearValue clampedPixel;
if(viewFormat.isSignedNormalized() || viewFormat.isUnsignedNormalized())
{
const float minValue = viewFormat.isSignedNormalized() ? -1.0f : 0.0f;
- memcpy(clampedPixel.float32, pixel, sizeof(VkClearColorValue));
- clampedPixel.float32[0] = sw::clamp(clampedPixel.float32[0], minValue, 1.0f);
- clampedPixel.float32[1] = sw::clamp(clampedPixel.float32[1], minValue, 1.0f);
- clampedPixel.float32[2] = sw::clamp(clampedPixel.float32[2], minValue, 1.0f);
- clampedPixel.float32[3] = sw::clamp(clampedPixel.float32[3], minValue, 1.0f);
- pixel = clampedPixel.float32;
+
+ if(aspect & VK_IMAGE_ASPECT_COLOR_BIT)
+ {
+ memcpy(clampedPixel.color.float32, pixel, sizeof(VkClearColorValue));
+ clampedPixel.color.float32[0] = sw::clamp(clampedPixel.color.float32[0], minValue, 1.0f);
+ clampedPixel.color.float32[1] = sw::clamp(clampedPixel.color.float32[1], minValue, 1.0f);
+ clampedPixel.color.float32[2] = sw::clamp(clampedPixel.color.float32[2], minValue, 1.0f);
+ clampedPixel.color.float32[3] = sw::clamp(clampedPixel.color.float32[3], minValue, 1.0f);
+ pixel = clampedPixel.color.float32;
+ }
+
+ // Stencil never requires clamping, so we can check for Depth only
+ if(aspect & VK_IMAGE_ASPECT_DEPTH_BIT)
+ {
+ memcpy(&(clampedPixel.depthStencil), pixel, sizeof(VkClearDepthStencilValue));
+ clampedPixel.depthStencil.depth = sw::clamp(clampedPixel.depthStencil.depth, minValue, 1.0f);
+ pixel = &(clampedPixel.depthStencil);
+ }
}
if(fastClear(pixel, format, dest, dstFormat, subresourceRange, renderArea))