diff options
Diffstat (limited to 'mesalib/src/mesa/main')
-rw-r--r-- | mesalib/src/mesa/main/bufferobj.c | 22 | ||||
-rw-r--r-- | mesalib/src/mesa/main/extensions.c | 1 | ||||
-rw-r--r-- | mesalib/src/mesa/main/ff_fragment_shader.cpp | 1 | ||||
-rw-r--r-- | mesalib/src/mesa/main/format_unpack.c | 101 | ||||
-rw-r--r-- | mesalib/src/mesa/main/format_unpack.h | 3 | ||||
-rw-r--r-- | mesalib/src/mesa/main/formats.c | 133 | ||||
-rw-r--r-- | mesalib/src/mesa/main/formats.h | 10 | ||||
-rw-r--r-- | mesalib/src/mesa/main/glformats.c | 21 | ||||
-rw-r--r-- | mesalib/src/mesa/main/mtypes.h | 9 | ||||
-rw-r--r-- | mesalib/src/mesa/main/set.c | 348 | ||||
-rw-r--r-- | mesalib/src/mesa/main/set.h | 94 | ||||
-rw-r--r-- | mesalib/src/mesa/main/shared.c | 12 | ||||
-rw-r--r-- | mesalib/src/mesa/main/syncobj.c | 31 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress.c | 100 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress_etc.c | 1376 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress_etc.h | 79 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texcompress_s3tc.c | 52 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texformat.c | 37 | ||||
-rw-r--r-- | mesalib/src/mesa/main/teximage.c | 21 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texstore.c | 12 |
20 files changed, 2372 insertions, 91 deletions
diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index dbcd0e6e6..ce873ecd7 100644 --- a/mesalib/src/mesa/main/bufferobj.c +++ b/mesalib/src/mesa/main/bufferobj.c @@ -2160,17 +2160,19 @@ _mesa_BindBufferRange(GLenum target, GLuint index, return; } - if (size <= 0) { - _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)", - (int) size); - return; - } + if (buffer != 0) { + if (size <= 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)", + (int) size); + return; + } - if (offset + size > bufObj->Size) { - _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBufferRange(offset + size %d > buffer size %d)", - (int) (offset + size), (int) (bufObj->Size)); - return; + if (offset + size > bufObj->Size) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glBindBufferRange(offset + size %d > buffer size %d)", + (int) (offset + size), (int) (bufObj->Size)); + return; + } } switch (target) { diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index 150d41e04..11cbea2b4 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -80,6 +80,7 @@ struct extension { static const struct extension extension_table[] = { /* ARB Extensions */ { "GL_ARB_ES2_compatibility", o(ARB_ES2_compatibility), GL, 2009 }, + { "GL_ARB_ES3_compatibility", o(ARB_ES3_compatibility), GL, 2012 }, { "GL_ARB_base_instance", o(ARB_base_instance), GL, 2011 }, { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL, 2009 }, { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), GL, 2004 }, diff --git a/mesalib/src/mesa/main/ff_fragment_shader.cpp b/mesalib/src/mesa/main/ff_fragment_shader.cpp index 3a80ab7f3..02b4707f0 100644 --- a/mesalib/src/mesa/main/ff_fragment_shader.cpp +++ b/mesalib/src/mesa/main/ff_fragment_shader.cpp @@ -1309,6 +1309,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key) p.shader_program->InternalSeparateShader = GL_TRUE; state->language_version = 130; + state->es_shader = false; if (ctx->Extensions.OES_EGL_image_external) state->OES_EGL_image_external_enable = true; _mesa_glsl_initialize_types(state); diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c index 04fd1d698..d34a27b82 100644 --- a/mesalib/src/mesa/main/format_unpack.c +++ b/mesalib/src/mesa/main/format_unpack.c @@ -57,8 +57,8 @@ struct z32f_x24s8 * linear RGB value in [0, 1]. * Implemented with a 256-entry lookup table. */ -static inline GLfloat -nonlinear_to_linear(GLubyte cs8) +GLfloat +_mesa_nonlinear_to_linear(GLubyte cs8) { static GLfloat table[256]; static GLboolean tableReady = GL_FALSE; @@ -742,9 +742,9 @@ unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n) const GLubyte *s = (const GLubyte *) src; GLuint i; for (i = 0; i < n; i++) { - dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]); - dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]); - dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]); + dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]); + dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]); dst[i][ACOMP] = 1.0F; } } @@ -755,9 +755,9 @@ unpack_SRGBA8(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] = nonlinear_to_linear( (s[i] >> 24) ); - dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); - dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) ); + dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */ } } @@ -768,9 +768,9 @@ unpack_SARGB8(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] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); - dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); - dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff ); + dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ } } @@ -783,7 +783,7 @@ unpack_SL8(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = nonlinear_to_linear(s[i]); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]); dst[i][ACOMP] = 1.0F; } } @@ -796,7 +796,7 @@ unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff); dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */ } } @@ -1337,6 +1337,68 @@ unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n) } static void +unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4], + GLuint n) +{ + /* XXX to do */ +} + +static void +unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4], + GLuint n) +{ + /* XXX to do */ +} + +static void unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n) { const GLbyte *s = ((const GLbyte *) src); @@ -1585,7 +1647,18 @@ get_unpack_rgba_function(gl_format format) table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2; table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8; - + table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8; + table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8; + table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC; + table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC; + table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC; + table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC; + table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC; + table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC; + table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] = + unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; + table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] = + unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1; table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8; table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8; table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88; diff --git a/mesalib/src/mesa/main/format_unpack.h b/mesalib/src/mesa/main/format_unpack.h index aad800dd1..29c526319 100644 --- a/mesalib/src/mesa/main/format_unpack.h +++ b/mesalib/src/mesa/main/format_unpack.h @@ -24,6 +24,9 @@ #ifndef FORMAT_UNPACK_H #define FORMAT_UNPACK_H +extern GLfloat +_mesa_nonlinear_to_linear(GLubyte cs8); + extern void _mesa_unpack_rgba_row(gl_format format, GLuint n, const void *src, GLfloat dst[][4]); diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c index df23af1dd..47a1d6802 100644 --- a/mesalib/src/mesa/main/formats.c +++ b/mesalib/src/mesa/main/formats.c @@ -1398,6 +1398,106 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = 4, 4, 8 /* 8 bytes per 4x4 block */ }, + { + MESA_FORMAT_ETC2_RGB8, + "MESA_FORMAT_ETC2_RGB8", + GL_RGB, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 0, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_SRGB8, + "MESA_FORMAT_ETC2_SRGB8", + GL_RGB, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 0, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_RGBA8_EAC, + "MESA_FORMAT_ETC2_RGBA8_EAC", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 4, 4, 16 /* 16 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC, + "MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 8, + 0, 0, 0, 0, 0, + 4, 4, 16 /* 16 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_R11_EAC, + "MESA_FORMAT_ETC2_R11_EAC", + GL_RED, + GL_UNSIGNED_NORMALIZED, + 11, 0, 0, 0, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_RG11_EAC, + "MESA_FORMAT_ETC2_RG11_EAC", + GL_RG, + GL_UNSIGNED_NORMALIZED, + 11, 11, 0, 0, + 0, 0, 0, 0, 0, + 4, 4, 16 /* 16 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_SIGNED_R11_EAC, + "MESA_FORMAT_ETC2_SIGNED_R11_EAC", + GL_RED, + GL_SIGNED_NORMALIZED, + 11, 0, 0, 0, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_SIGNED_RG11_EAC, + "MESA_FORMAT_ETC2_SIGNED_RG11_EAC", + GL_RG, + GL_SIGNED_NORMALIZED, + 11, 11, 0, 0, + 0, 0, 0, 0, 0, + 4, 4, 16 /* 16 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, + "MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 1, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + + { + MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, + "MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1", + GL_RGBA, + GL_UNSIGNED_NORMALIZED, + 8, 8, 8, 1, + 0, 0, 0, 0, 0, + 4, 4, 8 /* 8 bytes per 4x4 block */ + }, + /* Signed formats from EXT_texture_snorm that are not in GL3.1 */ { MESA_FORMAT_SIGNED_A8, @@ -1840,7 +1940,20 @@ _mesa_get_uncompressed_format(gl_format format) case MESA_FORMAT_SIGNED_LA_LATC2: return MESA_FORMAT_SIGNED_AL88; case MESA_FORMAT_ETC1_RGB8: + case MESA_FORMAT_ETC2_RGB8: + case MESA_FORMAT_ETC2_SRGB8: return MESA_FORMAT_RGB888; + case MESA_FORMAT_ETC2_RGBA8_EAC: + case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: + case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: + return MESA_FORMAT_RGBA8888; + case MESA_FORMAT_ETC2_R11_EAC: + case MESA_FORMAT_ETC2_SIGNED_R11_EAC: + return MESA_FORMAT_R16; + case MESA_FORMAT_ETC2_RG11_EAC: + case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: + return MESA_FORMAT_RG1616; default: #ifdef DEBUG assert(!_mesa_is_format_compressed(format)); @@ -2282,6 +2395,16 @@ _mesa_format_to_type_and_comps(gl_format format, case MESA_FORMAT_LA_LATC2: case MESA_FORMAT_SIGNED_LA_LATC2: case MESA_FORMAT_ETC1_RGB8: + case MESA_FORMAT_ETC2_RGB8: + case MESA_FORMAT_ETC2_SRGB8: + case MESA_FORMAT_ETC2_RGBA8_EAC: + case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: + case MESA_FORMAT_ETC2_R11_EAC: + case MESA_FORMAT_ETC2_RG11_EAC: + case MESA_FORMAT_ETC2_SIGNED_R11_EAC: + case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: + case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: /* XXX generate error instead? */ *datatype = GL_UNSIGNED_BYTE; *comps = 0; @@ -2912,6 +3035,16 @@ _mesa_format_matches_format_and_type(gl_format gl_format, return GL_FALSE; case MESA_FORMAT_ETC1_RGB8: + case MESA_FORMAT_ETC2_RGB8: + case MESA_FORMAT_ETC2_SRGB8: + case MESA_FORMAT_ETC2_RGBA8_EAC: + case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: + case MESA_FORMAT_ETC2_R11_EAC: + case MESA_FORMAT_ETC2_RG11_EAC: + case MESA_FORMAT_ETC2_SIGNED_R11_EAC: + case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: + case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return GL_FALSE; case MESA_FORMAT_SIGNED_A8: diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h index 1843eb6fc..050fce96c 100644 --- a/mesalib/src/mesa/main/formats.h +++ b/mesalib/src/mesa/main/formats.h @@ -259,6 +259,16 @@ typedef enum /*@}*/ MESA_FORMAT_ETC1_RGB8, + MESA_FORMAT_ETC2_RGB8, + MESA_FORMAT_ETC2_SRGB8, + MESA_FORMAT_ETC2_RGBA8_EAC, + MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC, + MESA_FORMAT_ETC2_R11_EAC, + MESA_FORMAT_ETC2_RG11_EAC, + MESA_FORMAT_ETC2_SIGNED_R11_EAC, + MESA_FORMAT_ETC2_SIGNED_RG11_EAC, + MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, + MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, MESA_FORMAT_SIGNED_A8, /* AAAA AAAA */ MESA_FORMAT_SIGNED_L8, /* LLLL LLLL */ diff --git a/mesalib/src/mesa/main/glformats.c b/mesalib/src/mesa/main/glformats.c index 69caef70b..fefa9c441 100644 --- a/mesalib/src/mesa/main/glformats.c +++ b/mesalib/src/mesa/main/glformats.c @@ -570,6 +570,16 @@ _mesa_is_color_format(GLenum format) case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: case GL_ETC1_RGB8_OES: + case GL_COMPRESSED_RGB8_ETC2: + case GL_COMPRESSED_SRGB8_ETC2: + case GL_COMPRESSED_RGBA8_ETC2_EAC: + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + case GL_COMPRESSED_R11_EAC: + case GL_COMPRESSED_RG11_EAC: + case GL_COMPRESSED_SIGNED_R11_EAC: + case GL_COMPRESSED_SIGNED_RG11_EAC: + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: /* generic integer formats */ case GL_RED_INTEGER_EXT: case GL_GREEN_INTEGER_EXT: @@ -829,6 +839,17 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format) case GL_ETC1_RGB8_OES: return _mesa_is_gles(ctx) && ctx->Extensions.OES_compressed_ETC1_RGB8_texture; + case GL_COMPRESSED_RGB8_ETC2: + case GL_COMPRESSED_SRGB8_ETC2: + case GL_COMPRESSED_RGBA8_ETC2_EAC: + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + case GL_COMPRESSED_R11_EAC: + case GL_COMPRESSED_RG11_EAC: + case GL_COMPRESSED_SIGNED_R11_EAC: + case GL_COMPRESSED_SIGNED_RG11_EAC: + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: + return _mesa_is_gles3(ctx); case GL_PALETTE4_RGB8_OES: case GL_PALETTE4_RGBA8_OES: case GL_PALETTE4_R5_G6_B5_OES: diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 5bfae69c8..b353e7026 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -79,6 +79,8 @@ struct st_context; struct gl_uniform_storage; struct prog_instruction; struct gl_program_parameter_list; +struct set; +struct set_entry; /*@}*/ @@ -2184,6 +2186,7 @@ struct gl_shader struct gl_sl_pragmas Pragmas; unsigned Version; /**< GLSL version used for linking */ + GLboolean IsES; /**< True if this shader uses GLSL ES */ /** * \name Sampler tracking @@ -2386,6 +2389,7 @@ struct gl_shader_program GLchar *InfoLog; unsigned Version; /**< GLSL version used for linking */ + GLboolean IsES; /**< True if this program uses GLSL ES */ /** * Per-stage shaders resulting from the first stage of linking. @@ -2509,7 +2513,7 @@ struct gl_query_state /** Sync object state */ struct gl_sync_object { - struct simple_node link; + struct set_entry *SetEntry; GLenum Type; /**< GL_SYNC_FENCE */ GLuint Name; /**< Fence name */ GLint RefCount; /**< Reference count */ @@ -2576,7 +2580,7 @@ struct gl_shared_state struct _mesa_HashTable *FrameBuffers; /* GL_ARB_sync */ - struct simple_node SyncObjects; + struct set *SyncObjects; /** GL_ARB_sampler_objects */ struct _mesa_HashTable *SamplerObjects; @@ -2939,6 +2943,7 @@ struct gl_extensions GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */ GLboolean ANGLE_texture_compression_dxt; GLboolean ARB_ES2_compatibility; + GLboolean ARB_ES3_compatibility; GLboolean ARB_base_instance; GLboolean ARB_blend_func_extended; GLboolean ARB_color_buffer_float; diff --git a/mesalib/src/mesa/main/set.c b/mesalib/src/mesa/main/set.c new file mode 100644 index 000000000..736841fc9 --- /dev/null +++ b/mesalib/src/mesa/main/set.c @@ -0,0 +1,348 @@ +/* + * Copyright © 2009-2012 Intel Corporation + * Copyright © 1988-2004 Keith Packard and Bart Massey. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors + * or their institutions shall not be used in advertising or + * otherwise to promote the sale, use or other dealings in this + * Software without prior written authorization from the + * authors. + * + * Authors: + * Eric Anholt <eric@anholt.net> + * Keith Packard <keithp@keithp.com> + */ + +#include <stdlib.h> + +#include "set.h" +#include "ralloc.h" + +#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) + +/* + * From Knuth -- a good choice for hash/rehash values is p, p-2 where + * p and p-2 are both prime. These tables are sized to have an extra 10% + * free to avoid exponential performance degradation as the hash table fills + */ + +uint32_t deleted_key_value; +const void *deleted_key = &deleted_key_value; + +static const struct { + uint32_t max_entries, size, rehash; +} hash_sizes[] = { + { 2, 5, 3 }, + { 4, 7, 5 }, + { 8, 13, 11 }, + { 16, 19, 17 }, + { 32, 43, 41 }, + { 64, 73, 71 }, + { 128, 151, 149 }, + { 256, 283, 281 }, + { 512, 571, 569 }, + { 1024, 1153, 1151 }, + { 2048, 2269, 2267 }, + { 4096, 4519, 4517 }, + { 8192, 9013, 9011 }, + { 16384, 18043, 18041 }, + { 32768, 36109, 36107 }, + { 65536, 72091, 72089 }, + { 131072, 144409, 144407 }, + { 262144, 288361, 288359 }, + { 524288, 576883, 576881 }, + { 1048576, 1153459, 1153457 }, + { 2097152, 2307163, 2307161 }, + { 4194304, 4613893, 4613891 }, + { 8388608, 9227641, 9227639 }, + { 16777216, 18455029, 18455027 }, + { 33554432, 36911011, 36911009 }, + { 67108864, 73819861, 73819859 }, + { 134217728, 147639589, 147639587 }, + { 268435456, 295279081, 295279079 }, + { 536870912, 590559793, 590559791 }, + { 1073741824, 1181116273, 1181116271 }, + { 2147483648ul, 2362232233ul, 2362232231ul } +}; + +static int +entry_is_free(struct set_entry *entry) +{ + return entry->key == NULL; +} + +static int +entry_is_deleted(struct set_entry *entry) +{ + return entry->key == deleted_key; +} + +static int +entry_is_present(struct set_entry *entry) +{ + return entry->key != NULL && entry->key != deleted_key; +} + +struct set * +_mesa_set_create(void *mem_ctx, + bool key_equals_function(const void *a, + const void *b)) +{ + struct set *ht; + + ht = ralloc(mem_ctx, struct set); + if (ht == NULL) + return NULL; + + ht->mem_ctx = mem_ctx; + ht->size_index = 0; + ht->size = hash_sizes[ht->size_index].size; + ht->rehash = hash_sizes[ht->size_index].rehash; + ht->max_entries = hash_sizes[ht->size_index].max_entries; + ht->key_equals_function = key_equals_function; + ht->table = rzalloc_array(ht, struct set_entry, ht->size); + ht->entries = 0; + ht->deleted_entries = 0; + + if (ht->table == NULL) { + ralloc_free(ht); + return NULL; + } + + return ht; +} + +/** + * Frees the given set. + * + * If delete_function is passed, it gets called on each entry present before + * freeing. + */ +void +_mesa_set_destroy(struct set *ht, void (*delete_function)(struct set_entry *entry)) +{ + if (!ht) + return; + + if (delete_function) { + struct set_entry *entry; + + set_foreach (ht, entry) { + delete_function(entry); + } + } + ralloc_free(ht->table); + ralloc_free(ht); +} + +/** + * Finds a set entry with the given key and hash of that key. + * + * Returns NULL if no entry is found. + */ +struct set_entry * +_mesa_set_search(const struct set *ht, uint32_t hash, const void *key) +{ + uint32_t hash_address; + + hash_address = hash % ht->size; + do { + uint32_t double_hash; + + struct set_entry *entry = ht->table + hash_address; + + if (entry_is_free(entry)) { + return NULL; + } else if (entry_is_present(entry) && entry->hash == hash) { + if (ht->key_equals_function(key, entry->key)) { + return entry; + } + } + + double_hash = 1 + hash % ht->rehash; + + hash_address = (hash_address + double_hash) % ht->size; + } while (hash_address != hash % ht->size); + + return NULL; +} + +static void +set_rehash(struct set *ht, int new_size_index) +{ + struct set old_ht; + struct set_entry *table, *entry; + + if (new_size_index >= ARRAY_SIZE(hash_sizes)) + return; + + table = rzalloc_array(ht, struct set_entry, + hash_sizes[new_size_index].size); + if (table == NULL) + return; + + old_ht = *ht; + + ht->table = table; + ht->size_index = new_size_index; + ht->size = hash_sizes[ht->size_index].size; + ht->rehash = hash_sizes[ht->size_index].rehash; + ht->max_entries = hash_sizes[ht->size_index].max_entries; + ht->entries = 0; + ht->deleted_entries = 0; + + for (entry = old_ht.table; + entry != old_ht.table + old_ht.size; + entry++) { + if (entry_is_present(entry)) { + _mesa_set_add(ht, entry->hash, entry->key); + } + } + + ralloc_free(old_ht.table); +} + +/** + * Inserts the key with the given hash into the table. + * + * Note that insertion may rearrange the table on a resize or rehash, + * so previously found hash_entries are no longer valid after this function. + */ +struct set_entry * +_mesa_set_add(struct set *ht, uint32_t hash, const void *key) +{ + uint32_t hash_address; + + if (ht->entries >= ht->max_entries) { + set_rehash(ht, ht->size_index + 1); + } else if (ht->deleted_entries + ht->entries >= ht->max_entries) { + set_rehash(ht, ht->size_index); + } + + hash_address = hash % ht->size; + do { + struct set_entry *entry = ht->table + hash_address; + uint32_t double_hash; + + if (!entry_is_present(entry)) { + if (entry_is_deleted(entry)) + ht->deleted_entries--; + entry->hash = hash; + entry->key = key; + ht->entries++; + return entry; + } + + /* Implement replacement when another insert happens + * with a matching key. This is a relatively common + * feature of hash tables, with the alternative + * generally being "insert the new value as well, and + * return it first when the key is searched for". + * + * Note that the hash table doesn't have a delete callback. + * If freeing of old keys is required to avoid memory leaks, + * perform a search before inserting. + */ + if (entry->hash == hash && + ht->key_equals_function(key, entry->key)) { + entry->key = key; + return entry; + } + + double_hash = 1 + hash % ht->rehash; + + hash_address = (hash_address + double_hash) % ht->size; + } while (hash_address != hash % ht->size); + + /* We could hit here if a required resize failed. An unchecked-malloc + * application could ignore this result. + */ + return NULL; +} + +/** + * This function deletes the given hash table entry. + * + * Note that deletion doesn't otherwise modify the table, so an iteration over + * the table deleting entries is safe. + */ +void +_mesa_set_remove(struct set *ht, struct set_entry *entry) +{ + if (!entry) + return; + + entry->key = deleted_key; + ht->entries--; + ht->deleted_entries++; +} + +/** + * This function is an iterator over the hash table. + * + * Pass in NULL for the first entry, as in the start of a for loop. Note that + * an iteration over the table is O(table_size) not O(entries). + */ +struct set_entry * +_mesa_set_next_entry(const struct set *ht, struct set_entry *entry) +{ + if (entry == NULL) + entry = ht->table; + else + entry = entry + 1; + + for (; entry != ht->table + ht->size; entry++) { + if (entry_is_present(entry)) { + return entry; + } + } + + return NULL; +} + +struct set_entry * +_mesa_set_random_entry(struct set *ht, + int (*predicate)(struct set_entry *entry)) +{ + struct set_entry *entry; + uint32_t i = rand() % ht->size; + + if (ht->entries == 0) + return NULL; + + for (entry = ht->table + i; entry != ht->table + ht->size; entry++) { + if (entry_is_present(entry) && + (!predicate || predicate(entry))) { + return entry; + } + } + + for (entry = ht->table; entry != ht->table + i; entry++) { + if (entry_is_present(entry) && + (!predicate || predicate(entry))) { + return entry; + } + } + + return NULL; +} + diff --git a/mesalib/src/mesa/main/set.h b/mesalib/src/mesa/main/set.h new file mode 100644 index 000000000..206d0c4d2 --- /dev/null +++ b/mesalib/src/mesa/main/set.h @@ -0,0 +1,94 @@ +/* + * Copyright © 2009-2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt <eric@anholt.net> + * + */ + +#ifndef _SET_H +#define _SET_H + +#include <inttypes.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct set_entry { + uint32_t hash; + const void *key; +}; + +struct set { + void *mem_ctx; + struct set_entry *table; + bool (*key_equals_function)(const void *a, const void *b); + uint32_t size; + uint32_t rehash; + uint32_t max_entries; + uint32_t size_index; + uint32_t entries; + uint32_t deleted_entries; +}; + +struct set * +_mesa_set_create(void *mem_ctx, + bool (*key_equals_function)(const void *a, + const void *b)); +void +_mesa_set_destroy(struct set *set, + void (*delete_function)(struct set_entry *entry)); + +struct set_entry * +_mesa_set_add(struct set *set, uint32_t hash, const void *key); + +struct set_entry * +_mesa_set_search(const struct set *set, uint32_t hash, + const void *key); + +void +_mesa_set_remove(struct set *set, struct set_entry *entry); + +struct set_entry * +_mesa_set_next_entry(const struct set *set, struct set_entry *entry); + +struct set_entry * +_mesa_set_random_entry(struct set *set, + int (*predicate)(struct set_entry *entry)); + +/** + * This foreach function is safe against deletion, but not against + * insertion (which may rehash the set, making entry a dangling + * pointer). + */ +#define set_foreach(set, entry) \ + for (entry = _mesa_set_next_entry(set, NULL); \ + entry != NULL; \ + entry = _mesa_set_next_entry(set, entry)) + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif /* _SET_H */ diff --git a/mesalib/src/mesa/main/shared.c b/mesalib/src/mesa/main/shared.c index eaf9f8de1..a98a45c75 100644 --- a/mesalib/src/mesa/main/shared.c +++ b/mesalib/src/mesa/main/shared.c @@ -31,12 +31,14 @@ #include "mfeatures.h" #include "mtypes.h" #include "hash.h" +#include "hash_table.h" #include "atifragshader.h" #include "bufferobj.h" #include "shared.h" #include "program/program.h" #include "dlist.h" #include "samplerobj.h" +#include "set.h" #include "shaderobj.h" #include "syncobj.h" @@ -115,7 +117,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx) shared->FrameBuffers = _mesa_NewHashTable(); shared->RenderBuffers = _mesa_NewHashTable(); - make_empty_list(& shared->SyncObjects); + shared->SyncObjects = _mesa_set_create(NULL, _mesa_key_pointer_equal); return shared; } @@ -327,13 +329,13 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL); { - struct simple_node *node; - struct simple_node *temp; + struct set_entry *entry; - foreach_s(node, temp, & shared->SyncObjects) { - _mesa_unref_sync_object(ctx, (struct gl_sync_object *) node); + set_foreach(shared->SyncObjects, entry) { + _mesa_unref_sync_object(ctx, (struct gl_sync_object *) entry->key); } } + _mesa_set_destroy(shared->SyncObjects, NULL); _mesa_HashDeleteAll(shared->SamplerObjects, delete_sampler_object_cb, ctx); _mesa_DeleteHashTable(shared->SamplerObjects); diff --git a/mesalib/src/mesa/main/syncobj.c b/mesalib/src/mesa/main/syncobj.c index 598414596..12e325ccd 100644 --- a/mesalib/src/mesa/main/syncobj.c +++ b/mesalib/src/mesa/main/syncobj.c @@ -64,6 +64,8 @@ #include "get.h" #include "dispatch.h" #include "mtypes.h" +#include "set.h" +#include "hash_table.h" #include "syncobj.h" @@ -174,9 +176,12 @@ _mesa_free_sync_data(struct gl_context *ctx) static int -_mesa_validate_sync(struct gl_sync_object *syncObj) +_mesa_validate_sync(struct gl_context *ctx, struct gl_sync_object *syncObj) { return (syncObj != NULL) + && _mesa_set_search(ctx->Shared->SyncObjects, + _mesa_hash_pointer(syncObj), + syncObj) != NULL && (syncObj->Type == GL_SYNC_FENCE) && !syncObj->DeletePending; } @@ -197,7 +202,7 @@ _mesa_unref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj) _glthread_LOCK_MUTEX(ctx->Shared->Mutex); syncObj->RefCount--; if (syncObj->RefCount == 0) { - remove_from_list(& syncObj->link); + _mesa_set_remove(ctx->Shared->SyncObjects, syncObj->SetEntry); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); ctx->Driver.DeleteSyncObject(ctx, syncObj); @@ -214,7 +219,7 @@ _mesa_IsSync(GLsync sync) struct gl_sync_object *const syncObj = (struct gl_sync_object *) sync; ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); - return _mesa_validate_sync(syncObj) ? GL_TRUE : GL_FALSE; + return _mesa_validate_sync(ctx, syncObj) ? GL_TRUE : GL_FALSE; } @@ -235,8 +240,8 @@ _mesa_DeleteSync(GLsync sync) return; } - if (!_mesa_validate_sync(syncObj)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteSync"); + if (!_mesa_validate_sync(ctx, syncObj)) { + _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteSync (not a valid sync object)"); return; } @@ -285,7 +290,9 @@ _mesa_FenceSync(GLenum condition, GLbitfield flags) ctx->Driver.FenceSync(ctx, syncObj, condition, flags); _glthread_LOCK_MUTEX(ctx->Shared->Mutex); - insert_at_tail(& ctx->Shared->SyncObjects, & syncObj->link); + syncObj->SetEntry = _mesa_set_add(ctx->Shared->SyncObjects, + _mesa_hash_pointer(syncObj), + syncObj); _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); return (GLsync) syncObj; @@ -303,8 +310,8 @@ _mesa_ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) GLenum ret; ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_WAIT_FAILED); - if (!_mesa_validate_sync(syncObj)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glClientWaitSync"); + if (!_mesa_validate_sync(ctx, syncObj)) { + _mesa_error(ctx, GL_INVALID_VALUE, "glClientWaitSync (not a valid sync object)"); return GL_WAIT_FAILED; } @@ -347,8 +354,8 @@ _mesa_WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) struct gl_sync_object *const syncObj = (struct gl_sync_object *) sync; ASSERT_OUTSIDE_BEGIN_END(ctx); - if (!_mesa_validate_sync(syncObj)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glWaitSync"); + if (!_mesa_validate_sync(ctx, syncObj)) { + _mesa_error(ctx, GL_INVALID_VALUE, "glWaitSync (not a valid sync object)"); return; } @@ -377,8 +384,8 @@ _mesa_GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint v[1]; ASSERT_OUTSIDE_BEGIN_END(ctx); - if (!_mesa_validate_sync(syncObj)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glGetSynciv"); + if (!_mesa_validate_sync(ctx, syncObj)) { + _mesa_error(ctx, GL_INVALID_VALUE, "glGetSynciv (not a valid sync object)"); return; } diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c index 957cc6df6..372a483fa 100644 --- a/mesalib/src/mesa/main/texcompress.c +++ b/mesalib/src/mesa/main/texcompress.c @@ -33,6 +33,7 @@ #include "glheader.h" #include "imports.h" #include "colormac.h" +#include "context.h" #include "formats.h" #include "mfeatures.h" #include "mtypes.h" @@ -77,12 +78,16 @@ _mesa_gl_compressed_format_base_format(GLenum format) { switch (format) { case GL_COMPRESSED_RED: + case GL_COMPRESSED_R11_EAC: case GL_COMPRESSED_RED_RGTC1: + case GL_COMPRESSED_SIGNED_R11_EAC: case GL_COMPRESSED_SIGNED_RED_RGTC1: return GL_RED; case GL_COMPRESSED_RG: + case GL_COMPRESSED_RG11_EAC: case GL_COMPRESSED_RG_RGTC2: + case GL_COMPRESSED_SIGNED_RG11_EAC: case GL_COMPRESSED_SIGNED_RG_RGTC2: return GL_RG; @@ -92,6 +97,8 @@ _mesa_gl_compressed_format_base_format(GLenum format) case GL_COMPRESSED_RGB_FXT1_3DFX: case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: case GL_ETC1_RGB8_OES: + case GL_COMPRESSED_RGB8_ETC2: + case GL_COMPRESSED_SRGB8_ETC2: return GL_RGB; case GL_COMPRESSED_RGBA: @@ -107,6 +114,10 @@ _mesa_gl_compressed_format_base_format(GLenum format) case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + case GL_COMPRESSED_RGBA8_ETC2_EAC: + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: return GL_RGBA; case GL_COMPRESSED_ALPHA: @@ -293,6 +304,23 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) } } + if (_mesa_is_gles3(ctx)) { + if (formats) { + formats[n++] = GL_COMPRESSED_RGB8_ETC2; + formats[n++] = GL_COMPRESSED_SRGB8_ETC2; + formats[n++] = GL_COMPRESSED_RGBA8_ETC2_EAC; + formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + formats[n++] = GL_COMPRESSED_R11_EAC; + formats[n++] = GL_COMPRESSED_RG11_EAC; + formats[n++] = GL_COMPRESSED_SIGNED_R11_EAC; + formats[n++] = GL_COMPRESSED_SIGNED_RG11_EAC; + formats[n++] = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + formats[n++] = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; + } + else { + n += 10; + } + } return n; } @@ -352,6 +380,26 @@ _mesa_glenum_to_compressed_format(GLenum format) case GL_ETC1_RGB8_OES: return MESA_FORMAT_ETC1_RGB8; + case GL_COMPRESSED_RGB8_ETC2: + return MESA_FORMAT_ETC2_RGB8; + case GL_COMPRESSED_SRGB8_ETC2: + return MESA_FORMAT_ETC2_SRGB8; + case GL_COMPRESSED_RGBA8_ETC2_EAC: + return MESA_FORMAT_ETC2_RGBA8_EAC; + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + return MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC; + case GL_COMPRESSED_R11_EAC: + return MESA_FORMAT_ETC2_R11_EAC; + case GL_COMPRESSED_RG11_EAC: + return MESA_FORMAT_ETC2_RG11_EAC; + case GL_COMPRESSED_SIGNED_R11_EAC: + return MESA_FORMAT_ETC2_SIGNED_R11_EAC; + case GL_COMPRESSED_SIGNED_RG11_EAC: + return MESA_FORMAT_ETC2_SIGNED_RG11_EAC; + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + return MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: + return MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1; default: return MESA_FORMAT_NONE; @@ -413,6 +461,26 @@ _mesa_compressed_format_to_glenum(struct gl_context *ctx, gl_format mesaFormat) case MESA_FORMAT_ETC1_RGB8: return GL_ETC1_RGB8_OES; + case MESA_FORMAT_ETC2_RGB8: + return GL_COMPRESSED_RGB8_ETC2; + case MESA_FORMAT_ETC2_SRGB8: + return GL_COMPRESSED_SRGB8_ETC2; + case MESA_FORMAT_ETC2_RGBA8_EAC: + return GL_COMPRESSED_RGBA8_ETC2_EAC; + case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: + return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + case MESA_FORMAT_ETC2_R11_EAC: + return GL_COMPRESSED_R11_EAC; + case MESA_FORMAT_ETC2_RG11_EAC: + return GL_COMPRESSED_RG11_EAC; + case MESA_FORMAT_ETC2_SIGNED_R11_EAC: + return GL_COMPRESSED_SIGNED_R11_EAC; + case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: + return GL_COMPRESSED_SIGNED_RG11_EAC; + case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: + return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; default: _mesa_problem(ctx, "Unexpected mesa texture format in" @@ -538,6 +606,38 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height, fetch = _mesa_fetch_texel_2d_f_etc1_rgb8; break; + /* ETC2 formats */ + case MESA_FORMAT_ETC2_RGB8: + fetch = _mesa_fetch_texel_2d_f_etc2_rgb8; + break; + case MESA_FORMAT_ETC2_SRGB8: + fetch = _mesa_fetch_texel_2d_f_etc2_srgb8; + break; + case MESA_FORMAT_ETC2_RGBA8_EAC: + fetch = _mesa_fetch_texel_2d_f_etc2_rgba8_eac; + break; + case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: + 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; + break; + case MESA_FORMAT_ETC2_RG11_EAC: + fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac; + break; + case MESA_FORMAT_ETC2_SIGNED_R11_EAC: + fetch = _mesa_fetch_texel_2d_f_etc2_signed_r11_eac; + break; + case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: + fetch = _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac; + break; + case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: + fetch = _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1; + break; + case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: + fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1; + break; + default: _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()"); return; diff --git a/mesalib/src/mesa/main/texcompress_etc.c b/mesalib/src/mesa/main/texcompress_etc.c index c645f52b9..73d2fa4fe 100644 --- a/mesalib/src/mesa/main/texcompress_etc.c +++ b/mesalib/src/mesa/main/texcompress_etc.c @@ -24,24 +24,78 @@ /** * \file texcompress_etc.c * GL_OES_compressed_ETC1_RGB8_texture support. + * Supported ETC2 texture formats are: + * GL_COMPRESSED_RGB8_ETC2 + * GL_COMPRESSED_SRGB8_ETC2 + * GL_COMPRESSED_RGBA8_ETC2_EAC + * GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC + * GL_COMPRESSED_R11_EAC + * GL_COMPRESSED_RG11_EAC + * GL_COMPRESSED_SIGNED_R11_EAC + * GL_COMPRESSED_SIGNED_RG11_EAC + * MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1 + * MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 */ - +#include <stdbool.h> #include "mfeatures.h" #include "texcompress.h" #include "texcompress_etc.h" #include "texstore.h" #include "macros.h" #include "swrast/s_context.h" +#include "format_unpack.h" -GLboolean -_mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS) -{ - /* GL_ETC1_RGB8_OES is only valid in glCompressedTexImage2D */ - ASSERT(0); +struct etc2_block { + int distance; + uint64_t pixel_indices[2]; + const int *modifier_tables[2]; + bool flipped; + bool opaque; + bool is_ind_mode; + bool is_diff_mode; + bool is_t_mode; + bool is_h_mode; + bool is_planar_mode; + uint8_t base_colors[3][3]; + uint8_t paint_colors[4][3]; + uint8_t base_codeword; + uint8_t multiplier; + uint8_t table_index; +}; - return GL_FALSE; -} +static const int etc2_distance_table[8] = { + 3, 6, 11, 16, 23, 32, 41, 64 }; + +static const int etc2_modifier_tables[16][8] = { + { -3, -6, -9, -15, 2, 5, 8, 14}, + { -3, -7, -10, -13, 2, 6, 9, 12}, + { -2, -5, -8, -13, 1, 4, 7, 12}, + { -2, -4, -6, -13, 1, 3, 5, 12}, + { -3, -6, -8, -12, 2, 5, 7, 11}, + { -3, -7, -9, -11, 2, 6, 8, 10}, + { -4, -7, -8, -11, 3, 6, 7, 10}, + { -3, -5, -8, -11, 2, 4, 7, 10}, + { -2, -6, -8, -10, 1, 5, 7, 9}, + { -2, -5, -8, -10, 1, 4, 7, 9}, + { -2, -4, -8, -10, 1, 3, 7, 9}, + { -2, -5, -7, -10, 1, 4, 6, 9}, + { -3, -4, -7, -10, 2, 3, 6, 9}, + { -1, -2, -3, -10, 0, 1, 2, 9}, + { -4, -6, -8, -9, 3, 5, 7, 8}, + { -3, -5, -7, -9, 2, 4, 6, 8}, +}; + +static const int etc2_modifier_tables_non_opaque[8][4] = { + { 0, 8, 0, -8}, + { 0, 17, 0, -17}, + { 0, 29, 0, -29}, + { 0, 42, 0, -42}, + { 0, 60, 0, -60}, + { 0, 80, 0, -80}, + { 0, 106, 0, -106}, + { 0, 183, 0, -183} +}; /* define etc1_parse_block and etc. */ #define UINT8_TYPE GLubyte @@ -50,6 +104,15 @@ _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS) #undef TAG #undef UINT8_TYPE +GLboolean +_mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS) +{ + /* GL_ETC1_RGB8_OES is only valid in glCompressedTexImage2D */ + ASSERT(0); + + return GL_FALSE; +} + void _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) @@ -101,3 +164,1300 @@ _mesa_etc1_unpack_rgba8888(uint8_t *dst_row, src_row, src_stride, src_width, src_height); } + +static uint8_t +etc2_base_color1_t_mode(const uint8_t *in, GLuint index) +{ + uint8_t R1a = 0, x = 0; + /* base col 1 = extend_4to8bits( (R1a << 2) | R1b, G1, B1) */ + switch(index) { + case 0: + R1a = (in[0] >> 3) & 0x3; + x = ((R1a << 2) | (in[0] & 0x3)); + break; + case 1: + x = ((in[1] >> 4) & 0xf); + break; + case 2: + x = (in[1] & 0xf); + break; + default: + /* invalid index */ + break; + } + return ((x << 4) | (x & 0xf)); +} + +static uint8_t +etc2_base_color2_t_mode(const uint8_t *in, GLuint index) +{ + uint8_t x = 0; + /*extend 4to8bits(R2, G2, B2)*/ + switch(index) { + case 0: + x = ((in[2] >> 4) & 0xf ); + break; + case 1: + x = (in[2] & 0xf); + break; + case 2: + x = ((in[3] >> 4) & 0xf); + break; + default: + /* invalid index */ + break; + } + return ((x << 4) | (x & 0xf)); +} + +static uint8_t +etc2_base_color1_h_mode(const uint8_t *in, GLuint index) +{ + uint8_t x = 0; + /* base col 1 = extend 4to8bits(R1, (G1a << 1) | G1b, (B1a << 3) | B1b) */ + switch(index) { + case 0: + x = ((in[0] >> 3) & 0xf); + break; + case 1: + x = (((in[0] & 0x7) << 1) | ((in[1] >> 4) & 0x1)); + break; + case 2: + x = ((in[1] & 0x8) | + (((in[1] & 0x3) << 1) | ((in[2] >> 7) & 0x1))); + break; + default: + /* invalid index */ + break; + } + return ((x << 4) | (x & 0xf)); + } + +static uint8_t +etc2_base_color2_h_mode(const uint8_t *in, GLuint index) +{ + uint8_t x = 0; + /* base col 2 = extend 4to8bits(R2, G2, B2) */ + switch(index) { + case 0: + x = ((in[2] >> 3) & 0xf ); + break; + case 1: + x = (((in[2] & 0x7) << 1) | ((in[3] >> 7) & 0x1)); + break; + case 2: + x = ((in[3] >> 3) & 0xf); + break; + default: + /* invalid index */ + break; + } + return ((x << 4) | (x & 0xf)); + } + +static uint8_t +etc2_base_color_o_planar(const uint8_t *in, GLuint index) +{ + GLuint tmp; + switch(index) { + case 0: + tmp = ((in[0] >> 1) & 0x3f); /* RO */ + return ((tmp << 2) | (tmp >> 4)); + case 1: + tmp = (((in[0] & 0x1) << 6) | /* GO1 */ + ((in[1] >> 1) & 0x3f)); /* GO2 */ + return ((tmp << 1) | (tmp >> 6)); + case 2: + tmp = (((in[1] & 0x1) << 5) | /* BO1 */ + (in[2] & 0x18) | /* BO2 */ + (((in[2] & 0x3) << 1) | ((in[3] >> 7) & 0x1))); /* BO3 */ + return ((tmp << 2) | (tmp >> 4)); + default: + /* invalid index */ + return 0; + } +} + +static uint8_t +etc2_base_color_h_planar(const uint8_t *in, GLuint index) +{ + GLuint tmp; + switch(index) { + case 0: + tmp = (((in[3] & 0x7c) >> 1) | /* RH1 */ + (in[3] & 0x1)); /* RH2 */ + return ((tmp << 2) | (tmp >> 4)); + case 1: + tmp = (in[4] >> 1) & 0x7f; /* GH */ + return ((tmp << 1) | (tmp >> 6)); + case 2: + tmp = (((in[4] & 0x1) << 5) | + ((in[5] >> 3) & 0x1f)); /* BH */ + return ((tmp << 2) | (tmp >> 4)); + default: + /* invalid index */ + return 0; + } +} + +static uint8_t +etc2_base_color_v_planar(const uint8_t *in, GLuint index) +{ + GLuint tmp; + switch(index) { + case 0: + tmp = (((in[5] & 0x7) << 0x3) | + ((in[6] >> 5) & 0x7)); /* RV */ + return ((tmp << 2) | (tmp >> 4)); + case 1: + tmp = (((in[6] & 0x1f) << 2) | + ((in[7] >> 6) & 0x3)); /* GV */ + return ((tmp << 1) | (tmp >> 6)); + case 2: + tmp = in[7] & 0x3f; /* BV */ + return ((tmp << 2) | (tmp >> 4)); + default: + /* invalid index */ + return 0; + } +} + +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) +{ + /* CLAMP(color, 0, 255) */ + return (uint8_t) CLAMP(color, 0, 255); +} + +static GLushort +etc2_clamp2(int color) +{ + /* CLAMP(color, 0, 2047) */ + return (GLushort) CLAMP(color, 0, 2047); +} + +static GLshort +etc2_clamp3(int color) +{ + /* CLAMP(color, -1023, 1023) */ + return (GLshort) CLAMP(color, -1023, 1023); +} + +static void +etc2_rgb8_parse_block(struct etc2_block *block, + const uint8_t *src, + GLboolean punchthrough_alpha) +{ + unsigned i; + GLboolean diffbit = false; + static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 }; + + const int R_plus_dR = (src[0] >> 3) + lookup[src[0] & 0x7]; + const int G_plus_dG = (src[1] >> 3) + lookup[src[1] & 0x7]; + const int B_plus_dB = (src[2] >> 3) + lookup[src[2] & 0x7]; + + /* Reset the mode flags */ + block->is_ind_mode = false; + block->is_diff_mode = false; + block->is_t_mode = false; + block->is_h_mode = false; + block->is_planar_mode = false; + + if (punchthrough_alpha) + block->opaque = src[3] & 0x2; + else + diffbit = src[3] & 0x2; + + if (!diffbit && !punchthrough_alpha) { + /* individual mode */ + block->is_ind_mode = true; + + for (i = 0; i < 3; i++) { + /* Texture decode algorithm is same for individual mode in etc1 + * & etc2. + */ + block->base_colors[0][i] = etc1_base_color_ind_hi(src[i]); + block->base_colors[1][i] = etc1_base_color_ind_lo(src[i]); + } + } + else if (R_plus_dR < 0 || R_plus_dR > 31){ + /* T mode */ + block->is_t_mode = true; + + for(i = 0; i < 3; i++) { + block->base_colors[0][i] = etc2_base_color1_t_mode(src, i); + block->base_colors[1][i] = etc2_base_color2_t_mode(src, i); + } + /* pick distance */ + block->distance = + etc2_distance_table[(((src[3] >> 2) & 0x3) << 1) | + (src[3] & 0x1)]; + + for (i = 0; i < 3; i++) { + block->paint_colors[0][i] = etc2_clamp(block->base_colors[0][i]); + block->paint_colors[1][i] = etc2_clamp(block->base_colors[1][i] + + block->distance); + block->paint_colors[2][i] = etc2_clamp(block->base_colors[1][i]); + block->paint_colors[3][i] = etc2_clamp(block->base_colors[1][i] - + block->distance); + } + } + else if (G_plus_dG < 0 || G_plus_dG > 31){ + int base_color_1_value, base_color_2_value; + + /* H mode */ + block->is_h_mode = true; + + for(i = 0; i < 3; i++) { + block->base_colors[0][i] = etc2_base_color1_h_mode(src, i); + block->base_colors[1][i] = etc2_base_color2_h_mode(src, i); + } + + base_color_1_value = (block->base_colors[0][0] << 16) + + (block->base_colors[0][1] << 8) + + block->base_colors[0][2]; + base_color_2_value = (block->base_colors[1][0] << 16) + + (block->base_colors[1][1] << 8) + + block->base_colors[1][2]; + /* pick distance */ + block->distance = + etc2_distance_table[(src[3] & 0x4) | + ((src[3] & 0x1) << 1) | + (base_color_1_value >= base_color_2_value)]; + + for (i = 0; i < 3; i++) { + block->paint_colors[0][i] = etc2_clamp(block->base_colors[0][i] + + block->distance); + block->paint_colors[1][i] = etc2_clamp(block->base_colors[0][i] - + block->distance); + block->paint_colors[2][i] = etc2_clamp(block->base_colors[1][i] + + block->distance); + block->paint_colors[3][i] = etc2_clamp(block->base_colors[1][i] - + block->distance); + } + } + else if (B_plus_dB < 0 || B_plus_dB > 31) { + /* Planar mode */ + block->is_planar_mode = true; + + /* opaque bit must be set in planar mode */ + if (!block->opaque) + block->opaque = true; + + for (i = 0; i < 3; i++) { + block->base_colors[0][i] = etc2_base_color_o_planar(src, i); + block->base_colors[1][i] = etc2_base_color_h_planar(src, i); + block->base_colors[2][i] = etc2_base_color_v_planar(src, i); + } + } + else if (diffbit || punchthrough_alpha) { + /* differential mode */ + block->is_diff_mode = true; + + for (i = 0; i < 3; i++) { + /* Texture decode algorithm is same for differential mode in etc1 + * & etc2. + */ + block->base_colors[0][i] = etc1_base_color_diff_hi(src[i]); + block->base_colors[1][i] = etc1_base_color_diff_lo(src[i]); + } + } + + if (block->is_ind_mode || block->is_diff_mode) { + int table1_idx = (src[3] >> 5) & 0x7; + int table2_idx = (src[3] >> 2) & 0x7; + + /* Use same modifier tables as for etc1 textures if opaque bit is set + * or if non punchthrough texture format + */ + block->modifier_tables[0] = (block->opaque || !punchthrough_alpha) ? + etc1_modifier_tables[table1_idx] : + etc2_modifier_tables_non_opaque[table1_idx]; + block->modifier_tables[1] = (block->opaque || !punchthrough_alpha) ? + etc1_modifier_tables[table2_idx] : + etc2_modifier_tables_non_opaque[table2_idx]; + + block->flipped = (src[3] & 0x1); + } + + block->pixel_indices[0] = + (src[4] << 24) | (src[5] << 16) | (src[6] << 8) | src[7]; +} + +static void +etc2_rgb8_fetch_texel(const struct etc2_block *block, + int x, int y, uint8_t *dst, + GLboolean punchthrough_alpha) +{ + const uint8_t *base_color; + int modifier, bit, idx, blk; + + /* get pixel index */ + bit = y + x * 4; + idx = ((block->pixel_indices[0] >> (15 + bit)) & 0x2) | + ((block->pixel_indices[0] >> (bit)) & 0x1); + + if (block->is_ind_mode || block->is_diff_mode) { + /* check for punchthrough_alpha format */ + if (punchthrough_alpha) { + if (!block->opaque && idx == 2) { + dst[0] = dst[1] = dst[2] = dst[3] = 0; + return; + } + else + dst[3] = 255; + } + + /* Use pixel index and subblock to get the modifier */ + blk = (block->flipped) ? (y >= 2) : (x >= 2); + base_color = block->base_colors[blk]; + modifier = block->modifier_tables[blk][idx]; + + dst[0] = etc2_clamp(base_color[0] + modifier); + dst[1] = etc2_clamp(base_color[1] + modifier); + dst[2] = etc2_clamp(base_color[2] + modifier); + } + else if (block->is_t_mode || block->is_h_mode) { + /* check for punchthrough_alpha format */ + if (punchthrough_alpha) { + if (!block->opaque && idx == 2) { + dst[0] = dst[1] = dst[2] = dst[3] = 0; + return; + } + else + dst[3] = 255; + } + + /* Use pixel index to pick one of the paint colors */ + dst[0] = block->paint_colors[idx][0]; + dst[1] = block->paint_colors[idx][1]; + dst[2] = block->paint_colors[idx][2]; + } + else if (block->is_planar_mode) { + /* {R(x, y) = clamp255((x × (RH − RO) + y × (RV − RO) + 4 × RO + 2) >> 2) + * {G(x, y) = clamp255((x × (GH − GO) + y × (GV − GO) + 4 × GO + 2) >> 2) + * {B(x, y) = clamp255((x × (BH − BO) + y × (BV − BO) + 4 × BO + 2) >> 2) + */ + int red, green, blue; + red = (x * (block->base_colors[1][0] - block->base_colors[0][0]) + + y * (block->base_colors[2][0] - block->base_colors[0][0]) + + 4 * block->base_colors[0][0] + 2) >> 2; + + green = (x * (block->base_colors[1][1] - block->base_colors[0][1]) + + y * (block->base_colors[2][1] - block->base_colors[0][1]) + + 4 * block->base_colors[0][1] + 2) >> 2; + + blue = (x * (block->base_colors[1][2] - block->base_colors[0][2]) + + y * (block->base_colors[2][2] - block->base_colors[0][2]) + + 4 * block->base_colors[0][2] + 2) >> 2; + + dst[0] = etc2_clamp(red); + dst[1] = etc2_clamp(green); + dst[2] = etc2_clamp(blue); + + /* check for punchthrough_alpha format */ + if (punchthrough_alpha) + dst[3] = 255; + } +} + +static void +etc2_alpha8_fetch_texel(const struct etc2_block *block, + int x, int y, uint8_t *dst) +{ + int modifier, alpha, idx; + /* get pixel index */ + 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_signed_r11_fetch_texel(const struct etc2_block *block, + int x, int y, uint8_t *dst) +{ + GLint modifier, idx; + GLshort color; + GLbyte base_codeword = (GLbyte) block->base_codeword; + + if (base_codeword == -128) + base_codeword = -127; + + /* Get pixel index */ + idx = etc2_get_pixel_index(block, x, y); + modifier = etc2_modifier_tables[block->table_index][idx]; + + if (block->multiplier != 0) + /* clamp3(base codeword × 8 + modifier × multiplier × 8) */ + color = etc2_clamp3((base_codeword << 3) + + ((modifier * block->multiplier) << 3)); + else + color = etc2_clamp3((base_codeword << 3) + 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. A negative 11-bit value must first be made positive before bit + * replication, and then made negative again + */ + if (color >= 0) + color = (color << 5) | (color >> 5); + else { + color = -color; + color = (color << 5) | (color >> 5); + color = -color; + } + ((GLshort *)dst)[0] = color; +} + +static void +etc2_alpha8_parse_block(struct etc2_block *block, const uint8_t *src) +{ + block->base_codeword = src[0]; + block->multiplier = (src[1] >> 4) & 0xf; + block->table_index = src[1] & 0xf; + block->pixel_indices[1] = (((uint64_t)src[2] << 40) | + ((uint64_t)src[3] << 32) | + ((uint64_t)src[4] << 24) | + ((uint64_t)src[5] << 16) | + ((uint64_t)src[6] << 8) | + ((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) +{ + /* RGB component is parsed the same way as for MESA_FORMAT_ETC2_RGB8 */ + etc2_rgb8_parse_block(block, src + 8, + false /* punchthrough_alpha */); + /* Parse Alpha component */ + etc2_alpha8_parse_block(block, src); +} + +static void +etc2_rgba8_fetch_texel(const struct etc2_block *block, + int x, int y, uint8_t *dst) +{ + etc2_rgb8_fetch_texel(block, x, y, dst, + false /* punchthrough_alpha */); + etc2_alpha8_fetch_texel(block, x, y, dst); +} + +static void +etc2_unpack_rgb8(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + const unsigned bw = 4, bh = 4, bs = 8, comps = 4; + 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_rgb8_parse_block(&block, src, + false /* punchthrough_alpha */); + + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgb8_fetch_texel(&block, i, j, dst, + false /* punchthrough_alpha */); + dst[3] = 255; + dst += comps; + } + } + + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_srgb8(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + const unsigned bw = 4, bh = 4, bs = 8, comps = 4; + struct etc2_block block; + unsigned x, y, i, j; + uint8_t tmp; + + for (y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + + for (x = 0; x < width; x+= bw) { + etc2_rgb8_parse_block(&block, src, + false /* punchthrough_alpha */); + + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgb8_fetch_texel(&block, i, j, dst, + false /* punchthrough_alpha */); + /* Convert to MESA_FORMAT_SARGB8 */ + tmp = dst[0]; + dst[0] = dst[2]; + dst[2] = tmp; + dst[3] = 255; + + dst += comps; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_rgba8(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_RGBA8_ETC2_EAC, each 4 × 4 block of + * RGBA8888 information is compressed to 128 bits. To decode a block, the + * two 64-bit integers int64bitAlpha and int64bitColor are calculated. + */ + const unsigned bw = 4, bh = 4, bs = 16, comps = 4; + 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_rgba8_parse_block(&block, src); + + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgba8_fetch_texel(&block, i, j, dst); + dst += comps; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_srgb8_alpha8(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, each 4 × 4 block + * of RGBA8888 information is compressed to 128 bits. To decode a block, the + * two 64-bit integers int64bitAlpha and int64bitColor are calculated. + */ + const unsigned bw = 4, bh = 4, bs = 16, comps = 4; + struct etc2_block block; + unsigned x, y, i, j; + uint8_t tmp; + + for (y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + + for (x = 0; x < width; x+= bw) { + etc2_rgba8_parse_block(&block, src); + + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgba8_fetch_texel(&block, i, j, dst); + + /* Convert to MESA_FORMAT_SARGB8 */ + tmp = dst[0]; + dst[0] = dst[2]; + dst[2] = tmp; + dst[3] = dst[3]; + + dst += comps; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +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; + } +} + +static void +etc2_unpack_rg11(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_RG11_EAC, each 4 × 4 block of + RG color information is compressed to 128 bits. + */ + const unsigned bw = 4, bh = 4, bs = 16, comps = 2, 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) { + /* red component */ + 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; + } + } + /* green component */ + etc2_r11_parse_block(&block, src + 8); + + 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 + comp_size); + dst += comps * comp_size; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_signed_r11(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_SIGNED_R11_EAC, each 4 × 4 block of + red 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_signed_r11_fetch_texel(&block, i, j, dst); + dst += comps * comp_size; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_signed_rg11(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_SIGNED_RG11_EAC, each 4 × 4 block of + RG color information is compressed to 128 bits. + */ + const unsigned bw = 4, bh = 4, bs = 16, comps = 2, 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) { + /* red component */ + 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_signed_r11_fetch_texel(&block, i, j, dst); + dst += comps * comp_size; + } + } + /* green component */ + etc2_r11_parse_block(&block, src + 8); + + 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_signed_r11_fetch_texel(&block, i, j, dst + comp_size); + dst += comps * comp_size; + } + } + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_rgb8_punchthrough_alpha1(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + const unsigned bw = 4, bh = 4, bs = 8, comps = 4; + 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_rgb8_parse_block(&block, src, + true /* punchthrough_alpha */); + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgb8_fetch_texel(&block, i, j, dst, + true /* punchthrough_alpha */); + dst += comps; + } + } + + src += bs; + } + + src_row += src_stride; + } +} + +static void +etc2_unpack_srgb8_punchthrough_alpha1(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + const unsigned bw = 4, bh = 4, bs = 8, comps = 4; + struct etc2_block block; + unsigned x, y, i, j; + uint8_t tmp; + + for (y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + + for (x = 0; x < width; x+= bw) { + etc2_rgb8_parse_block(&block, src, + true /* punchthrough_alpha */); + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgb8_fetch_texel(&block, i, j, dst, + true /* punchthrough_alpha */); + /* Convert to MESA_FORMAT_SARGB8 */ + tmp = dst[0]; + dst[0] = dst[2]; + dst[2] = tmp; + dst[3] = dst[3]; + + dst += comps; + } + } + + src += bs; + } + + src_row += src_stride; + } +} + +/* ETC2 texture formats are valid in glCompressedTexImage2D and + * glCompressedTexSubImage2D functions */ +GLboolean +_mesa_texstore_etc2_rgb8(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_srgb8(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_rgba8_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_signed_r11_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_signed_rg11_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_rgb8_punchthrough_alpha1(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + +GLboolean +_mesa_texstore_etc2_srgb8_punchthrough_alpha1(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) +{ + struct etc2_block block; + uint8_t dst[3]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8; + + etc2_rgb8_parse_block(&block, src, + false /* punchthrough_alpha */); + etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst, + false /* punchthrough_alpha */); + + texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]); + texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]); + texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]); + texel[ACOMP] = 1.0f; +} + +void +_mesa_fetch_texel_2d_f_etc2_srgb8(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + struct etc2_block block; + uint8_t dst[3]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8; + + etc2_rgb8_parse_block(&block, src, + false /* punchthrough_alpha */); + etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst, + false /* punchthrough_alpha */); + + texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]); + texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]); + texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]); + texel[ACOMP] = 1.0f; +} + +void +_mesa_fetch_texel_2d_f_etc2_rgba8_eac(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + struct etc2_block block; + uint8_t dst[4]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16; + + etc2_rgba8_parse_block(&block, src); + etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst); + + texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]); + texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]); + texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]); + texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); +} + +void +_mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel) +{ + struct etc2_block block; + uint8_t dst[4]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16; + + etc2_rgba8_parse_block(&block, src); + etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst); + + texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]); + texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]); + texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]); + 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; +} + +void +_mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel) +{ + struct etc2_block block; + GLushort dst[2]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16; + + /* red component */ + etc2_r11_parse_block(&block, src); + etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)dst); + + /* green component */ + etc2_r11_parse_block(&block, src + 8); + etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)(dst + 1)); + + texel[RCOMP] = USHORT_TO_FLOAT(dst[0]); + texel[GCOMP] = USHORT_TO_FLOAT(dst[1]); + texel[BCOMP] = 0.0f; + texel[ACOMP] = 1.0f; +} + +void +_mesa_fetch_texel_2d_f_etc2_signed_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_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)&dst); + + texel[RCOMP] = SHORT_TO_FLOAT(dst); + texel[GCOMP] = 0.0f; + texel[BCOMP] = 0.0f; + texel[ACOMP] = 1.0f; +} + +void +_mesa_fetch_texel_2d_f_etc2_signed_rg11_eac(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel) +{ + struct etc2_block block; + GLushort dst[2]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16; + + /* red component */ + etc2_r11_parse_block(&block, src); + etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)dst); + + /* green component */ + etc2_r11_parse_block(&block, src + 8); + etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)(dst + 1)); + + texel[RCOMP] = SHORT_TO_FLOAT(dst[0]); + texel[GCOMP] = SHORT_TO_FLOAT(dst[1]); + texel[BCOMP] = 0.0f; + texel[ACOMP] = 1.0f; +} + +void +_mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1( + const struct swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel) +{ + struct etc2_block block; + uint8_t dst[4]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8; + + etc2_rgb8_parse_block(&block, src, + true /* punchthrough alpha */); + etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst, + true /* punchthrough alpha */); + texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]); + texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]); + texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]); + texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); +} + +void +_mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1( + const struct swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel) +{ + struct etc2_block block; + uint8_t dst[4]; + const uint8_t *src; + + src = texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8; + + etc2_rgb8_parse_block(&block, src, + true /* punchthrough alpha */); + etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst, + true /* punchthrough alpha */); + texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]); + texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]); + texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]); + texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); +} + +/** + * 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` + * `MESA_FORMAT_ETC2_RG11_EAC` + * `MESA_FORMAT_ETC2_SIGNED_R11_EAC` + * `MESA_FORMAT_ETC2_SIGNED_RG11_EAC` + * `MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1` + * `MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1` + * + * 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. + * + * \param src_width in pixels + * \param src_height in pixels + * \param dst_stride in bytes + */ + +void +_mesa_unpack_etc2_format(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned src_width, + unsigned src_height, + gl_format format) +{ + if (format == MESA_FORMAT_ETC2_RGB8) + etc2_unpack_rgb8(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SRGB8) + etc2_unpack_srgb8(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_RGBA8_EAC) + etc2_unpack_rgba8(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC) + 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); + else if (format == MESA_FORMAT_ETC2_RG11_EAC) + etc2_unpack_rg11(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SIGNED_R11_EAC) + etc2_unpack_signed_r11(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SIGNED_RG11_EAC) + etc2_unpack_signed_rg11(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1) + etc2_unpack_rgb8_punchthrough_alpha1(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1) + etc2_unpack_srgb8_punchthrough_alpha1(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); +} diff --git a/mesalib/src/mesa/main/texcompress_etc.h b/mesalib/src/mesa/main/texcompress_etc.h index 411e1540d..5e086d4e7 100644 --- a/mesalib/src/mesa/main/texcompress_etc.h +++ b/mesalib/src/mesa/main/texcompress_etc.h @@ -34,16 +34,93 @@ struct swrast_texture_image; GLboolean _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS); +GLboolean +_mesa_texstore_etc2_rgb8(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_srgb8(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_rgba8_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_signed_r11_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_signed_rg11_eac(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_rgb8_punchthrough_alpha1(TEXSTORE_PARAMS); + +GLboolean +_mesa_texstore_etc2_srgb8_punchthrough_alpha1(TEXSTORE_PARAMS); + void _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_srgb8(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel); void +_mesa_fetch_texel_2d_f_etc2_rgba8_eac(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel); +void +_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_fetch_texel_2d_f_etc2_rg11_eac(const struct swrast_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_signed_rg11_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1( + const struct swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); +void +_mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1( + const struct swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); +void _mesa_etc1_unpack_rgba8888(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned src_width, unsigned src_height); - +void +_mesa_unpack_etc2_format(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned src_width, + unsigned src_height, + gl_format format); #endif diff --git a/mesalib/src/mesa/main/texcompress_s3tc.c b/mesalib/src/mesa/main/texcompress_s3tc.c index da7725964..476b998e0 100644 --- a/mesalib/src/mesa/main/texcompress_s3tc.c +++ b/mesalib/src/mesa/main/texcompress_s3tc.c @@ -45,6 +45,7 @@ #include "texcompress_s3tc.h" #include "texstore.h" #include "swrast/s_context.h" +#include "format_unpack.h" #if defined(_WIN32) || defined(WIN32) @@ -57,33 +58,6 @@ #define DXTN_LIBNAME "libtxc_dxtn.so" #endif -/** - * Convert an 8-bit sRGB value from non-linear space to a - * linear RGB value in [0, 1]. - * Implemented with a 256-entry lookup table. - */ -static inline GLfloat -nonlinear_to_linear(GLubyte cs8) -{ - static GLfloat table[256]; - static GLboolean tableReady = GL_FALSE; - if (!tableReady) { - /* compute lookup table now */ - GLuint i; - for (i = 0; i < 256; i++) { - const GLfloat cs = UBYTE_TO_FLOAT(i); - if (cs <= 0.04045) { - table[i] = cs / 12.92f; - } - else { - table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4); - } - } - tableReady = GL_TRUE; - } - return table[cs8]; -} - typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut ); static dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL; @@ -476,9 +450,9 @@ _mesa_fetch_texel_srgb_dxt1(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -489,9 +463,9 @@ _mesa_fetch_texel_srgba_dxt1(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -502,9 +476,9 @@ _mesa_fetch_texel_srgba_dxt3(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -515,8 +489,8 @@ _mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } diff --git a/mesalib/src/mesa/main/texformat.c b/mesalib/src/mesa/main/texformat.c index f0bc7fdb9..b3ffc6c51 100644 --- a/mesalib/src/mesa/main/texformat.c +++ b/mesalib/src/mesa/main/texformat.c @@ -972,6 +972,43 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target, } } + if (_mesa_is_gles3(ctx)) { + switch (internalFormat) { + case GL_COMPRESSED_RGB8_ETC2: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_RGB8); + break; + case GL_COMPRESSED_SRGB8_ETC2: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SRGB8); + break; + case GL_COMPRESSED_RGBA8_ETC2_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_RGBA8_EAC); + break; + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC); + break; + case GL_COMPRESSED_R11_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_R11_EAC); + break; + case GL_COMPRESSED_RG11_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_RG11_EAC); + break; + case GL_COMPRESSED_SIGNED_R11_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SIGNED_R11_EAC); + break; + case GL_COMPRESSED_SIGNED_RG11_EAC: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SIGNED_RG11_EAC); + break; + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1); + break; + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: + RETURN_IF_SUPPORTED(MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1); + break; + default: + ; /* fallthrough */ + } + } + _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()", _mesa_lookup_enum_by_nr(internalFormat)); return MESA_FORMAT_NONE; diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index a720c38b8..83b7e1488 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -529,6 +529,27 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) } } + if (_mesa_is_gles3(ctx)) { + switch (internalFormat) { + case GL_COMPRESSED_RGB8_ETC2: + case GL_COMPRESSED_SRGB8_ETC2: + return GL_RGB; + case GL_COMPRESSED_RGBA8_ETC2_EAC: + case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: + case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: + case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: + return GL_RGBA; + case GL_COMPRESSED_R11_EAC: + case GL_COMPRESSED_SIGNED_R11_EAC: + return GL_RED; + case GL_COMPRESSED_RG11_EAC: + case GL_COMPRESSED_SIGNED_RG11_EAC: + return GL_RG; + default: + ; /* fallthrough */ + } + } + if (ctx->API == API_OPENGLES) { switch (internalFormat) { case GL_PALETTE4_RGB8_OES: diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c index 1c088106f..26c5b6703 100644 --- a/mesalib/src/mesa/main/texstore.c +++ b/mesalib/src/mesa/main/texstore.c @@ -4124,6 +4124,18 @@ _mesa_get_texstore_func(gl_format format) table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2; table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2; table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8; + table[MESA_FORMAT_ETC2_RGB8] = _mesa_texstore_etc2_rgb8; + 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; + table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac; + table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = _mesa_texstore_etc2_signed_r11_eac; + table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = _mesa_texstore_etc2_signed_rg11_eac; + table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] = + _mesa_texstore_etc2_rgb8_punchthrough_alpha1; + table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] = + _mesa_texstore_etc2_srgb8_punchthrough_alpha1; table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8; table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8; table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88; |