Commit 37131679 by Alexis Hetu Committed by Alexis Hétu

Blend mode fix for 565 format

For 565 and 5551 formats, the blend equations were getting applied on top of colors represented by the top 5 or 6 MSB only, leading to precision errors. Fixed this by: - removing the scaling applied on the source color before blending is applied and the related inverse transform in the writeColor function - adding the proper remapping of the color to the full color range in the readPixel function That way, we're always working with full 16 bit range colors and the blend equations work properly. Fixes all tests in: dEQP-GLES3.functional.fragment_ops.interaction.basic_shader.* Bug: angleproject:4016 b/24332884 Change-Id: I53531b88a8629aaa61929e99efaac38cdb46c834 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38088Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 9da287fd
......@@ -226,33 +226,16 @@ namespace sw
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
for(unsigned int q = 0; q < state.multiSample; q++)
{
Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
Vector4s color;
if(format == VK_FORMAT_A1R5G5B5_UNORM_PACK16)
{
color.x = UShort4(c[index].x * Float4(0xFBFF), false);
color.y = UShort4(c[index].y * Float4(0xFBFF), false);
color.z = UShort4(c[index].z * Float4(0xFBFF), false);
color.w = UShort4(c[index].w * Float4(0xFFFF), false);
}
else if(format == VK_FORMAT_R5G6B5_UNORM_PACK16)
{
color.x = UShort4(c[index].x * Float4(0xFBFF), false);
color.y = UShort4(c[index].y * Float4(0xFDFF), false);
color.z = UShort4(c[index].z * Float4(0xFBFF), false);
color.w = UShort4(c[index].w * Float4(0xFFFF), false);
}
else
if(state.multiSampleMask & (1 << q))
{
Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
Vector4s color;
color.x = convertFixed16(c[index].x, false);
color.y = convertFixed16(c[index].y, false);
color.z = convertFixed16(c[index].z, false);
color.w = convertFixed16(c[index].w, false);
}
if(state.multiSampleMask & (1 << q))
{
alphaBlend(index, buffer, color, x);
writeColor(index, buffer, x, color, sMask[q], zMask[q], cMask[q]);
}
......@@ -287,11 +270,11 @@ namespace sw
case VK_FORMAT_A2B10G10R10_UINT_PACK32:
for(unsigned int q = 0; q < state.multiSample; q++)
{
Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
Vector4f color = c[index];
if(state.multiSampleMask & (1 << q))
{
Pointer<Byte> buffer = cBuffer[index] + q * *Pointer<Int>(data + OFFSET(DrawData, colorSliceB[index]));
Vector4f color = c[index];
alphaBlend(index, buffer, color, x);
writeColor(index, buffer, x, color, sMask[q], zMask[q], cMask[q]);
}
......
......@@ -968,7 +968,15 @@ namespace sw
pixel.x = (c01 & Short4(0x7C00u)) << 1;
pixel.y = (c01 & Short4(0x03E0u)) << 6;
pixel.z = (c01 & Short4(0x001Fu)) << 11;
pixel.w = (c01 & Short4(0x8000u));
pixel.w = (c01 & Short4(0x8000u)) >> 15;
// Expand to 16 bit range
pixel.x |= As<Short4>(As<UShort4>(pixel.x) >> 5);
pixel.x |= As<Short4>(As<UShort4>(pixel.x) >> 10);
pixel.y |= As<Short4>(As<UShort4>(pixel.y) >> 5);
pixel.y |= As<Short4>(As<UShort4>(pixel.y) >> 10);
pixel.z |= As<Short4>(As<UShort4>(pixel.z) >> 5);
pixel.z |= As<Short4>(As<UShort4>(pixel.z) >> 10);
break;
case VK_FORMAT_R5G6B5_UNORM_PACK16:
buffer = cBuffer + 2 * x;
......@@ -979,6 +987,14 @@ namespace sw
pixel.y = (c01 & Short4(0x07E0u)) << 5;
pixel.z = (c01 & Short4(0x001Fu)) << 11;
pixel.w = Short4(0xFFFFu);
// Expand to 16 bit range
pixel.x |= As<Short4>(As<UShort4>(pixel.x) >> 5);
pixel.x |= As<Short4>(As<UShort4>(pixel.x) >> 10);
pixel.y |= As<Short4>(As<UShort4>(pixel.y) >> 6);
pixel.y |= As<Short4>(As<UShort4>(pixel.y) >> 12);
pixel.z |= As<Short4>(As<UShort4>(pixel.z) >> 5);
pixel.z |= As<Short4>(As<UShort4>(pixel.z) >> 10);
break;
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_B8G8R8A8_SRGB:
......@@ -1216,16 +1232,6 @@ namespace sw
switch(state.targetFormat[index])
{
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
current.x = AddSat(As<UShort4>(current.x), UShort4(0x0400));
current.y = AddSat(As<UShort4>(current.y), UShort4(0x0400));
current.z = AddSat(As<UShort4>(current.z), UShort4(0x0400));
break;
case VK_FORMAT_R5G6B5_UNORM_PACK16:
current.x = AddSat(As<UShort4>(current.x), UShort4(0x0400));
current.y = AddSat(As<UShort4>(current.y), UShort4(0x0200));
current.z = AddSat(As<UShort4>(current.z), UShort4(0x0400));
break;
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_B8G8R8A8_SRGB:
case VK_FORMAT_R8G8B8A8_UNORM:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment