Commit 5ba566b1 by Nicolas Capens

Implement R5G6B5 clear.

Bug 20891368 Change-Id: I5c283589c1fb08003194e668c66ade4d0fe36842 Reviewed-on: https://swiftshader-review.googlesource.com/3250Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent fff3c9bc
...@@ -2211,7 +2211,7 @@ namespace sw ...@@ -2211,7 +2211,7 @@ namespace sw
return allocateZero(size(width4, height4, depth, format)); return allocateZero(size(width4, height4, depth, format));
} }
void Surface::memfill(void *buffer, int pattern, int bytes) void Surface::memfill4(void *buffer, int pattern, int bytes)
{ {
while((size_t)buffer & 0x1 && bytes >= 1) while((size_t)buffer & 0x1 && bytes >= 1)
{ {
...@@ -2305,17 +2305,15 @@ namespace sw ...@@ -2305,17 +2305,15 @@ namespace sw
// if(lockable || !quadLayoutEnabled) // if(lockable || !quadLayoutEnabled)
{ {
unsigned char *buffer = (unsigned char*)lockInternal(x0, y0, 0, lock, PUBLIC);
unsigned char r8 = (colorARGB & 0x00FF0000) >> 16; unsigned char r8 = (colorARGB & 0x00FF0000) >> 16;
unsigned char g8 = (colorARGB & 0x0000FF00) >> 8; unsigned char g8 = (colorARGB & 0x0000FF00) >> 8;
unsigned char b8 = (colorARGB & 0x000000FF) >> 0; unsigned char b8 = (colorARGB & 0x000000FF) >> 0;
unsigned char a8 = (colorARGB & 0xFF000000) >> 24; unsigned char a8 = (colorARGB & 0xFF000000) >> 24;
unsigned short r16 = (r8 << 8) + r8; unsigned short r16 = (r8 << 8) | r8;
unsigned short g16 = (g8 << 8) + g8; unsigned short g16 = (g8 << 8) | g8;
unsigned short b16 = (b8 << 8) + b8; unsigned short b16 = (b8 << 8) | b8;
unsigned short a16 = (a8 << 8) + a8; unsigned short a16 = (a8 << 8) | a8;
float r32f = r8 / 255.0f; float r32f = r8 / 255.0f;
float g32f = g8 / 255.0f; float g32f = g8 / 255.0f;
...@@ -2326,6 +2324,10 @@ namespace sw ...@@ -2326,6 +2324,10 @@ namespace sw
unsigned short g16r16[2] = {r16, g16}; unsigned short g16r16[2] = {r16, g16};
unsigned char a8b8g8r8[4] = {r8, g8, b8, a8}; unsigned char a8b8g8r8[4] = {r8, g8, b8, a8};
unsigned int colorABGR = (unsigned int&)a8b8g8r8; unsigned int colorABGR = (unsigned int&)a8b8g8r8;
unsigned int r5g6b5 = (((unsigned short)r8 << 8) & 0xF800) | (((unsigned short)g8 << 3) & 0x07E0) | ((unsigned short)b8 >> 3);
r5g6b5 |= r5g6b5 << 16;
unsigned char *buffer = (unsigned char*)lockInternal(x0, y0, 0, lock, PUBLIC);
for(int z = 0; z < internal.depth; z++) for(int z = 0; z < internal.depth; z++)
{ {
...@@ -2343,7 +2345,7 @@ namespace sw ...@@ -2343,7 +2345,7 @@ namespace sw
// case FORMAT_A8G8R8B8Q: // FIXME // case FORMAT_A8G8R8B8Q: // FIXME
if(rgbaMask == 0xF || (internal.format == FORMAT_X8R8G8B8 && rgbaMask == 0x7)) if(rgbaMask == 0xF || (internal.format == FORMAT_X8R8G8B8 && rgbaMask == 0x7))
{ {
memfill(target, colorARGB, 4 * (x1 - x0)); memfill4(target, colorARGB, 4 * (x1 - x0));
} }
else else
{ {
...@@ -2362,7 +2364,7 @@ namespace sw ...@@ -2362,7 +2364,7 @@ namespace sw
case FORMAT_A8B8G8R8: case FORMAT_A8B8G8R8:
if(rgbaMask == 0xF || (internal.format == FORMAT_X8B8G8R8 && rgbaMask == 0x7)) if(rgbaMask == 0xF || (internal.format == FORMAT_X8B8G8R8 && rgbaMask == 0x7))
{ {
memfill(target, colorABGR, 4 * (x1 - x0)); memfill4(target, colorABGR, 4 * (x1 - x0));
} }
else else
{ {
...@@ -2380,7 +2382,7 @@ namespace sw ...@@ -2380,7 +2382,7 @@ namespace sw
case FORMAT_G8R8: case FORMAT_G8R8:
if((rgbaMask & 0x3) == 0x3) if((rgbaMask & 0x3) == 0x3)
{ {
memfill(target, (int&)g8r8, 2 * (x1 - x0)); memfill4(target, (int&)g8r8, 2 * (x1 - x0));
} }
else else
{ {
...@@ -2398,7 +2400,7 @@ namespace sw ...@@ -2398,7 +2400,7 @@ namespace sw
case FORMAT_G16R16: case FORMAT_G16R16:
if((rgbaMask & 0x3) == 0x3) if((rgbaMask & 0x3) == 0x3)
{ {
memfill(target, (int&)g16r16, 4 * (x1 - x0)); memfill4(target, (int&)g16r16, 4 * (x1 - x0));
} }
else else
{ {
...@@ -2475,6 +2477,24 @@ namespace sw ...@@ -2475,6 +2477,24 @@ namespace sw
if(rgbaMask & 0x8) for(int x = 0; x < width; x++) ((float*)target)[4 * x + 3] = a32f; if(rgbaMask & 0x8) for(int x = 0; x < width; x++) ((float*)target)[4 * x + 3] = a32f;
} }
break; break;
case FORMAT_R5G6B5:
if((rgbaMask & 0x7) == 0x7)
{
memfill4(target, r5g6b5, 2 * (x1 - x0));
}
else
{
unsigned short rgbMask = (rgbaMask & 0x1 ? 0xF800 : 0) | (rgbaMask & 0x2 ? 0x07E0 : 0) | (rgbaMask & 0x3 ? 0x001F : 0);
unsigned short invMask = ~rgbMask;
unsigned short maskedColor = r5g6b5 & rgbMask;
unsigned short *target16 = (unsigned short*)target;
for(int x = 0; x < width; x++)
{
target16[x] = maskedColor | (target16[x] & invMask);
}
}
break;
default: default:
ASSERT(false); ASSERT(false);
} }
...@@ -2625,7 +2645,7 @@ namespace sw ...@@ -2625,7 +2645,7 @@ namespace sw
{ {
for(int y = y0; y < y1; y++) for(int y = y0; y < y1; y++)
{ {
memfill(target, (int&)depth, 4 * width); memfill4(target, (int&)depth, 4 * width);
target += width2; target += width2;
} }
} }
...@@ -2685,7 +2705,7 @@ namespace sw ...@@ -2685,7 +2705,7 @@ namespace sw
// qEnd: // qEnd:
// } // }
memfill(&target[((x0 + 1) & ~1) * 2], (int&)depth, 8 * ((x1 & ~1) - ((x0 + 1) & ~1))); memfill4(&target[((x0 + 1) & ~1) * 2], (int&)depth, 8 * ((x1 & ~1) - ((x0 + 1) & ~1)));
if((x1 & 1) != 0) if((x1 & 1) != 0)
{ {
...@@ -2745,7 +2765,7 @@ namespace sw ...@@ -2745,7 +2765,7 @@ namespace sw
{ {
if(mask == 0xFF) if(mask == 0xFF)
{ {
memfill(target, fill, width); memfill4(target, fill, width);
} }
else else
{ {
...@@ -2781,7 +2801,7 @@ namespace sw ...@@ -2781,7 +2801,7 @@ namespace sw
target[(x0 & ~1) * 2 + 3] = fill; target[(x0 & ~1) * 2 + 3] = fill;
} }
memfill(&target[((x0 + 1) & ~1) * 2], fill, ((x1 + 1) & ~1) * 2 - ((x0 + 1) & ~1) * 2); memfill4(&target[((x0 + 1) & ~1) * 2], fill, ((x1 + 1) & ~1) * 2 - ((x0 + 1) & ~1) * 2);
if((x1 & 1) != 0) if((x1 & 1) != 0)
{ {
...@@ -2834,7 +2854,7 @@ namespace sw ...@@ -2834,7 +2854,7 @@ namespace sw
for(int y = 0; y < height; y++) for(int y = 0; y < height; y++)
{ {
memfill(row, c, width * buffer->bytes); memfill4(row, c, width * buffer->bytes);
row += buffer->pitchB; row += buffer->pitchB;
} }
......
...@@ -348,7 +348,7 @@ namespace sw ...@@ -348,7 +348,7 @@ namespace sw
static void update(Buffer &destination, Buffer &source); static void update(Buffer &destination, Buffer &source);
static void genericUpdate(Buffer &destination, Buffer &source); static void genericUpdate(Buffer &destination, Buffer &source);
static void *allocateBuffer(int width, int height, int depth, Format format); static void *allocateBuffer(int width, int height, int depth, Format format);
static void memfill(void *buffer, int pattern, int bytes); static void memfill4(void *buffer, int pattern, int bytes);
bool identicalFormats() const; bool identicalFormats() const;
Format selectInternalFormat(Format format) const; Format selectInternalFormat(Format format) const;
......
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