Commit 2b052f89 by Alexis Hetu Committed by Alexis Hétu

Fixed stencil masking

This is odd, but stencil masking was simply disabled, so clearing the stencil buffer would only work if the mask was 0xFF, or it would simply skip the clearing entirely. I removed this condition to fix the issue. Also removed some dead code and added an early exit if the mask is 0. Change-Id: I359b10ed3382b75cb9d078470f237e68f1a6e7b9 Reviewed-on: https://swiftshader-review.googlesource.com/4303Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 25d47fc9
......@@ -3214,6 +3214,8 @@ namespace sw
void Surface::clearStencilBuffer(unsigned char s, unsigned char mask, int x0, int y0, int width, int height)
{
if(mask == 0) return;
// Not overlapping
if(x0 > internal.width) return;
if(y0 > internal.height) return;
......@@ -3236,77 +3238,46 @@ namespace sw
unsigned int fill = maskedS;
fill = fill | (fill << 8) | (fill << 16) + (fill << 24);
if(false)
{
char *target = (char*)lockStencil(0, PUBLIC) + x0 + width2 * y0;
char *buffer = (char*)lockStencil(0, PUBLIC);
for(int z = 0; z < stencil.depth; z++)
// Stencil buffers are assumed to use quad layout
for(int z = 0; z < stencil.depth; z++)
{
for(int y = y0; y < y1; y++)
{
for(int y = y0; y < y0 + height; y++)
char *target = buffer + (y & ~1) * width2 + (y & 1) * 2;
if((y & 1) == 0 && y + 1 < y1 && mask == 0xFF) // Fill quad line at once
{
if(mask == 0xFF)
if((x0 & 1) != 0)
{
memfill4(target, fill, width);
target[(x0 & ~1) * 2 + 1] = fill;
target[(x0 & ~1) * 2 + 3] = fill;
}
else
memfill4(&target[((x0 + 1) & ~1) * 2], fill, ((x1 + 1) & ~1) * 2 - ((x0 + 1) & ~1) * 2);
if((x1 & 1) != 0)
{
for(int x = 0; x < width; x++)
{
target[x] = maskedS | (target[x] & invMask);
}
target[(x1 & ~1) * 2 + 0] = fill;
target[(x1 & ~1) * 2 + 2] = fill;
}
target += width2;
y++;
}
}
unlockStencil();
}
else // Quad layout
{
char *buffer = (char*)lockStencil(0, PUBLIC);
if(mask == 0xFF)
{
for(int z = 0; z < stencil.depth; z++)
else
{
for(int y = y0; y < y1; y++)
for(int x = x0; x < x1; x++)
{
char *target = buffer + (y & ~1) * width2 + (y & 1) * 2;
if((y & 1) == 0 && y + 1 < y1 && mask == 0xFF) // Fill quad line at once
{
if((x0 & 1) != 0)
{
target[(x0 & ~1) * 2 + 1] = fill;
target[(x0 & ~1) * 2 + 3] = fill;
}
memfill4(&target[((x0 + 1) & ~1) * 2], fill, ((x1 + 1) & ~1) * 2 - ((x0 + 1) & ~1) * 2);
if((x1 & 1) != 0)
{
target[(x1 & ~1) * 2 + 0] = fill;
target[(x1 & ~1) * 2 + 2] = fill;
}
y++;
}
else
{
for(int x = x0; x < x1; x++)
{
target[(x & ~1) * 2 + (x & 1)] = maskedS | (target[x] & invMask);
}
}
target[(x & ~1) * 2 + (x & 1)] = maskedS | (target[x] & invMask);
}
buffer += stencil.sliceP;
}
}
unlockStencil();
buffer += stencil.sliceP;
}
unlockStencil();
}
void Surface::fill(const Color<float> &color, int x0, int y0, int width, int height)
......
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