mesa: Add MESA_FORMAT_SIGNED_RG88 and _RG1616.

Including pack/unpack and texstore code.  ARB_shader_image_load_store
requires support for the GL_RG8_SNORM and GL_RG16_SNORM formats, which
map to MESA_FORMAT_SIGNED_GR88 and MESA_FORMAT_SIGNED_GR1616 on
little-endian hosts, and MESA_FORMAT_SIGNED_RG88 and
MESA_FORMAT_SIGNED_RG1616 respectively on big-endian hosts -- only the
former were already present, add support for the latter.

Acked-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
This commit is contained in:
Francisco Jerez
2013-11-22 19:49:58 -08:00
parent 87942749a3
commit 7510c10209
6 changed files with 153 additions and 15 deletions

View File

@@ -1849,6 +1849,31 @@ pack_float_ABGR2101010(const GLfloat src[4], void *dst)
*d = PACK_COLOR_2101010_US(a, b, g, r);
}
/*
* MESA_FORMAT_SIGNED_RG88
*/
static void
pack_float_SIGNED_RG88(const GLfloat src[4], void *dst)
{
GLushort *d = (GLushort *) dst;
GLbyte r = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
GLbyte g = FLOAT_TO_BYTE(CLAMP(src[GCOMP], -1.0f, 1.0f));
*d = (r << 8) | (g & 0xff);
}
/*
* MESA_FORMAT_SIGNED_RG1616
*/
static void
pack_float_SIGNED_RG1616(const GLfloat src[4], void *dst)
{
GLuint *d = (GLuint *) dst;
GLshort r = FLOAT_TO_SHORT(CLAMP(src[RCOMP], -1.0f, 1.0f));
GLshort g = FLOAT_TO_SHORT(CLAMP(src[GCOMP], -1.0f, 1.0f));
*d = (r << 16) | (g & 0xffff);
}
/**
* Return a function that can pack a GLubyte rgba[4] color.
@@ -2165,6 +2190,9 @@ _mesa_get_pack_float_rgba_function(gl_format format)
table[MESA_FORMAT_ABGR2101010] = pack_float_ABGR2101010;
table[MESA_FORMAT_SIGNED_RG88] = pack_float_SIGNED_RG88;
table[MESA_FORMAT_SIGNED_RG1616] = pack_float_SIGNED_RG1616;
initialized = GL_TRUE;
}

View File

@@ -2281,6 +2281,32 @@ unpack_ABGR2101010(const void *src, GLfloat dst[][4], GLuint n)
}
}
static void
unpack_SIGNED_RG88(const void *src, GLfloat dst[][4], GLuint n)
{
const GLushort *s = ((const GLushort *) src);
GLuint i;
for (i = 0; i < n; i++) {
dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
dst[i][BCOMP] = 0.0F;
dst[i][ACOMP] = 1.0F;
}
}
static void
unpack_SIGNED_RG1616(const void *src, GLfloat dst[][4], GLuint n)
{
const GLuint *s = ((const GLuint *) src);
GLuint i;
for (i = 0; i < n; i++) {
dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
dst[i][BCOMP] = 0.0F;
dst[i][ACOMP] = 1.0F;
}
}
/**
* Return the unpacker function for the given format.
*/
@@ -2495,6 +2521,9 @@ get_unpack_rgba_function(gl_format format)
table[MESA_FORMAT_ABGR2101010] = unpack_ABGR2101010;
table[MESA_FORMAT_SIGNED_RG88] = unpack_SIGNED_RG88;
table[MESA_FORMAT_SIGNED_RG1616] = unpack_SIGNED_RG1616;
initialized = GL_TRUE;
}

View File

@@ -1772,6 +1772,24 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
0, 0, 0, 0, 0,
1, 1, 4
},
{
MESA_FORMAT_SIGNED_RG88,
"MESA_FORMAT_SIGNED_RG88",
GL_RG,
GL_SIGNED_NORMALIZED,
8, 8, 0, 0,
0, 0, 0, 0, 0,
1, 1, 2
},
{
MESA_FORMAT_SIGNED_RG1616,
"MESA_FORMAT_SIGNED_RG1616",
GL_RG,
GL_SIGNED_NORMALIZED,
16, 16, 0, 0,
0, 0, 0, 0, 0,
1, 1, 4
},
};
@@ -2855,6 +2873,16 @@ _mesa_format_to_type_and_comps(gl_format format,
*comps = 4;
return;
case MESA_FORMAT_SIGNED_RG88:
*datatype = GL_BYTE;
*comps = 2;
return;
case MESA_FORMAT_SIGNED_RG1616:
*datatype = GL_SHORT;
*comps = 2;
return;
case MESA_FORMAT_COUNT:
assert(0);
return;
@@ -3401,6 +3429,13 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
return format == GL_RGBA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
!swapBytes;
case MESA_FORMAT_SIGNED_RG88:
return format == GL_RG && type == GL_BYTE && !littleEndian &&
!swapBytes;
case MESA_FORMAT_SIGNED_RG1616:
return format == GL_RG && type == GL_SHORT && !littleEndian &&
!swapBytes;
}
return GL_FALSE;

View File

@@ -306,6 +306,9 @@ typedef enum
MESA_FORMAT_ABGR2101010,
MESA_FORMAT_SIGNED_RG88,
MESA_FORMAT_SIGNED_RG1616,
MESA_FORMAT_COUNT
} gl_format;

View File

@@ -2191,6 +2191,7 @@ _mesa_texstore_snorm88(TEXSTORE_PARAMS)
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
ASSERT(dstFormat == MESA_FORMAT_SIGNED_AL88 ||
dstFormat == MESA_FORMAT_SIGNED_RG88 ||
dstFormat == MESA_FORMAT_SIGNED_RG88_REV);
ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
@@ -2210,13 +2211,27 @@ _mesa_texstore_snorm88(TEXSTORE_PARAMS)
for (img = 0; img < srcDepth; img++) {
GLbyte *dstRow = (GLbyte *) dstSlices[img];
for (row = 0; row < srcHeight; row++) {
GLbyte *dst = dstRow;
for (col = 0; col < srcWidth; col++) {
dst[0] = FLOAT_TO_BYTE_TEX(src[0]);
dst[1] = FLOAT_TO_BYTE_TEX(src[1]);
src += 2;
dst += 2;
GLushort *dst = (GLushort *) dstRow;
if (dstFormat == MESA_FORMAT_SIGNED_AL88 ||
dstFormat == MESA_FORMAT_SIGNED_RG88_REV) {
for (col = 0; col < srcWidth; col++) {
GLubyte l = FLOAT_TO_BYTE_TEX(src[0]);
GLubyte a = FLOAT_TO_BYTE_TEX(src[1]);
dst[col] = PACK_COLOR_88_REV(l, a);
src += 2;
}
} else {
for (col = 0; col < srcWidth; col++) {
GLubyte l = FLOAT_TO_BYTE_TEX(src[0]);
GLubyte a = FLOAT_TO_BYTE_TEX(src[1]);
dst[col] = PACK_COLOR_88(l, a);
src += 2;
}
}
dstRow += dstRowStride;
}
}
@@ -2278,6 +2293,7 @@ _mesa_texstore_snorm1616(TEXSTORE_PARAMS)
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
ASSERT(dstFormat == MESA_FORMAT_SIGNED_AL1616 ||
dstFormat == MESA_FORMAT_SIGNED_RG1616 ||
dstFormat == MESA_FORMAT_SIGNED_GR1616);
ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
@@ -2297,17 +2313,29 @@ _mesa_texstore_snorm1616(TEXSTORE_PARAMS)
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = dstSlices[img];
for (row = 0; row < srcHeight; row++) {
GLshort *dst = (GLshort *) dstRow;
for (col = 0; col < srcWidth; col++) {
GLushort l, a;
GLuint *dst = (GLuint *) dstRow;
UNCLAMPED_FLOAT_TO_SHORT(l, src[0]);
UNCLAMPED_FLOAT_TO_SHORT(a, src[1]);
dst[0] = l;
dst[1] = a;
src += 2;
dst += 2;
if (dstFormat == MESA_FORMAT_SIGNED_AL1616 ||
dstFormat == MESA_FORMAT_SIGNED_GR1616) {
for (col = 0; col < srcWidth; col++) {
GLushort l, a;
UNCLAMPED_FLOAT_TO_SHORT(l, src[0]);
UNCLAMPED_FLOAT_TO_SHORT(a, src[1]);
dst[col] = PACK_COLOR_1616_REV(l, a);
src += 2;
}
} else {
for (col = 0; col < srcWidth; col++) {
GLushort l, a;
UNCLAMPED_FLOAT_TO_SHORT(l, src[0]);
UNCLAMPED_FLOAT_TO_SHORT(a, src[1]);
dst[col] = PACK_COLOR_1616_REV(l, a);
src += 2;
}
}
dstRow += dstRowStride;
}
}
@@ -3828,6 +3856,9 @@ _mesa_get_texstore_func(gl_format format)
table[MESA_FORMAT_ABGR2101010] = _mesa_texstore_abgr2101010;
table[MESA_FORMAT_SIGNED_RG88] = _mesa_texstore_snorm88;
table[MESA_FORMAT_SIGNED_RG1616] = _mesa_texstore_snorm1616;
initialized = GL_TRUE;
}

View File

@@ -1292,6 +1292,18 @@ texfetch_funcs[] =
NULL,
NULL
},
{
MESA_FORMAT_SIGNED_RG88,
NULL,
NULL,
NULL
},
{
MESA_FORMAT_SIGNED_RG1616,
NULL,
NULL,
NULL
},
};