diff options
author | marha <marha@users.sourceforge.net> | 2012-12-10 08:33:13 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-12-10 08:33:13 +0100 |
commit | 0328076efb5ff6e62152c09e38d0d11f7931d07b (patch) | |
tree | ce71cf0fe95186671dc75862c2ced47f4735214f /mesalib/src/mesa | |
parent | e82692e521240c5f8592f9ce56c9d5b3d68870ec (diff) | |
download | vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.tar.gz vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.tar.bz2 vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.zip |
fontconfig libX11 mesa pixman git update 10 dec 2012
libX11 9833489e6c3829a1e835bc0a11f028fc180809e4
mesa 17f5dc57306b8f5079304701e455bf4b927d3cae
pixman 8ca4e144724ba2041bc5ef077ccf6d24e7cf4d1f
fontconfig 608c5b590bd3428dfcd30f3d68ee8b7131e2f019
Diffstat (limited to 'mesalib/src/mesa')
38 files changed, 2839 insertions, 211 deletions
diff --git a/mesalib/src/mesa/Android.libmesa_glsl_utils.mk b/mesalib/src/mesa/Android.libmesa_glsl_utils.mk index 480275795..9beeda57f 100644 --- a/mesalib/src/mesa/Android.libmesa_glsl_utils.mk +++ b/mesalib/src/mesa/Android.libmesa_glsl_utils.mk @@ -36,7 +36,8 @@ include $(CLEAR_VARS) LOCAL_MODULE := libmesa_glsl_utils LOCAL_SRC_FILES := \ - program/hash_table.c \ + main/hash_table.c \ + program/prog_hash_table.c \ program/symbol_table.c include $(MESA_COMMON_MK) @@ -52,7 +53,8 @@ LOCAL_MODULE := libmesa_glsl_utils LOCAL_IS_HOST_MODULE := true LOCAL_SRC_FILES := \ - program/hash_table.c \ + main/hash_table.c \ + program/prog_hash_table.c \ program/symbol_table.c include $(MESA_COMMON_MK) diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript index be1ed5f60..a2492f771 100644 --- a/mesalib/src/mesa/SConscript +++ b/mesalib/src/mesa/SConscript @@ -107,6 +107,7 @@ main_sources = [ 'main/renderbuffer.c', 'main/samplerobj.c', 'main/scissor.c', + 'main/set.c', 'main/shaderapi.c', 'main/shaderobj.c', 'main/shader_query.cpp', @@ -293,7 +294,7 @@ env.Append(CPPPATH = [Dir('.').abspath]) program_sources = [ 'program/arbprogparse.c', - 'program/hash_table.c', + 'program/prog_hash_table.c', 'program/ir_to_mesa.cpp', 'program/program.c', 'program/program_parse_extra.c', diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c index d5e8af3c0..ac036eaac 100644 --- a/mesalib/src/mesa/drivers/common/meta.c +++ b/mesalib/src/mesa/drivers/common/meta.c @@ -133,6 +133,7 @@ struct save_state struct gl_vertex_program *VertexProgram; GLboolean FragmentProgramEnabled; struct gl_fragment_program *FragmentProgram; + GLboolean ATIFragmentShaderEnabled; struct gl_shader_program *VertexShader; struct gl_shader_program *GeometryShader; struct gl_shader_program *FragmentShader; @@ -594,6 +595,11 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state) _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_FALSE); } + if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ATI_fragment_shader) { + save->ATIFragmentShaderEnabled = ctx->ATIFragmentShader.Enabled; + _mesa_set_enable(ctx, GL_FRAGMENT_SHADER_ATI, GL_FALSE); + } + if (ctx->Extensions.ARB_shader_objects) { _mesa_reference_shader_program(ctx, &save->VertexShader, ctx->Shader.CurrentVertexProgram); @@ -914,6 +920,11 @@ _mesa_meta_end(struct gl_context *ctx) _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL); } + if (ctx->API == API_OPENGL_COMPAT && ctx->Extensions.ATI_fragment_shader) { + _mesa_set_enable(ctx, GL_FRAGMENT_SHADER_ATI, + save->ATIFragmentShaderEnabled); + } + if (ctx->Extensions.ARB_vertex_shader) _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader); @@ -1844,23 +1855,8 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear) "{\n" " gl_FragColor = color;\n" "}\n"; - const char *vs_int_source = - "#version 130\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = position;\n" - "}\n"; - const char *fs_int_source = - "#version 130\n" - "uniform ivec4 color;\n" - "out ivec4 out_color;\n" - "\n" - "void main()\n" - "{\n" - " out_color = color;\n" - "}\n"; GLuint vs, fs; + bool has_integer_textures; if (clear->ArrayObj != 0) return; @@ -1896,9 +1892,35 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear) clear->ColorLocation = _mesa_GetUniformLocation(clear->ShaderProg, "color"); - if (_mesa_is_desktop_gl(ctx) && ctx->Const.GLSLVersion >= 130) { + has_integer_textures = _mesa_is_gles3(ctx) || + (_mesa_is_desktop_gl(ctx) && ctx->Const.GLSLVersion >= 130); + + if (has_integer_textures) { + void *shader_source_mem_ctx = ralloc_context(NULL); + const char *vs_int_source = + ralloc_asprintf(shader_source_mem_ctx, + "#version %s\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = position;\n" + "}\n", + _mesa_is_desktop_gl(ctx) ? "130" : "300 es"); + const char *fs_int_source = + ralloc_asprintf(shader_source_mem_ctx, + "#version %s\n" + "uniform ivec4 color;\n" + "out ivec4 out_color;\n" + "\n" + "void main()\n" + "{\n" + " out_color = color;\n" + "}\n", + _mesa_is_desktop_gl(ctx) ? "130" : "300 es"); + vs = compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_int_source); fs = compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_int_source); + ralloc_free(shader_source_mem_ctx); clear->IntegerShaderProg = _mesa_CreateProgramObjectARB(); _mesa_AttachShader(clear->IntegerShaderProg, fs); @@ -3101,18 +3123,19 @@ setup_glsl_generate_mipmap(struct gl_context *ctx, sampler->func, sampler->texcoords); } else { - vs_source = - "#version 130\n" - "in vec2 position;\n" - "in vec3 textureCoords;\n" - "out vec3 texCoords;\n" - "void main()\n" - "{\n" - " texCoords = textureCoords;\n" - " gl_Position = vec4(position, 0.0, 1.0);\n" - "}\n"; + vs_source = ralloc_asprintf(mem_ctx, + "#version %s\n" + "in vec2 position;\n" + "in vec3 textureCoords;\n" + "out vec3 texCoords;\n" + "void main()\n" + "{\n" + " texCoords = textureCoords;\n" + " gl_Position = vec4(position, 0.0, 1.0);\n" + "}\n", + _mesa_is_desktop_gl(ctx) ? "130" : "300 es"); fs_source = ralloc_asprintf(mem_ctx, - "#version 130\n" + "#version %s\n" "uniform %s texSampler;\n" "in vec3 texCoords;\n" "out vec4 out_color;\n" @@ -3121,6 +3144,7 @@ setup_glsl_generate_mipmap(struct gl_context *ctx, "{\n" " out_color = texture(texSampler, %s);\n" "}\n", + _mesa_is_desktop_gl(ctx) ? "130" : "300 es", sampler->type, sampler->texcoords); } diff --git a/mesalib/src/mesa/drivers/dri/common/drisw_util.c b/mesalib/src/mesa/drivers/dri/common/drisw_util.c index 8fdb05ec3..cd5a39a37 100644 --- a/mesalib/src/mesa/drivers/dri/common/drisw_util.c +++ b/mesalib/src/mesa/drivers/dri/common/drisw_util.c @@ -126,7 +126,10 @@ driCreateContextAttribs(__DRIscreen *screen, int api, mesa_api = API_OPENGLES2; break; case __DRI_API_OPENGL_CORE: + mesa_api = API_OPENGL_CORE; + break; default: + *error = __DRI_CTX_ERROR_BAD_API; return NULL; } @@ -149,6 +152,19 @@ driCreateContextAttribs(__DRIscreen *screen, int api, } } + /* Mesa does not support the GL_ARB_compatibilty extension or the + * compatibility profile. This means that we treat a API_OPENGL_COMPAT 3.1 as + * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+. + */ + if (mesa_api == API_OPENGL_COMPAT && major_version == 3 && minor_version == 1) + mesa_api = API_OPENGL_CORE; + + if (mesa_api == API_OPENGL_COMPAT + && ((major_version > 3) + || (major_version == 3 && minor_version >= 2))) { + *error = __DRI_CTX_ERROR_BAD_API; + return NULL; + } /* There are no forward-compatible contexts before OpenGL 3.0. The * GLX_ARB_create_context spec says: * diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index 5521617f1..6733644b6 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 cc541c834..f599982bd 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; diff --git a/mesalib/src/mesa/program/Android.mk b/mesalib/src/mesa/program/Android.mk index 712506129..51362e0eb 100644 --- a/mesalib/src/mesa/program/Android.mk +++ b/mesalib/src/mesa/program/Android.mk @@ -65,6 +65,9 @@ LOCAL_GENERATED_SOURCES := \ $(intermediates)/program/program_parse.tab.c: $(LOCAL_PATH)/program_parse.y $(mesa_local-y-to-c-and-h) +$(intermediates)/program/program_parse.tab.h: $(intermediates)/program/program_parse.tab.c + @ + $(intermediates)/program/lex.yy.c: $(LOCAL_PATH)/program_lexer.l $(local-l-to-c) diff --git a/mesalib/src/mesa/program/hash_table.c b/mesalib/src/mesa/program/prog_hash_table.c index f45ed46af..f45ed46af 100644 --- a/mesalib/src/mesa/program/hash_table.c +++ b/mesalib/src/mesa/program/prog_hash_table.c diff --git a/mesalib/src/mesa/sources.mak b/mesalib/src/mesa/sources.mak index 54e58c21b..8cde2c4cf 100644 --- a/mesalib/src/mesa/sources.mak +++ b/mesalib/src/mesa/sources.mak @@ -76,6 +76,7 @@ MAIN_FILES = \ $(SRCDIR)main/renderbuffer.c \ $(SRCDIR)main/samplerobj.c \ $(SRCDIR)main/scissor.c \ + $(SRCDIR)main/set.c \ $(SRCDIR)main/shaderapi.c \ $(SRCDIR)main/shaderobj.c \ $(SRCDIR)main/shader_query.cpp \ @@ -247,7 +248,7 @@ STATETRACKER_FILES = \ PROGRAM_FILES = \ $(SRCDIR)program/arbprogparse.c \ - $(SRCDIR)program/hash_table.c \ + $(SRCDIR)program/prog_hash_table.c \ $(SRCDIR)program/ir_to_mesa.cpp \ $(SRCDIR)program/program.c \ $(SRCDIR)program/program_parse_extra.c \ diff --git a/mesalib/src/mesa/state_tracker/st_atom.c b/mesalib/src/mesa/state_tracker/st_atom.c index 102fee93b..32bcc266a 100644 --- a/mesalib/src/mesa/state_tracker/st_atom.c +++ b/mesalib/src/mesa/state_tracker/st_atom.c @@ -64,6 +64,8 @@ static const struct st_tracked_state *atoms[] = &st_update_vs_constants, &st_update_gs_constants, &st_update_fs_constants, + &st_bind_vs_ubos, + &st_bind_fs_ubos, &st_update_pixel_transfer, /* this must be done after the vertex program update */ diff --git a/mesalib/src/mesa/state_tracker/st_atom.h b/mesalib/src/mesa/state_tracker/st_atom.h index 6c7d09fba..101a3a6bd 100644 --- a/mesalib/src/mesa/state_tracker/st_atom.h +++ b/mesalib/src/mesa/state_tracker/st_atom.h @@ -67,6 +67,8 @@ extern const struct st_tracked_state st_finalize_textures; extern const struct st_tracked_state st_update_fs_constants; extern const struct st_tracked_state st_update_gs_constants; extern const struct st_tracked_state st_update_vs_constants; +extern const struct st_tracked_state st_bind_fs_ubos; +extern const struct st_tracked_state st_bind_vs_ubos; extern const struct st_tracked_state st_update_pixel_transfer; diff --git a/mesalib/src/mesa/state_tracker/st_atom_constbuf.c b/mesalib/src/mesa/state_tracker/st_atom_constbuf.c index 580393e60..961fb28a9 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_constbuf.c +++ b/mesalib/src/mesa/state_tracker/st_atom_constbuf.c @@ -45,7 +45,7 @@ #include "st_atom.h" #include "st_atom_constbuf.h" #include "st_program.h" - +#include "st_cb_bufferobjects.h" /** * Pass the given program parameters to the graphics pipe as a @@ -175,3 +175,69 @@ const struct st_tracked_state st_update_gs_constants = { }, update_gs_constants /* update */ }; + +static void st_bind_ubos(struct st_context *st, + struct gl_shader *shader, + unsigned shader_type) +{ + unsigned i; + struct pipe_constant_buffer cb = { 0 }; + + if (!shader) + return; + + for (i = 0; i < shader->NumUniformBlocks; i++) { + struct gl_uniform_buffer_binding *binding; + struct st_buffer_object *st_obj; + + binding = &st->ctx->UniformBufferBindings[shader->UniformBlocks[i].Binding]; + st_obj = st_buffer_object(binding->BufferObject); + pipe_resource_reference(&cb.buffer, st_obj->buffer); + + cb.buffer_size = st_obj->buffer->width0 - binding->Offset; + + st->pipe->set_constant_buffer(st->pipe, shader_type, 1 + i, &cb); + pipe_resource_reference(&cb.buffer, NULL); + } +} + +static void bind_vs_ubos(struct st_context *st) +{ + struct gl_shader_program *prog = st->ctx->Shader.CurrentVertexProgram; + + if (!prog) + return; + + st_bind_ubos(st, prog->_LinkedShaders[MESA_SHADER_VERTEX], PIPE_SHADER_VERTEX); +} + +const struct st_tracked_state st_bind_vs_ubos = { + "st_bind_vs_ubos", + { + (_NEW_PROGRAM | _NEW_BUFFER_OBJECT), + ST_NEW_VERTEX_PROGRAM, + }, + bind_vs_ubos +}; + +static void bind_fs_ubos(struct st_context *st) +{ + struct gl_shader_program *prog = st->ctx->Shader.CurrentFragmentProgram; + + if (!prog) + return; + + st_bind_ubos(st, prog->_LinkedShaders[MESA_SHADER_FRAGMENT], PIPE_SHADER_FRAGMENT); + +} + +const struct st_tracked_state st_bind_fs_ubos = { + "st_bind_fs_ubos", + { + (_NEW_PROGRAM | _NEW_BUFFER_OBJECT), + ST_NEW_FRAGMENT_PROGRAM, + }, + bind_fs_ubos +}; + + diff --git a/mesalib/src/mesa/state_tracker/st_atom_texture.c b/mesalib/src/mesa/state_tracker/st_atom_texture.c index df05e83c2..dba1d829c 100644 --- a/mesalib/src/mesa/state_tracker/st_atom_texture.c +++ b/mesalib/src/mesa/state_tracker/st_atom_texture.c @@ -215,13 +215,19 @@ update_single_texture(struct st_context *st, /* Determine the format of the texture sampler view */ st_view_format = stObj->pt->format; - { - const struct st_texture_image *firstImage = - st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); - const gl_format texFormat = firstImage->base.TexFormat; - enum pipe_format firstImageFormat = - st_mesa_format_to_pipe_format(texFormat); + { + gl_format texFormat; + enum pipe_format firstImageFormat; + + if (texObj->Target == GL_TEXTURE_BUFFER) { + texFormat = stObj->base._BufferObjectFormat; + } else { + const struct st_texture_image *firstImage = + st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); + texFormat = firstImage->base.TexFormat; + } + firstImageFormat = st_mesa_format_to_pipe_format(texFormat); if ((samp->sRGBDecode == GL_SKIP_DECODE_EXT) && (_mesa_get_format_color_encoding(texFormat) == GL_SRGB)) { /* Don't do sRGB->RGB conversion. Interpret the texture data as diff --git a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c index ac38128df..cf291c1c1 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -195,9 +195,15 @@ st_bufferobj_data(struct gl_context *ctx, case GL_ELEMENT_ARRAY_BUFFER_ARB: bind = PIPE_BIND_INDEX_BUFFER; break; + case GL_TEXTURE_BUFFER: + bind = PIPE_BIND_SAMPLER_VIEW; + break; case GL_TRANSFORM_FEEDBACK_BUFFER: bind = PIPE_BIND_STREAM_OUTPUT; break; + case GL_UNIFORM_BUFFER: + bind = PIPE_BIND_CONSTANT_BUFFER; + break; default: bind = 0; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index f06814f9c..ae069eb2c 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -48,6 +48,7 @@ #include "state_tracker/st_cb_fbo.h" #include "state_tracker/st_cb_flush.h" #include "state_tracker/st_cb_texture.h" +#include "state_tracker/st_cb_bufferobjects.h" #include "state_tracker/st_format.h" #include "state_tracker/st_texture.h" #include "state_tracker/st_gen_mipmap.h" @@ -59,6 +60,7 @@ #include "pipe/p_shader_tokens.h" #include "util/u_tile.h" #include "util/u_blit.h" +#include "util/u_blitter.h" #include "util/u_format.h" #include "util/u_surface.h" #include "util/u_sampler.h" @@ -922,12 +924,12 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; enum pipe_format dest_format, src_format; - GLboolean matching_base_formats; - GLuint color_writemask, zs_writemask, sample_count; + GLuint color_writemask; struct pipe_surface *dest_surface = NULL; GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP); struct pipe_surface surf_tmpl; - unsigned int dst_usage; + unsigned dst_usage; + unsigned blit_mask; GLint srcY0, srcY1; /* make sure finalize_textures has been called? @@ -939,12 +941,6 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, return; } - sample_count = strb->surface->texture->nr_samples; - /* I believe this would be legal, presumably would need to do a resolve - for color, and for depth/stencil spec says to just use one of the - depth/stencil samples per pixel? Need some transfer clarifications. */ - assert(sample_count < 2); - assert(strb); assert(strb->surface); assert(stImage->pt); @@ -952,22 +948,24 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, src_format = strb->surface->format; dest_format = stImage->pt->format; - /* - * Determine if the src framebuffer and dest texture have the same - * base format. We need this to detect a case such as the framebuffer - * being GL_RGBA but the texture being GL_RGB. If the actual hardware - * texture format stores RGBA we need to set A=1 (overriding the - * framebuffer's alpha values). We can't do that with the blit or - * textured-quad paths. - */ - matching_base_formats = - (_mesa_get_format_base_format(strb->Base.Format) == - _mesa_get_format_base_format(texImage->TexFormat)); + if (do_flip) { + srcY1 = strb->Base.Height - srcY - height; + srcY0 = srcY1 + height; + } + else { + srcY0 = srcY; + srcY1 = srcY0 + height; + } if (ctx->_ImageTransferState) { goto fallback; } + /* Compressed and subsampled textures aren't supported for blitting. */ + if (!util_format_is_plain(dest_format)) { + goto fallback; + } + if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) { /* 1D arrays might be thought of as 2D images but the actual layout * might not be that way. At some points, we convert OpenGL's 1D @@ -978,53 +976,112 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, goto fallback; } - if (matching_base_formats && - src_format == dest_format && - !do_flip) { - /* use surface_copy() / blit */ - struct pipe_box src_box; - unsigned dstLevel; + /* Set the blit writemask. */ + switch (texBaseFormat) { + case GL_DEPTH_STENCIL: + switch (strb->Base._BaseFormat) { + case GL_DEPTH_STENCIL: + blit_mask = PIPE_MASK_ZS; + break; + case GL_DEPTH_COMPONENT: + blit_mask = PIPE_MASK_Z; + break; + case GL_STENCIL_INDEX: + blit_mask = PIPE_MASK_S; + break; + default: + assert(0); + return; + } + dst_usage = PIPE_BIND_DEPTH_STENCIL; + break; + + case GL_DEPTH_COMPONENT: + blit_mask = PIPE_MASK_Z; + dst_usage = PIPE_BIND_DEPTH_STENCIL; + break; - u_box_2d_zslice(srcX, srcY, strb->surface->u.tex.first_layer, - width, height, &src_box); + default: + /* Colorbuffers. + * + * Determine if the src framebuffer and dest texture have the same + * base format. We need this to detect a case such as the framebuffer + * being GL_RGBA but the texture being GL_RGB. If the actual hardware + * texture format stores RGBA we need to set A=1 (overriding the + * framebuffer's alpha values). + * + * XXX util_blit_pixels doesn't support MSAA resolve, so always use + * pipe->blit + */ + if (texBaseFormat == strb->Base._BaseFormat || + strb->texture->nr_samples > 1) { + blit_mask = PIPE_MASK_RGBA; + } + else { + blit_mask = 0; + } + dst_usage = PIPE_BIND_RENDER_TARGET; + } + /* Blit the texture. + * This supports flipping, format conversions, and downsampling. + */ + if (blit_mask) { /* If stImage->pt is an independent image (not a pointer into a full * mipmap) stImage->pt.last_level will be zero and we need to use that * as the dest level. */ - dstLevel = MIN2(stImage->base.Level, stImage->pt->last_level); - - /* for resource_copy_region(), y=0=top, always */ - pipe->resource_copy_region(pipe, - /* dest */ - stImage->pt, - dstLevel, - destX, destY, destZ + stImage->base.Face, - /* src */ - strb->texture, - strb->surface->u.tex.level, - &src_box); - return; - } + unsigned dstLevel = MIN2(stImage->base.Level, stImage->pt->last_level); + struct pipe_blit_info blit; + + memset(&blit, 0, sizeof(blit)); + blit.src.resource = strb->texture; + blit.src.format = src_format; + blit.src.level = strb->surface->u.tex.level; + blit.src.box.x = srcX; + blit.src.box.y = srcY0; + blit.src.box.z = strb->surface->u.tex.first_layer; + blit.src.box.width = width; + blit.src.box.height = srcY1 - srcY0; + blit.src.box.depth = 1; + blit.dst.resource = stImage->pt; + blit.dst.format = dest_format; + blit.dst.level = dstLevel; + blit.dst.box.x = destX; + blit.dst.box.y = destY; + blit.dst.box.z = stImage->base.Face + destZ; + blit.dst.box.width = width; + blit.dst.box.height = height; + blit.dst.box.depth = 1; + blit.mask = blit_mask; + blit.filter = PIPE_TEX_FILTER_NEAREST; + + /* try resource_copy_region in case the format is not supported + * for rendering */ + if (util_try_blit_via_copy_region(pipe, &blit)) { + return; /* done */ + } - if (texBaseFormat == GL_DEPTH_STENCIL) { - goto fallback; - } + /* check the format support */ + if (!screen->is_format_supported(screen, src_format, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW) || + !screen->is_format_supported(screen, dest_format, + PIPE_TEXTURE_2D, 0, + dst_usage)) { + goto fallback; + } - if (texBaseFormat == GL_DEPTH_COMPONENT) { - color_writemask = 0; - zs_writemask = BLIT_WRITEMASK_Z; - dst_usage = PIPE_BIND_DEPTH_STENCIL; - } - else { - color_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage); - zs_writemask = 0; - dst_usage = PIPE_BIND_RENDER_TARGET; + pipe->blit(pipe, &blit); + return; } - if ((!color_writemask && !zs_writemask) || + /* try u_blit */ + color_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage); + + if (!color_writemask || !screen->is_format_supported(screen, src_format, - PIPE_TEXTURE_2D, sample_count, + PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW) || !screen->is_format_supported(screen, dest_format, PIPE_TEXTURE_2D, 0, @@ -1032,15 +1089,6 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, goto fallback; } - if (do_flip) { - srcY1 = strb->Base.Height - srcY - height; - srcY0 = srcY1 + height; - } - else { - srcY0 = srcY; - srcY1 = srcY0 + height; - } - /* Disable conditional rendering. */ if (st->render_condition) { pipe->render_condition(pipe, NULL, 0); @@ -1065,7 +1113,7 @@ st_CopyTexSubImage(struct gl_context *ctx, GLuint dims, destX, destY, destX + width, destY + height, 0.0, PIPE_TEX_MIPFILTER_NEAREST, - color_writemask, zs_writemask); + color_writemask, 0); pipe_surface_reference(&dest_surface, NULL); /* Restore conditional rendering state. */ @@ -1182,6 +1230,20 @@ st_finalize_texture(struct gl_context *ctx, stObj->lastLevel = stObj->base._MaxLevel; } + if (tObj->Target == GL_TEXTURE_BUFFER) { + struct st_buffer_object *st_obj = st_buffer_object(tObj->BufferObject); + + if (st_obj->buffer != stObj->pt) { + pipe_resource_reference(&stObj->pt, st_obj->buffer); + pipe_sampler_view_release(st->pipe, &stObj->sampler_view); + stObj->width0 = stObj->pt->width0 / _mesa_get_format_bytes(tObj->_BufferObjectFormat); + stObj->height0 = 1; + stObj->depth0 = 1; + } + return GL_TRUE; + + } + firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); assert(firstImage); diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 62a736bb6..93ef7a91c 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -70,6 +70,8 @@ void st_init_limits(struct st_context *st) struct pipe_screen *screen = st->pipe->screen; struct gl_constants *c = &st->ctx->Const; gl_shader_type sh; + boolean can_ubo = TRUE; + int max_const_buffers; c->MaxTextureLevels = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), @@ -218,6 +220,17 @@ void st_init_limits(struct st_context *st) options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_INDIRECT_CONST_ADDR); + if (pc->MaxNativeInstructions) { + if (options->EmitNoIndirectUniform) + can_ubo = FALSE; + + max_const_buffers = screen->get_shader_param(screen, sh, + PIPE_SHADER_CAP_MAX_CONST_BUFFERS); + /* we need 13 buffers - 1 constant, 12 UBO */ + if (max_const_buffers < 13) + can_ubo = FALSE; + } + if (options->EmitNoLoops) options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536); else @@ -251,6 +264,9 @@ void st_init_limits(struct st_context *st) c->GLSLSkipStrictMaxVaryingLimitCheck = screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS); + + if (can_ubo) + st->ctx->Extensions.ARB_uniform_buffer_object = GL_TRUE; } @@ -553,7 +569,12 @@ void st_init_extensions(struct st_context *st) /* Figure out GLSL support. */ glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL); - if (glsl_feature_level >= 130) { + if (glsl_feature_level >= 140) { + if (ctx->API == API_OPENGL_CORE) + ctx->Const.GLSLVersion = 140; + else + ctx->Const.GLSLVersion = 130; + } else if (glsl_feature_level >= 130) { ctx->Const.GLSLVersion = 130; } else { ctx->Const.GLSLVersion = 120; @@ -643,4 +664,6 @@ void st_init_extensions(struct st_context *st) if (ctx->Const.MinMapBufferAlignment >= 64) { ctx->Extensions.ARB_map_buffer_alignment = GL_TRUE; } + if (screen->get_param(screen, PIPE_CAP_TEXTURE_BUFFER_OBJECTS)) + ctx->Extensions.ARB_texture_buffer_object = GL_TRUE; } diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index c030a6b37..a4df4e5fa 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -107,6 +107,7 @@ public: else this->swizzle = SWIZZLE_XYZW; this->negate = 0; + this->index2D = 0; this->type = type ? type->base_type : GLSL_TYPE_ERROR; this->reladdr = NULL; } @@ -116,6 +117,18 @@ public: this->type = type; this->file = file; this->index = index; + this->index2D = 0; + this->swizzle = SWIZZLE_XYZW; + this->negate = 0; + this->reladdr = NULL; + } + + st_src_reg(gl_register_file file, int index, int type, int index2D) + { + this->type = type; + this->file = file; + this->index = index; + this->index2D = index2D; this->swizzle = SWIZZLE_XYZW; this->negate = 0; this->reladdr = NULL; @@ -126,6 +139,7 @@ public: this->type = GLSL_TYPE_ERROR; this->file = PROGRAM_UNDEFINED; this->index = 0; + this->index2D = 0; this->swizzle = 0; this->negate = 0; this->reladdr = NULL; @@ -135,6 +149,7 @@ public: gl_register_file file; /**< PROGRAM_* from Mesa */ int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */ + int index2D; GLuint swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */ int negate; /**< NEGATE_XYZW mask from mesa */ int type; /** GLSL_TYPE_* from GLSL IR (enum glsl_base_type) */ @@ -183,6 +198,7 @@ st_src_reg::st_src_reg(st_dst_reg reg) this->swizzle = SWIZZLE_XYZW; this->negate = 0; this->reladdr = reg.reladdr; + this->index2D = 0; } st_dst_reg::st_dst_reg(st_src_reg reg) @@ -1873,10 +1889,46 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) assert(!"GLSL 1.30 features unsupported"); break; - case ir_binop_ubo_load: - assert(!"not yet supported"); - break; + case ir_binop_ubo_load: { + ir_constant *uniform_block = ir->operands[0]->as_constant(); + ir_constant *const_offset_ir = ir->operands[1]->as_constant(); + unsigned const_offset = const_offset_ir ? const_offset_ir->value.u[0] : 0; + st_src_reg index_reg = get_temp(glsl_type::uint_type); + st_src_reg cbuf; + + cbuf.type = glsl_type::vec4_type->base_type; + cbuf.file = PROGRAM_CONSTANT; + cbuf.index = 0; + cbuf.index2D = uniform_block->value.u[0] + 1; + cbuf.reladdr = NULL; + cbuf.negate = 0; + + assert(ir->type->is_vector() || ir->type->is_scalar()); + + if (const_offset_ir) { + index_reg = st_src_reg_for_int(const_offset / 16); + } else { + emit(ir, TGSI_OPCODE_USHR, st_dst_reg(index_reg), op[1], st_src_reg_for_int(4)); + } + cbuf.swizzle = swizzle_for_size(ir->type->vector_elements); + cbuf.swizzle += MAKE_SWIZZLE4(const_offset % 16 / 4, + const_offset % 16 / 4, + const_offset % 16 / 4, + const_offset % 16 / 4); + + cbuf.reladdr = ralloc(mem_ctx, st_src_reg); + memcpy(cbuf.reladdr, &index_reg, sizeof(index_reg)); + + if (ir->type->base_type == GLSL_TYPE_BOOL) { + emit(ir, TGSI_OPCODE_USNE, result_dst, cbuf, st_src_reg_for_int(0)); + result_src.negate = 1; + emit(ir, TGSI_OPCODE_UCMP, result_dst, result_src, st_src_reg_for_int(~0), st_src_reg_for_int(0)); + } else { + emit(ir, TGSI_OPCODE_MOV, result_dst, cbuf); + } + break; + } case ir_quadop_vector: /* This operation should have already been handled. */ @@ -2776,7 +2828,7 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir) inst->tex_target = TEXTURE_RECT_INDEX; break; case GLSL_SAMPLER_DIM_BUF: - assert(!"FINISHME: Implement ARB_texture_buffer_object"); + inst->tex_target = TEXTURE_BUFFER_INDEX; break; case GLSL_SAMPLER_DIM_EXTERNAL: inst->tex_target = TEXTURE_EXTERNAL_INDEX; @@ -4061,7 +4113,7 @@ dst_register(struct st_translate *t, static struct ureg_src src_register(struct st_translate *t, gl_register_file file, - GLint index) + GLint index, GLint index2D) { switch(file) { case PROGRAM_UNDEFINED: @@ -4081,7 +4133,13 @@ src_register(struct st_translate *t, return t->constants[index]; case PROGRAM_STATE_VAR: case PROGRAM_CONSTANT: /* ie, immediate */ - if (index < 0) + if (index2D) { + struct ureg_src src; + src = ureg_src_register(TGSI_FILE_CONSTANT, 0); + src.Dimension = 1; + src.DimensionIndex = index2D; + return src; + } else if (index < 0) return ureg_DECL_constant(t->ureg, 0); else return t->constants[index]; @@ -4160,7 +4218,7 @@ translate_dst(struct st_translate *t, static struct ureg_src translate_src(struct st_translate *t, const st_src_reg *src_reg) { - struct ureg_src src = src_register(t, src_reg->file, src_reg->index); + struct ureg_src src = src_register(t, src_reg->file, src_reg->index, src_reg->index2D); src = ureg_swizzle(src, GET_SWZ(src_reg->swizzle, 0) & 0x3, @@ -4202,14 +4260,17 @@ translate_tex_offset(struct st_translate *t, const struct tgsi_texture_offset *in_offset) { struct tgsi_texture_offset offset; + struct ureg_src imm_src; assert(in_offset->File == PROGRAM_IMMEDIATE); + imm_src = t->immediates[in_offset->Index]; + offset.File = imm_src.File; + offset.Index = imm_src.Index; + offset.SwizzleX = imm_src.SwizzleX; + offset.SwizzleY = imm_src.SwizzleY; + offset.SwizzleZ = imm_src.SwizzleZ; offset.File = TGSI_FILE_IMMEDIATE; - offset.Index = in_offset->Index; - offset.SwizzleX = in_offset->SwizzleX; - offset.SwizzleY = in_offset->SwizzleY; - offset.SwizzleZ = in_offset->SwizzleZ; offset.Padding = 0; return offset; @@ -4754,6 +4815,14 @@ st_translate_program( } } } + + if (program->shader_program) { + unsigned num_ubos = program->shader_program->NumUniformBlocks; + + for (i = 0; i < num_ubos; i++) { + ureg_DECL_constant2D(t->ureg, 0, program->shader_program->UniformBlocks[i].UniformBufferSize / 4, i + 1); + } + } /* Emit immediate values. */ @@ -5060,6 +5129,8 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) do_mat_op_to_vec(ir); lower_instructions(ir, what_to_lower); + lower_ubo_reference(prog->_LinkedShaders[i], ir); + progress = do_lower_jumps(ir, true, true, options->EmitNoMainReturn, options->EmitNoCont, options->EmitNoLoops) || progress; progress = do_common_optimization(ir, true, true, @@ -5090,6 +5161,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) || progress; progress = do_vec_index_to_cond_assign(ir) || progress; + } while (progress); validate_ir_tree(ir); diff --git a/mesalib/src/mesa/state_tracker/st_manager.c b/mesalib/src/mesa/state_tracker/st_manager.c index 0b9add95e..b065db0ac 100644 --- a/mesalib/src/mesa/state_tracker/st_manager.c +++ b/mesalib/src/mesa/state_tracker/st_manager.c @@ -398,7 +398,7 @@ st_visual_to_context_mode(const struct st_visual *visual, UTIL_FORMAT_COLORSPACE_RGB, 3); } - if (visual->samples) { + if (visual->samples > 1) { mode->sampleBuffers = 1; mode->samples = visual->samples; } @@ -789,7 +789,7 @@ st_manager_flush_frontbuffer(struct st_context *st) /* never a dummy fb */ assert(&stfb->Base != _mesa_get_incomplete_framebuffer()); - stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT); + stfb->iface->flush_front(&st->iface, stfb->iface, ST_ATTACHMENT_FRONT_LEFT); } /** @@ -899,7 +899,7 @@ static const struct st_api st_gl_api = { ST_PROFILE_OPENGL_ES2_MASK | #endif 0, - 0, + ST_API_FEATURE_MS_VISUALS_MASK, st_api_destroy, st_api_get_proc_address, st_api_create_context, diff --git a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c index 81a870f86..e326bcc70 100644 --- a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -269,6 +269,7 @@ st_translate_texture_target( GLuint textarget, } switch( textarget ) { + case TEXTURE_BUFFER_INDEX: return TGSI_TEXTURE_BUFFER; case TEXTURE_1D_INDEX: return TGSI_TEXTURE_1D; case TEXTURE_2D_INDEX: return TGSI_TEXTURE_2D; case TEXTURE_3D_INDEX: return TGSI_TEXTURE_3D; diff --git a/mesalib/src/mesa/swrast/s_texfetch.c b/mesalib/src/mesa/swrast/s_texfetch.c index 7bfe3b941..86b01a0b3 100644 --- a/mesalib/src/mesa/swrast/s_texfetch.c +++ b/mesalib/src/mesa/swrast/s_texfetch.c @@ -1029,6 +1029,66 @@ texfetch_funcs[] = NULL }, { + MESA_FORMAT_ETC2_RGB8, + NULL, + _mesa_fetch_texel_2d_f_etc2_rgb8, + NULL + }, + { + MESA_FORMAT_ETC2_SRGB8, + NULL, + _mesa_fetch_texel_2d_f_etc2_srgb8, + NULL + }, + { + MESA_FORMAT_ETC2_RGBA8_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_rgba8_eac, + NULL + }, + { + MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac, + NULL + }, + { + MESA_FORMAT_ETC2_R11_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_r11_eac, + NULL + }, + { + MESA_FORMAT_ETC2_RG11_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_rg11_eac, + NULL + }, + { + MESA_FORMAT_ETC2_SIGNED_R11_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_signed_r11_eac, + NULL + }, + { + MESA_FORMAT_ETC2_SIGNED_RG11_EAC, + NULL, + _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac, + NULL + }, + { + MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, + NULL, + _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1, + NULL + }, + { + MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, + NULL, + _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1, + NULL + }, + { MESA_FORMAT_SIGNED_A8, fetch_texel_1d_signed_a8, fetch_texel_2d_signed_a8, |