mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 11:28:05 +02:00
mesa: Add decoding functions for GL_COMPRESSED_R11_EAC
Data in GL_COMPRESSED_R11_EAC format is decoded and stored in MESA_FORMAT_R16. Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com> Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
parent
5ea8cd0084
commit
dc86cb3705
5 changed files with 128 additions and 6 deletions
|
|
@ -620,7 +620,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
|
|||
fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac;
|
||||
break;
|
||||
case MESA_FORMAT_ETC2_R11_EAC:
|
||||
/* fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac; -- not implemented yet */
|
||||
fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac;
|
||||
break;
|
||||
case MESA_FORMAT_ETC2_RG11_EAC:
|
||||
/* fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac; -- not implemented yet */
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
* GL_COMPRESSED_SRGB8_ETC2
|
||||
* GL_COMPRESSED_RGBA8_ETC2_EAC
|
||||
* GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
|
||||
* GL_COMPRESSED_R11_EAC
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
|
@ -304,6 +305,14 @@ etc2_base_color_v_planar(const uint8_t *in, GLuint index)
|
|||
}
|
||||
}
|
||||
|
||||
static GLint
|
||||
etc2_get_pixel_index(const struct etc2_block *block, int x, int y)
|
||||
{
|
||||
int bit = ((3 - y) + (3 - x) * 4) * 3;
|
||||
int idx = (block->pixel_indices[1] >> bit) & 0x7;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static uint8_t
|
||||
etc2_clamp(int color)
|
||||
{
|
||||
|
|
@ -311,6 +320,13 @@ etc2_clamp(int color)
|
|||
return (uint8_t) CLAMP(color, 0, 255);
|
||||
}
|
||||
|
||||
static GLushort
|
||||
etc2_clamp2(int color)
|
||||
{
|
||||
/* CLAMP(color, 0, 2047) */
|
||||
return (GLushort) CLAMP(color, 0, 2047);
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_rgb8_parse_block(struct etc2_block *block, const uint8_t *src)
|
||||
{
|
||||
|
|
@ -486,15 +502,40 @@ static void
|
|||
etc2_alpha8_fetch_texel(const struct etc2_block *block,
|
||||
int x, int y, uint8_t *dst)
|
||||
{
|
||||
int modifier, alpha, bit, idx;
|
||||
int modifier, alpha, idx;
|
||||
/* get pixel index */
|
||||
bit = ((3 - y) + (3 - x) * 4) * 3;
|
||||
idx = (block->pixel_indices[1] >> bit) & 0x7;
|
||||
idx = etc2_get_pixel_index(block, x, y);
|
||||
modifier = etc2_modifier_tables[block->table_index][idx];
|
||||
alpha = block->base_codeword + modifier * block->multiplier;
|
||||
dst[3] = etc2_clamp(alpha);
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_r11_fetch_texel(const struct etc2_block *block,
|
||||
int x, int y, uint8_t *dst)
|
||||
{
|
||||
GLint modifier, idx;
|
||||
GLshort color;
|
||||
/* Get pixel index */
|
||||
idx = etc2_get_pixel_index(block, x, y);
|
||||
modifier = etc2_modifier_tables[block->table_index][idx];
|
||||
|
||||
if (block->multiplier != 0)
|
||||
/* clamp2(base codeword × 8 + 4 + modifier × multiplier × 8) */
|
||||
color = etc2_clamp2(((block->base_codeword << 3) | 0x4) +
|
||||
((modifier * block->multiplier) << 3));
|
||||
else
|
||||
color = etc2_clamp2(((block->base_codeword << 3) | 0x4) + modifier);
|
||||
|
||||
/* Extend 11 bits color value to 16 bits. OpenGL ES 3.0 specification
|
||||
* allows extending the color value to any number of bits. But, an
|
||||
* implementation is not allowed to truncate the 11-bit value to less than
|
||||
* 11 bits."
|
||||
*/
|
||||
color = (color << 5) | (color >> 6);
|
||||
((GLushort *)dst)[0] = color;
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_alpha8_parse_block(struct etc2_block *block, const uint8_t *src)
|
||||
{
|
||||
|
|
@ -509,6 +550,13 @@ etc2_alpha8_parse_block(struct etc2_block *block, const uint8_t *src)
|
|||
((uint64_t)src[7]));
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_r11_parse_block(struct etc2_block *block, const uint8_t *src)
|
||||
{
|
||||
/* Parsing logic remains same as for etc2_alpha8_parse_block */
|
||||
etc2_alpha8_parse_block(block, src);
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_rgba8_parse_block(struct etc2_block *block, const uint8_t *src)
|
||||
{
|
||||
|
|
@ -680,6 +728,41 @@ etc2_unpack_srgb8_alpha8(uint8_t *dst_row,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
etc2_unpack_r11(uint8_t *dst_row,
|
||||
unsigned dst_stride,
|
||||
const uint8_t *src_row,
|
||||
unsigned src_stride,
|
||||
unsigned width,
|
||||
unsigned height)
|
||||
{
|
||||
/* If internalformat is COMPRESSED_R11_EAC, each 4 × 4 block of
|
||||
color information is compressed to 64 bits.
|
||||
*/
|
||||
const unsigned bw = 4, bh = 4, bs = 8, comps = 1, comp_size = 2;
|
||||
struct etc2_block block;
|
||||
unsigned x, y, i, j;
|
||||
|
||||
for (y = 0; y < height; y += bh) {
|
||||
const uint8_t *src = src_row;
|
||||
|
||||
for (x = 0; x < width; x+= bw) {
|
||||
etc2_r11_parse_block(&block, src);
|
||||
|
||||
for (j = 0; j < bh; j++) {
|
||||
uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps * comp_size;
|
||||
for (i = 0; i < bw; i++) {
|
||||
etc2_r11_fetch_texel(&block, i, j, dst);
|
||||
dst += comps * comp_size;
|
||||
}
|
||||
}
|
||||
src += bs;
|
||||
}
|
||||
|
||||
src_row += src_stride;
|
||||
}
|
||||
}
|
||||
|
||||
/* ETC2 texture formats are valid in glCompressedTexImage2D and
|
||||
* glCompressedTexSubImage2D functions */
|
||||
GLboolean
|
||||
|
|
@ -714,6 +797,14 @@ _mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS)
|
|||
return GL_FALSE;
|
||||
}
|
||||
|
||||
GLboolean
|
||||
_mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS)
|
||||
{
|
||||
ASSERT(0);
|
||||
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
_mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage,
|
||||
GLint i, GLint j, GLint k, GLfloat *texel)
|
||||
|
|
@ -796,12 +887,33 @@ _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct
|
|||
texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
|
||||
}
|
||||
|
||||
void
|
||||
_mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
|
||||
GLint i, GLint j, GLint k, GLfloat *texel)
|
||||
{
|
||||
struct etc2_block block;
|
||||
GLushort dst;
|
||||
const uint8_t *src;
|
||||
|
||||
src = texImage->Map +
|
||||
(((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
|
||||
|
||||
etc2_r11_parse_block(&block, src);
|
||||
etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)&dst);
|
||||
|
||||
texel[RCOMP] = USHORT_TO_FLOAT(dst);
|
||||
texel[GCOMP] = 0.0f;
|
||||
texel[BCOMP] = 0.0f;
|
||||
texel[ACOMP] = 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode texture data in any one of following formats:
|
||||
* `MESA_FORMAT_ETC2_RGB8`
|
||||
* `MESA_FORMAT_ETC2_SRGB8`
|
||||
* `MESA_FORMAT_ETC2_RGBA8_EAC`
|
||||
* `MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC`
|
||||
* `MESA_FORMAT_ETC2_R11_EAC`
|
||||
*
|
||||
* The size of the source data must be a multiple of the ETC2 block size
|
||||
* even if the texture image's dimensions are not aligned to 4.
|
||||
|
|
@ -836,4 +948,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
|
|||
etc2_unpack_srgb8_alpha8(dst_row, dst_stride,
|
||||
src_row, src_stride,
|
||||
src_width, src_height);
|
||||
else if (format == MESA_FORMAT_ETC2_R11_EAC)
|
||||
etc2_unpack_r11(dst_row, dst_stride,
|
||||
src_row, src_stride,
|
||||
src_width, src_height);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ _mesa_texstore_etc2_rgba8_eac(TEXSTORE_PARAMS);
|
|||
GLboolean
|
||||
_mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS);
|
||||
|
||||
GLboolean
|
||||
_mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS);
|
||||
|
||||
void
|
||||
_mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
|
||||
GLint i, GLint j, GLint k, GLfloat *texel);
|
||||
|
|
@ -64,6 +67,9 @@ _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct
|
|||
swrast_texture_image *texImage,
|
||||
GLint i, GLint j,
|
||||
GLint k, GLfloat *texel);
|
||||
void
|
||||
_mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
|
||||
GLint i, GLint j, GLint k, GLfloat *texel);
|
||||
|
||||
void
|
||||
_mesa_etc1_unpack_rgba8888(uint8_t *dst_row,
|
||||
|
|
|
|||
|
|
@ -4128,7 +4128,7 @@ _mesa_get_texstore_func(gl_format format)
|
|||
table[MESA_FORMAT_ETC2_SRGB8] = _mesa_texstore_etc2_srgb8;
|
||||
table[MESA_FORMAT_ETC2_RGBA8_EAC] = _mesa_texstore_etc2_rgba8_eac;
|
||||
table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = _mesa_texstore_etc2_srgb8_alpha8_eac;
|
||||
/* table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac; -- not implemented yet */
|
||||
table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac;
|
||||
/* table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac; -- not implemented yet */
|
||||
/* table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = _mesa_texstore_etc2_signed_r11_eac; -- not implemented yet */
|
||||
/* table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = _mesa_texstore_etc2_signed_rg11_eac; -- not implemented yet */
|
||||
|
|
|
|||
|
|
@ -1055,7 +1055,7 @@ texfetch_funcs[] =
|
|||
{
|
||||
MESA_FORMAT_ETC2_R11_EAC,
|
||||
NULL,
|
||||
NULL /* _mesa_fetch_texel_2d_f_etc2_r11_eac -- not implemented yet */,
|
||||
_mesa_fetch_texel_2d_f_etc2_r11_eac,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue