mesa: Split tx_compress_dxtn into per-format functions
This avoids an unnecessary switch statement in many cases. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16631>
This commit is contained in:
parent
eb673c55f1
commit
5602f424c3
|
@ -84,9 +84,7 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
|
||||||
|
|
||||||
dst = dstSlices[0];
|
dst = dstSlices[0];
|
||||||
|
|
||||||
tx_compress_dxtn(3, srcWidth, srcHeight, pixels,
|
tx_compress_dxt1(3, srcWidth, srcHeight, pixels, dst, dstRowStride, 3);
|
||||||
GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
||||||
dst, dstRowStride);
|
|
||||||
|
|
||||||
free((void *) tempImage);
|
free((void *) tempImage);
|
||||||
|
|
||||||
|
@ -140,9 +138,7 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
|
||||||
|
|
||||||
dst = dstSlices[0];
|
dst = dstSlices[0];
|
||||||
|
|
||||||
tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
|
tx_compress_dxt1(4, srcWidth, srcHeight, pixels, dst, dstRowStride, 4);
|
||||||
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
|
||||||
dst, dstRowStride);
|
|
||||||
|
|
||||||
free((void*) tempImage);
|
free((void*) tempImage);
|
||||||
|
|
||||||
|
@ -195,9 +191,7 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
|
||||||
|
|
||||||
dst = dstSlices[0];
|
dst = dstSlices[0];
|
||||||
|
|
||||||
tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
|
tx_compress_dxt3(4, srcWidth, srcHeight, pixels, dst, dstRowStride);
|
||||||
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
||||||
dst, dstRowStride);
|
|
||||||
|
|
||||||
free((void *) tempImage);
|
free((void *) tempImage);
|
||||||
|
|
||||||
|
@ -250,9 +244,7 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
|
||||||
|
|
||||||
dst = dstSlices[0];
|
dst = dstSlices[0];
|
||||||
|
|
||||||
tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
|
tx_compress_dxt5(4, srcWidth, srcHeight, pixels, dst, dstRowStride);
|
||||||
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
||||||
dst, dstRowStride);
|
|
||||||
|
|
||||||
free((void *) tempImage);
|
free((void *) tempImage);
|
||||||
|
|
||||||
|
|
|
@ -906,88 +906,132 @@ static void extractsrccolors( GLubyte srcpixels[4][4][4], const GLchan *srcaddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void tx_compress_dxtn(GLint srccomps, GLint width, GLint height, const GLubyte *srcPixData,
|
static void
|
||||||
GLenum destFormat, GLubyte *dest, GLint dstRowStride)
|
tx_compress_dxt1(int srccomps, int width, int height,
|
||||||
|
const GLubyte *srcPixData, GLubyte *dest, int dstRowStride,
|
||||||
|
unsigned dstComps)
|
||||||
{
|
{
|
||||||
GLubyte *blkaddr = dest;
|
GLenum destFormat = dstComps == 3 ? GL_COMPRESSED_RGB_S3TC_DXT1_EXT
|
||||||
GLubyte srcpixels[4][4][4];
|
: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
const GLchan *srcaddr = srcPixData;
|
GLubyte *blkaddr = dest;
|
||||||
GLint numxpixels, numypixels;
|
GLubyte srcpixels[4][4][4];
|
||||||
GLint i, j;
|
const GLchan *srcaddr = srcPixData;
|
||||||
GLint dstRowDiff;
|
int numxpixels, numypixels;
|
||||||
|
|
||||||
|
/* hmm we used to get called without dstRowStride... */
|
||||||
|
int dstRowDiff = dstRowStride >= (width * 2) ?
|
||||||
|
dstRowStride - (((width + 3) & ~3) * 2) : 0;
|
||||||
|
/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n",
|
||||||
|
width, height, dstRowStride); */
|
||||||
|
for (int j = 0; j < height; j += 4) {
|
||||||
|
if (height > j + 3) numypixels = 4;
|
||||||
|
else numypixels = height - j;
|
||||||
|
srcaddr = srcPixData + j * width * srccomps;
|
||||||
|
for (int i = 0; i < width; i += 4) {
|
||||||
|
if (width > i + 3) numxpixels = 4;
|
||||||
|
else numxpixels = width - i;
|
||||||
|
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
||||||
|
encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
|
||||||
|
srcaddr += srccomps * numxpixels;
|
||||||
|
blkaddr += 8;
|
||||||
|
}
|
||||||
|
blkaddr += dstRowDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tx_compress_dxt3(int srccomps, int width, int height,
|
||||||
|
const GLubyte *srcPixData, GLubyte *dest, int dstRowStride)
|
||||||
|
{
|
||||||
|
GLenum destFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||||
|
GLubyte *blkaddr = dest;
|
||||||
|
GLubyte srcpixels[4][4][4];
|
||||||
|
const GLchan *srcaddr = srcPixData;
|
||||||
|
int numxpixels, numypixels;
|
||||||
|
|
||||||
|
int dstRowDiff = dstRowStride >= (width * 4) ?
|
||||||
|
dstRowStride - (((width + 3) & ~3) * 4) : 0;
|
||||||
|
/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n",
|
||||||
|
width, height, dstRowStride); */
|
||||||
|
for (int j = 0; j < height; j += 4) {
|
||||||
|
if (height > j + 3) numypixels = 4;
|
||||||
|
else numypixels = height - j;
|
||||||
|
srcaddr = srcPixData + j * width * srccomps;
|
||||||
|
for (int i = 0; i < width; i += 4) {
|
||||||
|
if (width > i + 3) numxpixels = 4;
|
||||||
|
else numxpixels = width - i;
|
||||||
|
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
||||||
|
*blkaddr++ = (srcpixels[0][0][3] >> 4) | (srcpixels[0][1][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[0][2][3] >> 4) | (srcpixels[0][3][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[1][0][3] >> 4) | (srcpixels[1][1][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[1][2][3] >> 4) | (srcpixels[1][3][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[2][0][3] >> 4) | (srcpixels[2][1][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[2][2][3] >> 4) | (srcpixels[2][3][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[3][0][3] >> 4) | (srcpixels[3][1][3] & 0xf0);
|
||||||
|
*blkaddr++ = (srcpixels[3][2][3] >> 4) | (srcpixels[3][3][3] & 0xf0);
|
||||||
|
encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
|
||||||
|
srcaddr += srccomps * numxpixels;
|
||||||
|
blkaddr += 8;
|
||||||
|
}
|
||||||
|
blkaddr += dstRowDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tx_compress_dxt5(int srccomps, int width, int height,
|
||||||
|
const GLubyte *srcPixData, GLubyte *dest, int dstRowStride)
|
||||||
|
{
|
||||||
|
GLenum destFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||||
|
GLubyte *blkaddr = dest;
|
||||||
|
GLubyte srcpixels[4][4][4];
|
||||||
|
const GLchan *srcaddr = srcPixData;
|
||||||
|
int numxpixels, numypixels;
|
||||||
|
|
||||||
|
int dstRowDiff = dstRowStride >= (width * 4) ?
|
||||||
|
dstRowStride - (((width + 3) & ~3) * 4) : 0;
|
||||||
|
/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n",
|
||||||
|
width, height, dstRowStride); */
|
||||||
|
for (int j = 0; j < height; j += 4) {
|
||||||
|
if (height > j + 3) numypixels = 4;
|
||||||
|
else numypixels = height - j;
|
||||||
|
srcaddr = srcPixData + j * width * srccomps;
|
||||||
|
for (int i = 0; i < width; i += 4) {
|
||||||
|
if (width > i + 3) numxpixels = 4;
|
||||||
|
else numxpixels = width - i;
|
||||||
|
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
||||||
|
encodedxt5alpha(blkaddr, srcpixels, numxpixels, numypixels);
|
||||||
|
encodedxtcolorblockfaster(blkaddr + 8, srcpixels, numxpixels, numypixels, destFormat);
|
||||||
|
srcaddr += srccomps * numxpixels;
|
||||||
|
blkaddr += 16;
|
||||||
|
}
|
||||||
|
blkaddr += dstRowDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tx_compress_dxtn(GLint srccomps, GLint width, GLint height,
|
||||||
|
const GLubyte *srcPixData, GLenum destFormat,
|
||||||
|
GLubyte *dest, GLint dstRowStride)
|
||||||
|
{
|
||||||
switch (destFormat) {
|
switch (destFormat) {
|
||||||
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
||||||
|
tx_compress_dxt1(srccomps, width, height, srcPixData,
|
||||||
|
dest, dstRowStride, 3);
|
||||||
|
break;
|
||||||
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
||||||
/* hmm we used to get called without dstRowStride... */
|
tx_compress_dxt1(srccomps, width, height, srcPixData,
|
||||||
dstRowDiff = dstRowStride >= (width * 2) ? dstRowStride - (((width + 3) & ~3) * 2) : 0;
|
dest, dstRowStride, 4);
|
||||||
/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n",
|
|
||||||
width, height, dstRowStride); */
|
|
||||||
for (j = 0; j < height; j += 4) {
|
|
||||||
if (height > j + 3) numypixels = 4;
|
|
||||||
else numypixels = height - j;
|
|
||||||
srcaddr = srcPixData + j * width * srccomps;
|
|
||||||
for (i = 0; i < width; i += 4) {
|
|
||||||
if (width > i + 3) numxpixels = 4;
|
|
||||||
else numxpixels = width - i;
|
|
||||||
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
|
||||||
encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
|
|
||||||
srcaddr += srccomps * numxpixels;
|
|
||||||
blkaddr += 8;
|
|
||||||
}
|
|
||||||
blkaddr += dstRowDiff;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
||||||
dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
|
tx_compress_dxt3(srccomps, width, height, srcPixData,
|
||||||
/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n",
|
dest, dstRowStride);
|
||||||
width, height, dstRowStride); */
|
|
||||||
for (j = 0; j < height; j += 4) {
|
|
||||||
if (height > j + 3) numypixels = 4;
|
|
||||||
else numypixels = height - j;
|
|
||||||
srcaddr = srcPixData + j * width * srccomps;
|
|
||||||
for (i = 0; i < width; i += 4) {
|
|
||||||
if (width > i + 3) numxpixels = 4;
|
|
||||||
else numxpixels = width - i;
|
|
||||||
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
|
||||||
*blkaddr++ = (srcpixels[0][0][3] >> 4) | (srcpixels[0][1][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[0][2][3] >> 4) | (srcpixels[0][3][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[1][0][3] >> 4) | (srcpixels[1][1][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[1][2][3] >> 4) | (srcpixels[1][3][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[2][0][3] >> 4) | (srcpixels[2][1][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[2][2][3] >> 4) | (srcpixels[2][3][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[3][0][3] >> 4) | (srcpixels[3][1][3] & 0xf0);
|
|
||||||
*blkaddr++ = (srcpixels[3][2][3] >> 4) | (srcpixels[3][3][3] & 0xf0);
|
|
||||||
encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
|
|
||||||
srcaddr += srccomps * numxpixels;
|
|
||||||
blkaddr += 8;
|
|
||||||
}
|
|
||||||
blkaddr += dstRowDiff;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
||||||
dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
|
tx_compress_dxt5(srccomps, width, height, srcPixData,
|
||||||
/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n",
|
dest, dstRowStride);
|
||||||
width, height, dstRowStride); */
|
|
||||||
for (j = 0; j < height; j += 4) {
|
|
||||||
if (height > j + 3) numypixels = 4;
|
|
||||||
else numypixels = height - j;
|
|
||||||
srcaddr = srcPixData + j * width * srccomps;
|
|
||||||
for (i = 0; i < width; i += 4) {
|
|
||||||
if (width > i + 3) numxpixels = 4;
|
|
||||||
else numxpixels = width - i;
|
|
||||||
extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
|
|
||||||
encodedxt5alpha(blkaddr, srcpixels, numxpixels, numypixels);
|
|
||||||
encodedxtcolorblockfaster(blkaddr + 8, srcpixels, numxpixels, numypixels, destFormat);
|
|
||||||
srcaddr += srccomps * numxpixels;
|
|
||||||
blkaddr += 16;
|
|
||||||
}
|
|
||||||
blkaddr += dstRowDiff;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
unreachable("unknown DXTn format");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue