diff options
Diffstat (limited to 'mesalib/src/mesa')
78 files changed, 4034 insertions, 5834 deletions
diff --git a/mesalib/src/mesa/Makefile.am b/mesalib/src/mesa/Makefile.am index 88eeff9ee..57c1e4a57 100644 --- a/mesalib/src/mesa/Makefile.am +++ b/mesalib/src/mesa/Makefile.am @@ -64,6 +64,7 @@ include Makefile.sources BUILT_SOURCES = \ main/get_hash.h \ + main/format_info.c \ $(BUILDDIR)main/git_sha1.h \ $(BUILDDIR)program/program_parse.tab.c \ $(BUILDDIR)program/lex.yy.c @@ -81,6 +82,15 @@ main/get_hash.h: $(GLAPI)/gl_and_es_API.xml main/get_hash_params.py \ -f $< > $@.tmp; \ mv $@.tmp $@; +main/format_info.c: main/formats.csv \ + main/format_parser.py main/format_info.py + $(AM_V_GEN)set -e; \ + $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/main/format_info.py \ + $< > $@.tmp; \ + mv $@.tmp $@; + +main/formats.c: main/format_info.c + noinst_LTLIBRARIES = $(ARCH_LIBS) if NEED_LIBMESA noinst_LTLIBRARIES += libmesa.la diff --git a/mesalib/src/mesa/Makefile.sources b/mesalib/src/mesa/Makefile.sources index f4904fbbd..594565771 100644 --- a/mesalib/src/mesa/Makefile.sources +++ b/mesalib/src/mesa/Makefile.sources @@ -3,6 +3,9 @@ # This file is among different build systems. SRCDIR must be defined with # a trailing slash because the Android build system leaves it undefined. +SRCDIR = $(top_srcdir)/src/mesa/ +BUILDDIR = $(top_builddir)/src/mesa/ + # this is part of MAIN_FILES MAIN_ES_FILES = \ $(SRCDIR)main/es1_conversion.c @@ -28,6 +31,7 @@ MAIN_FILES = \ $(SRCDIR)main/condrender.c \ $(SRCDIR)main/context.c \ $(SRCDIR)main/convolve.c \ + $(SRCDIR)main/copyimage.c \ $(SRCDIR)main/cpuinfo.c \ $(SRCDIR)main/debug.c \ $(SRCDIR)main/depth.c \ @@ -48,13 +52,13 @@ MAIN_FILES = \ $(SRCDIR)main/formats.c \ $(SRCDIR)main/format_pack.c \ $(SRCDIR)main/format_unpack.c \ + $(SRCDIR)main/format_utils.c \ $(SRCDIR)main/framebuffer.c \ $(SRCDIR)main/get.c \ $(SRCDIR)main/genmipmap.c \ $(SRCDIR)main/getstring.c \ $(SRCDIR)main/glformats.c \ $(SRCDIR)main/hash.c \ - $(SRCDIR)main/hash_table.c \ $(SRCDIR)main/hint.c \ $(SRCDIR)main/histogram.c \ $(SRCDIR)main/image.c \ @@ -321,6 +325,7 @@ SPARC_FILES = \ COMMON_DRIVER_FILES = \ $(SRCDIR)drivers/common/driverfuncs.c \ $(SRCDIR)drivers/common/meta_blit.c \ + $(SRCDIR)drivers/common/meta_copy_image.c \ $(SRCDIR)drivers/common/meta_generate_mipmap.c \ $(SRCDIR)drivers/common/meta.c @@ -349,6 +354,7 @@ MESA_GALLIUM_FILES = \ INCLUDE_DIRS = \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ -I$(top_srcdir)/src/glsl \ -I$(top_builddir)/src/glsl \ -I$(top_srcdir)/src/glsl/glcpp \ diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript index f56578672..e7c4f5ca1 100644 --- a/mesalib/src/mesa/SConscript +++ b/mesalib/src/mesa/SConscript @@ -11,6 +11,7 @@ from sys import executable as python_cmd env = env.Clone() env.Append(CPPPATH = [ + '#/src', '#/src/mapi', '#/src/glsl', '#/src/mesa', @@ -31,316 +32,22 @@ else: ('HAVE_DLOPEN', '1'), ]) -# -# Source files -# - -main_sources = [ - 'main/api_arrayelt.c', - 'main/api_exec.c', - 'main/api_loopback.c', - 'main/api_validate.c', - 'main/accum.c', - 'main/arbprogram.c', - 'main/atifragshader.c', - 'main/attrib.c', - 'main/arrayobj.c', - 'main/blend.c', - 'main/blit.c', - 'main/bufferobj.c', - 'main/buffers.c', - 'main/clear.c', - 'main/clip.c', - 'main/colortab.c', - 'main/compute.c', - 'main/condrender.c', - 'main/context.c', - 'main/convolve.c', - 'main/cpuinfo.c', - 'main/debug.c', - 'main/depth.c', - 'main/dlist.c', - 'main/drawpix.c', - 'main/drawtex.c', - 'main/enable.c', - 'main/enums.c', - 'main/errors.c', - 'main/es1_conversion.c', - 'main/eval.c', - 'main/execmem.c', - 'main/extensions.c', - 'main/fbobject.c', - 'main/feedback.c', - 'main/ff_fragment_shader.cpp', - 'main/ffvertex_prog.c', - 'main/fog.c', - 'main/formatquery.c', - 'main/formats.c', - 'main/format_pack.c', - 'main/format_unpack.c', - 'main/framebuffer.c', - 'main/genmipmap.c', - 'main/getstring.c', - 'main/glformats.c', - 'main/hash.c', - 'main/hash_table.c', - 'main/hint.c', - 'main/histogram.c', - 'main/image.c', - 'main/imports.c', - 'main/light.c', - 'main/lines.c', - 'main/matrix.c', - 'main/mipmap.c', - 'main/mm.c', - 'main/multisample.c', - 'main/objectlabel.c', - 'main/pack.c', - 'main/pbo.c', - 'main/performance_monitor.c', - 'main/pipelineobj.c', - 'main/pixel.c', - 'main/pixelstore.c', - 'main/pixeltransfer.c', - 'main/points.c', - 'main/polygon.c', - 'main/querymatrix.c', - 'main/queryobj.c', - 'main/rastpos.c', - 'main/readpix.c', - 'main/remap.c', - 'main/renderbuffer.c', - 'main/samplerobj.c', - 'main/scissor.c', - 'main/set.c', - 'main/shaderapi.c', - 'main/shaderimage.c', - 'main/shaderobj.c', - 'main/shader_query.cpp', - 'main/shared.c', - 'main/state.c', - 'main/stencil.c', - 'main/syncobj.c', - 'main/texcompress.c', - 'main/texcompress_cpal.c', - 'main/texcompress_rgtc.c', - 'main/texcompress_s3tc.c', - 'main/texcompress_fxt1.c', - 'main/texcompress_etc.c', - 'main/texenv.c', - 'main/texformat.c', - 'main/texgen.c', - 'main/texgetimage.c', - 'main/teximage.c', - 'main/texobj.c', - 'main/texparam.c', - 'main/texstate.c', - 'main/texstorage.c', - 'main/texstore.c', - 'main/texturebarrier.c', - 'main/textureview.c', - 'main/transformfeedback.c', - 'main/uniform_query.cpp', - 'main/uniforms.c', - 'main/varray.c', - 'main/vdpau.c', - 'main/version.c', - 'main/viewport.c', - 'main/vtxfmt.c', -] - -glget_sources = [ - 'main/get.c', -] - -math_sources = [ - 'math/m_debug_clip.c', - 'math/m_debug_norm.c', - 'math/m_debug_xform.c', - 'math/m_eval.c', - 'math/m_matrix.c', - 'math/m_translate.c', - 'math/m_vector.c', - 'math/m_xform.c', -] - -swrast_sources = [ - 'swrast/s_aaline.c', - 'swrast/s_aatriangle.c', - 'swrast/s_alpha.c', - 'swrast/s_atifragshader.c', - 'swrast/s_bitmap.c', - 'swrast/s_blend.c', - 'swrast/s_blit.c', - 'swrast/s_clear.c', - 'swrast/s_copypix.c', - 'swrast/s_context.c', - 'swrast/s_depth.c', - 'swrast/s_drawpix.c', - 'swrast/s_feedback.c', - 'swrast/s_fog.c', - 'swrast/s_fragprog.c', - 'swrast/s_lines.c', - 'swrast/s_logic.c', - 'swrast/s_masking.c', - 'swrast/s_points.c', - 'swrast/s_renderbuffer.c', - 'swrast/s_span.c', - 'swrast/s_stencil.c', - 'swrast/s_texcombine.c', - 'swrast/s_texfetch.c', - 'swrast/s_texfilter.c', - 'swrast/s_texrender.c', - 'swrast/s_texture.c', - 'swrast/s_triangle.c', - 'swrast/s_zoom.c', -] - -swrast_setup_sources = [ - 'swrast_setup/ss_context.c', - 'swrast_setup/ss_triangle.c', -] - -tnl_sources = [ - 'tnl/t_context.c', - 'tnl/t_pipeline.c', - 'tnl/t_draw.c', - 'tnl/t_rasterpos.c', - 'tnl/t_vb_program.c', - 'tnl/t_vb_render.c', - 'tnl/t_vb_texgen.c', - 'tnl/t_vb_texmat.c', - 'tnl/t_vb_vertex.c', - 'tnl/t_vb_fog.c', - 'tnl/t_vb_light.c', - 'tnl/t_vb_normals.c', - 'tnl/t_vb_points.c', - 'tnl/t_vp_build.c', - 'tnl/t_vertex.c', - 'tnl/t_vertex_sse.c', - 'tnl/t_vertex_generic.c', -] - -vbo_sources = [ - 'vbo/vbo_context.c', - 'vbo/vbo_exec.c', - 'vbo/vbo_exec_api.c', - 'vbo/vbo_exec_array.c', - 'vbo/vbo_exec_draw.c', - 'vbo/vbo_exec_eval.c', - 'vbo/vbo_noop.c', - 'vbo/vbo_primitive_restart.c', - 'vbo/vbo_rebase.c', - 'vbo/vbo_split.c', - 'vbo/vbo_split_copy.c', - 'vbo/vbo_split_inplace.c', - 'vbo/vbo_save.c', - 'vbo/vbo_save_api.c', - 'vbo/vbo_save_draw.c', - 'vbo/vbo_save_loopback.c', -] - -statetracker_sources = [ - 'state_tracker/st_atom.c', - 'state_tracker/st_atom_array.c', - 'state_tracker/st_atom_blend.c', - 'state_tracker/st_atom_clip.c', - 'state_tracker/st_atom_constbuf.c', - 'state_tracker/st_atom_depth.c', - 'state_tracker/st_atom_framebuffer.c', - 'state_tracker/st_atom_msaa.c', - 'state_tracker/st_atom_pixeltransfer.c', - 'state_tracker/st_atom_sampler.c', - 'state_tracker/st_atom_scissor.c', - 'state_tracker/st_atom_shader.c', - 'state_tracker/st_atom_rasterizer.c', - 'state_tracker/st_atom_stipple.c', - 'state_tracker/st_atom_texture.c', - 'state_tracker/st_atom_viewport.c', - 'state_tracker/st_cb_bitmap.c', - 'state_tracker/st_cb_blit.c', - 'state_tracker/st_cb_bufferobjects.c', - 'state_tracker/st_cb_clear.c', - 'state_tracker/st_cb_condrender.c', - 'state_tracker/st_cb_flush.c', - 'state_tracker/st_cb_drawpixels.c', - 'state_tracker/st_cb_drawtex.c', - 'state_tracker/st_cb_eglimage.c', - 'state_tracker/st_cb_fbo.c', - 'state_tracker/st_cb_feedback.c', - 'state_tracker/st_cb_msaa.c', - 'state_tracker/st_cb_program.c', - 'state_tracker/st_cb_queryobj.c', - 'state_tracker/st_cb_rasterpos.c', - 'state_tracker/st_cb_readpixels.c', - 'state_tracker/st_cb_syncobj.c', - 'state_tracker/st_cb_strings.c', - 'state_tracker/st_cb_texture.c', - 'state_tracker/st_cb_texturebarrier.c', - 'state_tracker/st_cb_viewport.c', - 'state_tracker/st_cb_xformfb.c', - 'state_tracker/st_context.c', - 'state_tracker/st_debug.c', - 'state_tracker/st_draw.c', - 'state_tracker/st_draw_feedback.c', - 'state_tracker/st_extensions.c', - 'state_tracker/st_format.c', - 'state_tracker/st_glsl_to_tgsi.cpp', - 'state_tracker/st_gen_mipmap.c', - 'state_tracker/st_manager.c', - 'state_tracker/st_mesa_to_tgsi.c', - 'state_tracker/st_program.c', - 'state_tracker/st_texture.c', - 'state_tracker/st_vdpau.c', -] +# parse Makefile.sources +source_lists = env.ParseSourceList('Makefile.sources') env.Append(YACCFLAGS = '-d -p "_mesa_program_"') program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l') program_parse = env.CFile('program/program_parse.tab.c', 'program/program_parse.y') - -program_sources = [ - 'program/arbprogparse.c', - 'program/prog_hash_table.c', - 'program/ir_to_mesa.cpp', - 'program/program.c', - 'program/program_parse_extra.c', - 'program/prog_cache.c', - 'program/prog_execute.c', - 'program/prog_instruction.c', - 'program/prog_noise.c', - 'program/prog_optimize.c', - 'program/prog_opt_constant_fold.c', - 'program/prog_parameter.c', - 'program/prog_parameter_layout.c', - 'program/prog_print.c', - 'program/prog_statevars.c', - 'program/programopt.c', - 'program/sampler.cpp', - 'program/symbol_table.c', - 'program/string_to_uint_map.cpp', +program_sources = source_lists['PROGRAM_FILES'] + [ program_lex, program_parse[0], ] -common_driver_sources = [ - 'drivers/common/driverfuncs.c', - 'drivers/common/meta.c', - 'drivers/common/meta_blit.c', - 'drivers/common/meta_generate_mipmap.c' -] - mesa_sources = ( - main_sources + - glget_sources + - math_sources + + source_lists['MESA_FILES'] + program_sources + - vbo_sources + - tnl_sources + - swrast_sources + - swrast_setup_sources + - common_driver_sources + - statetracker_sources + source_lists['STATETRACKER_FILES'] ) GLAPI = '#src/mapi/glapi/' @@ -352,6 +59,13 @@ get_hash_header = env.CodeGenerate( command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET' ) +format_info = env.CodeGenerate( + target = 'main/format_info.c', + script = 'main/format_info.py', + source = 'main/formats.csv', + command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET' +) + # # Assembly sources # @@ -364,45 +78,14 @@ if (env['gcc'] or env['clang']) and \ 'USE_3DNOW_ASM', 'USE_SSE_ASM', ]) - mesa_sources += [ - 'x86/common_x86.c', - 'x86/x86_xform.c', - 'x86/3dnow.c', - 'x86/sse.c', - 'x86/common_x86_asm.S', - 'x86/x86_xform2.S', - 'x86/x86_xform3.S', - 'x86/x86_xform4.S', - 'x86/x86_cliptest.S', - 'x86/mmx_blend.S', - 'x86/3dnow_xform1.S', - 'x86/3dnow_xform2.S', - 'x86/3dnow_xform3.S', - 'x86/3dnow_xform4.S', - 'x86/3dnow_normal.S', - 'x86/sse_xform1.S', - 'x86/sse_xform2.S', - 'x86/sse_xform3.S', - 'x86/sse_xform4.S', - 'x86/sse_normal.S', - 'x86/read_rgba_span_x86.S', - ] + mesa_sources += source_lists['X86_FILES'] elif env['machine'] == 'x86_64': env.Append(CPPDEFINES = [ 'USE_X86_64_ASM', ]) - mesa_sources += [ - 'x86/common_x86.c', - 'x86-64/x86-64.c', - 'x86-64/xform4.S', - ] + mesa_sources += source_lists['X86_64_FILES'] elif env['machine'] == 'sparc': - mesa_sources += [ - 'sparc/sparc.c', - 'sparc/sparc_clip.S', - 'sparc/norm.S', - 'sparc/xform.S', - ] + mesa_sources += source_lists['SPARC_FILES'] else: pass diff --git a/mesalib/src/mesa/drivers/common/meta.c b/mesalib/src/mesa/drivers/common/meta.c index b12898f26..a1d06d412 100644 --- a/mesalib/src/mesa/drivers/common/meta.c +++ b/mesalib/src/mesa/drivers/common/meta.c @@ -84,7 +84,7 @@ #include "drivers/common/meta.h" #include "main/enums.h" #include "main/glformats.h" -#include "../glsl/ralloc.h" +#include "util/ralloc.h" /** Return offset in bytes of the field within a vertex struct */ #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD)) @@ -101,18 +101,18 @@ static void meta_decompress_cleanup(struct decompress_state *decompress); static void meta_drawpix_cleanup(struct drawpix_state *drawpix); void -_mesa_meta_bind_fbo_image(GLenum attachment, +_mesa_meta_bind_fbo_image(GLenum fboTarget, GLenum attachment, struct gl_texture_image *texImage, GLuint layer) { struct gl_texture_object *texObj = texImage->TexObject; int level = texImage->Level; - GLenum target = texObj->Target; + GLenum texTarget = texObj->Target; - switch (target) { + switch (texTarget) { case GL_TEXTURE_1D: - _mesa_FramebufferTexture1D(GL_FRAMEBUFFER, + _mesa_FramebufferTexture1D(fboTarget, attachment, - target, + texTarget, texObj->Name, level); break; @@ -121,19 +121,19 @@ _mesa_meta_bind_fbo_image(GLenum attachment, case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: case GL_TEXTURE_CUBE_MAP_ARRAY: case GL_TEXTURE_3D: - _mesa_FramebufferTextureLayer(GL_FRAMEBUFFER, + _mesa_FramebufferTextureLayer(fboTarget, attachment, texObj->Name, level, layer); break; default: /* 2D / cube */ - if (target == GL_TEXTURE_CUBE_MAP) - target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face; + if (texTarget == GL_TEXTURE_CUBE_MAP) + texTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face; - _mesa_FramebufferTexture2D(GL_FRAMEBUFFER, + _mesa_FramebufferTexture2D(fboTarget, attachment, - target, + texTarget, texObj->Name, level); } @@ -2732,9 +2732,9 @@ _mesa_meta_blit_shader_table_cleanup(struct blit_shader_table *table) static GLenum get_temp_image_type(struct gl_context *ctx, mesa_format format) { - GLenum baseFormat; - - baseFormat = _mesa_get_format_base_format(format); + const GLenum baseFormat = _mesa_get_format_base_format(format); + const GLenum datatype = _mesa_get_format_datatype(format); + const GLint format_red_bits = _mesa_get_format_bits(format, GL_RED_BITS); switch (baseFormat) { case GL_RGBA: @@ -2745,30 +2745,24 @@ get_temp_image_type(struct gl_context *ctx, mesa_format format) case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_INTENSITY: - if (ctx->DrawBuffer->Visual.redBits <= 8) { + if (datatype == GL_INT || datatype == GL_UNSIGNED_INT) { + return datatype; + } else if (format_red_bits <= 8) { return GL_UNSIGNED_BYTE; - } else if (ctx->DrawBuffer->Visual.redBits <= 16) { + } else if (format_red_bits <= 16) { return GL_UNSIGNED_SHORT; - } else { - GLenum datatype = _mesa_get_format_datatype(format); - if (datatype == GL_INT || datatype == GL_UNSIGNED_INT) - return datatype; - return GL_FLOAT; } - case GL_DEPTH_COMPONENT: { - GLenum datatype = _mesa_get_format_datatype(format); + return GL_FLOAT; + case GL_DEPTH_COMPONENT: if (datatype == GL_FLOAT) return GL_FLOAT; else return GL_UNSIGNED_INT; - } - case GL_DEPTH_STENCIL: { - GLenum datatype = _mesa_get_format_datatype(format); + case GL_DEPTH_STENCIL: if (datatype == GL_FLOAT) return GL_FLOAT_32_UNSIGNED_INT_24_8_REV; else return GL_UNSIGNED_INT_24_8; - } default: _mesa_problem(ctx, "Unexpected format %d in get_temp_image_type()", baseFormat); @@ -2808,17 +2802,20 @@ copytexsubimage_using_blit_framebuffer(struct gl_context *ctx, GLuint dims, if (rb->_BaseFormat == GL_DEPTH_STENCIL || rb->_BaseFormat == GL_DEPTH_COMPONENT) { - _mesa_meta_bind_fbo_image(GL_DEPTH_ATTACHMENT, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + texImage, zoffset); mask = GL_DEPTH_BUFFER_BIT; if (rb->_BaseFormat == GL_DEPTH_STENCIL && texImage->_BaseFormat == GL_DEPTH_STENCIL) { - _mesa_meta_bind_fbo_image(GL_STENCIL_ATTACHMENT, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, + texImage, zoffset); mask |= GL_STENCIL_BUFFER_BIT; } _mesa_DrawBuffer(GL_NONE); } else { - _mesa_meta_bind_fbo_image(GL_COLOR_ATTACHMENT0, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + texImage, zoffset); mask = GL_COLOR_BUFFER_BIT; _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0); } @@ -3362,7 +3359,8 @@ cleartexsubimage_color(struct gl_context *ctx, GLenum datatype; GLenum status; - _mesa_meta_bind_fbo_image(GL_COLOR_ATTACHMENT0, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + texImage, zoffset); status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) @@ -3408,10 +3406,12 @@ cleartexsubimage_depth_stencil(struct gl_context *ctx, GLfloat depthValue; GLenum status; - _mesa_meta_bind_fbo_image(GL_DEPTH_ATTACHMENT, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + texImage, zoffset); if (texImage->_BaseFormat == GL_DEPTH_STENCIL) - _mesa_meta_bind_fbo_image(GL_STENCIL_ATTACHMENT, texImage, zoffset); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, + texImage, zoffset); status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) diff --git a/mesalib/src/mesa/drivers/common/meta.h b/mesalib/src/mesa/drivers/common/meta.h index b269dceed..e2da2f427 100644 --- a/mesalib/src/mesa/drivers/common/meta.h +++ b/mesalib/src/mesa/drivers/common/meta.h @@ -440,6 +440,14 @@ _mesa_meta_and_swrast_BlitFramebuffer(struct gl_context *ctx, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +bool +_mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx, + struct gl_texture_image *src_tex_image, + int src_x, int src_y, int src_z, + struct gl_texture_image *dst_tex_image, + int dst_x, int dst_y, int dst_z, + int src_width, int src_height); + extern void _mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers); @@ -570,7 +578,7 @@ void _mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state *mipmap); void -_mesa_meta_bind_fbo_image(GLenum attachment, +_mesa_meta_bind_fbo_image(GLenum target, GLenum attachment, struct gl_texture_image *texImage, GLuint layer); #endif /* META_H */ diff --git a/mesalib/src/mesa/drivers/common/meta_blit.c b/mesalib/src/mesa/drivers/common/meta_blit.c index bbf0c3c45..955e73f57 100644 --- a/mesalib/src/mesa/drivers/common/meta_blit.c +++ b/mesalib/src/mesa/drivers/common/meta_blit.c @@ -49,7 +49,7 @@ #include "main/viewport.h" #include "swrast/swrast.h" #include "drivers/common/meta.h" -#include "../glsl/ralloc.h" +#include "util/ralloc.h" /** Return offset in bytes of the field within a vertex struct */ #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD)) @@ -709,6 +709,9 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx, */ _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS); + /* Dithering shouldn't be performed for glBlitFramebuffer */ + _mesa_set_enable(ctx, GL_DITHER, GL_FALSE); + /* If the clipping earlier changed the destination rect at all, then * enable the scissor to clip to it. */ diff --git a/mesalib/src/mesa/drivers/common/meta_copy_image.c b/mesalib/src/mesa/drivers/common/meta_copy_image.c new file mode 100644 index 000000000..c40c2f011 --- /dev/null +++ b/mesalib/src/mesa/drivers/common/meta_copy_image.c @@ -0,0 +1,199 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2014 Intel Corporation. All Rights Reserved. + * + * 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 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. + */ + +#include "glheader.h" +#include "context.h" +#include "enums.h" +#include "imports.h" +#include "macros.h" +#include "teximage.h" +#include "texobj.h" +#include "fbobject.h" +#include "buffers.h" +#include "state.h" +#include "mtypes.h" +#include "meta.h" + +/* This function makes a texture view without bothering with all of the API + * checks. Most of them are the same for CopyTexSubImage so checking would + * be redundant. The one major difference is that we don't check for + * whether the texture is immutable or not. However, since the view will + * be created and then immediately destroyed, this should not be a problem. + */ +static bool +make_view(struct gl_context *ctx, struct gl_texture_image *tex_image, + struct gl_texture_image **view_tex_image, GLuint *view_tex_name, + GLenum internal_format) +{ + struct gl_texture_object *tex_obj = tex_image->TexObject; + struct gl_texture_object *view_tex_obj; + mesa_format tex_format; + + /* Set up the new texture object */ + _mesa_GenTextures(1, view_tex_name); + view_tex_obj = _mesa_lookup_texture(ctx, *view_tex_name); + if (!view_tex_obj) + return false; + + tex_format = _mesa_choose_texture_format(ctx, view_tex_obj, tex_obj->Target, + 0, internal_format, + GL_NONE, GL_NONE); + + if (!ctx->Driver.TestProxyTexImage(ctx, tex_obj->Target, 0, tex_format, + tex_image->Width, tex_image->Height, + tex_image->Depth, 0)) { + return false; + } + + view_tex_obj->Target = tex_obj->Target; + + *view_tex_image = _mesa_get_tex_image(ctx, view_tex_obj, tex_obj->Target, 0); + _mesa_init_teximage_fields(ctx, *view_tex_image, + tex_image->Width, tex_image->Height, + tex_image->Depth, + 0, internal_format, tex_format); + + view_tex_obj->MinLevel = 0; + view_tex_obj->NumLevels = 1; + view_tex_obj->MinLayer = tex_obj->MinLayer; + view_tex_obj->NumLayers = tex_obj->NumLayers; + view_tex_obj->Immutable = tex_obj->Immutable; + view_tex_obj->ImmutableLevels = tex_obj->ImmutableLevels; + view_tex_obj->Target = tex_obj->Target; + + if (ctx->Driver.TextureView != NULL && + !ctx->Driver.TextureView(ctx, view_tex_obj, tex_obj)) { + _mesa_DeleteTextures(1, view_tex_name); + *view_tex_name = 0; + return false; /* driver recorded error */ + } + + return true; +} + +/** A partial implementation of glCopyImageSubData + * + * This is a partial implementation of glCopyImageSubData that works only + * if both textures are uncompressed and the destination texture is + * renderable. It uses a slight abuse of a texture view (see make_view) to + * turn the source texture into the destination texture type and then uses + * _mesa_meta_BlitFramebuffers to do the copy. + */ +bool +_mesa_meta_CopyImageSubData_uncompressed(struct gl_context *ctx, + struct gl_texture_image *src_tex_image, + int src_x, int src_y, int src_z, + struct gl_texture_image *dst_tex_image, + int dst_x, int dst_y, int dst_z, + int src_width, int src_height) +{ + GLuint src_view_texture = 0; + struct gl_texture_image *src_view_tex_image; + GLuint fbos[2]; + bool success = false; + GLbitfield mask; + GLenum status, attachment; + + if (_mesa_is_format_compressed(dst_tex_image->TexFormat)) + return false; + + if (_mesa_is_format_compressed(src_tex_image->TexFormat)) + return false; + + if (src_tex_image->InternalFormat == dst_tex_image->InternalFormat) { + src_view_tex_image = src_tex_image; + } else { + if (!make_view(ctx, src_tex_image, &src_view_tex_image, &src_view_texture, + dst_tex_image->InternalFormat)) + goto cleanup; + } + + /* We really only need to stash the bound framebuffers. */ + _mesa_meta_begin(ctx, 0); + + _mesa_GenFramebuffers(2, fbos); + _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, fbos[0]); + _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[1]); + + switch (_mesa_get_format_base_format(src_tex_image->TexFormat)) { + case GL_DEPTH_COMPONENT: + attachment = GL_DEPTH_ATTACHMENT; + mask = GL_DEPTH_BUFFER_BIT; + break; + case GL_DEPTH_STENCIL: + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + mask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; + break; + case GL_STENCIL_INDEX: + attachment = GL_STENCIL_ATTACHMENT; + mask = GL_STENCIL_BUFFER_BIT; + break; + default: + attachment = GL_COLOR_ATTACHMENT0; + mask = GL_COLOR_BUFFER_BIT; + _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0); + _mesa_ReadBuffer(GL_COLOR_ATTACHMENT0); + } + + _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, attachment, + src_view_tex_image, src_z); + + status = _mesa_CheckFramebufferStatus(GL_READ_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto meta_end; + + _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, attachment, + dst_tex_image, dst_z); + + status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + goto meta_end; + + /* Since we've bound a new draw framebuffer, we need to update its + * derived state -- _Xmin, etc -- for BlitFramebuffer's clipping to + * be correct. + */ + _mesa_update_state(ctx); + + /* We skip the core BlitFramebuffer checks for format consistency. + * We have already created views to ensure that the texture formats + * match. + */ + ctx->Driver.BlitFramebuffer(ctx, src_x, src_y, + src_x + src_width, src_y + src_height, + dst_x, dst_y, + dst_x + src_width, dst_y + src_height, + mask, GL_NEAREST); + + success = true; + +meta_end: + _mesa_DeleteFramebuffers(2, fbos); + _mesa_meta_end(ctx); + +cleanup: + _mesa_DeleteTextures(1, &src_view_texture); + + return success; +} diff --git a/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c b/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c index 4b1718df9..8ffd8da3b 100644 --- a/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c +++ b/mesalib/src/mesa/drivers/common/meta_generate_mipmap.c @@ -104,7 +104,7 @@ fallback_required(struct gl_context *ctx, GLenum target, _mesa_GenFramebuffers(1, &mipmap->FBO); _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, mipmap->FBO); - _mesa_meta_bind_fbo_image(GL_COLOR_ATTACHMENT0, baseImage, 0); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, baseImage, 0); status = _mesa_CheckFramebufferStatus(GL_FRAMEBUFFER_EXT); @@ -327,7 +327,7 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, _mesa_BufferData(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_DYNAMIC_DRAW_ARB); - _mesa_meta_bind_fbo_image(GL_COLOR_ATTACHMENT0, dstImage, layer); + _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dstImage, layer); /* sanity check */ if (_mesa_CheckFramebufferStatus(GL_FRAMEBUFFER) != diff --git a/mesalib/src/mesa/drivers/dri/common/SConscript b/mesalib/src/mesa/drivers/dri/common/SConscript index d003139bf..0bee1b41f 100644 --- a/mesalib/src/mesa/drivers/dri/common/SConscript +++ b/mesalib/src/mesa/drivers/dri/common/SConscript @@ -10,6 +10,7 @@ drienv.Replace(CPPPATH = [ xmlpool_options.dir.dir, # Dir to generated xmlpool/options.h '#include', '#include/GL/internal', + '#src', '#src/mapi', '#src/gallium/include', '#src/gallium/auxiliary', diff --git a/mesalib/src/mesa/drivers/dri/common/xmlconfig.c b/mesalib/src/mesa/drivers/dri/common/xmlconfig.c index 58d0e0656..ce376475c 100644 --- a/mesalib/src/mesa/drivers/dri/common/xmlconfig.c +++ b/mesalib/src/mesa/drivers/dri/common/xmlconfig.c @@ -45,6 +45,8 @@ extern char *program_invocation_name, *program_invocation_short_name; # endif # define GET_PROGRAM_NAME() program_invocation_short_name +#elif defined(__CYGWIN__) +# define GET_PROGRAM_NAME() program_invocation_short_name #elif defined(__FreeBSD__) && (__FreeBSD__ >= 2) # include <osreldate.h> # if (__FreeBSD_version >= 440000) diff --git a/mesalib/src/mesa/drivers/dri/common/xmlconfig.h b/mesalib/src/mesa/drivers/dri/common/xmlconfig.h index af0323485..8969843bd 100644 --- a/mesalib/src/mesa/drivers/dri/common/xmlconfig.h +++ b/mesalib/src/mesa/drivers/dri/common/xmlconfig.h @@ -58,7 +58,7 @@ typedef struct driOptionInfo { char *name; /**< \brief Name */ driOptionType type; /**< \brief Type */ driOptionRange *ranges; /**< \brief Array of ranges */ - uint nRanges; /**< \brief Number of ranges */ + unsigned int nRanges; /**< \brief Number of ranges */ } driOptionInfo; /** \brief Option cache @@ -76,7 +76,7 @@ typedef struct driOptionCache { * \li Default values in screen * \li Actual values in contexts */ - uint tableSize; + unsigned int tableSize; /**< \brief Size of the arrays * * In the current implementation it's not actually a size but log2(size). diff --git a/mesalib/src/mesa/drivers/windows/gdi/SConscript b/mesalib/src/mesa/drivers/windows/gdi/SConscript index 10a7eeaa1..1f4d7e1fa 100644 --- a/mesalib/src/mesa/drivers/windows/gdi/SConscript +++ b/mesalib/src/mesa/drivers/windows/gdi/SConscript @@ -3,6 +3,7 @@ Import('*') env = env.Clone() env.Prepend(CPPPATH = [ + '#src', '#src/mapi', '#src/mesa', ]) @@ -16,6 +17,7 @@ if not env['gles']: env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS']) env.Prepend(LIBS = [ + mesautil, glapi, mesa, glsl, diff --git a/mesalib/src/mesa/main/.gitignore b/mesalib/src/mesa/main/.gitignore index 837f49036..fec06291a 100644 --- a/mesalib/src/mesa/main/.gitignore +++ b/mesalib/src/mesa/main/.gitignore @@ -8,3 +8,4 @@ git_sha1.h.tmp remap_helper.h get_hash.h get_hash.h.tmp +format_info.c diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index 7b1bba097..b6879ceb5 100644 --- a/mesalib/src/mesa/main/bufferobj.c +++ b/mesalib/src/mesa/main/bufferobj.c @@ -31,6 +31,7 @@ */ #include <stdbool.h> +#include <inttypes.h> /* for PRId64 macro */ #include "glheader.h" #include "enums.h" #include "hash.h" @@ -832,6 +833,9 @@ _mesa_init_buffer_objects( struct gl_context *ctx ) _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, ctx->Shared->NullBufferObj); + _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, + ctx->Shared->NullBufferObj); + _mesa_reference_buffer_object(ctx, &ctx->DrawIndirectBuffer, ctx->Shared->NullBufferObj); @@ -842,6 +846,14 @@ _mesa_init_buffer_objects( struct gl_context *ctx ) ctx->UniformBufferBindings[i].Offset = -1; ctx->UniformBufferBindings[i].Size = -1; } + + for (i = 0; i < MAX_COMBINED_ATOMIC_BUFFERS; i++) { + _mesa_reference_buffer_object(ctx, + &ctx->AtomicBufferBindings[i].BufferObject, + ctx->Shared->NullBufferObj); + ctx->AtomicBufferBindings[i].Offset = -1; + ctx->AtomicBufferBindings[i].Size = -1; + } } @@ -857,6 +869,8 @@ _mesa_free_buffer_objects( struct gl_context *ctx ) _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, NULL); + _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, NULL); + _mesa_reference_buffer_object(ctx, &ctx->DrawIndirectBuffer, NULL); for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) { @@ -864,6 +878,13 @@ _mesa_free_buffer_objects( struct gl_context *ctx ) &ctx->UniformBufferBindings[i].BufferObject, NULL); } + + for (i = 0; i < MAX_COMBINED_ATOMIC_BUFFERS; i++) { + _mesa_reference_buffer_object(ctx, + &ctx->AtomicBufferBindings[i].BufferObject, + NULL); + } + } bool @@ -1200,6 +1221,17 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids) _mesa_BindBuffer( GL_UNIFORM_BUFFER, 0 ); } + /* unbind Atomci Buffer binding points */ + for (j = 0; j < ctx->Const.MaxAtomicBufferBindings; j++) { + if (ctx->AtomicBufferBindings[j].BufferObject == bufObj) { + _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER, j, 0 ); + } + } + + if (ctx->UniformBuffer == bufObj) { + _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER, 0 ); + } + /* unbind any pixel pack/unpack pointers bound to this buffer */ if (ctx->Pack.BufferObj == bufObj) { _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT, 0 ); @@ -2793,8 +2825,8 @@ bind_buffers_check_offset_and_size(struct gl_context *ctx, * value in <offsets> is less than zero (per binding)." */ _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(offsets[%u]=%lld < 0)", - index, (long long int) offsets[index]); + "glBindBuffersRange(offsets[%u]=%" PRId64 " < 0)", + index, (int64_t) offsets[index]); return false; } @@ -2805,8 +2837,8 @@ bind_buffers_check_offset_and_size(struct gl_context *ctx, * value in <sizes> is less than or equal to zero (per binding)." */ _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(sizes[%u]=%lld <= 0)", - index, (long long int) sizes[index]); + "glBindBuffersRange(sizes[%u]=%" PRId64 " <= 0)", + index, (int64_t) sizes[index]); return false; } @@ -3001,11 +3033,11 @@ bind_uniform_buffers_range(struct gl_context *ctx, GLuint first, GLsizei count, */ if (offsets[i] & (ctx->Const.UniformBufferOffsetAlignment - 1)) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(offsets[%u]=%lld is misaligned; " - "it must be a multiple of the value of " + "glBindBuffersRange(offsets[%u]=%" PRId64 + " is misaligned; it must be a multiple of the value of " "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when " "target=GL_UNIFORM_BUFFER)", - i, (long long int) offsets[i], + i, (int64_t) offsets[i], ctx->Const.UniformBufferOffsetAlignment); continue; } @@ -3239,19 +3271,19 @@ bind_xfb_buffers_range(struct gl_context *ctx, */ if (offsets[i] & 0x3) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(offsets[%u]=%lld is misaligned; " - "it must be a multiple of 4 when " + "glBindBuffersRange(offsets[%u]=%" PRId64 + " is misaligned; it must be a multiple of 4 when " "target=GL_TRANSFORM_FEEDBACK_BUFFER)", - i, (long long int) offsets[i]); + i, (int64_t) offsets[i]); continue; } if (sizes[i] & 0x3) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(sizes[%u]=%lld is misaligned; " - "it must be a multiple of 4 when " + "glBindBuffersRange(sizes[%u]=%" PRId64 + " is misaligned; it must be a multiple of 4 when " "target=GL_TRANSFORM_FEEDBACK_BUFFER)", - i, (long long int) sizes[i]); + i, (int64_t) sizes[i]); continue; } @@ -3457,10 +3489,10 @@ bind_atomic_buffers_range(struct gl_context *ctx, */ if (offsets[i] & (ATOMIC_COUNTER_SIZE - 1)) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindBuffersRange(offsets[%u]=%lld is misaligned; " - "it must be a multiple of %d when " + "glBindBuffersRange(offsets[%u]=%" PRId64 + " is misaligned; it must be a multiple of %d when " "target=GL_ATOMIC_COUNTER_BUFFER)", - i, (long long int) offsets[i], ATOMIC_COUNTER_SIZE); + i, (int64_t) offsets[i], ATOMIC_COUNTER_SIZE); continue; } diff --git a/mesalib/src/mesa/main/buffers.c b/mesalib/src/mesa/main/buffers.c index b13a7af65..140cf6e82 100644 --- a/mesalib/src/mesa/main/buffers.c +++ b/mesalib/src/mesa/main/buffers.c @@ -494,10 +494,11 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers, } /* - * If n==1, destMask[0] may have up to four bits set. + * destMask[0] may have up to four bits set + * (ex: glDrawBuffer(GL_FRONT_AND_BACK)). * Otherwise, destMask[x] can only have one bit set. */ - if (n == 1) { + if (_mesa_bitcount(destMask[0]) > 1) { GLuint count = 0, destMask0 = destMask[0]; while (destMask0) { GLint bufIndex = ffs(destMask0) - 1; @@ -566,16 +567,11 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers, void _mesa_update_draw_buffers(struct gl_context *ctx) { - GLenum buffers[MAX_DRAW_BUFFERS]; - GLuint i; - /* should be a window system FBO */ assert(_mesa_is_winsys_fbo(ctx->DrawBuffer)); - for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) - buffers[i] = ctx->Color.DrawBuffer[i]; - - _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, buffers, NULL); + _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, + ctx->Color.DrawBuffer, NULL); } diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h index 79d8740e5..35160223e 100644 --- a/mesalib/src/mesa/main/compiler.h +++ b/mesalib/src/mesa/main/compiler.h @@ -44,6 +44,8 @@ #include <float.h> #include <stdarg.h> +#include "util/macros.h" + #include "c99_compat.h" /* inline, __func__, etc. */ @@ -130,23 +132,6 @@ extern "C" { #endif -/** - * __builtin_expect macros - */ -#if !defined(__GNUC__) -# define __builtin_expect(x, y) (x) -#endif - -#ifndef likely -# ifdef __GNUC__ -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) -# else -# define likely(x) (x) -# define unlikely(x) (x) -# endif -#endif - /* XXX: Use standard `__func__` instead */ #ifndef __FUNCTION__ # define __FUNCTION__ __func__ @@ -238,65 +223,16 @@ static INLINE GLuint CPU_TO_LE32(GLuint x) #endif -/** - * Static (compile-time) assertion. - * Basically, use COND to dimension an array. If COND is false/zero the - * array size will be -1 and we'll get a compilation error. - */ -#define STATIC_ASSERT(COND) \ - do { \ - (void) sizeof(char [1 - 2*!(COND)]); \ - } while (0) - -/** - * Unreachable macro. Useful for suppressing "control reaches end of non-void - * function" warnings. - */ -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 5 -#define unreachable(str) \ -do { \ - assert(!str); \ - __builtin_unreachable(); \ -} while (0) -#elif (defined(__clang__) && defined(__has_builtin)) -# if __has_builtin(__builtin_unreachable) -# define unreachable(str) \ -do { \ - assert(!str); \ - __builtin_unreachable(); \ -} while (0) -# endif -#endif - -#ifndef unreachable -#define unreachable(str) -#endif - /* * A trick to suppress uninitialized variable warning without generating any * code */ #define uninitialized_var(x) x = x -#if (__GNUC__ >= 3) -#define PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a))) -#else -#define PRINTFLIKE(f, a) -#endif - #ifndef NULL #define NULL 0 #endif -/* Used to optionally mark structures with misaligned elements or size as - * packed, to trade off performance for space. - */ -#if (__GNUC__ >= 3) -#define PACKED __attribute__((__packed__)) -#else -#define PACKED -#endif - /** * LONGSTRING macro @@ -329,25 +265,7 @@ do { \ #define FLT_MAX_EXP 128 #endif - -/** - * USE_IEEE: Determine if we're using IEEE floating point - */ -#if defined(__i386__) || defined(__386__) || defined(__sparc__) || \ - defined(__s390__) || defined(__s390x__) || defined(__powerpc__) || \ - defined(__x86_64__) || \ - defined(__m68k__) || \ - defined(ia64) || defined(__ia64__) || \ - defined(__hppa__) || defined(hpux) || \ - defined(__mips) || defined(_MIPS_ARCH) || \ - defined(__arm__) || defined(__aarch64__) || \ - defined(__sh__) || defined(__m32r__) || \ - (defined(__sun) && defined(_IEEE_754)) || \ - defined(__alpha__) -#define USE_IEEE #define IEEE_ONE 0x3f800000 -#endif - /** * START/END_FAST_MATH macros: @@ -433,30 +351,6 @@ do { \ #endif #ifdef __cplusplus -/** - * Macro function that evaluates to true if T is a trivially - * destructible type -- that is, if its (non-virtual) destructor - * performs no action and all member variables and base classes are - * trivially destructible themselves. - */ -# if defined(__GNUC__) -# if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) -# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) -# endif -# elif (defined(__clang__) && defined(__has_feature)) -# if __has_feature(has_trivial_destructor) -# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) -# endif -# endif -# ifndef HAS_TRIVIAL_DESTRUCTOR - /* It's always safe (if inefficient) to assume that a - * destructor is non-trivial. - */ -# define HAS_TRIVIAL_DESTRUCTOR(T) (false) -# endif -#endif - -#ifdef __cplusplus } #endif diff --git a/mesalib/src/mesa/main/copyimage.c b/mesalib/src/mesa/main/copyimage.c new file mode 100644 index 000000000..dcbc83de6 --- /dev/null +++ b/mesalib/src/mesa/main/copyimage.c @@ -0,0 +1,356 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2014 Intel Corporation. All Rights Reserved. + * + * 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 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: + * Jason Ekstrand <jason.ekstrand@intel.com> + */ + +#include "glheader.h" +#include "errors.h" +#include "enums.h" +#include "copyimage.h" +#include "teximage.h" +#include "texobj.h" +#include "fbobject.h" +#include "textureview.h" + +static bool +prepare_target(struct gl_context *ctx, GLuint name, GLenum *target, int level, + struct gl_texture_object **tex_obj, + struct gl_texture_image **tex_image, GLuint *tmp_tex, + const char *dbg_prefix) +{ + struct gl_renderbuffer *rb; + + if (name == 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sName = %d)", dbg_prefix, name); + return false; + } + + /* + * INVALID_ENUM is generated + * * if either <srcTarget> or <dstTarget> + * - is not RENDERBUFFER or a valid non-proxy texture target + * - is TEXTURE_BUFFER, or + * - is one of the cubemap face selectors described in table 3.17, + */ + switch (*target) { + case GL_RENDERBUFFER: + /* Not a texture target, but valid */ + case GL_TEXTURE_1D: + case GL_TEXTURE_1D_ARRAY: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_RECTANGLE: + case GL_TEXTURE_2D_ARRAY: + case GL_TEXTURE_CUBE_MAP_ARRAY: + case GL_TEXTURE_2D_MULTISAMPLE: + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: + /* These are all valid */ + break; + case GL_TEXTURE_EXTERNAL_OES: + /* Only exists in ES */ + case GL_TEXTURE_BUFFER: + default: + _mesa_error(ctx, GL_INVALID_ENUM, + "glCopyImageSubData(%sTarget = %s)", dbg_prefix, + _mesa_lookup_enum_by_nr(*target)); + return false; + } + + if (*target == GL_RENDERBUFFER) { + rb = _mesa_lookup_renderbuffer(ctx, name); + if (!rb) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sName = %u)", dbg_prefix, name); + return false; + } + + if (!rb->Name) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyImageSubData(%sName incomplete)", dbg_prefix); + return false; + } + + if (level != 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sLevel = %u)", dbg_prefix, level); + return false; + } + + if (rb->NumSamples > 1) + *target = GL_TEXTURE_2D_MULTISAMPLE; + else + *target = GL_TEXTURE_2D; + + *tmp_tex = 0; + _mesa_GenTextures(1, tmp_tex); + if (*tmp_tex == 0) + return false; /* Error already set by GenTextures */ + + _mesa_BindTexture(*target, *tmp_tex); + *tex_obj = _mesa_lookup_texture(ctx, *tmp_tex); + *tex_image = _mesa_get_tex_image(ctx, *tex_obj, *target, 0); + + if (!ctx->Driver.BindRenderbufferTexImage(ctx, rb, *tex_image)) { + _mesa_problem(ctx, "Failed to create texture from renderbuffer"); + return false; + } + + if (ctx->Driver.FinishRenderTexture && !rb->NeedsFinishRenderTexture) { + rb->NeedsFinishRenderTexture = true; + ctx->Driver.FinishRenderTexture(ctx, rb); + } + } else { + *tex_obj = _mesa_lookup_texture(ctx, name); + if (!*tex_obj) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sName = %u)", dbg_prefix, name); + return false; + } + + _mesa_test_texobj_completeness(ctx, *tex_obj); + if (!(*tex_obj)->_BaseComplete || + (level != 0 && !(*tex_obj)->_MipmapComplete)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyImageSubData(%sName incomplete)", dbg_prefix); + return false; + } + + if ((*tex_obj)->Target != *target) { + _mesa_error(ctx, GL_INVALID_ENUM, + "glCopyImageSubData(%sTarget = %s)", dbg_prefix, + _mesa_lookup_enum_by_nr(*target)); + return false; + } + + if (level < 0 || level >= MAX_TEXTURE_LEVELS) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sLevel = %d)", dbg_prefix, level); + return false; + } + + *tex_image = _mesa_select_tex_image(ctx, *tex_obj, *target, level); + if (!*tex_image) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sLevel = %u)", dbg_prefix, level); + return false; + } + } + + return true; +} + +static bool +check_region_bounds(struct gl_context *ctx, struct gl_texture_image *tex_image, + int x, int y, int z, int width, int height, int depth, + const char *dbg_prefix) +{ + if (width < 0 || height < 0 || depth < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sWidth, %sHeight, or %sDepth is negative)", + dbg_prefix, dbg_prefix, dbg_prefix); + return false; + } + + if (x < 0 || y < 0 || z < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sX, %sY, or %sZ is negative)", + dbg_prefix, dbg_prefix, dbg_prefix); + return false; + } + + if (x + width > tex_image->Width) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sX or %sWidth exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + + switch (tex_image->TexObject->Target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_1D_ARRAY: + if (y != 0 || height != 1) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sY or %sHeight exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + default: + if (y + height > tex_image->Height) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sY or %sHeight exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + } + + switch (tex_image->TexObject->Target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_2D_MULTISAMPLE: + case GL_TEXTURE_RECTANGLE: + if (z != 0 || depth != 1) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sZ or %sDepth exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + case GL_TEXTURE_CUBE_MAP: + if (z < 0 || z + depth > 6) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sZ or %sDepth exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + case GL_TEXTURE_1D_ARRAY: + if (z < 0 || z + depth > tex_image->Height) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sZ or %sDepth exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + case GL_TEXTURE_CUBE_MAP_ARRAY: + case GL_TEXTURE_2D_ARRAY: + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: + case GL_TEXTURE_3D: + if (z < 0 || z + depth > tex_image->Depth) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(%sZ or %sDepth exceeds image bounds)", + dbg_prefix, dbg_prefix); + return false; + } + break; + } + + return true; +} + +void GLAPIENTRY +_mesa_CopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, + GLint srcX, GLint srcY, GLint srcZ, + GLuint dstName, GLenum dstTarget, GLint dstLevel, + GLint dstX, GLint dstY, GLint dstZ, + GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth) +{ + GET_CURRENT_CONTEXT(ctx); + GLuint tmpTexNames[2] = { 0, 0 }; + struct gl_texture_object *srcTexObj, *dstTexObj; + struct gl_texture_image *srcTexImage, *dstTexImage; + GLuint src_bw, src_bh, dst_bw, dst_bh; + int i, srcNewZ, dstNewZ, Bpt; + + if (MESA_VERBOSE & VERBOSE_API) + _mesa_debug(ctx, "glCopyImageSubData(%u, %s, %d, %d, %d, %d, " + "%u, %s, %d, %d, %d, %d, " + "%d, %d, %d)\n", + srcName, _mesa_lookup_enum_by_nr(srcTarget), srcLevel, + srcX, srcY, srcZ, + dstName, _mesa_lookup_enum_by_nr(dstTarget), dstLevel, + dstX, dstY, dstZ, + srcWidth, srcHeight, srcWidth); + + if (!prepare_target(ctx, srcName, &srcTarget, srcLevel, + &srcTexObj, &srcTexImage, &tmpTexNames[0], "src")) + goto cleanup; + + if (!prepare_target(ctx, dstName, &dstTarget, dstLevel, + &dstTexObj, &dstTexImage, &tmpTexNames[1], "dst")) + goto cleanup; + + _mesa_get_format_block_size(srcTexImage->TexFormat, &src_bw, &src_bh); + if ((srcX % src_bw != 0) || (srcY % src_bh != 0) || + (srcWidth % src_bw != 0) || (srcHeight % src_bh != 0)) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(unaligned src rectangle)"); + goto cleanup; + } + + _mesa_get_format_block_size(dstTexImage->TexFormat, &dst_bw, &dst_bh); + if ((dstX % dst_bw != 0) || (dstY % dst_bh != 0)) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(unaligned dst rectangle)"); + goto cleanup; + } + + /* Very simple sanity check. This is sufficient if one of the textures + * is compressed. */ + Bpt = _mesa_get_format_bytes(srcTexImage->TexFormat); + if (_mesa_get_format_bytes(dstTexImage->TexFormat) != Bpt) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyImageSubData(internalFormat mismatch)"); + goto cleanup; + } + + if (!check_region_bounds(ctx, srcTexImage, srcX, srcY, srcZ, + srcWidth, srcHeight, srcDepth, "src")) + goto cleanup; + + if (!check_region_bounds(ctx, dstTexImage, dstX, dstY, dstZ, + (srcWidth / src_bw) * dst_bw, + (srcHeight / src_bh) * dst_bh, srcDepth, "dst")) + goto cleanup; + + if (_mesa_is_format_compressed(srcTexImage->TexFormat)) { + /* XXX: Technically, we should probaby do some more specific checking + * here. However, this should be sufficient for all compressed + * formats that mesa supports since it is a direct memory copy. + */ + } else if (_mesa_is_format_compressed(dstTexImage->TexFormat)) { + } else if (_mesa_texture_view_compatible_format(ctx, + srcTexImage->InternalFormat, + dstTexImage->InternalFormat)) { + } else { + return; /* Error loged by _mesa_texture_view_compatible_format */ + } + + for (i = 0; i < srcDepth; ++i) { + if (srcTexObj->Target == GL_TEXTURE_CUBE_MAP) { + srcTexImage = srcTexObj->Image[i + srcZ][srcLevel]; + srcNewZ = 0; + } else { + srcNewZ = srcZ + i; + } + + if (dstTexObj->Target == GL_TEXTURE_CUBE_MAP) { + dstTexImage = dstTexObj->Image[i + dstZ][dstLevel]; + dstNewZ = 0; + } else { + dstNewZ = dstZ + i; + } + + ctx->Driver.CopyImageSubData(ctx, srcTexImage, srcX, srcY, srcNewZ, + dstTexImage, dstX, dstY, dstNewZ, + srcWidth, srcHeight); + } + +cleanup: + _mesa_DeleteTextures(2, tmpTexNames); +} diff --git a/mesalib/src/mesa/main/copyimage.h b/mesalib/src/mesa/main/copyimage.h new file mode 100644 index 000000000..40e95b663 --- /dev/null +++ b/mesalib/src/mesa/main/copyimage.h @@ -0,0 +1,49 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2014 Intel Corporation. All Rights Reserved. + * + * 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 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: + * Jason Ekstrand <jason.ekstrand@intel.com> + */ + + +#ifndef COPYIMAGE_H +#define COPYIMAGE_H + +#include "mtypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void GLAPIENTRY +_mesa_CopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, + GLint srcX, GLint srcY, GLint srcZ, + GLuint destName, GLenum destTarget, GLint destLevel, + GLint destX, GLint destY, GLint destZ, + GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); + +#ifdef __cplusplus +} +#endif + +#endif /* COPYIMAGE_H */ diff --git a/mesalib/src/mesa/main/dd.h b/mesalib/src/mesa/main/dd.h index 89765351e..c130b14a5 100644 --- a/mesalib/src/mesa/main/dd.h +++ b/mesalib/src/mesa/main/dd.h @@ -269,6 +269,22 @@ struct dd_function_table { GLsizei width, GLsizei height); /** + * Called by glCopyImageSubData(). + * + * This function should copy one 2-D slice from srcTexImage to + * dstTexImage. If one of the textures is 3-D or is a 1-D or 2-D array + * texture, this function will be called multiple times: once for each + * slice. If one of the textures is a cube map, this function will be + * called once for each face to be copied. + */ + void (*CopyImageSubData)(struct gl_context *ctx, + struct gl_texture_image *src_image, + int src_x, int src_y, int src_z, + struct gl_texture_image *dstTexImage, + int dst_x, int dst_y, int dst_z, + int src_width, int src_height); + + /** * Called by glGenerateMipmap() or when GL_GENERATE_MIPMAP_SGIS is enabled. * Note that if the texture is a cube map, the <target> parameter will * indicate which cube face to generate (GL_POSITIVE/NEGATIVE_X/Y/Z). diff --git a/mesalib/src/mesa/main/enable.c b/mesalib/src/mesa/main/enable.c index 0f3bcf0a9..417548a3c 100644 --- a/mesalib/src/mesa/main/enable.c +++ b/mesalib/src/mesa/main/enable.c @@ -313,7 +313,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state) } } break; - case GL_CLIP_DISTANCE0: + case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */ case GL_CLIP_DISTANCE1: case GL_CLIP_DISTANCE2: case GL_CLIP_DISTANCE3: @@ -1202,7 +1202,7 @@ _mesa_IsEnabled( GLenum cap ) return ctx->Eval.AutoNormal; case GL_BLEND: return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */ - case GL_CLIP_DISTANCE0: + case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */ case GL_CLIP_DISTANCE1: case GL_CLIP_DISTANCE2: case GL_CLIP_DISTANCE3: diff --git a/mesalib/src/mesa/main/errors.c b/mesalib/src/mesa/main/errors.c index aa0ff50ac..9cde1e020 100644 --- a/mesalib/src/mesa/main/errors.c +++ b/mesalib/src/mesa/main/errors.c @@ -36,7 +36,7 @@ #include "hash.h" #include "mtypes.h" #include "version.h" -#include "hash_table.h" +#include "util/hash_table.h" static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP; static GLuint NextDynamicID = 1; diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index 9ac8377a4..d60838a1c 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -95,6 +95,7 @@ static const struct extension extension_table[] = { { "GL_ARB_compressed_texture_pixel_storage", o(dummy_true), GL, 2011 }, { "GL_ARB_compute_shader", o(ARB_compute_shader), GL, 2012 }, { "GL_ARB_copy_buffer", o(dummy_true), GL, 2008 }, + { "GL_ARB_copy_image", o(ARB_copy_image), GL, 2012 }, { "GL_ARB_conservative_depth", o(ARB_conservative_depth), GL, 2011 }, { "GL_ARB_debug_output", o(dummy_true), GL, 2009 }, { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL, 2008 }, diff --git a/mesalib/src/mesa/main/format_info.py b/mesalib/src/mesa/main/format_info.py new file mode 100644 index 000000000..448bd0055 --- /dev/null +++ b/mesalib/src/mesa/main/format_info.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python +# +# Copyright 2014 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, sub license, 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 NON-INFRINGEMENT. +# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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. + +import format_parser as parser +import sys + +def get_gl_base_format(fmat): + if fmat.name == 'MESA_FORMAT_NONE': + return 'GL_NONE' + elif fmat.name in ['MESA_FORMAT_YCBCR', 'MESA_FORMAT_YCBCR_REV']: + return 'GL_YCBCR_MESA' + elif fmat.has_channel('r'): + if fmat.has_channel('g'): + if fmat.has_channel('b'): + if fmat.has_channel('a'): + return 'GL_RGBA' + else: + return 'GL_RGB' + else: + return 'GL_RG' + else: + return 'GL_RED' + elif fmat.has_channel('l'): + if fmat.has_channel('a'): + return 'GL_LUMINANCE_ALPHA' + else: + return 'GL_LUMINANCE' + elif fmat.has_channel('a') and fmat.num_channels() == 1: + return 'GL_ALPHA' + elif fmat.has_channel('z'): + if fmat.has_channel('s'): + return 'GL_DEPTH_STENCIL' + else: + return 'GL_DEPTH_COMPONENT' + elif fmat.has_channel('s'): + return 'GL_STENCIL_INDEX' + elif fmat.has_channel('i') and fmat.num_channels() == 1: + return 'GL_INTENSITY' + else: + assert False + +def get_gl_data_type(fmat): + if fmat.is_compressed(): + if 'SIGNED' in fmat.name or 'SNORM' in fmat.name: + return 'GL_SIGNED_NORMALIZED' + else: + return 'GL_UNSIGNED_NORMALIZED' + elif fmat.name in ['MESA_FORMAT_YCBCR', 'MESA_FORMAT_YCBCR_REV']: + return 'GL_UNSIGNED_NORMALIZED' + + channel = None + for chan in fmat.channels: + if chan.type == 'x' and len(fmat.channels) > 1: + continue # We can do better + elif chan.name == 's' and fmat.has_channel('z'): + continue # We'll use the type from the depth instead + + channel = chan + break; + + if channel.type == parser.UNSIGNED: + if channel.norm: + return 'GL_UNSIGNED_NORMALIZED' + else: + return 'GL_UNSIGNED_INT' + elif channel.type == parser.SIGNED: + if channel.norm: + return 'GL_SIGNED_NORMALIZED' + else: + return 'GL_INT' + elif channel.type == parser.FLOAT: + return 'GL_FLOAT' + elif channel.type == parser.VOID: + return 'GL_NONE' + else: + assert False + +def get_mesa_layout(fmat): + if fmat.layout == 'array': + return 'MESA_FORMAT_LAYOUT_ARRAY' + elif fmat.layout == 'packed': + return 'MESA_FORMAT_LAYOUT_PACKED' + else: + return 'MESA_FORMAT_LAYOUT_OTHER' + +def get_channel_bits(fmat, chan_name): + if fmat.is_compressed(): + # These values are pretty-much bogus, but OpenGL requires that we + # return an "approximate" number of bits. + if fmat.layout == 's3tc': + return 4 if fmat.has_channel(chan_name) else 0 + elif fmat.layout == 'fxt1': + if chan_name in 'rgb': + return 4 + elif chan_name == 'a': + return 1 if fmat.has_channel('a') else 0 + else: + return 0 + elif fmat.layout == 'rgtc': + return 8 if fmat.has_channel(chan_name) else 0 + elif fmat.layout in ('etc1', 'etc2'): + if fmat.name.endswith('_ALPHA1') and chan_name == 'a': + return 1 + + bits = 11 if fmat.name.endswith('11_EAC') else 8 + return bits if fmat.has_channel(chan_name) else 0 + else: + assert False + else: + # Uncompressed textures + for chan in fmat.channels: + if chan.name == chan_name: + return chan.size + return 0 + +formats = parser.parse(sys.argv[1]) + +print ''' +/* + * Mesa 3-D graphics library + * + * Copyright (c) 2014 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 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. + */ + + /* + * This file is AUTOGENERATED by format_info.py. Do not edit it + * manually or commit it into version control. + */ + +static struct gl_format_info format_info[MESA_FORMAT_COUNT] = +{ +''' + +for fmat in formats: + print ' {' + print ' {0},'.format(fmat.name) + print ' "{0}",'.format(fmat.name) + print ' {0},'.format(get_mesa_layout(fmat)) + print ' {0},'.format(get_gl_base_format(fmat)) + print ' {0},'.format(get_gl_data_type(fmat)) + + bits = [ get_channel_bits(fmat, name) for name in ['r', 'g', 'b', 'a']] + print ' {0},'.format(', '.join(map(str, bits))) + bits = [ get_channel_bits(fmat, name) for name in ['l', 'i', 'z', 's']] + print ' {0},'.format(', '.join(map(str, bits))) + + print ' {0}, {1}, {2},'.format(fmat.block_width, fmat.block_height, + int(fmat.block_size() / 8)) + + print ' {{ {0} }},'.format(', '.join(map(str, fmat.swizzle))) + print ' },' + +print '};' diff --git a/mesalib/src/mesa/main/format_pack.c b/mesalib/src/mesa/main/format_pack.c index c97c05297..6cbf8593b 100644 --- a/mesalib/src/mesa/main/format_pack.c +++ b/mesalib/src/mesa/main/format_pack.c @@ -41,6 +41,7 @@ #include "macros.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" +#include "util/format_srgb.h" /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */ @@ -58,39 +59,6 @@ typedef void (*pack_float_rgba_row_func)(GLuint n, const GLfloat src[][4], void *dst); - -static inline GLfloat -linear_to_srgb(GLfloat cl) -{ - if (cl < 0.0f) - return 0.0f; - else if (cl < 0.0031308f) - return 12.92f * cl; - else if (cl < 1.0f) - return 1.055f * powf(cl, 0.41666f) - 0.055f; - else - return 1.0f; -} - - -static inline GLubyte -linear_float_to_srgb_ubyte(GLfloat cl) -{ - GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl)); - return res; -} - - -static inline GLubyte -linear_ubyte_to_srgb_ubyte(GLubyte cl) -{ - GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl / 255.0f)); - return res; -} - - - - /* * MESA_FORMAT_A8B8G8R8_UNORM */ @@ -1043,18 +1011,18 @@ static void pack_ubyte_BGR_SRGB8(const GLubyte src[4], void *dst) { GLubyte *d = ((GLubyte *) dst); - d[2] = linear_ubyte_to_srgb_ubyte(src[RCOMP]); - d[1] = linear_ubyte_to_srgb_ubyte(src[GCOMP]); - d[0] = linear_ubyte_to_srgb_ubyte(src[BCOMP]); + d[2] = util_format_linear_to_srgb_8unorm(src[RCOMP]); + d[1] = util_format_linear_to_srgb_8unorm(src[GCOMP]); + d[0] = util_format_linear_to_srgb_8unorm(src[BCOMP]); } static void pack_float_BGR_SRGB8(const GLfloat src[4], void *dst) { GLubyte *d = ((GLubyte *) dst); - d[2] = linear_float_to_srgb_ubyte(src[RCOMP]); - d[1] = linear_float_to_srgb_ubyte(src[GCOMP]); - d[0] = linear_float_to_srgb_ubyte(src[BCOMP]); + d[2] = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + d[1] = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + d[0] = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); } @@ -1064,9 +1032,9 @@ static void pack_ubyte_A8B8G8R8_SRGB(const GLubyte src[4], void *dst) { GLuint *d = ((GLuint *) dst); - GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]); - GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]); - GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]); + GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]); + GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]); + GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]); *d = PACK_COLOR_8888(r, g, b, src[ACOMP]); } @@ -1075,9 +1043,9 @@ pack_float_A8B8G8R8_SRGB(const GLfloat src[4], void *dst) { GLuint *d = ((GLuint *) dst); GLubyte r, g, b, a; - r = linear_float_to_srgb_ubyte(src[RCOMP]); - g = linear_float_to_srgb_ubyte(src[GCOMP]); - b = linear_float_to_srgb_ubyte(src[BCOMP]); + r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]); *d = PACK_COLOR_8888(r, g, b, a); } @@ -1089,9 +1057,9 @@ static void pack_ubyte_B8G8R8A8_SRGB(const GLubyte src[4], void *dst) { GLuint *d = ((GLuint *) dst); - GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]); - GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]); - GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]); + GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]); + GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]); + GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]); *d = PACK_COLOR_8888(src[ACOMP], r, g, b); } @@ -1100,9 +1068,9 @@ pack_float_B8G8R8A8_SRGB(const GLfloat src[4], void *dst) { GLuint *d = ((GLuint *) dst); GLubyte r, g, b, a; - r = linear_float_to_srgb_ubyte(src[RCOMP]); - g = linear_float_to_srgb_ubyte(src[GCOMP]); - b = linear_float_to_srgb_ubyte(src[BCOMP]); + r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]); *d = PACK_COLOR_8888(a, r, g, b); } @@ -1114,9 +1082,9 @@ static void pack_ubyte_R8G8B8A8_SRGB(const GLubyte src[4], void *dst) { GLuint *d = ((GLuint *) dst); - GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]); - GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]); - GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]); + GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]); + GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]); + GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]); *d = PACK_COLOR_8888(src[ACOMP], b, g, r); } @@ -1125,9 +1093,9 @@ pack_float_R8G8B8A8_SRGB(const GLfloat src[4], void *dst) { GLuint *d = ((GLuint *) dst); GLubyte r, g, b, a; - r = linear_float_to_srgb_ubyte(src[RCOMP]); - g = linear_float_to_srgb_ubyte(src[GCOMP]); - b = linear_float_to_srgb_ubyte(src[BCOMP]); + r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]); *d = PACK_COLOR_8888(a, b, g, r); } @@ -1139,14 +1107,14 @@ static void pack_ubyte_L_SRGB8(const GLubyte src[4], void *dst) { GLubyte *d = ((GLubyte *) dst); - *d = linear_ubyte_to_srgb_ubyte(src[RCOMP]); + *d = util_format_linear_to_srgb_8unorm(src[RCOMP]); } static void pack_float_L_SRGB8(const GLfloat src[4], void *dst) { GLubyte *d = ((GLubyte *) dst); - GLubyte l = linear_float_to_srgb_ubyte(src[RCOMP]); + GLubyte l = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); *d = l; } @@ -1157,7 +1125,7 @@ static void pack_ubyte_L8A8_SRGB(const GLubyte src[4], void *dst) { GLushort *d = ((GLushort *) dst); - GLubyte l = linear_ubyte_to_srgb_ubyte(src[RCOMP]); + GLubyte l = util_format_linear_to_srgb_8unorm(src[RCOMP]); *d = PACK_COLOR_88(src[ACOMP], l); } @@ -1165,7 +1133,7 @@ static void pack_float_L8A8_SRGB(const GLfloat src[4], void *dst) { GLushort *d = ((GLushort *) dst); - GLubyte a, l = linear_float_to_srgb_ubyte(src[RCOMP]); + GLubyte a, l = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); CLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]); *d = PACK_COLOR_88(a, l); } @@ -1742,9 +1710,9 @@ static void pack_float_R8G8B8X8_SRGB(const GLfloat src[4], void *dst) { GLuint *d = (GLuint *) dst; - GLubyte r = linear_float_to_srgb_ubyte(src[RCOMP]); - GLubyte g = linear_float_to_srgb_ubyte(src[GCOMP]); - GLubyte b = linear_float_to_srgb_ubyte(src[BCOMP]); + GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); *d = PACK_COLOR_8888(127, b, g, r); } @@ -1892,9 +1860,9 @@ static void pack_float_B8G8R8X8_SRGB(const GLfloat src[4], void *dst) { GLuint *d = (GLuint *) dst; - GLubyte r = linear_float_to_srgb_ubyte(src[RCOMP]); - GLubyte g = linear_float_to_srgb_ubyte(src[GCOMP]); - GLubyte b = linear_float_to_srgb_ubyte(src[BCOMP]); + GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]); + GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]); + GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]); *d = PACK_COLOR_8888(127, r, g, b); } diff --git a/mesalib/src/mesa/main/format_parser.py b/mesalib/src/mesa/main/format_parser.py new file mode 100644 index 000000000..5e45c74de --- /dev/null +++ b/mesalib/src/mesa/main/format_parser.py @@ -0,0 +1,521 @@ +#!/usr/bin/env python +# +# Copyright 2009 VMware, Inc. +# Copyright 2014 Intel Corporation +# All Rights Reserved. +# +# 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, sub license, 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 NON-INFRINGEMENT. +# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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. + +VOID = 'x' +UNSIGNED = 'u' +SIGNED = 's' +FLOAT = 'f' + +ARRAY = 'array' +PACKED = 'packed' +OTHER = 'other' + +RGB = 'rgb' +SRGB = 'srgb' +YUV = 'yuv' +ZS = 'zs' + +def is_power_of_two(x): + return not bool(x & (x - 1)) + +VERY_LARGE = 99999999999999999999999 + +class Channel: + """Describes a color channel.""" + + def __init__(self, type, norm, size): + self.type = type + self.norm = norm + self.size = size + self.sign = type in (SIGNED, FLOAT) + self.name = None # Set when the channels are added to the format + self.shift = -1 # Set when the channels are added to the format + self.index = -1 # Set when the channels are added to the format + + def __str__(self): + s = str(self.type) + if self.norm: + s += 'n' + s += str(self.size) + return s + + def __eq__(self, other): + return self.type == other.type and self.norm == other.norm and self.size == other.size + + def max(self): + """Returns the maximum representable number.""" + if self.type == FLOAT: + return VERY_LARGE + if self.norm: + return 1 + if self.type == UNSIGNED: + return (1 << self.size) - 1 + if self.type == SIGNED: + return (1 << (self.size - 1)) - 1 + assert False + + def min(self): + """Returns the minimum representable number.""" + if self.type == FLOAT: + return -VERY_LARGE + if self.type == UNSIGNED: + return 0 + if self.norm: + return -1 + if self.type == SIGNED: + return -(1 << (self.size - 1)) + assert False + + def one(self): + """Returns the value that represents 1.0f.""" + if self.type == UNSIGNED: + return (1 << self.size) - 1 + if self.type == SIGNED: + return (1 << (self.size - 1)) - 1 + else: + return 1 + + def is_power_of_two(self): + """Returns true if the size of this channel is a power of two.""" + return is_power_of_two(self.size) + +class Swizzle: + """Describes a swizzle operation. + + A Swizzle is a mapping from one set of channels in one format to the + channels in another. Each channel in the destination format is + associated with one of the following constants: + + * SWIZZLE_X: The first channel in the source format + * SWIZZLE_Y: The second channel in the source format + * SWIZZLE_Z: The third channel in the source format + * SWIZZLE_W: The fourth channel in the source format + * SWIZZLE_ZERO: The numeric constant 0 + * SWIZZLE_ONE: THe numeric constant 1 + * SWIZZLE_NONE: No data available for this channel + + Sometimes a Swizzle is represented by a 4-character string. In this + case, the source channels are represented by the characters "x", "y", + "z", and "w"; the numeric constants are represented as "0" and "1"; and + no mapping is represented by "_". For instance, the map from + luminance-alpha to rgba is given by "xxxy" because each of the three rgb + channels maps to the first luminance-alpha channel and the alpha channel + maps to second luminance-alpha channel. The mapping from bgr to rgba is + given by "zyx1" because the first three colors are reversed and alpha is + always 1. + """ + + __identity_str = 'xyzw01_' + + SWIZZLE_X = 0 + SWIZZLE_Y = 1 + SWIZZLE_Z = 2 + SWIZZLE_W = 3 + SWIZZLE_ZERO = 4 + SWIZZLE_ONE = 5 + SWIZZLE_NONE = 6 + + def __init__(self, swizzle): + """Creates a Swizzle object from a string or array.""" + if isinstance(swizzle, str): + swizzle = [Swizzle.__identity_str.index(c) for c in swizzle] + else: + swizzle = list(swizzle) + for s in swizzle: + assert isinstance(s, int) and 0 <= s and s <= Swizzle.SWIZZLE_NONE + + assert len(swizzle) <= 4 + + self.__list = swizzle + [Swizzle.SWIZZLE_NONE] * (4 - len(swizzle)) + assert len(self.__list) == 4 + + def __iter__(self): + """Returns an iterator that iterates over this Swizzle. + + The values that the iterator produces are described by the SWIZZLE_* + constants. + """ + return self.__list.__iter__() + + def __str__(self): + """Returns a string representation of this Swizzle.""" + return ''.join(Swizzle.__identity_str[i] for i in self.__list) + + def __getitem__(self, idx): + """Returns the SWIZZLE_* constant for the given destination channel. + + Valid values for the destination channel include any of the SWIZZLE_* + constants or any of the following single-character strings: "x", "y", + "z", "w", "r", "g", "b", "a", "z" "s". + """ + + if isinstance(idx, int): + assert idx >= Swizzle.SWIZZLE_X and idx <= Swizzle.SWIZZLE_NONE + if idx <= Swizzle.SWIZZLE_W: + return self.__list.__getitem__(idx) + else: + return idx + elif isinstance(idx, str): + if idx in 'xyzw': + idx = 'xyzw'.find(idx) + elif idx in 'rgba': + idx = 'rgba'.find(idx) + elif idx in 'zs': + idx = 'zs'.find(idx) + else: + assert False + return self.__list.__getitem__(idx) + else: + assert False + + def __mul__(self, other): + """Returns the composition of this Swizzle with another Swizzle. + + The resulting swizzle is such that, for any valid input to + __getitem__, (a * b)[i] = a[b[i]]. + """ + assert isinstance(other, Swizzle) + return Swizzle(self[x] for x in other) + + def inverse(self): + """Returns a pseudo-inverse of this swizzle. + + Since swizzling isn't necisaraly a bijection, a Swizzle can never + be truely inverted. However, the swizzle returned is *almost* the + inverse of this swizzle in the sense that, for each i in range(3), + a[a.inverse()[i]] is either i or SWIZZLE_NONE. If swizzle is just + a permutation with no channels added or removed, then this + function returns the actual inverse. + + This "pseudo-inverse" idea can be demonstrated by mapping from + luminance-alpha to rgba that is given by "xxxy". To get from rgba + to lumanence-alpha, we use Swizzle("xxxy").inverse() or "xw__". + This maps the first component in the lumanence-alpha texture is + the red component of the rgba image and the second to the alpha + component, exactly as you would expect. + """ + rev = [Swizzle.SWIZZLE_NONE] * 4 + for i in xrange(4): + for j in xrange(4): + if self.__list[j] == i and rev[i] == Swizzle.SWIZZLE_NONE: + rev[i] = j + return Swizzle(rev) + + +class Format: + """Describes a pixel format.""" + + def __init__(self, name, layout, block_width, block_height, channels, swizzle, colorspace): + """Constructs a Format from some metadata and a list of channels. + + The channel objects must be unique to this Format and should not be + re-used to construct another Format. This is because certain channel + information such as shift, offset, and the channel name are set when + the Format is created and are calculated based on the entire list of + channels. + + Arguments: + name -- Name of the format such as 'MESA_FORMAT_A8R8G8B8' + layout -- One of 'array', 'packed' 'other', or a compressed layout + block_width -- The block width if the format is compressed, 1 otherwise + block_height -- The block height if the format is compressed, 1 otherwise + channels -- A list of Channel objects + swizzle -- A Swizzle from this format to rgba + colorspace -- one of 'rgb', 'srgb', 'yuv', or 'zs' + """ + self.name = name + self.layout = layout + self.block_width = block_width + self.block_height = block_height + self.channels = channels + assert isinstance(swizzle, Swizzle) + self.swizzle = swizzle + self.name = name + assert colorspace in (RGB, SRGB, YUV, ZS) + self.colorspace = colorspace + + # Name the channels + chan_names = ['']*4 + if self.colorspace in (RGB, SRGB): + for (i, s) in enumerate(swizzle): + if s < 4: + chan_names[s] += 'rgba'[i] + elif colorspace == ZS: + for (i, s) in enumerate(swizzle): + if s < 4: + chan_names[s] += 'zs'[i] + else: + chan_names = ['x', 'y', 'z', 'w'] + + for c, name in zip(self.channels, chan_names): + assert c.name is None + if name == 'rgb': + c.name = 'l' + elif name == 'rgba': + c.name = 'i' + elif name == '': + c.name = 'x' + else: + c.name = name + + # Set indices and offsets + if self.layout == PACKED: + shift = 0 + for channel in self.channels: + assert channel.shift == -1 + channel.shift = shift + shift += channel.size + for idx, channel in enumerate(self.channels): + assert channel.index == -1 + channel.index = idx + else: + pass # Shift means nothing here + + def __str__(self): + return self.name + + def short_name(self): + """Returns a short name for a format. + + The short name should be suitable to be used as suffix in function + names. + """ + + name = self.name + if name.startswith('MESA_FORMAT_'): + name = name[len('MESA_FORMAT_'):] + name = name.lower() + return name + + def block_size(self): + """Returns the block size (in bits) of the format.""" + size = 0 + for channel in self.channels: + size += channel.size + return size + + def num_channels(self): + """Returns the number of channels in the format.""" + nr_channels = 0 + for channel in self.channels: + if channel.size: + nr_channels += 1 + return nr_channels + + def array_element(self): + """Returns a non-void channel if this format is an array, otherwise None. + + If the returned channel is not None, then this format can be + considered to be an array of num_channels() channels identical to the + returned channel. + """ + if self.layout == ARRAY: + return self.channels[0] + elif self.layout == PACKED: + ref_channel = self.channels[0] + if ref_channel.type == VOID: + ref_channel = self.channels[1] + for channel in self.channels: + if channel.size == 0 or channel.type == VOID: + continue + if channel.size != ref_channel.size or channel.size % 8 != 0: + return None + if channel.type != ref_channel.type: + return None + if channel.norm != ref_channel.norm: + return None + return ref_channel + else: + return None + + def is_array(self): + """Returns true if this format can be considered an array format. + + This function will return true if self.layout == 'array'. However, + some formats, such as MESA_FORMAT_A8G8B8R8, can be considered as + array formats even though they are technically packed. + """ + return self.array_element() != None + + def is_compressed(self): + """Returns true if this is a compressed format.""" + return self.block_width != 1 or self.block_height != 1 + + def is_int(self): + """Returns true if this format is an integer format. + + See also: is_norm() + """ + if self.layout not in (ARRAY, PACKED): + return False + for channel in self.channels: + if channel.type not in (VOID, UNSIGNED, SIGNED): + return False + return True + + def is_float(self): + """Returns true if this format is an floating-point format.""" + if self.layout not in (ARRAY, PACKED): + return False + for channel in self.channels: + if channel.type not in (VOID, FLOAT): + return False + return True + + def channel_type(self): + """Returns the type of the channels in this format.""" + _type = VOID + for c in self.channels: + if c.type == VOID: + continue + if _type == VOID: + _type = c.type + assert c.type == _type + return _type + + def channel_size(self): + """Returns the size (in bits) of the channels in this format. + + This function should only be called if all of the channels have the + same size. This is always the case if is_array() returns true. + """ + size = None + for c in self.channels: + if c.type == VOID: + continue + if size is None: + size = c.size + assert c.size == size + return size + + def max_channel_size(self): + """Returns the size of the largest channel.""" + size = 0 + for c in self.channels: + if c.type == VOID: + continue + size = max(size, c.size) + return size + + def is_normalized(self): + """Returns true if this format is normalized. + + While only integer formats can be normalized, not all integer formats + are normalized. Normalized integer formats are those where the + integer value is re-interpreted as a fixed point value in the range + [0, 1]. + """ + norm = None + for c in self.channels: + if c.type == VOID: + continue + if norm is None: + norm = c.norm + assert c.norm == norm + return norm + + def has_channel(self, name): + """Returns true if this format has the given channel.""" + if self.is_compressed(): + # Compressed formats are a bit tricky because the list of channels + # contains a single channel of type void. Since we don't have any + # channel information there, we pull it from the swizzle. + if str(self.swizzle) == 'xxxx': + return name == 'i' + elif str(self.swizzle)[0:3] in ('xxx', 'yyy'): + if name == 'l': + return True + elif name == 'a': + return self.swizzle['a'] <= Swizzle.SWIZZLE_W + else: + return False + elif name in 'rgba': + return self.swizzle[name] <= Swizzle.SWIZZLE_W + else: + return False + else: + for channel in self.channels: + if channel.name == name: + return True + return False + + def get_channel(self, name): + """Returns the channel with the given name if it exists.""" + for channel in self.channels: + if channel.name == name: + return channel + return None + +def _parse_channels(fields, layout, colorspace, swizzle): + channels = [] + for field in fields: + if not field: + continue + + type = field[0] if field[0] else 'x' + + if field[1] == 'n': + norm = True + size = int(field[2:]) + else: + norm = False + size = int(field[1:]) + + channel = Channel(type, norm, size) + channels.append(channel) + + return channels + +def parse(filename): + """Parse a format descrition in CSV format. + + This function parses the given CSV file and returns an iterable of + channels.""" + + with open(filename) as stream: + for line in stream: + try: + comment = line.index('#') + except ValueError: + pass + else: + line = line[:comment] + line = line.strip() + if not line: + continue + + fields = [field.strip() for field in line.split(',')] + + name = fields[0] + layout = fields[1] + block_width = int(fields[2]) + block_height = int(fields[3]) + colorspace = fields[9] + + swizzle = Swizzle(fields[8]) + channels = _parse_channels(fields[4:8], layout, colorspace, swizzle) + + yield Format(name, layout, block_width, block_height, channels, swizzle, colorspace) diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c index ad5ea4cd1..b84ed0248 100644 --- a/mesalib/src/mesa/main/format_unpack.c +++ b/mesalib/src/mesa/main/format_unpack.c @@ -28,6 +28,7 @@ #include "macros.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" +#include "util/format_srgb.h" /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */ @@ -53,34 +54,6 @@ struct z32f_x24s8 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) ) -/** - * 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. - */ -GLfloat -_mesa_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]; -} - - /**********************************************************************/ /* Unpack, returning GLfloat colors */ /**********************************************************************/ @@ -763,9 +736,9 @@ unpack_BGR_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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+2]); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+1]); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+0]); dst[i][ACOMP] = 1.0F; } } @@ -776,9 +749,9 @@ unpack_A8B8G8R8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) ); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */ } } @@ -789,9 +762,9 @@ unpack_B8G8R8A8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ } } @@ -802,9 +775,9 @@ unpack_R8G8B8A8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff ); - dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); - dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff ); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ } } @@ -817,7 +790,7 @@ unpack_L_SRGB8(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i]); dst[i][ACOMP] = 1.0F; } } @@ -830,7 +803,7 @@ unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] & 0xff); dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */ } } @@ -2124,9 +2097,9 @@ unpack_R8G8B8X8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff ); - dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); - dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff ); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ } } @@ -2319,9 +2292,9 @@ unpack_B8G8R8X8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff ); dst[i][ACOMP] = 1.0F; } } diff --git a/mesalib/src/mesa/main/format_unpack.h b/mesalib/src/mesa/main/format_unpack.h index 51f97df4d..eba3c6650 100644 --- a/mesalib/src/mesa/main/format_unpack.h +++ b/mesalib/src/mesa/main/format_unpack.h @@ -25,9 +25,6 @@ #ifndef FORMAT_UNPACK_H #define FORMAT_UNPACK_H -extern GLfloat -_mesa_nonlinear_to_linear(GLubyte cs8); - extern void _mesa_unpack_rgba_row(mesa_format format, GLuint n, const void *src, GLfloat dst[][4]); diff --git a/mesalib/src/mesa/main/format_utils.c b/mesalib/src/mesa/main/format_utils.c new file mode 100644 index 000000000..240e3bc0c --- /dev/null +++ b/mesalib/src/mesa/main/format_utils.c @@ -0,0 +1,977 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2014 Intel Corporation All Rights Reserved. + * + * 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 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. + */ + +#include "format_utils.h" +#include "glformats.h" + +static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 }; +static const uint8_t map_3210[7] = { 3, 2, 1, 0, 4, 5, 6 }; +static const uint8_t map_1032[7] = { 1, 0, 3, 2, 4, 5, 6 }; + +/** + * Describes a format as an array format, if possible + * + * A helper function for figuring out if a (possibly packed) format is + * actually an array format and, if so, what the array parameters are. + * + * \param[in] format the mesa format + * \param[out] type the GL type of the array (GL_BYTE, etc.) + * \param[out] num_components the number of components in the array + * \param[out] swizzle a swizzle describing how to get from the + * given format to RGBA + * \param[out] normalized for integer formats, this represents whether + * the format is a normalized integer or a + * regular integer + * \return true if this format is an array format, false otherwise + */ +bool +_mesa_format_to_array(mesa_format format, GLenum *type, int *num_components, + uint8_t swizzle[4], bool *normalized) +{ + int i; + GLuint format_components; + uint8_t packed_swizzle[4]; + const uint8_t *endian; + + if (_mesa_is_format_compressed(format)) + return false; + + *normalized = !_mesa_is_format_integer(format); + + _mesa_format_to_type_and_comps(format, type, &format_components); + + switch (_mesa_get_format_layout(format)) { + case MESA_FORMAT_LAYOUT_ARRAY: + *num_components = format_components; + _mesa_get_format_swizzle(format, swizzle); + return true; + case MESA_FORMAT_LAYOUT_PACKED: + switch (*type) { + case GL_UNSIGNED_BYTE: + case GL_BYTE: + if (_mesa_get_format_max_bits(format) != 8) + return false; + *num_components = _mesa_get_format_bytes(format); + switch (*num_components) { + case 1: + endian = map_identity; + break; + case 2: + endian = _mesa_little_endian() ? map_identity : map_1032; + break; + case 4: + endian = _mesa_little_endian() ? map_identity : map_3210; + break; + default: + endian = map_identity; + assert(!"Invalid number of components"); + } + break; + case GL_UNSIGNED_SHORT: + case GL_SHORT: + case GL_HALF_FLOAT: + if (_mesa_get_format_max_bits(format) != 16) + return false; + *num_components = _mesa_get_format_bytes(format) / 2; + switch (*num_components) { + case 1: + endian = map_identity; + break; + case 2: + endian = _mesa_little_endian() ? map_identity : map_1032; + break; + default: + endian = map_identity; + assert(!"Invalid number of components"); + } + break; + case GL_UNSIGNED_INT: + case GL_INT: + case GL_FLOAT: + /* This isn't packed. At least not really. */ + assert(format_components == 1); + if (_mesa_get_format_max_bits(format) != 32) + return false; + *num_components = format_components; + endian = map_identity; + break; + default: + return false; + } + + _mesa_get_format_swizzle(format, packed_swizzle); + + for (i = 0; i < 4; ++i) + swizzle[i] = endian[packed_swizzle[i]]; + + return true; + case MESA_FORMAT_LAYOUT_OTHER: + default: + return false; + } +} + +/* A bunch of format conversion macros and helper functions used below */ + +/* Only guaranteed to work for BITS <= 32 */ +#define MAX_UINT(BITS) ((BITS) == 32 ? UINT32_MAX : ((1u << (BITS)) - 1)) +#define MAX_INT(BITS) ((int)MAX_UINT((BITS) - 1)) + +/* Extends an integer of size SRC_BITS to one of size DST_BITS linearly */ +#define EXTEND_NORMALIZED_INT(X, SRC_BITS, DST_BITS) \ + (((X) * (int)(MAX_UINT(DST_BITS) / MAX_UINT(SRC_BITS))) + \ + ((DST_BITS % SRC_BITS) ? ((X) >> (SRC_BITS - DST_BITS % SRC_BITS)) : 0)) + +static inline float +unorm_to_float(unsigned x, unsigned src_bits) +{ + return x * (1.0f / (float)MAX_UINT(src_bits)); +} + +static inline float +snorm_to_float(int x, unsigned src_bits) +{ + if (x == -MAX_INT(src_bits)) + return -1.0f; + else + return x * (1.0f / (float)MAX_INT(src_bits)); +} + +static inline uint16_t +unorm_to_half(unsigned x, unsigned src_bits) +{ + return _mesa_float_to_half(unorm_to_float(x, src_bits)); +} + +static inline uint16_t +snorm_to_half(int x, unsigned src_bits) +{ + return _mesa_float_to_half(snorm_to_float(x, src_bits)); +} + +static inline unsigned +float_to_unorm(float x, unsigned dst_bits) +{ + if (x < 0.0f) + return 0; + else if (x > 1.0f) + return MAX_UINT(dst_bits); + else + return F_TO_I(x * MAX_UINT(dst_bits)); +} + +static inline unsigned +half_to_unorm(uint16_t x, unsigned dst_bits) +{ + return float_to_unorm(_mesa_half_to_float(x), dst_bits); +} + +static inline unsigned +unorm_to_unorm(unsigned x, unsigned src_bits, unsigned dst_bits) +{ + if (src_bits < dst_bits) + return EXTEND_NORMALIZED_INT(x, src_bits, dst_bits); + else + return x >> (src_bits - dst_bits); +} + +static inline unsigned +snorm_to_unorm(int x, unsigned src_bits, unsigned dst_bits) +{ + if (x < 0) + return 0; + else + return unorm_to_unorm(x, src_bits - 1, dst_bits); +} + +static inline int +float_to_snorm(float x, unsigned dst_bits) +{ + if (x < -1.0f) + return -MAX_INT(dst_bits); + else if (x > 1.0f) + return MAX_INT(dst_bits); + else + return F_TO_I(x * MAX_INT(dst_bits)); +} + +static inline int +half_to_snorm(uint16_t x, unsigned dst_bits) +{ + return float_to_snorm(_mesa_half_to_float(x), dst_bits); +} + +static inline int +unorm_to_snorm(unsigned x, unsigned src_bits, unsigned dst_bits) +{ + return unorm_to_unorm(x, src_bits, dst_bits - 1); +} + +static inline int +snorm_to_snorm(int x, unsigned src_bits, unsigned dst_bits) +{ + if (x < -MAX_INT(src_bits)) + return -MAX_INT(dst_bits); + else if (src_bits < dst_bits) + return EXTEND_NORMALIZED_INT(x, src_bits - 1, dst_bits - 1); + else + return x >> (src_bits - dst_bits); +} + +static inline unsigned +float_to_uint(float x) +{ + if (x < 0.0f) + return 0; + else + return x; +} + +static inline unsigned +half_to_uint(uint16_t x) +{ + if (_mesa_half_is_negative(x)) + return 0; + else + return _mesa_float_to_half(x); +} + +/** + * Attempts to perform the given swizzle-and-convert operation with memcpy + * + * This function determines if the given swizzle-and-convert operation can + * be done with a simple memcpy and, if so, does the memcpy. If not, it + * returns false and we fall back to the standard version below. + * + * The arguments are exactly the same as for _mesa_swizzle_and_convert + * + * \return true if it successfully performed the swizzle-and-convert + * operation with memcpy, false otherwise + */ +static bool +swizzle_convert_try_memcpy(void *dst, GLenum dst_type, int num_dst_channels, + const void *src, GLenum src_type, int num_src_channels, + const uint8_t swizzle[4], bool normalized, int count) +{ + int i; + + if (src_type != dst_type) + return false; + if (num_src_channels != num_dst_channels) + return false; + + for (i = 0; i < num_dst_channels; ++i) + if (swizzle[i] != i && swizzle[i] != MESA_FORMAT_SWIZZLE_NONE) + return false; + + memcpy(dst, src, count * num_src_channels * _mesa_sizeof_type(src_type)); + + return true; +} + +/** + * Represents a single instance of the standard swizzle-and-convert loop + * + * Any swizzle-and-convert operation simply loops through the pixels and + * performs the transformation operation one pixel at a time. This macro + * embodies one instance of the conversion loop. This way we can do all + * control flow outside of the loop and allow the compiler to unroll + * everything inside the loop. + * + * Note: This loop is carefully crafted for performance. Be careful when + * changing it and run some benchmarks to ensure no performance regressions + * if you do. + * + * \param DST_TYPE the C datatype of the destination + * \param DST_CHANS the number of destination channels + * \param SRC_TYPE the C datatype of the source + * \param SRC_CHANS the number of source channels + * \param CONV an expression for converting from the source data, + * storred in the variable "src", to the destination + * format + */ +#define SWIZZLE_CONVERT_LOOP(DST_TYPE, DST_CHANS, SRC_TYPE, SRC_CHANS, CONV) \ + for (s = 0; s < count; ++s) { \ + for (j = 0; j < SRC_CHANS; ++j) { \ + SRC_TYPE src = typed_src[j]; \ + tmp[j] = CONV; \ + } \ + \ + typed_dst[0] = tmp[swizzle_x]; \ + if (DST_CHANS > 1) { \ + typed_dst[1] = tmp[swizzle_y]; \ + if (DST_CHANS > 2) { \ + typed_dst[2] = tmp[swizzle_z]; \ + if (DST_CHANS > 3) { \ + typed_dst[3] = tmp[swizzle_w]; \ + } \ + } \ + } \ + typed_src += SRC_CHANS; \ + typed_dst += DST_CHANS; \ + } \ + +/** + * Represents a single swizzle-and-convert operation + * + * This macro represents everything done in a single swizzle-and-convert + * operation. The actual work is done by the SWIZZLE_CONVERT_LOOP macro. + * This macro acts as a wrapper that uses a nested switch to ensure that + * all looping parameters get unrolled. + * + * This macro makes assumptions about variables etc. in the calling + * function. Changes to _mesa_swizzle_and_convert may require changes to + * this macro. + * + * \param DST_TYPE the C datatype of the destination + * \param SRC_TYPE the C datatype of the source + * \param CONV an expression for converting from the source data, + * storred in the variable "src", to the destination + * format + */ +#define SWIZZLE_CONVERT(DST_TYPE, SRC_TYPE, CONV) \ + do { \ + const SRC_TYPE *typed_src = void_src; \ + DST_TYPE *typed_dst = void_dst; \ + DST_TYPE tmp[7]; \ + tmp[4] = 0; \ + tmp[5] = one; \ + switch (num_dst_channels) { \ + case 1: \ + switch (num_src_channels) { \ + case 1: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 1, CONV) \ + break; \ + case 2: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 2, CONV) \ + break; \ + case 3: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 3, CONV) \ + break; \ + case 4: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 4, CONV) \ + break; \ + } \ + break; \ + case 2: \ + switch (num_src_channels) { \ + case 1: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 1, CONV) \ + break; \ + case 2: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 2, CONV) \ + break; \ + case 3: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 3, CONV) \ + break; \ + case 4: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 4, CONV) \ + break; \ + } \ + break; \ + case 3: \ + switch (num_src_channels) { \ + case 1: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 1, CONV) \ + break; \ + case 2: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 2, CONV) \ + break; \ + case 3: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 3, CONV) \ + break; \ + case 4: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 4, CONV) \ + break; \ + } \ + break; \ + case 4: \ + switch (num_src_channels) { \ + case 1: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 1, CONV) \ + break; \ + case 2: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 2, CONV) \ + break; \ + case 3: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 3, CONV) \ + break; \ + case 4: \ + SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 4, CONV) \ + break; \ + } \ + break; \ + } \ + } while (0); + +/** + * Convert between array-based color formats. + * + * Most format conversion operations required by GL can be performed by + * converting one channel at a time, shuffling the channels around, and + * optionally filling missing channels with zeros and ones. This function + * does just that in a general, yet efficient, way. + * + * The swizzle parameter is an array of 4 numbers (see + * _mesa_get_format_swizzle) that describes where each channel in the + * destination should come from in the source. If swizzle[i] < 4 then it + * means that dst[i] = CONVERT(src[swizzle[i]]). If swizzle[i] is + * MESA_FORMAT_SWIZZLE_ZERO or MESA_FORMAT_SWIZZLE_ONE, the corresponding + * dst[i] will be filled with the appropreate representation of zero or one + * respectively. + * + * Under most circumstances, the source and destination images must be + * different as no care is taken not to clobber one with the other. + * However, if they have the same number of bits per pixel, it is safe to + * do an in-place conversion. + * + * \param[out] dst pointer to where the converted data should + * be stored + * + * \param[in] dst_type the destination GL type of the converted + * data (GL_BYTE, etc.) + * + * \param[in] num_dst_channels the number of channels in the converted + * data + * + * \param[in] src pointer to the source data + * + * \param[in] src_type the GL type of the source data (GL_BYTE, + * etc.) + * + * \param[in] num_src_channels the number of channels in the source data + * (the number of channels total, not just + * the number used) + * + * \param[in] swizzle describes how to get the destination data + * from the source data. + * + * \param[in] normalized for integer types, this indicates whether + * the data should be considered as integers + * or as normalized integers; + * + * \param[in] count the number of pixels to convert + */ +void +_mesa_swizzle_and_convert(void *void_dst, GLenum dst_type, int num_dst_channels, + const void *void_src, GLenum src_type, int num_src_channels, + const uint8_t swizzle[4], bool normalized, int count) +{ + int s, j; + register uint8_t swizzle_x, swizzle_y, swizzle_z, swizzle_w; + + if (swizzle_convert_try_memcpy(void_dst, dst_type, num_dst_channels, + void_src, src_type, num_src_channels, + swizzle, normalized, count)) + return; + + swizzle_x = swizzle[0]; + swizzle_y = swizzle[1]; + swizzle_z = swizzle[2]; + swizzle_w = swizzle[3]; + + switch (dst_type) { + case GL_FLOAT: + { + const float one = 1.0f; + switch (src_type) { + case GL_FLOAT: + SWIZZLE_CONVERT(float, float, src) + break; + case GL_HALF_FLOAT: + SWIZZLE_CONVERT(float, uint16_t, _mesa_half_to_float(src)) + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(float, uint8_t, unorm_to_float(src, 8)) + } else { + SWIZZLE_CONVERT(float, uint8_t, src) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(float, int8_t, snorm_to_float(src, 8)) + } else { + SWIZZLE_CONVERT(float, int8_t, src) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(float, uint16_t, unorm_to_float(src, 16)) + } else { + SWIZZLE_CONVERT(float, uint16_t, src) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(float, int16_t, snorm_to_float(src, 16)) + } else { + SWIZZLE_CONVERT(float, int16_t, src) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(float, uint32_t, unorm_to_float(src, 32)) + } else { + SWIZZLE_CONVERT(float, uint32_t, src) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(float, int32_t, snorm_to_float(src, 32)) + } else { + SWIZZLE_CONVERT(float, int32_t, src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_HALF_FLOAT: + { + const uint16_t one = _mesa_float_to_half(1.0f); + switch (src_type) { + case GL_FLOAT: + SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_half(src)) + break; + case GL_HALF_FLOAT: + SWIZZLE_CONVERT(uint16_t, uint16_t, src) + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint8_t, unorm_to_half(src, 8)) + } else { + SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_float_to_half(src)) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int8_t, snorm_to_half(src, 8)) + } else { + SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_float_to_half(src)) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint16_t, unorm_to_half(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_float_to_half(src)) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int16_t, snorm_to_half(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_float_to_half(src)) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_half(src, 32)) + } else { + SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_float_to_half(src)) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_half(src, 32)) + } else { + SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_float_to_half(src)) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_UNSIGNED_BYTE: + { + const uint8_t one = normalized ? UINT8_MAX : 1; + switch (src_type) { + case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, float, float_to_unorm(src, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, float, (src < 0) ? 0 : src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_unorm(src, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_uint(src)) + } + break; + case GL_UNSIGNED_BYTE: + SWIZZLE_CONVERT(uint8_t, uint8_t, src) + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, int8_t, snorm_to_unorm(src, 8, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, int8_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, uint16_t, unorm_to_unorm(src, 16, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, uint16_t, src) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, int16_t, snorm_to_unorm(src, 16, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, int16_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, uint32_t, unorm_to_unorm(src, 32, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, uint32_t, src) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, int32_t, snorm_to_unorm(src, 32, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, int32_t, (src < 0) ? 0 : src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_BYTE: + { + const int8_t one = normalized ? INT8_MAX : 1; + switch (src_type) { + case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, float, float_to_snorm(src, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, float, src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_snorm(src, 8)) + } else { + SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_float(src)) + } + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(int8_t, uint8_t, unorm_to_snorm(src, 8, 8)) + } else { + SWIZZLE_CONVERT(int8_t, uint8_t, src) + } + break; + case GL_BYTE: + SWIZZLE_CONVERT(int8_t, int8_t, src) + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(int8_t, uint16_t, unorm_to_snorm(src, 16, 8)) + } else { + SWIZZLE_CONVERT(int8_t, uint16_t, src) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(int8_t, int16_t, snorm_to_snorm(src, 16, 8)) + } else { + SWIZZLE_CONVERT(int8_t, int16_t, src) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(int8_t, uint32_t, unorm_to_snorm(src, 32, 8)) + } else { + SWIZZLE_CONVERT(int8_t, uint32_t, src) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(int8_t, int32_t, snorm_to_snorm(src, 32, 8)) + } else { + SWIZZLE_CONVERT(int8_t, int32_t, src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_UNSIGNED_SHORT: + { + const uint16_t one = normalized ? UINT16_MAX : 1; + switch (src_type) { + case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, float, float_to_unorm(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, float, (src < 0) ? 0 : src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_unorm(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_uint(src)) + } + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint8_t, unorm_to_unorm(src, 8, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, uint8_t, src) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int8_t, snorm_to_unorm(src, 8, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, int8_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_SHORT: + SWIZZLE_CONVERT(uint16_t, uint16_t, src) + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int16_t, snorm_to_unorm(src, 16, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, int16_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_unorm(src, 32, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, uint32_t, src) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_unorm(src, 32, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, int32_t, (src < 0) ? 0 : src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_SHORT: + { + const int16_t one = normalized ? INT16_MAX : 1; + switch (src_type) { + case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, float, float_to_snorm(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, float, src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_snorm(src, 16)) + } else { + SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_float(src)) + } + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(int16_t, uint8_t, unorm_to_snorm(src, 8, 16)) + } else { + SWIZZLE_CONVERT(int16_t, uint8_t, src) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(int16_t, int8_t, snorm_to_snorm(src, 8, 16)) + } else { + SWIZZLE_CONVERT(int16_t, int8_t, src) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(int16_t, uint16_t, unorm_to_snorm(src, 16, 16)) + } else { + SWIZZLE_CONVERT(int16_t, uint16_t, src) + } + break; + case GL_SHORT: + SWIZZLE_CONVERT(int16_t, int16_t, src) + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(int16_t, uint32_t, unorm_to_snorm(src, 32, 16)) + } else { + SWIZZLE_CONVERT(int16_t, uint32_t, src) + } + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(int16_t, int32_t, snorm_to_snorm(src, 32, 16)) + } else { + SWIZZLE_CONVERT(int16_t, int32_t, src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_UNSIGNED_INT: + { + const uint32_t one = normalized ? UINT32_MAX : 1; + switch (src_type) { case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, float, float_to_unorm(src, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, float, (src < 0) ? 0 : src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_unorm(src, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_uint(src)) + } + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, uint8_t, unorm_to_unorm(src, 8, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, uint8_t, src) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, int8_t, snorm_to_unorm(src, 8, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, int8_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, uint16_t, unorm_to_unorm(src, 16, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, uint16_t, src) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, int16_t, snorm_to_unorm(src, 16, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, int16_t, (src < 0) ? 0 : src) + } + break; + case GL_UNSIGNED_INT: + SWIZZLE_CONVERT(uint32_t, uint32_t, src) + break; + case GL_INT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, int32_t, snorm_to_unorm(src, 32, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, int32_t, (src < 0) ? 0 : src) + } + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + case GL_INT: + { + const int32_t one = normalized ? INT32_MAX : 1; + switch (src_type) { + case GL_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, float, float_to_snorm(src, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, float, src) + } + break; + case GL_HALF_FLOAT: + if (normalized) { + SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_snorm(src, 32)) + } else { + SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_float(src)) + } + break; + case GL_UNSIGNED_BYTE: + if (normalized) { + SWIZZLE_CONVERT(int32_t, uint8_t, unorm_to_snorm(src, 8, 32)) + } else { + SWIZZLE_CONVERT(int32_t, uint8_t, src) + } + break; + case GL_BYTE: + if (normalized) { + SWIZZLE_CONVERT(int32_t, int8_t, snorm_to_snorm(src, 8, 32)) + } else { + SWIZZLE_CONVERT(int32_t, int8_t, src) + } + break; + case GL_UNSIGNED_SHORT: + if (normalized) { + SWIZZLE_CONVERT(int32_t, uint16_t, unorm_to_snorm(src, 16, 32)) + } else { + SWIZZLE_CONVERT(int32_t, uint16_t, src) + } + break; + case GL_SHORT: + if (normalized) { + SWIZZLE_CONVERT(int32_t, int16_t, snorm_to_snorm(src, 16, 32)) + } else { + SWIZZLE_CONVERT(int32_t, int16_t, src) + } + break; + case GL_UNSIGNED_INT: + if (normalized) { + SWIZZLE_CONVERT(int32_t, uint32_t, unorm_to_snorm(src, 32, 32)) + } else { + SWIZZLE_CONVERT(int32_t, uint32_t, src) + } + break; + case GL_INT: + SWIZZLE_CONVERT(int32_t, int32_t, src) + break; + default: + assert(!"Invalid channel type combination"); + } + } + break; + default: + assert(!"Invalid channel type"); + } +} diff --git a/mesalib/src/mesa/main/format_utils.h b/mesalib/src/mesa/main/format_utils.h new file mode 100644 index 000000000..9f778e377 --- /dev/null +++ b/mesalib/src/mesa/main/format_utils.h @@ -0,0 +1,45 @@ +/** + * \file format_utils.h + * A collection of format conversion utility functions. + */ + +/* + * Mesa 3-D graphics library + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 2014 Intel Corporation All Rights Reserved. + * + * 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 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. + */ + +#ifndef FORMAT_UTILS_H +#define FORMAT_UTILS_H + +#include "imports.h" + +bool +_mesa_format_to_array(mesa_format, GLenum *type, int *num_components, + uint8_t swizzle[4], bool *normalized); + +void +_mesa_swizzle_and_convert(void *dst, GLenum dst_type, int num_dst_channels, + const void *src, GLenum src_type, int num_src_channels, + const uint8_t swizzle[4], bool normalized, int count); + +#endif diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c index 1f20a9a6a..f03425e41 100644 --- a/mesalib/src/mesa/main/formats.c +++ b/mesalib/src/mesa/main/formats.c @@ -40,6 +40,8 @@ struct gl_format_info /** text name for debugging */ const char *StrName; + enum mesa_format_layout Layout; + /** * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA, * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, @@ -59,7 +61,6 @@ struct gl_format_info GLubyte AlphaBits; GLubyte LuminanceBits; GLubyte IntensityBits; - GLubyte IndexBits; GLubyte DepthBits; GLubyte StencilBits; @@ -68,1745 +69,11 @@ struct gl_format_info */ GLubyte BlockWidth, BlockHeight; GLubyte BytesPerBlock; -}; - -/** - * Info about each format. - * These must be in the same order as the MESA_FORMAT_* enums so that - * we can do lookups without searching. - */ -static struct gl_format_info format_info[MESA_FORMAT_COUNT] = -{ - /* Packed unorm formats */ - { - MESA_FORMAT_NONE, /* Name */ - "MESA_FORMAT_NONE", /* StrName */ - GL_NONE, /* BaseFormat */ - GL_NONE, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 0, 0, 0 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A8B8G8R8_UNORM, /* Name */ - "MESA_FORMAT_A8B8G8R8_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_X8B8G8R8_UNORM, /* Name */ - "MESA_FORMAT_X8B8G8R8_UNORM",/* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R8G8B8A8_UNORM, /* Name */ - "MESA_FORMAT_R8G8B8A8_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R8G8B8X8_UNORM, /* Name */ - "MESA_FORMAT_R8G8B8X8_UNORM",/* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B8G8R8A8_UNORM, /* Name */ - "MESA_FORMAT_B8G8R8A8_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B8G8R8X8_UNORM, /* Name */ - "MESA_FORMAT_B8G8R8X8_UNORM",/* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A8R8G8B8_UNORM, /* Name */ - "MESA_FORMAT_A8R8G8B8_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_X8R8G8B8_UNORM, /* Name */ - "MESA_FORMAT_X8R8G8B8_UNORM",/* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_L16A16_UNORM, /* Name */ - "MESA_FORMAT_L16A16_UNORM", /* StrName */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ - 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A16L16_UNORM, /* Name */ - "MESA_FORMAT_A16L16_UNORM", /* StrName */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ - 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B5G6R5_UNORM, /* Name */ - "MESA_FORMAT_B5G6R5_UNORM", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R5G6B5_UNORM, /* Name */ - "MESA_FORMAT_R5G6B5_UNORM", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B4G4R4A4_UNORM, /* Name */ - "MESA_FORMAT_B4G4R4A4_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B4G4R4X4_UNORM, - "MESA_FORMAT_B4G4R4X4_UNORM", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_A4R4G4B4_UNORM, /* Name */ - "MESA_FORMAT_A4R4G4B4_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A1B5G5R5_UNORM, /* Name */ - "MESA_FORMAT_A1B5G5R5_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B5G5R5A1_UNORM, /* Name */ - "MESA_FORMAT_B5G5R5A1_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B5G5R5X1_UNORM, - "MESA_FORMAT_B5G5R5X1_UNORM", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 5, 5, 5, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_A1R5G5B5_UNORM, /* Name */ - "MESA_FORMAT_A1R5G5B5_UNORM",/* StrName */ - GL_RGBA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_L8A8_UNORM, /* Name */ - "MESA_FORMAT_L8A8_UNORM", /* StrName */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ - 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A8L8_UNORM, /* Name */ - "MESA_FORMAT_A8L8_UNORM", /* StrName */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ - 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R8G8_UNORM, - "MESA_FORMAT_R8G8_UNORM", - GL_RG, - GL_UNSIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_G8R8_UNORM, - "MESA_FORMAT_G8R8_UNORM", - GL_RG, - GL_UNSIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L4A4_UNORM, /* Name */ - "MESA_FORMAT_L4A4_UNORM", /* StrName */ - GL_LUMINANCE_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */ - 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_B2G3R3_UNORM, /* Name */ - "MESA_FORMAT_B2G3R3_UNORM", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R16G16_UNORM, - "MESA_FORMAT_R16G16_UNORM", - GL_RG, - GL_UNSIGNED_NORMALIZED, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_G16R16_UNORM, - "MESA_FORMAT_G16R16_UNORM", - GL_RG, - GL_UNSIGNED_NORMALIZED, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_B10G10R10A2_UNORM, - "MESA_FORMAT_B10G10R10A2_UNORM", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 10, 10, 10, 2, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_B10G10R10X2_UNORM, - "MESA_FORMAT_B10G10R10X2_UNORM", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 10, 10, 10, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R10G10B10A2_UNORM, - "MESA_FORMAT_R10G10B10A2_UNORM", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 10, 10, 10, 2, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_S8_UINT_Z24_UNORM, /* Name */ - "MESA_FORMAT_S8_UINT_Z24_UNORM", /* StrName */ - GL_DEPTH_STENCIL, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_X8_UINT_Z24_UNORM, /* Name */ - "MESA_FORMAT_X8_UINT_Z24_UNORM", /* StrName */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_Z24_UNORM_S8_UINT, /* Name */ - "MESA_FORMAT_Z24_UNORM_S8_UINT", /* StrName */ - GL_DEPTH_STENCIL, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_Z24_UNORM_X8_UINT, /* Name */ - "MESA_FORMAT_Z24_UNORM_X8_UINT", /* StrName */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_YCBCR, /* Name */ - "MESA_FORMAT_YCBCR", /* StrName */ - GL_YCBCR_MESA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_YCBCR_REV, /* Name */ - "MESA_FORMAT_YCBCR_REV", /* StrName */ - GL_YCBCR_MESA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - - /* Array unorm formats */ - { - MESA_FORMAT_A_UNORM8, /* Name */ - "MESA_FORMAT_A_UNORM8", /* StrName */ - GL_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_A_UNORM16, /* Name */ - "MESA_FORMAT_A_UNORM16", /* StrName */ - GL_ALPHA, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_L_UNORM8, /* Name */ - "MESA_FORMAT_L_UNORM8", /* StrName */ - GL_LUMINANCE, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_L_UNORM16, /* Name */ - "MESA_FORMAT_L_UNORM16", /* StrName */ - GL_LUMINANCE, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_I_UNORM8, /* Name */ - "MESA_FORMAT_I_UNORM8", /* StrName */ - GL_INTENSITY, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_I_UNORM16, /* Name */ - "MESA_FORMAT_I_UNORM16", /* StrName */ - GL_INTENSITY, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R_UNORM8, - "MESA_FORMAT_R_UNORM8", - GL_RED, - GL_UNSIGNED_NORMALIZED, - 8, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_R_UNORM16, - "MESA_FORMAT_R_UNORM16", - GL_RED, - GL_UNSIGNED_NORMALIZED, - 16, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_BGR_UNORM8, /* Name */ - "MESA_FORMAT_BGR_UNORM8", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 3 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_RGB_UNORM8, /* Name */ - "MESA_FORMAT_RGB_UNORM8", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 3 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_RGBA_UNORM16, - "MESA_FORMAT_RGBA_UNORM16", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 16, 16, 16, 16, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBX_UNORM16, - "MESA_FORMAT_RGBX_UNORM16", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_Z_UNORM16, /* Name */ - "MESA_FORMAT_Z_UNORM16", /* StrName */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 2 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_Z_UNORM32, /* Name */ - "MESA_FORMAT_Z_UNORM32", /* StrName */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_S_UINT8, /* Name */ - "MESA_FORMAT_S_UINT8", /* StrName */ - GL_STENCIL_INDEX, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - - /* Packed signed/normalized formats */ - { - MESA_FORMAT_A8B8G8R8_SNORM, - "MESA_FORMAT_A8B8G8R8_SNORM", - GL_RGBA, - GL_SIGNED_NORMALIZED, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_X8B8G8R8_SNORM, - "MESA_FORMAT_X8B8G8R8_SNORM", - GL_RGB, - GL_SIGNED_NORMALIZED, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 /* 4 bpp, but no alpha */ - }, - { - MESA_FORMAT_R8G8B8A8_SNORM, - "MESA_FORMAT_R8G8B8A8_SNORM", - GL_RGBA, - GL_SIGNED_NORMALIZED, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R8G8B8X8_SNORM, - "MESA_FORMAT_R8G8B8X8_SNORM", - GL_RGB, - GL_SIGNED_NORMALIZED, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R16G16_SNORM, - "MESA_FORMAT_R16G16_SNORM", - GL_RG, - GL_SIGNED_NORMALIZED, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_G16R16_SNORM, - "MESA_FORMAT_G16R16_SNORM", - GL_RG, - GL_SIGNED_NORMALIZED, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R8G8_SNORM, - "MESA_FORMAT_R8G8_SNORM", - GL_RG, - GL_SIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_G8R8_SNORM, - "MESA_FORMAT_G8R8_SNORM", - GL_RG, - GL_SIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L8A8_SNORM, - "MESA_FORMAT_L8A8_SNORM", - GL_LUMINANCE_ALPHA, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 8, - 8, 0, 0, 0, 0, - 1, 1, 2 - }, - - /* Array signed/normalized formats */ - { - MESA_FORMAT_A_SNORM8, - "MESA_FORMAT_A_SNORM8", - GL_ALPHA, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 8, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_A_SNORM16, - "MESA_FORMAT_A_SNORM16", - GL_ALPHA, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 16, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L_SNORM8, - "MESA_FORMAT_L_SNORM8", - GL_LUMINANCE, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 0, - 8, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_L_SNORM16, - "MESA_FORMAT_L_SNORM16", - GL_LUMINANCE, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 0, - 16, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_I_SNORM8, - "MESA_FORMAT_I_SNORM8", - GL_INTENSITY, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 0, - 0, 8, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_I_SNORM16, - "MESA_FORMAT_I_SNORM16", - GL_INTENSITY, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 0, - 0, 16, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_R_SNORM8, /* Name */ - "MESA_FORMAT_R_SNORM8", /* StrName */ - GL_RED, /* BaseFormat */ - GL_SIGNED_NORMALIZED, /* DataType */ - 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 1 /* BlockWidth/Height,Bytes */ - }, - { - MESA_FORMAT_R_SNORM16, - "MESA_FORMAT_R_SNORM16", - GL_RED, - GL_SIGNED_NORMALIZED, - 16, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_LA_SNORM16, - "MESA_FORMAT_LA_SNORM16", - GL_LUMINANCE_ALPHA, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 16, - 16, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RGB_SNORM16, - "MESA_FORMAT_RGB_SNORM16", - GL_RGB, - GL_SIGNED_NORMALIZED, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 6 - }, - { - MESA_FORMAT_RGBA_SNORM16, - "MESA_FORMAT_RGBA_SNORM16", - GL_RGBA, - GL_SIGNED_NORMALIZED, - 16, 16, 16, 16, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBX_SNORM16, - "MESA_FORMAT_RGBX_SNORM16", - GL_RGB, - GL_SIGNED_NORMALIZED, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - - /* Packed sRGB formats */ - { - MESA_FORMAT_A8B8G8R8_SRGB, - "MESA_FORMAT_A8B8G8R8_SRGB", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_B8G8R8A8_SRGB, - "MESA_FORMAT_B8G8R8A8_SRGB", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_B8G8R8X8_SRGB, - "MESA_FORMAT_B8G8R8X8_SRGB", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R8G8B8A8_SRGB, - "MESA_FORMAT_R8G8B8A8_SRGB", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R8G8B8X8_SRGB, - "MESA_FORMAT_R8G8B8X8_SRGB", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_L8A8_SRGB, - "MESA_FORMAT_L8A8_SRGB", - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_NORMALIZED, - 0, 0, 0, 8, - 8, 0, 0, 0, 0, - 1, 1, 2 - }, - - /* Array sRGB formats */ - { - MESA_FORMAT_L_SRGB8, - "MESA_FORMAT_L_SRGB8", - GL_LUMINANCE, - GL_UNSIGNED_NORMALIZED, - 0, 0, 0, 0, - 8, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_BGR_SRGB8, - "MESA_FORMAT_BGR_SRGB8", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 3 - }, - - /* Packed float formats */ - { - MESA_FORMAT_R9G9B9E5_FLOAT, - "MESA_FORMAT_RGB9_E5", - GL_RGB, - GL_FLOAT, - 9, 9, 9, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R11G11B10_FLOAT, - "MESA_FORMAT_R11G11B10_FLOAT", - GL_RGB, - GL_FLOAT, - 11, 11, 10, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_Z32_FLOAT_S8X24_UINT, /* Name */ - "MESA_FORMAT_Z32_FLOAT_S8X24_UINT", /* StrName */ - GL_DEPTH_STENCIL, /* BaseFormat */ - /* DataType here is used to answer GL_TEXTURE_DEPTH_TYPE queries, and is - * never used for stencil because stencil is always GL_UNSIGNED_INT. - */ - GL_FLOAT, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 32, 8, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 8 /* BlockWidth/Height,Bytes */ - }, - - /* Array float formats */ - { - MESA_FORMAT_A_FLOAT16, - "MESA_FORMAT_A_FLOAT16", - GL_ALPHA, - GL_FLOAT, - 0, 0, 0, 16, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_A_FLOAT32, - "MESA_FORMAT_A_FLOAT32", - GL_ALPHA, - GL_FLOAT, - 0, 0, 0, 32, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_L_FLOAT16, - "MESA_FORMAT_L_FLOAT16", - GL_LUMINANCE, - GL_FLOAT, - 0, 0, 0, 0, - 16, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L_FLOAT32, - "MESA_FORMAT_L_FLOAT32", - GL_LUMINANCE, - GL_FLOAT, - 0, 0, 0, 0, - 32, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_LA_FLOAT16, - "MESA_FORMAT_LA_FLOAT16", - GL_LUMINANCE_ALPHA, - GL_FLOAT, - 0, 0, 0, 16, - 16, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_LA_FLOAT32, - "MESA_FORMAT_LA_FLOAT32", - GL_LUMINANCE_ALPHA, - GL_FLOAT, - 0, 0, 0, 32, - 32, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_I_FLOAT16, - "MESA_FORMAT_I_FLOAT16", - GL_INTENSITY, - GL_FLOAT, - 0, 0, 0, 0, - 0, 16, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_I_FLOAT32, - "MESA_FORMAT_I_FLOAT32", - GL_INTENSITY, - GL_FLOAT, - 0, 0, 0, 0, - 0, 32, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R_FLOAT16, - "MESA_FORMAT_R_FLOAT16", - GL_RED, - GL_FLOAT, - 16, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_R_FLOAT32, - "MESA_FORMAT_R_FLOAT32", - GL_RED, - GL_FLOAT, - 32, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RG_FLOAT16, - "MESA_FORMAT_RG_FLOAT16", - GL_RG, - GL_FLOAT, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RG_FLOAT32, - "MESA_FORMAT_RG_FLOAT32", - GL_RG, - GL_FLOAT, - 32, 32, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGB_FLOAT16, - "MESA_FORMAT_RGB_FLOAT16", - GL_RGB, - GL_FLOAT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 6 - }, - { - MESA_FORMAT_RGB_FLOAT32, - "MESA_FORMAT_RGB_FLOAT32", - GL_RGB, - GL_FLOAT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 12 - }, - { - MESA_FORMAT_RGBA_FLOAT16, - "MESA_FORMAT_RGBA_FLOAT16", - GL_RGBA, - GL_FLOAT, - 16, 16, 16, 16, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBA_FLOAT32, - "MESA_FORMAT_RGBA_FLOAT32", - GL_RGBA, - GL_FLOAT, - 32, 32, 32, 32, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - { - MESA_FORMAT_RGBX_FLOAT16, - "MESA_FORMAT_RGBX_FLOAT16", - GL_RGB, - GL_FLOAT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBX_FLOAT32, - "MESA_FORMAT_RGBX_FLOAT32", - GL_RGB, - GL_FLOAT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - { - MESA_FORMAT_Z_FLOAT32, /* Name */ - "MESA_FORMAT_Z_FLOAT32", /* StrName */ - GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_FLOAT, /* DataType */ - 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ - 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */ - 1, 1, 4 /* BlockWidth/Height,Bytes */ - }, - - /* Packed signed/unsigned non-normalized integer formats */ - { - MESA_FORMAT_B10G10R10A2_UINT, - "MESA_FORMAT_B10G10R10A2_UINT", - GL_RGBA, - GL_UNSIGNED_INT, - 10, 10, 10, 2, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R10G10B10A2_UINT, - "MESA_FORMAT_R10G10B10A2_UINT", - GL_RGBA, - GL_UNSIGNED_INT, - 10, 10, 10, 2, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - - /* Array signed/unsigned non-normalized integer formats */ - { - MESA_FORMAT_A_UINT8, - "MESA_FORMAT_A_UINT8", - GL_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 8, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_A_UINT16, - "MESA_FORMAT_A_UINT16", - GL_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 16, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_A_UINT32, - "MESA_FORMAT_A_UINT32", - GL_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 32, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_A_SINT8, - "MESA_FORMAT_A_SINT8", - GL_ALPHA, - GL_INT, - 0, 0, 0, 8, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_A_SINT16, - "MESA_FORMAT_A_SINT16", - GL_ALPHA, - GL_INT, - 0, 0, 0, 16, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_A_SINT32, - "MESA_FORMAT_A_SINT32", - GL_ALPHA, - GL_INT, - 0, 0, 0, 32, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_I_UINT8, - "MESA_FORMAT_I_UINT8", - GL_INTENSITY, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 0, 8, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_I_UINT16, - "MESA_FORMAT_I_UINT16", - GL_INTENSITY, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 0, 16, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_I_UINT32, - "MESA_FORMAT_I_UINT32", - GL_INTENSITY, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 0, 32, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_I_SINT8, - "MESA_FORMAT_I_SINT8", - GL_INTENSITY, - GL_INT, - 0, 0, 0, 0, - 0, 8, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_I_SINT16, - "MESA_FORMAT_I_SINT16", - GL_INTENSITY, - GL_INT, - 0, 0, 0, 0, - 0, 16, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_I_SINT32, - "MESA_FORMAT_I_SINT32", - GL_INTENSITY, - GL_INT, - 0, 0, 0, 0, - 0, 32, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_L_UINT8, - "MESA_FORMAT_L_UINT8", - GL_LUMINANCE, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 8, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_L_UINT16, - "MESA_FORMAT_L_UINT16", - GL_LUMINANCE, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 16, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L_UINT32, - "MESA_FORMAT_L_UINT32", - GL_LUMINANCE, - GL_UNSIGNED_INT, - 0, 0, 0, 0, - 32, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_L_SINT8, - "MESA_FORMAT_L_SINT8", - GL_LUMINANCE, - GL_INT, - 0, 0, 0, 0, - 8, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_L_SINT16, - "MESA_FORMAT_L_SINT16", - GL_LUMINANCE, - GL_INT, - 0, 0, 0, 0, - 16, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_L_SINT32, - "MESA_FORMAT_L_SINT32", - GL_LUMINANCE, - GL_INT, - 0, 0, 0, 0, - 32, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_LA_UINT8, - "MESA_FORMAT_LA_UINT8", - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 8, - 8, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_LA_UINT16, - "MESA_FORMAT_LA_UINT16", - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 16, - 16, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_LA_UINT32, - "MESA_FORMAT_LA_UINT32", - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_INT, - 0, 0, 0, 32, - 32, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_LA_SINT8, - "MESA_FORMAT_LA_SINT8", - GL_LUMINANCE_ALPHA, - GL_INT, - 0, 0, 0, 8, - 8, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_LA_SINT16, - "MESA_FORMAT_LA_SINT16", - GL_LUMINANCE_ALPHA, - GL_INT, - 0, 0, 0, 16, - 16, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_LA_SINT32, - "MESA_FORMAT_LA_SINT32", - GL_LUMINANCE_ALPHA, - GL_INT, - 0, 0, 0, 32, - 32, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_R_UINT8, - "MESA_FORMAT_R_UINT8", - GL_RED, - GL_UNSIGNED_INT, - 8, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_R_UINT16, - "MESA_FORMAT_R_UINT16", - GL_RED, - GL_UNSIGNED_INT, - 16, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_R_UINT32, - "MESA_FORMAT_R_UINT32", - GL_RED, - GL_UNSIGNED_INT, - 32, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_R_SINT8, - "MESA_FORMAT_R_SINT8", - GL_RED, - GL_INT, - 8, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 1 - }, - { - MESA_FORMAT_R_SINT16, - "MESA_FORMAT_R_SINT16", - GL_RED, - GL_INT, - 16, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_R_SINT32, - "MESA_FORMAT_R_SINT32", - GL_RED, - GL_INT, - 32, 0, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RG_UINT8, - "MESA_FORMAT_RG_UINT8", - GL_RG, - GL_UNSIGNED_INT, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_RG_UINT16, - "MESA_FORMAT_RG_UINT16", - GL_RG, - GL_UNSIGNED_INT, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RG_UINT32, - "MESA_FORMAT_RG_UINT32", - GL_RG, - GL_UNSIGNED_INT, - 32, 32, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RG_SINT8, - "MESA_FORMAT_RG_SINT8", - GL_RG, - GL_INT, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 2 - }, - { - MESA_FORMAT_RG_SINT16, - "MESA_FORMAT_RG_SINT16", - GL_RG, - GL_INT, - 16, 16, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RG_SINT32, - "MESA_FORMAT_RG_SINT32", - GL_RG, - GL_INT, - 32, 32, 0, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGB_UINT8, - "MESA_FORMAT_RGB_UINT8", - GL_RGB, - GL_UNSIGNED_INT, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 3 - }, - { - MESA_FORMAT_RGB_UINT16, - "MESA_FORMAT_RGB_UINT16", - GL_RGB, - GL_UNSIGNED_INT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 6 - }, - { - MESA_FORMAT_RGB_UINT32, - "MESA_FORMAT_RGB_UINT32", - GL_RGB, - GL_UNSIGNED_INT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 12 - }, - { - MESA_FORMAT_RGB_SINT8, - "MESA_FORMAT_RGB_SINT8", - GL_RGB, - GL_INT, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 3 - }, - { - MESA_FORMAT_RGB_SINT16, - "MESA_FORMAT_RGB_SINT16", - GL_RGB, - GL_INT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 6 - }, - { - MESA_FORMAT_RGB_SINT32, - "MESA_FORMAT_RGB_SINT32", - GL_RGB, - GL_INT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 12 - }, - { - MESA_FORMAT_RGBA_UINT8, - "MESA_FORMAT_RGBA_UINT8", - GL_RGBA, - GL_UNSIGNED_INT, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RGBA_UINT16, - "MESA_FORMAT_RGBA_UINT16", - GL_RGBA, - GL_UNSIGNED_INT, - 16, 16, 16, 16, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBA_UINT32, - "MESA_FORMAT_RGBA_UINT32", - GL_RGBA, - GL_UNSIGNED_INT, - 32, 32, 32, 32, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - { - MESA_FORMAT_RGBA_SINT8, - "MESA_FORMAT_RGBA_SINT8", - GL_RGBA, - GL_INT, - 8, 8, 8, 8, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RGBA_SINT16, - "MESA_FORMAT_RGBA_SINT16", - GL_RGBA, - GL_INT, - 16, 16, 16, 16, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBA_SINT32, - "MESA_FORMAT_RGBA_SINT32", - GL_RGBA, - GL_INT, - 32, 32, 32, 32, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - { - MESA_FORMAT_RGBX_UINT8, - "MESA_FORMAT_RGBX_UINT8", - GL_RGB, - GL_UNSIGNED_INT, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RGBX_UINT16, - "MESA_FORMAT_RGBX_UINT16", - GL_RGB, - GL_UNSIGNED_INT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBX_UINT32, - "MESA_FORMAT_RGBX_UINT32", - GL_RGB, - GL_UNSIGNED_INT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - { - MESA_FORMAT_RGBX_SINT8, - "MESA_FORMAT_RGBX_SINT8", - GL_RGB, - GL_INT, - 8, 8, 8, 0, - 0, 0, 0, 0, 0, - 1, 1, 4 - }, - { - MESA_FORMAT_RGBX_SINT16, - "MESA_FORMAT_RGBX_SINT16", - GL_RGB, - GL_INT, - 16, 16, 16, 0, - 0, 0, 0, 0, 0, - 1, 1, 8 - }, - { - MESA_FORMAT_RGBX_SINT32, - "MESA_FORMAT_RGBX_SINT32", - GL_RGB, - GL_INT, - 32, 32, 32, 0, - 0, 0, 0, 0, 0, - 1, 1, 16 - }, - - /* DXT compressed formats */ - { - MESA_FORMAT_RGB_DXT1, /* Name */ - "MESA_FORMAT_RGB_DXT1", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_RGBA_DXT1, - "MESA_FORMAT_RGBA_DXT1", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_RGBA_DXT3, - "MESA_FORMAT_RGBA_DXT3", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - { - MESA_FORMAT_RGBA_DXT5, - "MESA_FORMAT_RGBA_DXT5", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - - /* DXT sRGB compressed formats */ - { - MESA_FORMAT_SRGB_DXT1, /* Name */ - "MESA_FORMAT_SRGB_DXT1", /* StrName */ - GL_RGB, /* BaseFormat */ - GL_UNSIGNED_NORMALIZED, /* DataType */ - 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */ - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_SRGBA_DXT1, - "MESA_FORMAT_SRGBA_DXT1", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_SRGBA_DXT3, - "MESA_FORMAT_SRGBA_DXT3", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - { - MESA_FORMAT_SRGBA_DXT5, - "MESA_FORMAT_SRGBA_DXT5", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 4, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - - /* FXT1 compressed formats */ - { - MESA_FORMAT_RGB_FXT1, - "MESA_FORMAT_RGB_FXT1", - GL_RGB, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 0, /* approx Red/Green/BlueBits */ - 0, 0, 0, 0, 0, - 8, 4, 16 /* 16 bytes per 8x4 block */ - }, - { - MESA_FORMAT_RGBA_FXT1, - "MESA_FORMAT_RGBA_FXT1", - GL_RGBA, - GL_UNSIGNED_NORMALIZED, - 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */ - 0, 0, 0, 0, 0, - 8, 4, 16 /* 16 bytes per 8x4 block */ - }, - - /* RGTC compressed formats */ - { - MESA_FORMAT_R_RGTC1_UNORM, - "MESA_FORMAT_R_RGTC1_UNORM", - GL_RED, - GL_UNSIGNED_NORMALIZED, - 8, 0, 0, 0, - 0, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_R_RGTC1_SNORM, - "MESA_FORMAT_R_RGTC1_SNORM", - GL_RED, - GL_SIGNED_NORMALIZED, - 8, 0, 0, 0, - 0, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_RG_RGTC2_UNORM, - "MESA_FORMAT_RG_RGTC2_UNORM", - GL_RG, - GL_UNSIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - { - MESA_FORMAT_RG_RGTC2_SNORM, - "MESA_FORMAT_RG_RGTC2_SNORM", - GL_RG, - GL_SIGNED_NORMALIZED, - 8, 8, 0, 0, - 0, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - - /* LATC1/2 compressed formats */ - { - MESA_FORMAT_L_LATC1_UNORM, - "MESA_FORMAT_L_LATC1_UNORM", - GL_LUMINANCE, - GL_UNSIGNED_NORMALIZED, - 0, 0, 0, 0, - 4, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_L_LATC1_SNORM, - "MESA_FORMAT_L_LATC1_SNORM", - GL_LUMINANCE, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 0, - 4, 0, 0, 0, 0, - 4, 4, 8 /* 8 bytes per 4x4 block */ - }, - { - MESA_FORMAT_LA_LATC2_UNORM, - "MESA_FORMAT_LA_LATC2_UNORM", - GL_LUMINANCE_ALPHA, - GL_UNSIGNED_NORMALIZED, - 0, 0, 0, 4, - 4, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - { - MESA_FORMAT_LA_LATC2_SNORM, - "MESA_FORMAT_LA_LATC2_SNORM", - GL_LUMINANCE_ALPHA, - GL_SIGNED_NORMALIZED, - 0, 0, 0, 4, - 4, 0, 0, 0, 0, - 4, 4, 16 /* 16 bytes per 4x4 block */ - }, - - /* ETC1/2 compressed formats */ - { - MESA_FORMAT_ETC1_RGB8, - "MESA_FORMAT_ETC1_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_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 */ - }, + uint8_t Swizzle[4]; }; - +#include "format_info.c" static const struct gl_format_info * _mesa_get_format_info(mesa_format format) @@ -1881,7 +148,7 @@ _mesa_get_format_bits(mesa_format format, GLenum pname) case GL_TEXTURE_LUMINANCE_SIZE: return info->LuminanceBits; case GL_INDEX_BITS: - return info->IndexBits; + return 0; case GL_DEPTH_BITS: case GL_TEXTURE_DEPTH_SIZE_ARB: case GL_RENDERBUFFER_DEPTH_SIZE_EXT: @@ -1915,6 +182,21 @@ _mesa_get_format_max_bits(mesa_format format) /** + * Return the layout type of the given format. + * The return value will be one of: + * MESA_FORMAT_LAYOUT_ARRAY + * MESA_FORMAT_LAYOUT_PACKED + * MESA_FORMAT_LAYOUT_OTHER + */ +extern enum mesa_format_layout +_mesa_get_format_layout(mesa_format format) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + return info->Layout; +} + + +/** * Return the data type (or more specifically, the data representation) * for the given format. * The return value will be one of: @@ -1961,6 +243,33 @@ _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh) } +/** + * Returns the an array of four numbers representing the transformation + * from the RGBA or SZ colorspace to the given format. For array formats, + * the i'th RGBA component is given by: + * + * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W) + * comp = data[swizzle[i]]; + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO) + * comp = 0; + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE) + * comp = 1; + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE) + * // data does not contain a channel of this format + * + * For packed formats, the swizzle gives the number of components left of + * the least significant bit. + * + * Compressed formats have no swizzle. + */ +void +_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]) +{ + const struct gl_format_info *info = _mesa_get_format_info(format); + memcpy(swizzle_out, info->Swizzle, sizeof(info->Swizzle)); +} + + /** Is the given format a compressed format? */ GLboolean _mesa_is_format_compressed(mesa_format format) @@ -2331,7 +640,6 @@ check_format_to_type_and_comps(void) } } - /** * Do sanity checking of the format info table. */ diff --git a/mesalib/src/mesa/main/formats.csv b/mesalib/src/mesa/main/formats.csv new file mode 100644 index 000000000..eade6facd --- /dev/null +++ b/mesalib/src/mesa/main/formats.csv @@ -0,0 +1,282 @@ +########################################################################### +# +# Copyright 2009-2010 VMware, Inc. +# Copyright 2014 Intel Corporation +# All Rights Reserved. +# +# 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, sub license, 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 NON-INFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS 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. +# +########################################################################### + +# This CSV file has the input data for gen_format.h and gen_format.c +# +# Each format entry contains: +# - name, per enum mesa_format +# - layout +# - pixel block's width +# - pixel block's height +# - channel encoding (only meaningful for array or packed layout), containing for each +# channel the following information: +# - type, one of +# - 'x': void +# - 'u': unsigned +# - 's': signed +# - 'h': fixed +# - 'f': FLOAT +# - optionally followed by 'n' if it is normalized +# - number of bits +# - channel swizzle +# - color space: rgb, srgb, yub, sz + +# None +# Described as regular uint_8 bytes, i.e. MESA_FORMAT_R8_USCALED +MESA_FORMAT_NONE , other , 1, 1, x8 , , , , 0001, rgb + +# Packed unorm formats +MESA_FORMAT_A8B8G8R8_UNORM , packed, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb +MESA_FORMAT_X8B8G8R8_UNORM , packed, 1, 1, x8 , un8 , un8 , un8 , wzy1, rgb +MESA_FORMAT_R8G8B8A8_UNORM , packed, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb +MESA_FORMAT_R8G8B8X8_UNORM , packed, 1, 1, un8 , un8 , un8 , x8 , xyz1, rgb +MESA_FORMAT_B8G8R8A8_UNORM , packed, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb +MESA_FORMAT_B8G8R8X8_UNORM , packed, 1, 1, un8 , un8 , un8 , x8 , zyx1, rgb +MESA_FORMAT_A8R8G8B8_UNORM , packed, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb +MESA_FORMAT_X8R8G8B8_UNORM , packed, 1, 1, x8 , un8 , un8 , un8 , yzw1, rgb +MESA_FORMAT_L16A16_UNORM , packed, 1, 1, un16, un16, , , xxxy, rgb +MESA_FORMAT_A16L16_UNORM , packed, 1, 1, un16, un16, , , yyyx, rgb +MESA_FORMAT_B5G6R5_UNORM , packed, 1, 1, un5 , un6 , un5 , , zyx1, rgb +MESA_FORMAT_R5G6B5_UNORM , packed, 1, 1, un5 , un6 , un5 , , xyz1, rgb +MESA_FORMAT_B4G4R4A4_UNORM , packed, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb +MESA_FORMAT_B4G4R4X4_UNORM , packed, 1, 1, un4 , un4 , un4 , x4 , zyx1, rgb +MESA_FORMAT_A4R4G4B4_UNORM , packed, 1, 1, un4 , un4 , un4 , un4 , yzwx, rgb +MESA_FORMAT_A1B5G5R5_UNORM , packed, 1, 1, un1 , un5 , un5 , un5 , wzyx, rgb +MESA_FORMAT_B5G5R5A1_UNORM , packed, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb +MESA_FORMAT_B5G5R5X1_UNORM , packed, 1, 1, un5 , un5 , un5 , x1 , zyx1, rgb +MESA_FORMAT_A1R5G5B5_UNORM , packed, 1, 1, un1 , un5 , un5 , un5 , yzwx, rgb +MESA_FORMAT_L8A8_UNORM , packed, 1, 1, un8 , un8 , , , xxxy, rgb +MESA_FORMAT_A8L8_UNORM , packed, 1, 1, un8 , un8 , , , yyyx, rgb +MESA_FORMAT_R8G8_UNORM , packed, 1, 1, un8 , un8 , , , xy01, rgb +MESA_FORMAT_G8R8_UNORM , packed, 1, 1, un8 , un8 , , , yx01, rgb +MESA_FORMAT_L4A4_UNORM , packed, 1, 1, un4 , un4 , , , xxxy, rgb + +MESA_FORMAT_B2G3R3_UNORM , packed, 1, 1, un2 , un3 , un3 , , zyx1, rgb +MESA_FORMAT_R16G16_UNORM , packed, 1, 1, un16, un16, , , xy01, rgb +MESA_FORMAT_G16R16_UNORM , packed, 1, 1, un16, un16, , , yx01, rgb +MESA_FORMAT_B10G10R10A2_UNORM , packed, 1, 1, un10, un10, un10, un2 , zyxw, rgb +MESA_FORMAT_B10G10R10X2_UNORM , packed, 1, 1, un10, un10, un10, x2 , zyx1, rgb +MESA_FORMAT_R10G10B10A2_UNORM , packed, 1, 1, un10, un10, un10, un2 , xyzw, rgb + +MESA_FORMAT_S8_UINT_Z24_UNORM , packed, 1, 1, un24, u8 , , , xy__, zs +MESA_FORMAT_X8_UINT_Z24_UNORM , packed, 1, 1, un24, x8 , , , x___, zs +MESA_FORMAT_Z24_UNORM_S8_UINT , packed, 1, 1, u8 , un24, , , yx__, zs +MESA_FORMAT_Z24_UNORM_X8_UINT , packed, 1, 1, x8 , un24, , , y___, zs + +MESA_FORMAT_YCBCR , other , 1, 1, x16 , , , , xyzw, yuv +MESA_FORMAT_YCBCR_REV , other , 1, 1, x16 , , , , xyzw, yuv + +# Array normalized formats +MESA_FORMAT_A_UNORM8 , array , 1, 1, un8 , , , , 000x, rgb +MESA_FORMAT_A_UNORM16 , array , 1, 1, un16, , , , 000x, rgb +MESA_FORMAT_L_UNORM8 , array , 1, 1, un8 , , , , xxx1, rgb +MESA_FORMAT_L_UNORM16 , array , 1, 1, un16, , , , xxx1, rgb +MESA_FORMAT_I_UNORM8 , array , 1, 1, un8 , , , , xxxx, rgb +MESA_FORMAT_I_UNORM16 , array , 1, 1, un16, , , , xxxx, rgb +MESA_FORMAT_R_UNORM8 , array , 1, 1, un8 , , , , x001, rgb +MESA_FORMAT_R_UNORM16 , array , 1, 1, un16, , , , x001, rgb +MESA_FORMAT_BGR_UNORM8 , array , 1, 1, un8 , un8 , un8 , , zyx1, rgb +MESA_FORMAT_RGB_UNORM8 , array , 1, 1, un8 , un8 , un8 , , xyz1, rgb +MESA_FORMAT_RGBA_UNORM16 , array , 1, 1, un16, un16, un16, un16, xyzw, rgb +MESA_FORMAT_RGBX_UNORM16 , array , 1, 1, un16, un16, un16, x16 , xyz1, rgb + +MESA_FORMAT_Z_UNORM16 , array , 1, 1, un16, , , , x___, zs +MESA_FORMAT_Z_UNORM32 , array , 1, 1, un32, , , , x___, zs +MESA_FORMAT_S_UINT8 , array , 1, 1, u8 , , , , _x__, zs + +# Packed signed formats +MESA_FORMAT_A8B8G8R8_SNORM , packed, 1, 1, sn8 , sn8 , sn8 , sn8 , wzyx, rgb +MESA_FORMAT_X8B8G8R8_SNORM , packed, 1, 1, x8 , sn8 , sn8 , sn8 , wzy1, rgb +MESA_FORMAT_R8G8B8A8_SNORM , packed, 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb +MESA_FORMAT_R8G8B8X8_SNORM , packed, 1, 1, sn8 , sn8 , sn8 , x8 , xyz1, rgb +MESA_FORMAT_R16G16_SNORM , packed, 1, 1, sn16, sn16, , , xy01, rgb +MESA_FORMAT_G16R16_SNORM , packed, 1, 1, sn16, sn16, , , yx01, rgb +MESA_FORMAT_R8G8_SNORM , packed, 1, 1, sn8 , sn8 , , , xy01, rgb +MESA_FORMAT_G8R8_SNORM , packed, 1, 1, sn8 , sn8 , , , yx01, rgb +MESA_FORMAT_L8A8_SNORM , packed, 1, 1, sn8 , sn8 , , , xxxy, rgb + +# Array signed/normalized formats +MESA_FORMAT_A_SNORM8 , array , 1, 1, sn8 , , , , 000x, rgb +MESA_FORMAT_A_SNORM16 , array , 1, 1, sn16, , , , 000x, rgb +MESA_FORMAT_L_SNORM8 , array , 1, 1, sn8 , , , , xxx1, rgb +MESA_FORMAT_L_SNORM16 , array , 1, 1, sn16, , , , xxx1, rgb +MESA_FORMAT_I_SNORM8 , array , 1, 1, sn8 , , , , xxxx, rgb +MESA_FORMAT_I_SNORM16 , array , 1, 1, sn16, , , , xxxx, rgb +MESA_FORMAT_R_SNORM8 , array , 1, 1, sn8 , , , , x001, rgb +MESA_FORMAT_R_SNORM16 , array , 1, 1, sn16, , , , x001, rgb +MESA_FORMAT_LA_SNORM16 , array , 1, 1, sn16, sn16, , , xxxy, rgb +MESA_FORMAT_RGB_SNORM16 , array , 1, 1, sn16, sn16, sn16, , xyz1, rgb +MESA_FORMAT_RGBA_SNORM16 , array , 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb +MESA_FORMAT_RGBX_SNORM16 , array , 1, 1, sn16, sn16, sn16, x16 , xyz1, rgb + +# Packed sRGB formats +MESA_FORMAT_A8B8G8R8_SRGB , packed, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb +MESA_FORMAT_B8G8R8A8_SRGB , packed, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb +MESA_FORMAT_B8G8R8X8_SRGB , packed, 1, 1, un8 , un8 , un8 , x8 , zyx1, srgb +MESA_FORMAT_R8G8B8A8_SRGB , packed, 1, 1, un8 , un8 , un8 , un8 , xyzw, srgb +MESA_FORMAT_R8G8B8X8_SRGB , packed, 1, 1, un8 , un8 , un8 , x8 , xyz1, srgb +MESA_FORMAT_L8A8_SRGB , packed, 1, 1, un8 , un8 , , , xxxy, srgb + +# Array sRGB formats +MESA_FORMAT_L_SRGB8 , array , 1, 1, un8 , , , , xxx1, srgb +MESA_FORMAT_BGR_SRGB8 , array , 1, 1, un8 , un8 , un8 , , zyx1, srgb + +# Packed float formats +MESA_FORMAT_R9G9B9E5_FLOAT , other , 1, 1, f9 , f9 , f9 , x5 , xyz1, rgb +MESA_FORMAT_R11G11B10_FLOAT , packed, 1, 1, f11 , f11 , f10 , , xyz1, rgb +MESA_FORMAT_Z32_FLOAT_S8X24_UINT , packed, 1, 1, u8 , x24 , f32 , , zx__, zs + +# Array float formats +MESA_FORMAT_A_FLOAT16 , array , 1, 1, f16 , , , , 000x, rgb +MESA_FORMAT_A_FLOAT32 , array , 1, 1, f32 , , , , 000x, rgb +MESA_FORMAT_L_FLOAT16 , array , 1, 1, f16 , , , , xxx1, rgb +MESA_FORMAT_L_FLOAT32 , array , 1, 1, f32 , , , , xxx1, rgb +MESA_FORMAT_LA_FLOAT16 , array , 1, 1, f16 , f16 , , , xxxy, rgb +MESA_FORMAT_LA_FLOAT32 , array , 1, 1, f32 , f32 , , , xxxy, rgb +MESA_FORMAT_I_FLOAT16 , array , 1, 1, f16 , , , , xxxx, rgb +MESA_FORMAT_I_FLOAT32 , array , 1, 1, f32 , , , , xxxx, rgb +MESA_FORMAT_R_FLOAT16 , array , 1, 1, f16 , , , , x001, rgb +MESA_FORMAT_R_FLOAT32 , array , 1, 1, f32 , , , , x001, rgb +MESA_FORMAT_RG_FLOAT16 , array , 1, 1, f16 , f16 , , , xy01, rgb +MESA_FORMAT_RG_FLOAT32 , array , 1, 1, f32 , f32 , , , xy01, rgb +MESA_FORMAT_RGB_FLOAT16 , array , 1, 1, f16 , f16 , f16 , , xyz1, rgb +MESA_FORMAT_RGB_FLOAT32 , array , 1, 1, f32 , f32 , f32 , , xyz1, rgb +MESA_FORMAT_RGBA_FLOAT16 , array , 1, 1, f16 , f16 , f16 , f16 , xyzw, rgb +MESA_FORMAT_RGBA_FLOAT32 , array , 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb +MESA_FORMAT_RGBX_FLOAT16 , array , 1, 1, f16 , f16 , f16 , x16 , xyz1, rgb +MESA_FORMAT_RGBX_FLOAT32 , array , 1, 1, f32 , f32 , f32 , x32 , xyz1, rgb +MESA_FORMAT_Z_FLOAT32 , array , 1, 1, f32 , , , , x___, zs + +# Packed signed/unsigned non-normalized integer formats +MESA_FORMAT_B10G10R10A2_UINT , packed, 1, 1, u10 , u10 , u10 , u2 , zyxw, rgb +MESA_FORMAT_R10G10B10A2_UINT , packed, 1, 1, u10 , u10 , u10 , u2 , xyzw, rgb + +# Array signed/unsigned non-normalized integer formats +MESA_FORMAT_A_UINT8 , array , 1, 1, u8 , , , , 000x, rgb +MESA_FORMAT_A_UINT16 , array , 1, 1, u16 , , , , 000x, rgb +MESA_FORMAT_A_UINT32 , array , 1, 1, u32 , , , , 000x, rgb +MESA_FORMAT_A_SINT8 , array , 1, 1, s8 , , , , 000x, rgb +MESA_FORMAT_A_SINT16 , array , 1, 1, s16 , , , , 000x, rgb +MESA_FORMAT_A_SINT32 , array , 1, 1, s32 , , , , 000x, rgb + +MESA_FORMAT_I_UINT8 , array , 1, 1, u8 , , , , xxxx, rgb +MESA_FORMAT_I_UINT16 , array , 1, 1, u16 , , , , xxxx, rgb +MESA_FORMAT_I_UINT32 , array , 1, 1, u32 , , , , xxxx, rgb +MESA_FORMAT_I_SINT8 , array , 1, 1, s8 , , , , xxxx, rgb +MESA_FORMAT_I_SINT16 , array , 1, 1, s16 , , , , xxxx, rgb +MESA_FORMAT_I_SINT32 , array , 1, 1, s32 , , , , xxxx, rgb + +MESA_FORMAT_L_UINT8 , array , 1, 1, u8 , , , , xxx1, rgb +MESA_FORMAT_L_UINT16 , array , 1, 1, u16 , , , , xxx1, rgb +MESA_FORMAT_L_UINT32 , array , 1, 1, u32 , , , , xxx1, rgb +MESA_FORMAT_L_SINT8 , array , 1, 1, s8 , , , , xxx1, rgb +MESA_FORMAT_L_SINT16 , array , 1, 1, s16 , , , , xxx1, rgb +MESA_FORMAT_L_SINT32 , array , 1, 1, s32 , , , , xxx1, rgb + +MESA_FORMAT_LA_UINT8 , array , 1, 1, u8 , u8 , , , xxxy, rgb +MESA_FORMAT_LA_UINT16 , array , 1, 1, u16 , u16 , , , xxxy, rgb +MESA_FORMAT_LA_UINT32 , array , 1, 1, u32 , u32 , , , xxxy, rgb +MESA_FORMAT_LA_SINT8 , array , 1, 1, s8 , s8 , , , xxxy, rgb +MESA_FORMAT_LA_SINT16 , array , 1, 1, s16 , s16 , , , xxxy, rgb +MESA_FORMAT_LA_SINT32 , array , 1, 1, s32 , s32 , , , xxxy, rgb + +MESA_FORMAT_R_UINT8 , array , 1, 1, u8 , , , , x001, rgb +MESA_FORMAT_R_UINT16 , array , 1, 1, u16 , , , , x001, rgb +MESA_FORMAT_R_UINT32 , array , 1, 1, u32 , , , , x001, rgb +MESA_FORMAT_R_SINT8 , array , 1, 1, s8 , , , , x001, rgb +MESA_FORMAT_R_SINT16 , array , 1, 1, s16 , , , , x001, rgb +MESA_FORMAT_R_SINT32 , array , 1, 1, s32 , , , , x001, rgb + +MESA_FORMAT_RG_UINT8 , array , 1, 1, u8 , u8 , , , xy01, rgb +MESA_FORMAT_RG_UINT16 , array , 1, 1, u16 , u16 , , , xy01, rgb +MESA_FORMAT_RG_UINT32 , array , 1, 1, u32 , u32 , , , xy01, rgb +MESA_FORMAT_RG_SINT8 , array , 1, 1, s8 , s8 , , , xy01, rgb +MESA_FORMAT_RG_SINT16 , array , 1, 1, s16 , s16 , , , xy01, rgb +MESA_FORMAT_RG_SINT32 , array , 1, 1, s32 , s32 , , , xy01, rgb + +MESA_FORMAT_RGB_UINT8 , array , 1, 1, u8 , u8 , u8 , , xyz1, rgb +MESA_FORMAT_RGB_UINT16 , array , 1, 1, u16 , u16 , u16 , , xyz1, rgb +MESA_FORMAT_RGB_UINT32 , array , 1, 1, u32 , u32 , u32 , , xyz1, rgb +MESA_FORMAT_RGB_SINT8 , array , 1, 1, s8 , s8 , s8 , , xyz1, rgb +MESA_FORMAT_RGB_SINT16 , array , 1, 1, s16 , s16 , s16 , , xyz1, rgb +MESA_FORMAT_RGB_SINT32 , array , 1, 1, s32 , s32 , s32 , , xyz1, rgb + +MESA_FORMAT_RGBA_UINT8 , array , 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb +MESA_FORMAT_RGBA_UINT16 , array , 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb +MESA_FORMAT_RGBA_UINT32 , array , 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb +MESA_FORMAT_RGBA_SINT8 , array , 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb +MESA_FORMAT_RGBA_SINT16 , array , 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb +MESA_FORMAT_RGBA_SINT32 , array , 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb + +MESA_FORMAT_RGBX_UINT8 , array , 1, 1, u8 , u8 , u8 , x8 , xyz1, rgb +MESA_FORMAT_RGBX_UINT16 , array , 1, 1, u16 , u16 , u16 , x16 , xyz1, rgb +MESA_FORMAT_RGBX_UINT32 , array , 1, 1, u32 , u32 , u32 , x32 , xyz1, rgb +MESA_FORMAT_RGBX_SINT8 , array , 1, 1, s8 , s8 , s8 , x8 , xyz1, rgb +MESA_FORMAT_RGBX_SINT16 , array , 1, 1, s16 , s16 , s16 , x16 , xyz1, rgb +MESA_FORMAT_RGBX_SINT32 , array , 1, 1, s32 , s32 , s32 , x32 , xyz1, rgb + +# DTX compressed formats +MESA_FORMAT_RGB_DXT1 , s3tc , 4, 4, x64 , , , , xyz1, rgb +MESA_FORMAT_RGBA_DXT1 , s3tc , 4, 4, x64 , , , , xyzw, rgb +MESA_FORMAT_RGBA_DXT3 , s3tc , 4, 4, x128, , , , xyzw, rgb +MESA_FORMAT_RGBA_DXT5 , s3tc , 4, 4, x128, , , , xyzw, rgb + +# DTX sRGB compressed formats +MESA_FORMAT_SRGB_DXT1 , s3tc , 4, 4, x64 , , , , xyz1, srgb +MESA_FORMAT_SRGBA_DXT1 , s3tc , 4, 4, x64 , , , , xyzw, srgb +MESA_FORMAT_SRGBA_DXT3 , s3tc , 4, 4, x128, , , , xyzw, srgb +MESA_FORMAT_SRGBA_DXT5 , s3tc , 4, 4, x128, , , , xyzw, srgb + +# FXT1 compressed formats +MESA_FORMAT_RGB_FXT1 , fxt1 , 8, 4, x128, , , , xyz1, rgb +MESA_FORMAT_RGBA_FXT1 , fxt1 , 8, 4, x128, , , , xyzw, rgb + +# RGTC compressed formats +MESA_FORMAT_R_RGTC1_UNORM , rgtc , 4, 4, x64 , , , , x001, rgb +MESA_FORMAT_R_RGTC1_SNORM , rgtc , 4, 4, x64 , , , , x001, rgb +MESA_FORMAT_RG_RGTC2_UNORM , rgtc , 4, 4, x128, , , , xy01, rgb +MESA_FORMAT_RG_RGTC2_SNORM , rgtc , 4, 4, x128, , , , xy01, rgb + +# LATC1/2 compressed formats +MESA_FORMAT_L_LATC1_UNORM , rgtc , 4, 4, x64 , , , , xxx1, rgb +MESA_FORMAT_L_LATC1_SNORM , rgtc , 4, 4, x64 , , , , xxx1, rgb +MESA_FORMAT_LA_LATC2_UNORM , rgtc , 4, 4, x128, , , , xxxy, rgb +MESA_FORMAT_LA_LATC2_SNORM , rgtc , 4, 4, x128, , , , xxxy, rgb + +# ETC1/2 compressed formats +MESA_FORMAT_ETC1_RGB8 , etc1 , 4, 4, x64 , , , , xyz1, rgb +MESA_FORMAT_ETC2_RGB8 , etc2 , 4, 4, x64 , , , , xyz1, rgb +MESA_FORMAT_ETC2_SRGB8 , etc2 , 4, 4, x64 , , , , xyz1, srgb +MESA_FORMAT_ETC2_RGBA8_EAC , etc2 , 4, 4, x128, , , , xyzw, rgb +MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC , etc2 , 4, 4, x128, , , , xyzw, srgb +MESA_FORMAT_ETC2_R11_EAC , etc2 , 4, 4, x64 , , , , x001, rgb +MESA_FORMAT_ETC2_RG11_EAC , etc2 , 4, 4, x128, , , , xy01, rgb +MESA_FORMAT_ETC2_SIGNED_R11_EAC , etc2 , 4, 4, x64 , , , , x001, rgb +MESA_FORMAT_ETC2_SIGNED_RG11_EAC , etc2 , 4, 4, x128, , , , xy01, rgb +MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1 , etc2 , 4, 4, x64 , , , , xyzw, rgb +MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, etc2 , 4, 4, x64 , , , , xyzw, srgb diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h index dc50bc830..457c8abf8 100644 --- a/mesalib/src/mesa/main/formats.h +++ b/mesalib/src/mesa/main/formats.h @@ -35,6 +35,7 @@ #include <GL/gl.h> #include <stdbool.h> +#include <stdint.h> #ifdef __cplusplus @@ -56,6 +57,29 @@ extern "C" { */ #define MAX_PIXEL_BYTES 16 +/** + * Specifies the layout of a pixel format. See the MESA_FORMAT + * documentation below. + */ +enum mesa_format_layout { + MESA_FORMAT_LAYOUT_ARRAY, + MESA_FORMAT_LAYOUT_PACKED, + MESA_FORMAT_LAYOUT_OTHER, +}; + +/** + * An enum representing different possible swizzling values. This is used + * to interpret the output of _mesa_get_format_swizzle + */ +enum { + MESA_FORMAT_SWIZZLE_X = 0, + MESA_FORMAT_SWIZZLE_Y = 1, + MESA_FORMAT_SWIZZLE_Z = 2, + MESA_FORMAT_SWIZZLE_W = 3, + MESA_FORMAT_SWIZZLE_ZERO = 4, + MESA_FORMAT_SWIZZLE_ONE = 5, + MESA_FORMAT_SWIZZLE_NONE = 6, +}; /** * Mesa texture/renderbuffer image formats. @@ -419,6 +443,9 @@ _mesa_get_format_bits(mesa_format format, GLenum pname); extern GLuint _mesa_get_format_max_bits(mesa_format format); +extern enum mesa_format_layout +_mesa_get_format_layout(mesa_format format); + extern GLenum _mesa_get_format_datatype(mesa_format format); @@ -428,6 +455,9 @@ _mesa_get_format_base_format(mesa_format format); extern void _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh); +extern void +_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]); + extern GLboolean _mesa_is_format_compressed(mesa_format format); diff --git a/mesalib/src/mesa/main/get_hash_params.py b/mesalib/src/mesa/main/get_hash_params.py index 35d6172a3..ff858207b 100644 --- a/mesalib/src/mesa/main/get_hash_params.py +++ b/mesalib/src/mesa/main/get_hash_params.py @@ -84,6 +84,7 @@ descriptor=[ [ "SAMPLES_ARB", "BUFFER_INT(Visual.samples), extra_new_buffers" ], # GL_ARB_sample_shading + [ "SAMPLE_SHADING_ARB", "CONTEXT_BOOL(Multisample.SampleShading), extra_gl40_ARB_sample_shading" ], [ "MIN_SAMPLE_SHADING_VALUE_ARB", "CONTEXT_FLOAT(Multisample.MinSampleShadingValue), extra_gl40_ARB_sample_shading" ], # GL_SGIS_generate_mipmap diff --git a/mesalib/src/mesa/main/glformats.c b/mesalib/src/mesa/main/glformats.c index 304d45298..0fb25ba0f 100644 --- a/mesalib/src/mesa/main/glformats.c +++ b/mesalib/src/mesa/main/glformats.c @@ -353,6 +353,170 @@ _mesa_bytes_per_vertex_attrib(GLint comps, GLenum type) } } +/** + * Test if the given format is unsized. + */ +GLboolean +_mesa_is_enum_format_unsized(GLenum format) +{ + switch (format) { + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + case GL_RGB: + case GL_BGR: + case GL_RG: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_INTENSITY: + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + + case GL_SRGB: + case GL_SRGB_ALPHA: + case GL_SLUMINANCE: + case GL_SLUMINANCE_ALPHA: + + case GL_RGBA_SNORM: + case GL_RGB_SNORM: + case GL_RG_SNORM: + case GL_RED_SNORM: + case GL_ALPHA_SNORM: + case GL_INTENSITY_SNORM: + case GL_LUMINANCE_SNORM: + case GL_LUMINANCE_ALPHA_SNORM: + + case GL_RED_INTEGER: + case GL_GREEN_INTEGER: + case GL_BLUE_INTEGER: + case GL_ALPHA_INTEGER: + case GL_RGB_INTEGER: + case GL_RGBA_INTEGER: + case GL_BGR_INTEGER: + case GL_BGRA_INTEGER: + case GL_RG_INTEGER: + case GL_LUMINANCE_INTEGER_EXT: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + + case GL_DEPTH_COMPONENT: + case GL_DEPTH_STENCIL: + case GL_STENCIL_INDEX: + return GL_TRUE; + default: + return GL_FALSE; + } +} + +/** + * Test if the given format is a UNORM (unsigned-normalized) format. + */ +GLboolean +_mesa_is_enum_format_unorm(GLenum format) +{ + switch(format) { + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + case 1: + case GL_LUMINANCE: + case GL_SLUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + case 2: + case GL_LUMINANCE_ALPHA: + case GL_SLUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + case GL_R8: + case GL_R16: + case GL_RG: + case GL_RG8: + case GL_RG16: + case 3: + case GL_RGB: + case GL_BGR: + case GL_SRGB: + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + case GL_RGB565: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + case 4: + case GL_ABGR_EXT: + case GL_RGBA: + case GL_BGRA: + case GL_SRGB_ALPHA: + case GL_RGBA2: + case GL_RGBA4: + case GL_RGB5_A1: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return GL_TRUE; + default: + return GL_FALSE; + } +} + +/** + * Test if the given format is a SNORM (signed-normalized) format. + */ +GLboolean +_mesa_is_enum_format_snorm(GLenum format) +{ + switch (format) { + /* signed, normalized texture formats */ + case GL_RED_SNORM: + case GL_R8_SNORM: + case GL_R16_SNORM: + case GL_RG_SNORM: + case GL_RG8_SNORM: + case GL_RG16_SNORM: + case GL_RGB_SNORM: + case GL_RGB8_SNORM: + case GL_RGB16_SNORM: + case GL_RGBA_SNORM: + case GL_RGBA8_SNORM: + case GL_RGBA16_SNORM: + case GL_ALPHA_SNORM: + case GL_ALPHA8_SNORM: + case GL_ALPHA16_SNORM: + case GL_LUMINANCE_SNORM: + case GL_LUMINANCE8_SNORM: + case GL_LUMINANCE16_SNORM: + case GL_LUMINANCE_ALPHA_SNORM: + case GL_LUMINANCE8_ALPHA8_SNORM: + case GL_LUMINANCE16_ALPHA16_SNORM: + case GL_INTENSITY_SNORM: + case GL_INTENSITY8_SNORM: + case GL_INTENSITY16_SNORM: + return GL_TRUE; + default: + return GL_FALSE; + } +} /** * Test if the given format is an integer (non-normalized) format. diff --git a/mesalib/src/mesa/main/glformats.h b/mesalib/src/mesa/main/glformats.h index d64114ec9..7b0321570 100644 --- a/mesalib/src/mesa/main/glformats.h +++ b/mesalib/src/mesa/main/glformats.h @@ -57,6 +57,15 @@ extern GLboolean _mesa_is_type_unsigned(GLenum type); extern GLboolean +_mesa_is_enum_format_unsized(GLenum format); + +extern GLboolean +_mesa_is_enum_format_unorm(GLenum format); + +extern GLboolean +_mesa_is_enum_format_snorm(GLenum format); + +extern GLboolean _mesa_is_enum_format_integer(GLenum format); extern GLboolean diff --git a/mesalib/src/mesa/main/hash.c b/mesalib/src/mesa/main/hash.c index 674c29d65..52095f7d1 100644 --- a/mesalib/src/mesa/main/hash.c +++ b/mesalib/src/mesa/main/hash.c @@ -37,7 +37,7 @@ #include "glheader.h" #include "imports.h" #include "hash.h" -#include "hash_table.h" +#include "util/hash_table.h" /** * Magic GLuint object name that gets stored outside of the struct hash_table. diff --git a/mesalib/src/mesa/main/hash_table.c b/mesalib/src/mesa/main/hash_table.c deleted file mode 100644 index ad8f89852..000000000 --- a/mesalib/src/mesa/main/hash_table.c +++ /dev/null @@ -1,440 +0,0 @@ -/* - * 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> - */ - -/** - * Implements an open-addressing, linear-reprobing hash table. - * - * For more information, see: - * - * http://cgit.freedesktop.org/~anholt/hash_table/tree/README - */ - -#include <stdlib.h> -#include <string.h> - -#include "main/hash_table.h" -#include "main/macros.h" -#include "ralloc.h" - -static const uint32_t deleted_key_value; - -/** - * 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 - */ -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(const struct hash_entry *entry) -{ - return entry->key == NULL; -} - -static int -entry_is_deleted(const struct hash_table *ht, struct hash_entry *entry) -{ - return entry->key == ht->deleted_key; -} - -static int -entry_is_present(const struct hash_table *ht, struct hash_entry *entry) -{ - return entry->key != NULL && entry->key != ht->deleted_key; -} - -struct hash_table * -_mesa_hash_table_create(void *mem_ctx, - bool (*key_equals_function)(const void *a, - const void *b)) -{ - struct hash_table *ht; - - ht = ralloc(mem_ctx, struct hash_table); - if (ht == NULL) - return NULL; - - 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 hash_entry, ht->size); - ht->entries = 0; - ht->deleted_entries = 0; - ht->deleted_key = &deleted_key_value; - - if (ht->table == NULL) { - ralloc_free(ht); - return NULL; - } - - return ht; -} - -/** - * Frees the given hash table. - * - * If delete_function is passed, it gets called on each entry present before - * freeing. - */ -void -_mesa_hash_table_destroy(struct hash_table *ht, - void (*delete_function)(struct hash_entry *entry)) -{ - if (!ht) - return; - - if (delete_function) { - struct hash_entry *entry; - - hash_table_foreach(ht, entry) { - delete_function(entry); - } - } - ralloc_free(ht); -} - -/** Sets the value of the key pointer used for deleted entries in the table. - * - * The assumption is that usually keys are actual pointers, so we use a - * default value of a pointer to an arbitrary piece of storage in the library. - * But in some cases a consumer wants to store some other sort of value in the - * table, like a uint32_t, in which case that pointer may conflict with one of - * their valid keys. This lets that user select a safe value. - * - * This must be called before any keys are actually deleted from the table. - */ -void -_mesa_hash_table_set_deleted_key(struct hash_table *ht, const void *deleted_key) -{ - ht->deleted_key = deleted_key; -} - -/** - * Finds a hash table entry with the given key and hash of that key. - * - * Returns NULL if no entry is found. Note that the data pointer may be - * modified by the user. - */ -struct hash_entry * -_mesa_hash_table_search(struct hash_table *ht, uint32_t hash, - const void *key) -{ - uint32_t start_hash_address = hash % ht->size; - uint32_t hash_address = start_hash_address; - - do { - uint32_t double_hash; - - struct hash_entry *entry = ht->table + hash_address; - - if (entry_is_free(entry)) { - return NULL; - } else if (entry_is_present(ht, 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 != start_hash_address); - - return NULL; -} - -static void -_mesa_hash_table_rehash(struct hash_table *ht, int new_size_index) -{ - struct hash_table old_ht; - struct hash_entry *table, *entry; - - if (new_size_index >= ARRAY_SIZE(hash_sizes)) - return; - - table = rzalloc_array(ht, struct hash_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; - - hash_table_foreach(&old_ht, entry) { - _mesa_hash_table_insert(ht, entry->hash, - entry->key, entry->data); - } - - 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 hash_entry * -_mesa_hash_table_insert(struct hash_table *ht, uint32_t hash, - const void *key, void *data) -{ - uint32_t start_hash_address, hash_address; - - if (ht->entries >= ht->max_entries) { - _mesa_hash_table_rehash(ht, ht->size_index + 1); - } else if (ht->deleted_entries + ht->entries >= ht->max_entries) { - _mesa_hash_table_rehash(ht, ht->size_index); - } - - start_hash_address = hash % ht->size; - hash_address = start_hash_address; - do { - struct hash_entry *entry = ht->table + hash_address; - uint32_t double_hash; - - if (!entry_is_present(ht, entry)) { - if (entry_is_deleted(ht, entry)) - ht->deleted_entries--; - entry->hash = hash; - entry->key = key; - entry->data = data; - 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 data pointers 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; - entry->data = data; - return entry; - } - - - double_hash = 1 + hash % ht->rehash; - - hash_address = (hash_address + double_hash) % ht->size; - } while (hash_address != start_hash_address); - - /* 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_hash_table_remove(struct hash_table *ht, - struct hash_entry *entry) -{ - if (!entry) - return; - - entry->key = ht->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 hash_entry * -_mesa_hash_table_next_entry(struct hash_table *ht, - struct hash_entry *entry) -{ - if (entry == NULL) - entry = ht->table; - else - entry = entry + 1; - - for (; entry != ht->table + ht->size; entry++) { - if (entry_is_present(ht, entry)) { - return entry; - } - } - - return NULL; -} - -/** - * Returns a random entry from the hash table. - * - * This may be useful in implementing random replacement (as opposed - * to just removing everything) in caches based on this hash table - * implementation. @predicate may be used to filter entries, or may - * be set to NULL for no filtering. - */ -struct hash_entry * -_mesa_hash_table_random_entry(struct hash_table *ht, - bool (*predicate)(struct hash_entry *entry)) -{ - struct hash_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(ht, entry) && - (!predicate || predicate(entry))) { - return entry; - } - } - - for (entry = ht->table; entry != ht->table + i; entry++) { - if (entry_is_present(ht, entry) && - (!predicate || predicate(entry))) { - return entry; - } - } - - return NULL; -} - - -/** - * Quick FNV-1 hash implementation based on: - * http://www.isthe.com/chongo/tech/comp/fnv/ - * - * FNV-1 is not be the best hash out there -- Jenkins's lookup3 is supposed to - * be quite good, and it probably beats FNV. But FNV has the advantage that - * it involves almost no code. For an improvement on both, see Paul - * Hsieh's http://www.azillionmonkeys.com/qed/hash.html - */ -uint32_t -_mesa_hash_data(const void *data, size_t size) -{ - uint32_t hash = 2166136261ul; - const uint8_t *bytes = data; - - while (size-- != 0) { - hash ^= *bytes; - hash = hash * 0x01000193; - bytes++; - } - - return hash; -} - -/** FNV-1 string hash implementation */ -uint32_t -_mesa_hash_string(const char *key) -{ - uint32_t hash = 2166136261ul; - - while (*key != 0) { - hash ^= *key; - hash = hash * 0x01000193; - key++; - } - - return hash; -} - -/** - * String compare function for use as the comparison callback in - * _mesa_hash_table_create(). - */ -bool -_mesa_key_string_equal(const void *a, const void *b) -{ - return strcmp(a, b) == 0; -} - -bool -_mesa_key_pointer_equal(const void *a, const void *b) -{ - return a == b; -} diff --git a/mesalib/src/mesa/main/hash_table.h b/mesalib/src/mesa/main/hash_table.h deleted file mode 100644 index f51131aee..000000000 --- a/mesalib/src/mesa/main/hash_table.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 _HASH_TABLE_H -#define _HASH_TABLE_H - -#include <inttypes.h> -#include <stdbool.h> - -#include "compiler.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct hash_entry { - uint32_t hash; - const void *key; - void *data; -}; - -struct hash_table { - struct hash_entry *table; - bool (*key_equals_function)(const void *a, const void *b); - const void *deleted_key; - uint32_t size; - uint32_t rehash; - uint32_t max_entries; - uint32_t size_index; - uint32_t entries; - uint32_t deleted_entries; -}; - -struct hash_table * -_mesa_hash_table_create(void *mem_ctx, - bool (*key_equals_function)(const void *a, - const void *b)); -void _mesa_hash_table_destroy(struct hash_table *ht, - void (*delete_function)(struct hash_entry *entry)); -void _mesa_hash_table_set_deleted_key(struct hash_table *ht, - const void *deleted_key); - -struct hash_entry * -_mesa_hash_table_insert(struct hash_table *ht, uint32_t hash, - const void *key, void *data); -struct hash_entry * -_mesa_hash_table_search(struct hash_table *ht, uint32_t hash, - const void *key); -void _mesa_hash_table_remove(struct hash_table *ht, - struct hash_entry *entry); - -struct hash_entry *_mesa_hash_table_next_entry(struct hash_table *ht, - struct hash_entry *entry); -struct hash_entry * -_mesa_hash_table_random_entry(struct hash_table *ht, - bool (*predicate)(struct hash_entry *entry)); - -uint32_t _mesa_hash_data(const void *data, size_t size); -uint32_t _mesa_hash_string(const char *key); -bool _mesa_key_string_equal(const void *a, const void *b); -bool _mesa_key_pointer_equal(const void *a, const void *b); - -static inline uint32_t _mesa_hash_pointer(const void *pointer) -{ - return _mesa_hash_data(&pointer, sizeof(pointer)); -} - -/** - * This foreach function is safe against deletion (which just replaces - * an entry's data with the deleted marker), but not against insertion - * (which may rehash the table, making entry a dangling pointer). - */ -#define hash_table_foreach(ht, entry) \ - for (entry = _mesa_hash_table_next_entry(ht, NULL); \ - entry != NULL; \ - entry = _mesa_hash_table_next_entry(ht, entry)) - -#ifdef __cplusplus -} /* extern C */ -#endif - -#endif /* _HASH_TABLE_H */ diff --git a/mesalib/src/mesa/main/imports.h b/mesalib/src/mesa/main/imports.h index 09e55ebf0..59fd19c36 100644 --- a/mesalib/src/mesa/main/imports.h +++ b/mesalib/src/mesa/main/imports.h @@ -164,7 +164,6 @@ INV_SQRTF(float x) ***/ static inline GLfloat LOG2(GLfloat x) { -#ifdef USE_IEEE #if 0 /* This is pretty fast, but not accurate enough (only 2 fractional bits). * Based on code from http://www.stereopsis.com/log2.html @@ -186,13 +185,6 @@ static inline GLfloat LOG2(GLfloat x) num.i += 127 << 23; num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3; return num.f + log_2; -#else - /* - * NOTE: log_base_2(x) = log(x) / log(2) - * NOTE: 1.442695 = 1/log(2). - */ - return (GLfloat) (log(x) * 1.442695F); -#endif } @@ -200,14 +192,7 @@ static inline GLfloat LOG2(GLfloat x) /*** *** IS_INF_OR_NAN: test if float is infinite or NaN ***/ -#ifdef USE_IEEE -static inline int IS_INF_OR_NAN( float x ) -{ - fi_type tmp; - tmp.f = x; - return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31); -} -#elif defined(isfinite) +#if defined(isfinite) #define IS_INF_OR_NAN(x) (!isfinite(x)) #elif defined(finite) #define IS_INF_OR_NAN(x) (!finite(x)) @@ -321,7 +306,7 @@ static inline int IFLOOR(float f) __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st"); __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st"); return (ai - bi) >> 1; -#elif defined(USE_IEEE) +#else int ai, bi; double af, bf; fi_type u; @@ -330,9 +315,6 @@ static inline int IFLOOR(float f) u.f = (float) af; ai = u.i; u.f = (float) bf; bi = u.i; return (ai - bi) >> 1; -#else - int i = IROUND(f); - return (i > f) ? i - 1 : i; #endif } @@ -356,7 +338,7 @@ static inline int ICEIL(float f) __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st"); __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st"); return (ai - bi + 1) >> 1; -#elif defined(USE_IEEE) +#else int ai, bi; double af, bf; fi_type u; @@ -365,9 +347,6 @@ static inline int ICEIL(float f) u.f = (float) af; ai = u.i; u.f = (float) bf; bi = u.i; return (ai - bi + 1) >> 1; -#else - int i = IROUND(f); - return (i < f) ? i + 1 : i; #endif } @@ -552,6 +531,11 @@ _mesa_float_to_half(float f); extern float _mesa_half_to_float(GLhalfARB h); +static inline bool +_mesa_half_is_negative(GLhalfARB h) +{ + return h & 0x8000; +} extern void * _mesa_bsearch( const void *key, const void *base, size_t nmemb, size_t size, diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h index 5228c3a8f..0ba658a9a 100644 --- a/mesalib/src/mesa/main/macros.h +++ b/mesalib/src/mesa/main/macros.h @@ -140,7 +140,7 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256]; *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255] *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255] ***/ -#if defined(USE_IEEE) && !defined(DEBUG) +#ifndef DEBUG /* This function/macro is sensitive to precision. Test very carefully * if you change it! */ @@ -818,7 +818,9 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y) #define ENUM_TO_BOOLEAN(E) ((E) ? GL_TRUE : GL_FALSE) /* Compute the size of an array */ -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#endif /* Stringify */ #define STRINGIFY(x) #x diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 3f60a5530..e141ac658 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -1693,6 +1693,9 @@ struct gl_array_attrib /** One of the DRAW_xxx flags, not consumed by drivers */ gl_draw_method DrawMethod; + + /** Legal array datatypes */ + GLbitfield LegalTypesMask; }; @@ -2048,13 +2051,31 @@ typedef enum */ typedef enum { - SYSTEM_VALUE_FRONT_FACE, /**< Fragment shader only (not done yet) */ - SYSTEM_VALUE_VERTEX_ID, /**< Vertex shader only */ - SYSTEM_VALUE_INSTANCE_ID, /**< Vertex shader only */ - SYSTEM_VALUE_SAMPLE_ID, /**< Fragment shader only */ - SYSTEM_VALUE_SAMPLE_POS, /**< Fragment shader only */ - SYSTEM_VALUE_SAMPLE_MASK_IN, /**< Fragment shader only */ - SYSTEM_VALUE_INVOCATION_ID, /**< Geometry shader only */ + /** + * \name Vertex shader system values + */ + /*@{*/ + SYSTEM_VALUE_VERTEX_ID, + SYSTEM_VALUE_INSTANCE_ID, + /*@}*/ + + /** + * \name Geometry shader system values + */ + /*@{*/ + SYSTEM_VALUE_INVOCATION_ID, + /*@}*/ + + /** + * \name Fragment shader system values + */ + /*@{*/ + SYSTEM_VALUE_FRONT_FACE, /**< (not done yet) */ + SYSTEM_VALUE_SAMPLE_ID, + SYSTEM_VALUE_SAMPLE_POS, + SYSTEM_VALUE_SAMPLE_MASK_IN, + /*@}*/ + SYSTEM_VALUE_MAX /**< Number of values */ } gl_system_value; @@ -3531,6 +3552,7 @@ struct gl_extensions GLboolean ARB_color_buffer_float; GLboolean ARB_compute_shader; GLboolean ARB_conservative_depth; + GLboolean ARB_copy_image; GLboolean ARB_depth_buffer_float; GLboolean ARB_depth_clamp; GLboolean ARB_depth_texture; diff --git a/mesalib/src/mesa/main/performance_monitor.c b/mesalib/src/mesa/main/performance_monitor.c index c26eda4c6..c02910e31 100644 --- a/mesalib/src/mesa/main/performance_monitor.c +++ b/mesalib/src/mesa/main/performance_monitor.c @@ -43,7 +43,7 @@ #include "mtypes.h" #include "performance_monitor.h" #include "bitset.h" -#include "ralloc.h" +#include "util/ralloc.h" void _mesa_init_performance_monitors(struct gl_context *ctx) diff --git a/mesalib/src/mesa/main/pipelineobj.c b/mesalib/src/mesa/main/pipelineobj.c index 90c1d005f..017d4257e 100644 --- a/mesalib/src/mesa/main/pipelineobj.c +++ b/mesalib/src/mesa/main/pipelineobj.c @@ -44,7 +44,7 @@ #include "main/uniforms.h" #include "program/program.h" #include "program/prog_parameter.h" -#include "ralloc.h" +#include "util/ralloc.h" #include <stdbool.h> #include "../glsl/glsl_parser_extras.h" #include "../glsl/ir_uniform.h" diff --git a/mesalib/src/mesa/main/set.c b/mesalib/src/mesa/main/set.c index 989e5dece..52c1dabd8 100644 --- a/mesalib/src/mesa/main/set.c +++ b/mesalib/src/mesa/main/set.c @@ -36,7 +36,7 @@ #include "macros.h" #include "set.h" -#include "ralloc.h" +#include "util/ralloc.h" /* * From Knuth -- a good choice for hash/rehash values is p, p-2 where diff --git a/mesalib/src/mesa/main/shaderapi.c b/mesalib/src/mesa/main/shaderapi.c index 2bbef35d3..b4a5e7050 100644 --- a/mesalib/src/mesa/main/shaderapi.c +++ b/mesalib/src/mesa/main/shaderapi.c @@ -42,7 +42,6 @@ #include "main/dispatch.h" #include "main/enums.h" #include "main/hash.h" -#include "main/hash_table.h" #include "main/mtypes.h" #include "main/pipelineobj.h" #include "main/shaderapi.h" @@ -52,7 +51,8 @@ #include "program/program.h" #include "program/prog_print.h" #include "program/prog_parameter.h" -#include "ralloc.h" +#include "util/ralloc.h" +#include "util/hash_table.h" #include <stdbool.h> #include "../glsl/glsl_parser_extras.h" #include "../glsl/ir.h" diff --git a/mesalib/src/mesa/main/shaderobj.c b/mesalib/src/mesa/main/shaderobj.c index b9feff4a4..693e9a259 100644 --- a/mesalib/src/mesa/main/shaderobj.c +++ b/mesalib/src/mesa/main/shaderobj.c @@ -40,7 +40,7 @@ #include "program/program.h" #include "program/prog_parameter.h" #include "program/hash_table.h" -#include "ralloc.h" +#include "util/ralloc.h" /**********************************************************************/ /*** Shader object functions ***/ diff --git a/mesalib/src/mesa/main/shared.c b/mesalib/src/mesa/main/shared.c index 5ae7014b1..0189dd296 100644 --- a/mesalib/src/mesa/main/shared.c +++ b/mesalib/src/mesa/main/shared.c @@ -30,7 +30,6 @@ #include "imports.h" #include "mtypes.h" #include "hash.h" -#include "hash_table.h" #include "atifragshader.h" #include "bufferobj.h" #include "shared.h" @@ -42,6 +41,7 @@ #include "shaderobj.h" #include "syncobj.h" +#include "util/hash_table.h" /** * Allocate and initialize a shared context state structure. diff --git a/mesalib/src/mesa/main/syncobj.c b/mesalib/src/mesa/main/syncobj.c index a88d7e469..225399eda 100644 --- a/mesalib/src/mesa/main/syncobj.c +++ b/mesalib/src/mesa/main/syncobj.c @@ -64,7 +64,7 @@ #include "dispatch.h" #include "mtypes.h" #include "set.h" -#include "hash_table.h" +#include "util/hash_table.h" #include "syncobj.h" diff --git a/mesalib/src/mesa/main/texcompress_etc.c b/mesalib/src/mesa/main/texcompress_etc.c index ae973b001..98b4fe201 100644 --- a/mesalib/src/mesa/main/texcompress_etc.c +++ b/mesalib/src/mesa/main/texcompress_etc.c @@ -43,6 +43,7 @@ #include "texstore.h" #include "macros.h" #include "format_unpack.h" +#include "util/format_srgb.h" struct etc2_block { @@ -1307,9 +1308,9 @@ fetch_etc2_srgb8(const GLubyte *map, 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[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]); texel[ACOMP] = 1.0f; } @@ -1345,9 +1346,9 @@ fetch_etc2_srgb8_alpha8_eac(const GLubyte *map, 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[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]); texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); } @@ -1473,9 +1474,9 @@ fetch_etc2_srgb8_punchthrough_alpha1(const GLubyte *map, 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[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]); texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); } diff --git a/mesalib/src/mesa/main/texcompress_s3tc.c b/mesalib/src/mesa/main/texcompress_s3tc.c index 894c46de1..5b275efe0 100644 --- a/mesalib/src/mesa/main/texcompress_s3tc.c +++ b/mesalib/src/mesa/main/texcompress_s3tc.c @@ -44,6 +44,7 @@ #include "texcompress_s3tc.h" #include "texstore.h" #include "format_unpack.h" +#include "util/format_srgb.h" #if defined(_WIN32) || defined(WIN32) @@ -419,9 +420,9 @@ fetch_srgb_dxt1(const GLubyte *map, if (fetch_ext_rgb_dxt1) { GLubyte tex[4]; fetch_ext_rgb_dxt1(rowStride, map, i, j, tex); - texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]); - texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]); - texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); } else { @@ -436,9 +437,9 @@ fetch_srgba_dxt1(const GLubyte *map, if (fetch_ext_rgba_dxt1) { GLubyte tex[4]; fetch_ext_rgba_dxt1(rowStride, map, i, j, tex); - texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]); - texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]); - texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); } else { @@ -453,9 +454,9 @@ fetch_srgba_dxt3(const GLubyte *map, if (fetch_ext_rgba_dxt3) { GLubyte tex[4]; fetch_ext_rgba_dxt3(rowStride, map, i, j, tex); - texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]); - texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]); - texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); } else { @@ -470,9 +471,9 @@ fetch_srgba_dxt5(const GLubyte *map, if (fetch_ext_rgba_dxt5) { GLubyte tex[4]; fetch_ext_rgba_dxt5(rowStride, map, i, j, tex); - texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]); - texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]); - texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); } else { diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index fb2dee7d8..bb050b188 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -1770,9 +1770,9 @@ compressedteximage_only_format(const struct gl_context *ctx, GLenum format) * Helper function to determine whether a target and specific compression * format are supported. */ -static GLboolean -target_can_be_compressed(const struct gl_context *ctx, GLenum target, - GLenum intFormat) +GLboolean +_mesa_target_can_be_compressed(const struct gl_context *ctx, GLenum target, + GLenum intFormat) { (void) intFormat; /* not used yet */ @@ -1781,6 +1781,7 @@ target_can_be_compressed(const struct gl_context *ctx, GLenum target, case GL_PROXY_TEXTURE_2D: return GL_TRUE; /* true for any compressed format so far */ case GL_PROXY_TEXTURE_CUBE_MAP: + case GL_TEXTURE_CUBE_MAP: case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: @@ -2211,7 +2212,7 @@ texture_error_check( struct gl_context *ctx, /* additional checks for compressed textures */ if (_mesa_is_compressed_format(ctx, internalFormat)) { - if (!target_can_be_compressed(ctx, target, internalFormat)) { + if (!_mesa_target_can_be_compressed(ctx, target, internalFormat)) { _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%dD(target can't be compressed)", dimensions); return GL_TRUE; @@ -2297,9 +2298,16 @@ compressed_texture_error_check(struct gl_context *ctx, GLint dimensions, GLenum error = GL_NO_ERROR; char *reason = ""; /* no error */ - if (!target_can_be_compressed(ctx, target, internalFormat)) { + if (!_mesa_target_can_be_compressed(ctx, target, internalFormat)) { reason = "target"; - error = GL_INVALID_ENUM; + /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec: + * + * "The ETC2/EAC texture compression algorithm supports only + * two-dimensional images. If internalformat is an ETC2/EAC format, + * CompressedTexImage3D will generate an INVALID_OPERATION error if + * target is not TEXTURE_2D_ARRAY." + */ + error = _mesa_is_desktop_gl(ctx) ? GL_INVALID_ENUM : GL_INVALID_OPERATION; goto error; } @@ -2704,6 +2712,17 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions, "glCopyTexImage%dD(srgb usage mismatch)", dimensions); return GL_TRUE; } + + /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels + * types for SNORM formats. Also, conversion to SNORM formats is not + * allowed by Table 3.2 on Page 110. + */ + if(_mesa_is_enum_format_snorm(internalFormat)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyTexImage%dD(internalFormat=%s)", dimensions, + _mesa_lookup_enum_by_nr(internalFormat)); + return GL_TRUE; + } } if (!_mesa_source_buffer_exists(ctx, baseFormat)) { @@ -2722,6 +2741,8 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions, if (_mesa_is_color_format(internalFormat)) { bool is_int = _mesa_is_enum_format_integer(internalFormat); bool is_rbint = _mesa_is_enum_format_integer(rb_internal_format); + bool is_unorm = _mesa_is_enum_format_unorm(internalFormat); + bool is_rbunorm = _mesa_is_enum_format_unorm(rb_internal_format); if (is_int || is_rbint) { if (is_int != is_rbint) { _mesa_error(ctx, GL_INVALID_OPERATION, @@ -2735,10 +2756,23 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions, return GL_TRUE; } } + + /* From page 138 of OpenGL ES 3.0 spec: + * "The error INVALID_OPERATION is generated if floating-point RGBA + * data is required; if signed integer RGBA data is required and the + * format of the current color buffer is not signed integer; if + * unsigned integer RGBA data is required and the format of the + * current color buffer is not unsigned integer; or if fixed-point + * RGBA data is required and the format of the current color buffer + * is not fixed-point. + */ + if (_mesa_is_gles(ctx) && is_unorm != is_rbunorm) + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyTexImage%dD(unorm vs non-unorm)", dimensions); } if (_mesa_is_compressed_format(ctx, internalFormat)) { - if (!target_can_be_compressed(ctx, target, internalFormat)) { + if (!_mesa_target_can_be_compressed(ctx, target, internalFormat)) { _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage%dD(target)", dimensions); return GL_TRUE; @@ -3608,6 +3642,28 @@ copytexsubimage_by_slice(struct gl_context *ctx, } } +static GLboolean +formats_differ_in_component_sizes (mesa_format f1, + mesa_format f2) +{ + GLint f1_r_bits = _mesa_get_format_bits(f1, GL_RED_BITS); + GLint f1_g_bits = _mesa_get_format_bits(f1, GL_GREEN_BITS); + GLint f1_b_bits = _mesa_get_format_bits(f1, GL_BLUE_BITS); + GLint f1_a_bits = _mesa_get_format_bits(f1, GL_ALPHA_BITS); + + GLint f2_r_bits = _mesa_get_format_bits(f2, GL_RED_BITS); + GLint f2_g_bits = _mesa_get_format_bits(f2, GL_GREEN_BITS); + GLint f2_b_bits = _mesa_get_format_bits(f2, GL_BLUE_BITS); + GLint f2_a_bits = _mesa_get_format_bits(f2, GL_ALPHA_BITS); + + if ((f1_r_bits && f2_r_bits && f1_r_bits != f2_r_bits) + || (f1_g_bits && f2_g_bits && f1_g_bits != f2_g_bits) + || (f1_b_bits && f2_b_bits && f1_b_bits != f2_b_bits) + || (f1_a_bits && f2_a_bits && f1_a_bits != f2_a_bits)) + return GL_TRUE; + + return GL_FALSE; +} /** * Implement the glCopyTexImage1/2D() functions. @@ -3621,6 +3677,7 @@ copyteximage(struct gl_context *ctx, GLuint dims, struct gl_texture_image *texImage; const GLuint face = _mesa_tex_target_to_face(target); mesa_format texFormat; + struct gl_renderbuffer *rb; FLUSH_VERTICES(ctx, 0); @@ -3650,6 +3707,40 @@ copyteximage(struct gl_context *ctx, GLuint dims, texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, internalFormat, GL_NONE, GL_NONE); + + rb = _mesa_get_read_renderbuffer_for_format(ctx, internalFormat); + + if (_mesa_is_gles3(ctx)) { + if (_mesa_is_enum_format_unsized(internalFormat)) { + /* Conversion from GL_RGB10_A2 source buffer format is not allowed in + * OpenGL ES 3.0. Khronos bug# 9807. + */ + if (rb->InternalFormat == GL_RGB10_A2) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and" + " writing to unsized internal format)", dims); + return; + } + } + /* From Page 139 of OpenGL ES 3.0 spec: + * "If internalformat is sized, the internal format of the new texel + * array is internalformat, and this is also the new texel array’s + * effective internal format. If the component sizes of internalformat + * do not exactly match the corresponding component sizes of the source + * buffer’s effective internal format, described below, an + * INVALID_OPERATION error is generated. If internalformat is unsized, + * the internal format of the new texel array is the effective internal + * format of the source buffer, and this is also the new texel array’s + * effective internal format. + */ + else if (formats_differ_in_component_sizes (texFormat, rb->Format)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glCopyTexImage%uD(componenet size changed in" + " internal format)", dims); + return; + } + } + assert(texFormat != MESA_FORMAT_NONE); if (!ctx->Driver.TestProxyTexImage(ctx, proxy_target(target), diff --git a/mesalib/src/mesa/main/teximage.h b/mesalib/src/mesa/main/teximage.h index 42305f44f..52bfa7816 100644 --- a/mesalib/src/mesa/main/teximage.h +++ b/mesalib/src/mesa/main/teximage.h @@ -123,6 +123,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level, mesa_format format, GLint width, GLint height, GLint depth, GLint border); +extern GLboolean +_mesa_target_can_be_compressed(const struct gl_context *ctx, GLenum target, + GLenum intFormat); extern GLuint _mesa_tex_target_to_face(GLenum target); diff --git a/mesalib/src/mesa/main/texstorage.c b/mesalib/src/mesa/main/texstorage.c index 86c8f3c92..897d5891a 100644 --- a/mesalib/src/mesa/main/texstorage.c +++ b/mesalib/src/mesa/main/texstorage.c @@ -41,6 +41,7 @@ #include "texstorage.h" #include "textureview.h" #include "mtypes.h" +#include "glformats.h" @@ -53,6 +54,13 @@ static GLboolean legal_texobj_target(struct gl_context *ctx, GLuint dims, GLenum target) { + if (_mesa_is_gles3(ctx) + && target != GL_TEXTURE_2D + && target != GL_TEXTURE_CUBE_MAP + && target != GL_TEXTURE_3D + && target != GL_TEXTURE_2D_ARRAY) + return GL_FALSE; + switch (dims) { case 1: switch (target) { @@ -294,6 +302,23 @@ tex_storage_error_check(struct gl_context *ctx, GLuint dims, GLenum target, return GL_TRUE; } + /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec: + * + * "The ETC2/EAC texture compression algorithm supports only + * two-dimensional images. If internalformat is an ETC2/EAC format, + * CompressedTexImage3D will generate an INVALID_OPERATION error if + * target is not TEXTURE_2D_ARRAY." + * + * This should also be applicable for glTexStorage3D(). + */ + if (_mesa_is_compressed_format(ctx, internalformat) + && !_mesa_target_can_be_compressed(ctx, target, internalformat)) { + _mesa_error(ctx, _mesa_is_desktop_gl(ctx)? + GL_INVALID_ENUM : GL_INVALID_OPERATION, + "glTexStorage3D(internalformat = %s)", + _mesa_lookup_enum_by_nr(internalformat)); + } + /* levels check */ if (levels < 1) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexStorage%uD(levels < 1)", diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c index aea53f8d1..0e036d9eb 100644 --- a/mesalib/src/mesa/main/texstore.c +++ b/mesalib/src/mesa/main/texstore.c @@ -55,6 +55,7 @@ #include "bufferobj.h" #include "colormac.h" #include "format_pack.h" +#include "format_utils.h" #include "image.h" #include "macros.h" #include "mipmap.h" @@ -87,35 +88,6 @@ enum { typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS); -/** - * Return GL_TRUE if the given image format is one that be converted - * to another format by swizzling. - */ -static GLboolean -can_swizzle(GLenum logicalBaseFormat) -{ - switch (logicalBaseFormat) { - case GL_RGBA: - case GL_RGB: - case GL_LUMINANCE_ALPHA: - case GL_INTENSITY: - case GL_ALPHA: - case GL_LUMINANCE: - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_BGR: - case GL_BGRA: - case GL_ABGR_EXT: - case GL_RG: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - - enum { IDX_LUMINANCE = 0, IDX_ALPHA, @@ -233,21 +205,44 @@ static int get_map_idx(GLenum value) { switch (value) { - case GL_LUMINANCE: return IDX_LUMINANCE; - case GL_ALPHA: return IDX_ALPHA; - case GL_INTENSITY: return IDX_INTENSITY; - case GL_LUMINANCE_ALPHA: return IDX_LUMINANCE_ALPHA; - case GL_RGB: return IDX_RGB; - case GL_RGBA: return IDX_RGBA; - case GL_RED: return IDX_RED; - case GL_GREEN: return IDX_GREEN; - case GL_BLUE: return IDX_BLUE; - case GL_BGR: return IDX_BGR; - case GL_BGRA: return IDX_BGRA; - case GL_ABGR_EXT: return IDX_ABGR; - case GL_RG: return IDX_RG; + case GL_LUMINANCE: + case GL_LUMINANCE_INTEGER_EXT: + return IDX_LUMINANCE; + case GL_ALPHA: + case GL_ALPHA_INTEGER: + return IDX_ALPHA; + case GL_INTENSITY: + return IDX_INTENSITY; + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + return IDX_LUMINANCE_ALPHA; + case GL_RGB: + case GL_RGB_INTEGER: + return IDX_RGB; + case GL_RGBA: + case GL_RGBA_INTEGER: + return IDX_RGBA; + case GL_RED: + case GL_RED_INTEGER: + return IDX_RED; + case GL_GREEN: + return IDX_GREEN; + case GL_BLUE: + return IDX_BLUE; + case GL_BGR: + case GL_BGR_INTEGER: + return IDX_BGR; + case GL_BGRA: + case GL_BGRA_INTEGER: + return IDX_BGRA; + case GL_ABGR_EXT: + return IDX_ABGR; + case GL_RG: + case GL_RG_INTEGER: + return IDX_RG; default: - _mesa_problem(NULL, "Unexpected inFormat"); + _mesa_problem(NULL, "Unexpected inFormat %s", + _mesa_lookup_enum_by_nr(value)); return 0; } } @@ -662,257 +657,9 @@ _mesa_make_temp_ubyte_image(struct gl_context *ctx, GLuint dims, } -/** - * Copy GLubyte pixels from <src> to <dst> with swizzling. - * \param dst destination pixels - * \param dstComponents number of color components in destination pixels - * \param src source pixels - * \param srcComponents number of color components in source pixels - * \param map the swizzle mapping. map[X] says where to find the X component - * in the source image's pixels. For example, if the source image - * is GL_BGRA and X = red, map[0] yields 2. - * \param count number of pixels to copy/swizzle. - */ -static void -swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src, - GLuint srcComponents, const GLubyte *map, GLuint count) -{ -#define SWZ_CPY(dst, src, count, dstComps, srcComps) \ - do { \ - GLuint i; \ - for (i = 0; i < count; i++) { \ - GLuint j; \ - if (srcComps == 4) { \ - COPY_4UBV(tmp, src); \ - } \ - else { \ - for (j = 0; j < srcComps; j++) { \ - tmp[j] = src[j]; \ - } \ - } \ - src += srcComps; \ - for (j = 0; j < dstComps; j++) { \ - dst[j] = tmp[map[j]]; \ - } \ - dst += dstComps; \ - } \ - } while (0) - - GLubyte tmp[6]; - - tmp[ZERO] = 0x0; - tmp[ONE] = 0xff; - - ASSERT(srcComponents <= 4); - ASSERT(dstComponents <= 4); - - switch (dstComponents) { - case 4: - switch (srcComponents) { - case 4: - SWZ_CPY(dst, src, count, 4, 4); - break; - case 3: - SWZ_CPY(dst, src, count, 4, 3); - break; - case 2: - SWZ_CPY(dst, src, count, 4, 2); - break; - case 1: - SWZ_CPY(dst, src, count, 4, 1); - break; - default: - ; - } - break; - case 3: - switch (srcComponents) { - case 4: - SWZ_CPY(dst, src, count, 3, 4); - break; - case 3: - SWZ_CPY(dst, src, count, 3, 3); - break; - case 2: - SWZ_CPY(dst, src, count, 3, 2); - break; - case 1: - SWZ_CPY(dst, src, count, 3, 1); - break; - default: - ; - } - break; - case 2: - switch (srcComponents) { - case 4: - SWZ_CPY(dst, src, count, 2, 4); - break; - case 3: - SWZ_CPY(dst, src, count, 2, 3); - break; - case 2: - SWZ_CPY(dst, src, count, 2, 2); - break; - case 1: - SWZ_CPY(dst, src, count, 2, 1); - break; - default: - ; - } - break; - case 1: - switch (srcComponents) { - case 4: - SWZ_CPY(dst, src, count, 1, 4); - break; - case 3: - SWZ_CPY(dst, src, count, 1, 3); - break; - case 2: - SWZ_CPY(dst, src, count, 1, 2); - break; - case 1: - SWZ_CPY(dst, src, count, 1, 1); - break; - default: - ; - } - break; - default: - ; - } -#undef SWZ_CPY -} - - - static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE }; static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE }; - - -/** - * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a - * mapping array depending on endianness. - */ -static const GLubyte * -type_mapping( GLenum srcType ) -{ - switch (srcType) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - return map_identity; - case GL_UNSIGNED_INT_8_8_8_8: - return _mesa_little_endian() ? map_3210 : map_identity; - case GL_UNSIGNED_INT_8_8_8_8_REV: - return _mesa_little_endian() ? map_identity : map_3210; - default: - return NULL; - } -} - - -/** - * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a - * mapping array depending on pixelstore byte swapping state. - */ -static const GLubyte * -byteswap_mapping( GLboolean swapBytes, - GLenum srcType ) -{ - if (!swapBytes) - return map_identity; - - switch (srcType) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - return map_identity; - case GL_UNSIGNED_INT_8_8_8_8: - case GL_UNSIGNED_INT_8_8_8_8_REV: - return map_3210; - default: - return NULL; - } -} - - - -/** - * Transfer a GLubyte texture image with component swizzling. - */ -static void -_mesa_swizzle_ubyte_image(struct gl_context *ctx, - GLuint dimensions, - GLenum srcFormat, - GLenum srcType, - - GLenum baseInternalFormat, - - const GLubyte *rgba2dst, - GLuint dstComponents, - - GLint dstRowStride, - GLubyte **dstSlices, - - GLint srcWidth, GLint srcHeight, GLint srcDepth, - const GLvoid *srcAddr, - const struct gl_pixelstore_attrib *srcPacking ) -{ - GLint srcComponents = _mesa_components_in_format(srcFormat); - const GLubyte *srctype2ubyte, *swap; - GLubyte map[4], src2base[6], base2rgba[6]; - GLint i; - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, - srcFormat, GL_UNSIGNED_BYTE); - const GLint srcImageStride - = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat, - GL_UNSIGNED_BYTE); - const GLubyte *srcImage - = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr, - srcWidth, srcHeight, srcFormat, - GL_UNSIGNED_BYTE, 0, 0, 0); - - (void) ctx; - - /* Translate from src->baseInternal->GL_RGBA->dst. This will - * correctly deal with RGBA->RGB->RGBA conversions where the final - * A value must be 0xff regardless of the incoming alpha values. - */ - compute_component_mapping(srcFormat, baseInternalFormat, src2base); - compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba); - swap = byteswap_mapping(srcPacking->SwapBytes, srcType); - srctype2ubyte = type_mapping(srcType); - - - for (i = 0; i < 4; i++) - map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]]; - -/* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */ - - if (srcComponents == dstComponents && - srcRowStride == dstRowStride && - srcRowStride == srcWidth * srcComponents && - dimensions < 3) { - /* 1 and 2D images only */ - GLubyte *dstImage = dstSlices[0]; - swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map, - srcWidth * srcHeight); - } - else { - GLint img, row; - for (img = 0; img < srcDepth; img++) { - const GLubyte *srcRow = srcImage; - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth); - dstRow += dstRowStride; - srcRow += srcRowStride; - } - srcImage += srcImageStride; - } - } -} +static const GLubyte map_1032[6] = { 1, 0, 3, 2, ZERO, ONE }; /** @@ -988,6 +735,10 @@ store_ubyte_texture(TEXSTORE_PARAMS) if (!tempImage) return GL_FALSE; + /* This way we will use the RGB versions of the packing functions and it + * will work for both RGB and sRGB textures*/ + dstFormat = _mesa_get_srgb_format_linear(dstFormat); + src = tempImage; for (img = 0; img < srcDepth; img++) { _mesa_pack_ubyte_rgba_rect(dstFormat, srcWidth, srcHeight, @@ -1178,845 +929,13 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS) dst += dstRowStride; src += srcRowStride; } + return GL_TRUE; + } else { + return GL_FALSE; } - else { - return store_ubyte_texture(ctx, dims, baseInternalFormat, - dstFormat, dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - } - return GL_TRUE; -} - - -/** - * Store a texture in MESA_FORMAT_A8B8G8R8_UNORM or MESA_FORMAT_R8G8B8A8_UNORM. - */ -static GLboolean -_mesa_texstore_rgba8888(TEXSTORE_PARAMS) -{ - const GLboolean littleEndian = _mesa_little_endian(); - - ASSERT(dstFormat == MESA_FORMAT_A8B8G8R8_UNORM || - dstFormat == MESA_FORMAT_R8G8B8A8_UNORM || - dstFormat == MESA_FORMAT_X8B8G8R8_UNORM || - dstFormat == MESA_FORMAT_R8G8B8X8_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - if (!ctx->_ImageTransferState && - (srcType == GL_UNSIGNED_BYTE || - srcType == GL_UNSIGNED_INT_8_8_8_8 || - srcType == GL_UNSIGNED_INT_8_8_8_8_REV) && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - if ((littleEndian && (dstFormat == MESA_FORMAT_A8B8G8R8_UNORM || - dstFormat == MESA_FORMAT_X8B8G8R8_UNORM)) || - (!littleEndian && (dstFormat == MESA_FORMAT_R8G8B8A8_UNORM || - dstFormat == MESA_FORMAT_R8G8B8X8_UNORM))) { - dstmap[3] = 0; - dstmap[2] = 1; - dstmap[1] = 2; - dstmap[0] = 3; - } - else { - dstmap[3] = 3; - dstmap[2] = 2; - dstmap[1] = 1; - dstmap[0] = 0; - } - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 4, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - return store_ubyte_texture(ctx, dims, baseInternalFormat, - dstFormat, dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_argb8888(TEXSTORE_PARAMS) -{ - const GLboolean littleEndian = _mesa_little_endian(); - - ASSERT(dstFormat == MESA_FORMAT_B8G8R8A8_UNORM || - dstFormat == MESA_FORMAT_A8R8G8B8_UNORM || - dstFormat == MESA_FORMAT_B8G8R8X8_UNORM || - dstFormat == MESA_FORMAT_X8R8G8B8_UNORM ); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - if (!ctx->_ImageTransferState && - !srcPacking->SwapBytes && - (dstFormat == MESA_FORMAT_B8G8R8A8_UNORM || - dstFormat == MESA_FORMAT_B8G8R8X8_UNORM) && - srcFormat == GL_RGB && - (baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB) && - srcType == GL_UNSIGNED_BYTE) { - int img, row, col; - for (img = 0; img < srcDepth; img++) { - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); - GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking, - srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0); - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *d4 = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - d4[col] = PACK_COLOR_8888(0xff, - srcRow[col * 3 + RCOMP], - srcRow[col * 3 + GCOMP], - srcRow[col * 3 + BCOMP]); - } - dstRow += dstRowStride; - srcRow += srcRowStride; - } - } - } - else if (!ctx->_ImageTransferState && - !srcPacking->SwapBytes && - dstFormat == MESA_FORMAT_B8G8R8A8_UNORM && - srcFormat == GL_LUMINANCE_ALPHA && - baseInternalFormat == GL_RGBA && - srcType == GL_UNSIGNED_BYTE) { - /* special case of storing LA -> ARGB8888 */ - int img, row, col; - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); - for (img = 0; img < srcDepth; img++) { - const GLubyte *srcRow = (const GLubyte *) - _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, - srcHeight, srcFormat, srcType, img, 0, 0); - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *d4 = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLubyte l = srcRow[col * 2 + 0], a = srcRow[col * 2 + 1]; - d4[col] = PACK_COLOR_8888(a, l, l, l); - } - dstRow += dstRowStride; - srcRow += srcRowStride; - } - } - } - else if (!ctx->_ImageTransferState && - !srcPacking->SwapBytes && - dstFormat == MESA_FORMAT_B8G8R8A8_UNORM && - srcFormat == GL_RGBA && - baseInternalFormat == GL_RGBA && - srcType == GL_UNSIGNED_BYTE) { - /* same as above case, but src data has alpha too */ - GLint img, row, col; - /* For some reason, streaming copies to write-combined regions - * are extremely sensitive to the characteristics of how the - * source data is retrieved. By reordering the source reads to - * be in-order, the speed of this operation increases by half. - * Strangely the same isn't required for the RGB path, above. - */ - for (img = 0; img < srcDepth; img++) { - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); - GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking, - srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0); - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *d4 = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - d4[col] = PACK_COLOR_8888(srcRow[col * 4 + ACOMP], - srcRow[col * 4 + RCOMP], - srcRow[col * 4 + GCOMP], - srcRow[col * 4 + BCOMP]); - } - dstRow += dstRowStride; - srcRow += srcRowStride; - } - } - } - else if (!ctx->_ImageTransferState && - (srcType == GL_UNSIGNED_BYTE || - srcType == GL_UNSIGNED_INT_8_8_8_8 || - srcType == GL_UNSIGNED_INT_8_8_8_8_REV) && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - if ((littleEndian && dstFormat == MESA_FORMAT_B8G8R8A8_UNORM) || - (littleEndian && dstFormat == MESA_FORMAT_B8G8R8X8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_A8R8G8B8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_X8R8G8B8_UNORM)) { - dstmap[3] = 3; /* alpha */ - dstmap[2] = 0; /* red */ - dstmap[1] = 1; /* green */ - dstmap[0] = 2; /* blue */ - } - else { - assert((littleEndian && dstFormat == MESA_FORMAT_A8R8G8B8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_B8G8R8A8_UNORM) || - (littleEndian && dstFormat == MESA_FORMAT_X8R8G8B8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_B8G8R8X8_UNORM)); - dstmap[3] = 2; - dstmap[2] = 1; - dstmap[1] = 0; - dstmap[0] = 3; - } - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 4, - dstRowStride, - dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - return store_ubyte_texture(ctx, dims, baseInternalFormat, - dstFormat, dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_rgb888(TEXSTORE_PARAMS) -{ - ASSERT(dstFormat == MESA_FORMAT_BGR_UNORM8); - ASSERT(_mesa_get_format_bytes(dstFormat) == 3); - - if (!ctx->_ImageTransferState && - !srcPacking->SwapBytes && - srcFormat == GL_RGBA && - srcType == GL_UNSIGNED_BYTE) { - /* extract RGB from RGBA */ - GLint img, row, col; - for (img = 0; img < srcDepth; img++) { - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); - GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking, - srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0); - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - for (col = 0; col < srcWidth; col++) { - dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP]; - dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP]; - dstRow[col * 3 + 2] = srcRow[col * 4 + RCOMP]; - } - dstRow += dstRowStride; - srcRow += srcRowStride; - } - } - } - else if (!ctx->_ImageTransferState && - srcType == GL_UNSIGNED_BYTE && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - dstmap[0] = 2; - dstmap[1] = 1; - dstmap[2] = 0; - dstmap[3] = ONE; /* ? */ - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 3, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - return store_ubyte_texture(ctx, dims, baseInternalFormat, - dstFormat, dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_bgr888(TEXSTORE_PARAMS) -{ - ASSERT(dstFormat == MESA_FORMAT_RGB_UNORM8); - ASSERT(_mesa_get_format_bytes(dstFormat) == 3); - - if (!ctx->_ImageTransferState && - !srcPacking->SwapBytes && - srcFormat == GL_RGBA && - srcType == GL_UNSIGNED_BYTE) { - /* extract BGR from RGBA */ - int img, row, col; - for (img = 0; img < srcDepth; img++) { - const GLint srcRowStride = - _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); - GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking, - srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0); - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - for (col = 0; col < srcWidth; col++) { - dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP]; - dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP]; - dstRow[col * 3 + 2] = srcRow[col * 4 + BCOMP]; - } - dstRow += dstRowStride; - srcRow += srcRowStride; - } - } - } - else if (!ctx->_ImageTransferState && - srcType == GL_UNSIGNED_BYTE && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - dstmap[0] = 0; - dstmap[1] = 1; - dstmap[2] = 2; - dstmap[3] = ONE; /* ? */ - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 3, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - return store_ubyte_texture(ctx, dims, baseInternalFormat, - dstFormat, dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_argb2101010(TEXSTORE_PARAMS) -{ - ASSERT(dstFormat == MESA_FORMAT_B10G10R10A2_UNORM || - dstFormat == MESA_FORMAT_B10G10R10X2_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0 - * if the internal format is RGB. */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - GL_RGBA, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - if (baseInternalFormat == GL_RGBA || baseInternalFormat == GL_RGB) { - for (row = 0; row < srcHeight; row++) { - GLuint *dstUI = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLushort a,r,g,b; - - UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]); - UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]); - UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]); - UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]); - dstUI[col] = PACK_COLOR_2101010_US(a, r, g, b); - src += 4; - } - dstRow += dstRowStride; - } - } else { - ASSERT(0); - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** - * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats. - */ -static GLboolean -_mesa_texstore_unorm44(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_L4A4_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 1); - - { - /* general path */ - const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking); - const GLubyte *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLubyte *dstUS = (GLubyte *) dstRow; - for (col = 0; col < srcWidth; col++) { - /* src[0] is luminance, src[1] is alpha */ - dstUS[col] = PACK_COLOR_44( src[1], - src[0] ); - src += 2; - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** - * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats. - */ -static GLboolean -_mesa_texstore_unorm88(TEXSTORE_PARAMS) -{ - const GLboolean littleEndian = _mesa_little_endian(); - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_L8A8_UNORM || - dstFormat == MESA_FORMAT_A8L8_UNORM || - dstFormat == MESA_FORMAT_R8G8_UNORM || - dstFormat == MESA_FORMAT_G8R8_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 2); - - if (!ctx->_ImageTransferState && - littleEndian && - srcType == GL_UNSIGNED_BYTE && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - if (dstFormat == MESA_FORMAT_L8A8_UNORM || dstFormat == MESA_FORMAT_A8L8_UNORM) { - if ((littleEndian && dstFormat == MESA_FORMAT_L8A8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_A8L8_UNORM)) { - dstmap[0] = 0; - dstmap[1] = 3; - } - else { - dstmap[0] = 3; - dstmap[1] = 0; - } - } - else { - if ((littleEndian && dstFormat == MESA_FORMAT_R8G8_UNORM) || - (!littleEndian && dstFormat == MESA_FORMAT_G8R8_UNORM)) { - dstmap[0] = 0; - dstmap[1] = 1; - } - else { - dstmap[0] = 1; - dstmap[1] = 0; - } - } - dstmap[2] = ZERO; /* ? */ - dstmap[3] = ONE; /* ? */ - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 2, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - /* general path */ - const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking); - const GLubyte *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLushort *dstUS = (GLushort *) dstRow; - if (dstFormat == MESA_FORMAT_L8A8_UNORM || - dstFormat == MESA_FORMAT_R8G8_UNORM) { - for (col = 0; col < srcWidth; col++) { - /* src[0] is luminance (or R), src[1] is alpha (or G) */ - dstUS[col] = PACK_COLOR_88( src[1], - src[0] ); - src += 2; - } - } - else { - for (col = 0; col < srcWidth; col++) { - /* src[0] is luminance (or R), src[1] is alpha (or G) */ - dstUS[col] = PACK_COLOR_88_REV( src[1], - src[0] ); - src += 2; - } - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** - * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats. - */ -static GLboolean -_mesa_texstore_unorm1616(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_L16A16_UNORM || - dstFormat == MESA_FORMAT_A16L16_UNORM || - dstFormat == MESA_FORMAT_R16G16_UNORM || - dstFormat == MESA_FORMAT_G16R16_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *dstUI = (GLuint *) dstRow; - if (dstFormat == MESA_FORMAT_L16A16_UNORM || - dstFormat == MESA_FORMAT_R16G16_UNORM) { - for (col = 0; col < srcWidth; col++) { - GLushort l, a; - - UNCLAMPED_FLOAT_TO_USHORT(l, src[0]); - UNCLAMPED_FLOAT_TO_USHORT(a, src[1]); - dstUI[col] = PACK_COLOR_1616(a, l); - src += 2; - } - } - else { - for (col = 0; col < srcWidth; col++) { - GLushort l, a; - - UNCLAMPED_FLOAT_TO_USHORT(l, src[0]); - UNCLAMPED_FLOAT_TO_USHORT(a, src[1]); - dstUI[col] = PACK_COLOR_1616_REV(a, l); - src += 2; - } - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* Texstore for R16, A16, L16, I16. */ -static GLboolean -_mesa_texstore_unorm16(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_R_UNORM16 || - dstFormat == MESA_FORMAT_A_UNORM16 || - dstFormat == MESA_FORMAT_L_UNORM16 || - dstFormat == MESA_FORMAT_I_UNORM16); - ASSERT(_mesa_get_format_bytes(dstFormat) == 2); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLushort r; - - UNCLAMPED_FLOAT_TO_USHORT(r, src[0]); - dstUS[col] = r; - src += 1; - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_rgba_16(TEXSTORE_PARAMS) -{ - ASSERT(dstFormat == MESA_FORMAT_RGBA_UNORM16 || - dstFormat == MESA_FORMAT_RGBX_UNORM16); - ASSERT(_mesa_get_format_bytes(dstFormat) == 8); - - { - /* general path */ - /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0 - * if the internal format is RGB. */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - GL_RGBA, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - - if (!tempImage) - return GL_FALSE; - - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLushort *dstUS = (GLushort *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLushort r, g, b, a; - - UNCLAMPED_FLOAT_TO_USHORT(r, src[0]); - UNCLAMPED_FLOAT_TO_USHORT(g, src[1]); - UNCLAMPED_FLOAT_TO_USHORT(b, src[2]); - UNCLAMPED_FLOAT_TO_USHORT(a, src[3]); - dstUS[col*4+0] = r; - dstUS[col*4+1] = g; - dstUS[col*4+2] = b; - dstUS[col*4+3] = a; - src += 4; - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_RGB_SNORM16 || - dstFormat == MESA_FORMAT_RGBA_SNORM16 || - dstFormat == MESA_FORMAT_RGBX_SNORM16); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2; - GLint img, row, col; - - if (!tempImage) - return GL_FALSE; - - /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2, - * 3 or 4 components/pixel here. - */ - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLshort *dstRowS = (GLshort *) dstRow; - if (dstFormat == MESA_FORMAT_RGBA_SNORM16) { - for (col = 0; col < srcWidth; col++) { - GLuint c; - for (c = 0; c < comps; c++) { - GLshort p; - UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]); - dstRowS[col * comps + c] = p; - } - } - dstRow += dstRowStride; - src += 4 * srcWidth; - } - else if (dstFormat == MESA_FORMAT_RGBX_SNORM16) { - for (col = 0; col < srcWidth; col++) { - GLuint c; - - for (c = 0; c < 3; c++) { - GLshort p; - UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 3 + c]); - dstRowS[col * comps + c] = p; - } - dstRowS[col * comps + 3] = 32767; - } - dstRow += dstRowStride; - src += 3 * srcWidth; - } - else { - for (col = 0; col < srcWidth; col++) { - GLuint c; - for (c = 0; c < comps; c++) { - GLshort p; - UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 3 + c]); - dstRowS[col * comps + c] = p; - } - } - dstRow += dstRowStride; - src += 3 * srcWidth; - } - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** - * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8. - */ -static GLboolean -_mesa_texstore_unorm8(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_A_UNORM8 || - dstFormat == MESA_FORMAT_L_UNORM8 || - dstFormat == MESA_FORMAT_I_UNORM8 || - dstFormat == MESA_FORMAT_R_UNORM8); - ASSERT(_mesa_get_format_bytes(dstFormat) == 1); - - if (!ctx->_ImageTransferState && - srcType == GL_UNSIGNED_BYTE && - can_swizzle(baseInternalFormat) && - can_swizzle(srcFormat)) { - GLubyte dstmap[4]; - - /* dstmap - how to swizzle from RGBA to dst format: - */ - if (dstFormat == MESA_FORMAT_A_UNORM8) { - dstmap[0] = 3; - } - else { - dstmap[0] = 0; - } - dstmap[1] = ZERO; /* ? */ - dstmap[2] = ZERO; /* ? */ - dstmap[3] = ONE; /* ? */ - - _mesa_swizzle_ubyte_image(ctx, dims, - srcFormat, - srcType, - baseInternalFormat, - dstmap, 1, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, srcAddr, - srcPacking); - } - else { - /* general path */ - const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking); - const GLubyte *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - for (col = 0; col < srcWidth; col++) { - dstRow[col] = src[col]; - } - dstRow += dstRowStride; - src += srcWidth; - } - } - free((void *) tempImage); - } - return GL_TRUE; } - /** * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV. */ @@ -2063,330 +982,6 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS) /** - * Store a texture in a signed normalized 8-bit format. - */ -static GLboolean -_mesa_texstore_snorm8(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_A_SNORM8 || - dstFormat == MESA_FORMAT_L_SNORM8 || - dstFormat == MESA_FORMAT_I_SNORM8 || - dstFormat == MESA_FORMAT_R_SNORM8); - ASSERT(_mesa_get_format_bytes(dstFormat) == 1); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLbyte *dstRow = (GLbyte *) dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - for (col = 0; col < srcWidth; col++) { - dstRow[col] = FLOAT_TO_BYTE_TEX(src[col]); - } - dstRow += dstRowStride; - src += srcWidth; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** - * Store a texture in a signed normalized two-channel 16-bit format. - */ -static GLboolean -_mesa_texstore_snorm88(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_L8A8_SNORM || - dstFormat == MESA_FORMAT_G8R8_SNORM || - dstFormat == MESA_FORMAT_R8G8_SNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 2); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLbyte *dstRow = (GLbyte *) dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLushort *dst = (GLushort *) dstRow; - - if (dstFormat == MESA_FORMAT_L8A8_SNORM || - dstFormat == MESA_FORMAT_R8G8_SNORM) { - for (col = 0; col < srcWidth; col++) { - GLubyte l = FLOAT_TO_BYTE_TEX(src[0]); - GLubyte a = FLOAT_TO_BYTE_TEX(src[1]); - - dst[col] = PACK_COLOR_88_REV(l, a); - src += 2; - } - } else { - for (col = 0; col < srcWidth; col++) { - GLubyte l = FLOAT_TO_BYTE_TEX(src[0]); - GLubyte a = FLOAT_TO_BYTE_TEX(src[1]); - - dst[col] = PACK_COLOR_88(l, a); - src += 2; - } - } - - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - -/* Texstore for signed R16, A16, L16, I16. */ -static GLboolean -_mesa_texstore_snorm16(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_R_SNORM16 || - dstFormat == MESA_FORMAT_A_SNORM16 || - dstFormat == MESA_FORMAT_L_SNORM16 || - dstFormat == MESA_FORMAT_I_SNORM16); - ASSERT(_mesa_get_format_bytes(dstFormat) == 2); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLshort *dstUS = (GLshort *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLushort r; - - UNCLAMPED_FLOAT_TO_SHORT(r, src[0]); - dstUS[col] = r; - src += 1; - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - -/** - * Do texstore for 2-channel, 16-bit/channel, signed normalized formats. - */ -static GLboolean -_mesa_texstore_snorm1616(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_LA_SNORM16 || - dstFormat == MESA_FORMAT_G16R16_SNORM || - dstFormat == MESA_FORMAT_R16G16_SNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *dst = (GLuint *) dstRow; - - if (dstFormat == MESA_FORMAT_LA_SNORM16 || - dstFormat == MESA_FORMAT_R16G16_SNORM) { - for (col = 0; col < srcWidth; col++) { - GLushort l, a; - - UNCLAMPED_FLOAT_TO_SHORT(l, src[0]); - UNCLAMPED_FLOAT_TO_SHORT(a, src[1]); - dst[col] = PACK_COLOR_1616_REV(l, a); - src += 2; - } - } else { - for (col = 0; col < srcWidth; col++) { - GLushort l, a; - - UNCLAMPED_FLOAT_TO_SHORT(l, src[0]); - UNCLAMPED_FLOAT_TO_SHORT(a, src[1]); - dst[col] = PACK_COLOR_1616_REV(l, a); - src += 2; - } - } - - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - -/** - * Store a texture in MESA_FORMAT_X8B8G8R8_SNORM or - * MESA_FORMAT_R8G8B8X8_SNORM. - */ -static GLboolean -_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_X8B8G8R8_SNORM || - dstFormat == MESA_FORMAT_R8G8B8X8_SNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *srcRow = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLbyte *dstRow = (GLbyte *) dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLbyte *dst = dstRow; - if (dstFormat == MESA_FORMAT_X8B8G8R8_SNORM) { - for (col = 0; col < srcWidth; col++) { - dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]); - dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]); - dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]); - dst[0] = 127; - srcRow += 3; - dst += 4; - } - } - else { - for (col = 0; col < srcWidth; col++) { - dst[0] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]); - dst[1] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]); - dst[2] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]); - dst[3] = 127; - srcRow += 3; - dst += 4; - } - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - - -/** - * Store a texture in MESA_FORMAT_A8B8G8R8_SNORM or - * MESA_FORMAT_R8G8B8A8_SNORM - */ -static GLboolean -_mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_A8B8G8R8_SNORM || - dstFormat == MESA_FORMAT_R8G8B8A8_SNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *srcRow = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLbyte *dstRow = (GLbyte *) dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLbyte *dst = dstRow; - if (dstFormat == MESA_FORMAT_A8B8G8R8_SNORM) { - for (col = 0; col < srcWidth; col++) { - dst[3] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]); - dst[2] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]); - dst[1] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]); - dst[0] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]); - srcRow += 4; - dst += 4; - } - } - else { - for (col = 0; col < srcWidth; col++) { - dst[0] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]); - dst[1] = FLOAT_TO_BYTE_TEX(srcRow[GCOMP]); - dst[2] = FLOAT_TO_BYTE_TEX(srcRow[BCOMP]); - dst[3] = FLOAT_TO_BYTE_TEX(srcRow[ACOMP]); - srcRow += 4; - dst += 4; - } - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} - - -/** * Store a combined depth/stencil texture image. */ static GLboolean @@ -2599,742 +1194,6 @@ _mesa_texstore_s8(TEXSTORE_PARAMS) } -/** - * Store an image in any of the formats: - * _mesa_texformat_rgba_float32 - * _mesa_texformat_rgb_float32 - * _mesa_texformat_alpha_float32 - * _mesa_texformat_luminance_float32 - * _mesa_texformat_luminance_alpha_float32 - * _mesa_texformat_intensity_float32 - */ -static GLboolean -_mesa_texstore_rgba_float32(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in _mesa_make_temp_float_image */ - if (dstFormat == MESA_FORMAT_RGBX_FLOAT32) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT32 || - dstFormat == MESA_FORMAT_RGB_FLOAT32 || - dstFormat == MESA_FORMAT_A_FLOAT32 || - dstFormat == MESA_FORMAT_L_FLOAT32 || - dstFormat == MESA_FORMAT_LA_FLOAT32 || - dstFormat == MESA_FORMAT_I_FLOAT32 || - dstFormat == MESA_FORMAT_R_FLOAT32 || - dstFormat == MESA_FORMAT_RG_FLOAT32 || - dstFormat == MESA_FORMAT_RGBX_FLOAT32); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_RG); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLfloat)); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *srcRow = tempImage; - GLint bytesPerRow; - GLint img, row; - if (!tempImage) - return GL_FALSE; - bytesPerRow = srcWidth * components * sizeof(GLfloat); - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - memcpy(dstRow, srcRow, bytesPerRow); - dstRow += dstRowStride; - srcRow += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - - -/** - * As above, but store 16-bit floats. - */ -static GLboolean -_mesa_texstore_rgba_float16(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in _mesa_make_temp_float_image */ - if (dstFormat == MESA_FORMAT_RGBX_FLOAT16) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT16 || - dstFormat == MESA_FORMAT_RGB_FLOAT16 || - dstFormat == MESA_FORMAT_A_FLOAT16 || - dstFormat == MESA_FORMAT_L_FLOAT16 || - dstFormat == MESA_FORMAT_LA_FLOAT16 || - dstFormat == MESA_FORMAT_I_FLOAT16 || - dstFormat == MESA_FORMAT_R_FLOAT16 || - dstFormat == MESA_FORMAT_RG_FLOAT16 || - dstFormat == MESA_FORMAT_RGBX_FLOAT16); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_RG); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLhalfARB)); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLhalfARB *dstTexel = (GLhalfARB *) dstRow; - GLint i; - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = _mesa_float_to_half(src[i]); - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, signed int8 */ -static GLboolean -_mesa_texstore_rgba_int8(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_SINT8) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_SINT8 || - dstFormat == MESA_FORMAT_RG_SINT8 || - dstFormat == MESA_FORMAT_RGB_SINT8 || - dstFormat == MESA_FORMAT_RGBA_SINT8 || - dstFormat == MESA_FORMAT_A_SINT8 || - dstFormat == MESA_FORMAT_I_SINT8 || - dstFormat == MESA_FORMAT_L_SINT8 || - dstFormat == MESA_FORMAT_LA_SINT8 || - dstFormat == MESA_FORMAT_RGBX_SINT8); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLbyte)); - - { - /* general path */ - const GLuint *tempImage = make_temp_uint_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, - srcPacking); - const GLuint *src = tempImage; - GLint img, row; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLbyte *dstTexel = (GLbyte *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLbyte) MIN2(src[i], 0x7f); - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLbyte) CLAMP((GLint) src[i], -0x80, 0x7f); - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, signed int16 */ -static GLboolean -_mesa_texstore_rgba_int16(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_SINT16) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_SINT16 || - dstFormat == MESA_FORMAT_RG_SINT16 || - dstFormat == MESA_FORMAT_RGB_SINT16 || - dstFormat == MESA_FORMAT_RGBA_SINT16 || - dstFormat == MESA_FORMAT_A_SINT16 || - dstFormat == MESA_FORMAT_L_SINT16 || - dstFormat == MESA_FORMAT_I_SINT16 || - dstFormat == MESA_FORMAT_LA_SINT16 || - dstFormat == MESA_FORMAT_RGBX_SINT16); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLshort)); - - { - /* general path */ - const GLuint *tempImage = make_temp_uint_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, - srcPacking); - const GLuint *src = tempImage; - GLint img, row; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLshort *dstTexel = (GLshort *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLshort) MIN2(src[i], 0x7fff); - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLshort)CLAMP((GLint) src[i], -0x8000, 0x7fff); - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, signed int32 */ -static GLboolean -_mesa_texstore_rgba_int32(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_SINT32) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_SINT32 || - dstFormat == MESA_FORMAT_RG_SINT32 || - dstFormat == MESA_FORMAT_RGB_SINT32 || - dstFormat == MESA_FORMAT_RGBA_SINT32 || - dstFormat == MESA_FORMAT_A_SINT32 || - dstFormat == MESA_FORMAT_I_SINT32 || - dstFormat == MESA_FORMAT_L_SINT32 || - dstFormat == MESA_FORMAT_LA_SINT32 || - dstFormat == MESA_FORMAT_RGBX_SINT32); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLint)); - - { - /* general path */ - const GLuint *tempImage = make_temp_uint_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, - srcPacking); - const GLuint *src = tempImage; - GLint img, row; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLint *dstTexel = (GLint *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLint) MIN2(src[i], 0x7fffffff); - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLint) src[i]; - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, unsigned int8 */ -static GLboolean -_mesa_texstore_rgba_uint8(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_UINT8) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_UINT8 || - dstFormat == MESA_FORMAT_RG_UINT8 || - dstFormat == MESA_FORMAT_RGB_UINT8 || - dstFormat == MESA_FORMAT_RGBA_UINT8 || - dstFormat == MESA_FORMAT_A_UINT8 || - dstFormat == MESA_FORMAT_I_UINT8 || - dstFormat == MESA_FORMAT_L_UINT8 || - dstFormat == MESA_FORMAT_LA_UINT8 || - dstFormat == MESA_FORMAT_RGBX_UINT8); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLubyte)); - - { - /* general path */ - const GLuint *tempImage = - make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - const GLuint *src = tempImage; - GLint img, row; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLubyte *dstTexel = (GLubyte *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLubyte) MIN2(src[i], 0xff); - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLubyte) CLAMP((GLint) src[i], 0, 0xff); - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, unsigned int16 */ -static GLboolean -_mesa_texstore_rgba_uint16(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_UINT16) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_UINT16 || - dstFormat == MESA_FORMAT_RG_UINT16 || - dstFormat == MESA_FORMAT_RGB_UINT16 || - dstFormat == MESA_FORMAT_RGBA_UINT16 || - dstFormat == MESA_FORMAT_A_UINT16 || - dstFormat == MESA_FORMAT_I_UINT16 || - dstFormat == MESA_FORMAT_L_UINT16 || - dstFormat == MESA_FORMAT_LA_UINT16 || - dstFormat == MESA_FORMAT_RGBX_UINT16); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLushort)); - - { - /* general path */ - const GLuint *tempImage = - make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - const GLuint *src = tempImage; - GLint img, row; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLushort *dstTexel = (GLushort *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLushort) MIN2(src[i], 0xffff); - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = (GLushort) CLAMP((GLint) src[i], 0, 0xffff); - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -/* non-normalized, unsigned int32 */ -static GLboolean -_mesa_texstore_rgba_uint32(TEXSTORE_PARAMS) -{ - GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - GLint components = _mesa_components_in_format(baseFormat); - - /* this forces alpha to 1 in make_temp_uint_image */ - if (dstFormat == MESA_FORMAT_RGBX_UINT32) { - baseFormat = GL_RGBA; - components = 4; - } - - ASSERT(dstFormat == MESA_FORMAT_R_UINT32 || - dstFormat == MESA_FORMAT_RG_UINT32 || - dstFormat == MESA_FORMAT_RGB_UINT32 || - dstFormat == MESA_FORMAT_RGBA_UINT32 || - dstFormat == MESA_FORMAT_A_UINT32 || - dstFormat == MESA_FORMAT_I_UINT32 || - dstFormat == MESA_FORMAT_L_UINT32 || - dstFormat == MESA_FORMAT_LA_UINT32 || - dstFormat == MESA_FORMAT_RGBX_UINT32); - ASSERT(baseInternalFormat == GL_RGBA || - baseInternalFormat == GL_RGB || - baseInternalFormat == GL_RG || - baseInternalFormat == GL_RED || - baseInternalFormat == GL_ALPHA || - baseInternalFormat == GL_LUMINANCE || - baseInternalFormat == GL_LUMINANCE_ALPHA || - baseInternalFormat == GL_INTENSITY); - ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLuint)); - - { - /* general path */ - const GLuint *tempImage = - make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - const GLuint *src = tempImage; - GLboolean is_unsigned = _mesa_is_type_unsigned(srcType); - GLint img, row; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *dstTexel = (GLuint *) dstRow; - GLint i; - if (is_unsigned) { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = src[i]; - } - } else { - for (i = 0; i < srcWidth * components; i++) { - dstTexel[i] = MAX2((GLint) src[i], 0); - } - } - dstRow += dstRowStride; - src += srcWidth * components; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - -static GLboolean -_mesa_texstore_srgb8(TEXSTORE_PARAMS) -{ - mesa_format newDstFormat; - GLboolean k; - - ASSERT(dstFormat == MESA_FORMAT_BGR_SRGB8); - - /* reuse normal rgb texstore code */ - newDstFormat = MESA_FORMAT_BGR_UNORM8; - - k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat, - newDstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, srcPacking); - return k; -} - - -static GLboolean -_mesa_texstore_srgba8(TEXSTORE_PARAMS) -{ - mesa_format newDstFormat; - GLboolean k; - - ASSERT(dstFormat == MESA_FORMAT_A8B8G8R8_SRGB || - dstFormat == MESA_FORMAT_R8G8B8X8_SRGB || - dstFormat == MESA_FORMAT_R8G8B8A8_SRGB); - - newDstFormat = _mesa_get_srgb_format_linear(dstFormat); - - k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat, - newDstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, srcPacking); - return k; -} - - -static GLboolean -_mesa_texstore_sargb8(TEXSTORE_PARAMS) -{ - mesa_format newDstFormat; - GLboolean k; - - assert(dstFormat == MESA_FORMAT_B8G8R8A8_SRGB || - dstFormat == MESA_FORMAT_B8G8R8X8_SRGB); - - newDstFormat = _mesa_get_srgb_format_linear(dstFormat); - - k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat, - newDstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, srcPacking); - return k; -} - - -static GLboolean -_mesa_texstore_sl8(TEXSTORE_PARAMS) -{ - mesa_format newDstFormat; - GLboolean k; - - ASSERT(dstFormat == MESA_FORMAT_L_SRGB8); - - newDstFormat = MESA_FORMAT_L_UNORM8; - - /* _mesa_textore_a8 handles luminance8 too */ - k = _mesa_texstore_unorm8(ctx, dims, baseInternalFormat, - newDstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, srcPacking); - return k; -} - - -static GLboolean -_mesa_texstore_sla8(TEXSTORE_PARAMS) -{ - mesa_format newDstFormat; - GLboolean k; - - ASSERT(dstFormat == MESA_FORMAT_L8A8_SRGB); - - /* reuse normal luminance/alpha texstore code */ - newDstFormat = MESA_FORMAT_L8A8_UNORM; - - k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat, - newDstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, - srcAddr, srcPacking); - return k; -} - -static GLboolean -_mesa_texstore_rgb9_e5(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_R9G9B9E5_FLOAT); - ASSERT(baseInternalFormat == GL_RGB); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *srcRow = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *dstUI = (GLuint*)dstRow; - for (col = 0; col < srcWidth; col++) { - dstUI[col] = float3_to_rgb9e5(&srcRow[col * 3]); - } - dstRow += dstRowStride; - srcRow += srcWidth * 3; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - -static GLboolean -_mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_R11G11B10_FLOAT); - ASSERT(baseInternalFormat == GL_RGB); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *srcRow = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - for (row = 0; row < srcHeight; row++) { - GLuint *dstUI = (GLuint*)dstRow; - for (col = 0; col < srcWidth; col++) { - dstUI[col] = float3_to_r11g11b10f(&srcRow[col * 3]); - } - dstRow += dstRowStride; - srcRow += srcWidth * 3; - } - } - - free((void *) tempImage); - } - return GL_TRUE; -} - - static GLboolean _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS) { @@ -3496,118 +1355,16 @@ _mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS) return GL_TRUE; } -static GLboolean -_mesa_texstore_abgr2101010(TEXSTORE_PARAMS) -{ - const GLenum baseFormat = _mesa_get_format_base_format(dstFormat); - - ASSERT(dstFormat == MESA_FORMAT_R10G10B10A2_UNORM); - ASSERT(_mesa_get_format_bytes(dstFormat) == 4); - - { - /* general path */ - const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims, - baseInternalFormat, - baseFormat, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, - srcPacking, - ctx->_ImageTransferState); - const GLfloat *src = tempImage; - GLint img, row, col; - if (!tempImage) - return GL_FALSE; - for (img = 0; img < srcDepth; img++) { - GLubyte *dstRow = dstSlices[img]; - - for (row = 0; row < srcHeight; row++) { - GLuint *dstUI = (GLuint *) dstRow; - for (col = 0; col < srcWidth; col++) { - GLushort a,r,g,b; - - UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]); - UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]); - UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]); - UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]); - dstUI[col] = PACK_COLOR_2101010_US(a, b, g, r); - src += 4; - } - dstRow += dstRowStride; - } - } - free((void *) tempImage); - } - return GL_TRUE; -} static GLboolean -_mesa_texstore_null(TEXSTORE_PARAMS) -{ - (void) ctx; (void) dims; - (void) baseInternalFormat; - (void) dstFormat; - (void) dstRowStride; (void) dstSlices, - (void) srcWidth; (void) srcHeight; (void) srcDepth; - (void) srcFormat; (void) srcType; - (void) srcAddr; - (void) srcPacking; - - /* should never happen */ - _mesa_problem(NULL, "_mesa_texstore_null() is called"); - return GL_FALSE; -} - - -/** - * Return the StoreTexImageFunc pointer to store an image in the given format. - */ -static StoreTexImageFunc -_mesa_get_texstore_func(mesa_format format) +texstore_depth_stencil(TEXSTORE_PARAMS) { static StoreTexImageFunc table[MESA_FORMAT_COUNT]; static GLboolean initialized = GL_FALSE; if (!initialized) { - table[MESA_FORMAT_NONE] = _mesa_texstore_null; - - table[MESA_FORMAT_A8B8G8R8_UNORM] = _mesa_texstore_rgba8888; - table[MESA_FORMAT_R8G8B8A8_UNORM] = _mesa_texstore_rgba8888; - table[MESA_FORMAT_B8G8R8A8_UNORM] = _mesa_texstore_argb8888; - table[MESA_FORMAT_A8R8G8B8_UNORM] = _mesa_texstore_argb8888; - table[MESA_FORMAT_X8B8G8R8_UNORM] = _mesa_texstore_rgba8888; - table[MESA_FORMAT_R8G8B8X8_UNORM] = _mesa_texstore_rgba8888; - table[MESA_FORMAT_B8G8R8X8_UNORM] = _mesa_texstore_argb8888; - table[MESA_FORMAT_X8R8G8B8_UNORM] = _mesa_texstore_argb8888; - table[MESA_FORMAT_BGR_UNORM8] = _mesa_texstore_rgb888; - table[MESA_FORMAT_RGB_UNORM8] = _mesa_texstore_bgr888; - table[MESA_FORMAT_B5G6R5_UNORM] = _mesa_texstore_rgb565; - table[MESA_FORMAT_R5G6B5_UNORM] = _mesa_texstore_rgb565; - table[MESA_FORMAT_B4G4R4A4_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_A4R4G4B4_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_A1B5G5R5_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_B5G5R5A1_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_A1R5G5B5_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_L4A4_UNORM] = _mesa_texstore_unorm44; - table[MESA_FORMAT_L8A8_UNORM] = _mesa_texstore_unorm88; - table[MESA_FORMAT_A8L8_UNORM] = _mesa_texstore_unorm88; - table[MESA_FORMAT_L16A16_UNORM] = _mesa_texstore_unorm1616; - table[MESA_FORMAT_A16L16_UNORM] = _mesa_texstore_unorm1616; - table[MESA_FORMAT_B2G3R3_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_A_UNORM8] = _mesa_texstore_unorm8; - table[MESA_FORMAT_A_UNORM16] = _mesa_texstore_unorm16; - table[MESA_FORMAT_L_UNORM8] = _mesa_texstore_unorm8; - table[MESA_FORMAT_L_UNORM16] = _mesa_texstore_unorm16; - table[MESA_FORMAT_I_UNORM8] = _mesa_texstore_unorm8; - table[MESA_FORMAT_I_UNORM16] = _mesa_texstore_unorm16; - table[MESA_FORMAT_YCBCR] = _mesa_texstore_ycbcr; - table[MESA_FORMAT_YCBCR_REV] = _mesa_texstore_ycbcr; - table[MESA_FORMAT_R_UNORM8] = _mesa_texstore_unorm8; - table[MESA_FORMAT_R8G8_UNORM] = _mesa_texstore_unorm88; - table[MESA_FORMAT_G8R8_UNORM] = _mesa_texstore_unorm88; - table[MESA_FORMAT_R_UNORM16] = _mesa_texstore_unorm16; - table[MESA_FORMAT_R16G16_UNORM] = _mesa_texstore_unorm1616; - table[MESA_FORMAT_G16R16_UNORM] = _mesa_texstore_unorm1616; - table[MESA_FORMAT_B10G10R10A2_UNORM] = _mesa_texstore_argb2101010; + memset(table, 0, sizeof table); + table[MESA_FORMAT_S8_UINT_Z24_UNORM] = _mesa_texstore_z24_s8; table[MESA_FORMAT_Z24_UNORM_S8_UINT] = _mesa_texstore_s8_z24; table[MESA_FORMAT_Z_UNORM16] = _mesa_texstore_z16; @@ -3615,11 +1372,28 @@ _mesa_get_texstore_func(mesa_format format) table[MESA_FORMAT_X8_UINT_Z24_UNORM] = _mesa_texstore_z24_x8; table[MESA_FORMAT_Z_UNORM32] = _mesa_texstore_z32; table[MESA_FORMAT_S_UINT8] = _mesa_texstore_s8; - table[MESA_FORMAT_BGR_SRGB8] = _mesa_texstore_srgb8; - table[MESA_FORMAT_A8B8G8R8_SRGB] = _mesa_texstore_srgba8; - table[MESA_FORMAT_B8G8R8A8_SRGB] = _mesa_texstore_sargb8; - table[MESA_FORMAT_L_SRGB8] = _mesa_texstore_sl8; - table[MESA_FORMAT_L8A8_SRGB] = _mesa_texstore_sla8; + table[MESA_FORMAT_Z_FLOAT32] = _mesa_texstore_z32; + table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = _mesa_texstore_z32f_x24s8; + + initialized = GL_TRUE; + } + + ASSERT(table[dstFormat]); + return table[dstFormat](ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); +} + +static GLboolean +texstore_compressed(TEXSTORE_PARAMS) +{ + static StoreTexImageFunc table[MESA_FORMAT_COUNT]; + static GLboolean initialized = GL_FALSE; + + if (!initialized) { + memset(table, 0, sizeof table); + table[MESA_FORMAT_SRGB_DXT1] = _mesa_texstore_rgb_dxt1; table[MESA_FORMAT_SRGBA_DXT1] = _mesa_texstore_rgba_dxt1; table[MESA_FORMAT_SRGBA_DXT3] = _mesa_texstore_rgba_dxt3; @@ -3630,32 +1404,6 @@ _mesa_get_texstore_func(mesa_format format) table[MESA_FORMAT_RGBA_DXT1] = _mesa_texstore_rgba_dxt1; table[MESA_FORMAT_RGBA_DXT3] = _mesa_texstore_rgba_dxt3; table[MESA_FORMAT_RGBA_DXT5] = _mesa_texstore_rgba_dxt5; - table[MESA_FORMAT_RGBA_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_RGBA_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_RGB_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_RGB_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_A_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_A_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_L_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_L_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_LA_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_LA_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_I_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_I_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_R_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_R_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_RG_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_RG_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_R_SNORM8] = _mesa_texstore_snorm8; - table[MESA_FORMAT_R8G8_SNORM] = _mesa_texstore_snorm88; - table[MESA_FORMAT_X8B8G8R8_SNORM] = _mesa_texstore_signed_rgbx8888; - table[MESA_FORMAT_A8B8G8R8_SNORM] = _mesa_texstore_signed_rgba8888; - table[MESA_FORMAT_R8G8B8A8_SNORM] = _mesa_texstore_signed_rgba8888; - table[MESA_FORMAT_R_SNORM16] = _mesa_texstore_snorm16; - table[MESA_FORMAT_R16G16_SNORM] = _mesa_texstore_snorm1616; - table[MESA_FORMAT_RGB_SNORM16] = _mesa_texstore_signed_rgba_16; - table[MESA_FORMAT_RGBA_SNORM16] = _mesa_texstore_signed_rgba_16; - table[MESA_FORMAT_RGBA_UNORM16] = _mesa_texstore_rgba_16; table[MESA_FORMAT_R_RGTC1_UNORM] = _mesa_texstore_red_rgtc1; table[MESA_FORMAT_R_RGTC1_SNORM] = _mesa_texstore_signed_red_rgtc1; table[MESA_FORMAT_RG_RGTC2_UNORM] = _mesa_texstore_rg_rgtc2; @@ -3677,107 +1425,327 @@ _mesa_get_texstore_func(mesa_format format) _mesa_texstore_etc2_rgb8_punchthrough_alpha1; table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] = _mesa_texstore_etc2_srgb8_punchthrough_alpha1; - table[MESA_FORMAT_A_SNORM8] = _mesa_texstore_snorm8; - table[MESA_FORMAT_L_SNORM8] = _mesa_texstore_snorm8; - table[MESA_FORMAT_L8A8_SNORM] = _mesa_texstore_snorm88; - table[MESA_FORMAT_I_SNORM8] = _mesa_texstore_snorm8; - table[MESA_FORMAT_A_SNORM16] = _mesa_texstore_snorm16; - table[MESA_FORMAT_L_SNORM16] = _mesa_texstore_snorm16; - table[MESA_FORMAT_LA_SNORM16] = _mesa_texstore_snorm1616; - table[MESA_FORMAT_I_SNORM16] = _mesa_texstore_snorm16; - table[MESA_FORMAT_R9G9B9E5_FLOAT] = _mesa_texstore_rgb9_e5; - table[MESA_FORMAT_R11G11B10_FLOAT] = _mesa_texstore_r11_g11_b10f; - table[MESA_FORMAT_Z_FLOAT32] = _mesa_texstore_z32; - table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = _mesa_texstore_z32f_x24s8; - table[MESA_FORMAT_A_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_A_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_A_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_A_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_A_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_A_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_I_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_I_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_I_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_I_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_I_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_I_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_L_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_L_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_L_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_L_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_L_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_L_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_LA_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_LA_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_LA_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_LA_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_LA_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_LA_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_R_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_RG_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_RGB_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_RGBA_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_R_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_RG_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_RGB_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_RGBA_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_R_SINT32] = _mesa_texstore_rgba_int32; - table[MESA_FORMAT_RG_SINT32] = _mesa_texstore_rgba_int32; - table[MESA_FORMAT_RGB_SINT32] = _mesa_texstore_rgba_int32; - table[MESA_FORMAT_RGBA_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_R_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_RG_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_RGB_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_RGBA_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_R_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_RG_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_RGB_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_RGBA_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_R_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_RG_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_RGB_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32; + initialized = GL_TRUE; + } + + ASSERT(table[dstFormat]); + return table[dstFormat](ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); +} + +static void +invert_swizzle(uint8_t dst[4], const uint8_t src[4]) +{ + int i, j; + + dst[0] = MESA_FORMAT_SWIZZLE_NONE; + dst[1] = MESA_FORMAT_SWIZZLE_NONE; + dst[2] = MESA_FORMAT_SWIZZLE_NONE; + dst[3] = MESA_FORMAT_SWIZZLE_NONE; + + for (i = 0; i < 4; ++i) + for (j = 0; j < 4; ++j) + if (src[j] == i && dst[i] == MESA_FORMAT_SWIZZLE_NONE) + dst[i] = j; +} + +/** Store a texture by per-channel conversions and swizzling. + * + * This function attempts to perform a texstore operation by doing simple + * per-channel conversions and swizzling. This covers a huge chunk of the + * texture storage operations that anyone cares about. If this function is + * incapable of performing the operation, it bails and returns GL_FALSE. + */ +static GLboolean +texstore_swizzle(TEXSTORE_PARAMS) +{ + const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, + srcFormat, srcType); + const GLint srcImageStride = _mesa_image_image_stride(srcPacking, + srcWidth, srcHeight, srcFormat, srcType); + const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dims, + srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0); + const int src_components = _mesa_components_in_format(srcFormat); + + GLubyte swizzle[4], rgba2base[6], base2src[6], rgba2dst[4], dst2rgba[4]; + const GLubyte *swap; + GLenum dst_type; + int dst_components; + bool is_array, normalized, need_swap; + GLint i, img, row; + const GLubyte *src_row; + GLubyte *dst_row; + + is_array = _mesa_format_to_array(dstFormat, &dst_type, &dst_components, + rgba2dst, &normalized); + + if (!is_array) + return GL_FALSE; + + switch (srcType) { + case GL_FLOAT: + case GL_UNSIGNED_BYTE: + case GL_BYTE: + case GL_UNSIGNED_SHORT: + case GL_SHORT: + case GL_UNSIGNED_INT: + case GL_INT: + /* If wa have to swap bytes in a multi-byte datatype, that means + * we're not doing an array conversion anymore */ + if (srcPacking->SwapBytes) + return GL_FALSE; + need_swap = false; + break; + case GL_UNSIGNED_INT_8_8_8_8: + need_swap = srcPacking->SwapBytes; + if (_mesa_little_endian()) + need_swap = !need_swap; + srcType = GL_UNSIGNED_BYTE; + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + need_swap = srcPacking->SwapBytes; + if (!_mesa_little_endian()) + need_swap = !need_swap; + srcType = GL_UNSIGNED_BYTE; + break; + default: + return GL_FALSE; + } + swap = need_swap ? map_3210 : map_identity; + + compute_component_mapping(srcFormat, baseInternalFormat, base2src); + compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base); + invert_swizzle(dst2rgba, rgba2dst); + + for (i = 0; i < 4; i++) { + if (dst2rgba[i] == MESA_FORMAT_SWIZZLE_NONE) + swizzle[i] = MESA_FORMAT_SWIZZLE_NONE; + else + swizzle[i] = swap[base2src[rgba2base[dst2rgba[i]]]]; + } + + /* Is it normalized? */ + normalized |= !_mesa_is_enum_format_integer(srcFormat); + + for (img = 0; img < srcDepth; img++) { + if (dstRowStride == srcWidth * dst_components && + srcRowStride == srcWidth * src_components) { + _mesa_swizzle_and_convert(dstSlices[img], dst_type, dst_components, + srcImage, srcType, src_components, + swizzle, normalized, srcWidth * srcHeight); + } else { + src_row = srcImage; + dst_row = dstSlices[img]; + for (row = 0; row < srcHeight; row++) { + _mesa_swizzle_and_convert(dst_row, dst_type, dst_components, + src_row, srcType, src_components, + swizzle, normalized, srcWidth); + dst_row += dstRowStride; + src_row += srcRowStride; + } + } + srcImage += srcImageStride; + } + + return GL_TRUE; +} + + +/** Stores a texture by converting float and then to the texture format + * + * This function performs a texstore operation by converting to float, + * applying pixel transfer ops, and then converting to the texture's + * internal format using pixel store functions. This function will work + * for any rgb or srgb textore format. + */ +static GLboolean +texstore_via_float(TEXSTORE_PARAMS) +{ + GLuint i, img, row; + const GLint src_stride = + _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); + float *tmp_row; + bool need_convert; + uint8_t *src_row, *dst_row, map[4], rgba2base[6], base2rgba[6]; + + tmp_row = malloc(srcWidth * 4 * sizeof(*tmp_row)); + if (!tmp_row) + return GL_FALSE; + + /* The GL spec (4.0, compatibility profile) only specifies srgb + * conversion as something that is done in the sampler during the + * filtering process before the colors are handed to the shader. + * Furthermore, the flowchart (Figure 3.7 in the 4.0 compatibility spec) + * does not list RGB <-> sRGB conversions anywhere. Therefore, we just + * treat sRGB formats the same as RGB formats for the purposes of + * texture upload and transfer ops. + */ + dstFormat = _mesa_get_srgb_format_linear(dstFormat); + + need_convert = false; + if (baseInternalFormat != _mesa_get_format_base_format(dstFormat)) { + compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba); + compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base); + for (i = 0; i < 4; ++i) { + map[i] = base2rgba[rgba2base[i]]; + if (map[i] != i) + need_convert = true; + } + } + + for (img = 0; img < srcDepth; img++) { + dst_row = dstSlices[img]; + src_row = _mesa_image_address(dims, srcPacking, srcAddr, + srcWidth, srcHeight, + srcFormat, srcType, + img, 0, 0); + for (row = 0; row < srcHeight; row++) { + _mesa_unpack_color_span_float(ctx, srcWidth, GL_RGBA, tmp_row, + srcFormat, srcType, src_row, + srcPacking, ctx->_ImageTransferState); + if (need_convert) + _mesa_swizzle_and_convert(tmp_row, GL_FLOAT, 4, + tmp_row, GL_FLOAT, 4, + map, false, srcWidth); + _mesa_pack_float_rgba_row(dstFormat, srcWidth, + (const GLfloat (*)[4])tmp_row, + dst_row); + dst_row += dstRowStride; + src_row += src_stride; + } + } + + return GL_TRUE; +} + +/** Stores an integer rgba texture + * + * This function performs an integer texture storage operation by unpacking + * the texture to 32-bit integers, and repacking it into the internal + * format of the texture. This will work for any integer rgb texture + * storage operation. + */ +static GLboolean +texstore_rgba_integer(TEXSTORE_PARAMS) +{ + GLuint i, img, row, *tmp_row; + GLenum dst_type, tmp_type; + const GLint src_stride = + _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType); + int num_dst_components; + bool is_array, normalized; + uint8_t *src_row, *dst_row; + uint8_t swizzle[4], rgba2base[6], base2rgba[6], rgba2dst[4], dst2rgba[4]; + + tmp_row = malloc(srcWidth * 4 * sizeof(*tmp_row)); + if (!tmp_row) + return GL_FALSE; + + is_array = _mesa_format_to_array(dstFormat, &dst_type, &num_dst_components, + rgba2dst, &normalized); + + assert(is_array && !normalized); + + if (!is_array) + return GL_FALSE; + + invert_swizzle(dst2rgba, rgba2dst); + compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba); + compute_component_mapping(baseInternalFormat, GL_RGBA, rgba2base); + + for (i = 0; i < 4; ++i) { + if (dst2rgba[i] == MESA_FORMAT_SWIZZLE_NONE) + swizzle[i] = MESA_FORMAT_SWIZZLE_NONE; + else + swizzle[i] = base2rgba[rgba2base[dst2rgba[i]]]; + } + + if (_mesa_is_type_unsigned(srcType)) { + tmp_type = GL_UNSIGNED_INT; + } else { + tmp_type = GL_INT; + } + + for (img = 0; img < srcDepth; img++) { + dst_row = dstSlices[img]; + src_row = _mesa_image_address(dims, srcPacking, srcAddr, + srcWidth, srcHeight, + srcFormat, srcType, + img, 0, 0); + for (row = 0; row < srcHeight; row++) { + _mesa_unpack_color_span_uint(ctx, srcWidth, GL_RGBA, tmp_row, + srcFormat, srcType, src_row, srcPacking); + _mesa_swizzle_and_convert(dst_row, dst_type, num_dst_components, + tmp_row, tmp_type, 4, + swizzle, false, srcWidth); + dst_row += dstRowStride; + src_row += src_stride; + } + } + + return GL_TRUE; +} + +static GLboolean +texstore_rgba(TEXSTORE_PARAMS) +{ + static StoreTexImageFunc table[MESA_FORMAT_COUNT]; + static GLboolean initialized = GL_FALSE; + + if (!initialized) { + memset(table, 0, sizeof table); + + table[MESA_FORMAT_B5G6R5_UNORM] = _mesa_texstore_rgb565; + table[MESA_FORMAT_R5G6B5_UNORM] = _mesa_texstore_rgb565; + table[MESA_FORMAT_YCBCR] = _mesa_texstore_ycbcr; + table[MESA_FORMAT_YCBCR_REV] = _mesa_texstore_ycbcr; table[MESA_FORMAT_B10G10R10A2_UINT] = _mesa_texstore_argb2101010_uint; table[MESA_FORMAT_R10G10B10A2_UINT] = _mesa_texstore_abgr2101010_uint; - table[MESA_FORMAT_B4G4R4X4_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_B5G5R5X1_UNORM] = store_ubyte_texture; - table[MESA_FORMAT_R8G8B8X8_SNORM] = _mesa_texstore_signed_rgbx8888; - table[MESA_FORMAT_R8G8B8X8_SRGB] = _mesa_texstore_srgba8; - table[MESA_FORMAT_R8G8B8A8_SRGB] = _mesa_texstore_srgba8; - table[MESA_FORMAT_RGBX_UINT8] = _mesa_texstore_rgba_uint8; - table[MESA_FORMAT_RGBX_SINT8] = _mesa_texstore_rgba_int8; - table[MESA_FORMAT_B10G10R10X2_UNORM] = _mesa_texstore_argb2101010; - table[MESA_FORMAT_RGBX_UNORM16] = _mesa_texstore_rgba_16; - table[MESA_FORMAT_RGBX_SNORM16] = _mesa_texstore_signed_rgba_16; - table[MESA_FORMAT_RGBX_FLOAT16] = _mesa_texstore_rgba_float16; - table[MESA_FORMAT_RGBX_UINT16] = _mesa_texstore_rgba_uint16; - table[MESA_FORMAT_RGBX_SINT16] = _mesa_texstore_rgba_int16; - table[MESA_FORMAT_RGBX_FLOAT32] = _mesa_texstore_rgba_float32; - table[MESA_FORMAT_RGBX_UINT32] = _mesa_texstore_rgba_uint32; - table[MESA_FORMAT_RGBX_SINT32] = _mesa_texstore_rgba_int32; - - table[MESA_FORMAT_R10G10B10A2_UNORM] = _mesa_texstore_abgr2101010; - - table[MESA_FORMAT_G8R8_SNORM] = _mesa_texstore_snorm88; - table[MESA_FORMAT_G16R16_SNORM] = _mesa_texstore_snorm1616; - - table[MESA_FORMAT_B8G8R8X8_SRGB] = _mesa_texstore_sargb8; - initialized = GL_TRUE; } - ASSERT(table[format]); - return table[format]; -} + if (table[dstFormat] && table[dstFormat](ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking)) { + return GL_TRUE; + } + + if (texstore_swizzle(ctx, dims, baseInternalFormat, + dstFormat, + dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking)) { + return GL_TRUE; + } + if (_mesa_is_format_integer(dstFormat)) { + return texstore_rgba_integer(ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking); + } else if (_mesa_get_format_max_bits(dstFormat) <= 8 && + !_mesa_is_format_signed(dstFormat)) { + return store_ubyte_texture(ctx, dims, baseInternalFormat, + dstFormat, + dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); + } else { + return texstore_via_float(ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, + srcPacking); + } +} GLboolean _mesa_texstore_needs_transfer_ops(struct gl_context *ctx, @@ -3863,8 +1831,6 @@ _mesa_texstore_memcpy(TEXSTORE_PARAMS) srcAddr, srcPacking); return GL_TRUE; } - - /** * Store user data into texture memory. * Called via glTex[Sub]Image1/2/3D() @@ -3873,9 +1839,6 @@ _mesa_texstore_memcpy(TEXSTORE_PARAMS) GLboolean _mesa_texstore(TEXSTORE_PARAMS) { - StoreTexImageFunc storeImage; - GLboolean success; - if (_mesa_texstore_memcpy(ctx, dims, baseInternalFormat, dstFormat, dstRowStride, dstSlices, @@ -3884,14 +1847,22 @@ _mesa_texstore(TEXSTORE_PARAMS) return GL_TRUE; } - storeImage = _mesa_get_texstore_func(dstFormat); - - success = storeImage(ctx, dims, baseInternalFormat, - dstFormat, - dstRowStride, dstSlices, - srcWidth, srcHeight, srcDepth, - srcFormat, srcType, srcAddr, srcPacking); - return success; + if (_mesa_is_depth_or_stencil_format(baseInternalFormat)) { + return texstore_depth_stencil(ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); + } else if (_mesa_is_format_compressed(dstFormat)) { + return texstore_compressed(ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); + } else { + return texstore_rgba(ctx, dims, baseInternalFormat, + dstFormat, dstRowStride, dstSlices, + srcWidth, srcHeight, srcDepth, + srcFormat, srcType, srcAddr, srcPacking); + } } diff --git a/mesalib/src/mesa/main/textureview.c b/mesalib/src/mesa/main/textureview.c index 77a3b782b..b3521e219 100644 --- a/mesalib/src/mesa/main/textureview.c +++ b/mesalib/src/mesa/main/textureview.c @@ -320,15 +320,11 @@ target_valid(struct gl_context *ctx, GLenum origTarget, GLenum newTarget) * If an error is found, record it with _mesa_error() * \return false if any error, true otherwise. */ -static bool -compatible_format(struct gl_context *ctx, const struct gl_texture_object *origTexObj, - GLenum internalformat) +GLboolean +_mesa_texture_view_compatible_format(struct gl_context *ctx, + GLenum origInternalFormat, + GLenum newInternalFormat) { - /* Level 0 of a texture created by glTextureStorage or glTextureView - * is always defined. - */ - struct gl_texture_image *texImage = origTexObj->Image[0][0]; - GLint origInternalFormat = texImage->InternalFormat; unsigned int origViewClass, newViewClass; /* The two textures' internal formats must be compatible according to @@ -337,19 +333,15 @@ compatible_format(struct gl_context *ctx, const struct gl_texture_object *origTe * The internal formats must be identical if not in that table, * or an INVALID_OPERATION error is generated. */ - if (origInternalFormat == internalformat) - return true; + if (origInternalFormat == newInternalFormat) + return GL_TRUE; origViewClass = lookup_view_class(ctx, origInternalFormat); - newViewClass = lookup_view_class(ctx, internalformat); + newViewClass = lookup_view_class(ctx, newInternalFormat); if ((origViewClass == newViewClass) && origViewClass != false) - return true; + return GL_TRUE; - _mesa_error(ctx, GL_INVALID_OPERATION, - "glTextureView(internalformat %s not compatible with origtexture %s)", - _mesa_lookup_enum_by_nr(internalformat), - _mesa_lookup_enum_by_nr(origInternalFormat)); - return false; + return GL_FALSE; } /** * Helper function for TexStorage and teximagemultisample to set immutable @@ -512,8 +504,14 @@ _mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture, return; } - if (!compatible_format(ctx, origTexObj, internalformat)) { - return; /* Error logged */ + if (!_mesa_texture_view_compatible_format(ctx, + origTexObj->Image[0][0]->InternalFormat, + internalformat)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glTextureView(internalformat %s not compatible with origtexture %s)", + _mesa_lookup_enum_by_nr(internalformat), + _mesa_lookup_enum_by_nr(origTexObj->Image[0][0]->InternalFormat)); + return; } texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0, diff --git a/mesalib/src/mesa/main/textureview.h b/mesalib/src/mesa/main/textureview.h index 3088ac193..549a13cd8 100644 --- a/mesalib/src/mesa/main/textureview.h +++ b/mesalib/src/mesa/main/textureview.h @@ -29,6 +29,10 @@ #ifndef TEXTUREVIEW_H #define TEXTUREVIEW_H +GLboolean +_mesa_texture_view_compatible_format(struct gl_context *ctx, + GLenum origInternalFormat, + GLenum newInternalFormat); extern void GLAPIENTRY _mesa_TextureView(GLuint texture, GLenum target, GLuint origtexture, diff --git a/mesalib/src/mesa/main/uniform_query.cpp b/mesalib/src/mesa/main/uniform_query.cpp index 609d94bd7..7e630e65b 100644 --- a/mesalib/src/mesa/main/uniform_query.cpp +++ b/mesalib/src/mesa/main/uniform_query.cpp @@ -171,18 +171,17 @@ _mesa_GetActiveUniformsiv(GLuint program, _mesa_error(ctx, GL_INVALID_ENUM, "glGetActiveUniformsiv(pname)"); } -static bool +static struct gl_uniform_storage * validate_uniform_parameters(struct gl_context *ctx, struct gl_shader_program *shProg, GLint location, GLsizei count, - unsigned *loc, unsigned *array_index, const char *caller, bool negative_one_is_not_valid) { if (!shProg || !shProg->LinkStatus) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)", caller); - return false; + return NULL; } if (location == -1) { @@ -214,7 +213,7 @@ validate_uniform_parameters(struct gl_context *ctx, caller, location); } - return false; + return NULL; } /* From page 12 (page 26 of the PDF) of the OpenGL 2.1 spec: @@ -224,7 +223,7 @@ validate_uniform_parameters(struct gl_context *ctx, */ if (count < 0) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(count < 0)", caller); - return false; + return NULL; } /* Page 82 (page 96 of the PDF) of the OpenGL 2.1 spec says: @@ -243,14 +242,14 @@ validate_uniform_parameters(struct gl_context *ctx, if (location < -1) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)", caller, location); - return false; + return NULL; } /* Check that the given location is in bounds of uniform remap table. */ if (location >= (GLint) shProg->NumUniformRemapTable) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)", caller, location); - return false; + return NULL; } /* If the driver storage pointer in remap table is -1, we ignore silently. @@ -266,30 +265,33 @@ validate_uniform_parameters(struct gl_context *ctx, */ if (shProg->UniformRemapTable[location] == INACTIVE_UNIFORM_EXPLICIT_LOCATION) - return false; + return NULL; - _mesa_uniform_split_location_offset(shProg, location, loc, array_index); + struct gl_uniform_storage *const uni = shProg->UniformRemapTable[location]; - if (shProg->UniformStorage[*loc].array_elements == 0 && count > 1) { + if (uni->array_elements == 0 && count > 1) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(count > 1 for non-array, location=%d)", caller, location); - return false; + return NULL; } + /* The array index specified by the uniform location is just the uniform + * location minus the base location of of the uniform. + */ + *array_index = location - uni->remap_location; + /* If the uniform is an array, check that array_index is in bounds. * If not an array, check that array_index is zero. * array_index is unsigned so no need to check for less than zero. */ - unsigned limit = shProg->UniformStorage[*loc].array_elements; - if (limit == 0) - limit = 1; + const unsigned limit = MAX2(uni->array_elements, 1); if (*array_index >= limit) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)", caller, location); - return false; + return NULL; } - return true; + return uni; } /** @@ -302,15 +304,14 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location, { struct gl_shader_program *shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetUniformfv"); - struct gl_uniform_storage *uni; - unsigned loc, offset; + unsigned offset; - if (!validate_uniform_parameters(ctx, shProg, location, 1, - &loc, &offset, "glGetUniform", true)) + struct gl_uniform_storage *const uni = + validate_uniform_parameters(ctx, shProg, location, 1, + &offset, "glGetUniform", true); + if (uni == NULL) return; - uni = &shProg->UniformStorage[loc]; - { unsigned elements = (uni->type->is_sampler()) ? 1 : uni->type->components(); @@ -607,18 +608,17 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg, GLint location, GLsizei count, const GLvoid *values, GLenum type) { - unsigned loc, offset; + unsigned offset; unsigned components; unsigned src_components; enum glsl_base_type basicType; - struct gl_uniform_storage *uni; - if (!validate_uniform_parameters(ctx, shProg, location, count, - &loc, &offset, "glUniform", false)) + struct gl_uniform_storage *const uni = + validate_uniform_parameters(ctx, shProg, location, count, + &offset, "glUniform", false); + if (uni == NULL) return; - uni = &shProg->UniformStorage[loc]; - /* Verify that the types are compatible. */ switch (type) { @@ -894,17 +894,17 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg, GLint location, GLsizei count, GLboolean transpose, const GLfloat *values) { - unsigned loc, offset; + unsigned offset; unsigned vectors; unsigned components; unsigned elements; - struct gl_uniform_storage *uni; - if (!validate_uniform_parameters(ctx, shProg, location, count, - &loc, &offset, "glUniformMatrix", false)) + struct gl_uniform_storage *const uni = + validate_uniform_parameters(ctx, shProg, location, count, + &offset, "glUniformMatrix", false); + if (uni == NULL) return; - uni = &shProg->UniformStorage[loc]; if (!uni->type->is_matrix()) { _mesa_error(ctx, GL_INVALID_OPERATION, "glUniformMatrix(non-matrix uniform)"); @@ -993,9 +993,7 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg, * * Returns the uniform index into UniformStorage (also the * glGetActiveUniformsiv uniform index), and stores the referenced - * array offset in *offset, or GL_INVALID_INDEX (-1). Those two - * return values can be encoded into a uniform location for - * glUniform* using _mesa_uniform_merge_location_offset(index, offset). + * array offset in *offset, or GL_INVALID_INDEX (-1). */ extern "C" unsigned _mesa_get_uniform_location(struct gl_context *ctx, diff --git a/mesalib/src/mesa/main/uniforms.c b/mesalib/src/mesa/main/uniforms.c index f450173af..0d0cbf57e 100644 --- a/mesalib/src/mesa/main/uniforms.c +++ b/mesalib/src/mesa/main/uniforms.c @@ -932,7 +932,8 @@ _mesa_GetUniformLocation(GLuint programObj, const GLcharARB *name) shProg->UniformStorage[index].atomic_buffer_index != -1) return -1; - return _mesa_uniform_merge_location_offset(shProg, index, offset); + /* location in remap table + array element offset */ + return shProg->UniformStorage[index].remap_location + offset; } GLuint GLAPIENTRY @@ -1089,18 +1090,38 @@ _mesa_GetActiveUniformBlockiv(GLuint program, params[0] = strlen(block->Name) + 1; return; - case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: - params[0] = block->NumUniforms; + case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: { + unsigned count = 0; + + for (i = 0; i < block->NumUniforms; i++) { + unsigned offset; + const int idx = + _mesa_get_uniform_location(ctx, shProg, + block->Uniforms[i].IndexName, + &offset); + if (idx != -1) + count++; + } + + params[0] = count; return; + } + + case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: { + unsigned count = 0; - case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: for (i = 0; i < block->NumUniforms; i++) { unsigned offset; - params[i] = _mesa_get_uniform_location(ctx, shProg, - block->Uniforms[i].IndexName, - &offset); + const int idx = + _mesa_get_uniform_location(ctx, shProg, + block->Uniforms[i].IndexName, + &offset); + + if (idx != -1) + params[count++] = idx; } return; + } case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: params[0] = shProg->UniformBlockStageIndex[MESA_SHADER_VERTEX][uniformBlockIndex] != -1; diff --git a/mesalib/src/mesa/main/uniforms.h b/mesalib/src/mesa/main/uniforms.h index 10518dcbb..e7a370e84 100644 --- a/mesalib/src/mesa/main/uniforms.h +++ b/mesalib/src/mesa/main/uniforms.h @@ -323,69 +323,6 @@ struct gl_builtin_uniform_desc { unsigned int num_elements; }; -/** - * \name GLSL uniform arrays and structs require special handling. - * - * The GL_ARB_shader_objects spec says that if you use - * glGetUniformLocation to get the location of an array, you CANNOT - * access other elements of the array by adding an offset to the - * returned location. For example, you must call - * glGetUniformLocation("foo[16]") if you want to set the 16th element - * of the array with glUniform(). - * - * HOWEVER, some other OpenGL drivers allow accessing array elements - * by adding an offset to the returned array location. And some apps - * seem to depend on that behaviour. - * - * Mesa's gl_uniform_list doesn't directly support this since each - * entry in the list describes one uniform variable, not one uniform - * element. We could insert dummy entries in the list for each array - * element after [0] but that causes complications elsewhere. - * - * We solve this problem by creating multiple entries for uniform arrays - * in the UniformRemapTable so that their elements get sequential locations. - * - * Utility functions below offer functionality to split UniformRemapTable - * location in to location of the uniform in UniformStorage + offset to the - * array element (0 if not an array) and also merge it back again as the - * UniformRemapTable location. - * - */ -/*@{*/ -/** - * Combine the uniform's storage index and the array index - */ -static inline GLint -_mesa_uniform_merge_location_offset(const struct gl_shader_program *prog, - unsigned storage_index, - unsigned uniform_array_index) -{ - /* location in remap table + array element offset */ - return prog->UniformStorage[storage_index].remap_location + - uniform_array_index; -} - -/** - * Separate the uniform storage index and array index - */ -static inline void -_mesa_uniform_split_location_offset(const struct gl_shader_program *prog, - GLint location, unsigned *storage_index, - unsigned *uniform_array_index) -{ - *storage_index = prog->UniformRemapTable[location] - prog->UniformStorage; - *uniform_array_index = location - - prog->UniformRemapTable[location]->remap_location; - - /*gl_uniform_storage in UniformStorage with the calculated base_location - * must match with the entry in remap table - */ - assert(&prog->UniformStorage[*storage_index] == - prog->UniformRemapTable[location]); -} -/*@}*/ - - #ifdef __cplusplus } #endif diff --git a/mesalib/src/mesa/main/varray.c b/mesalib/src/mesa/main/varray.c index 46956efb5..230fb30cb 100644 --- a/mesalib/src/mesa/main/varray.c +++ b/mesalib/src/mesa/main/varray.c @@ -24,6 +24,8 @@ */ +#include <inttypes.h> /* for PRId64 macro */ + #include "glheader.h" #include "imports.h" #include "bufferobj.h" @@ -46,21 +48,22 @@ /** Used to indicate which GL datatypes are accepted by each of the * glVertex/Color/Attrib/EtcPointer() functions. */ -#define BOOL_BIT 0x1 -#define BYTE_BIT 0x2 -#define UNSIGNED_BYTE_BIT 0x4 -#define SHORT_BIT 0x8 -#define UNSIGNED_SHORT_BIT 0x10 -#define INT_BIT 0x20 -#define UNSIGNED_INT_BIT 0x40 -#define HALF_BIT 0x80 -#define FLOAT_BIT 0x100 -#define DOUBLE_BIT 0x200 -#define FIXED_ES_BIT 0x400 -#define FIXED_GL_BIT 0x800 -#define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000 -#define INT_2_10_10_10_REV_BIT 0x2000 -#define UNSIGNED_INT_10F_11F_11F_REV_BIT 0x4000 +#define BOOL_BIT (1 << 0) +#define BYTE_BIT (1 << 1) +#define UNSIGNED_BYTE_BIT (1 << 2) +#define SHORT_BIT (1 << 3) +#define UNSIGNED_SHORT_BIT (1 << 4) +#define INT_BIT (1 << 5) +#define UNSIGNED_INT_BIT (1 << 6) +#define HALF_BIT (1 << 7) +#define FLOAT_BIT (1 << 8) +#define DOUBLE_BIT (1 << 9) +#define FIXED_ES_BIT (1 << 10) +#define FIXED_GL_BIT (1 << 11) +#define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12) +#define INT_2_10_10_10_REV_BIT (1 << 13) +#define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14) +#define ALL_TYPE_BITS ((1 << 15) - 1) /** Convert GL datatype enum into a <type>_BIT value seen above */ @@ -179,6 +182,53 @@ vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex, /** + * Examine the API profile and extensions to determine which types are legal + * for vertex arrays. This is called once from update_array_format(). + */ +static GLbitfield +get_legal_types_mask(const struct gl_context *ctx) +{ + GLbitfield legalTypesMask = ALL_TYPE_BITS; + + if (_mesa_is_gles(ctx)) { + legalTypesMask &= ~(FIXED_GL_BIT | + DOUBLE_BIT | + UNSIGNED_INT_10F_11F_11F_REV_BIT); + + /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until + * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or + * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed + * until 3.0 or with the GL_OES_vertex_half float extension, which isn't + * quite as trivial as we'd like because it uses a different enum value + * for GL_HALF_FLOAT_OES. + */ + if (ctx->Version < 30) { + legalTypesMask &= ~(UNSIGNED_INT_BIT | + INT_BIT | + UNSIGNED_INT_2_10_10_10_REV_BIT | + INT_2_10_10_10_REV_BIT | + HALF_BIT); + } + } + else { + legalTypesMask &= ~FIXED_ES_BIT; + + if (!ctx->Extensions.ARB_ES2_compatibility) + legalTypesMask &= ~FIXED_GL_BIT; + + if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) + legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT | + INT_2_10_10_10_REV_BIT); + + if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev) + legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT; + } + + return legalTypesMask; +} + + +/** * Does error checking and updates the format in an attrib array. * * Called by update_array() and VertexAttrib*Format(). @@ -208,40 +258,19 @@ update_array_format(struct gl_context *ctx, GLuint elementSize; GLenum format = GL_RGBA; - if (_mesa_is_gles(ctx)) { - legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT | UNSIGNED_INT_10F_11F_11F_REV_BIT); - - /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until - * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or - * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed - * until 3.0 or with the GL_OES_vertex_half float extension, which isn't - * quite as trivial as we'd like because it uses a different enum value - * for GL_HALF_FLOAT_OES. + if (ctx->Array.LegalTypesMask == 0) { + /* One-time initialization. We can't do this in _mesa_init_varrays() + * below because extensions are not yet enabled at that point. */ - if (ctx->Version < 30) { - legalTypesMask &= ~(UNSIGNED_INT_BIT - | INT_BIT - | UNSIGNED_INT_2_10_10_10_REV_BIT - | INT_2_10_10_10_REV_BIT - | HALF_BIT); - } + ctx->Array.LegalTypesMask = get_legal_types_mask(ctx); + } + + legalTypesMask &= ctx->Array.LegalTypesMask; + if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) { /* BGRA ordering is not supported in ES contexts. */ - if (sizeMax == BGRA_OR_4) - sizeMax = 4; - } else { - legalTypesMask &= ~FIXED_ES_BIT; - - if (!ctx->Extensions.ARB_ES2_compatibility) - legalTypesMask &= ~FIXED_GL_BIT; - - if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) - legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT | - INT_2_10_10_10_REV_BIT); - - if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev) - legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT; + sizeMax = 4; } typeBit = type_to_bit(ctx, type); @@ -1397,7 +1426,8 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, */ if (offset < 0) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindVertexBuffer(offset=%lld < 0)", (long long)offset); + "glBindVertexBuffer(offset=%" PRId64 " < 0)", + (int64_t) offset); return; } @@ -1523,15 +1553,15 @@ _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers, */ if (offsets[i] < 0) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindVertexBuffer(offsets[%u]=%lldd < 0)", - i, (long long int) offsets[i]); + "glBindVertexBuffer(offsets[%u]=%" PRId64 " < 0)", + i, (int64_t) offsets[i]); continue; } if (strides[i] < 0) { _mesa_error(ctx, GL_INVALID_VALUE, - "glBindVertexBuffer(strides[%u]=%lld < 0)", - i, (long long int) strides[i]); + "glBindVertexBuffer(strides[%u]=%d < 0)", + i, strides[i]); continue; } diff --git a/mesalib/src/mesa/main/vdpau.c b/mesalib/src/mesa/main/vdpau.c index 975b812cd..e1c3e00ba 100644 --- a/mesalib/src/mesa/main/vdpau.c +++ b/mesalib/src/mesa/main/vdpau.c @@ -32,9 +32,9 @@ */ #include <stdbool.h> +#include "util/hash_table.h" #include "context.h" #include "glformats.h" -#include "hash_table.h" #include "set.h" #include "texobj.h" #include "teximage.h" diff --git a/mesalib/src/mesa/program/arbprogparse.c b/mesalib/src/mesa/program/arbprogparse.c index 5b9665091..7dec399a5 100644 --- a/mesalib/src/mesa/program/arbprogparse.c +++ b/mesalib/src/mesa/program/arbprogparse.c @@ -60,6 +60,7 @@ having three separate program parameter arrays. #include "prog_parameter.h" #include "prog_statevars.h" #include "prog_instruction.h" +#include "prog_optimize.h" #include "program_parser.h" @@ -84,6 +85,9 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, return; } + if ((ctx->_Shader->Flags & GLSL_NO_OPT) == 0) + _mesa_optimize_program(ctx, &prog); + free(program->Base.String); /* Copy the relevant contents of the arb_program struct into the @@ -177,6 +181,9 @@ _mesa_parse_arb_vertex_program(struct gl_context *ctx, GLenum target, return; } + if ((ctx->_Shader->Flags & GLSL_NO_OPT) == 0) + _mesa_optimize_program(ctx, &prog); + free(program->Base.String); /* Copy the relevant contents of the arb_program struct into the diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index 2a82e9d9d..b088160d3 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -793,7 +793,7 @@ ir_to_mesa_visitor::visit(ir_function *ir) const ir_function_signature *sig; exec_list empty; - sig = ir->matching_signature(NULL, &empty); + sig = ir->matching_signature(NULL, &empty, false); assert(sig); diff --git a/mesalib/src/mesa/program/prog_execute.c b/mesalib/src/mesa/program/prog_execute.c index 115525eba..fcc9ed518 100644 --- a/mesalib/src/mesa/program/prog_execute.c +++ b/mesalib/src/mesa/program/prog_execute.c @@ -52,7 +52,6 @@ /** * Set x to positive or negative infinity. */ -#if defined(USE_IEEE) || defined(_WIN32) #define SET_POS_INFINITY(x) \ do { \ fi_type fi; \ @@ -65,10 +64,6 @@ fi.i = 0xFF800000; \ x = fi.f; \ } while (0) -#else -#define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL -#define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL -#endif #define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits diff --git a/mesalib/src/mesa/program/program.c b/mesalib/src/mesa/program/program.c index aedce3e3c..ef5bf6b11 100644 --- a/mesalib/src/mesa/program/program.c +++ b/mesalib/src/mesa/program/program.c @@ -226,27 +226,24 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, /** - * Initialize a new vertex/fragment program object. + * Initialize a new gl_program object. */ -static struct gl_program * -_mesa_init_program_struct( struct gl_context *ctx, struct gl_program *prog, - GLenum target, GLuint id) +static void +init_program_struct(struct gl_program *prog, GLenum target, GLuint id) { - (void) ctx; - if (prog) { - GLuint i; - memset(prog, 0, sizeof(*prog)); - prog->Id = id; - prog->Target = target; - prog->RefCount = 1; - prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB; - - /* default mapping from samplers to texture units */ - for (i = 0; i < MAX_SAMPLERS; i++) - prog->SamplerUnits[i] = i; - } + GLuint i; - return prog; + assert(prog); + + memset(prog, 0, sizeof(*prog)); + prog->Id = id; + prog->Target = target; + prog->RefCount = 1; + prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB; + + /* default mapping from samplers to texture units */ + for (i = 0; i < MAX_SAMPLERS; i++) + prog->SamplerUnits[i] = i; } @@ -254,13 +251,15 @@ _mesa_init_program_struct( struct gl_context *ctx, struct gl_program *prog, * Initialize a new fragment program object. */ struct gl_program * -_mesa_init_fragment_program( struct gl_context *ctx, struct gl_fragment_program *prog, - GLenum target, GLuint id) +_mesa_init_fragment_program(struct gl_context *ctx, + struct gl_fragment_program *prog, + GLenum target, GLuint id) { - if (prog) - return _mesa_init_program_struct( ctx, &prog->Base, target, id ); - else - return NULL; + if (prog) { + init_program_struct(&prog->Base, target, id); + return &prog->Base; + } + return NULL; } @@ -268,13 +267,15 @@ _mesa_init_fragment_program( struct gl_context *ctx, struct gl_fragment_program * Initialize a new vertex program object. */ struct gl_program * -_mesa_init_vertex_program( struct gl_context *ctx, struct gl_vertex_program *prog, - GLenum target, GLuint id) +_mesa_init_vertex_program(struct gl_context *ctx, + struct gl_vertex_program *prog, + GLenum target, GLuint id) { - if (prog) - return _mesa_init_program_struct( ctx, &prog->Base, target, id ); - else - return NULL; + if (prog) { + init_program_struct(&prog->Base, target, id); + return &prog->Base; + } + return NULL; } @@ -283,13 +284,14 @@ _mesa_init_vertex_program( struct gl_context *ctx, struct gl_vertex_program *pro */ struct gl_program * _mesa_init_compute_program(struct gl_context *ctx, - struct gl_compute_program *prog, GLenum target, - GLuint id) + struct gl_compute_program *prog, + GLenum target, GLuint id) { - if (prog) - return _mesa_init_program_struct( ctx, &prog->Base, target, id ); - else - return NULL; + if (prog) { + init_program_struct(&prog->Base, target, id); + return &prog->Base; + } + return NULL; } @@ -297,13 +299,15 @@ _mesa_init_compute_program(struct gl_context *ctx, * Initialize a new geometry program object. */ struct gl_program * -_mesa_init_geometry_program( struct gl_context *ctx, struct gl_geometry_program *prog, - GLenum target, GLuint id) +_mesa_init_geometry_program(struct gl_context *ctx, + struct gl_geometry_program *prog, + GLenum target, GLuint id) { - if (prog) - return _mesa_init_program_struct( ctx, &prog->Base, target, id ); - else - return NULL; + if (prog) { + init_program_struct(&prog->Base, target, id); + return &prog->Base; + } + return NULL; } diff --git a/mesalib/src/mesa/program/register_allocate.c b/mesalib/src/mesa/program/register_allocate.c index 6fac69033..549154e8a 100644 --- a/mesalib/src/mesa/program/register_allocate.c +++ b/mesalib/src/mesa/program/register_allocate.c @@ -71,8 +71,8 @@ */ #include <stdbool.h> -#include <ralloc.h> +#include "util/ralloc.h" #include "main/imports.h" #include "main/macros.h" #include "main/mtypes.h" diff --git a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c index 3b4d28d47..e0cb979f2 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -31,6 +31,8 @@ */ +#include <inttypes.h> /* for PRId64 macro */ + #include "main/imports.h" #include "main/mtypes.h" #include "main/arrayobj.h" @@ -271,7 +273,8 @@ st_bufferobj_data(struct gl_context *ctx, pipe_resource_reference( &st_obj->buffer, NULL ); if (ST_DEBUG & DEBUG_BUFFER) { - debug_printf("Create buffer size %td bind 0x%x\n", size, bind); + debug_printf("Create buffer size %" PRId64 " bind 0x%x\n", + (int64_t) size, bind); } if (size != 0) { diff --git a/mesalib/src/mesa/state_tracker/st_cb_clear.c b/mesalib/src/mesa/state_tracker/st_cb_clear.c index 4bfa8d75a..2c1414e48 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_clear.c +++ b/mesalib/src/mesa/state_tracker/st_cb_clear.c @@ -173,6 +173,9 @@ draw_quad(struct st_context *st, return; } + /* Convert Z from [0,1] to [-1,1] range */ + z = z * 2.0f - 1.0f; + /* positions */ vertices[0][0][0] = x0; vertices[0][0][1] = y0; @@ -319,11 +322,11 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers) struct pipe_viewport_state vp; vp.scale[0] = 0.5f * fb_width; vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f); - vp.scale[2] = 1.0f; + vp.scale[2] = 0.5f; vp.scale[3] = 1.0f; vp.translate[0] = 0.5f * fb_width; vp.translate[1] = 0.5f * fb_height; - vp.translate[2] = 0.0f; + vp.translate[2] = 0.5f; vp.translate[3] = 0.0f; cso_set_viewport(st->cso_context, &vp); } diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c index 6119cc275..d13a17f50 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c @@ -494,22 +494,19 @@ make_texture(struct st_context *st, pipeFormat = st_choose_matching_format(pipe->screen, PIPE_BIND_SAMPLER_VIEW, format, type, unpack->SwapBytes); - if (pipeFormat != PIPE_FORMAT_NONE) { - mformat = st_pipe_format_to_mesa_format(pipeFormat); - baseInternalFormat = _mesa_get_format_base_format(mformat); - } - else { + if (pipeFormat == PIPE_FORMAT_NONE) { /* Use the generic approach. */ GLenum intFormat = internal_format(ctx, format, type); - baseInternalFormat = _mesa_base_tex_format(ctx, intFormat); pipeFormat = st_choose_format(st, intFormat, format, type, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, FALSE); assert(pipeFormat != PIPE_FORMAT_NONE); - mformat = st_pipe_format_to_mesa_format(pipeFormat); } + mformat = st_pipe_format_to_mesa_format(pipeFormat); + baseInternalFormat = _mesa_get_format_base_format(mformat); + pixels = _mesa_map_pbo_source(ctx, unpack, pixels); if (!pixels) return NULL; diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index aa6b05f0b..c4b2107ba 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -719,6 +719,8 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims, /* From now on, we need the gallium representation of dimensions. */ if (gl_target == GL_TEXTURE_1D_ARRAY) { + zoffset = yoffset; + yoffset = 0; depth = height; height = 1; } diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index aa59fbfa9..7ac484056 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -146,7 +146,7 @@ void st_init_limits(struct st_context *st) c->MaxUniformBlockSize = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, - PIPE_SHADER_CAP_MAX_CONSTS) * 16; + PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE); if (c->MaxUniformBlockSize < 16384) { can_ubo = FALSE; } @@ -194,7 +194,8 @@ void st_init_limits(struct st_context *st) _min(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS), MAX_PROGRAM_ADDRESS_REGS); pc->MaxParameters = pc->MaxNativeParameters = - screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS); + screen->get_shader_param(screen, sh, + PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE) / sizeof(float[4]); pc->MaxUniformComponents = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS); 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 5ea146547..0290553c6 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -1192,7 +1192,7 @@ glsl_to_tgsi_visitor::visit(ir_function *ir) const ir_function_signature *sig; exec_list empty; - sig = ir->matching_signature(NULL, &empty); + sig = ir->matching_signature(NULL, &empty, false); assert(sig); @@ -1354,7 +1354,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) /* Quick peephole: Emit OPCODE_MAD(-a, -b, a) instead of AND(a, NOT(b)) */ - if (ir->operation == ir_binop_logic_and) { + if (!native_integers && ir->operation == ir_binop_logic_and) { if (try_emit_mad_for_and_not(ir, 1)) return; if (try_emit_mad_for_and_not(ir, 0)) @@ -1947,16 +1947,16 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) break; case ir_binop_ubo_load: { - ir_constant *uniform_block = ir->operands[0]->as_constant(); + ir_constant *const_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; + unsigned const_block = const_uniform_block ? const_uniform_block->value.u[0] + 1 : 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; @@ -1966,7 +1966,6 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) /* Constant index into constant buffer */ cbuf.reladdr = NULL; cbuf.index = const_offset / 16; - cbuf.has_index2 = true; } else { /* Relative/variable index into constant buffer */ @@ -1976,6 +1975,20 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) memcpy(cbuf.reladdr, &index_reg, sizeof(index_reg)); } + if (const_uniform_block) { + /* Constant constant buffer */ + cbuf.reladdr2 = NULL; + cbuf.index2D = const_block; + cbuf.has_index2 = true; + } + else { + /* Relative/variable constant buffer */ + cbuf.reladdr2 = ralloc(mem_ctx, st_src_reg); + cbuf.index2D = 1; + memcpy(cbuf.reladdr2, &op[0], sizeof(st_src_reg)); + cbuf.has_index2 = true; + } + cbuf.swizzle = swizzle_for_size(ir->type->vector_elements); cbuf.swizzle += MAKE_SWIZZLE4(const_offset % 16 / 4, const_offset % 16 / 4, @@ -3216,78 +3229,6 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog) _mesa_update_shader_textures_used(v->shader_program, prog); } -static void -set_uniform_initializer(struct gl_context *ctx, void *mem_ctx, - struct gl_shader_program *shader_program, - const char *name, const glsl_type *type, - ir_constant *val) -{ - if (type->is_record()) { - ir_constant *field_constant; - - field_constant = (ir_constant *)val->components.get_head(); - - for (unsigned int i = 0; i < type->length; i++) { - const glsl_type *field_type = type->fields.structure[i].type; - const char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name, - type->fields.structure[i].name); - set_uniform_initializer(ctx, mem_ctx, shader_program, field_name, - field_type, field_constant); - field_constant = (ir_constant *)field_constant->next; - } - return; - } - - unsigned offset; - unsigned index = _mesa_get_uniform_location(ctx, shader_program, name, - &offset); - if (offset == GL_INVALID_INDEX) { - fail_link(shader_program, - "Couldn't find uniform for initializer %s\n", name); - return; - } - int loc = _mesa_uniform_merge_location_offset(shader_program, index, offset); - - for (unsigned int i = 0; i < (type->is_array() ? type->length : 1); i++) { - ir_constant *element; - const glsl_type *element_type; - if (type->is_array()) { - element = val->array_elements[i]; - element_type = type->fields.array; - } else { - element = val; - element_type = type; - } - - void *values; - - if (element_type->base_type == GLSL_TYPE_BOOL) { - int *conv = ralloc_array(mem_ctx, int, element_type->components()); - for (unsigned int j = 0; j < element_type->components(); j++) { - conv[j] = element->value.b[j]; - } - values = (void *)conv; - element_type = glsl_type::get_instance(GLSL_TYPE_INT, - element_type->vector_elements, - 1); - } else { - values = &element->value; - } - - if (element_type->is_matrix()) { - _mesa_uniform_matrix(ctx, shader_program, - element_type->matrix_columns, - element_type->vector_elements, - loc, 1, GL_FALSE, (GLfloat *)values); - } else { - _mesa_uniform(ctx, shader_program, loc, element_type->matrix_columns, - values, element_type->gl_type); - } - - loc++; - } -} - /** * Returns the mask of channels (bitmask of WRITEMASK_X,Y,Z,W) which * are read from the given src in this instruction @@ -4225,14 +4166,22 @@ struct st_translate { }; /** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ -static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = { - TGSI_SEMANTIC_FACE, +const unsigned _mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = { + /* Vertex shader + */ TGSI_SEMANTIC_VERTEXID, TGSI_SEMANTIC_INSTANCEID, + + /* Geometry shader + */ + TGSI_SEMANTIC_INVOCATIONID, + + /* Fragment shader + */ + TGSI_SEMANTIC_FACE, TGSI_SEMANTIC_SAMPLEID, TGSI_SEMANTIC_SAMPLEPOS, TGSI_SEMANTIC_SAMPLEMASK, - TGSI_SEMANTIC_INVOCATIONID, }; /** @@ -4321,9 +4270,8 @@ dst_register(struct st_translate *t, return ureg_dst_undef(); case PROGRAM_TEMPORARY: - assert(index >= 0); - assert(index < (int) Elements(t->temps)); - + assert(index < Elements(t->temps)); + if (ureg_dst_is_undef(t->temps[index])) t->temps[index] = ureg_DECL_local_temporary(t->ureg); @@ -4332,8 +4280,7 @@ dst_register(struct st_translate *t, case PROGRAM_ARRAY: array = index >> 16; - assert(array >= 0); - assert(array < (int) Elements(t->arrays)); + assert(array < Elements(t->arrays)); if (ureg_dst_is_undef(t->arrays[array])) t->arrays[array] = ureg_DECL_array_temporary( @@ -4367,51 +4314,45 @@ dst_register(struct st_translate *t, * Map a glsl_to_tgsi src register to a TGSI ureg_src register. */ static struct ureg_src -src_register(struct st_translate *t, - gl_register_file file, - GLint index, GLint index2D) +src_register(struct st_translate *t, const struct st_src_reg *reg) { - switch(file) { + switch(reg->file) { case PROGRAM_UNDEFINED: return ureg_src_undef(); case PROGRAM_TEMPORARY: case PROGRAM_ARRAY: - return ureg_src(dst_register(t, file, index)); + return ureg_src(dst_register(t, reg->file, reg->index)); case PROGRAM_UNIFORM: - assert(index >= 0); - return t->constants[index]; + assert(reg->index >= 0); + return t->constants[reg->index]; case PROGRAM_STATE_VAR: case PROGRAM_CONSTANT: /* ie, immediate */ - if (index2D) { - struct ureg_src src; - src = ureg_src_register(TGSI_FILE_CONSTANT, index); - src.Dimension = 1; - src.DimensionIndex = index2D; - return src; - } else if (index < 0) + if (reg->has_index2) + return ureg_src_register(TGSI_FILE_CONSTANT, reg->index); + else if (reg->index < 0) return ureg_DECL_constant(t->ureg, 0); else - return t->constants[index]; + return t->constants[reg->index]; case PROGRAM_IMMEDIATE: - return t->immediates[index]; + return t->immediates[reg->index]; case PROGRAM_INPUT: - assert(t->inputMapping[index] < Elements(t->inputs)); - return t->inputs[t->inputMapping[index]]; + assert(t->inputMapping[reg->index] < Elements(t->inputs)); + return t->inputs[t->inputMapping[reg->index]]; case PROGRAM_OUTPUT: - assert(t->outputMapping[index] < Elements(t->outputs)); - return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */ + assert(t->outputMapping[reg->index] < Elements(t->outputs)); + return ureg_src(t->outputs[t->outputMapping[reg->index]]); /* not needed? */ case PROGRAM_ADDRESS: - return ureg_src(t->address[index]); + return ureg_src(t->address[reg->index]); case PROGRAM_SYSTEM_VALUE: - assert(index < (int) Elements(t->systemValues)); - return t->systemValues[index]; + assert(reg->index < (int) Elements(t->systemValues)); + return t->systemValues[reg->index]; default: assert(!"unknown src register file"); @@ -4472,13 +4413,12 @@ 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, src_reg->index2D); + struct ureg_src src = src_register(t, src_reg); if (src_reg->has_index2) { /* 2D indexes occur with geometry shader inputs (attrib, vertex) * and UBO constant buffers (buffer, position). */ - src = src_register(t, src_reg->file, src_reg->index, src_reg->index2D); if (src_reg->reladdr2) src = ureg_src_dimension_indirect(src, ureg_src(t->address[1]), src_reg->index2D); @@ -4900,6 +4840,21 @@ st_translate_program( assert(numInputs <= Elements(t->inputs)); assert(numOutputs <= Elements(t->outputs)); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_FRONT_FACE] == + TGSI_SEMANTIC_FACE); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_VERTEX_ID] == + TGSI_SEMANTIC_VERTEXID); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_INSTANCE_ID] == + TGSI_SEMANTIC_INSTANCEID); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_ID] == + TGSI_SEMANTIC_SAMPLEID); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_POS] == + TGSI_SEMANTIC_SAMPLEPOS); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_MASK_IN] == + TGSI_SEMANTIC_SAMPLEMASK); + assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_INVOCATION_ID] == + TGSI_SEMANTIC_INVOCATIONID); + t = CALLOC_STRUCT(st_translate); if (!t) { ret = PIPE_ERROR_OUT_OF_MEMORY; @@ -5035,7 +4990,7 @@ st_translate_program( unsigned numSys = 0; for (i = 0; sysInputs; i++) { if (sysInputs & (1 << i)) { - unsigned semName = mesa_sysval_to_semantic[i]; + unsigned semName = _mesa_sysval_to_semantic[i]; t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0); if (semName == TGSI_SEMANTIC_INSTANCEID || semName == TGSI_SEMANTIC_VERTEXID) { @@ -5109,8 +5064,7 @@ st_translate_program( unsigned num_ubos = program->shader->NumUniformBlocks; for (i = 0; i < num_ubos; i++) { - unsigned size = - program->shader_program->UniformBlocks[i].UniformBufferSize; + unsigned size = program->shader->UniformBlocks[i].UniformBufferSize; unsigned num_const_vecs = (size + 15) / 16; unsigned first, last; assert(num_const_vecs > 0); diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.h b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.h index 2e7cb78d5..18f666f5b 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.h +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.h @@ -73,6 +73,7 @@ st_translate_stream_output_info(struct glsl_to_tgsi_visitor *glsl_to_tgsi, const GLuint outputMapping[], struct pipe_stream_output_info *so); +extern const unsigned _mesa_sysval_to_semantic[SYSTEM_VALUE_MAX]; #ifdef __cplusplus } 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 683cd1cac..26a5f51c7 100644 --- a/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/mesalib/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -44,6 +44,7 @@ #include "util/u_debug.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "st_glsl_to_tgsi.h" /* for _mesa_sysval_to_semantic */ #define PROGRAM_ANY_CONST ((1 << PROGRAM_STATE_VAR) | \ @@ -96,14 +97,6 @@ struct st_translate { }; -/** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */ -static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = { - TGSI_SEMANTIC_FACE, - TGSI_SEMANTIC_VERTEXID, - TGSI_SEMANTIC_INSTANCEID -}; - - /** * Make note of a branch to a label in the TGSI code. * After we've emitted all instructions, we'll go over the list @@ -1147,7 +1140,7 @@ st_translate_mesa_program( unsigned numSys = 0; for (i = 0; sysInputs; i++) { if (sysInputs & (1 << i)) { - unsigned semName = mesa_sysval_to_semantic[i]; + unsigned semName = _mesa_sysval_to_semantic[i]; t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0); if (semName == TGSI_SEMANTIC_INSTANCEID || semName == TGSI_SEMANTIC_VERTEXID) { diff --git a/mesalib/src/mesa/state_tracker/st_program.c b/mesalib/src/mesa/state_tracker/st_program.c index 9d7b7c475..fbf8930cb 100644 --- a/mesalib/src/mesa/state_tracker/st_program.c +++ b/mesalib/src/mesa/state_tracker/st_program.c @@ -393,13 +393,12 @@ st_translate_vertex_program(struct st_context *st, &vpv->tgsi.stream_output); } - vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi); - if (ST_DEBUG & DEBUG_TGSI) { - tgsi_dump( vpv->tgsi.tokens, 0 ); + tgsi_dump(vpv->tgsi.tokens, 0); debug_printf("\n"); } + vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi); return vpv; fail: @@ -804,15 +803,15 @@ st_translate_fragment_program(struct st_context *st, variant->tgsi.tokens = ureg_get_tokens( ureg, NULL ); ureg_destroy( ureg ); - /* fill in variant */ - variant->driver_shader = pipe->create_fs_state(pipe, &variant->tgsi); - variant->key = *key; - if (ST_DEBUG & DEBUG_TGSI) { - tgsi_dump( variant->tgsi.tokens, 0/*TGSI_DUMP_VERBOSE*/ ); + tgsi_dump(variant->tgsi.tokens, 0/*TGSI_DUMP_VERBOSE*/); debug_printf("\n"); } + /* fill in variant */ + variant->driver_shader = pipe->create_fs_state(pipe, &variant->tgsi); + variant->key = *key; + if (deleteFP) { /* Free the temporary program made above */ struct gl_fragment_program *fp = &stfp->Base; @@ -1173,10 +1172,6 @@ st_translate_geometry_program(struct st_context *st, &stgp->tgsi.stream_output); } - /* fill in new variant */ - gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi); - gpv->key = *key; - if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { _mesa_print_program(&stgp->Base.Base); debug_printf("\n"); @@ -1187,6 +1182,9 @@ st_translate_geometry_program(struct st_context *st, debug_printf("\n"); } + /* fill in new variant */ + gpv->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi); + gpv->key = *key; return gpv; } diff --git a/mesalib/src/mesa/swrast/s_texfetch.c b/mesalib/src/mesa/swrast/s_texfetch.c index e508368c8..aef023217 100644 --- a/mesalib/src/mesa/swrast/s_texfetch.c +++ b/mesalib/src/mesa/swrast/s_texfetch.c @@ -46,35 +46,7 @@ #include "s_texfetch.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" - - -/** - * 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]; -} - +#include "util/format_srgb.h" /* Texel fetch routines for all supported formats diff --git a/mesalib/src/mesa/swrast/s_texfetch_tmp.h b/mesalib/src/mesa/swrast/s_texfetch_tmp.h index deda59246..72037ec00 100644 --- a/mesalib/src/mesa/swrast/s_texfetch_tmp.h +++ b/mesalib/src/mesa/swrast/s_texfetch_tmp.h @@ -737,9 +737,9 @@ FETCH(BGR_SRGB8)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3); - texel[RCOMP] = nonlinear_to_linear(src[2]); - texel[GCOMP] = nonlinear_to_linear(src[1]); - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(src[2]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(src[1]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = 1.0F; } @@ -749,9 +749,9 @@ FETCH(A8B8G8R8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s >> 24) ); - texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 24) ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */ } @@ -761,9 +761,9 @@ FETCH(B8G8R8A8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ } @@ -773,9 +773,9 @@ FETCH(R8G8B8A8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ } @@ -785,9 +785,9 @@ FETCH(R8G8B8X8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); texel[ACOMP] = 1.0f; } @@ -799,7 +799,7 @@ FETCH(L_SRGB8)(const struct swrast_texture_image *texImage, const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1); texel[RCOMP] = texel[GCOMP] = - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = 1.0F; } @@ -811,7 +811,7 @@ FETCH(L8A8_SRGB)(const struct swrast_texture_image *texImage, const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2); texel[RCOMP] = texel[GCOMP] = - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */ } diff --git a/mesalib/src/mesa/x86/common_x86.c b/mesalib/src/mesa/x86/common_x86.c index b401c354a..2a936a473 100644 --- a/mesalib/src/mesa/x86/common_x86.c +++ b/mesalib/src/mesa/x86/common_x86.c @@ -343,16 +343,18 @@ _mesa_get_x86_features(void) #endif #elif defined(USE_X86_64_ASM) - unsigned int uninitialized_var(eax), uninitialized_var(ebx), - uninitialized_var(ecx), uninitialized_var(edx); + { + unsigned int uninitialized_var(eax), uninitialized_var(ebx), + uninitialized_var(ecx), uninitialized_var(edx); - /* Always available on x86-64. */ - _mesa_x86_cpu_features |= X86_FEATURE_XMM | X86_FEATURE_XMM2; + /* Always available on x86-64. */ + _mesa_x86_cpu_features |= X86_FEATURE_XMM | X86_FEATURE_XMM2; - __get_cpuid(1, &eax, &ebx, &ecx, &edx); + __get_cpuid(1, &eax, &ebx, &ecx, &edx); - if (ecx & bit_SSE4_1) - _mesa_x86_cpu_features |= X86_FEATURE_SSE4_1; + if (ecx & bit_SSE4_1) + _mesa_x86_cpu_features |= X86_FEATURE_SSE4_1; + } #endif /* USE_X86_64_ASM */ (void) detection_debug; |