diff options
Diffstat (limited to 'mesalib/src/gallium')
73 files changed, 10744 insertions, 9896 deletions
diff --git a/mesalib/src/gallium/Android.common.mk b/mesalib/src/gallium/Android.common.mk new file mode 100644 index 000000000..782510ff0 --- /dev/null +++ b/mesalib/src/gallium/Android.common.mk @@ -0,0 +1,32 @@ +# Mesa 3-D graphics library +# +# Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> +# Copyright (C) 2010-2011 LunarG Inc. +# +# 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. + +# src/gallium/Android.common.mk + +LOCAL_C_INCLUDES += \ + $(GALLIUM_TOP)/include \ + $(GALLIUM_TOP)/auxiliary \ + $(GALLIUM_TOP)/winsys \ + $(GALLIUM_TOP)/drivers + +include $(MESA_COMMON_MK) diff --git a/mesalib/src/gallium/Android.mk b/mesalib/src/gallium/Android.mk new file mode 100644 index 000000000..1d002d053 --- /dev/null +++ b/mesalib/src/gallium/Android.mk @@ -0,0 +1,72 @@ +# Mesa 3-D graphics library +# +# Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> +# Copyright (C) 2010-2011 LunarG Inc. +# +# 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. + +# src/gallium/Android.mk + +GALLIUM_TOP := $(call my-dir) +GALLIUM_COMMON_MK := $(GALLIUM_TOP)/Android.common.mk + +SUBDIRS := \ + targets/egl-static \ + state_trackers/egl \ + auxiliary + +# swrast +SUBDIRS += winsys/sw/android drivers/softpipe + +# i915g +ifneq ($(filter i915g, $(MESA_GPU_DRIVERS)),) +SUBDIRS += winsys/i915/drm drivers/i915 +endif + +# nouveau +ifneq ($(filter nouveau, $(MESA_GPU_DRIVERS)),) +SUBDIRS += \ + winsys/nouveau/drm \ + drivers/nouveau \ + drivers/nvfx \ + drivers/nv50 \ + drivers/nvc0 +endif + +# r300g/r600g/radeonsi +ifneq ($(filter r300g r600g radeonsi, $(MESA_GPU_DRIVERS)),) +SUBDIRS += winsys/radeon/drm +ifneq ($(filter r300g, $(MESA_GPU_DRIVERS)),) +SUBDIRS += drivers/r300 +endif +ifneq ($(filter r600g, $(MESA_GPU_DRIVERS)),) +SUBDIRS += drivers/r600 +endif +ifneq ($(filter radeonsi, $(MESA_GPU_DRIVERS)),) +SUBDIRS += drivers/radeonsi +endif +endif + +# vmwgfx +ifneq ($(filter vmwgfx, $(MESA_GPU_DRIVERS)),) +SUBDIRS += winsys/svga/drm drivers/svga +endif + +mkfiles := $(patsubst %,$(GALLIUM_TOP)/%/Android.mk,$(SUBDIRS)) +include $(mkfiles) diff --git a/mesalib/src/gallium/Makefile b/mesalib/src/gallium/Makefile new file mode 100644 index 000000000..79ca767f7 --- /dev/null +++ b/mesalib/src/gallium/Makefile @@ -0,0 +1,12 @@ +# src/gallium/Makefile +TOP = ../.. +include $(TOP)/configs/current + +SUBDIRS = $(GALLIUM_DIRS) + +default install clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1; \ + fi \ + done diff --git a/mesalib/src/gallium/Makefile.template b/mesalib/src/gallium/Makefile.template new file mode 100644 index 000000000..036c11986 --- /dev/null +++ b/mesalib/src/gallium/Makefile.template @@ -0,0 +1,73 @@ +# src/gallium/Makefile.template + +# Template makefile for gallium libraries. +# +# Usage: +# The minimum that the including makefile needs to define +# is TOP, LIBNAME and one of of the *_SOURCES. +# +# Optional defines: +# LIBRARY_INCLUDES are appended to the list of includes directories. +# LIBRARY_DEFINES is not used for makedepend, but for compilation. + +### Basic defines ### + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + $(LIBRARY_INCLUDES) + +ifeq ($(MESA_LLVM),1) +LIBRARY_DEFINES += $(LLVM_CFLAGS) +endif + + +##### TARGETS ##### + +default: depend lib$(LIBNAME).a $(PROGS) + +lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template + $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS) + +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null + +$(PROGS): % : %.o $(PROGS_DEPS) + $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find $(TOP)/src/gallium/include -name \*.h` + +# Remove .o and backup files +clean: + rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak $(CLEAN_EXTRA) + +# Dummy target +install: + @echo -n "" + +##### RULES ##### + +%.s: %.c + $(CC) -S $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.cpp + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.S + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + + +sinclude depend diff --git a/mesalib/src/gallium/README.portability b/mesalib/src/gallium/README.portability new file mode 100644 index 000000000..adecf4bb7 --- /dev/null +++ b/mesalib/src/gallium/README.portability @@ -0,0 +1,109 @@ + CROSS-PLATFORM PORTABILITY GUIDELINES FOR GALLIUM3D + + += General Considerations = + +The state tracker and winsys driver support a rather limited number of +platforms. However, the pipe drivers are meant to run in a wide number of +platforms. Hence the pipe drivers, the auxiliary modules, and all public +headers in general, should strictly follow these guidelines to ensure + + += Compiler Support = + +* Include the p_compiler.h. + +* Don't use the 'inline' keyword, use the INLINE macro in p_compiler.h instead. + +* Cast explicitly when converting to integer types of smaller sizes. + +* Cast explicitly when converting between float, double and integral types. + +* Don't use named struct initializers. + +* Don't use variable number of macro arguments. Use static inline functions +instead. + +* Don't use C99 features. + += Standard Library = + +* Avoid including standard library headers. Most standard library functions are +not available in Windows Kernel Mode. Use the appropriate p_*.h include. + +== Memory Allocation == + +* Use MALLOC, CALLOC, FREE instead of the malloc, calloc, free functions. + +* Use align_pointer() function defined in u_memory.h for aligning pointers + in a portable way. + +== Debugging == + +* Use the functions/macros in p_debug.h. + +* Don't include assert.h, call abort, printf, etc. + + += Code Style = + +== Inherantice in C == + +The main thing we do is mimic inheritance by structure containment. + +Here's a silly made-up example: + +/* base class */ +struct buffer +{ + int size; + void (*validate)(struct buffer *buf); +}; + +/* sub-class of bufffer */ +struct texture_buffer +{ + struct buffer base; /* the base class, MUST COME FIRST! */ + int format; + int width, height; +}; + + +Then, we'll typically have cast-wrapper functions to convert base-class +pointers to sub-class pointers where needed: + +static inline struct vertex_buffer *vertex_buffer(struct buffer *buf) +{ + return (struct vertex_buffer *) buf; +} + + +To create/init a sub-classed object: + +struct buffer *create_texture_buffer(int w, int h, int format) +{ + struct texture_buffer *t = malloc(sizeof(*t)); + t->format = format; + t->width = w; + t->height = h; + t->base.size = w * h; + t->base.validate = tex_validate; + return &t->base; +} + +Example sub-class method: + +void tex_validate(struct buffer *buf) +{ + struct texture_buffer *tb = texture_buffer(buf); + assert(tb->format); + assert(tb->width); + assert(tb->height); +} + + +Note that we typically do not use typedefs to make "class names"; we use +'struct whatever' everywhere. + +Gallium's pipe_context and the subclassed psb_context, etc are prime examples +of this. There's also many examples in Mesa and the Mesa state tracker. diff --git a/mesalib/src/gallium/SConscript b/mesalib/src/gallium/SConscript new file mode 100644 index 000000000..f281f4c65 --- /dev/null +++ b/mesalib/src/gallium/SConscript @@ -0,0 +1,179 @@ +Import('env') + +# +# Auxiliary modules +# + +SConscript('auxiliary/SConscript') + +# +# Drivers +# + +# These are common and work across all platforms +SConscript([ + 'drivers/galahad/SConscript', + 'drivers/identity/SConscript', + 'drivers/llvmpipe/SConscript', + 'drivers/rbug/SConscript', + 'drivers/softpipe/SConscript', + 'drivers/svga/SConscript', + 'drivers/trace/SConscript', +]) + +if not env['msvc']: + # These drivers do not build on MSVC compilers + SConscript([ + 'drivers/i915/SConscript', + ]) + +if env['drm']: + # These drivers depend on drm headers + if env['drm_radeon']: + SConscript([ + 'drivers/r300/SConscript', + 'drivers/r600/SConscript', + ]) + if env['llvm']: + SConscript([ + 'drivers/radeonsi/SConscript', + ]) + # XXX: nouveau drivers have a tight dependency on libdrm, so to enable + # we need some version logic before we enable them. Also, ATM there is + # no nouveau target in scons + # if env['drm_nouveau']: + # SConscript([ + # 'drivers/nouveau/SConscript', + # 'drivers/nv50/SConscript', + # 'drivers/nvc0/SConscript', + # 'drivers/nvfx/SConscript', + # ]) + +# +# State trackers +# + +# Needed by some state trackers +SConscript('winsys/sw/null/SConscript') + +if not env['embedded']: + SConscript('state_trackers/vega/SConscript') + if env['platform'] not in ('cygwin', 'darwin', 'haiku', 'sunos'): + SConscript('state_trackers/egl/SConscript') + + if env['x11']: + SConscript('state_trackers/glx/xlib/SConscript') + + if env['dri']: + SConscript('state_trackers/dri/SConscript') + + if env['dri'] and env['xorg']: + SConscript('state_trackers/xorg/SConscript') + + if env['platform'] == 'windows': + SConscript('state_trackers/wgl/SConscript') + +# +# Winsys +# + +SConscript([ + 'winsys/sw/wrapper/SConscript', +]) + +if env['x11']: + SConscript([ + 'winsys/sw/xlib/SConscript', + ]) + +if env['platform'] == 'windows': + SConscript([ + 'winsys/sw/gdi/SConscript', + ]) + +if not env['msvc']: + SConscript([ + 'winsys/i915/sw/SConscript', + ]) + +if env['dri']: + SConscript([ + 'winsys/sw/dri/SConscript', + ]) + + SConscript([ + 'winsys/svga/drm/SConscript', + ]) + + if env['drm_intel']: + SConscript([ + 'winsys/i915/drm/SConscript', + ]) + + if env['drm_radeon']: + SConscript([ + 'winsys/radeon/drm/SConscript', + ]) + +# +# Targets +# + +SConscript([ + 'targets/graw-null/SConscript', +]) + +if not env['embedded']: + if env['platform'] not in ('cygwin', 'darwin', 'freebsd', 'haiku', 'sunos'): + SConscript([ + 'targets/egl-static/SConscript' + ]) + + if env['x11']: + SConscript([ + 'targets/graw-xlib/SConscript', + 'targets/libgl-xlib/SConscript', + ]) + + if env['platform'] == 'windows': + SConscript([ + 'targets/graw-gdi/SConscript', + 'targets/libgl-gdi/SConscript', + ]) + + if env['dri']: + SConscript([ + 'targets/SConscript.dri', + 'targets/dri-swrast/SConscript', + 'targets/dri-vmwgfx/SConscript', + #'targets/dri-nouveau/SConscript', + ]) + if env['drm_intel']: + SConscript([ + 'targets/dri-i915/SConscript', + ]) + if env['drm_radeon']: + SConscript([ + 'targets/dri-r300/SConscript', + 'targets/dri-r600/SConscript', + ]) + if env['llvm']: + SConscript([ + 'targets/dri-radeonsi/SConscript', + ]) + + if env['xorg'] and env['drm']: + SConscript([ + #'targets/xorg-i915/SConscript', + #'targets/xorg-nouveau/SConscript', + #'targets/xorg-radeon/SConscript', + ]) + + +# +# Unit tests & tools +# + +if not env['embedded']: + SConscript('tests/unit/SConscript') + SConscript('tests/graw/SConscript') diff --git a/mesalib/src/gallium/auxiliary/Android.mk b/mesalib/src/gallium/auxiliary/Android.mk new file mode 100644 index 000000000..0c37dd31a --- /dev/null +++ b/mesalib/src/gallium/auxiliary/Android.mk @@ -0,0 +1,55 @@ +# Mesa 3-D graphics library +# +# Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> +# Copyright (C) 2010-2011 LunarG Inc. +# +# 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. + +LOCAL_PATH := $(call my-dir) + +# get C_SOURCES and GENERATED_SOURCES +include $(LOCAL_PATH)/Makefile.sources + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(C_SOURCES) + +LOCAL_C_INCLUDES := $(GALLIUM_TOP)/auxiliary/util + +LOCAL_MODULE := libmesa_gallium + +# generate sources +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +intermediates := $(call local-intermediates-dir) +LOCAL_GENERATED_SOURCES := $(addprefix $(intermediates)/, $(GENERATED_SOURCES)) + +$(LOCAL_GENERATED_SOURCES): PRIVATE_PYTHON := $(MESA_PYTHON2) +$(LOCAL_GENERATED_SOURCES): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PYTHON) $^ > $@ + +$(intermediates)/indices/u_indices_gen.c \ +$(intermediates)/indices/u_unfilled_gen.c \ +$(intermediates)/util/u_format_srgb.c \ +$(intermediates)/util/u_half.c: $(intermediates)/%.c: $(LOCAL_PATH)/%.py + $(transform-generated-source) + +$(intermediates)/util/u_format_table.c: $(intermediates)/%.c: $(LOCAL_PATH)/%.py $(LOCAL_PATH)/util/u_format.csv + $(transform-generated-source) + +include $(GALLIUM_COMMON_MK) +include $(BUILD_STATIC_LIBRARY) diff --git a/mesalib/src/gallium/auxiliary/Makefile b/mesalib/src/gallium/auxiliary/Makefile new file mode 100644 index 000000000..a70ae7384 --- /dev/null +++ b/mesalib/src/gallium/auxiliary/Makefile @@ -0,0 +1,44 @@ +TOP = ../../.. +include $(TOP)/configs/current + +LIBNAME = gallium + +# get source lists +include Makefile.sources + +C_SOURCES += $(GENERATED_SOURCES) + +ifeq ($(MESA_LLVM),1) +C_SOURCES += \ + $(GALLIVM_SOURCES) +CPP_SOURCES += \ + $(GALLIVM_CPP_SOURCES) +endif + + +include ../Makefile.template + +default install clean: %: subdirs-% + +subdirs-%: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $*) || exit 1; \ + fi \ + done + +indices/u_indices_gen.c: indices/u_indices_gen.py + $(PYTHON2) $< > $@ + +indices/u_unfilled_gen.c: indices/u_unfilled_gen.py + $(PYTHON2) $< > $@ + +util/u_format_srgb.c: util/u_format_srgb.py + $(PYTHON2) $< > $@ + +util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv + $(PYTHON2) util/u_format_table.py util/u_format.csv > $@ + +util/u_half.c: util/u_half.py + $(PYTHON2) util/u_half.py > $@ +# DO NOT DELETE diff --git a/mesalib/src/gallium/auxiliary/Makefile.sources b/mesalib/src/gallium/auxiliary/Makefile.sources new file mode 100644 index 000000000..277428b38 --- /dev/null +++ b/mesalib/src/gallium/auxiliary/Makefile.sources @@ -0,0 +1,197 @@ +SUBDIRS := pipe-loader + +C_SOURCES := \ + cso_cache/cso_cache.c \ + cso_cache/cso_context.c \ + cso_cache/cso_hash.c \ + draw/draw_context.c \ + draw/draw_fs.c \ + draw/draw_gs.c \ + draw/draw_pipe.c \ + draw/draw_pipe_aaline.c \ + draw/draw_pipe_aapoint.c \ + draw/draw_pipe_clip.c \ + draw/draw_pipe_cull.c \ + draw/draw_pipe_flatshade.c \ + draw/draw_pipe_offset.c \ + draw/draw_pipe_pstipple.c \ + draw/draw_pipe_stipple.c \ + draw/draw_pipe_twoside.c \ + draw/draw_pipe_unfilled.c \ + draw/draw_pipe_util.c \ + draw/draw_pipe_validate.c \ + draw/draw_pipe_vbuf.c \ + draw/draw_pipe_wide_line.c \ + draw/draw_pipe_wide_point.c \ + draw/draw_pt.c \ + draw/draw_pt_emit.c \ + draw/draw_pt_fetch.c \ + draw/draw_pt_fetch_emit.c \ + draw/draw_pt_fetch_shade_emit.c \ + draw/draw_pt_fetch_shade_pipeline.c \ + draw/draw_pt_post_vs.c \ + draw/draw_pt_so_emit.c \ + draw/draw_pt_util.c \ + draw/draw_pt_vsplit.c \ + draw/draw_vertex.c \ + draw/draw_vs.c \ + draw/draw_vs_exec.c \ + draw/draw_vs_ppc.c \ + draw/draw_vs_variant.c \ + os/os_misc.c \ + os/os_time.c \ + pipebuffer/pb_buffer_fenced.c \ + pipebuffer/pb_buffer_malloc.c \ + pipebuffer/pb_bufmgr_alt.c \ + pipebuffer/pb_bufmgr_cache.c \ + pipebuffer/pb_bufmgr_debug.c \ + pipebuffer/pb_bufmgr_mm.c \ + pipebuffer/pb_bufmgr_ondemand.c \ + pipebuffer/pb_bufmgr_pool.c \ + pipebuffer/pb_bufmgr_slab.c \ + pipebuffer/pb_validate.c \ + postprocess/pp_celshade.c \ + postprocess/pp_colors.c \ + postprocess/pp_init.c \ + postprocess/pp_mlaa.c \ + postprocess/pp_run.c \ + postprocess/pp_program.c \ + rbug/rbug_connection.c \ + rbug/rbug_context.c \ + rbug/rbug_core.c \ + rbug/rbug_demarshal.c \ + rbug/rbug_texture.c \ + rbug/rbug_shader.c \ + rtasm/rtasm_cpu.c \ + rtasm/rtasm_execmem.c \ + rtasm/rtasm_ppc.c \ + rtasm/rtasm_x86sse.c \ + tgsi/tgsi_build.c \ + tgsi/tgsi_dump.c \ + tgsi/tgsi_exec.c \ + tgsi/tgsi_info.c \ + tgsi/tgsi_iterate.c \ + tgsi/tgsi_parse.c \ + tgsi/tgsi_ppc.c \ + tgsi/tgsi_sanity.c \ + tgsi/tgsi_scan.c \ + tgsi/tgsi_strings.c \ + tgsi/tgsi_text.c \ + tgsi/tgsi_transform.c \ + tgsi/tgsi_ureg.c \ + tgsi/tgsi_util.c \ + translate/translate.c \ + translate/translate_cache.c \ + translate/translate_generic.c \ + translate/translate_sse.c \ + util/u_debug.c \ + util/u_debug_describe.c \ + util/u_debug_memory.c \ + util/u_debug_refcnt.c \ + util/u_debug_stack.c \ + util/u_debug_symbol.c \ + util/u_dump_defines.c \ + util/u_dump_state.c \ + util/u_bitmask.c \ + util/u_blit.c \ + util/u_blitter.c \ + util/u_cache.c \ + util/u_caps.c \ + util/u_cpu_detect.c \ + util/u_dl.c \ + util/u_draw.c \ + util/u_draw_quad.c \ + util/u_format.c \ + util/u_format_other.c \ + util/u_format_latc.c \ + util/u_format_s3tc.c \ + util/u_format_rgtc.c \ + util/u_format_etc.c \ + util/u_format_tests.c \ + util/u_format_yuv.c \ + util/u_format_zs.c \ + util/u_framebuffer.c \ + util/u_gen_mipmap.c \ + util/u_handle_table.c \ + util/u_hash.c \ + util/u_hash_table.c \ + util/u_index_modify.c \ + util/u_keymap.c \ + util/u_linear.c \ + util/u_linkage.c \ + util/u_network.c \ + util/u_math.c \ + util/u_mm.c \ + util/u_pstipple.c \ + util/u_rect.c \ + util/u_ringbuffer.c \ + util/u_sampler.c \ + util/u_simple_shaders.c \ + util/u_slab.c \ + util/u_snprintf.c \ + util/u_staging.c \ + util/u_surface.c \ + util/u_surfaces.c \ + util/u_texture.c \ + util/u_tile.c \ + util/u_transfer.c \ + util/u_resource.c \ + util/u_upload_mgr.c \ + util/u_vbuf.c \ + vl/vl_csc.c \ + vl/vl_compositor.c \ + vl/vl_matrix_filter.c \ + vl/vl_median_filter.c \ + vl/vl_decoder.c \ + vl/vl_mpeg12_decoder.c \ + vl/vl_mpeg12_bitstream.c \ + vl/vl_zscan.c \ + vl/vl_idct.c \ + vl/vl_mc.c \ + vl/vl_vertex_buffers.c \ + vl/vl_video_buffer.c + +GENERATED_SOURCES := \ + indices/u_indices_gen.c \ + indices/u_unfilled_gen.c \ + util/u_format_srgb.c \ + util/u_format_table.c \ + util/u_half.c + +GALLIVM_SOURCES := \ + gallivm/lp_bld_arit.c \ + gallivm/lp_bld_assert.c \ + gallivm/lp_bld_bitarit.c \ + gallivm/lp_bld_const.c \ + gallivm/lp_bld_conv.c \ + gallivm/lp_bld_flow.c \ + gallivm/lp_bld_format_aos.c \ + gallivm/lp_bld_format_soa.c \ + gallivm/lp_bld_format_yuv.c \ + gallivm/lp_bld_gather.c \ + gallivm/lp_bld_init.c \ + gallivm/lp_bld_intr.c \ + gallivm/lp_bld_logic.c \ + gallivm/lp_bld_pack.c \ + gallivm/lp_bld_printf.c \ + gallivm/lp_bld_quad.c \ + gallivm/lp_bld_sample.c \ + gallivm/lp_bld_sample_aos.c \ + gallivm/lp_bld_sample_soa.c \ + gallivm/lp_bld_struct.c \ + gallivm/lp_bld_swizzle.c \ + gallivm/lp_bld_tgsi.c \ + gallivm/lp_bld_tgsi_action.c \ + gallivm/lp_bld_tgsi_aos.c \ + gallivm/lp_bld_tgsi_info.c \ + gallivm/lp_bld_tgsi_soa.c \ + gallivm/lp_bld_type.c \ + draw/draw_llvm.c \ + draw/draw_llvm_sample.c \ + draw/draw_llvm_translate.c \ + draw/draw_vs_llvm.c \ + draw/draw_pt_fetch_shade_pipeline_llvm.c + +GALLIVM_CPP_SOURCES := \ + gallivm/lp_bld_debug.cpp \ + gallivm/lp_bld_misc.cpp diff --git a/mesalib/src/gallium/auxiliary/SConscript b/mesalib/src/gallium/auxiliary/SConscript new file mode 100644 index 000000000..07c420e13 --- /dev/null +++ b/mesalib/src/gallium/auxiliary/SConscript @@ -0,0 +1,72 @@ +Import('*') + +from sys import executable as python_cmd + +env.Append(CPPPATH = [ + 'indices', + 'util', +]) + +env.CodeGenerate( + target = 'indices/u_indices_gen.c', + script = 'indices/u_indices_gen.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'indices/u_unfilled_gen.c', + script = 'indices/u_unfilled_gen.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_format_srgb.c', + script = 'util/u_format_srgb.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_format_table.c', + script = '#src/gallium/auxiliary/util/u_format_table.py', + source = ['#src/gallium/auxiliary/util/u_format.csv'], + command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_half.c', + script = 'util/u_half.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.Depends('util/u_format_table.c', [ + '#src/gallium/auxiliary/util/u_format_parse.py', + 'util/u_format_pack.py', +]) + +source = env.ParseSourceList('Makefile.sources', [ + 'C_SOURCES', + 'GENERATED_SOURCES' +]) + +if env['llvm']: + source += env.ParseSourceList('Makefile.sources', [ + 'GALLIVM_SOURCES', + 'GALLIVM_CPP_SOURCES' + ]) + + if env['toolchain'] == 'crossmingw': + # compile lp_bld_misc.cpp without -gstabs option + source = env.compile_without_gstabs(source, "gallivm/lp_bld_misc.cpp") + +gallium = env.ConvenienceLibrary( + target = 'gallium', + source = source, +) + +env.Alias('gallium', gallium) + +Export('gallium') diff --git a/mesalib/src/gallium/auxiliary/util/.gitignore b/mesalib/src/gallium/auxiliary/util/.gitignore new file mode 100644 index 000000000..5dd0408ef --- /dev/null +++ b/mesalib/src/gallium/auxiliary/util/.gitignore @@ -0,0 +1,3 @@ +u_format_srgb.c +u_format_table.c +u_half.c diff --git a/mesalib/src/gallium/auxiliary/util/dbghelp.h b/mesalib/src/gallium/auxiliary/util/dbghelp.h index da5e3ad08..bc7c53cf9 100644 --- a/mesalib/src/gallium/auxiliary/util/dbghelp.h +++ b/mesalib/src/gallium/auxiliary/util/dbghelp.h @@ -1,1265 +1,1265 @@ -/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the w64 mingw-runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-#ifndef _DBGHELP_
-#define _DBGHELP_
-
-#ifdef _WIN64
-#ifndef _IMAGEHLP64
-#define _IMAGEHLP64
-#endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define IMAGEAPI DECLSPEC_IMPORT WINAPI
-#define DBHLP_DEPRECIATED __declspec(deprecated)
-
-#define DBHLPAPI IMAGEAPI
-
-#define IMAGE_SEPARATION (64*1024)
-
- typedef struct _LOADED_IMAGE {
- PSTR ModuleName;
- HANDLE hFile;
- PUCHAR MappedAddress;
-#ifdef _IMAGEHLP64
- PIMAGE_NT_HEADERS64 FileHeader;
-#else
- PIMAGE_NT_HEADERS32 FileHeader;
-#endif
- PIMAGE_SECTION_HEADER LastRvaSection;
- ULONG NumberOfSections;
- PIMAGE_SECTION_HEADER Sections;
- ULONG Characteristics;
- BOOLEAN fSystemImage;
- BOOLEAN fDOSImage;
- LIST_ENTRY Links;
- ULONG SizeOfImage;
- } LOADED_IMAGE,*PLOADED_IMAGE;
-
-#define MAX_SYM_NAME 2000
-
- typedef BOOL (CALLBACK *PFIND_DEBUG_FILE_CALLBACK)(HANDLE FileHandle,PSTR FileName,PVOID CallerData);
- typedef BOOL (CALLBACK *PFINDFILEINPATHCALLBACK)(PSTR filename,PVOID context);
- typedef BOOL (CALLBACK *PFIND_EXE_FILE_CALLBACK)(HANDLE FileHandle,PSTR FileName,PVOID CallerData);
-
- typedef BOOL (WINAPI *PSYMBOLSERVERPROC)(LPCSTR,LPCSTR,PVOID,DWORD,DWORD,LPSTR);
- typedef BOOL (WINAPI *PSYMBOLSERVEROPENPROC)(VOID);
- typedef BOOL (WINAPI *PSYMBOLSERVERCLOSEPROC)(VOID);
- typedef BOOL (WINAPI *PSYMBOLSERVERSETOPTIONSPROC)(UINT_PTR,ULONG64);
- typedef BOOL (CALLBACK WINAPI *PSYMBOLSERVERCALLBACKPROC)(UINT_PTR action,ULONG64 data,ULONG64 context);
- typedef UINT_PTR (WINAPI *PSYMBOLSERVERGETOPTIONSPROC)();
- typedef BOOL (WINAPI *PSYMBOLSERVERPINGPROC)(LPCSTR);
-
- HANDLE IMAGEAPI FindDebugInfoFile(PSTR FileName,PSTR SymbolPath,PSTR DebugFilePath);
- HANDLE IMAGEAPI FindDebugInfoFileEx(PSTR FileName,PSTR SymbolPath,PSTR DebugFilePath,PFIND_DEBUG_FILE_CALLBACK Callback,PVOID CallerData);
- BOOL IMAGEAPI SymFindFileInPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,PVOID id,DWORD two,DWORD three,DWORD flags,LPSTR FoundFile,PFINDFILEINPATHCALLBACK callback,PVOID context);
- HANDLE IMAGEAPI FindExecutableImage(PSTR FileName,PSTR SymbolPath,PSTR ImageFilePath);
- HANDLE IMAGEAPI FindExecutableImageEx(PSTR FileName,PSTR SymbolPath,PSTR ImageFilePath,PFIND_EXE_FILE_CALLBACK Callback,PVOID CallerData);
- PIMAGE_NT_HEADERS IMAGEAPI ImageNtHeader(PVOID Base);
- PVOID IMAGEAPI ImageDirectoryEntryToDataEx(PVOID Base,BOOLEAN MappedAsImage,USHORT DirectoryEntry,PULONG Size,PIMAGE_SECTION_HEADER *FoundHeader);
- PVOID IMAGEAPI ImageDirectoryEntryToData(PVOID Base,BOOLEAN MappedAsImage,USHORT DirectoryEntry,PULONG Size);
- PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection(PIMAGE_NT_HEADERS NtHeaders,PVOID Base,ULONG Rva);
- PVOID IMAGEAPI ImageRvaToVa(PIMAGE_NT_HEADERS NtHeaders,PVOID Base,ULONG Rva,PIMAGE_SECTION_HEADER *LastRvaSection);
-
-#define SSRVOPT_CALLBACK 0x0001
-#define SSRVOPT_DWORD 0x0002
-#define SSRVOPT_DWORDPTR 0x0004
-#define SSRVOPT_GUIDPTR 0x0008
-#define SSRVOPT_OLDGUIDPTR 0x0010
-#define SSRVOPT_UNATTENDED 0x0020
-#define SSRVOPT_NOCOPY 0x0040
-#define SSRVOPT_PARENTWIN 0x0080
-#define SSRVOPT_PARAMTYPE 0x0100
-#define SSRVOPT_SECURE 0x0200
-#define SSRVOPT_TRACE 0x0400
-#define SSRVOPT_SETCONTEXT 0x0800
-#define SSRVOPT_PROXY 0x1000
-#define SSRVOPT_DOWNSTREAM_STORE 0x2000
-#define SSRVOPT_RESET ((ULONG_PTR)-1)
-
-#define SSRVACTION_TRACE 1
-#define SSRVACTION_QUERYCANCEL 2
-#define SSRVACTION_EVENT 3
-
-#ifndef _WIN64
-
- typedef struct _IMAGE_DEBUG_INFORMATION {
- LIST_ENTRY List;
- DWORD ReservedSize;
- PVOID ReservedMappedBase;
- USHORT ReservedMachine;
- USHORT ReservedCharacteristics;
- DWORD ReservedCheckSum;
- DWORD ImageBase;
- DWORD SizeOfImage;
- DWORD ReservedNumberOfSections;
- PIMAGE_SECTION_HEADER ReservedSections;
- DWORD ReservedExportedNamesSize;
- PSTR ReservedExportedNames;
- DWORD ReservedNumberOfFunctionTableEntries;
- PIMAGE_FUNCTION_ENTRY ReservedFunctionTableEntries;
- DWORD ReservedLowestFunctionStartingAddress;
- DWORD ReservedHighestFunctionEndingAddress;
- DWORD ReservedNumberOfFpoTableEntries;
- PFPO_DATA ReservedFpoTableEntries;
- DWORD SizeOfCoffSymbols;
- PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols;
- DWORD ReservedSizeOfCodeViewSymbols;
- PVOID ReservedCodeViewSymbols;
- PSTR ImageFilePath;
- PSTR ImageFileName;
- PSTR ReservedDebugFilePath;
- DWORD ReservedTimeDateStamp;
- BOOL ReservedRomImage;
- PIMAGE_DEBUG_DIRECTORY ReservedDebugDirectory;
- DWORD ReservedNumberOfDebugDirectories;
- DWORD ReservedOriginalFunctionTableBaseAddress;
- DWORD Reserved[2 ];
- } IMAGE_DEBUG_INFORMATION,*PIMAGE_DEBUG_INFORMATION;
-
- PIMAGE_DEBUG_INFORMATION IMAGEAPI MapDebugInformation(HANDLE FileHandle,PSTR FileName,PSTR SymbolPath,DWORD ImageBase);
- BOOL IMAGEAPI UnmapDebugInformation(PIMAGE_DEBUG_INFORMATION DebugInfo);
-#endif
-
- typedef BOOL (CALLBACK *PENUMDIRTREE_CALLBACK)(LPCSTR FilePath,PVOID CallerData);
-
- BOOL IMAGEAPI SearchTreeForFile(PSTR RootPath,PSTR InputPathName,PSTR OutputPathBuffer);
- BOOL IMAGEAPI EnumDirTree(HANDLE hProcess,PSTR RootPath,PSTR InputPathName,PSTR OutputPathBuffer,PENUMDIRTREE_CALLBACK Callback,PVOID CallbackData);
- BOOL IMAGEAPI MakeSureDirectoryPathExists(PCSTR DirPath);
-
-#define UNDNAME_COMPLETE (0x0000)
-#define UNDNAME_NO_LEADING_UNDERSCORES (0x0001)
-#define UNDNAME_NO_MS_KEYWORDS (0x0002)
-#define UNDNAME_NO_FUNCTION_RETURNS (0x0004)
-#define UNDNAME_NO_ALLOCATION_MODEL (0x0008)
-#define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010)
-#define UNDNAME_NO_MS_THISTYPE (0x0020)
-#define UNDNAME_NO_CV_THISTYPE (0x0040)
-#define UNDNAME_NO_THISTYPE (0x0060)
-#define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080)
-#define UNDNAME_NO_THROW_SIGNATURES (0x0100)
-#define UNDNAME_NO_MEMBER_TYPE (0x0200)
-#define UNDNAME_NO_RETURN_UDT_MODEL (0x0400)
-#define UNDNAME_32_BIT_DECODE (0x0800)
-#define UNDNAME_NAME_ONLY (0x1000)
-#define UNDNAME_NO_ARGUMENTS (0x2000)
-#define UNDNAME_NO_SPECIAL_SYMS (0x4000)
-
- DWORD IMAGEAPI WINAPI UnDecorateSymbolName(PCSTR DecoratedName,PSTR UnDecoratedName,DWORD UndecoratedLength,DWORD Flags);
-
-#define DBHHEADER_DEBUGDIRS 0x1
-
- typedef struct _MODLOAD_DATA {
- DWORD ssize;
- DWORD ssig;
- PVOID data;
- DWORD size;
- DWORD flags;
- } MODLOAD_DATA,*PMODLOAD_DATA;
-
- typedef enum {
- AddrMode1616,AddrMode1632,AddrModeReal,AddrModeFlat
- } ADDRESS_MODE;
-
- typedef struct _tagADDRESS64 {
- DWORD64 Offset;
- WORD Segment;
- ADDRESS_MODE Mode;
- } ADDRESS64,*LPADDRESS64;
-
-#ifdef _IMAGEHLP64
-#define ADDRESS ADDRESS64
-#define LPADDRESS LPADDRESS64
-#else
- typedef struct _tagADDRESS {
- DWORD Offset;
- WORD Segment;
- ADDRESS_MODE Mode;
- } ADDRESS,*LPADDRESS;
-
- static __inline void Address32To64(LPADDRESS a32,LPADDRESS64 a64) {
- a64->Offset = (ULONG64)(LONG64)(LONG)a32->Offset;
- a64->Segment = a32->Segment;
- a64->Mode = a32->Mode;
- }
-
- static __inline void Address64To32(LPADDRESS64 a64,LPADDRESS a32) {
- a32->Offset = (ULONG)a64->Offset;
- a32->Segment = a64->Segment;
- a32->Mode = a64->Mode;
- }
-#endif
-
- typedef struct _KDHELP64 {
- DWORD64 Thread;
- DWORD ThCallbackStack;
- DWORD ThCallbackBStore;
- DWORD NextCallback;
- DWORD FramePointer;
- DWORD64 KiCallUserMode;
- DWORD64 KeUserCallbackDispatcher;
- DWORD64 SystemRangeStart;
- DWORD64 Reserved[8];
- } KDHELP64,*PKDHELP64;
-
-#ifdef _IMAGEHLP64
-#define KDHELP KDHELP64
-#define PKDHELP PKDHELP64
-#else
- typedef struct _KDHELP {
- DWORD Thread;
- DWORD ThCallbackStack;
- DWORD NextCallback;
- DWORD FramePointer;
- DWORD KiCallUserMode;
- DWORD KeUserCallbackDispatcher;
- DWORD SystemRangeStart;
- DWORD ThCallbackBStore;
- DWORD Reserved[8];
- } KDHELP,*PKDHELP;
-
- static __inline void KdHelp32To64(PKDHELP p32,PKDHELP64 p64) {
- p64->Thread = p32->Thread;
- p64->ThCallbackStack = p32->ThCallbackStack;
- p64->NextCallback = p32->NextCallback;
- p64->FramePointer = p32->FramePointer;
- p64->KiCallUserMode = p32->KiCallUserMode;
- p64->KeUserCallbackDispatcher = p32->KeUserCallbackDispatcher;
- p64->SystemRangeStart = p32->SystemRangeStart;
- }
-#endif
-
- typedef struct _tagSTACKFRAME64 {
- ADDRESS64 AddrPC;
- ADDRESS64 AddrReturn;
- ADDRESS64 AddrFrame;
- ADDRESS64 AddrStack;
- ADDRESS64 AddrBStore;
- PVOID FuncTableEntry;
- DWORD64 Params[4];
- BOOL Far;
- BOOL Virtual;
- DWORD64 Reserved[3];
- KDHELP64 KdHelp;
- } STACKFRAME64,*LPSTACKFRAME64;
-
-#ifdef _IMAGEHLP64
-#define STACKFRAME STACKFRAME64
-#define LPSTACKFRAME LPSTACKFRAME64
-#else
- typedef struct _tagSTACKFRAME {
- ADDRESS AddrPC;
- ADDRESS AddrReturn;
- ADDRESS AddrFrame;
- ADDRESS AddrStack;
- PVOID FuncTableEntry;
- DWORD Params[4];
- BOOL Far;
- BOOL Virtual;
- DWORD Reserved[3];
- KDHELP KdHelp;
- ADDRESS AddrBStore;
- } STACKFRAME,*LPSTACKFRAME;
-#endif
-
- typedef BOOL (WINAPI *PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess,DWORD64 qwBaseAddress,PVOID lpBuffer,DWORD nSize,LPDWORD lpNumberOfBytesRead);
- typedef PVOID (WINAPI *PFUNCTION_TABLE_ACCESS_ROUTINE64)(HANDLE hProcess,DWORD64 AddrBase);
- typedef DWORD64 (WINAPI *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess,DWORD64 Address);
- typedef DWORD64 (WINAPI *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess,HANDLE hThread,LPADDRESS64 lpaddr);
-
- BOOL IMAGEAPI StackWalk64(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME64 StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
-
-#ifdef _IMAGEHLP64
-#define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64
-#define PFUNCTION_TABLE_ACCESS_ROUTINE PFUNCTION_TABLE_ACCESS_ROUTINE64
-#define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64
-#define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64
-#define StackWalk StackWalk64
-#else
- typedef BOOL (WINAPI *PREAD_PROCESS_MEMORY_ROUTINE)(HANDLE hProcess,DWORD lpBaseAddress,PVOID lpBuffer,DWORD nSize,PDWORD lpNumberOfBytesRead);
- typedef PVOID (WINAPI *PFUNCTION_TABLE_ACCESS_ROUTINE)(HANDLE hProcess,DWORD AddrBase);
- typedef DWORD (WINAPI *PGET_MODULE_BASE_ROUTINE)(HANDLE hProcess,DWORD Address);
- typedef DWORD (WINAPI *PTRANSLATE_ADDRESS_ROUTINE)(HANDLE hProcess,HANDLE hThread,LPADDRESS lpaddr);
-
- BOOL IMAGEAPI StackWalk(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE TranslateAddress);
-#endif
-
-#define API_VERSION_NUMBER 9
-
- typedef struct API_VERSION {
- USHORT MajorVersion;
- USHORT MinorVersion;
- USHORT Revision;
- USHORT Reserved;
- } API_VERSION,*LPAPI_VERSION;
-
- LPAPI_VERSION IMAGEAPI ImagehlpApiVersion(VOID);
- LPAPI_VERSION IMAGEAPI ImagehlpApiVersionEx(LPAPI_VERSION AppVersion);
- DWORD IMAGEAPI GetTimestampForLoadedLibrary(HMODULE Module);
-
- typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK64)(PSTR ModuleName,DWORD64 BaseOfDll,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64)(PSTR SymbolName,DWORD64 SymbolAddress,ULONG SymbolSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64W)(PWSTR SymbolName,DWORD64 SymbolAddress,ULONG SymbolSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACK64)(PSTR ModuleName,DWORD64 ModuleBase,ULONG ModuleSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(HANDLE hProcess,ULONG ActionCode,ULONG64 CallbackData,ULONG64 UserContext);
- typedef PVOID (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK)(HANDLE hProcess,DWORD AddrBase,PVOID UserContext);
- typedef PVOID (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK64)(HANDLE hProcess,ULONG64 AddrBase,ULONG64 UserContext);
-
-#ifdef _IMAGEHLP64
-#define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64
-#define PSYM_ENUMSYMBOLS_CALLBACK PSYM_ENUMSYMBOLS_CALLBACK64
-#define PSYM_ENUMSYMBOLS_CALLBACKW PSYM_ENUMSYMBOLS_CALLBACK64W
-#define PENUMLOADED_MODULES_CALLBACK PENUMLOADED_MODULES_CALLBACK64
-#define PSYMBOL_REGISTERED_CALLBACK PSYMBOL_REGISTERED_CALLBACK64
-#define PSYMBOL_FUNCENTRY_CALLBACK PSYMBOL_FUNCENTRY_CALLBACK64
-#else
- typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)(PSTR ModuleName,ULONG BaseOfDll,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK)(PSTR SymbolName,ULONG SymbolAddress,ULONG SymbolSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACKW)(PWSTR SymbolName,ULONG SymbolAddress,ULONG SymbolSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACK)(PSTR ModuleName,ULONG ModuleBase,ULONG ModuleSize,PVOID UserContext);
- typedef BOOL (CALLBACK *PSYMBOL_REGISTERED_CALLBACK)(HANDLE hProcess,ULONG ActionCode,PVOID CallbackData,PVOID UserContext);
-#endif
-
-#define SYMFLAG_VALUEPRESENT 0x00000001
-#define SYMFLAG_REGISTER 0x00000008
-#define SYMFLAG_REGREL 0x00000010
-#define SYMFLAG_FRAMEREL 0x00000020
-#define SYMFLAG_PARAMETER 0x00000040
-#define SYMFLAG_LOCAL 0x00000080
-#define SYMFLAG_CONSTANT 0x00000100
-#define SYMFLAG_EXPORT 0x00000200
-#define SYMFLAG_FORWARDER 0x00000400
-#define SYMFLAG_FUNCTION 0x00000800
-#define SYMFLAG_VIRTUAL 0x00001000
-#define SYMFLAG_THUNK 0x00002000
-#define SYMFLAG_TLSREL 0x00004000
-
- typedef enum {
- SymNone = 0,SymCoff,SymCv,SymPdb,SymExport,SymDeferred,SymSym,SymDia,SymVirtual,NumSymTypes
- } SYM_TYPE;
-
- typedef struct _IMAGEHLP_SYMBOL64 {
- DWORD SizeOfStruct;
- DWORD64 Address;
- DWORD Size;
- DWORD Flags;
- DWORD MaxNameLength;
- CHAR Name[1];
- } IMAGEHLP_SYMBOL64,*PIMAGEHLP_SYMBOL64;
-
- typedef struct _IMAGEHLP_SYMBOL64_PACKAGE {
- IMAGEHLP_SYMBOL64 sym;
- CHAR name[MAX_SYM_NAME + 1];
- } IMAGEHLP_SYMBOL64_PACKAGE,*PIMAGEHLP_SYMBOL64_PACKAGE;
-
-#ifdef _IMAGEHLP64
-
-#define IMAGEHLP_SYMBOL IMAGEHLP_SYMBOL64
-#define PIMAGEHLP_SYMBOL PIMAGEHLP_SYMBOL64
-#define IMAGEHLP_SYMBOL_PACKAGE IMAGEHLP_SYMBOL64_PACKAGE
-#define PIMAGEHLP_SYMBOL_PACKAGE PIMAGEHLP_SYMBOL64_PACKAGE
-#else
-
- typedef struct _IMAGEHLP_SYMBOL {
- DWORD SizeOfStruct;
- DWORD Address;
- DWORD Size;
- DWORD Flags;
- DWORD MaxNameLength;
- CHAR Name[1];
- } IMAGEHLP_SYMBOL,*PIMAGEHLP_SYMBOL;
-
- typedef struct _IMAGEHLP_SYMBOL_PACKAGE {
- IMAGEHLP_SYMBOL sym;
- CHAR name[MAX_SYM_NAME + 1];
- } IMAGEHLP_SYMBOL_PACKAGE,*PIMAGEHLP_SYMBOL_PACKAGE;
-#endif
-
- typedef struct _IMAGEHLP_MODULE64 {
- DWORD SizeOfStruct;
- DWORD64 BaseOfImage;
- DWORD ImageSize;
- DWORD TimeDateStamp;
- DWORD CheckSum;
- DWORD NumSyms;
- SYM_TYPE SymType;
- CHAR ModuleName[32];
- CHAR ImageName[256];
- CHAR LoadedImageName[256];
- CHAR LoadedPdbName[256];
- DWORD CVSig;
- CHAR CVData[MAX_PATH*3];
- DWORD PdbSig;
- GUID PdbSig70;
- DWORD PdbAge;
- BOOL PdbUnmatched;
- BOOL DbgUnmatched;
- BOOL LineNumbers;
- BOOL GlobalSymbols;
- BOOL TypeInfo;
- } IMAGEHLP_MODULE64,*PIMAGEHLP_MODULE64;
-
- typedef struct _IMAGEHLP_MODULE64W {
- DWORD SizeOfStruct;
- DWORD64 BaseOfImage;
- DWORD ImageSize;
- DWORD TimeDateStamp;
- DWORD CheckSum;
- DWORD NumSyms;
- SYM_TYPE SymType;
- WCHAR ModuleName[32];
- WCHAR ImageName[256];
- WCHAR LoadedImageName[256];
- WCHAR LoadedPdbName[256];
- DWORD CVSig;
- WCHAR CVData[MAX_PATH*3];
- DWORD PdbSig;
- GUID PdbSig70;
- DWORD PdbAge;
- BOOL PdbUnmatched;
- BOOL DbgUnmatched;
- BOOL LineNumbers;
- BOOL GlobalSymbols;
- BOOL TypeInfo;
- } IMAGEHLP_MODULEW64,*PIMAGEHLP_MODULEW64;
-
-#ifdef _IMAGEHLP64
-#define IMAGEHLP_MODULE IMAGEHLP_MODULE64
-#define PIMAGEHLP_MODULE PIMAGEHLP_MODULE64
-#define IMAGEHLP_MODULEW IMAGEHLP_MODULEW64
-#define PIMAGEHLP_MODULEW PIMAGEHLP_MODULEW64
-#else
- typedef struct _IMAGEHLP_MODULE {
- DWORD SizeOfStruct;
- DWORD BaseOfImage;
- DWORD ImageSize;
- DWORD TimeDateStamp;
- DWORD CheckSum;
- DWORD NumSyms;
- SYM_TYPE SymType;
- CHAR ModuleName[32];
- CHAR ImageName[256];
- CHAR LoadedImageName[256];
- } IMAGEHLP_MODULE,*PIMAGEHLP_MODULE;
-
- typedef struct _IMAGEHLP_MODULEW {
- DWORD SizeOfStruct;
- DWORD BaseOfImage;
- DWORD ImageSize;
- DWORD TimeDateStamp;
- DWORD CheckSum;
- DWORD NumSyms;
- SYM_TYPE SymType;
- WCHAR ModuleName[32];
- WCHAR ImageName[256];
- WCHAR LoadedImageName[256];
- } IMAGEHLP_MODULEW,*PIMAGEHLP_MODULEW;
-#endif
-
- typedef struct _IMAGEHLP_LINE64 {
- DWORD SizeOfStruct;
- PVOID Key;
- DWORD LineNumber;
- PCHAR FileName;
- DWORD64 Address;
- } IMAGEHLP_LINE64,*PIMAGEHLP_LINE64;
-
-#ifdef _IMAGEHLP64
-#define IMAGEHLP_LINE IMAGEHLP_LINE64
-#define PIMAGEHLP_LINE PIMAGEHLP_LINE64
-#else
- typedef struct _IMAGEHLP_LINE {
- DWORD SizeOfStruct;
- PVOID Key;
- DWORD LineNumber;
- PCHAR FileName;
- DWORD Address;
- } IMAGEHLP_LINE,*PIMAGEHLP_LINE;
-#endif
-
- typedef struct _SOURCEFILE {
- DWORD64 ModBase;
- PCHAR FileName;
- } SOURCEFILE,*PSOURCEFILE;
-
-#define CBA_DEFERRED_SYMBOL_LOAD_START 0x00000001
-#define CBA_DEFERRED_SYMBOL_LOAD_COMPLETE 0x00000002
-#define CBA_DEFERRED_SYMBOL_LOAD_FAILURE 0x00000003
-#define CBA_SYMBOLS_UNLOADED 0x00000004
-#define CBA_DUPLICATE_SYMBOL 0x00000005
-#define CBA_READ_MEMORY 0x00000006
-#define CBA_DEFERRED_SYMBOL_LOAD_CANCEL 0x00000007
-#define CBA_SET_OPTIONS 0x00000008
-#define CBA_EVENT 0x00000010
-#define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL 0x00000020
-#define CBA_DEBUG_INFO 0x10000000
-
- typedef struct _IMAGEHLP_CBA_READ_MEMORY {
- DWORD64 addr;
- PVOID buf;
- DWORD bytes;
- DWORD *bytesread;
- } IMAGEHLP_CBA_READ_MEMORY,*PIMAGEHLP_CBA_READ_MEMORY;
-
- enum {
- sevInfo = 0,sevProblem,sevAttn,sevFatal,sevMax
- };
-
- typedef struct _IMAGEHLP_CBA_EVENT {
- DWORD severity;
- DWORD code;
- PCHAR desc;
- PVOID object;
- } IMAGEHLP_CBA_EVENT,*PIMAGEHLP_CBA_EVENT;
-
- typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD64 {
- DWORD SizeOfStruct;
- DWORD64 BaseOfImage;
- DWORD CheckSum;
- DWORD TimeDateStamp;
- CHAR FileName[MAX_PATH];
- BOOLEAN Reparse;
- HANDLE hFile;
- DWORD Flags;
- } IMAGEHLP_DEFERRED_SYMBOL_LOAD64,*PIMAGEHLP_DEFERRED_SYMBOL_LOAD64;
-
-#define DSLFLAG_MISMATCHED_PDB 0x1
-#define DSLFLAG_MISMATCHED_DBG 0x2
-
-#ifdef _IMAGEHLP64
-#define IMAGEHLP_DEFERRED_SYMBOL_LOAD IMAGEHLP_DEFERRED_SYMBOL_LOAD64
-#define PIMAGEHLP_DEFERRED_SYMBOL_LOAD PIMAGEHLP_DEFERRED_SYMBOL_LOAD64
-#else
- typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD {
- DWORD SizeOfStruct;
- DWORD BaseOfImage;
- DWORD CheckSum;
- DWORD TimeDateStamp;
- CHAR FileName[MAX_PATH];
- BOOLEAN Reparse;
- HANDLE hFile;
- } IMAGEHLP_DEFERRED_SYMBOL_LOAD,*PIMAGEHLP_DEFERRED_SYMBOL_LOAD;
-#endif
-
- typedef struct _IMAGEHLP_DUPLICATE_SYMBOL64 {
- DWORD SizeOfStruct;
- DWORD NumberOfDups;
- PIMAGEHLP_SYMBOL64 Symbol;
- DWORD SelectedSymbol;
- } IMAGEHLP_DUPLICATE_SYMBOL64,*PIMAGEHLP_DUPLICATE_SYMBOL64;
-
-#ifdef _IMAGEHLP64
-#define IMAGEHLP_DUPLICATE_SYMBOL IMAGEHLP_DUPLICATE_SYMBOL64
-#define PIMAGEHLP_DUPLICATE_SYMBOL PIMAGEHLP_DUPLICATE_SYMBOL64
-#else
- typedef struct _IMAGEHLP_DUPLICATE_SYMBOL {
- DWORD SizeOfStruct;
- DWORD NumberOfDups;
- PIMAGEHLP_SYMBOL Symbol;
- DWORD SelectedSymbol;
- } IMAGEHLP_DUPLICATE_SYMBOL,*PIMAGEHLP_DUPLICATE_SYMBOL;
-#endif
-
- BOOL IMAGEAPI SymSetParentWindow(HWND hwnd);
- PCHAR IMAGEAPI SymSetHomeDirectory(PCSTR dir);
- PCHAR IMAGEAPI SymGetHomeDirectory(DWORD type,PSTR dir,size_t size);
-
- enum {
- hdBase = 0,hdSym,hdSrc,hdMax
- };
-
-#define SYMOPT_CASE_INSENSITIVE 0x00000001
-#define SYMOPT_UNDNAME 0x00000002
-#define SYMOPT_DEFERRED_LOADS 0x00000004
-#define SYMOPT_NO_CPP 0x00000008
-#define SYMOPT_LOAD_LINES 0x00000010
-#define SYMOPT_OMAP_FIND_NEAREST 0x00000020
-#define SYMOPT_LOAD_ANYTHING 0x00000040
-#define SYMOPT_IGNORE_CVREC 0x00000080
-#define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100
-#define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200
-#define SYMOPT_EXACT_SYMBOLS 0x00000400
-#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800
-#define SYMOPT_IGNORE_NT_SYMPATH 0x00001000
-#define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000
-#define SYMOPT_PUBLICS_ONLY 0x00004000
-#define SYMOPT_NO_PUBLICS 0x00008000
-#define SYMOPT_AUTO_PUBLICS 0x00010000
-#define SYMOPT_NO_IMAGE_SEARCH 0x00020000
-#define SYMOPT_SECURE 0x00040000
-#define SYMOPT_NO_PROMPTS 0x00080000
-
-#define SYMOPT_DEBUG 0x80000000
-
- DWORD IMAGEAPI SymSetOptions(DWORD SymOptions);
- DWORD IMAGEAPI SymGetOptions(VOID);
- BOOL IMAGEAPI SymCleanup(HANDLE hProcess);
- BOOL IMAGEAPI SymMatchString(LPSTR string,LPSTR expression,BOOL fCase);
-
- typedef BOOL (CALLBACK *PSYM_ENUMSOURCFILES_CALLBACK)(PSOURCEFILE pSourceFile,PVOID UserContext);
-
- BOOL IMAGEAPI SymEnumSourceFiles(HANDLE hProcess,ULONG64 ModBase,LPSTR Mask,PSYM_ENUMSOURCFILES_CALLBACK cbSrcFiles,PVOID UserContext);
- BOOL IMAGEAPI SymEnumerateModules64(HANDLE hProcess,PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,PVOID UserContext);
-
-#ifdef _IMAGEHLP64
-#define SymEnumerateModules SymEnumerateModules64
-#else
- BOOL IMAGEAPI SymEnumerateModules(HANDLE hProcess,PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,PVOID UserContext);
-#endif
-
- BOOL IMAGEAPI SymEnumerateSymbols64(HANDLE hProcess,DWORD64 BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback,PVOID UserContext);
- BOOL IMAGEAPI SymEnumerateSymbolsW64(HANDLE hProcess,DWORD64 BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK64W EnumSymbolsCallback,PVOID UserContext);
-
-#ifdef _IMAGEHLP64
-#define SymEnumerateSymbols SymEnumerateSymbols64
-#define SymEnumerateSymbolsW SymEnumerateSymbolsW64
-#else
- BOOL IMAGEAPI SymEnumerateSymbols(HANDLE hProcess,DWORD BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext);
- BOOL IMAGEAPI SymEnumerateSymbolsW(HANDLE hProcess,DWORD BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACKW EnumSymbolsCallback,PVOID UserContext);
-#endif
-
- BOOL IMAGEAPI EnumerateLoadedModules64(HANDLE hProcess,PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,PVOID UserContext);
-#ifdef _IMAGEHLP64
-#define EnumerateLoadedModules EnumerateLoadedModules64
-#else
- BOOL IMAGEAPI EnumerateLoadedModules(HANDLE hProcess,PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,PVOID UserContext);
-#endif
-
- PVOID IMAGEAPI SymFunctionTableAccess64(HANDLE hProcess,DWORD64 AddrBase);
-
-#ifdef _IMAGEHLP64
-#define SymFunctionTableAccess SymFunctionTableAccess64
-#else
- PVOID IMAGEAPI SymFunctionTableAccess(HANDLE hProcess,DWORD AddrBase);
-#endif
-
- BOOL IMAGEAPI SymGetModuleInfo64(HANDLE hProcess,DWORD64 qwAddr,PIMAGEHLP_MODULE64 ModuleInfo);
- BOOL IMAGEAPI SymGetModuleInfoW64(HANDLE hProcess,DWORD64 qwAddr,PIMAGEHLP_MODULEW64 ModuleInfo);
-
-#ifdef _IMAGEHLP64
-#define SymGetModuleInfo SymGetModuleInfo64
-#define SymGetModuleInfoW SymGetModuleInfoW64
-#else
- BOOL IMAGEAPI SymGetModuleInfo(HANDLE hProcess,DWORD dwAddr,PIMAGEHLP_MODULE ModuleInfo);
- BOOL IMAGEAPI SymGetModuleInfoW(HANDLE hProcess,DWORD dwAddr,PIMAGEHLP_MODULEW ModuleInfo);
-#endif
-
- DWORD64 IMAGEAPI SymGetModuleBase64(HANDLE hProcess,DWORD64 qwAddr);
-
-#ifdef _IMAGEHLP64
-#define SymGetModuleBase SymGetModuleBase64
-#else
- DWORD IMAGEAPI SymGetModuleBase(HANDLE hProcess,DWORD dwAddr);
-#endif
-
- BOOL IMAGEAPI SymGetSymNext64(HANDLE hProcess,PIMAGEHLP_SYMBOL64 Symbol);
-
-#ifdef _IMAGEHLP64
-#define SymGetSymNext SymGetSymNext64
-#else
- BOOL IMAGEAPI SymGetSymNext(HANDLE hProcess,PIMAGEHLP_SYMBOL Symbol);
-#endif
-
- BOOL IMAGEAPI SymGetSymPrev64(HANDLE hProcess,PIMAGEHLP_SYMBOL64 Symbol);
-
-#ifdef _IMAGEHLP64
-#define SymGetSymPrev SymGetSymPrev64
-#else
- BOOL IMAGEAPI SymGetSymPrev(HANDLE hProcess,PIMAGEHLP_SYMBOL Symbol);
-#endif
-
- typedef struct _SRCCODEINFO {
- DWORD SizeOfStruct;
- PVOID Key;
- DWORD64 ModBase;
- CHAR Obj[MAX_PATH + 1];
- CHAR FileName[MAX_PATH + 1];
- DWORD LineNumber;
- DWORD64 Address;
- } SRCCODEINFO,*PSRCCODEINFO;
-
- typedef BOOL (CALLBACK *PSYM_ENUMLINES_CALLBACK)(PSRCCODEINFO LineInfo,PVOID UserContext);
-
- BOOL IMAGEAPI SymEnumLines(HANDLE hProcess,ULONG64 Base,PCSTR Obj,PCSTR File,PSYM_ENUMLINES_CALLBACK EnumLinesCallback,PVOID UserContext);
- BOOL IMAGEAPI SymGetLineFromAddr64(HANDLE hProcess,DWORD64 qwAddr,PDWORD pdwDisplacement,PIMAGEHLP_LINE64 Line64);
-
-#ifdef _IMAGEHLP64
-#define SymGetLineFromAddr SymGetLineFromAddr64
-#else
- BOOL IMAGEAPI SymGetLineFromAddr(HANDLE hProcess,DWORD dwAddr,PDWORD pdwDisplacement,PIMAGEHLP_LINE Line);
-#endif
-
- BOOL IMAGEAPI SymGetLineFromName64(HANDLE hProcess,PSTR ModuleName,PSTR FileName,DWORD dwLineNumber,PLONG plDisplacement,PIMAGEHLP_LINE64 Line);
-
-#ifdef _IMAGEHLP64
-#define SymGetLineFromName SymGetLineFromName64
-#else
- BOOL IMAGEAPI SymGetLineFromName(HANDLE hProcess,PSTR ModuleName,PSTR FileName,DWORD dwLineNumber,PLONG plDisplacement,PIMAGEHLP_LINE Line);
-#endif
-
- BOOL IMAGEAPI SymGetLineNext64(HANDLE hProcess,PIMAGEHLP_LINE64 Line);
-
-#ifdef _IMAGEHLP64
-#define SymGetLineNext SymGetLineNext64
-#else
- BOOL IMAGEAPI SymGetLineNext(HANDLE hProcess,PIMAGEHLP_LINE Line);
-#endif
-
- BOOL IMAGEAPI SymGetLinePrev64(HANDLE hProcess,PIMAGEHLP_LINE64 Line);
-
-#ifdef _IMAGEHLP64
-#define SymGetLinePrev SymGetLinePrev64
-#else
- BOOL IMAGEAPI SymGetLinePrev(HANDLE hProcess,PIMAGEHLP_LINE Line);
-#endif
-
- BOOL IMAGEAPI SymMatchFileName(PSTR FileName,PSTR Match,PSTR *FileNameStop,PSTR *MatchStop);
- BOOL IMAGEAPI SymInitialize(HANDLE hProcess,PSTR UserSearchPath,BOOL fInvadeProcess);
- BOOL IMAGEAPI SymGetSearchPath(HANDLE hProcess,PSTR SearchPath,DWORD SearchPathLength);
- BOOL IMAGEAPI SymSetSearchPath(HANDLE hProcess,PSTR SearchPath);
- DWORD64 IMAGEAPI SymLoadModule64(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD64 BaseOfDll,DWORD SizeOfDll);
-
-#define SLMFLAG_VIRTUAL 0x1
-
- DWORD64 IMAGEAPI SymLoadModuleEx(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD64 BaseOfDll,DWORD DllSize,PMODLOAD_DATA Data,DWORD Flags);
-
-#ifdef _IMAGEHLP64
-#define SymLoadModule SymLoadModule64
-#else
- DWORD IMAGEAPI SymLoadModule(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD BaseOfDll,DWORD SizeOfDll);
-#endif
-
- BOOL IMAGEAPI SymUnloadModule64(HANDLE hProcess,DWORD64 BaseOfDll);
-
-#ifdef _IMAGEHLP64
-#define SymUnloadModule SymUnloadModule64
-#else
- BOOL IMAGEAPI SymUnloadModule(HANDLE hProcess,DWORD BaseOfDll);
-#endif
-
- BOOL IMAGEAPI SymUnDName64(PIMAGEHLP_SYMBOL64 sym,PSTR UnDecName,DWORD UnDecNameLength);
-
-#ifdef _IMAGEHLP64
-#define SymUnDName SymUnDName64
-#else
- BOOL IMAGEAPI SymUnDName(PIMAGEHLP_SYMBOL sym,PSTR UnDecName,DWORD UnDecNameLength);
-#endif
-
- BOOL IMAGEAPI SymRegisterCallback64(HANDLE hProcess,PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,ULONG64 UserContext);
-
- BOOL IMAGEAPI SymRegisterFunctionEntryCallback64(HANDLE hProcess,PSYMBOL_FUNCENTRY_CALLBACK64 CallbackFunction,ULONG64 UserContext);
-
-#ifdef _IMAGEHLP64
-#define SymRegisterCallback SymRegisterCallback64
-#define SymRegisterFunctionEntryCallback SymRegisterFunctionEntryCallback64
-#else
- BOOL IMAGEAPI SymRegisterCallback(HANDLE hProcess,PSYMBOL_REGISTERED_CALLBACK CallbackFunction,PVOID UserContext);
- BOOL IMAGEAPI SymRegisterFunctionEntryCallback(HANDLE hProcess,PSYMBOL_FUNCENTRY_CALLBACK CallbackFunction,PVOID UserContext);
-#endif
-
- typedef struct _IMAGEHLP_SYMBOL_SRC {
- DWORD sizeofstruct;
- DWORD type;
- char file[MAX_PATH];
- } IMAGEHLP_SYMBOL_SRC,*PIMAGEHLP_SYMBOL_SRC;
-
- typedef struct _MODULE_TYPE_INFO {
- USHORT dataLength;
- USHORT leaf;
- BYTE data[1];
- } MODULE_TYPE_INFO,*PMODULE_TYPE_INFO;
-
- typedef struct _SYMBOL_INFO {
- ULONG SizeOfStruct;
- ULONG TypeIndex;
- ULONG64 Reserved[2];
- ULONG info;
- ULONG Size;
- ULONG64 ModBase;
- ULONG Flags;
- ULONG64 Value;
- ULONG64 Address;
- ULONG Register;
- ULONG Scope;
- ULONG Tag;
- ULONG NameLen;
- ULONG MaxNameLen;
- CHAR Name[1];
- } SYMBOL_INFO,*PSYMBOL_INFO;
-
- typedef struct _SYMBOL_INFO_PACKAGE {
- SYMBOL_INFO si;
- CHAR name[MAX_SYM_NAME + 1];
- } SYMBOL_INFO_PACKAGE,*PSYMBOL_INFO_PACKAGE;
-
- typedef struct _IMAGEHLP_STACK_FRAME
- {
- ULONG64 InstructionOffset;
- ULONG64 ReturnOffset;
- ULONG64 FrameOffset;
- ULONG64 StackOffset;
- ULONG64 BackingStoreOffset;
- ULONG64 FuncTableEntry;
- ULONG64 Params[4];
- ULONG64 Reserved[5];
- BOOL Virtual;
- ULONG Reserved2;
- } IMAGEHLP_STACK_FRAME,*PIMAGEHLP_STACK_FRAME;
-
- typedef VOID IMAGEHLP_CONTEXT,*PIMAGEHLP_CONTEXT;
-
- BOOL IMAGEAPI SymSetContext(HANDLE hProcess,PIMAGEHLP_STACK_FRAME StackFrame,PIMAGEHLP_CONTEXT Context);
- BOOL IMAGEAPI SymFromAddr(HANDLE hProcess,DWORD64 Address,PDWORD64 Displacement,PSYMBOL_INFO Symbol);
- BOOL IMAGEAPI SymFromToken(HANDLE hProcess,DWORD64 Base,DWORD Token,PSYMBOL_INFO Symbol);
- BOOL IMAGEAPI SymFromName(HANDLE hProcess,LPSTR Name,PSYMBOL_INFO Symbol);
-
- typedef BOOL (CALLBACK *PSYM_ENUMERATESYMBOLS_CALLBACK)(PSYMBOL_INFO pSymInfo,ULONG SymbolSize,PVOID UserContext);
-
- BOOL IMAGEAPI SymEnumSymbols(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Mask,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext);
- BOOL IMAGEAPI SymEnumSymbolsForAddr(HANDLE hProcess,DWORD64 Address,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext);
-
-#define SYMENUMFLAG_FULLSRCH 1
-#define SYMENUMFLAG_SPEEDSRCH 2
-
- typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO {
- TI_GET_SYMTAG,TI_GET_SYMNAME,TI_GET_LENGTH,TI_GET_TYPE,TI_GET_TYPEID,TI_GET_BASETYPE,TI_GET_ARRAYINDEXTYPEID,TI_FINDCHILDREN,
- TI_GET_DATAKIND,TI_GET_ADDRESSOFFSET,TI_GET_OFFSET,TI_GET_VALUE,TI_GET_COUNT,TI_GET_CHILDRENCOUNT,TI_GET_BITPOSITION,TI_GET_VIRTUALBASECLASS,
- TI_GET_VIRTUALTABLESHAPEID,TI_GET_VIRTUALBASEPOINTEROFFSET,TI_GET_CLASSPARENTID,TI_GET_NESTED,TI_GET_SYMINDEX,TI_GET_LEXICALPARENT,
- TI_GET_ADDRESS,TI_GET_THISADJUST,TI_GET_UDTKIND,TI_IS_EQUIV_TO,TI_GET_CALLING_CONVENTION
- } IMAGEHLP_SYMBOL_TYPE_INFO;
-
- typedef struct _TI_FINDCHILDREN_PARAMS {
- ULONG Count;
- ULONG Start;
- ULONG ChildId[1];
- } TI_FINDCHILDREN_PARAMS;
-
- BOOL IMAGEAPI SymGetTypeInfo(HANDLE hProcess,DWORD64 ModBase,ULONG TypeId,IMAGEHLP_SYMBOL_TYPE_INFO GetType,PVOID pInfo);
- BOOL IMAGEAPI SymEnumTypes(HANDLE hProcess,ULONG64 BaseOfDll,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext);
- BOOL IMAGEAPI SymGetTypeFromName(HANDLE hProcess,ULONG64 BaseOfDll,LPSTR Name,PSYMBOL_INFO Symbol);
- BOOL IMAGEAPI SymAddSymbol(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Name,DWORD64 Address,DWORD Size,DWORD Flags);
- BOOL IMAGEAPI SymDeleteSymbol(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Name,DWORD64 Address,DWORD Flags);
-
- typedef BOOL (WINAPI *PDBGHELP_CREATE_USER_DUMP_CALLBACK)(DWORD DataType,PVOID *Data,LPDWORD DataLength,PVOID UserData);
-
- BOOL WINAPI DbgHelpCreateUserDump(LPSTR FileName,PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,PVOID UserData);
- BOOL WINAPI DbgHelpCreateUserDumpW(LPWSTR FileName,PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,PVOID UserData);
- BOOL IMAGEAPI SymGetSymFromAddr64(HANDLE hProcess,DWORD64 qwAddr,PDWORD64 pdwDisplacement,PIMAGEHLP_SYMBOL64 Symbol);
-
-#ifdef _IMAGEHLP64
-#define SymGetSymFromAddr SymGetSymFromAddr64
-#else
- BOOL IMAGEAPI SymGetSymFromAddr(HANDLE hProcess,DWORD dwAddr,PDWORD pdwDisplacement,PIMAGEHLP_SYMBOL Symbol);
-#endif
-
- BOOL IMAGEAPI SymGetSymFromName64(HANDLE hProcess,PSTR Name,PIMAGEHLP_SYMBOL64 Symbol);
-
-#ifdef _IMAGEHLP64
-#define SymGetSymFromName SymGetSymFromName64
-#else
- BOOL IMAGEAPI SymGetSymFromName(HANDLE hProcess,PSTR Name,PIMAGEHLP_SYMBOL Symbol);
-#endif
-
- DBHLP_DEPRECIATED BOOL IMAGEAPI FindFileInPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,PVOID id,DWORD two,DWORD three,DWORD flags,LPSTR FilePath);
- DBHLP_DEPRECIATED BOOL IMAGEAPI FindFileInSearchPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,DWORD one,DWORD two,DWORD three,LPSTR FilePath);
- DBHLP_DEPRECIATED BOOL IMAGEAPI SymEnumSym(HANDLE hProcess,ULONG64 BaseOfDll,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext);
-
-#define SYMF_OMAP_GENERATED 0x00000001
-#define SYMF_OMAP_MODIFIED 0x00000002
-#define SYMF_REGISTER 0x00000008
-#define SYMF_REGREL 0x00000010
-#define SYMF_FRAMEREL 0x00000020
-#define SYMF_PARAMETER 0x00000040
-#define SYMF_LOCAL 0x00000080
-#define SYMF_CONSTANT 0x00000100
-#define SYMF_EXPORT 0x00000200
-#define SYMF_FORWARDER 0x00000400
-#define SYMF_FUNCTION 0x00000800
-#define SYMF_VIRTUAL 0x00001000
-#define SYMF_THUNK 0x00002000
-#define SYMF_TLSREL 0x00004000
-
-#define IMAGEHLP_SYMBOL_INFO_VALUEPRESENT 1
-#define IMAGEHLP_SYMBOL_INFO_REGISTER SYMF_REGISTER
-#define IMAGEHLP_SYMBOL_INFO_REGRELATIVE SYMF_REGREL
-#define IMAGEHLP_SYMBOL_INFO_FRAMERELATIVE SYMF_FRAMEREL
-#define IMAGEHLP_SYMBOL_INFO_PARAMETER SYMF_PARAMETER
-#define IMAGEHLP_SYMBOL_INFO_LOCAL SYMF_LOCAL
-#define IMAGEHLP_SYMBOL_INFO_CONSTANT SYMF_CONSTANT
-#define IMAGEHLP_SYMBOL_FUNCTION SYMF_FUNCTION
-#define IMAGEHLP_SYMBOL_VIRTUAL SYMF_VIRTUAL
-#define IMAGEHLP_SYMBOL_THUNK SYMF_THUNK
-#define IMAGEHLP_SYMBOL_INFO_TLSRELATIVE SYMF_TLSREL
-
-#include <pshpack4.h>
-
-#define MINIDUMP_SIGNATURE ('PMDM')
-#define MINIDUMP_VERSION (42899)
- typedef DWORD RVA;
- typedef ULONG64 RVA64;
-
- typedef struct _MINIDUMP_LOCATION_DESCRIPTOR {
- ULONG32 DataSize;
- RVA Rva;
- } MINIDUMP_LOCATION_DESCRIPTOR;
-
- typedef struct _MINIDUMP_LOCATION_DESCRIPTOR64 {
- ULONG64 DataSize;
- RVA64 Rva;
- } MINIDUMP_LOCATION_DESCRIPTOR64;
-
- typedef struct _MINIDUMP_MEMORY_DESCRIPTOR {
- ULONG64 StartOfMemoryRange;
- MINIDUMP_LOCATION_DESCRIPTOR Memory;
- } MINIDUMP_MEMORY_DESCRIPTOR,*PMINIDUMP_MEMORY_DESCRIPTOR;
-
- typedef struct _MINIDUMP_MEMORY_DESCRIPTOR64 {
- ULONG64 StartOfMemoryRange;
- ULONG64 DataSize;
- } MINIDUMP_MEMORY_DESCRIPTOR64,*PMINIDUMP_MEMORY_DESCRIPTOR64;
-
- typedef struct _MINIDUMP_HEADER {
- ULONG32 Signature;
- ULONG32 Version;
- ULONG32 NumberOfStreams;
- RVA StreamDirectoryRva;
- ULONG32 CheckSum;
- union {
- ULONG32 Reserved;
- ULONG32 TimeDateStamp;
- } DUMMYUNIONNAME;
- ULONG64 Flags;
- } MINIDUMP_HEADER,*PMINIDUMP_HEADER;
-
- typedef struct _MINIDUMP_DIRECTORY {
- ULONG32 StreamType;
- MINIDUMP_LOCATION_DESCRIPTOR Location;
- } MINIDUMP_DIRECTORY,*PMINIDUMP_DIRECTORY;
-
- typedef struct _MINIDUMP_STRING {
- ULONG32 Length;
- WCHAR Buffer [0];
- } MINIDUMP_STRING,*PMINIDUMP_STRING;
-
- typedef enum _MINIDUMP_STREAM_TYPE {
- UnusedStream = 0,ReservedStream0 = 1,ReservedStream1 = 2,ThreadListStream = 3,ModuleListStream = 4,MemoryListStream = 5,
- ExceptionStream = 6,SystemInfoStream = 7,ThreadExListStream = 8,Memory64ListStream = 9,CommentStreamA = 10,CommentStreamW = 11,
- HandleDataStream = 12,FunctionTableStream = 13,UnloadedModuleListStream = 14,MiscInfoStream = 15,LastReservedStream = 0xffff
- } MINIDUMP_STREAM_TYPE;
-
- typedef union _CPU_INFORMATION {
- struct {
- ULONG32 VendorId [3 ];
- ULONG32 VersionInformation;
- ULONG32 FeatureInformation;
- ULONG32 AMDExtendedCpuFeatures;
- } X86CpuInfo;
- struct {
- ULONG64 ProcessorFeatures [2 ];
- } OtherCpuInfo;
- } CPU_INFORMATION,*PCPU_INFORMATION;
-
- typedef struct _MINIDUMP_SYSTEM_INFO {
- USHORT ProcessorArchitecture;
- USHORT ProcessorLevel;
- USHORT ProcessorRevision;
- union {
- USHORT Reserved0;
- struct {
- UCHAR NumberOfProcessors;
- UCHAR ProductType;
- } DUMMYSTRUCTNAME;
- } DUMMYUNIONNAME;
- ULONG32 MajorVersion;
- ULONG32 MinorVersion;
- ULONG32 BuildNumber;
- ULONG32 PlatformId;
- RVA CSDVersionRva;
- union {
- ULONG32 Reserved1;
- struct {
- USHORT SuiteMask;
- USHORT Reserved2;
- } DUMMYSTRUCTNAME;
- } DUMMYUNIONNAME1;
- CPU_INFORMATION Cpu;
- } MINIDUMP_SYSTEM_INFO,*PMINIDUMP_SYSTEM_INFO;
-
- C_ASSERT (sizeof (((PPROCESS_INFORMATION)0)->dwThreadId)==4);
-
- typedef struct _MINIDUMP_THREAD {
- ULONG32 ThreadId;
- ULONG32 SuspendCount;
- ULONG32 PriorityClass;
- ULONG32 Priority;
- ULONG64 Teb;
- MINIDUMP_MEMORY_DESCRIPTOR Stack;
- MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
- } MINIDUMP_THREAD,*PMINIDUMP_THREAD;
-
- typedef struct _MINIDUMP_THREAD_LIST {
- ULONG32 NumberOfThreads;
- MINIDUMP_THREAD Threads [0];
- } MINIDUMP_THREAD_LIST,*PMINIDUMP_THREAD_LIST;
-
- typedef struct _MINIDUMP_THREAD_EX {
- ULONG32 ThreadId;
- ULONG32 SuspendCount;
- ULONG32 PriorityClass;
- ULONG32 Priority;
- ULONG64 Teb;
- MINIDUMP_MEMORY_DESCRIPTOR Stack;
- MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
- MINIDUMP_MEMORY_DESCRIPTOR BackingStore;
- } MINIDUMP_THREAD_EX,*PMINIDUMP_THREAD_EX;
-
- typedef struct _MINIDUMP_THREAD_EX_LIST {
- ULONG32 NumberOfThreads;
- MINIDUMP_THREAD_EX Threads [0];
- } MINIDUMP_THREAD_EX_LIST,*PMINIDUMP_THREAD_EX_LIST;
-
- typedef struct _MINIDUMP_EXCEPTION {
- ULONG32 ExceptionCode;
- ULONG32 ExceptionFlags;
- ULONG64 ExceptionRecord;
- ULONG64 ExceptionAddress;
- ULONG32 NumberParameters;
- ULONG32 __unusedAlignment;
- ULONG64 ExceptionInformation [EXCEPTION_MAXIMUM_PARAMETERS ];
- } MINIDUMP_EXCEPTION,*PMINIDUMP_EXCEPTION;
-
- typedef struct MINIDUMP_EXCEPTION_STREAM {
- ULONG32 ThreadId;
- ULONG32 __alignment;
- MINIDUMP_EXCEPTION ExceptionRecord;
- MINIDUMP_LOCATION_DESCRIPTOR ThreadContext;
- } MINIDUMP_EXCEPTION_STREAM,*PMINIDUMP_EXCEPTION_STREAM;
-
- typedef struct _MINIDUMP_MODULE {
- ULONG64 BaseOfImage;
- ULONG32 SizeOfImage;
- ULONG32 CheckSum;
- ULONG32 TimeDateStamp;
- RVA ModuleNameRva;
- VS_FIXEDFILEINFO VersionInfo;
- MINIDUMP_LOCATION_DESCRIPTOR CvRecord;
- MINIDUMP_LOCATION_DESCRIPTOR MiscRecord;
- ULONG64 Reserved0;
- ULONG64 Reserved1;
- } MINIDUMP_MODULE,*PMINIDUMP_MODULE;
-
- typedef struct _MINIDUMP_MODULE_LIST {
- ULONG32 NumberOfModules;
- MINIDUMP_MODULE Modules [0 ];
- } MINIDUMP_MODULE_LIST,*PMINIDUMP_MODULE_LIST;
-
- typedef struct _MINIDUMP_MEMORY_LIST {
- ULONG32 NumberOfMemoryRanges;
- MINIDUMP_MEMORY_DESCRIPTOR MemoryRanges [0];
- } MINIDUMP_MEMORY_LIST,*PMINIDUMP_MEMORY_LIST;
-
- typedef struct _MINIDUMP_MEMORY64_LIST {
- ULONG64 NumberOfMemoryRanges;
- RVA64 BaseRva;
- MINIDUMP_MEMORY_DESCRIPTOR64 MemoryRanges [0];
- } MINIDUMP_MEMORY64_LIST,*PMINIDUMP_MEMORY64_LIST;
-
- typedef struct _MINIDUMP_EXCEPTION_INFORMATION {
- DWORD ThreadId;
- PEXCEPTION_POINTERS ExceptionPointers;
- BOOL ClientPointers;
- } MINIDUMP_EXCEPTION_INFORMATION,*PMINIDUMP_EXCEPTION_INFORMATION;
-
- typedef struct _MINIDUMP_EXCEPTION_INFORMATION64 {
- DWORD ThreadId;
- ULONG64 ExceptionRecord;
- ULONG64 ContextRecord;
- BOOL ClientPointers;
- } MINIDUMP_EXCEPTION_INFORMATION64,*PMINIDUMP_EXCEPTION_INFORMATION64;
-
- typedef struct _MINIDUMP_HANDLE_DESCRIPTOR {
- ULONG64 Handle;
- RVA TypeNameRva;
- RVA ObjectNameRva;
- ULONG32 Attributes;
- ULONG32 GrantedAccess;
- ULONG32 HandleCount;
- ULONG32 PointerCount;
- } MINIDUMP_HANDLE_DESCRIPTOR,*PMINIDUMP_HANDLE_DESCRIPTOR;
-
- typedef struct _MINIDUMP_HANDLE_DATA_STREAM {
- ULONG32 SizeOfHeader;
- ULONG32 SizeOfDescriptor;
- ULONG32 NumberOfDescriptors;
- ULONG32 Reserved;
- } MINIDUMP_HANDLE_DATA_STREAM,*PMINIDUMP_HANDLE_DATA_STREAM;
-
- typedef struct _MINIDUMP_FUNCTION_TABLE_DESCRIPTOR {
- ULONG64 MinimumAddress;
- ULONG64 MaximumAddress;
- ULONG64 BaseAddress;
- ULONG32 EntryCount;
- ULONG32 SizeOfAlignPad;
- } MINIDUMP_FUNCTION_TABLE_DESCRIPTOR,*PMINIDUMP_FUNCTION_TABLE_DESCRIPTOR;
-
- typedef struct _MINIDUMP_FUNCTION_TABLE_STREAM {
- ULONG32 SizeOfHeader;
- ULONG32 SizeOfDescriptor;
- ULONG32 SizeOfNativeDescriptor;
- ULONG32 SizeOfFunctionEntry;
- ULONG32 NumberOfDescriptors;
- ULONG32 SizeOfAlignPad;
- } MINIDUMP_FUNCTION_TABLE_STREAM,*PMINIDUMP_FUNCTION_TABLE_STREAM;
-
- typedef struct _MINIDUMP_UNLOADED_MODULE {
- ULONG64 BaseOfImage;
- ULONG32 SizeOfImage;
- ULONG32 CheckSum;
- ULONG32 TimeDateStamp;
- RVA ModuleNameRva;
- } MINIDUMP_UNLOADED_MODULE,*PMINIDUMP_UNLOADED_MODULE;
-
- typedef struct _MINIDUMP_UNLOADED_MODULE_LIST {
- ULONG32 SizeOfHeader;
- ULONG32 SizeOfEntry;
- ULONG32 NumberOfEntries;
- } MINIDUMP_UNLOADED_MODULE_LIST,*PMINIDUMP_UNLOADED_MODULE_LIST;
-
-#define MINIDUMP_MISC1_PROCESS_ID 0x00000001
-#define MINIDUMP_MISC1_PROCESS_TIMES 0x00000002
-
- typedef struct _MINIDUMP_MISC_INFO {
- ULONG32 SizeOfInfo;
- ULONG32 Flags1;
- ULONG32 ProcessId;
- ULONG32 ProcessCreateTime;
- ULONG32 ProcessUserTime;
- ULONG32 ProcessKernelTime;
- } MINIDUMP_MISC_INFO,*PMINIDUMP_MISC_INFO;
-
- typedef struct _MINIDUMP_USER_RECORD {
- ULONG32 Type;
- MINIDUMP_LOCATION_DESCRIPTOR Memory;
- } MINIDUMP_USER_RECORD,*PMINIDUMP_USER_RECORD;
-
- typedef struct _MINIDUMP_USER_STREAM {
- ULONG32 Type;
- ULONG BufferSize;
- PVOID Buffer;
- } MINIDUMP_USER_STREAM,*PMINIDUMP_USER_STREAM;
-
- typedef struct _MINIDUMP_USER_STREAM_INFORMATION {
- ULONG UserStreamCount;
- PMINIDUMP_USER_STREAM UserStreamArray;
- } MINIDUMP_USER_STREAM_INFORMATION,*PMINIDUMP_USER_STREAM_INFORMATION;
-
- typedef enum _MINIDUMP_CALLBACK_TYPE {
- ModuleCallback,ThreadCallback,ThreadExCallback,IncludeThreadCallback,IncludeModuleCallback,MemoryCallback
- } MINIDUMP_CALLBACK_TYPE;
-
- typedef struct _MINIDUMP_THREAD_CALLBACK {
- ULONG ThreadId;
- HANDLE ThreadHandle;
- CONTEXT Context;
- ULONG SizeOfContext;
- ULONG64 StackBase;
- ULONG64 StackEnd;
- } MINIDUMP_THREAD_CALLBACK,*PMINIDUMP_THREAD_CALLBACK;
-
- typedef struct _MINIDUMP_THREAD_EX_CALLBACK {
- ULONG ThreadId;
- HANDLE ThreadHandle;
- CONTEXT Context;
- ULONG SizeOfContext;
- ULONG64 StackBase;
- ULONG64 StackEnd;
- ULONG64 BackingStoreBase;
- ULONG64 BackingStoreEnd;
- } MINIDUMP_THREAD_EX_CALLBACK,*PMINIDUMP_THREAD_EX_CALLBACK;
-
- typedef struct _MINIDUMP_INCLUDE_THREAD_CALLBACK {
- ULONG ThreadId;
- } MINIDUMP_INCLUDE_THREAD_CALLBACK,*PMINIDUMP_INCLUDE_THREAD_CALLBACK;
-
- typedef enum _THREAD_WRITE_FLAGS {
- ThreadWriteThread = 0x0001,ThreadWriteStack = 0x0002,ThreadWriteContext = 0x0004,ThreadWriteBackingStore = 0x0008,
- ThreadWriteInstructionWindow = 0x0010,ThreadWriteThreadData = 0x0020
- } THREAD_WRITE_FLAGS;
-
- typedef struct _MINIDUMP_MODULE_CALLBACK {
- PWCHAR FullPath;
- ULONG64 BaseOfImage;
- ULONG SizeOfImage;
- ULONG CheckSum;
- ULONG TimeDateStamp;
- VS_FIXEDFILEINFO VersionInfo;
- PVOID CvRecord;
- ULONG SizeOfCvRecord;
- PVOID MiscRecord;
- ULONG SizeOfMiscRecord;
- } MINIDUMP_MODULE_CALLBACK,*PMINIDUMP_MODULE_CALLBACK;
-
- typedef struct _MINIDUMP_INCLUDE_MODULE_CALLBACK {
- ULONG64 BaseOfImage;
- } MINIDUMP_INCLUDE_MODULE_CALLBACK,*PMINIDUMP_INCLUDE_MODULE_CALLBACK;
-
- typedef enum _MODULE_WRITE_FLAGS {
- ModuleWriteModule = 0x0001,ModuleWriteDataSeg = 0x0002,ModuleWriteMiscRecord = 0x0004,ModuleWriteCvRecord = 0x0008,
- ModuleReferencedByMemory = 0x0010
- } MODULE_WRITE_FLAGS;
-
- typedef struct _MINIDUMP_CALLBACK_INPUT {
- ULONG ProcessId;
- HANDLE ProcessHandle;
- ULONG CallbackType;
- union {
- MINIDUMP_THREAD_CALLBACK Thread;
- MINIDUMP_THREAD_EX_CALLBACK ThreadEx;
- MINIDUMP_MODULE_CALLBACK Module;
- MINIDUMP_INCLUDE_THREAD_CALLBACK IncludeThread;
- MINIDUMP_INCLUDE_MODULE_CALLBACK IncludeModule;
- } DUMMYUNIONNAME;
- } MINIDUMP_CALLBACK_INPUT,*PMINIDUMP_CALLBACK_INPUT;
-
- typedef struct _MINIDUMP_CALLBACK_OUTPUT {
- union {
- ULONG ModuleWriteFlags;
- ULONG ThreadWriteFlags;
- struct {
- ULONG64 MemoryBase;
- ULONG MemorySize;
- } DUMMYSTRUCTNAME;
- } DUMMYUNIONNAME;
- } MINIDUMP_CALLBACK_OUTPUT,*PMINIDUMP_CALLBACK_OUTPUT;
-
- typedef enum _MINIDUMP_TYPE {
- MiniDumpNormal = 0x0000,MiniDumpWithDataSegs = 0x0001,MiniDumpWithFullMemory = 0x0002,MiniDumpWithHandleData = 0x0004,
- MiniDumpFilterMemory = 0x0008,MiniDumpScanMemory = 0x0010,MiniDumpWithUnloadedModules = 0x0020,MiniDumpWithIndirectlyReferencedMemory = 0x0040,
- MiniDumpFilterModulePaths = 0x0080,MiniDumpWithProcessThreadData = 0x0100,MiniDumpWithPrivateReadWriteMemory = 0x0200,
- MiniDumpWithoutOptionalData = 0x0400
- } MINIDUMP_TYPE;
-
- typedef BOOL (WINAPI *MINIDUMP_CALLBACK_ROUTINE)(PVOID CallbackParam,CONST PMINIDUMP_CALLBACK_INPUT CallbackInput,PMINIDUMP_CALLBACK_OUTPUT CallbackOutput);
-
- typedef struct _MINIDUMP_CALLBACK_INFORMATION {
- MINIDUMP_CALLBACK_ROUTINE CallbackRoutine;
- PVOID CallbackParam;
- } MINIDUMP_CALLBACK_INFORMATION,*PMINIDUMP_CALLBACK_INFORMATION;
-
-#define RVA_TO_ADDR(Mapping,Rva) ((PVOID)(((ULONG_PTR) (Mapping)) + (Rva)))
-
- BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,MINIDUMP_TYPE DumpType,CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
- BOOL WINAPI MiniDumpReadDumpStream(PVOID BaseOfDump,ULONG StreamNumber,PMINIDUMP_DIRECTORY *Dir,PVOID *StreamPointer,ULONG *StreamSize);
-
-#include <poppack.h>
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the w64 mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ +#ifndef _DBGHELP_ +#define _DBGHELP_ + +#ifdef _WIN64 +#ifndef _IMAGEHLP64 +#define _IMAGEHLP64 +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define IMAGEAPI DECLSPEC_IMPORT WINAPI +#define DBHLP_DEPRECIATED __declspec(deprecated) + +#define DBHLPAPI IMAGEAPI + +#define IMAGE_SEPARATION (64*1024) + + typedef struct _LOADED_IMAGE { + PSTR ModuleName; + HANDLE hFile; + PUCHAR MappedAddress; +#ifdef _IMAGEHLP64 + PIMAGE_NT_HEADERS64 FileHeader; +#else + PIMAGE_NT_HEADERS32 FileHeader; +#endif + PIMAGE_SECTION_HEADER LastRvaSection; + ULONG NumberOfSections; + PIMAGE_SECTION_HEADER Sections; + ULONG Characteristics; + BOOLEAN fSystemImage; + BOOLEAN fDOSImage; + LIST_ENTRY Links; + ULONG SizeOfImage; + } LOADED_IMAGE,*PLOADED_IMAGE; + +#define MAX_SYM_NAME 2000 + + typedef BOOL (CALLBACK *PFIND_DEBUG_FILE_CALLBACK)(HANDLE FileHandle,PSTR FileName,PVOID CallerData); + typedef BOOL (CALLBACK *PFINDFILEINPATHCALLBACK)(PSTR filename,PVOID context); + typedef BOOL (CALLBACK *PFIND_EXE_FILE_CALLBACK)(HANDLE FileHandle,PSTR FileName,PVOID CallerData); + + typedef BOOL (WINAPI *PSYMBOLSERVERPROC)(LPCSTR,LPCSTR,PVOID,DWORD,DWORD,LPSTR); + typedef BOOL (WINAPI *PSYMBOLSERVEROPENPROC)(VOID); + typedef BOOL (WINAPI *PSYMBOLSERVERCLOSEPROC)(VOID); + typedef BOOL (WINAPI *PSYMBOLSERVERSETOPTIONSPROC)(UINT_PTR,ULONG64); + typedef BOOL (CALLBACK WINAPI *PSYMBOLSERVERCALLBACKPROC)(UINT_PTR action,ULONG64 data,ULONG64 context); + typedef UINT_PTR (WINAPI *PSYMBOLSERVERGETOPTIONSPROC)(); + typedef BOOL (WINAPI *PSYMBOLSERVERPINGPROC)(LPCSTR); + + HANDLE IMAGEAPI FindDebugInfoFile(PSTR FileName,PSTR SymbolPath,PSTR DebugFilePath); + HANDLE IMAGEAPI FindDebugInfoFileEx(PSTR FileName,PSTR SymbolPath,PSTR DebugFilePath,PFIND_DEBUG_FILE_CALLBACK Callback,PVOID CallerData); + BOOL IMAGEAPI SymFindFileInPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,PVOID id,DWORD two,DWORD three,DWORD flags,LPSTR FoundFile,PFINDFILEINPATHCALLBACK callback,PVOID context); + HANDLE IMAGEAPI FindExecutableImage(PSTR FileName,PSTR SymbolPath,PSTR ImageFilePath); + HANDLE IMAGEAPI FindExecutableImageEx(PSTR FileName,PSTR SymbolPath,PSTR ImageFilePath,PFIND_EXE_FILE_CALLBACK Callback,PVOID CallerData); + PIMAGE_NT_HEADERS IMAGEAPI ImageNtHeader(PVOID Base); + PVOID IMAGEAPI ImageDirectoryEntryToDataEx(PVOID Base,BOOLEAN MappedAsImage,USHORT DirectoryEntry,PULONG Size,PIMAGE_SECTION_HEADER *FoundHeader); + PVOID IMAGEAPI ImageDirectoryEntryToData(PVOID Base,BOOLEAN MappedAsImage,USHORT DirectoryEntry,PULONG Size); + PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection(PIMAGE_NT_HEADERS NtHeaders,PVOID Base,ULONG Rva); + PVOID IMAGEAPI ImageRvaToVa(PIMAGE_NT_HEADERS NtHeaders,PVOID Base,ULONG Rva,PIMAGE_SECTION_HEADER *LastRvaSection); + +#define SSRVOPT_CALLBACK 0x0001 +#define SSRVOPT_DWORD 0x0002 +#define SSRVOPT_DWORDPTR 0x0004 +#define SSRVOPT_GUIDPTR 0x0008 +#define SSRVOPT_OLDGUIDPTR 0x0010 +#define SSRVOPT_UNATTENDED 0x0020 +#define SSRVOPT_NOCOPY 0x0040 +#define SSRVOPT_PARENTWIN 0x0080 +#define SSRVOPT_PARAMTYPE 0x0100 +#define SSRVOPT_SECURE 0x0200 +#define SSRVOPT_TRACE 0x0400 +#define SSRVOPT_SETCONTEXT 0x0800 +#define SSRVOPT_PROXY 0x1000 +#define SSRVOPT_DOWNSTREAM_STORE 0x2000 +#define SSRVOPT_RESET ((ULONG_PTR)-1) + +#define SSRVACTION_TRACE 1 +#define SSRVACTION_QUERYCANCEL 2 +#define SSRVACTION_EVENT 3 + +#ifndef _WIN64 + + typedef struct _IMAGE_DEBUG_INFORMATION { + LIST_ENTRY List; + DWORD ReservedSize; + PVOID ReservedMappedBase; + USHORT ReservedMachine; + USHORT ReservedCharacteristics; + DWORD ReservedCheckSum; + DWORD ImageBase; + DWORD SizeOfImage; + DWORD ReservedNumberOfSections; + PIMAGE_SECTION_HEADER ReservedSections; + DWORD ReservedExportedNamesSize; + PSTR ReservedExportedNames; + DWORD ReservedNumberOfFunctionTableEntries; + PIMAGE_FUNCTION_ENTRY ReservedFunctionTableEntries; + DWORD ReservedLowestFunctionStartingAddress; + DWORD ReservedHighestFunctionEndingAddress; + DWORD ReservedNumberOfFpoTableEntries; + PFPO_DATA ReservedFpoTableEntries; + DWORD SizeOfCoffSymbols; + PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols; + DWORD ReservedSizeOfCodeViewSymbols; + PVOID ReservedCodeViewSymbols; + PSTR ImageFilePath; + PSTR ImageFileName; + PSTR ReservedDebugFilePath; + DWORD ReservedTimeDateStamp; + BOOL ReservedRomImage; + PIMAGE_DEBUG_DIRECTORY ReservedDebugDirectory; + DWORD ReservedNumberOfDebugDirectories; + DWORD ReservedOriginalFunctionTableBaseAddress; + DWORD Reserved[2 ]; + } IMAGE_DEBUG_INFORMATION,*PIMAGE_DEBUG_INFORMATION; + + PIMAGE_DEBUG_INFORMATION IMAGEAPI MapDebugInformation(HANDLE FileHandle,PSTR FileName,PSTR SymbolPath,DWORD ImageBase); + BOOL IMAGEAPI UnmapDebugInformation(PIMAGE_DEBUG_INFORMATION DebugInfo); +#endif + + typedef BOOL (CALLBACK *PENUMDIRTREE_CALLBACK)(LPCSTR FilePath,PVOID CallerData); + + BOOL IMAGEAPI SearchTreeForFile(PSTR RootPath,PSTR InputPathName,PSTR OutputPathBuffer); + BOOL IMAGEAPI EnumDirTree(HANDLE hProcess,PSTR RootPath,PSTR InputPathName,PSTR OutputPathBuffer,PENUMDIRTREE_CALLBACK Callback,PVOID CallbackData); + BOOL IMAGEAPI MakeSureDirectoryPathExists(PCSTR DirPath); + +#define UNDNAME_COMPLETE (0x0000) +#define UNDNAME_NO_LEADING_UNDERSCORES (0x0001) +#define UNDNAME_NO_MS_KEYWORDS (0x0002) +#define UNDNAME_NO_FUNCTION_RETURNS (0x0004) +#define UNDNAME_NO_ALLOCATION_MODEL (0x0008) +#define UNDNAME_NO_ALLOCATION_LANGUAGE (0x0010) +#define UNDNAME_NO_MS_THISTYPE (0x0020) +#define UNDNAME_NO_CV_THISTYPE (0x0040) +#define UNDNAME_NO_THISTYPE (0x0060) +#define UNDNAME_NO_ACCESS_SPECIFIERS (0x0080) +#define UNDNAME_NO_THROW_SIGNATURES (0x0100) +#define UNDNAME_NO_MEMBER_TYPE (0x0200) +#define UNDNAME_NO_RETURN_UDT_MODEL (0x0400) +#define UNDNAME_32_BIT_DECODE (0x0800) +#define UNDNAME_NAME_ONLY (0x1000) +#define UNDNAME_NO_ARGUMENTS (0x2000) +#define UNDNAME_NO_SPECIAL_SYMS (0x4000) + + DWORD IMAGEAPI WINAPI UnDecorateSymbolName(PCSTR DecoratedName,PSTR UnDecoratedName,DWORD UndecoratedLength,DWORD Flags); + +#define DBHHEADER_DEBUGDIRS 0x1 + + typedef struct _MODLOAD_DATA { + DWORD ssize; + DWORD ssig; + PVOID data; + DWORD size; + DWORD flags; + } MODLOAD_DATA,*PMODLOAD_DATA; + + typedef enum { + AddrMode1616,AddrMode1632,AddrModeReal,AddrModeFlat + } ADDRESS_MODE; + + typedef struct _tagADDRESS64 { + DWORD64 Offset; + WORD Segment; + ADDRESS_MODE Mode; + } ADDRESS64,*LPADDRESS64; + +#ifdef _IMAGEHLP64 +#define ADDRESS ADDRESS64 +#define LPADDRESS LPADDRESS64 +#else + typedef struct _tagADDRESS { + DWORD Offset; + WORD Segment; + ADDRESS_MODE Mode; + } ADDRESS,*LPADDRESS; + + static __inline void Address32To64(LPADDRESS a32,LPADDRESS64 a64) { + a64->Offset = (ULONG64)(LONG64)(LONG)a32->Offset; + a64->Segment = a32->Segment; + a64->Mode = a32->Mode; + } + + static __inline void Address64To32(LPADDRESS64 a64,LPADDRESS a32) { + a32->Offset = (ULONG)a64->Offset; + a32->Segment = a64->Segment; + a32->Mode = a64->Mode; + } +#endif + + typedef struct _KDHELP64 { + DWORD64 Thread; + DWORD ThCallbackStack; + DWORD ThCallbackBStore; + DWORD NextCallback; + DWORD FramePointer; + DWORD64 KiCallUserMode; + DWORD64 KeUserCallbackDispatcher; + DWORD64 SystemRangeStart; + DWORD64 Reserved[8]; + } KDHELP64,*PKDHELP64; + +#ifdef _IMAGEHLP64 +#define KDHELP KDHELP64 +#define PKDHELP PKDHELP64 +#else + typedef struct _KDHELP { + DWORD Thread; + DWORD ThCallbackStack; + DWORD NextCallback; + DWORD FramePointer; + DWORD KiCallUserMode; + DWORD KeUserCallbackDispatcher; + DWORD SystemRangeStart; + DWORD ThCallbackBStore; + DWORD Reserved[8]; + } KDHELP,*PKDHELP; + + static __inline void KdHelp32To64(PKDHELP p32,PKDHELP64 p64) { + p64->Thread = p32->Thread; + p64->ThCallbackStack = p32->ThCallbackStack; + p64->NextCallback = p32->NextCallback; + p64->FramePointer = p32->FramePointer; + p64->KiCallUserMode = p32->KiCallUserMode; + p64->KeUserCallbackDispatcher = p32->KeUserCallbackDispatcher; + p64->SystemRangeStart = p32->SystemRangeStart; + } +#endif + + typedef struct _tagSTACKFRAME64 { + ADDRESS64 AddrPC; + ADDRESS64 AddrReturn; + ADDRESS64 AddrFrame; + ADDRESS64 AddrStack; + ADDRESS64 AddrBStore; + PVOID FuncTableEntry; + DWORD64 Params[4]; + BOOL Far; + BOOL Virtual; + DWORD64 Reserved[3]; + KDHELP64 KdHelp; + } STACKFRAME64,*LPSTACKFRAME64; + +#ifdef _IMAGEHLP64 +#define STACKFRAME STACKFRAME64 +#define LPSTACKFRAME LPSTACKFRAME64 +#else + typedef struct _tagSTACKFRAME { + ADDRESS AddrPC; + ADDRESS AddrReturn; + ADDRESS AddrFrame; + ADDRESS AddrStack; + PVOID FuncTableEntry; + DWORD Params[4]; + BOOL Far; + BOOL Virtual; + DWORD Reserved[3]; + KDHELP KdHelp; + ADDRESS AddrBStore; + } STACKFRAME,*LPSTACKFRAME; +#endif + + typedef BOOL (WINAPI *PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess,DWORD64 qwBaseAddress,PVOID lpBuffer,DWORD nSize,LPDWORD lpNumberOfBytesRead); + typedef PVOID (WINAPI *PFUNCTION_TABLE_ACCESS_ROUTINE64)(HANDLE hProcess,DWORD64 AddrBase); + typedef DWORD64 (WINAPI *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess,DWORD64 Address); + typedef DWORD64 (WINAPI *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess,HANDLE hThread,LPADDRESS64 lpaddr); + + BOOL IMAGEAPI StackWalk64(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME64 StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); + +#ifdef _IMAGEHLP64 +#define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64 +#define PFUNCTION_TABLE_ACCESS_ROUTINE PFUNCTION_TABLE_ACCESS_ROUTINE64 +#define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64 +#define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64 +#define StackWalk StackWalk64 +#else + typedef BOOL (WINAPI *PREAD_PROCESS_MEMORY_ROUTINE)(HANDLE hProcess,DWORD lpBaseAddress,PVOID lpBuffer,DWORD nSize,PDWORD lpNumberOfBytesRead); + typedef PVOID (WINAPI *PFUNCTION_TABLE_ACCESS_ROUTINE)(HANDLE hProcess,DWORD AddrBase); + typedef DWORD (WINAPI *PGET_MODULE_BASE_ROUTINE)(HANDLE hProcess,DWORD Address); + typedef DWORD (WINAPI *PTRANSLATE_ADDRESS_ROUTINE)(HANDLE hProcess,HANDLE hThread,LPADDRESS lpaddr); + + BOOL IMAGEAPI StackWalk(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE TranslateAddress); +#endif + +#define API_VERSION_NUMBER 9 + + typedef struct API_VERSION { + USHORT MajorVersion; + USHORT MinorVersion; + USHORT Revision; + USHORT Reserved; + } API_VERSION,*LPAPI_VERSION; + + LPAPI_VERSION IMAGEAPI ImagehlpApiVersion(VOID); + LPAPI_VERSION IMAGEAPI ImagehlpApiVersionEx(LPAPI_VERSION AppVersion); + DWORD IMAGEAPI GetTimestampForLoadedLibrary(HMODULE Module); + + typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK64)(PSTR ModuleName,DWORD64 BaseOfDll,PVOID UserContext); + typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64)(PSTR SymbolName,DWORD64 SymbolAddress,ULONG SymbolSize,PVOID UserContext); + typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64W)(PWSTR SymbolName,DWORD64 SymbolAddress,ULONG SymbolSize,PVOID UserContext); + typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACK64)(PSTR ModuleName,DWORD64 ModuleBase,ULONG ModuleSize,PVOID UserContext); + typedef BOOL (CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(HANDLE hProcess,ULONG ActionCode,ULONG64 CallbackData,ULONG64 UserContext); + typedef PVOID (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK)(HANDLE hProcess,DWORD AddrBase,PVOID UserContext); + typedef PVOID (CALLBACK *PSYMBOL_FUNCENTRY_CALLBACK64)(HANDLE hProcess,ULONG64 AddrBase,ULONG64 UserContext); + +#ifdef _IMAGEHLP64 +#define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64 +#define PSYM_ENUMSYMBOLS_CALLBACK PSYM_ENUMSYMBOLS_CALLBACK64 +#define PSYM_ENUMSYMBOLS_CALLBACKW PSYM_ENUMSYMBOLS_CALLBACK64W +#define PENUMLOADED_MODULES_CALLBACK PENUMLOADED_MODULES_CALLBACK64 +#define PSYMBOL_REGISTERED_CALLBACK PSYMBOL_REGISTERED_CALLBACK64 +#define PSYMBOL_FUNCENTRY_CALLBACK PSYMBOL_FUNCENTRY_CALLBACK64 +#else + typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)(PSTR ModuleName,ULONG BaseOfDll,PVOID UserContext); + typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK)(PSTR SymbolName,ULONG SymbolAddress,ULONG SymbolSize,PVOID UserContext); + typedef BOOL (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACKW)(PWSTR SymbolName,ULONG SymbolAddress,ULONG SymbolSize,PVOID UserContext); + typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACK)(PSTR ModuleName,ULONG ModuleBase,ULONG ModuleSize,PVOID UserContext); + typedef BOOL (CALLBACK *PSYMBOL_REGISTERED_CALLBACK)(HANDLE hProcess,ULONG ActionCode,PVOID CallbackData,PVOID UserContext); +#endif + +#define SYMFLAG_VALUEPRESENT 0x00000001 +#define SYMFLAG_REGISTER 0x00000008 +#define SYMFLAG_REGREL 0x00000010 +#define SYMFLAG_FRAMEREL 0x00000020 +#define SYMFLAG_PARAMETER 0x00000040 +#define SYMFLAG_LOCAL 0x00000080 +#define SYMFLAG_CONSTANT 0x00000100 +#define SYMFLAG_EXPORT 0x00000200 +#define SYMFLAG_FORWARDER 0x00000400 +#define SYMFLAG_FUNCTION 0x00000800 +#define SYMFLAG_VIRTUAL 0x00001000 +#define SYMFLAG_THUNK 0x00002000 +#define SYMFLAG_TLSREL 0x00004000 + + typedef enum { + SymNone = 0,SymCoff,SymCv,SymPdb,SymExport,SymDeferred,SymSym,SymDia,SymVirtual,NumSymTypes + } SYM_TYPE; + + typedef struct _IMAGEHLP_SYMBOL64 { + DWORD SizeOfStruct; + DWORD64 Address; + DWORD Size; + DWORD Flags; + DWORD MaxNameLength; + CHAR Name[1]; + } IMAGEHLP_SYMBOL64,*PIMAGEHLP_SYMBOL64; + + typedef struct _IMAGEHLP_SYMBOL64_PACKAGE { + IMAGEHLP_SYMBOL64 sym; + CHAR name[MAX_SYM_NAME + 1]; + } IMAGEHLP_SYMBOL64_PACKAGE,*PIMAGEHLP_SYMBOL64_PACKAGE; + +#ifdef _IMAGEHLP64 + +#define IMAGEHLP_SYMBOL IMAGEHLP_SYMBOL64 +#define PIMAGEHLP_SYMBOL PIMAGEHLP_SYMBOL64 +#define IMAGEHLP_SYMBOL_PACKAGE IMAGEHLP_SYMBOL64_PACKAGE +#define PIMAGEHLP_SYMBOL_PACKAGE PIMAGEHLP_SYMBOL64_PACKAGE +#else + + typedef struct _IMAGEHLP_SYMBOL { + DWORD SizeOfStruct; + DWORD Address; + DWORD Size; + DWORD Flags; + DWORD MaxNameLength; + CHAR Name[1]; + } IMAGEHLP_SYMBOL,*PIMAGEHLP_SYMBOL; + + typedef struct _IMAGEHLP_SYMBOL_PACKAGE { + IMAGEHLP_SYMBOL sym; + CHAR name[MAX_SYM_NAME + 1]; + } IMAGEHLP_SYMBOL_PACKAGE,*PIMAGEHLP_SYMBOL_PACKAGE; +#endif + + typedef struct _IMAGEHLP_MODULE64 { + DWORD SizeOfStruct; + DWORD64 BaseOfImage; + DWORD ImageSize; + DWORD TimeDateStamp; + DWORD CheckSum; + DWORD NumSyms; + SYM_TYPE SymType; + CHAR ModuleName[32]; + CHAR ImageName[256]; + CHAR LoadedImageName[256]; + CHAR LoadedPdbName[256]; + DWORD CVSig; + CHAR CVData[MAX_PATH*3]; + DWORD PdbSig; + GUID PdbSig70; + DWORD PdbAge; + BOOL PdbUnmatched; + BOOL DbgUnmatched; + BOOL LineNumbers; + BOOL GlobalSymbols; + BOOL TypeInfo; + } IMAGEHLP_MODULE64,*PIMAGEHLP_MODULE64; + + typedef struct _IMAGEHLP_MODULE64W { + DWORD SizeOfStruct; + DWORD64 BaseOfImage; + DWORD ImageSize; + DWORD TimeDateStamp; + DWORD CheckSum; + DWORD NumSyms; + SYM_TYPE SymType; + WCHAR ModuleName[32]; + WCHAR ImageName[256]; + WCHAR LoadedImageName[256]; + WCHAR LoadedPdbName[256]; + DWORD CVSig; + WCHAR CVData[MAX_PATH*3]; + DWORD PdbSig; + GUID PdbSig70; + DWORD PdbAge; + BOOL PdbUnmatched; + BOOL DbgUnmatched; + BOOL LineNumbers; + BOOL GlobalSymbols; + BOOL TypeInfo; + } IMAGEHLP_MODULEW64,*PIMAGEHLP_MODULEW64; + +#ifdef _IMAGEHLP64 +#define IMAGEHLP_MODULE IMAGEHLP_MODULE64 +#define PIMAGEHLP_MODULE PIMAGEHLP_MODULE64 +#define IMAGEHLP_MODULEW IMAGEHLP_MODULEW64 +#define PIMAGEHLP_MODULEW PIMAGEHLP_MODULEW64 +#else + typedef struct _IMAGEHLP_MODULE { + DWORD SizeOfStruct; + DWORD BaseOfImage; + DWORD ImageSize; + DWORD TimeDateStamp; + DWORD CheckSum; + DWORD NumSyms; + SYM_TYPE SymType; + CHAR ModuleName[32]; + CHAR ImageName[256]; + CHAR LoadedImageName[256]; + } IMAGEHLP_MODULE,*PIMAGEHLP_MODULE; + + typedef struct _IMAGEHLP_MODULEW { + DWORD SizeOfStruct; + DWORD BaseOfImage; + DWORD ImageSize; + DWORD TimeDateStamp; + DWORD CheckSum; + DWORD NumSyms; + SYM_TYPE SymType; + WCHAR ModuleName[32]; + WCHAR ImageName[256]; + WCHAR LoadedImageName[256]; + } IMAGEHLP_MODULEW,*PIMAGEHLP_MODULEW; +#endif + + typedef struct _IMAGEHLP_LINE64 { + DWORD SizeOfStruct; + PVOID Key; + DWORD LineNumber; + PCHAR FileName; + DWORD64 Address; + } IMAGEHLP_LINE64,*PIMAGEHLP_LINE64; + +#ifdef _IMAGEHLP64 +#define IMAGEHLP_LINE IMAGEHLP_LINE64 +#define PIMAGEHLP_LINE PIMAGEHLP_LINE64 +#else + typedef struct _IMAGEHLP_LINE { + DWORD SizeOfStruct; + PVOID Key; + DWORD LineNumber; + PCHAR FileName; + DWORD Address; + } IMAGEHLP_LINE,*PIMAGEHLP_LINE; +#endif + + typedef struct _SOURCEFILE { + DWORD64 ModBase; + PCHAR FileName; + } SOURCEFILE,*PSOURCEFILE; + +#define CBA_DEFERRED_SYMBOL_LOAD_START 0x00000001 +#define CBA_DEFERRED_SYMBOL_LOAD_COMPLETE 0x00000002 +#define CBA_DEFERRED_SYMBOL_LOAD_FAILURE 0x00000003 +#define CBA_SYMBOLS_UNLOADED 0x00000004 +#define CBA_DUPLICATE_SYMBOL 0x00000005 +#define CBA_READ_MEMORY 0x00000006 +#define CBA_DEFERRED_SYMBOL_LOAD_CANCEL 0x00000007 +#define CBA_SET_OPTIONS 0x00000008 +#define CBA_EVENT 0x00000010 +#define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL 0x00000020 +#define CBA_DEBUG_INFO 0x10000000 + + typedef struct _IMAGEHLP_CBA_READ_MEMORY { + DWORD64 addr; + PVOID buf; + DWORD bytes; + DWORD *bytesread; + } IMAGEHLP_CBA_READ_MEMORY,*PIMAGEHLP_CBA_READ_MEMORY; + + enum { + sevInfo = 0,sevProblem,sevAttn,sevFatal,sevMax + }; + + typedef struct _IMAGEHLP_CBA_EVENT { + DWORD severity; + DWORD code; + PCHAR desc; + PVOID object; + } IMAGEHLP_CBA_EVENT,*PIMAGEHLP_CBA_EVENT; + + typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD64 { + DWORD SizeOfStruct; + DWORD64 BaseOfImage; + DWORD CheckSum; + DWORD TimeDateStamp; + CHAR FileName[MAX_PATH]; + BOOLEAN Reparse; + HANDLE hFile; + DWORD Flags; + } IMAGEHLP_DEFERRED_SYMBOL_LOAD64,*PIMAGEHLP_DEFERRED_SYMBOL_LOAD64; + +#define DSLFLAG_MISMATCHED_PDB 0x1 +#define DSLFLAG_MISMATCHED_DBG 0x2 + +#ifdef _IMAGEHLP64 +#define IMAGEHLP_DEFERRED_SYMBOL_LOAD IMAGEHLP_DEFERRED_SYMBOL_LOAD64 +#define PIMAGEHLP_DEFERRED_SYMBOL_LOAD PIMAGEHLP_DEFERRED_SYMBOL_LOAD64 +#else + typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD { + DWORD SizeOfStruct; + DWORD BaseOfImage; + DWORD CheckSum; + DWORD TimeDateStamp; + CHAR FileName[MAX_PATH]; + BOOLEAN Reparse; + HANDLE hFile; + } IMAGEHLP_DEFERRED_SYMBOL_LOAD,*PIMAGEHLP_DEFERRED_SYMBOL_LOAD; +#endif + + typedef struct _IMAGEHLP_DUPLICATE_SYMBOL64 { + DWORD SizeOfStruct; + DWORD NumberOfDups; + PIMAGEHLP_SYMBOL64 Symbol; + DWORD SelectedSymbol; + } IMAGEHLP_DUPLICATE_SYMBOL64,*PIMAGEHLP_DUPLICATE_SYMBOL64; + +#ifdef _IMAGEHLP64 +#define IMAGEHLP_DUPLICATE_SYMBOL IMAGEHLP_DUPLICATE_SYMBOL64 +#define PIMAGEHLP_DUPLICATE_SYMBOL PIMAGEHLP_DUPLICATE_SYMBOL64 +#else + typedef struct _IMAGEHLP_DUPLICATE_SYMBOL { + DWORD SizeOfStruct; + DWORD NumberOfDups; + PIMAGEHLP_SYMBOL Symbol; + DWORD SelectedSymbol; + } IMAGEHLP_DUPLICATE_SYMBOL,*PIMAGEHLP_DUPLICATE_SYMBOL; +#endif + + BOOL IMAGEAPI SymSetParentWindow(HWND hwnd); + PCHAR IMAGEAPI SymSetHomeDirectory(PCSTR dir); + PCHAR IMAGEAPI SymGetHomeDirectory(DWORD type,PSTR dir,size_t size); + + enum { + hdBase = 0,hdSym,hdSrc,hdMax + }; + +#define SYMOPT_CASE_INSENSITIVE 0x00000001 +#define SYMOPT_UNDNAME 0x00000002 +#define SYMOPT_DEFERRED_LOADS 0x00000004 +#define SYMOPT_NO_CPP 0x00000008 +#define SYMOPT_LOAD_LINES 0x00000010 +#define SYMOPT_OMAP_FIND_NEAREST 0x00000020 +#define SYMOPT_LOAD_ANYTHING 0x00000040 +#define SYMOPT_IGNORE_CVREC 0x00000080 +#define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100 +#define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200 +#define SYMOPT_EXACT_SYMBOLS 0x00000400 +#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800 +#define SYMOPT_IGNORE_NT_SYMPATH 0x00001000 +#define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000 +#define SYMOPT_PUBLICS_ONLY 0x00004000 +#define SYMOPT_NO_PUBLICS 0x00008000 +#define SYMOPT_AUTO_PUBLICS 0x00010000 +#define SYMOPT_NO_IMAGE_SEARCH 0x00020000 +#define SYMOPT_SECURE 0x00040000 +#define SYMOPT_NO_PROMPTS 0x00080000 + +#define SYMOPT_DEBUG 0x80000000 + + DWORD IMAGEAPI SymSetOptions(DWORD SymOptions); + DWORD IMAGEAPI SymGetOptions(VOID); + BOOL IMAGEAPI SymCleanup(HANDLE hProcess); + BOOL IMAGEAPI SymMatchString(LPSTR string,LPSTR expression,BOOL fCase); + + typedef BOOL (CALLBACK *PSYM_ENUMSOURCFILES_CALLBACK)(PSOURCEFILE pSourceFile,PVOID UserContext); + + BOOL IMAGEAPI SymEnumSourceFiles(HANDLE hProcess,ULONG64 ModBase,LPSTR Mask,PSYM_ENUMSOURCFILES_CALLBACK cbSrcFiles,PVOID UserContext); + BOOL IMAGEAPI SymEnumerateModules64(HANDLE hProcess,PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,PVOID UserContext); + +#ifdef _IMAGEHLP64 +#define SymEnumerateModules SymEnumerateModules64 +#else + BOOL IMAGEAPI SymEnumerateModules(HANDLE hProcess,PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,PVOID UserContext); +#endif + + BOOL IMAGEAPI SymEnumerateSymbols64(HANDLE hProcess,DWORD64 BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback,PVOID UserContext); + BOOL IMAGEAPI SymEnumerateSymbolsW64(HANDLE hProcess,DWORD64 BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK64W EnumSymbolsCallback,PVOID UserContext); + +#ifdef _IMAGEHLP64 +#define SymEnumerateSymbols SymEnumerateSymbols64 +#define SymEnumerateSymbolsW SymEnumerateSymbolsW64 +#else + BOOL IMAGEAPI SymEnumerateSymbols(HANDLE hProcess,DWORD BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext); + BOOL IMAGEAPI SymEnumerateSymbolsW(HANDLE hProcess,DWORD BaseOfDll,PSYM_ENUMSYMBOLS_CALLBACKW EnumSymbolsCallback,PVOID UserContext); +#endif + + BOOL IMAGEAPI EnumerateLoadedModules64(HANDLE hProcess,PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,PVOID UserContext); +#ifdef _IMAGEHLP64 +#define EnumerateLoadedModules EnumerateLoadedModules64 +#else + BOOL IMAGEAPI EnumerateLoadedModules(HANDLE hProcess,PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,PVOID UserContext); +#endif + + PVOID IMAGEAPI SymFunctionTableAccess64(HANDLE hProcess,DWORD64 AddrBase); + +#ifdef _IMAGEHLP64 +#define SymFunctionTableAccess SymFunctionTableAccess64 +#else + PVOID IMAGEAPI SymFunctionTableAccess(HANDLE hProcess,DWORD AddrBase); +#endif + + BOOL IMAGEAPI SymGetModuleInfo64(HANDLE hProcess,DWORD64 qwAddr,PIMAGEHLP_MODULE64 ModuleInfo); + BOOL IMAGEAPI SymGetModuleInfoW64(HANDLE hProcess,DWORD64 qwAddr,PIMAGEHLP_MODULEW64 ModuleInfo); + +#ifdef _IMAGEHLP64 +#define SymGetModuleInfo SymGetModuleInfo64 +#define SymGetModuleInfoW SymGetModuleInfoW64 +#else + BOOL IMAGEAPI SymGetModuleInfo(HANDLE hProcess,DWORD dwAddr,PIMAGEHLP_MODULE ModuleInfo); + BOOL IMAGEAPI SymGetModuleInfoW(HANDLE hProcess,DWORD dwAddr,PIMAGEHLP_MODULEW ModuleInfo); +#endif + + DWORD64 IMAGEAPI SymGetModuleBase64(HANDLE hProcess,DWORD64 qwAddr); + +#ifdef _IMAGEHLP64 +#define SymGetModuleBase SymGetModuleBase64 +#else + DWORD IMAGEAPI SymGetModuleBase(HANDLE hProcess,DWORD dwAddr); +#endif + + BOOL IMAGEAPI SymGetSymNext64(HANDLE hProcess,PIMAGEHLP_SYMBOL64 Symbol); + +#ifdef _IMAGEHLP64 +#define SymGetSymNext SymGetSymNext64 +#else + BOOL IMAGEAPI SymGetSymNext(HANDLE hProcess,PIMAGEHLP_SYMBOL Symbol); +#endif + + BOOL IMAGEAPI SymGetSymPrev64(HANDLE hProcess,PIMAGEHLP_SYMBOL64 Symbol); + +#ifdef _IMAGEHLP64 +#define SymGetSymPrev SymGetSymPrev64 +#else + BOOL IMAGEAPI SymGetSymPrev(HANDLE hProcess,PIMAGEHLP_SYMBOL Symbol); +#endif + + typedef struct _SRCCODEINFO { + DWORD SizeOfStruct; + PVOID Key; + DWORD64 ModBase; + CHAR Obj[MAX_PATH + 1]; + CHAR FileName[MAX_PATH + 1]; + DWORD LineNumber; + DWORD64 Address; + } SRCCODEINFO,*PSRCCODEINFO; + + typedef BOOL (CALLBACK *PSYM_ENUMLINES_CALLBACK)(PSRCCODEINFO LineInfo,PVOID UserContext); + + BOOL IMAGEAPI SymEnumLines(HANDLE hProcess,ULONG64 Base,PCSTR Obj,PCSTR File,PSYM_ENUMLINES_CALLBACK EnumLinesCallback,PVOID UserContext); + BOOL IMAGEAPI SymGetLineFromAddr64(HANDLE hProcess,DWORD64 qwAddr,PDWORD pdwDisplacement,PIMAGEHLP_LINE64 Line64); + +#ifdef _IMAGEHLP64 +#define SymGetLineFromAddr SymGetLineFromAddr64 +#else + BOOL IMAGEAPI SymGetLineFromAddr(HANDLE hProcess,DWORD dwAddr,PDWORD pdwDisplacement,PIMAGEHLP_LINE Line); +#endif + + BOOL IMAGEAPI SymGetLineFromName64(HANDLE hProcess,PSTR ModuleName,PSTR FileName,DWORD dwLineNumber,PLONG plDisplacement,PIMAGEHLP_LINE64 Line); + +#ifdef _IMAGEHLP64 +#define SymGetLineFromName SymGetLineFromName64 +#else + BOOL IMAGEAPI SymGetLineFromName(HANDLE hProcess,PSTR ModuleName,PSTR FileName,DWORD dwLineNumber,PLONG plDisplacement,PIMAGEHLP_LINE Line); +#endif + + BOOL IMAGEAPI SymGetLineNext64(HANDLE hProcess,PIMAGEHLP_LINE64 Line); + +#ifdef _IMAGEHLP64 +#define SymGetLineNext SymGetLineNext64 +#else + BOOL IMAGEAPI SymGetLineNext(HANDLE hProcess,PIMAGEHLP_LINE Line); +#endif + + BOOL IMAGEAPI SymGetLinePrev64(HANDLE hProcess,PIMAGEHLP_LINE64 Line); + +#ifdef _IMAGEHLP64 +#define SymGetLinePrev SymGetLinePrev64 +#else + BOOL IMAGEAPI SymGetLinePrev(HANDLE hProcess,PIMAGEHLP_LINE Line); +#endif + + BOOL IMAGEAPI SymMatchFileName(PSTR FileName,PSTR Match,PSTR *FileNameStop,PSTR *MatchStop); + BOOL IMAGEAPI SymInitialize(HANDLE hProcess,PSTR UserSearchPath,BOOL fInvadeProcess); + BOOL IMAGEAPI SymGetSearchPath(HANDLE hProcess,PSTR SearchPath,DWORD SearchPathLength); + BOOL IMAGEAPI SymSetSearchPath(HANDLE hProcess,PSTR SearchPath); + DWORD64 IMAGEAPI SymLoadModule64(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD64 BaseOfDll,DWORD SizeOfDll); + +#define SLMFLAG_VIRTUAL 0x1 + + DWORD64 IMAGEAPI SymLoadModuleEx(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD64 BaseOfDll,DWORD DllSize,PMODLOAD_DATA Data,DWORD Flags); + +#ifdef _IMAGEHLP64 +#define SymLoadModule SymLoadModule64 +#else + DWORD IMAGEAPI SymLoadModule(HANDLE hProcess,HANDLE hFile,PSTR ImageName,PSTR ModuleName,DWORD BaseOfDll,DWORD SizeOfDll); +#endif + + BOOL IMAGEAPI SymUnloadModule64(HANDLE hProcess,DWORD64 BaseOfDll); + +#ifdef _IMAGEHLP64 +#define SymUnloadModule SymUnloadModule64 +#else + BOOL IMAGEAPI SymUnloadModule(HANDLE hProcess,DWORD BaseOfDll); +#endif + + BOOL IMAGEAPI SymUnDName64(PIMAGEHLP_SYMBOL64 sym,PSTR UnDecName,DWORD UnDecNameLength); + +#ifdef _IMAGEHLP64 +#define SymUnDName SymUnDName64 +#else + BOOL IMAGEAPI SymUnDName(PIMAGEHLP_SYMBOL sym,PSTR UnDecName,DWORD UnDecNameLength); +#endif + + BOOL IMAGEAPI SymRegisterCallback64(HANDLE hProcess,PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,ULONG64 UserContext); + + BOOL IMAGEAPI SymRegisterFunctionEntryCallback64(HANDLE hProcess,PSYMBOL_FUNCENTRY_CALLBACK64 CallbackFunction,ULONG64 UserContext); + +#ifdef _IMAGEHLP64 +#define SymRegisterCallback SymRegisterCallback64 +#define SymRegisterFunctionEntryCallback SymRegisterFunctionEntryCallback64 +#else + BOOL IMAGEAPI SymRegisterCallback(HANDLE hProcess,PSYMBOL_REGISTERED_CALLBACK CallbackFunction,PVOID UserContext); + BOOL IMAGEAPI SymRegisterFunctionEntryCallback(HANDLE hProcess,PSYMBOL_FUNCENTRY_CALLBACK CallbackFunction,PVOID UserContext); +#endif + + typedef struct _IMAGEHLP_SYMBOL_SRC { + DWORD sizeofstruct; + DWORD type; + char file[MAX_PATH]; + } IMAGEHLP_SYMBOL_SRC,*PIMAGEHLP_SYMBOL_SRC; + + typedef struct _MODULE_TYPE_INFO { + USHORT dataLength; + USHORT leaf; + BYTE data[1]; + } MODULE_TYPE_INFO,*PMODULE_TYPE_INFO; + + typedef struct _SYMBOL_INFO { + ULONG SizeOfStruct; + ULONG TypeIndex; + ULONG64 Reserved[2]; + ULONG info; + ULONG Size; + ULONG64 ModBase; + ULONG Flags; + ULONG64 Value; + ULONG64 Address; + ULONG Register; + ULONG Scope; + ULONG Tag; + ULONG NameLen; + ULONG MaxNameLen; + CHAR Name[1]; + } SYMBOL_INFO,*PSYMBOL_INFO; + + typedef struct _SYMBOL_INFO_PACKAGE { + SYMBOL_INFO si; + CHAR name[MAX_SYM_NAME + 1]; + } SYMBOL_INFO_PACKAGE,*PSYMBOL_INFO_PACKAGE; + + typedef struct _IMAGEHLP_STACK_FRAME + { + ULONG64 InstructionOffset; + ULONG64 ReturnOffset; + ULONG64 FrameOffset; + ULONG64 StackOffset; + ULONG64 BackingStoreOffset; + ULONG64 FuncTableEntry; + ULONG64 Params[4]; + ULONG64 Reserved[5]; + BOOL Virtual; + ULONG Reserved2; + } IMAGEHLP_STACK_FRAME,*PIMAGEHLP_STACK_FRAME; + + typedef VOID IMAGEHLP_CONTEXT,*PIMAGEHLP_CONTEXT; + + BOOL IMAGEAPI SymSetContext(HANDLE hProcess,PIMAGEHLP_STACK_FRAME StackFrame,PIMAGEHLP_CONTEXT Context); + BOOL IMAGEAPI SymFromAddr(HANDLE hProcess,DWORD64 Address,PDWORD64 Displacement,PSYMBOL_INFO Symbol); + BOOL IMAGEAPI SymFromToken(HANDLE hProcess,DWORD64 Base,DWORD Token,PSYMBOL_INFO Symbol); + BOOL IMAGEAPI SymFromName(HANDLE hProcess,LPSTR Name,PSYMBOL_INFO Symbol); + + typedef BOOL (CALLBACK *PSYM_ENUMERATESYMBOLS_CALLBACK)(PSYMBOL_INFO pSymInfo,ULONG SymbolSize,PVOID UserContext); + + BOOL IMAGEAPI SymEnumSymbols(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Mask,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext); + BOOL IMAGEAPI SymEnumSymbolsForAddr(HANDLE hProcess,DWORD64 Address,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext); + +#define SYMENUMFLAG_FULLSRCH 1 +#define SYMENUMFLAG_SPEEDSRCH 2 + + typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO { + TI_GET_SYMTAG,TI_GET_SYMNAME,TI_GET_LENGTH,TI_GET_TYPE,TI_GET_TYPEID,TI_GET_BASETYPE,TI_GET_ARRAYINDEXTYPEID,TI_FINDCHILDREN, + TI_GET_DATAKIND,TI_GET_ADDRESSOFFSET,TI_GET_OFFSET,TI_GET_VALUE,TI_GET_COUNT,TI_GET_CHILDRENCOUNT,TI_GET_BITPOSITION,TI_GET_VIRTUALBASECLASS, + TI_GET_VIRTUALTABLESHAPEID,TI_GET_VIRTUALBASEPOINTEROFFSET,TI_GET_CLASSPARENTID,TI_GET_NESTED,TI_GET_SYMINDEX,TI_GET_LEXICALPARENT, + TI_GET_ADDRESS,TI_GET_THISADJUST,TI_GET_UDTKIND,TI_IS_EQUIV_TO,TI_GET_CALLING_CONVENTION + } IMAGEHLP_SYMBOL_TYPE_INFO; + + typedef struct _TI_FINDCHILDREN_PARAMS { + ULONG Count; + ULONG Start; + ULONG ChildId[1]; + } TI_FINDCHILDREN_PARAMS; + + BOOL IMAGEAPI SymGetTypeInfo(HANDLE hProcess,DWORD64 ModBase,ULONG TypeId,IMAGEHLP_SYMBOL_TYPE_INFO GetType,PVOID pInfo); + BOOL IMAGEAPI SymEnumTypes(HANDLE hProcess,ULONG64 BaseOfDll,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext); + BOOL IMAGEAPI SymGetTypeFromName(HANDLE hProcess,ULONG64 BaseOfDll,LPSTR Name,PSYMBOL_INFO Symbol); + BOOL IMAGEAPI SymAddSymbol(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Name,DWORD64 Address,DWORD Size,DWORD Flags); + BOOL IMAGEAPI SymDeleteSymbol(HANDLE hProcess,ULONG64 BaseOfDll,PCSTR Name,DWORD64 Address,DWORD Flags); + + typedef BOOL (WINAPI *PDBGHELP_CREATE_USER_DUMP_CALLBACK)(DWORD DataType,PVOID *Data,LPDWORD DataLength,PVOID UserData); + + BOOL WINAPI DbgHelpCreateUserDump(LPSTR FileName,PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,PVOID UserData); + BOOL WINAPI DbgHelpCreateUserDumpW(LPWSTR FileName,PDBGHELP_CREATE_USER_DUMP_CALLBACK Callback,PVOID UserData); + BOOL IMAGEAPI SymGetSymFromAddr64(HANDLE hProcess,DWORD64 qwAddr,PDWORD64 pdwDisplacement,PIMAGEHLP_SYMBOL64 Symbol); + +#ifdef _IMAGEHLP64 +#define SymGetSymFromAddr SymGetSymFromAddr64 +#else + BOOL IMAGEAPI SymGetSymFromAddr(HANDLE hProcess,DWORD dwAddr,PDWORD pdwDisplacement,PIMAGEHLP_SYMBOL Symbol); +#endif + + BOOL IMAGEAPI SymGetSymFromName64(HANDLE hProcess,PSTR Name,PIMAGEHLP_SYMBOL64 Symbol); + +#ifdef _IMAGEHLP64 +#define SymGetSymFromName SymGetSymFromName64 +#else + BOOL IMAGEAPI SymGetSymFromName(HANDLE hProcess,PSTR Name,PIMAGEHLP_SYMBOL Symbol); +#endif + + DBHLP_DEPRECIATED BOOL IMAGEAPI FindFileInPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,PVOID id,DWORD two,DWORD three,DWORD flags,LPSTR FilePath); + DBHLP_DEPRECIATED BOOL IMAGEAPI FindFileInSearchPath(HANDLE hprocess,LPSTR SearchPath,LPSTR FileName,DWORD one,DWORD two,DWORD three,LPSTR FilePath); + DBHLP_DEPRECIATED BOOL IMAGEAPI SymEnumSym(HANDLE hProcess,ULONG64 BaseOfDll,PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,PVOID UserContext); + +#define SYMF_OMAP_GENERATED 0x00000001 +#define SYMF_OMAP_MODIFIED 0x00000002 +#define SYMF_REGISTER 0x00000008 +#define SYMF_REGREL 0x00000010 +#define SYMF_FRAMEREL 0x00000020 +#define SYMF_PARAMETER 0x00000040 +#define SYMF_LOCAL 0x00000080 +#define SYMF_CONSTANT 0x00000100 +#define SYMF_EXPORT 0x00000200 +#define SYMF_FORWARDER 0x00000400 +#define SYMF_FUNCTION 0x00000800 +#define SYMF_VIRTUAL 0x00001000 +#define SYMF_THUNK 0x00002000 +#define SYMF_TLSREL 0x00004000 + +#define IMAGEHLP_SYMBOL_INFO_VALUEPRESENT 1 +#define IMAGEHLP_SYMBOL_INFO_REGISTER SYMF_REGISTER +#define IMAGEHLP_SYMBOL_INFO_REGRELATIVE SYMF_REGREL +#define IMAGEHLP_SYMBOL_INFO_FRAMERELATIVE SYMF_FRAMEREL +#define IMAGEHLP_SYMBOL_INFO_PARAMETER SYMF_PARAMETER +#define IMAGEHLP_SYMBOL_INFO_LOCAL SYMF_LOCAL +#define IMAGEHLP_SYMBOL_INFO_CONSTANT SYMF_CONSTANT +#define IMAGEHLP_SYMBOL_FUNCTION SYMF_FUNCTION +#define IMAGEHLP_SYMBOL_VIRTUAL SYMF_VIRTUAL +#define IMAGEHLP_SYMBOL_THUNK SYMF_THUNK +#define IMAGEHLP_SYMBOL_INFO_TLSRELATIVE SYMF_TLSREL + +#include <pshpack4.h> + +#define MINIDUMP_SIGNATURE ('PMDM') +#define MINIDUMP_VERSION (42899) + typedef DWORD RVA; + typedef ULONG64 RVA64; + + typedef struct _MINIDUMP_LOCATION_DESCRIPTOR { + ULONG32 DataSize; + RVA Rva; + } MINIDUMP_LOCATION_DESCRIPTOR; + + typedef struct _MINIDUMP_LOCATION_DESCRIPTOR64 { + ULONG64 DataSize; + RVA64 Rva; + } MINIDUMP_LOCATION_DESCRIPTOR64; + + typedef struct _MINIDUMP_MEMORY_DESCRIPTOR { + ULONG64 StartOfMemoryRange; + MINIDUMP_LOCATION_DESCRIPTOR Memory; + } MINIDUMP_MEMORY_DESCRIPTOR,*PMINIDUMP_MEMORY_DESCRIPTOR; + + typedef struct _MINIDUMP_MEMORY_DESCRIPTOR64 { + ULONG64 StartOfMemoryRange; + ULONG64 DataSize; + } MINIDUMP_MEMORY_DESCRIPTOR64,*PMINIDUMP_MEMORY_DESCRIPTOR64; + + typedef struct _MINIDUMP_HEADER { + ULONG32 Signature; + ULONG32 Version; + ULONG32 NumberOfStreams; + RVA StreamDirectoryRva; + ULONG32 CheckSum; + union { + ULONG32 Reserved; + ULONG32 TimeDateStamp; + } DUMMYUNIONNAME; + ULONG64 Flags; + } MINIDUMP_HEADER,*PMINIDUMP_HEADER; + + typedef struct _MINIDUMP_DIRECTORY { + ULONG32 StreamType; + MINIDUMP_LOCATION_DESCRIPTOR Location; + } MINIDUMP_DIRECTORY,*PMINIDUMP_DIRECTORY; + + typedef struct _MINIDUMP_STRING { + ULONG32 Length; + WCHAR Buffer [0]; + } MINIDUMP_STRING,*PMINIDUMP_STRING; + + typedef enum _MINIDUMP_STREAM_TYPE { + UnusedStream = 0,ReservedStream0 = 1,ReservedStream1 = 2,ThreadListStream = 3,ModuleListStream = 4,MemoryListStream = 5, + ExceptionStream = 6,SystemInfoStream = 7,ThreadExListStream = 8,Memory64ListStream = 9,CommentStreamA = 10,CommentStreamW = 11, + HandleDataStream = 12,FunctionTableStream = 13,UnloadedModuleListStream = 14,MiscInfoStream = 15,LastReservedStream = 0xffff + } MINIDUMP_STREAM_TYPE; + + typedef union _CPU_INFORMATION { + struct { + ULONG32 VendorId [3 ]; + ULONG32 VersionInformation; + ULONG32 FeatureInformation; + ULONG32 AMDExtendedCpuFeatures; + } X86CpuInfo; + struct { + ULONG64 ProcessorFeatures [2 ]; + } OtherCpuInfo; + } CPU_INFORMATION,*PCPU_INFORMATION; + + typedef struct _MINIDUMP_SYSTEM_INFO { + USHORT ProcessorArchitecture; + USHORT ProcessorLevel; + USHORT ProcessorRevision; + union { + USHORT Reserved0; + struct { + UCHAR NumberOfProcessors; + UCHAR ProductType; + } DUMMYSTRUCTNAME; + } DUMMYUNIONNAME; + ULONG32 MajorVersion; + ULONG32 MinorVersion; + ULONG32 BuildNumber; + ULONG32 PlatformId; + RVA CSDVersionRva; + union { + ULONG32 Reserved1; + struct { + USHORT SuiteMask; + USHORT Reserved2; + } DUMMYSTRUCTNAME; + } DUMMYUNIONNAME1; + CPU_INFORMATION Cpu; + } MINIDUMP_SYSTEM_INFO,*PMINIDUMP_SYSTEM_INFO; + + C_ASSERT (sizeof (((PPROCESS_INFORMATION)0)->dwThreadId)==4); + + typedef struct _MINIDUMP_THREAD { + ULONG32 ThreadId; + ULONG32 SuspendCount; + ULONG32 PriorityClass; + ULONG32 Priority; + ULONG64 Teb; + MINIDUMP_MEMORY_DESCRIPTOR Stack; + MINIDUMP_LOCATION_DESCRIPTOR ThreadContext; + } MINIDUMP_THREAD,*PMINIDUMP_THREAD; + + typedef struct _MINIDUMP_THREAD_LIST { + ULONG32 NumberOfThreads; + MINIDUMP_THREAD Threads [0]; + } MINIDUMP_THREAD_LIST,*PMINIDUMP_THREAD_LIST; + + typedef struct _MINIDUMP_THREAD_EX { + ULONG32 ThreadId; + ULONG32 SuspendCount; + ULONG32 PriorityClass; + ULONG32 Priority; + ULONG64 Teb; + MINIDUMP_MEMORY_DESCRIPTOR Stack; + MINIDUMP_LOCATION_DESCRIPTOR ThreadContext; + MINIDUMP_MEMORY_DESCRIPTOR BackingStore; + } MINIDUMP_THREAD_EX,*PMINIDUMP_THREAD_EX; + + typedef struct _MINIDUMP_THREAD_EX_LIST { + ULONG32 NumberOfThreads; + MINIDUMP_THREAD_EX Threads [0]; + } MINIDUMP_THREAD_EX_LIST,*PMINIDUMP_THREAD_EX_LIST; + + typedef struct _MINIDUMP_EXCEPTION { + ULONG32 ExceptionCode; + ULONG32 ExceptionFlags; + ULONG64 ExceptionRecord; + ULONG64 ExceptionAddress; + ULONG32 NumberParameters; + ULONG32 __unusedAlignment; + ULONG64 ExceptionInformation [EXCEPTION_MAXIMUM_PARAMETERS ]; + } MINIDUMP_EXCEPTION,*PMINIDUMP_EXCEPTION; + + typedef struct MINIDUMP_EXCEPTION_STREAM { + ULONG32 ThreadId; + ULONG32 __alignment; + MINIDUMP_EXCEPTION ExceptionRecord; + MINIDUMP_LOCATION_DESCRIPTOR ThreadContext; + } MINIDUMP_EXCEPTION_STREAM,*PMINIDUMP_EXCEPTION_STREAM; + + typedef struct _MINIDUMP_MODULE { + ULONG64 BaseOfImage; + ULONG32 SizeOfImage; + ULONG32 CheckSum; + ULONG32 TimeDateStamp; + RVA ModuleNameRva; + VS_FIXEDFILEINFO VersionInfo; + MINIDUMP_LOCATION_DESCRIPTOR CvRecord; + MINIDUMP_LOCATION_DESCRIPTOR MiscRecord; + ULONG64 Reserved0; + ULONG64 Reserved1; + } MINIDUMP_MODULE,*PMINIDUMP_MODULE; + + typedef struct _MINIDUMP_MODULE_LIST { + ULONG32 NumberOfModules; + MINIDUMP_MODULE Modules [0 ]; + } MINIDUMP_MODULE_LIST,*PMINIDUMP_MODULE_LIST; + + typedef struct _MINIDUMP_MEMORY_LIST { + ULONG32 NumberOfMemoryRanges; + MINIDUMP_MEMORY_DESCRIPTOR MemoryRanges [0]; + } MINIDUMP_MEMORY_LIST,*PMINIDUMP_MEMORY_LIST; + + typedef struct _MINIDUMP_MEMORY64_LIST { + ULONG64 NumberOfMemoryRanges; + RVA64 BaseRva; + MINIDUMP_MEMORY_DESCRIPTOR64 MemoryRanges [0]; + } MINIDUMP_MEMORY64_LIST,*PMINIDUMP_MEMORY64_LIST; + + typedef struct _MINIDUMP_EXCEPTION_INFORMATION { + DWORD ThreadId; + PEXCEPTION_POINTERS ExceptionPointers; + BOOL ClientPointers; + } MINIDUMP_EXCEPTION_INFORMATION,*PMINIDUMP_EXCEPTION_INFORMATION; + + typedef struct _MINIDUMP_EXCEPTION_INFORMATION64 { + DWORD ThreadId; + ULONG64 ExceptionRecord; + ULONG64 ContextRecord; + BOOL ClientPointers; + } MINIDUMP_EXCEPTION_INFORMATION64,*PMINIDUMP_EXCEPTION_INFORMATION64; + + typedef struct _MINIDUMP_HANDLE_DESCRIPTOR { + ULONG64 Handle; + RVA TypeNameRva; + RVA ObjectNameRva; + ULONG32 Attributes; + ULONG32 GrantedAccess; + ULONG32 HandleCount; + ULONG32 PointerCount; + } MINIDUMP_HANDLE_DESCRIPTOR,*PMINIDUMP_HANDLE_DESCRIPTOR; + + typedef struct _MINIDUMP_HANDLE_DATA_STREAM { + ULONG32 SizeOfHeader; + ULONG32 SizeOfDescriptor; + ULONG32 NumberOfDescriptors; + ULONG32 Reserved; + } MINIDUMP_HANDLE_DATA_STREAM,*PMINIDUMP_HANDLE_DATA_STREAM; + + typedef struct _MINIDUMP_FUNCTION_TABLE_DESCRIPTOR { + ULONG64 MinimumAddress; + ULONG64 MaximumAddress; + ULONG64 BaseAddress; + ULONG32 EntryCount; + ULONG32 SizeOfAlignPad; + } MINIDUMP_FUNCTION_TABLE_DESCRIPTOR,*PMINIDUMP_FUNCTION_TABLE_DESCRIPTOR; + + typedef struct _MINIDUMP_FUNCTION_TABLE_STREAM { + ULONG32 SizeOfHeader; + ULONG32 SizeOfDescriptor; + ULONG32 SizeOfNativeDescriptor; + ULONG32 SizeOfFunctionEntry; + ULONG32 NumberOfDescriptors; + ULONG32 SizeOfAlignPad; + } MINIDUMP_FUNCTION_TABLE_STREAM,*PMINIDUMP_FUNCTION_TABLE_STREAM; + + typedef struct _MINIDUMP_UNLOADED_MODULE { + ULONG64 BaseOfImage; + ULONG32 SizeOfImage; + ULONG32 CheckSum; + ULONG32 TimeDateStamp; + RVA ModuleNameRva; + } MINIDUMP_UNLOADED_MODULE,*PMINIDUMP_UNLOADED_MODULE; + + typedef struct _MINIDUMP_UNLOADED_MODULE_LIST { + ULONG32 SizeOfHeader; + ULONG32 SizeOfEntry; + ULONG32 NumberOfEntries; + } MINIDUMP_UNLOADED_MODULE_LIST,*PMINIDUMP_UNLOADED_MODULE_LIST; + +#define MINIDUMP_MISC1_PROCESS_ID 0x00000001 +#define MINIDUMP_MISC1_PROCESS_TIMES 0x00000002 + + typedef struct _MINIDUMP_MISC_INFO { + ULONG32 SizeOfInfo; + ULONG32 Flags1; + ULONG32 ProcessId; + ULONG32 ProcessCreateTime; + ULONG32 ProcessUserTime; + ULONG32 ProcessKernelTime; + } MINIDUMP_MISC_INFO,*PMINIDUMP_MISC_INFO; + + typedef struct _MINIDUMP_USER_RECORD { + ULONG32 Type; + MINIDUMP_LOCATION_DESCRIPTOR Memory; + } MINIDUMP_USER_RECORD,*PMINIDUMP_USER_RECORD; + + typedef struct _MINIDUMP_USER_STREAM { + ULONG32 Type; + ULONG BufferSize; + PVOID Buffer; + } MINIDUMP_USER_STREAM,*PMINIDUMP_USER_STREAM; + + typedef struct _MINIDUMP_USER_STREAM_INFORMATION { + ULONG UserStreamCount; + PMINIDUMP_USER_STREAM UserStreamArray; + } MINIDUMP_USER_STREAM_INFORMATION,*PMINIDUMP_USER_STREAM_INFORMATION; + + typedef enum _MINIDUMP_CALLBACK_TYPE { + ModuleCallback,ThreadCallback,ThreadExCallback,IncludeThreadCallback,IncludeModuleCallback,MemoryCallback + } MINIDUMP_CALLBACK_TYPE; + + typedef struct _MINIDUMP_THREAD_CALLBACK { + ULONG ThreadId; + HANDLE ThreadHandle; + CONTEXT Context; + ULONG SizeOfContext; + ULONG64 StackBase; + ULONG64 StackEnd; + } MINIDUMP_THREAD_CALLBACK,*PMINIDUMP_THREAD_CALLBACK; + + typedef struct _MINIDUMP_THREAD_EX_CALLBACK { + ULONG ThreadId; + HANDLE ThreadHandle; + CONTEXT Context; + ULONG SizeOfContext; + ULONG64 StackBase; + ULONG64 StackEnd; + ULONG64 BackingStoreBase; + ULONG64 BackingStoreEnd; + } MINIDUMP_THREAD_EX_CALLBACK,*PMINIDUMP_THREAD_EX_CALLBACK; + + typedef struct _MINIDUMP_INCLUDE_THREAD_CALLBACK { + ULONG ThreadId; + } MINIDUMP_INCLUDE_THREAD_CALLBACK,*PMINIDUMP_INCLUDE_THREAD_CALLBACK; + + typedef enum _THREAD_WRITE_FLAGS { + ThreadWriteThread = 0x0001,ThreadWriteStack = 0x0002,ThreadWriteContext = 0x0004,ThreadWriteBackingStore = 0x0008, + ThreadWriteInstructionWindow = 0x0010,ThreadWriteThreadData = 0x0020 + } THREAD_WRITE_FLAGS; + + typedef struct _MINIDUMP_MODULE_CALLBACK { + PWCHAR FullPath; + ULONG64 BaseOfImage; + ULONG SizeOfImage; + ULONG CheckSum; + ULONG TimeDateStamp; + VS_FIXEDFILEINFO VersionInfo; + PVOID CvRecord; + ULONG SizeOfCvRecord; + PVOID MiscRecord; + ULONG SizeOfMiscRecord; + } MINIDUMP_MODULE_CALLBACK,*PMINIDUMP_MODULE_CALLBACK; + + typedef struct _MINIDUMP_INCLUDE_MODULE_CALLBACK { + ULONG64 BaseOfImage; + } MINIDUMP_INCLUDE_MODULE_CALLBACK,*PMINIDUMP_INCLUDE_MODULE_CALLBACK; + + typedef enum _MODULE_WRITE_FLAGS { + ModuleWriteModule = 0x0001,ModuleWriteDataSeg = 0x0002,ModuleWriteMiscRecord = 0x0004,ModuleWriteCvRecord = 0x0008, + ModuleReferencedByMemory = 0x0010 + } MODULE_WRITE_FLAGS; + + typedef struct _MINIDUMP_CALLBACK_INPUT { + ULONG ProcessId; + HANDLE ProcessHandle; + ULONG CallbackType; + union { + MINIDUMP_THREAD_CALLBACK Thread; + MINIDUMP_THREAD_EX_CALLBACK ThreadEx; + MINIDUMP_MODULE_CALLBACK Module; + MINIDUMP_INCLUDE_THREAD_CALLBACK IncludeThread; + MINIDUMP_INCLUDE_MODULE_CALLBACK IncludeModule; + } DUMMYUNIONNAME; + } MINIDUMP_CALLBACK_INPUT,*PMINIDUMP_CALLBACK_INPUT; + + typedef struct _MINIDUMP_CALLBACK_OUTPUT { + union { + ULONG ModuleWriteFlags; + ULONG ThreadWriteFlags; + struct { + ULONG64 MemoryBase; + ULONG MemorySize; + } DUMMYSTRUCTNAME; + } DUMMYUNIONNAME; + } MINIDUMP_CALLBACK_OUTPUT,*PMINIDUMP_CALLBACK_OUTPUT; + + typedef enum _MINIDUMP_TYPE { + MiniDumpNormal = 0x0000,MiniDumpWithDataSegs = 0x0001,MiniDumpWithFullMemory = 0x0002,MiniDumpWithHandleData = 0x0004, + MiniDumpFilterMemory = 0x0008,MiniDumpScanMemory = 0x0010,MiniDumpWithUnloadedModules = 0x0020,MiniDumpWithIndirectlyReferencedMemory = 0x0040, + MiniDumpFilterModulePaths = 0x0080,MiniDumpWithProcessThreadData = 0x0100,MiniDumpWithPrivateReadWriteMemory = 0x0200, + MiniDumpWithoutOptionalData = 0x0400 + } MINIDUMP_TYPE; + + typedef BOOL (WINAPI *MINIDUMP_CALLBACK_ROUTINE)(PVOID CallbackParam,CONST PMINIDUMP_CALLBACK_INPUT CallbackInput,PMINIDUMP_CALLBACK_OUTPUT CallbackOutput); + + typedef struct _MINIDUMP_CALLBACK_INFORMATION { + MINIDUMP_CALLBACK_ROUTINE CallbackRoutine; + PVOID CallbackParam; + } MINIDUMP_CALLBACK_INFORMATION,*PMINIDUMP_CALLBACK_INFORMATION; + +#define RVA_TO_ADDR(Mapping,Rva) ((PVOID)(((ULONG_PTR) (Mapping)) + (Rva))) + + BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess,DWORD ProcessId,HANDLE hFile,MINIDUMP_TYPE DumpType,CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); + BOOL WINAPI MiniDumpReadDumpStream(PVOID BaseOfDump,ULONG StreamNumber,PMINIDUMP_DIRECTORY *Dir,PVOID *StreamPointer,ULONG *StreamSize); + +#include <poppack.h> + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_bitmask.c b/mesalib/src/gallium/auxiliary/util/u_bitmask.c index c2952a30d..23c93a3eb 100644 --- a/mesalib/src/gallium/auxiliary/util/u_bitmask.c +++ b/mesalib/src/gallium/auxiliary/util/u_bitmask.c @@ -1,328 +1,328 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Generic bitmask implementation.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-
-#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "util/u_memory.h"
-#include "util/u_bitmask.h"
-
-
-typedef uint32_t util_bitmask_word;
-
-
-#define UTIL_BITMASK_INITIAL_WORDS 16
-#define UTIL_BITMASK_BITS_PER_BYTE 8
-#define UTIL_BITMASK_BITS_PER_WORD (sizeof(util_bitmask_word) * UTIL_BITMASK_BITS_PER_BYTE)
-
-
-struct util_bitmask
-{
- util_bitmask_word *words;
-
- /** Number of bits we can currently hold */
- unsigned size;
-
- /** Number of consecutive bits set at the start of the bitmask */
- unsigned filled;
-};
-
-
-struct util_bitmask *
-util_bitmask_create(void)
-{
- struct util_bitmask *bm;
-
- bm = MALLOC_STRUCT(util_bitmask);
- if(!bm)
- return NULL;
-
- bm->words = (util_bitmask_word *)CALLOC(UTIL_BITMASK_INITIAL_WORDS, sizeof(util_bitmask_word));
- if(!bm->words) {
- FREE(bm);
- return NULL;
- }
-
- bm->size = UTIL_BITMASK_INITIAL_WORDS * UTIL_BITMASK_BITS_PER_WORD;
- bm->filled = 0;
-
- return bm;
-}
-
-
-/**
- * Resize the bitmask if necessary
- */
-static INLINE boolean
-util_bitmask_resize(struct util_bitmask *bm,
- unsigned minimum_index)
-{
- unsigned minimum_size = minimum_index + 1;
- unsigned new_size;
- util_bitmask_word *new_words;
-
- /* Check integer overflow */
- if(!minimum_size)
- return FALSE;
-
- if(bm->size >= minimum_size)
- return TRUE;
-
- assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0);
- new_size = bm->size;
- while(new_size < minimum_size) {
- new_size *= 2;
- /* Check integer overflow */
- if(new_size < bm->size)
- return FALSE;
- }
- assert(new_size);
- assert(new_size % UTIL_BITMASK_BITS_PER_WORD == 0);
-
- new_words = (util_bitmask_word *)REALLOC((void *)bm->words,
- bm->size / UTIL_BITMASK_BITS_PER_BYTE,
- new_size / UTIL_BITMASK_BITS_PER_BYTE);
- if(!new_words)
- return FALSE;
-
- memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD,
- 0,
- (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE);
-
- bm->size = new_size;
- bm->words = new_words;
-
- return TRUE;
-}
-
-
-/**
- * Lazily update the filled.
- */
-static INLINE void
-util_bitmask_filled_set(struct util_bitmask *bm,
- unsigned index)
-{
- assert(bm->filled <= bm->size);
- assert(index < bm->size);
-
- if(index == bm->filled) {
- ++bm->filled;
- assert(bm->filled <= bm->size);
- }
-}
-
-static INLINE void
-util_bitmask_filled_unset(struct util_bitmask *bm,
- unsigned index)
-{
- assert(bm->filled <= bm->size);
- assert(index < bm->size);
-
- if(index < bm->filled)
- bm->filled = index;
-}
-
-
-unsigned
-util_bitmask_add(struct util_bitmask *bm)
-{
- unsigned word;
- unsigned bit;
- util_bitmask_word mask;
-
- assert(bm);
-
- /* linear search for an empty index */
- word = bm->filled / UTIL_BITMASK_BITS_PER_WORD;
- bit = bm->filled % UTIL_BITMASK_BITS_PER_WORD;
- mask = 1 << bit;
- while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) {
- while(bit < UTIL_BITMASK_BITS_PER_WORD) {
- if(!(bm->words[word] & mask))
- goto found;
- ++bm->filled;
- ++bit;
- mask <<= 1;
- }
- ++word;
- bit = 0;
- mask = 1;
- }
-found:
-
- /* grow the bitmask if necessary */
- if(!util_bitmask_resize(bm, bm->filled))
- return UTIL_BITMASK_INVALID_INDEX;
-
- assert(!(bm->words[word] & mask));
- bm->words[word] |= mask;
-
- return bm->filled++;
-}
-
-
-unsigned
-util_bitmask_set(struct util_bitmask *bm,
- unsigned index)
-{
- unsigned word;
- unsigned bit;
- util_bitmask_word mask;
-
- assert(bm);
-
- /* grow the bitmask if necessary */
- if(!util_bitmask_resize(bm, index))
- return UTIL_BITMASK_INVALID_INDEX;
-
- word = index / UTIL_BITMASK_BITS_PER_WORD;
- bit = index % UTIL_BITMASK_BITS_PER_WORD;
- mask = 1 << bit;
-
- bm->words[word] |= mask;
-
- util_bitmask_filled_set(bm, index);
-
- return index;
-}
-
-
-void
-util_bitmask_clear(struct util_bitmask *bm,
- unsigned index)
-{
- unsigned word;
- unsigned bit;
- util_bitmask_word mask;
-
- assert(bm);
-
- if(index >= bm->size)
- return;
-
- word = index / UTIL_BITMASK_BITS_PER_WORD;
- bit = index % UTIL_BITMASK_BITS_PER_WORD;
- mask = 1 << bit;
-
- bm->words[word] &= ~mask;
-
- util_bitmask_filled_unset(bm, index);
-}
-
-
-boolean
-util_bitmask_get(struct util_bitmask *bm,
- unsigned index)
-{
- unsigned word = index / UTIL_BITMASK_BITS_PER_WORD;
- unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD;
- util_bitmask_word mask = 1 << bit;
-
- assert(bm);
-
- if(index < bm->filled) {
- assert(bm->words[word] & mask);
- return TRUE;
- }
-
- if(index >= bm->size)
- return FALSE;
-
- if(bm->words[word] & mask) {
- util_bitmask_filled_set(bm, index);
- return TRUE;
- }
- else
- return FALSE;
-}
-
-
-unsigned
-util_bitmask_get_next_index(struct util_bitmask *bm,
- unsigned index)
-{
- unsigned word = index / UTIL_BITMASK_BITS_PER_WORD;
- unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD;
- util_bitmask_word mask = 1 << bit;
-
- if(index < bm->filled) {
- assert(bm->words[word] & mask);
- return index;
- }
-
- if(index >= bm->size) {
- return UTIL_BITMASK_INVALID_INDEX;
- }
-
- /* Do a linear search */
- while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) {
- while(bit < UTIL_BITMASK_BITS_PER_WORD) {
- if(bm->words[word] & mask) {
- if(index == bm->filled) {
- ++bm->filled;
- assert(bm->filled <= bm->size);
- }
- return index;
- }
- ++index;
- ++bit;
- mask <<= 1;
- }
- ++word;
- bit = 0;
- mask = 1;
- }
-
- return UTIL_BITMASK_INVALID_INDEX;
-}
-
-
-unsigned
-util_bitmask_get_first_index(struct util_bitmask *bm)
-{
- return util_bitmask_get_next_index(bm, 0);
-}
-
-
-void
-util_bitmask_destroy(struct util_bitmask *bm)
-{
- assert(bm);
-
- FREE(bm->words);
- FREE(bm);
-}
-
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Generic bitmask implementation. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_memory.h" +#include "util/u_bitmask.h" + + +typedef uint32_t util_bitmask_word; + + +#define UTIL_BITMASK_INITIAL_WORDS 16 +#define UTIL_BITMASK_BITS_PER_BYTE 8 +#define UTIL_BITMASK_BITS_PER_WORD (sizeof(util_bitmask_word) * UTIL_BITMASK_BITS_PER_BYTE) + + +struct util_bitmask +{ + util_bitmask_word *words; + + /** Number of bits we can currently hold */ + unsigned size; + + /** Number of consecutive bits set at the start of the bitmask */ + unsigned filled; +}; + + +struct util_bitmask * +util_bitmask_create(void) +{ + struct util_bitmask *bm; + + bm = MALLOC_STRUCT(util_bitmask); + if(!bm) + return NULL; + + bm->words = (util_bitmask_word *)CALLOC(UTIL_BITMASK_INITIAL_WORDS, sizeof(util_bitmask_word)); + if(!bm->words) { + FREE(bm); + return NULL; + } + + bm->size = UTIL_BITMASK_INITIAL_WORDS * UTIL_BITMASK_BITS_PER_WORD; + bm->filled = 0; + + return bm; +} + + +/** + * Resize the bitmask if necessary + */ +static INLINE boolean +util_bitmask_resize(struct util_bitmask *bm, + unsigned minimum_index) +{ + unsigned minimum_size = minimum_index + 1; + unsigned new_size; + util_bitmask_word *new_words; + + /* Check integer overflow */ + if(!minimum_size) + return FALSE; + + if(bm->size >= minimum_size) + return TRUE; + + assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0); + new_size = bm->size; + while(new_size < minimum_size) { + new_size *= 2; + /* Check integer overflow */ + if(new_size < bm->size) + return FALSE; + } + assert(new_size); + assert(new_size % UTIL_BITMASK_BITS_PER_WORD == 0); + + new_words = (util_bitmask_word *)REALLOC((void *)bm->words, + bm->size / UTIL_BITMASK_BITS_PER_BYTE, + new_size / UTIL_BITMASK_BITS_PER_BYTE); + if(!new_words) + return FALSE; + + memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD, + 0, + (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE); + + bm->size = new_size; + bm->words = new_words; + + return TRUE; +} + + +/** + * Lazily update the filled. + */ +static INLINE void +util_bitmask_filled_set(struct util_bitmask *bm, + unsigned index) +{ + assert(bm->filled <= bm->size); + assert(index < bm->size); + + if(index == bm->filled) { + ++bm->filled; + assert(bm->filled <= bm->size); + } +} + +static INLINE void +util_bitmask_filled_unset(struct util_bitmask *bm, + unsigned index) +{ + assert(bm->filled <= bm->size); + assert(index < bm->size); + + if(index < bm->filled) + bm->filled = index; +} + + +unsigned +util_bitmask_add(struct util_bitmask *bm) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + /* linear search for an empty index */ + word = bm->filled / UTIL_BITMASK_BITS_PER_WORD; + bit = bm->filled % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { + while(bit < UTIL_BITMASK_BITS_PER_WORD) { + if(!(bm->words[word] & mask)) + goto found; + ++bm->filled; + ++bit; + mask <<= 1; + } + ++word; + bit = 0; + mask = 1; + } +found: + + /* grow the bitmask if necessary */ + if(!util_bitmask_resize(bm, bm->filled)) + return UTIL_BITMASK_INVALID_INDEX; + + assert(!(bm->words[word] & mask)); + bm->words[word] |= mask; + + return bm->filled++; +} + + +unsigned +util_bitmask_set(struct util_bitmask *bm, + unsigned index) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + /* grow the bitmask if necessary */ + if(!util_bitmask_resize(bm, index)) + return UTIL_BITMASK_INVALID_INDEX; + + word = index / UTIL_BITMASK_BITS_PER_WORD; + bit = index % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + + bm->words[word] |= mask; + + util_bitmask_filled_set(bm, index); + + return index; +} + + +void +util_bitmask_clear(struct util_bitmask *bm, + unsigned index) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + if(index >= bm->size) + return; + + word = index / UTIL_BITMASK_BITS_PER_WORD; + bit = index % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + + bm->words[word] &= ~mask; + + util_bitmask_filled_unset(bm, index); +} + + +boolean +util_bitmask_get(struct util_bitmask *bm, + unsigned index) +{ + unsigned word = index / UTIL_BITMASK_BITS_PER_WORD; + unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD; + util_bitmask_word mask = 1 << bit; + + assert(bm); + + if(index < bm->filled) { + assert(bm->words[word] & mask); + return TRUE; + } + + if(index >= bm->size) + return FALSE; + + if(bm->words[word] & mask) { + util_bitmask_filled_set(bm, index); + return TRUE; + } + else + return FALSE; +} + + +unsigned +util_bitmask_get_next_index(struct util_bitmask *bm, + unsigned index) +{ + unsigned word = index / UTIL_BITMASK_BITS_PER_WORD; + unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD; + util_bitmask_word mask = 1 << bit; + + if(index < bm->filled) { + assert(bm->words[word] & mask); + return index; + } + + if(index >= bm->size) { + return UTIL_BITMASK_INVALID_INDEX; + } + + /* Do a linear search */ + while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { + while(bit < UTIL_BITMASK_BITS_PER_WORD) { + if(bm->words[word] & mask) { + if(index == bm->filled) { + ++bm->filled; + assert(bm->filled <= bm->size); + } + return index; + } + ++index; + ++bit; + mask <<= 1; + } + ++word; + bit = 0; + mask = 1; + } + + return UTIL_BITMASK_INVALID_INDEX; +} + + +unsigned +util_bitmask_get_first_index(struct util_bitmask *bm) +{ + return util_bitmask_get_next_index(bm, 0); +} + + +void +util_bitmask_destroy(struct util_bitmask *bm) +{ + assert(bm); + + FREE(bm->words); + FREE(bm); +} + diff --git a/mesalib/src/gallium/auxiliary/util/u_bitmask.h b/mesalib/src/gallium/auxiliary/util/u_bitmask.h index 179328ae9..98b85ddec 100644 --- a/mesalib/src/gallium/auxiliary/util/u_bitmask.h +++ b/mesalib/src/gallium/auxiliary/util/u_bitmask.h @@ -1,117 +1,117 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Generic bitmask.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#ifndef U_HANDLE_BITMASK_H_
-#define U_HANDLE_BITMASK_H_
-
-
-#include "pipe/p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define UTIL_BITMASK_INVALID_INDEX (~0U)
-
-
-/**
- * Abstract data type to represent arbitrary set of bits.
- */
-struct util_bitmask;
-
-
-struct util_bitmask *
-util_bitmask_create(void);
-
-
-/**
- * Search a cleared bit and set it.
- *
- * It searches for the first cleared bit.
- *
- * Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of
- * memory growing the bitmask.
- */
-unsigned
-util_bitmask_add(struct util_bitmask *bm);
-
-/**
- * Set a bit.
- *
- * Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of
- * memory growing the bitmask.
- */
-unsigned
-util_bitmask_set(struct util_bitmask *bm,
- unsigned index);
-
-void
-util_bitmask_clear(struct util_bitmask *bm,
- unsigned index);
-
-boolean
-util_bitmask_get(struct util_bitmask *bm,
- unsigned index);
-
-
-void
-util_bitmask_destroy(struct util_bitmask *bm);
-
-
-/**
- * Search for the first set bit.
- *
- * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found.
- */
-unsigned
-util_bitmask_get_first_index(struct util_bitmask *bm);
-
-
-/**
- * Search for the first set bit, starting from the giving index.
- *
- * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found.
- */
-unsigned
-util_bitmask_get_next_index(struct util_bitmask *bm,
- unsigned index);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_HANDLE_BITMASK_H_ */
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Generic bitmask. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#ifndef U_HANDLE_BITMASK_H_ +#define U_HANDLE_BITMASK_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define UTIL_BITMASK_INVALID_INDEX (~0U) + + +/** + * Abstract data type to represent arbitrary set of bits. + */ +struct util_bitmask; + + +struct util_bitmask * +util_bitmask_create(void); + + +/** + * Search a cleared bit and set it. + * + * It searches for the first cleared bit. + * + * Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of + * memory growing the bitmask. + */ +unsigned +util_bitmask_add(struct util_bitmask *bm); + +/** + * Set a bit. + * + * Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of + * memory growing the bitmask. + */ +unsigned +util_bitmask_set(struct util_bitmask *bm, + unsigned index); + +void +util_bitmask_clear(struct util_bitmask *bm, + unsigned index); + +boolean +util_bitmask_get(struct util_bitmask *bm, + unsigned index); + + +void +util_bitmask_destroy(struct util_bitmask *bm); + + +/** + * Search for the first set bit. + * + * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. + */ +unsigned +util_bitmask_get_first_index(struct util_bitmask *bm); + + +/** + * Search for the first set bit, starting from the giving index. + * + * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. + */ +unsigned +util_bitmask_get_next_index(struct util_bitmask *bm, + unsigned index); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HANDLE_BITMASK_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_box.h b/mesalib/src/gallium/auxiliary/util/u_box.h index f2f0829b5..0b28d0f12 100644 --- a/mesalib/src/gallium/auxiliary/util/u_box.h +++ b/mesalib/src/gallium/auxiliary/util/u_box.h @@ -1,80 +1,80 @@ -#ifndef UTIL_BOX_INLINES_H
-#define UTIL_BOX_INLINES_H
-
-#include "pipe/p_state.h"
-
-static INLINE
-void u_box_1d( unsigned x,
- unsigned w,
- struct pipe_box *box )
-{
- box->x = x;
- box->y = 0;
- box->z = 0;
- box->width = w;
- box->height = 1;
- box->depth = 1;
-}
-
-static INLINE
-void u_box_2d( unsigned x,
- unsigned y,
- unsigned w,
- unsigned h,
- struct pipe_box *box )
-{
- box->x = x;
- box->y = y;
- box->z = 0;
- box->width = w;
- box->height = h;
- box->depth = 1;
-}
-
-static INLINE
-void u_box_origin_2d( unsigned w,
- unsigned h,
- struct pipe_box *box )
-{
- box->x = 0;
- box->y = 0;
- box->z = 0;
- box->width = w;
- box->height = h;
- box->depth = 1;
-}
-
-static INLINE
-void u_box_2d_zslice( unsigned x,
- unsigned y,
- unsigned z,
- unsigned w,
- unsigned h,
- struct pipe_box *box )
-{
- box->x = x;
- box->y = y;
- box->z = z;
- box->width = w;
- box->height = h;
- box->depth = 1;
-}
-
-static INLINE
-void u_box_3d( unsigned x,
- unsigned y,
- unsigned z,
- unsigned w,
- unsigned h,
- unsigned d,
- struct pipe_box *box )
-{
- box->x = x;
- box->y = y;
- box->z = z;
- box->width = w;
- box->height = h;
- box->depth = d;
-}
-
-#endif
+#ifndef UTIL_BOX_INLINES_H +#define UTIL_BOX_INLINES_H + +#include "pipe/p_state.h" + +static INLINE +void u_box_1d( unsigned x, + unsigned w, + struct pipe_box *box ) +{ + box->x = x; + box->y = 0; + box->z = 0; + box->width = w; + box->height = 1; + box->depth = 1; +} + +static INLINE +void u_box_2d( unsigned x, + unsigned y, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_origin_2d( unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = 0; + box->y = 0; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_2d_zslice( unsigned x, + unsigned y, + unsigned z, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = z; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_3d( unsigned x, + unsigned y, + unsigned z, + unsigned w, + unsigned h, + unsigned d, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = z; + box->width = w; + box->height = h; + box->depth = d; +} + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_cache.c b/mesalib/src/gallium/auxiliary/util/u_cache.c index 215236818..df08ec302 100644 --- a/mesalib/src/gallium/auxiliary/util/u_cache.c +++ b/mesalib/src/gallium/auxiliary/util/u_cache.c @@ -1,351 +1,351 @@ -/**************************************************************************
- *
- * Copyright 2008 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Improved cache implementation.
- *
- * Fixed size array with linear probing on collision and LRU eviction
- * on full.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-
-#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "util/u_math.h"
-#include "util/u_memory.h"
-#include "util/u_cache.h"
-#include "util/u_simple_list.h"
-
-
-struct util_cache_entry
-{
- enum { EMPTY = 0, FILLED, DELETED } state;
- uint32_t hash;
-
- struct util_cache_entry *next;
- struct util_cache_entry *prev;
-
- void *key;
- void *value;
-
-#ifdef DEBUG
- unsigned count;
-#endif
-};
-
-
-struct util_cache
-{
- /** Hash function */
- uint32_t (*hash)(const void *key);
-
- /** Compare two keys */
- int (*compare)(const void *key1, const void *key2);
-
- /** Destroy a (key, value) pair */
- void (*destroy)(void *key, void *value);
-
- uint32_t size;
-
- struct util_cache_entry *entries;
-
- unsigned count;
- struct util_cache_entry lru;
-};
-
-static void
-ensure_sanity(const struct util_cache *cache);
-
-#define CACHE_DEFAULT_ALPHA 2
-
-struct util_cache *
-util_cache_create(uint32_t (*hash)(const void *key),
- int (*compare)(const void *key1, const void *key2),
- void (*destroy)(void *key, void *value),
- uint32_t size)
-{
- struct util_cache *cache;
-
- cache = CALLOC_STRUCT(util_cache);
- if(!cache)
- return NULL;
-
- cache->hash = hash;
- cache->compare = compare;
- cache->destroy = destroy;
-
- make_empty_list(&cache->lru);
-
- size *= CACHE_DEFAULT_ALPHA;
- cache->size = size;
-
- cache->entries = CALLOC(size, sizeof(struct util_cache_entry));
- if(!cache->entries) {
- FREE(cache);
- return NULL;
- }
-
- ensure_sanity(cache);
- return cache;
-}
-
-
-static struct util_cache_entry *
-util_cache_entry_get(struct util_cache *cache,
- uint32_t hash,
- const void *key)
-{
- struct util_cache_entry *first_unfilled = NULL;
- uint32_t index = hash % cache->size;
- uint32_t probe;
-
- /* Probe until we find either a matching FILLED entry or an EMPTY
- * slot (which has never been occupied).
- *
- * Deleted or non-matching slots are not indicative of completion
- * as a previous linear probe for the same key could have continued
- * past this point.
- */
- for (probe = 0; probe < cache->size; probe++) {
- uint32_t i = (index + probe) % cache->size;
- struct util_cache_entry *current = &cache->entries[i];
-
- if (current->state == FILLED) {
- if (current->hash == hash &&
- cache->compare(key, current->key) == 0)
- return current;
- }
- else {
- if (!first_unfilled)
- first_unfilled = current;
-
- if (current->state == EMPTY)
- return first_unfilled;
- }
- }
-
- return NULL;
-}
-
-static INLINE void
-util_cache_entry_destroy(struct util_cache *cache,
- struct util_cache_entry *entry)
-{
- void *key = entry->key;
- void *value = entry->value;
-
- entry->key = NULL;
- entry->value = NULL;
-
- if (entry->state == FILLED) {
- remove_from_list(entry);
- cache->count--;
-
- if(cache->destroy)
- cache->destroy(key, value);
-
- entry->state = DELETED;
- }
-}
-
-
-void
-util_cache_set(struct util_cache *cache,
- void *key,
- void *value)
-{
- struct util_cache_entry *entry;
- uint32_t hash = cache->hash(key);
-
- assert(cache);
- if (!cache)
- return;
-
- entry = util_cache_entry_get(cache, hash, key);
- if (!entry)
- entry = cache->lru.prev;
-
- if (cache->count >= cache->size / CACHE_DEFAULT_ALPHA)
- util_cache_entry_destroy(cache, cache->lru.prev);
-
- util_cache_entry_destroy(cache, entry);
-
-#ifdef DEBUG
- ++entry->count;
-#endif
-
- entry->key = key;
- entry->hash = hash;
- entry->value = value;
- entry->state = FILLED;
- insert_at_head(&cache->lru, entry);
- cache->count++;
-
- ensure_sanity(cache);
-}
-
-
-void *
-util_cache_get(struct util_cache *cache,
- const void *key)
-{
- struct util_cache_entry *entry;
- uint32_t hash = cache->hash(key);
-
- assert(cache);
- if (!cache)
- return NULL;
-
- entry = util_cache_entry_get(cache, hash, key);
- if (!entry)
- return NULL;
-
- if (entry->state == FILLED)
- move_to_head(&cache->lru, entry);
-
- return entry->value;
-}
-
-
-void
-util_cache_clear(struct util_cache *cache)
-{
- uint32_t i;
-
- assert(cache);
- if (!cache)
- return;
-
- for(i = 0; i < cache->size; ++i) {
- util_cache_entry_destroy(cache, &cache->entries[i]);
- cache->entries[i].state = EMPTY;
- }
-
- assert(cache->count == 0);
- assert(is_empty_list(&cache->lru));
- ensure_sanity(cache);
-}
-
-
-void
-util_cache_destroy(struct util_cache *cache)
-{
- assert(cache);
- if (!cache)
- return;
-
-#ifdef DEBUG
- if(cache->count >= 20*cache->size) {
- /* Normal approximation of the Poisson distribution */
- double mean = (double)cache->count/(double)cache->size;
- double stddev = sqrt(mean);
- unsigned i;
- for(i = 0; i < cache->size; ++i) {
- double z = fabs(cache->entries[i].count - mean)/stddev;
- /* This assert should not fail 99.9999998027% of the times, unless
- * the hash function is a poor one */
- assert(z <= 6.0);
- }
- }
-#endif
-
- util_cache_clear(cache);
-
- FREE(cache->entries);
- FREE(cache);
-}
-
-
-void
-util_cache_remove(struct util_cache *cache,
- const void *key)
-{
- struct util_cache_entry *entry;
- uint32_t hash;
-
- assert(cache);
- if (!cache)
- return;
-
- hash = cache->hash(key);
-
- entry = util_cache_entry_get(cache, hash, key);
- if (!entry)
- return;
-
- if (entry->state == FILLED)
- util_cache_entry_destroy(cache, entry);
-
- ensure_sanity(cache);
-}
-
-
-static void
-ensure_sanity(const struct util_cache *cache)
-{
-#ifdef DEBUG
- unsigned i, cnt = 0;
-
- assert(cache);
- for (i = 0; i < cache->size; i++) {
- struct util_cache_entry *header = &cache->entries[i];
-
- assert(header);
- assert(header->state == FILLED ||
- header->state == EMPTY ||
- header->state == DELETED);
- if (header->state == FILLED) {
- cnt++;
- assert(header->hash == cache->hash(header->key));
- }
- }
-
- assert(cnt == cache->count);
- assert(cache->size >= cnt);
-
- if (cache->count == 0) {
- assert (is_empty_list(&cache->lru));
- }
- else {
- struct util_cache_entry *header = cache->lru.next;
-
- assert (header);
- assert (!is_empty_list(&cache->lru));
-
- for (i = 0; i < cache->count; i++)
- header = header->next;
-
- assert(header == &cache->lru);
- }
-#endif
-
- (void)cache;
-}
+/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Improved cache implementation. + * + * Fixed size array with linear probing on collision and LRU eviction + * on full. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_cache.h" +#include "util/u_simple_list.h" + + +struct util_cache_entry +{ + enum { EMPTY = 0, FILLED, DELETED } state; + uint32_t hash; + + struct util_cache_entry *next; + struct util_cache_entry *prev; + + void *key; + void *value; + +#ifdef DEBUG + unsigned count; +#endif +}; + + +struct util_cache +{ + /** Hash function */ + uint32_t (*hash)(const void *key); + + /** Compare two keys */ + int (*compare)(const void *key1, const void *key2); + + /** Destroy a (key, value) pair */ + void (*destroy)(void *key, void *value); + + uint32_t size; + + struct util_cache_entry *entries; + + unsigned count; + struct util_cache_entry lru; +}; + +static void +ensure_sanity(const struct util_cache *cache); + +#define CACHE_DEFAULT_ALPHA 2 + +struct util_cache * +util_cache_create(uint32_t (*hash)(const void *key), + int (*compare)(const void *key1, const void *key2), + void (*destroy)(void *key, void *value), + uint32_t size) +{ + struct util_cache *cache; + + cache = CALLOC_STRUCT(util_cache); + if(!cache) + return NULL; + + cache->hash = hash; + cache->compare = compare; + cache->destroy = destroy; + + make_empty_list(&cache->lru); + + size *= CACHE_DEFAULT_ALPHA; + cache->size = size; + + cache->entries = CALLOC(size, sizeof(struct util_cache_entry)); + if(!cache->entries) { + FREE(cache); + return NULL; + } + + ensure_sanity(cache); + return cache; +} + + +static struct util_cache_entry * +util_cache_entry_get(struct util_cache *cache, + uint32_t hash, + const void *key) +{ + struct util_cache_entry *first_unfilled = NULL; + uint32_t index = hash % cache->size; + uint32_t probe; + + /* Probe until we find either a matching FILLED entry or an EMPTY + * slot (which has never been occupied). + * + * Deleted or non-matching slots are not indicative of completion + * as a previous linear probe for the same key could have continued + * past this point. + */ + for (probe = 0; probe < cache->size; probe++) { + uint32_t i = (index + probe) % cache->size; + struct util_cache_entry *current = &cache->entries[i]; + + if (current->state == FILLED) { + if (current->hash == hash && + cache->compare(key, current->key) == 0) + return current; + } + else { + if (!first_unfilled) + first_unfilled = current; + + if (current->state == EMPTY) + return first_unfilled; + } + } + + return NULL; +} + +static INLINE void +util_cache_entry_destroy(struct util_cache *cache, + struct util_cache_entry *entry) +{ + void *key = entry->key; + void *value = entry->value; + + entry->key = NULL; + entry->value = NULL; + + if (entry->state == FILLED) { + remove_from_list(entry); + cache->count--; + + if(cache->destroy) + cache->destroy(key, value); + + entry->state = DELETED; + } +} + + +void +util_cache_set(struct util_cache *cache, + void *key, + void *value) +{ + struct util_cache_entry *entry; + uint32_t hash = cache->hash(key); + + assert(cache); + if (!cache) + return; + + entry = util_cache_entry_get(cache, hash, key); + if (!entry) + entry = cache->lru.prev; + + if (cache->count >= cache->size / CACHE_DEFAULT_ALPHA) + util_cache_entry_destroy(cache, cache->lru.prev); + + util_cache_entry_destroy(cache, entry); + +#ifdef DEBUG + ++entry->count; +#endif + + entry->key = key; + entry->hash = hash; + entry->value = value; + entry->state = FILLED; + insert_at_head(&cache->lru, entry); + cache->count++; + + ensure_sanity(cache); +} + + +void * +util_cache_get(struct util_cache *cache, + const void *key) +{ + struct util_cache_entry *entry; + uint32_t hash = cache->hash(key); + + assert(cache); + if (!cache) + return NULL; + + entry = util_cache_entry_get(cache, hash, key); + if (!entry) + return NULL; + + if (entry->state == FILLED) + move_to_head(&cache->lru, entry); + + return entry->value; +} + + +void +util_cache_clear(struct util_cache *cache) +{ + uint32_t i; + + assert(cache); + if (!cache) + return; + + for(i = 0; i < cache->size; ++i) { + util_cache_entry_destroy(cache, &cache->entries[i]); + cache->entries[i].state = EMPTY; + } + + assert(cache->count == 0); + assert(is_empty_list(&cache->lru)); + ensure_sanity(cache); +} + + +void +util_cache_destroy(struct util_cache *cache) +{ + assert(cache); + if (!cache) + return; + +#ifdef DEBUG + if(cache->count >= 20*cache->size) { + /* Normal approximation of the Poisson distribution */ + double mean = (double)cache->count/(double)cache->size; + double stddev = sqrt(mean); + unsigned i; + for(i = 0; i < cache->size; ++i) { + double z = fabs(cache->entries[i].count - mean)/stddev; + /* This assert should not fail 99.9999998027% of the times, unless + * the hash function is a poor one */ + assert(z <= 6.0); + } + } +#endif + + util_cache_clear(cache); + + FREE(cache->entries); + FREE(cache); +} + + +void +util_cache_remove(struct util_cache *cache, + const void *key) +{ + struct util_cache_entry *entry; + uint32_t hash; + + assert(cache); + if (!cache) + return; + + hash = cache->hash(key); + + entry = util_cache_entry_get(cache, hash, key); + if (!entry) + return; + + if (entry->state == FILLED) + util_cache_entry_destroy(cache, entry); + + ensure_sanity(cache); +} + + +static void +ensure_sanity(const struct util_cache *cache) +{ +#ifdef DEBUG + unsigned i, cnt = 0; + + assert(cache); + for (i = 0; i < cache->size; i++) { + struct util_cache_entry *header = &cache->entries[i]; + + assert(header); + assert(header->state == FILLED || + header->state == EMPTY || + header->state == DELETED); + if (header->state == FILLED) { + cnt++; + assert(header->hash == cache->hash(header->key)); + } + } + + assert(cnt == cache->count); + assert(cache->size >= cnt); + + if (cache->count == 0) { + assert (is_empty_list(&cache->lru)); + } + else { + struct util_cache_entry *header = cache->lru.next; + + assert (header); + assert (!is_empty_list(&cache->lru)); + + for (i = 0; i < cache->count; i++) + header = header->next; + + assert(header == &cache->lru); + } +#endif + + (void)cache; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_cache.h b/mesalib/src/gallium/auxiliary/util/u_cache.h index f88ccb2b2..be3631b72 100644 --- a/mesalib/src/gallium/auxiliary/util/u_cache.h +++ b/mesalib/src/gallium/auxiliary/util/u_cache.h @@ -1,91 +1,91 @@ -/**************************************************************************
- *
- * Copyright 2008 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Simple cache.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#ifndef U_CACHE_H_
-#define U_CACHE_H_
-
-
-#include "pipe/p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
- * Least Recently Used (LRU) cache.
- */
-struct util_cache;
-
-
-/**
- * Create a cache.
- *
- * @param hash hash function
- * @param compare should return 0 for two equal keys
- * @param destroy destruction callback (optional)
- * @param size maximum number of entries
- */
-struct util_cache *
-util_cache_create(uint32_t (*hash)(const void *key),
- int (*compare)(const void *key1, const void *key2),
- void (*destroy)(void *key, void *value),
- uint32_t size);
-
-void
-util_cache_set(struct util_cache *cache,
- void *key,
- void *value);
-
-void *
-util_cache_get(struct util_cache *cache,
- const void *key);
-
-void
-util_cache_clear(struct util_cache *cache);
-
-void
-util_cache_destroy(struct util_cache *cache);
-
-void
-util_cache_remove(struct util_cache *cache,
- const void *key);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_CACHE_H_ */
+/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Simple cache. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#ifndef U_CACHE_H_ +#define U_CACHE_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Least Recently Used (LRU) cache. + */ +struct util_cache; + + +/** + * Create a cache. + * + * @param hash hash function + * @param compare should return 0 for two equal keys + * @param destroy destruction callback (optional) + * @param size maximum number of entries + */ +struct util_cache * +util_cache_create(uint32_t (*hash)(const void *key), + int (*compare)(const void *key1, const void *key2), + void (*destroy)(void *key, void *value), + uint32_t size); + +void +util_cache_set(struct util_cache *cache, + void *key, + void *value); + +void * +util_cache_get(struct util_cache *cache, + const void *key); + +void +util_cache_clear(struct util_cache *cache); + +void +util_cache_destroy(struct util_cache *cache); + +void +util_cache_remove(struct util_cache *cache, + const void *key); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_CACHE_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c index 28929d174..e0c8f73c7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c +++ b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c @@ -1,343 +1,343 @@ -/**************************************************************************
- *
- * Copyright 2008 Dennis Smit
- * 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
- * on 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
- * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * CPU feature detection.
- *
- * @author Dennis Smit
- * @author Based on the work of Eric Anholt <anholt@FreeBSD.org>
- */
-
-#include "pipe/p_config.h"
-
-#include "u_debug.h"
-#include "u_cpu_detect.h"
-
-#if defined(PIPE_ARCH_PPC)
-#if defined(PIPE_OS_APPLE)
-#include <sys/sysctl.h>
-#else
-#include <signal.h>
-#include <setjmp.h>
-#endif
-#endif
-
-#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD)
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <machine/cpu.h>
-#endif
-
-#if defined(PIPE_OS_FREEBSD)
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#endif
-
-#if defined(PIPE_OS_LINUX)
-#include <signal.h>
-#endif
-
-#ifdef PIPE_OS_UNIX
-#include <unistd.h>
-#endif
-
-#if defined(PIPE_OS_WINDOWS)
-#include <windows.h>
-#if defined(MSVC)
-#include <intrin.h>
-#endif
-#endif
-
-
-#ifdef DEBUG
-DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", FALSE)
-#endif
-
-
-struct util_cpu_caps util_cpu_caps;
-
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-static int has_cpuid(void);
-#endif
-
-
-#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE)
-static jmp_buf __lv_powerpc_jmpbuf;
-static volatile sig_atomic_t __lv_powerpc_canjump = 0;
-
-static void
-sigill_handler(int sig)
-{
- if (!__lv_powerpc_canjump) {
- signal (sig, SIG_DFL);
- raise (sig);
- }
-
- __lv_powerpc_canjump = 0;
- longjmp(__lv_powerpc_jmpbuf, 1);
-}
-#endif
-
-#if defined(PIPE_ARCH_PPC)
-static void
-check_os_altivec_support(void)
-{
-#if defined(PIPE_OS_APPLE)
- int sels[2] = {CTL_HW, HW_VECTORUNIT};
- int has_vu = 0;
- int len = sizeof (has_vu);
- int err;
-
- err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
-
- if (err == 0) {
- if (has_vu != 0) {
- util_cpu_caps.has_altivec = 1;
- }
- }
-#else /* !PIPE_OS_APPLE */
- /* not on Apple/Darwin, do it the brute-force way */
- /* this is borrowed from the libmpeg2 library */
- signal(SIGILL, sigill_handler);
- if (setjmp(__lv_powerpc_jmpbuf)) {
- signal(SIGILL, SIG_DFL);
- } else {
- __lv_powerpc_canjump = 1;
-
- __asm __volatile
- ("mtspr 256, %0\n\t"
- "vand %%v0, %%v0, %%v0"
- :
- : "r" (-1));
-
- signal(SIGILL, SIG_DFL);
- util_cpu_caps.has_altivec = 1;
- }
-#endif /* !PIPE_OS_APPLE */
-}
-#endif /* PIPE_ARCH_PPC */
-
-
-#if defined(PIPE_ARCH_X86) || defined (PIPE_ARCH_X86_64)
-static int has_cpuid(void)
-{
-#if defined(PIPE_ARCH_X86)
-#if defined(PIPE_OS_GCC)
- int a, c;
-
- __asm __volatile
- ("pushf\n"
- "popl %0\n"
- "movl %0, %1\n"
- "xorl $0x200000, %0\n"
- "push %0\n"
- "popf\n"
- "pushf\n"
- "popl %0\n"
- : "=a" (a), "=c" (c)
- :
- : "cc");
-
- return a != c;
-#else
- /* FIXME */
- return 1;
-#endif
-#elif defined(PIPE_ARCH_X86_64)
- return 1;
-#else
- return 0;
-#endif
-}
-
-
-/**
- * @sa cpuid.h included in gcc-4.3 onwards.
- * @sa http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
- */
-static INLINE void
-cpuid(uint32_t ax, uint32_t *p)
-{
-#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
- __asm __volatile (
- "xchgl %%ebx, %1\n\t"
- "cpuid\n\t"
- "xchgl %%ebx, %1"
- : "=a" (p[0]),
- "=S" (p[1]),
- "=c" (p[2]),
- "=d" (p[3])
- : "0" (ax)
- );
-#elif defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64)
- __asm __volatile (
- "cpuid\n\t"
- : "=a" (p[0]),
- "=b" (p[1]),
- "=c" (p[2]),
- "=d" (p[3])
- : "0" (ax)
- );
-#elif defined(PIPE_CC_MSVC)
- __cpuid(p, ax);
-#else
- p[0] = 0;
- p[1] = 0;
- p[2] = 0;
- p[3] = 0;
-#endif
-}
-#endif /* X86 or X86_64 */
-
-void
-util_cpu_detect(void)
-{
- static boolean util_cpu_detect_initialized = FALSE;
-
- if(util_cpu_detect_initialized)
- return;
-
- memset(&util_cpu_caps, 0, sizeof util_cpu_caps);
-
- /* Count the number of CPUs in system */
-#if defined(PIPE_OS_WINDOWS)
- {
- SYSTEM_INFO system_info;
- GetSystemInfo(&system_info);
- util_cpu_caps.nr_cpus = system_info.dwNumberOfProcessors;
- }
-#elif defined(PIPE_OS_UNIX) && defined(_SC_NPROCESSORS_ONLN)
- util_cpu_caps.nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
- if (util_cpu_caps.nr_cpus == -1)
- util_cpu_caps.nr_cpus = 1;
-#elif defined(PIPE_OS_BSD)
- {
- int mib[2], ncpu;
- int len;
-
- mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
-
- len = sizeof (ncpu);
- sysctl(mib, 2, &ncpu, &len, NULL, 0);
- util_cpu_caps.nr_cpus = ncpu;
- }
-#else
- util_cpu_caps.nr_cpus = 1;
-#endif
-
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
- if (has_cpuid()) {
- uint32_t regs[4];
- uint32_t regs2[4];
-
- util_cpu_caps.cacheline = 32;
-
- /* Get max cpuid level */
- cpuid(0x00000000, regs);
-
- if (regs[0] >= 0x00000001) {
- unsigned int cacheline;
-
- cpuid (0x00000001, regs2);
-
- util_cpu_caps.x86_cpu_type = (regs2[0] >> 8) & 0xf;
- if (util_cpu_caps.x86_cpu_type == 0xf)
- util_cpu_caps.x86_cpu_type = 8 + ((regs2[0] >> 20) & 255); /* use extended family (P4, IA64) */
-
- /* general feature flags */
- util_cpu_caps.has_tsc = (regs2[3] >> 8) & 1; /* 0x0000010 */
- util_cpu_caps.has_mmx = (regs2[3] >> 23) & 1; /* 0x0800000 */
- util_cpu_caps.has_sse = (regs2[3] >> 25) & 1; /* 0x2000000 */
- util_cpu_caps.has_sse2 = (regs2[3] >> 26) & 1; /* 0x4000000 */
- util_cpu_caps.has_sse3 = (regs2[2] >> 0) & 1; /* 0x0000001 */
- util_cpu_caps.has_ssse3 = (regs2[2] >> 9) & 1; /* 0x0000020 */
- util_cpu_caps.has_sse4_1 = (regs2[2] >> 19) & 1;
- util_cpu_caps.has_sse4_2 = (regs2[2] >> 20) & 1;
- util_cpu_caps.has_avx = (regs2[2] >> 28) & 1;
- util_cpu_caps.has_mmx2 = util_cpu_caps.has_sse; /* SSE cpus supports mmxext too */
-
- cacheline = ((regs2[1] >> 8) & 0xFF) * 8;
- if (cacheline > 0)
- util_cpu_caps.cacheline = cacheline;
- }
-
- cpuid(0x80000000, regs);
-
- if (regs[0] >= 0x80000001) {
-
- cpuid(0x80000001, regs2);
-
- util_cpu_caps.has_mmx |= (regs2[3] >> 23) & 1;
- util_cpu_caps.has_mmx2 |= (regs2[3] >> 22) & 1;
- util_cpu_caps.has_3dnow = (regs2[3] >> 31) & 1;
- util_cpu_caps.has_3dnow_ext = (regs2[3] >> 30) & 1;
- }
-
- if (regs[0] >= 0x80000006) {
- cpuid(0x80000006, regs2);
- util_cpu_caps.cacheline = regs2[2] & 0xFF;
- }
-
- if (!util_cpu_caps.has_sse) {
- util_cpu_caps.has_sse2 = 0;
- util_cpu_caps.has_sse3 = 0;
- util_cpu_caps.has_ssse3 = 0;
- util_cpu_caps.has_sse4_1 = 0;
- }
- }
-#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
-
-#if defined(PIPE_ARCH_PPC)
- check_os_altivec_support();
-#endif /* PIPE_ARCH_PPC */
-
-#ifdef DEBUG
- if (debug_get_option_dump_cpu()) {
- debug_printf("util_cpu_caps.nr_cpus = %u\n", util_cpu_caps.nr_cpus);
-
- debug_printf("util_cpu_caps.x86_cpu_type = %u\n", util_cpu_caps.x86_cpu_type);
- debug_printf("util_cpu_caps.cacheline = %u\n", util_cpu_caps.cacheline);
-
- debug_printf("util_cpu_caps.has_tsc = %u\n", util_cpu_caps.has_tsc);
- debug_printf("util_cpu_caps.has_mmx = %u\n", util_cpu_caps.has_mmx);
- debug_printf("util_cpu_caps.has_mmx2 = %u\n", util_cpu_caps.has_mmx2);
- debug_printf("util_cpu_caps.has_sse = %u\n", util_cpu_caps.has_sse);
- debug_printf("util_cpu_caps.has_sse2 = %u\n", util_cpu_caps.has_sse2);
- debug_printf("util_cpu_caps.has_sse3 = %u\n", util_cpu_caps.has_sse3);
- debug_printf("util_cpu_caps.has_ssse3 = %u\n", util_cpu_caps.has_ssse3);
- debug_printf("util_cpu_caps.has_sse4_1 = %u\n", util_cpu_caps.has_sse4_1);
- debug_printf("util_cpu_caps.has_sse4_2 = %u\n", util_cpu_caps.has_sse4_2);
- debug_printf("util_cpu_caps.has_avx = %u\n", util_cpu_caps.has_avx);
- debug_printf("util_cpu_caps.has_3dnow = %u\n", util_cpu_caps.has_3dnow);
- debug_printf("util_cpu_caps.has_3dnow_ext = %u\n", util_cpu_caps.has_3dnow_ext);
- debug_printf("util_cpu_caps.has_altivec = %u\n", util_cpu_caps.has_altivec);
- }
-#endif
-
- util_cpu_detect_initialized = TRUE;
-}
+/************************************************************************** + * + * Copyright 2008 Dennis Smit + * 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 + * on 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 + * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR 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. + * + **************************************************************************/ + +/** + * @file + * CPU feature detection. + * + * @author Dennis Smit + * @author Based on the work of Eric Anholt <anholt@FreeBSD.org> + */ + +#include "pipe/p_config.h" + +#include "u_debug.h" +#include "u_cpu_detect.h" + +#if defined(PIPE_ARCH_PPC) +#if defined(PIPE_OS_APPLE) +#include <sys/sysctl.h> +#else +#include <signal.h> +#include <setjmp.h> +#endif +#endif + +#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) +#include <sys/param.h> +#include <sys/sysctl.h> +#include <machine/cpu.h> +#endif + +#if defined(PIPE_OS_FREEBSD) +#include <sys/types.h> +#include <sys/sysctl.h> +#endif + +#if defined(PIPE_OS_LINUX) +#include <signal.h> +#endif + +#ifdef PIPE_OS_UNIX +#include <unistd.h> +#endif + +#if defined(PIPE_OS_WINDOWS) +#include <windows.h> +#if defined(MSVC) +#include <intrin.h> +#endif +#endif + + +#ifdef DEBUG +DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", FALSE) +#endif + + +struct util_cpu_caps util_cpu_caps; + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +static int has_cpuid(void); +#endif + + +#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) +static jmp_buf __lv_powerpc_jmpbuf; +static volatile sig_atomic_t __lv_powerpc_canjump = 0; + +static void +sigill_handler(int sig) +{ + if (!__lv_powerpc_canjump) { + signal (sig, SIG_DFL); + raise (sig); + } + + __lv_powerpc_canjump = 0; + longjmp(__lv_powerpc_jmpbuf, 1); +} +#endif + +#if defined(PIPE_ARCH_PPC) +static void +check_os_altivec_support(void) +{ +#if defined(PIPE_OS_APPLE) + int sels[2] = {CTL_HW, HW_VECTORUNIT}; + int has_vu = 0; + int len = sizeof (has_vu); + int err; + + err = sysctl(sels, 2, &has_vu, &len, NULL, 0); + + if (err == 0) { + if (has_vu != 0) { + util_cpu_caps.has_altivec = 1; + } + } +#else /* !PIPE_OS_APPLE */ + /* not on Apple/Darwin, do it the brute-force way */ + /* this is borrowed from the libmpeg2 library */ + signal(SIGILL, sigill_handler); + if (setjmp(__lv_powerpc_jmpbuf)) { + signal(SIGILL, SIG_DFL); + } else { + __lv_powerpc_canjump = 1; + + __asm __volatile + ("mtspr 256, %0\n\t" + "vand %%v0, %%v0, %%v0" + : + : "r" (-1)); + + signal(SIGILL, SIG_DFL); + util_cpu_caps.has_altivec = 1; + } +#endif /* !PIPE_OS_APPLE */ +} +#endif /* PIPE_ARCH_PPC */ + + +#if defined(PIPE_ARCH_X86) || defined (PIPE_ARCH_X86_64) +static int has_cpuid(void) +{ +#if defined(PIPE_ARCH_X86) +#if defined(PIPE_OS_GCC) + int a, c; + + __asm __volatile + ("pushf\n" + "popl %0\n" + "movl %0, %1\n" + "xorl $0x200000, %0\n" + "push %0\n" + "popf\n" + "pushf\n" + "popl %0\n" + : "=a" (a), "=c" (c) + : + : "cc"); + + return a != c; +#else + /* FIXME */ + return 1; +#endif +#elif defined(PIPE_ARCH_X86_64) + return 1; +#else + return 0; +#endif +} + + +/** + * @sa cpuid.h included in gcc-4.3 onwards. + * @sa http://msdn.microsoft.com/en-us/library/hskdteyh.aspx + */ +static INLINE void +cpuid(uint32_t ax, uint32_t *p) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + __asm __volatile ( + "xchgl %%ebx, %1\n\t" + "cpuid\n\t" + "xchgl %%ebx, %1" + : "=a" (p[0]), + "=S" (p[1]), + "=c" (p[2]), + "=d" (p[3]) + : "0" (ax) + ); +#elif defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64) + __asm __volatile ( + "cpuid\n\t" + : "=a" (p[0]), + "=b" (p[1]), + "=c" (p[2]), + "=d" (p[3]) + : "0" (ax) + ); +#elif defined(PIPE_CC_MSVC) + __cpuid(p, ax); +#else + p[0] = 0; + p[1] = 0; + p[2] = 0; + p[3] = 0; +#endif +} +#endif /* X86 or X86_64 */ + +void +util_cpu_detect(void) +{ + static boolean util_cpu_detect_initialized = FALSE; + + if(util_cpu_detect_initialized) + return; + + memset(&util_cpu_caps, 0, sizeof util_cpu_caps); + + /* Count the number of CPUs in system */ +#if defined(PIPE_OS_WINDOWS) + { + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + util_cpu_caps.nr_cpus = system_info.dwNumberOfProcessors; + } +#elif defined(PIPE_OS_UNIX) && defined(_SC_NPROCESSORS_ONLN) + util_cpu_caps.nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (util_cpu_caps.nr_cpus == -1) + util_cpu_caps.nr_cpus = 1; +#elif defined(PIPE_OS_BSD) + { + int mib[2], ncpu; + int len; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + + len = sizeof (ncpu); + sysctl(mib, 2, &ncpu, &len, NULL, 0); + util_cpu_caps.nr_cpus = ncpu; + } +#else + util_cpu_caps.nr_cpus = 1; +#endif + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + if (has_cpuid()) { + uint32_t regs[4]; + uint32_t regs2[4]; + + util_cpu_caps.cacheline = 32; + + /* Get max cpuid level */ + cpuid(0x00000000, regs); + + if (regs[0] >= 0x00000001) { + unsigned int cacheline; + + cpuid (0x00000001, regs2); + + util_cpu_caps.x86_cpu_type = (regs2[0] >> 8) & 0xf; + if (util_cpu_caps.x86_cpu_type == 0xf) + util_cpu_caps.x86_cpu_type = 8 + ((regs2[0] >> 20) & 255); /* use extended family (P4, IA64) */ + + /* general feature flags */ + util_cpu_caps.has_tsc = (regs2[3] >> 8) & 1; /* 0x0000010 */ + util_cpu_caps.has_mmx = (regs2[3] >> 23) & 1; /* 0x0800000 */ + util_cpu_caps.has_sse = (regs2[3] >> 25) & 1; /* 0x2000000 */ + util_cpu_caps.has_sse2 = (regs2[3] >> 26) & 1; /* 0x4000000 */ + util_cpu_caps.has_sse3 = (regs2[2] >> 0) & 1; /* 0x0000001 */ + util_cpu_caps.has_ssse3 = (regs2[2] >> 9) & 1; /* 0x0000020 */ + util_cpu_caps.has_sse4_1 = (regs2[2] >> 19) & 1; + util_cpu_caps.has_sse4_2 = (regs2[2] >> 20) & 1; + util_cpu_caps.has_avx = (regs2[2] >> 28) & 1; + util_cpu_caps.has_mmx2 = util_cpu_caps.has_sse; /* SSE cpus supports mmxext too */ + + cacheline = ((regs2[1] >> 8) & 0xFF) * 8; + if (cacheline > 0) + util_cpu_caps.cacheline = cacheline; + } + + cpuid(0x80000000, regs); + + if (regs[0] >= 0x80000001) { + + cpuid(0x80000001, regs2); + + util_cpu_caps.has_mmx |= (regs2[3] >> 23) & 1; + util_cpu_caps.has_mmx2 |= (regs2[3] >> 22) & 1; + util_cpu_caps.has_3dnow = (regs2[3] >> 31) & 1; + util_cpu_caps.has_3dnow_ext = (regs2[3] >> 30) & 1; + } + + if (regs[0] >= 0x80000006) { + cpuid(0x80000006, regs2); + util_cpu_caps.cacheline = regs2[2] & 0xFF; + } + + if (!util_cpu_caps.has_sse) { + util_cpu_caps.has_sse2 = 0; + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_ssse3 = 0; + util_cpu_caps.has_sse4_1 = 0; + } + } +#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */ + +#if defined(PIPE_ARCH_PPC) + check_os_altivec_support(); +#endif /* PIPE_ARCH_PPC */ + +#ifdef DEBUG + if (debug_get_option_dump_cpu()) { + debug_printf("util_cpu_caps.nr_cpus = %u\n", util_cpu_caps.nr_cpus); + + debug_printf("util_cpu_caps.x86_cpu_type = %u\n", util_cpu_caps.x86_cpu_type); + debug_printf("util_cpu_caps.cacheline = %u\n", util_cpu_caps.cacheline); + + debug_printf("util_cpu_caps.has_tsc = %u\n", util_cpu_caps.has_tsc); + debug_printf("util_cpu_caps.has_mmx = %u\n", util_cpu_caps.has_mmx); + debug_printf("util_cpu_caps.has_mmx2 = %u\n", util_cpu_caps.has_mmx2); + debug_printf("util_cpu_caps.has_sse = %u\n", util_cpu_caps.has_sse); + debug_printf("util_cpu_caps.has_sse2 = %u\n", util_cpu_caps.has_sse2); + debug_printf("util_cpu_caps.has_sse3 = %u\n", util_cpu_caps.has_sse3); + debug_printf("util_cpu_caps.has_ssse3 = %u\n", util_cpu_caps.has_ssse3); + debug_printf("util_cpu_caps.has_sse4_1 = %u\n", util_cpu_caps.has_sse4_1); + debug_printf("util_cpu_caps.has_sse4_2 = %u\n", util_cpu_caps.has_sse4_2); + debug_printf("util_cpu_caps.has_avx = %u\n", util_cpu_caps.has_avx); + debug_printf("util_cpu_caps.has_3dnow = %u\n", util_cpu_caps.has_3dnow); + debug_printf("util_cpu_caps.has_3dnow_ext = %u\n", util_cpu_caps.has_3dnow_ext); + debug_printf("util_cpu_caps.has_altivec = %u\n", util_cpu_caps.has_altivec); + } +#endif + + util_cpu_detect_initialized = TRUE; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.h b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.h index fa2f769ae..856e8d7a0 100644 --- a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.h +++ b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.h @@ -1,69 +1,69 @@ -/**************************************************************************
- *
- * Copyright 2008 Dennis Smit
- * 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
- * on 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
- * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR 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.
- *
- ***************************************************************************/
-
-/**
- * @file
- * CPU feature detection.
- *
- * @author Dennis Smit
- * @author Based on the work of Eric Anholt <anholt@FreeBSD.org>
- */
-
-#ifndef _UTIL_CPU_DETECT_H
-#define _UTIL_CPU_DETECT_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_config.h"
-
-struct util_cpu_caps {
- unsigned nr_cpus;
-
- /* Feature flags */
- int x86_cpu_type;
- unsigned cacheline;
-
- unsigned has_tsc:1;
- unsigned has_mmx:1;
- unsigned has_mmx2:1;
- unsigned has_sse:1;
- unsigned has_sse2:1;
- unsigned has_sse3:1;
- unsigned has_ssse3:1;
- unsigned has_sse4_1:1;
- unsigned has_sse4_2:1;
- unsigned has_avx:1;
- unsigned has_3dnow:1;
- unsigned has_3dnow_ext:1;
- unsigned has_altivec:1;
-};
-
-extern struct util_cpu_caps
-util_cpu_caps;
-
-void util_cpu_detect(void);
-
-
-#endif /* _UTIL_CPU_DETECT_H */
+/************************************************************************** + * + * Copyright 2008 Dennis Smit + * 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 + * on 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 + * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR 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. + * + ***************************************************************************/ + +/** + * @file + * CPU feature detection. + * + * @author Dennis Smit + * @author Based on the work of Eric Anholt <anholt@FreeBSD.org> + */ + +#ifndef _UTIL_CPU_DETECT_H +#define _UTIL_CPU_DETECT_H + +#include "pipe/p_compiler.h" +#include "pipe/p_config.h" + +struct util_cpu_caps { + unsigned nr_cpus; + + /* Feature flags */ + int x86_cpu_type; + unsigned cacheline; + + unsigned has_tsc:1; + unsigned has_mmx:1; + unsigned has_mmx2:1; + unsigned has_sse:1; + unsigned has_sse2:1; + unsigned has_sse3:1; + unsigned has_ssse3:1; + unsigned has_sse4_1:1; + unsigned has_sse4_2:1; + unsigned has_avx:1; + unsigned has_3dnow:1; + unsigned has_3dnow_ext:1; + unsigned has_altivec:1; +}; + +extern struct util_cpu_caps +util_cpu_caps; + +void util_cpu_detect(void); + + +#endif /* _UTIL_CPU_DETECT_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_stack.h b/mesalib/src/gallium/auxiliary/util/u_debug_stack.h index 1d9a4a843..f50f04e0f 100644 --- a/mesalib/src/gallium/auxiliary/util/u_debug_stack.h +++ b/mesalib/src/gallium/auxiliary/util/u_debug_stack.h @@ -1,65 +1,65 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-#ifndef U_DEBUG_STACK_H_
-#define U_DEBUG_STACK_H_
-
-
-/**
- * @file
- * Stack backtracing.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-struct debug_stack_frame
-{
- const void *function;
-};
-
-
-void
-debug_backtrace_capture(struct debug_stack_frame *backtrace,
- unsigned start_frame,
- unsigned nr_frames);
-
-void
-debug_backtrace_dump(const struct debug_stack_frame *backtrace,
- unsigned nr_frames);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_DEBUG_STACK_H_ */
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +#ifndef U_DEBUG_STACK_H_ +#define U_DEBUG_STACK_H_ + + +/** + * @file + * Stack backtracing. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct debug_stack_frame +{ + const void *function; +}; + + +void +debug_backtrace_capture(struct debug_stack_frame *backtrace, + unsigned start_frame, + unsigned nr_frames); + +void +debug_backtrace_dump(const struct debug_stack_frame *backtrace, + unsigned nr_frames); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_STACK_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c index b2f762c66..bae9be87a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c +++ b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.c @@ -1,243 +1,243 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Symbol lookup.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#include "pipe/p_compiler.h"
-#include "os/os_thread.h"
-#include "u_string.h"
-
-#include "u_debug.h"
-#include "u_debug_symbol.h"
-#include "u_hash_table.h"
-
-#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86)
-
-#include <windows.h>
-#include <stddef.h>
-
-#include "dbghelp.h"
-
-
-static BOOL bSymInitialized = FALSE;
-
-static HMODULE hModule_Dbghelp = NULL;
-
-
-static
-FARPROC WINAPI __GetProcAddress(LPCSTR lpProcName)
-{
-#ifdef PIPE_CC_GCC
- if (!hModule_Dbghelp) {
- /*
- * bfdhelp.dll is a dbghelp.dll look-alike replacement, which is able to
- * understand MinGW symbols using BFD library. It is available from
- * http://people.freedesktop.org/~jrfonseca/bfdhelp/ for now.
- */
- hModule_Dbghelp = LoadLibraryA("bfdhelp.dll");
- }
-#endif
-
- if (!hModule_Dbghelp) {
- hModule_Dbghelp = LoadLibraryA("dbghelp.dll");
- if (!hModule_Dbghelp) {
- return NULL;
- }
- }
-
- return GetProcAddress(hModule_Dbghelp, lpProcName);
-}
-
-
-typedef BOOL (WINAPI *PFNSYMINITIALIZE)(HANDLE, LPSTR, BOOL);
-static PFNSYMINITIALIZE pfnSymInitialize = NULL;
-
-static
-BOOL WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess)
-{
- if(
- (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) __GetProcAddress("SymInitialize")))
- )
- return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess);
- else
- return FALSE;
-}
-
-typedef DWORD (WINAPI *PFNSYMSETOPTIONS)(DWORD);
-static PFNSYMSETOPTIONS pfnSymSetOptions = NULL;
-
-static
-DWORD WINAPI j_SymSetOptions(DWORD SymOptions)
-{
- if(
- (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) __GetProcAddress("SymSetOptions")))
- )
- return pfnSymSetOptions(SymOptions);
- else
- return FALSE;
-}
-
-typedef BOOL (WINAPI *PFNSYMGETSYMFROMADDR)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO);
-static PFNSYMGETSYMFROMADDR pfnSymFromAddr = NULL;
-
-static
-BOOL WINAPI j_SymFromAddr(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol)
-{
- if(
- (pfnSymFromAddr || (pfnSymFromAddr = (PFNSYMGETSYMFROMADDR) __GetProcAddress("SymFromAddr")))
- )
- return pfnSymFromAddr(hProcess, Address, Displacement, Symbol);
- else
- return FALSE;
-}
-
-
-static INLINE void
-debug_symbol_name_dbghelp(const void *addr, char* buf, unsigned size)
-{
- HANDLE hProcess;
- BYTE symbolBuffer[1024];
- PSYMBOL_INFO pSymbol = (PSYMBOL_INFO) symbolBuffer;
- DWORD64 dwDisplacement = 0; /* Displacement of the input address, relative to the start of the symbol */
-
- hProcess = GetCurrentProcess();
-
- memset(pSymbol, 0, sizeof *pSymbol);
- pSymbol->SizeOfStruct = sizeof(symbolBuffer);
- pSymbol->MaxNameLen = sizeof(symbolBuffer) - offsetof(SYMBOL_INFO, Name);
-
- if(!bSymInitialized) {
- j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES);
- if(j_SymInitialize(hProcess, NULL, TRUE))
- bSymInitialized = TRUE;
- }
-
- if(!j_SymFromAddr(hProcess, (DWORD64)(uintptr_t)addr, &dwDisplacement, pSymbol))
- buf[0] = 0;
- else
- {
- strncpy(buf, pSymbol->Name, size);
- buf[size - 1] = 0;
- }
-}
-#endif
-
-#ifdef __GLIBC__
-#include <execinfo.h>
-
-/* This can only provide dynamic symbols, or binary offsets into a file.
- *
- * To fix this, post-process the output with tools/addr2line.sh
- */
-static INLINE void
-debug_symbol_name_glibc(const void *addr, char* buf, unsigned size)
-{
- char** syms = backtrace_symbols((void**)&addr, 1);
- strncpy(buf, syms[0], size);
- buf[size - 1] = 0;
- free(syms);
-}
-#endif
-
-void
-debug_symbol_name(const void *addr, char* buf, unsigned size)
-{
-#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86)
- debug_symbol_name_dbghelp(addr, buf, size);
- if(buf[0])
- return;
-#endif
-
-#ifdef __GLIBC__
- debug_symbol_name_glibc(addr, buf, size);
- if(buf[0])
- return;
-#endif
-
- util_snprintf(buf, size, "%p", addr);
- buf[size - 1] = 0;
-}
-
-void
-debug_symbol_print(const void *addr)
-{
- char buf[1024];
- debug_symbol_name(addr, buf, sizeof(buf));
- debug_printf("\t%s\n", buf);
-}
-
-struct util_hash_table* symbols_hash;
-pipe_static_mutex(symbols_mutex);
-
-static unsigned hash_ptr(void* p)
-{
- return (unsigned)(uintptr_t)p;
-}
-
-static int compare_ptr(void* a, void* b)
-{
- if(a == b)
- return 0;
- else if(a < b)
- return -1;
- else
- return 1;
-}
-
-const char*
-debug_symbol_name_cached(const void *addr)
-{
- const char* name;
-#ifdef PIPE_SUBSYSTEM_WINDOWS_USER
- static boolean first = TRUE;
-
- if (first) {
- pipe_mutex_init(symbols_mutex);
- first = FALSE;
- }
-#endif
-
- pipe_mutex_lock(symbols_mutex);
- if(!symbols_hash)
- symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
- name = util_hash_table_get(symbols_hash, (void*)addr);
- if(!name)
- {
- char buf[1024];
- debug_symbol_name(addr, buf, sizeof(buf));
- name = strdup(buf);
-
- util_hash_table_set(symbols_hash, (void*)addr, (void*)name);
- }
- pipe_mutex_unlock(symbols_mutex);
- return name;
-}
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Symbol lookup. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#include "pipe/p_compiler.h" +#include "os/os_thread.h" +#include "u_string.h" + +#include "u_debug.h" +#include "u_debug_symbol.h" +#include "u_hash_table.h" + +#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86) + +#include <windows.h> +#include <stddef.h> + +#include "dbghelp.h" + + +static BOOL bSymInitialized = FALSE; + +static HMODULE hModule_Dbghelp = NULL; + + +static +FARPROC WINAPI __GetProcAddress(LPCSTR lpProcName) +{ +#ifdef PIPE_CC_GCC + if (!hModule_Dbghelp) { + /* + * bfdhelp.dll is a dbghelp.dll look-alike replacement, which is able to + * understand MinGW symbols using BFD library. It is available from + * http://people.freedesktop.org/~jrfonseca/bfdhelp/ for now. + */ + hModule_Dbghelp = LoadLibraryA("bfdhelp.dll"); + } +#endif + + if (!hModule_Dbghelp) { + hModule_Dbghelp = LoadLibraryA("dbghelp.dll"); + if (!hModule_Dbghelp) { + return NULL; + } + } + + return GetProcAddress(hModule_Dbghelp, lpProcName); +} + + +typedef BOOL (WINAPI *PFNSYMINITIALIZE)(HANDLE, LPSTR, BOOL); +static PFNSYMINITIALIZE pfnSymInitialize = NULL; + +static +BOOL WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess) +{ + if( + (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) __GetProcAddress("SymInitialize"))) + ) + return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess); + else + return FALSE; +} + +typedef DWORD (WINAPI *PFNSYMSETOPTIONS)(DWORD); +static PFNSYMSETOPTIONS pfnSymSetOptions = NULL; + +static +DWORD WINAPI j_SymSetOptions(DWORD SymOptions) +{ + if( + (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) __GetProcAddress("SymSetOptions"))) + ) + return pfnSymSetOptions(SymOptions); + else + return FALSE; +} + +typedef BOOL (WINAPI *PFNSYMGETSYMFROMADDR)(HANDLE, DWORD64, PDWORD64, PSYMBOL_INFO); +static PFNSYMGETSYMFROMADDR pfnSymFromAddr = NULL; + +static +BOOL WINAPI j_SymFromAddr(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol) +{ + if( + (pfnSymFromAddr || (pfnSymFromAddr = (PFNSYMGETSYMFROMADDR) __GetProcAddress("SymFromAddr"))) + ) + return pfnSymFromAddr(hProcess, Address, Displacement, Symbol); + else + return FALSE; +} + + +static INLINE void +debug_symbol_name_dbghelp(const void *addr, char* buf, unsigned size) +{ + HANDLE hProcess; + BYTE symbolBuffer[1024]; + PSYMBOL_INFO pSymbol = (PSYMBOL_INFO) symbolBuffer; + DWORD64 dwDisplacement = 0; /* Displacement of the input address, relative to the start of the symbol */ + + hProcess = GetCurrentProcess(); + + memset(pSymbol, 0, sizeof *pSymbol); + pSymbol->SizeOfStruct = sizeof(symbolBuffer); + pSymbol->MaxNameLen = sizeof(symbolBuffer) - offsetof(SYMBOL_INFO, Name); + + if(!bSymInitialized) { + j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES); + if(j_SymInitialize(hProcess, NULL, TRUE)) + bSymInitialized = TRUE; + } + + if(!j_SymFromAddr(hProcess, (DWORD64)(uintptr_t)addr, &dwDisplacement, pSymbol)) + buf[0] = 0; + else + { + strncpy(buf, pSymbol->Name, size); + buf[size - 1] = 0; + } +} +#endif + +#ifdef __GLIBC__ +#include <execinfo.h> + +/* This can only provide dynamic symbols, or binary offsets into a file. + * + * To fix this, post-process the output with tools/addr2line.sh + */ +static INLINE void +debug_symbol_name_glibc(const void *addr, char* buf, unsigned size) +{ + char** syms = backtrace_symbols((void**)&addr, 1); + strncpy(buf, syms[0], size); + buf[size - 1] = 0; + free(syms); +} +#endif + +void +debug_symbol_name(const void *addr, char* buf, unsigned size) +{ +#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86) + debug_symbol_name_dbghelp(addr, buf, size); + if(buf[0]) + return; +#endif + +#ifdef __GLIBC__ + debug_symbol_name_glibc(addr, buf, size); + if(buf[0]) + return; +#endif + + util_snprintf(buf, size, "%p", addr); + buf[size - 1] = 0; +} + +void +debug_symbol_print(const void *addr) +{ + char buf[1024]; + debug_symbol_name(addr, buf, sizeof(buf)); + debug_printf("\t%s\n", buf); +} + +struct util_hash_table* symbols_hash; +pipe_static_mutex(symbols_mutex); + +static unsigned hash_ptr(void* p) +{ + return (unsigned)(uintptr_t)p; +} + +static int compare_ptr(void* a, void* b) +{ + if(a == b) + return 0; + else if(a < b) + return -1; + else + return 1; +} + +const char* +debug_symbol_name_cached(const void *addr) +{ + const char* name; +#ifdef PIPE_SUBSYSTEM_WINDOWS_USER + static boolean first = TRUE; + + if (first) { + pipe_mutex_init(symbols_mutex); + first = FALSE; + } +#endif + + pipe_mutex_lock(symbols_mutex); + if(!symbols_hash) + symbols_hash = util_hash_table_create(hash_ptr, compare_ptr); + name = util_hash_table_get(symbols_hash, (void*)addr); + if(!name) + { + char buf[1024]; + debug_symbol_name(addr, buf, sizeof(buf)); + name = strdup(buf); + + util_hash_table_set(symbols_hash, (void*)addr, (void*)name); + } + pipe_mutex_unlock(symbols_mutex); + return name; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.h b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.h index 74285e064..b247706c2 100644 --- a/mesalib/src/gallium/auxiliary/util/u_debug_symbol.h +++ b/mesalib/src/gallium/auxiliary/util/u_debug_symbol.h @@ -1,58 +1,58 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-#ifndef U_DEBUG_SYMBOL_H_
-#define U_DEBUG_SYMBOL_H_
-
-
-/**
- * @file
- * Symbol lookup.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-void
-debug_symbol_name(const void *addr, char* buf, unsigned size);
-
-const char*
-debug_symbol_name_cached(const void *addr);
-
-void
-debug_symbol_print(const void *addr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_DEBUG_SYMBOL_H_ */
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +#ifndef U_DEBUG_SYMBOL_H_ +#define U_DEBUG_SYMBOL_H_ + + +/** + * @file + * Symbol lookup. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void +debug_symbol_name(const void *addr, char* buf, unsigned size); + +const char* +debug_symbol_name_cached(const void *addr); + +void +debug_symbol_print(const void *addr); + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_SYMBOL_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_dirty_flags.h b/mesalib/src/gallium/auxiliary/util/u_dirty_flags.h index 9b509d591..40539f0b0 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dirty_flags.h +++ b/mesalib/src/gallium/auxiliary/util/u_dirty_flags.h @@ -1,32 +1,32 @@ -#ifndef U_DIRTY_FLAGS_H
-#define U_DIRTY_FLAGS_H
-
-/* Here's a convenient list of dirty flags to use in a driver. Either
- * include it directly or use it as a starting point for your own
- * list.
- */
-#define U_NEW_VIEWPORT 0x1
-#define U_NEW_RASTERIZER 0x2
-#define U_NEW_FS 0x4
-#define U_NEW_FS_CONSTANTS 0x8
-#define U_NEW_FS_SAMPLER_VIEW 0x10
-#define U_NEW_FS_SAMPLER_STATES 0x20
-#define U_NEW_VS 0x40
-#define U_NEW_VS_CONSTANTS 0x80
-#define U_NEW_VS_SAMPLER_VIEW 0x100
-#define U_NEW_VS_SAMPLER_STATES 0x200
-#define U_NEW_BLEND 0x400
-#define U_NEW_CLIP 0x800
-#define U_NEW_SCISSOR 0x1000
-#define U_NEW_POLYGON_STIPPLE 0x2000
-#define U_NEW_FRAMEBUFFER 0x4000
-#define U_NEW_VERTEX_ELEMENTS 0x8000
-#define U_NEW_VERTEX_BUFFER 0x10000
-#define U_NEW_QUERY 0x20000
-#define U_NEW_DEPTH_STENCIL 0x40000
-#define U_NEW_GS 0x80000
-#define U_NEW_GS_CONSTANTS 0x100000
-#define U_NEW_GS_SAMPLER_VIEW 0x200000
-#define U_NEW_GS_SAMPLER_STATES 0x400000
-
-#endif
+#ifndef U_DIRTY_FLAGS_H +#define U_DIRTY_FLAGS_H + +/* Here's a convenient list of dirty flags to use in a driver. Either + * include it directly or use it as a starting point for your own + * list. + */ +#define U_NEW_VIEWPORT 0x1 +#define U_NEW_RASTERIZER 0x2 +#define U_NEW_FS 0x4 +#define U_NEW_FS_CONSTANTS 0x8 +#define U_NEW_FS_SAMPLER_VIEW 0x10 +#define U_NEW_FS_SAMPLER_STATES 0x20 +#define U_NEW_VS 0x40 +#define U_NEW_VS_CONSTANTS 0x80 +#define U_NEW_VS_SAMPLER_VIEW 0x100 +#define U_NEW_VS_SAMPLER_STATES 0x200 +#define U_NEW_BLEND 0x400 +#define U_NEW_CLIP 0x800 +#define U_NEW_SCISSOR 0x1000 +#define U_NEW_POLYGON_STIPPLE 0x2000 +#define U_NEW_FRAMEBUFFER 0x4000 +#define U_NEW_VERTEX_ELEMENTS 0x8000 +#define U_NEW_VERTEX_BUFFER 0x10000 +#define U_NEW_QUERY 0x20000 +#define U_NEW_DEPTH_STENCIL 0x40000 +#define U_NEW_GS 0x80000 +#define U_NEW_GS_CONSTANTS 0x100000 +#define U_NEW_GS_SAMPLER_VIEW 0x200000 +#define U_NEW_GS_SAMPLER_STATES 0x400000 + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_dirty_surfaces.h b/mesalib/src/gallium/auxiliary/util/u_dirty_surfaces.h index bbc3179f0..f3618d9be 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dirty_surfaces.h +++ b/mesalib/src/gallium/auxiliary/util/u_dirty_surfaces.h @@ -1,119 +1,119 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#ifndef U_DIRTY_SURFACES_H_
-#define U_DIRTY_SURFACES_H_
-
-#include "pipe/p_state.h"
-
-#include "util/u_double_list.h"
-#include "util/u_math.h"
-
-struct pipe_context;
-
-typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *);
-
-struct util_dirty_surfaces
-{
- struct list_head dirty_list;
-};
-
-struct util_dirty_surface
-{
- struct pipe_surface base;
- struct list_head dirty_list;
-};
-
-static INLINE void
-util_dirty_surfaces_init(struct util_dirty_surfaces *ds)
-{
- LIST_INITHEAD(&ds->dirty_list);
-}
-
-static INLINE void
-util_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush)
-{
- struct list_head *p, *next;
- for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next)
- {
- struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);
- next = p->next;
-
- flush(pipe, &ds->base);
- }
-}
-
-static INLINE void
-util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, unsigned first, unsigned last, util_dirty_surface_flush_t flush)
-{
- struct list_head *p, *next;
- if(first > last)
- return;
- for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next)
- {
- struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);
- next = p->next;
-
- if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last)
- flush(pipe, &ds->base);
- }
-}
-
-static INLINE void
-util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush)
-{
- if(!LIST_IS_EMPTY(&dss->dirty_list))
- util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level,
- MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush);
-}
-
-static INLINE void
-util_dirty_surface_init(struct util_dirty_surface *ds)
-{
- LIST_INITHEAD(&ds->dirty_list);
-}
-
-static INLINE boolean
-util_dirty_surface_is_dirty(struct util_dirty_surface *ds)
-{
- return !LIST_IS_EMPTY(&ds->dirty_list);
-}
-
-static INLINE void
-util_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds)
-{
- if(LIST_IS_EMPTY(&ds->dirty_list))
- LIST_ADDTAIL(&ds->dirty_list, &dss->dirty_list);
-}
-
-static INLINE void
-util_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds)
-{
- if(!LIST_IS_EMPTY(&ds->dirty_list))
- LIST_DELINIT(&ds->dirty_list);
-}
-
-#endif
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#ifndef U_DIRTY_SURFACES_H_ +#define U_DIRTY_SURFACES_H_ + +#include "pipe/p_state.h" + +#include "util/u_double_list.h" +#include "util/u_math.h" + +struct pipe_context; + +typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *); + +struct util_dirty_surfaces +{ + struct list_head dirty_list; +}; + +struct util_dirty_surface +{ + struct pipe_surface base; + struct list_head dirty_list; +}; + +static INLINE void +util_dirty_surfaces_init(struct util_dirty_surfaces *ds) +{ + LIST_INITHEAD(&ds->dirty_list); +} + +static INLINE void +util_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush) +{ + struct list_head *p, *next; + for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) + { + struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); + next = p->next; + + flush(pipe, &ds->base); + } +} + +static INLINE void +util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, unsigned first, unsigned last, util_dirty_surface_flush_t flush) +{ + struct list_head *p, *next; + if(first > last) + return; + for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) + { + struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); + next = p->next; + + if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last) + flush(pipe, &ds->base); + } +} + +static INLINE void +util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush) +{ + if(!LIST_IS_EMPTY(&dss->dirty_list)) + util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level, + MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush); +} + +static INLINE void +util_dirty_surface_init(struct util_dirty_surface *ds) +{ + LIST_INITHEAD(&ds->dirty_list); +} + +static INLINE boolean +util_dirty_surface_is_dirty(struct util_dirty_surface *ds) +{ + return !LIST_IS_EMPTY(&ds->dirty_list); +} + +static INLINE void +util_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) +{ + if(LIST_IS_EMPTY(&ds->dirty_list)) + LIST_ADDTAIL(&ds->dirty_list, &dss->dirty_list); +} + +static INLINE void +util_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) +{ + if(!LIST_IS_EMPTY(&ds->dirty_list)) + LIST_DELINIT(&ds->dirty_list); +} + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_dl.c b/mesalib/src/gallium/auxiliary/util/u_dl.c index dcdb7ebdd..aca435d6c 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dl.c +++ b/mesalib/src/gallium/auxiliary/util/u_dl.c @@ -1,94 +1,94 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * Copyright 1999-2008 Brian Paul
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#include "pipe/p_config.h"
-#include "pipe/p_compiler.h"
-
-#if defined(PIPE_OS_UNIX)
-#include <dlfcn.h>
-#endif
-#if defined(PIPE_OS_WINDOWS)
-#include <windows.h>
-#endif
-
-#include "u_dl.h"
-#include "u_pointer.h"
-
-
-struct util_dl_library *
-util_dl_open(const char *filename)
-{
-#if defined(PIPE_OS_UNIX)
- return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
-#elif defined(PIPE_OS_WINDOWS)
- return (struct util_dl_library *)LoadLibraryA(filename);
-#else
- return NULL;
-#endif
-}
-
-
-util_dl_proc
-util_dl_get_proc_address(struct util_dl_library *library,
- const char *procname)
-{
-#if defined(PIPE_OS_UNIX)
- return (util_dl_proc) pointer_to_func(dlsym((void *)library, procname));
-#elif defined(PIPE_OS_WINDOWS)
- return (util_dl_proc)GetProcAddress((HMODULE)library, procname);
-#else
- return (util_dl_proc)NULL;
-#endif
-}
-
-
-void
-util_dl_close(struct util_dl_library *library)
-{
-#if defined(PIPE_OS_UNIX)
- dlclose((void *)library);
-#elif defined(PIPE_OS_WINDOWS)
- FreeLibrary((HMODULE)library);
-#else
- (void)library;
-#endif
-}
-
-
-const char *
-util_dl_error(void)
-{
-#if defined(PIPE_OS_UNIX)
- return dlerror();
-#elif defined(PIPE_OS_WINDOWS)
- return "unknown error";
-#else
- return "unknown error";
-#endif
-}
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 1999-2008 Brian Paul + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#include "pipe/p_config.h" +#include "pipe/p_compiler.h" + +#if defined(PIPE_OS_UNIX) +#include <dlfcn.h> +#endif +#if defined(PIPE_OS_WINDOWS) +#include <windows.h> +#endif + +#include "u_dl.h" +#include "u_pointer.h" + + +struct util_dl_library * +util_dl_open(const char *filename) +{ +#if defined(PIPE_OS_UNIX) + return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); +#elif defined(PIPE_OS_WINDOWS) + return (struct util_dl_library *)LoadLibraryA(filename); +#else + return NULL; +#endif +} + + +util_dl_proc +util_dl_get_proc_address(struct util_dl_library *library, + const char *procname) +{ +#if defined(PIPE_OS_UNIX) + return (util_dl_proc) pointer_to_func(dlsym((void *)library, procname)); +#elif defined(PIPE_OS_WINDOWS) + return (util_dl_proc)GetProcAddress((HMODULE)library, procname); +#else + return (util_dl_proc)NULL; +#endif +} + + +void +util_dl_close(struct util_dl_library *library) +{ +#if defined(PIPE_OS_UNIX) + dlclose((void *)library); +#elif defined(PIPE_OS_WINDOWS) + FreeLibrary((HMODULE)library); +#else + (void)library; +#endif +} + + +const char * +util_dl_error(void) +{ +#if defined(PIPE_OS_UNIX) + return dlerror(); +#elif defined(PIPE_OS_WINDOWS) + return "unknown error"; +#else + return "unknown error"; +#endif +} diff --git a/mesalib/src/gallium/auxiliary/util/u_dl.h b/mesalib/src/gallium/auxiliary/util/u_dl.h index b24183494..80a00ed67 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dl.h +++ b/mesalib/src/gallium/auxiliary/util/u_dl.h @@ -1,83 +1,83 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#ifndef U_DL_H_
-#define U_DL_H_
-
-
-#include "pipe/p_config.h"
-
-
-#if defined(PIPE_OS_WINDOWS)
-# define UTIL_DL_EXT ".dll"
-# define UTIL_DL_PREFIX ""
-#elif defined(PIPE_OS_APPLE)
-# define UTIL_DL_EXT ".dylib"
-# define UTIL_DL_PREFIX "lib"
-#else
-# define UTIL_DL_EXT ".so"
-# define UTIL_DL_PREFIX "lib"
-#endif
-
-
-struct util_dl_library;
-
-
-typedef void (*util_dl_proc)(void);
-
-
-/**
- * Open a library dynamically.
- */
-struct util_dl_library *
-util_dl_open(const char *filename);
-
-
-/**
- * Lookup a function in a library.
- */
-util_dl_proc
-util_dl_get_proc_address(struct util_dl_library *library,
- const char *procname);
-
-
-/**
- * Close a library.
- */
-void
-util_dl_close(struct util_dl_library *library);
-
-
-/**
- * Return most recent error message.
- */
-const char *
-util_dl_error(void);
-
-
-#endif /* U_DL_H_ */
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_DL_H_ +#define U_DL_H_ + + +#include "pipe/p_config.h" + + +#if defined(PIPE_OS_WINDOWS) +# define UTIL_DL_EXT ".dll" +# define UTIL_DL_PREFIX "" +#elif defined(PIPE_OS_APPLE) +# define UTIL_DL_EXT ".dylib" +# define UTIL_DL_PREFIX "lib" +#else +# define UTIL_DL_EXT ".so" +# define UTIL_DL_PREFIX "lib" +#endif + + +struct util_dl_library; + + +typedef void (*util_dl_proc)(void); + + +/** + * Open a library dynamically. + */ +struct util_dl_library * +util_dl_open(const char *filename); + + +/** + * Lookup a function in a library. + */ +util_dl_proc +util_dl_get_proc_address(struct util_dl_library *library, + const char *procname); + + +/** + * Close a library. + */ +void +util_dl_close(struct util_dl_library *library); + + +/** + * Return most recent error message. + */ +const char * +util_dl_error(void); + + +#endif /* U_DL_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_dump_defines.c b/mesalib/src/gallium/auxiliary/util/u_dump_defines.c index 0a00195aa..692d4447c 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dump_defines.c +++ b/mesalib/src/gallium/auxiliary/util/u_dump_defines.c @@ -1,336 +1,336 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-
-#include "util/u_memory.h"
-#include "util/u_debug.h"
-#include "util/u_dump.h"
-
-
-#if 0
-static const char *
-util_dump_strip_prefix(const char *name,
- const char *prefix)
-{
- const char *stripped;
- assert(name);
- assert(prefix);
- stripped = name;
- while(*prefix) {
- if(*stripped != *prefix)
- return name;
-
- ++stripped;
- ++prefix;
- }
- return stripped;
-}
-#endif
-
-static const char *
-util_dump_enum_continuous(unsigned value,
- unsigned num_names,
- const char **names)
-{
- if (value >= num_names)
- return UTIL_DUMP_INVALID_NAME;
- return names[value];
-}
-
-
-#define DEFINE_UTIL_DUMP_CONTINUOUS(_name) \
- const char * \
- util_dump_##_name(unsigned value, boolean shortened) \
- { \
- if(shortened) \
- return util_dump_enum_continuous(value, Elements(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \
- else \
- return util_dump_enum_continuous(value, Elements(util_dump_##_name##_names), util_dump_##_name##_names); \
- }
-
-
-static const char *
-util_dump_blend_factor_names[] = {
- UTIL_DUMP_INVALID_NAME, /* 0x0 */
- "PIPE_BLENDFACTOR_ONE",
- "PIPE_BLENDFACTOR_SRC_COLOR",
- "PIPE_BLENDFACTOR_SRC_ALPHA",
- "PIPE_BLENDFACTOR_DST_ALPHA",
- "PIPE_BLENDFACTOR_DST_COLOR",
- "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE",
- "PIPE_BLENDFACTOR_CONST_COLOR",
- "PIPE_BLENDFACTOR_CONST_ALPHA",
- "PIPE_BLENDFACTOR_SRC1_COLOR",
- "PIPE_BLENDFACTOR_SRC1_ALPHA",
- UTIL_DUMP_INVALID_NAME, /* 0x0b */
- UTIL_DUMP_INVALID_NAME, /* 0x0c */
- UTIL_DUMP_INVALID_NAME, /* 0x0d */
- UTIL_DUMP_INVALID_NAME, /* 0x0e */
- UTIL_DUMP_INVALID_NAME, /* 0x0f */
- UTIL_DUMP_INVALID_NAME, /* 0x10 */
- "PIPE_BLENDFACTOR_ZERO",
- "PIPE_BLENDFACTOR_INV_SRC_COLOR",
- "PIPE_BLENDFACTOR_INV_SRC_ALPHA",
- "PIPE_BLENDFACTOR_INV_DST_ALPHA",
- "PIPE_BLENDFACTOR_INV_DST_COLOR",
- UTIL_DUMP_INVALID_NAME, /* 0x16 */
- "PIPE_BLENDFACTOR_INV_CONST_COLOR",
- "PIPE_BLENDFACTOR_INV_CONST_ALPHA",
- "PIPE_BLENDFACTOR_INV_SRC1_COLOR",
- "PIPE_BLENDFACTOR_INV_SRC1_ALPHA"
-};
-
-static const char *
-util_dump_blend_factor_short_names[] = {
- UTIL_DUMP_INVALID_NAME, /* 0x0 */
- "one",
- "src_color",
- "src_alpha",
- "dst_alpha",
- "dst_color",
- "src_alpha_saturate",
- "const_color",
- "const_alpha",
- "src1_color",
- "src1_alpha",
- UTIL_DUMP_INVALID_NAME, /* 0x0b */
- UTIL_DUMP_INVALID_NAME, /* 0x0c */
- UTIL_DUMP_INVALID_NAME, /* 0x0d */
- UTIL_DUMP_INVALID_NAME, /* 0x0e */
- UTIL_DUMP_INVALID_NAME, /* 0x0f */
- UTIL_DUMP_INVALID_NAME, /* 0x10 */
- "zero",
- "inv_src_color",
- "inv_src_alpha",
- "inv_dst_alpha",
- "inv_dst_color",
- UTIL_DUMP_INVALID_NAME, /* 0x16 */
- "inv_const_color",
- "inv_const_alpha",
- "inv_src1_color",
- "inv_src1_alpha"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(blend_factor)
-
-
-static const char *
-util_dump_blend_func_names[] = {
- "PIPE_BLEND_ADD",
- "PIPE_BLEND_SUBTRACT",
- "PIPE_BLEND_REVERSE_SUBTRACT",
- "PIPE_BLEND_MIN",
- "PIPE_BLEND_MAX"
-};
-
-static const char *
-util_dump_blend_func_short_names[] = {
- "add",
- "sub",
- "rev_sub",
- "min",
- "max"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(blend_func)
-
-
-static const char *
-util_dump_logicop_names[] = {
- "PIPE_LOGICOP_CLEAR",
- "PIPE_LOGICOP_NOR",
- "PIPE_LOGICOP_AND_INVERTED",
- "PIPE_LOGICOP_COPY_INVERTED",
- "PIPE_LOGICOP_AND_REVERSE",
- "PIPE_LOGICOP_INVERT",
- "PIPE_LOGICOP_XOR",
- "PIPE_LOGICOP_NAND",
- "PIPE_LOGICOP_AND",
- "PIPE_LOGICOP_EQUIV",
- "PIPE_LOGICOP_NOOP",
- "PIPE_LOGICOP_OR_INVERTED",
- "PIPE_LOGICOP_COPY",
- "PIPE_LOGICOP_OR_REVERSE",
- "PIPE_LOGICOP_OR",
- "PIPE_LOGICOP_SET"
-};
-
-static const char *
-util_dump_logicop_short_names[] = {
- "clear",
- "nor",
- "and_inverted",
- "copy_inverted",
- "and_reverse",
- "invert",
- "xor",
- "nand",
- "and",
- "equiv",
- "noop",
- "or_inverted",
- "copy",
- "or_reverse",
- "or",
- "set"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(logicop)
-
-
-static const char *
-util_dump_func_names[] = {
- "PIPE_FUNC_NEVER",
- "PIPE_FUNC_LESS",
- "PIPE_FUNC_EQUAL",
- "PIPE_FUNC_LEQUAL",
- "PIPE_FUNC_GREATER",
- "PIPE_FUNC_NOTEQUAL",
- "PIPE_FUNC_GEQUAL",
- "PIPE_FUNC_ALWAYS"
-};
-
-static const char *
-util_dump_func_short_names[] = {
- "never",
- "less",
- "equal",
- "less_equal",
- "greater",
- "not_equal",
- "greater_equal",
- "always"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(func)
-
-
-static const char *
-util_dump_stencil_op_names[] = {
- "PIPE_STENCIL_OP_KEEP",
- "PIPE_STENCIL_OP_ZERO",
- "PIPE_STENCIL_OP_REPLACE",
- "PIPE_STENCIL_OP_INCR",
- "PIPE_STENCIL_OP_DECR",
- "PIPE_STENCIL_OP_INCR_WRAP",
- "PIPE_STENCIL_OP_DECR_WRAP",
- "PIPE_STENCIL_OP_INVERT"
-};
-
-static const char *
-util_dump_stencil_op_short_names[] = {
- "keep",
- "zero",
- "replace",
- "incr",
- "decr",
- "incr_wrap",
- "decr_wrap",
- "invert"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(stencil_op)
-
-
-static const char *
-util_dump_tex_target_names[] = {
- "PIPE_BUFFER",
- "PIPE_TEXTURE_1D",
- "PIPE_TEXTURE_2D",
- "PIPE_TEXTURE_3D",
- "PIPE_TEXTURE_CUBE"
-};
-
-static const char *
-util_dump_tex_target_short_names[] = {
- "buffer",
- "1d",
- "2d",
- "3d",
- "cube"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(tex_target)
-
-
-static const char *
-util_dump_tex_wrap_names[] = {
- "PIPE_TEX_WRAP_REPEAT",
- "PIPE_TEX_WRAP_CLAMP",
- "PIPE_TEX_WRAP_CLAMP_TO_EDGE",
- "PIPE_TEX_WRAP_CLAMP_TO_BORDER",
- "PIPE_TEX_WRAP_MIRROR_REPEAT",
- "PIPE_TEX_WRAP_MIRROR_CLAMP",
- "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE",
- "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER"
-};
-
-static const char *
-util_dump_tex_wrap_short_names[] = {
- "repeat",
- "clamp",
- "clamp_to_edge",
- "clamp_to_border",
- "mirror_repeat",
- "mirror_clamp",
- "mirror_clamp_to_edge",
- "mirror_clamp_to_border"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(tex_wrap)
-
-
-static const char *
-util_dump_tex_mipfilter_names[] = {
- "PIPE_TEX_MIPFILTER_NEAREST",
- "PIPE_TEX_MIPFILTER_LINEAR",
- "PIPE_TEX_MIPFILTER_NONE"
-};
-
-static const char *
-util_dump_tex_mipfilter_short_names[] = {
- "nearest",
- "linear",
- "none"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(tex_mipfilter)
-
-
-static const char *
-util_dump_tex_filter_names[] = {
- "PIPE_TEX_FILTER_NEAREST",
- "PIPE_TEX_FILTER_LINEAR"
-};
-
-static const char *
-util_dump_tex_filter_short_names[] = {
- "nearest",
- "linear"
-};
-
-DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter)
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_dump.h" + + +#if 0 +static const char * +util_dump_strip_prefix(const char *name, + const char *prefix) +{ + const char *stripped; + assert(name); + assert(prefix); + stripped = name; + while(*prefix) { + if(*stripped != *prefix) + return name; + + ++stripped; + ++prefix; + } + return stripped; +} +#endif + +static const char * +util_dump_enum_continuous(unsigned value, + unsigned num_names, + const char **names) +{ + if (value >= num_names) + return UTIL_DUMP_INVALID_NAME; + return names[value]; +} + + +#define DEFINE_UTIL_DUMP_CONTINUOUS(_name) \ + const char * \ + util_dump_##_name(unsigned value, boolean shortened) \ + { \ + if(shortened) \ + return util_dump_enum_continuous(value, Elements(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \ + else \ + return util_dump_enum_continuous(value, Elements(util_dump_##_name##_names), util_dump_##_name##_names); \ + } + + +static const char * +util_dump_blend_factor_names[] = { + UTIL_DUMP_INVALID_NAME, /* 0x0 */ + "PIPE_BLENDFACTOR_ONE", + "PIPE_BLENDFACTOR_SRC_COLOR", + "PIPE_BLENDFACTOR_SRC_ALPHA", + "PIPE_BLENDFACTOR_DST_ALPHA", + "PIPE_BLENDFACTOR_DST_COLOR", + "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE", + "PIPE_BLENDFACTOR_CONST_COLOR", + "PIPE_BLENDFACTOR_CONST_ALPHA", + "PIPE_BLENDFACTOR_SRC1_COLOR", + "PIPE_BLENDFACTOR_SRC1_ALPHA", + UTIL_DUMP_INVALID_NAME, /* 0x0b */ + UTIL_DUMP_INVALID_NAME, /* 0x0c */ + UTIL_DUMP_INVALID_NAME, /* 0x0d */ + UTIL_DUMP_INVALID_NAME, /* 0x0e */ + UTIL_DUMP_INVALID_NAME, /* 0x0f */ + UTIL_DUMP_INVALID_NAME, /* 0x10 */ + "PIPE_BLENDFACTOR_ZERO", + "PIPE_BLENDFACTOR_INV_SRC_COLOR", + "PIPE_BLENDFACTOR_INV_SRC_ALPHA", + "PIPE_BLENDFACTOR_INV_DST_ALPHA", + "PIPE_BLENDFACTOR_INV_DST_COLOR", + UTIL_DUMP_INVALID_NAME, /* 0x16 */ + "PIPE_BLENDFACTOR_INV_CONST_COLOR", + "PIPE_BLENDFACTOR_INV_CONST_ALPHA", + "PIPE_BLENDFACTOR_INV_SRC1_COLOR", + "PIPE_BLENDFACTOR_INV_SRC1_ALPHA" +}; + +static const char * +util_dump_blend_factor_short_names[] = { + UTIL_DUMP_INVALID_NAME, /* 0x0 */ + "one", + "src_color", + "src_alpha", + "dst_alpha", + "dst_color", + "src_alpha_saturate", + "const_color", + "const_alpha", + "src1_color", + "src1_alpha", + UTIL_DUMP_INVALID_NAME, /* 0x0b */ + UTIL_DUMP_INVALID_NAME, /* 0x0c */ + UTIL_DUMP_INVALID_NAME, /* 0x0d */ + UTIL_DUMP_INVALID_NAME, /* 0x0e */ + UTIL_DUMP_INVALID_NAME, /* 0x0f */ + UTIL_DUMP_INVALID_NAME, /* 0x10 */ + "zero", + "inv_src_color", + "inv_src_alpha", + "inv_dst_alpha", + "inv_dst_color", + UTIL_DUMP_INVALID_NAME, /* 0x16 */ + "inv_const_color", + "inv_const_alpha", + "inv_src1_color", + "inv_src1_alpha" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(blend_factor) + + +static const char * +util_dump_blend_func_names[] = { + "PIPE_BLEND_ADD", + "PIPE_BLEND_SUBTRACT", + "PIPE_BLEND_REVERSE_SUBTRACT", + "PIPE_BLEND_MIN", + "PIPE_BLEND_MAX" +}; + +static const char * +util_dump_blend_func_short_names[] = { + "add", + "sub", + "rev_sub", + "min", + "max" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(blend_func) + + +static const char * +util_dump_logicop_names[] = { + "PIPE_LOGICOP_CLEAR", + "PIPE_LOGICOP_NOR", + "PIPE_LOGICOP_AND_INVERTED", + "PIPE_LOGICOP_COPY_INVERTED", + "PIPE_LOGICOP_AND_REVERSE", + "PIPE_LOGICOP_INVERT", + "PIPE_LOGICOP_XOR", + "PIPE_LOGICOP_NAND", + "PIPE_LOGICOP_AND", + "PIPE_LOGICOP_EQUIV", + "PIPE_LOGICOP_NOOP", + "PIPE_LOGICOP_OR_INVERTED", + "PIPE_LOGICOP_COPY", + "PIPE_LOGICOP_OR_REVERSE", + "PIPE_LOGICOP_OR", + "PIPE_LOGICOP_SET" +}; + +static const char * +util_dump_logicop_short_names[] = { + "clear", + "nor", + "and_inverted", + "copy_inverted", + "and_reverse", + "invert", + "xor", + "nand", + "and", + "equiv", + "noop", + "or_inverted", + "copy", + "or_reverse", + "or", + "set" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(logicop) + + +static const char * +util_dump_func_names[] = { + "PIPE_FUNC_NEVER", + "PIPE_FUNC_LESS", + "PIPE_FUNC_EQUAL", + "PIPE_FUNC_LEQUAL", + "PIPE_FUNC_GREATER", + "PIPE_FUNC_NOTEQUAL", + "PIPE_FUNC_GEQUAL", + "PIPE_FUNC_ALWAYS" +}; + +static const char * +util_dump_func_short_names[] = { + "never", + "less", + "equal", + "less_equal", + "greater", + "not_equal", + "greater_equal", + "always" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(func) + + +static const char * +util_dump_stencil_op_names[] = { + "PIPE_STENCIL_OP_KEEP", + "PIPE_STENCIL_OP_ZERO", + "PIPE_STENCIL_OP_REPLACE", + "PIPE_STENCIL_OP_INCR", + "PIPE_STENCIL_OP_DECR", + "PIPE_STENCIL_OP_INCR_WRAP", + "PIPE_STENCIL_OP_DECR_WRAP", + "PIPE_STENCIL_OP_INVERT" +}; + +static const char * +util_dump_stencil_op_short_names[] = { + "keep", + "zero", + "replace", + "incr", + "decr", + "incr_wrap", + "decr_wrap", + "invert" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(stencil_op) + + +static const char * +util_dump_tex_target_names[] = { + "PIPE_BUFFER", + "PIPE_TEXTURE_1D", + "PIPE_TEXTURE_2D", + "PIPE_TEXTURE_3D", + "PIPE_TEXTURE_CUBE" +}; + +static const char * +util_dump_tex_target_short_names[] = { + "buffer", + "1d", + "2d", + "3d", + "cube" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_target) + + +static const char * +util_dump_tex_wrap_names[] = { + "PIPE_TEX_WRAP_REPEAT", + "PIPE_TEX_WRAP_CLAMP", + "PIPE_TEX_WRAP_CLAMP_TO_EDGE", + "PIPE_TEX_WRAP_CLAMP_TO_BORDER", + "PIPE_TEX_WRAP_MIRROR_REPEAT", + "PIPE_TEX_WRAP_MIRROR_CLAMP", + "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE", + "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER" +}; + +static const char * +util_dump_tex_wrap_short_names[] = { + "repeat", + "clamp", + "clamp_to_edge", + "clamp_to_border", + "mirror_repeat", + "mirror_clamp", + "mirror_clamp_to_edge", + "mirror_clamp_to_border" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_wrap) + + +static const char * +util_dump_tex_mipfilter_names[] = { + "PIPE_TEX_MIPFILTER_NEAREST", + "PIPE_TEX_MIPFILTER_LINEAR", + "PIPE_TEX_MIPFILTER_NONE" +}; + +static const char * +util_dump_tex_mipfilter_short_names[] = { + "nearest", + "linear", + "none" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_mipfilter) + + +static const char * +util_dump_tex_filter_names[] = { + "PIPE_TEX_FILTER_NEAREST", + "PIPE_TEX_FILTER_LINEAR" +}; + +static const char * +util_dump_tex_filter_short_names[] = { + "nearest", + "linear" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter) diff --git a/mesalib/src/gallium/auxiliary/util/u_dynarray.h b/mesalib/src/gallium/auxiliary/util/u_dynarray.h index 4dd6c3eaa..980cadf22 100644 --- a/mesalib/src/gallium/auxiliary/util/u_dynarray.h +++ b/mesalib/src/gallium/auxiliary/util/u_dynarray.h @@ -1,114 +1,114 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#ifndef U_DYNARRAY_H
-#define U_DYNARRAY_H
-
-#include "pipe/p_compiler.h"
-#include "util/u_memory.h"
-
-/* A zero-initialized version of this is guaranteed to represent an
- * empty array.
- *
- * Also, size <= capacity and data != 0 if and only if capacity != 0
- * capacity will always be the allocation size of data
- */
-struct util_dynarray
-{
- void *data;
- unsigned size;
- unsigned capacity;
-};
-
-static INLINE void
-util_dynarray_init(struct util_dynarray *buf)
-{
- memset(buf, 0, sizeof(*buf));
-}
-
-static INLINE void
-util_dynarray_fini(struct util_dynarray *buf)
-{
- if(buf->data)
- {
- FREE(buf->data);
- util_dynarray_init(buf);
- }
-}
-
-/* use util_dynarray_trim to reduce the allocated storage */
-static INLINE void *
-util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
-{
- char *p;
- if(newsize > buf->capacity)
- {
- unsigned newcap = buf->capacity << 1;
- if(newsize > newcap)
- newcap = newsize;
- buf->data = REALLOC(buf->data, buf->capacity, newcap);
- buf->capacity = newcap;
- }
-
- p = (char *)buf->data + buf->size;
- buf->size = newsize;
- return p;
-}
-
-static INLINE void *
-util_dynarray_grow(struct util_dynarray *buf, int diff)
-{
- return util_dynarray_resize(buf, buf->size + diff);
-}
-
-static INLINE void
-util_dynarray_trim(struct util_dynarray *buf)
-{
- if (buf->size != buf->capacity) {
- if (buf->size) {
- buf->data = REALLOC(buf->data, buf->capacity, buf->size);
- buf->capacity = buf->size;
- }
- else {
- FREE(buf->data);
- buf->data = 0;
- buf->capacity = 0;
- }
- }
-}
-
-#define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), sizeof(type)), &__v, sizeof(type));} while(0)
-#define util_dynarray_top_ptr(buf, type) (type*)((char*)(buf)->data + (buf)->size - sizeof(type))
-#define util_dynarray_top(buf, type) *util_dynarray_top_ptr(buf, type)
-#define util_dynarray_pop_ptr(buf, type) (type*)((char*)(buf)->data + ((buf)->size -= sizeof(type)))
-#define util_dynarray_pop(buf, type) *util_dynarray_pop_ptr(buf, type)
-#define util_dynarray_contains(buf, type) ((buf)->size >= sizeof(type))
-#define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx))
-#define util_dynarray_begin(buf) ((buf)->data)
-#define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size))
-
-#endif /* U_DYNARRAY_H */
-
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#ifndef U_DYNARRAY_H +#define U_DYNARRAY_H + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" + +/* A zero-initialized version of this is guaranteed to represent an + * empty array. + * + * Also, size <= capacity and data != 0 if and only if capacity != 0 + * capacity will always be the allocation size of data + */ +struct util_dynarray +{ + void *data; + unsigned size; + unsigned capacity; +}; + +static INLINE void +util_dynarray_init(struct util_dynarray *buf) +{ + memset(buf, 0, sizeof(*buf)); +} + +static INLINE void +util_dynarray_fini(struct util_dynarray *buf) +{ + if(buf->data) + { + FREE(buf->data); + util_dynarray_init(buf); + } +} + +/* use util_dynarray_trim to reduce the allocated storage */ +static INLINE void * +util_dynarray_resize(struct util_dynarray *buf, unsigned newsize) +{ + char *p; + if(newsize > buf->capacity) + { + unsigned newcap = buf->capacity << 1; + if(newsize > newcap) + newcap = newsize; + buf->data = REALLOC(buf->data, buf->capacity, newcap); + buf->capacity = newcap; + } + + p = (char *)buf->data + buf->size; + buf->size = newsize; + return p; +} + +static INLINE void * +util_dynarray_grow(struct util_dynarray *buf, int diff) +{ + return util_dynarray_resize(buf, buf->size + diff); +} + +static INLINE void +util_dynarray_trim(struct util_dynarray *buf) +{ + if (buf->size != buf->capacity) { + if (buf->size) { + buf->data = REALLOC(buf->data, buf->capacity, buf->size); + buf->capacity = buf->size; + } + else { + FREE(buf->data); + buf->data = 0; + buf->capacity = 0; + } + } +} + +#define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), sizeof(type)), &__v, sizeof(type));} while(0) +#define util_dynarray_top_ptr(buf, type) (type*)((char*)(buf)->data + (buf)->size - sizeof(type)) +#define util_dynarray_top(buf, type) *util_dynarray_top_ptr(buf, type) +#define util_dynarray_pop_ptr(buf, type) (type*)((char*)(buf)->data + ((buf)->size -= sizeof(type))) +#define util_dynarray_pop(buf, type) *util_dynarray_pop_ptr(buf, type) +#define util_dynarray_contains(buf, type) ((buf)->size >= sizeof(type)) +#define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx)) +#define util_dynarray_begin(buf) ((buf)->data) +#define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size)) + +#endif /* U_DYNARRAY_H */ + diff --git a/mesalib/src/gallium/auxiliary/util/u_fifo.h b/mesalib/src/gallium/auxiliary/util/u_fifo.h index 7c13f119e..9e007de1a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_fifo.h +++ b/mesalib/src/gallium/auxiliary/util/u_fifo.h @@ -1,94 +1,94 @@ -/**************************************************************************
- *
- * Copyright © 2009 Jakob Bornecrantz
- *
- * 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.
- *
- **************************************************************************/
-
-#ifndef U_FIFO_H
-#define U_FIFO_H
-
-#include "util/u_memory.h"
-
-struct util_fifo
-{
- size_t head;
- size_t tail;
- size_t num;
- size_t size;
-};
-
-static INLINE struct util_fifo *
-u_fifo_create(size_t size)
-{
- struct util_fifo *fifo;
- fifo = MALLOC(sizeof(*fifo) + size * sizeof(void*));
-
- fifo->head = 0;
- fifo->tail = 0;
- fifo->num = 0;
- fifo->size = size;
-
- return fifo;
-}
-
-static INLINE boolean
-u_fifo_add(struct util_fifo *fifo, void *ptr)
-{
- void **array = (void**)&fifo[1];
- if (fifo->num >= fifo->size)
- return FALSE;
-
- if (++fifo->head >= fifo->size)
- fifo->head = 0;
-
- array[fifo->head] = ptr;
-
- ++fifo->num;
-
- return TRUE;
-}
-
-static INLINE boolean
-u_fifo_pop(struct util_fifo *fifo, void **ptr)
-{
- void **array = (void**)&fifo[1];
-
- if (!fifo->num)
- return FALSE;
-
- if (++fifo->tail >= fifo->size)
- fifo->tail = 0;
-
- *ptr = array[fifo->tail];
-
- ++fifo->num;
-
- return TRUE;
-}
-
-static INLINE void
-u_fifo_destroy(struct util_fifo *fifo)
-{
- FREE(fifo);
-}
-
-#endif
+/************************************************************************** + * + * Copyright © 2009 Jakob Bornecrantz + * + * 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. + * + **************************************************************************/ + +#ifndef U_FIFO_H +#define U_FIFO_H + +#include "util/u_memory.h" + +struct util_fifo +{ + size_t head; + size_t tail; + size_t num; + size_t size; +}; + +static INLINE struct util_fifo * +u_fifo_create(size_t size) +{ + struct util_fifo *fifo; + fifo = MALLOC(sizeof(*fifo) + size * sizeof(void*)); + + fifo->head = 0; + fifo->tail = 0; + fifo->num = 0; + fifo->size = size; + + return fifo; +} + +static INLINE boolean +u_fifo_add(struct util_fifo *fifo, void *ptr) +{ + void **array = (void**)&fifo[1]; + if (fifo->num >= fifo->size) + return FALSE; + + if (++fifo->head >= fifo->size) + fifo->head = 0; + + array[fifo->head] = ptr; + + ++fifo->num; + + return TRUE; +} + +static INLINE boolean +u_fifo_pop(struct util_fifo *fifo, void **ptr) +{ + void **array = (void**)&fifo[1]; + + if (!fifo->num) + return FALSE; + + if (++fifo->tail >= fifo->size) + fifo->tail = 0; + + *ptr = array[fifo->tail]; + + ++fifo->num; + + return TRUE; +} + +static INLINE void +u_fifo_destroy(struct util_fifo *fifo) +{ + FREE(fifo); +} + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_format_latc.h b/mesalib/src/gallium/auxiliary/util/u_format_latc.h index 324717215..1f0888753 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_latc.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_latc.h @@ -1,108 +1,108 @@ -/**************************************************************************
- *
- * Copyright 2011 Red Hat Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-#ifndef U_FORMAT_LATC_H_
-#define U_FORMAT_LATC_H_
-
-void
-util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_latc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-
-void
-util_format_latc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_latc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_latc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_latc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_latc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_latc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-#endif
+/************************************************************************** + * + * Copyright 2011 Red Hat Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +#ifndef U_FORMAT_LATC_H_ +#define U_FORMAT_LATC_H_ + +void +util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_latc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + + +void +util_format_latc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_latc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_latc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_latc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_latc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_latc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_format_other.c b/mesalib/src/gallium/auxiliary/util/u_format_other.c index b6173a12e..c23f4ee4a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_other.c +++ b/mesalib/src/gallium/auxiliary/util/u_format_other.c @@ -1,472 +1,472 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#include "u_math.h"
-#include "u_format_other.h"
-#include "u_format_rgb9e5.h"
-#include "u_format_r11g11b10f.h"
-
-
-void
-util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- float *dst = dst_row;
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- rgb9e5_to_float3(value, dst);
- dst[3] = 1; /* a */
- src += 4;
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-void
-util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = float3_to_rgb9e5(src);
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- *(uint32_t *)dst = value;
- src += 4;
- dst += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-void
-util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j)
-{
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- rgb9e5_to_float3(value, dst);
- dst[3] = 1; /* a */
-}
-
-
-void
-util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- float p[3];
- for(y = 0; y < height; y += 1) {
- uint8_t *dst = dst_row;
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- rgb9e5_to_float3(value, p);
- dst[0] = float_to_ubyte(p[0]); /* r */
- dst[1] = float_to_ubyte(p[1]); /* g */
- dst[2] = float_to_ubyte(p[2]); /* b */
- dst[3] = 255; /* a */
- src += 4;
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-
-void
-util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- float p[3];
- for(y = 0; y < height; y += 1) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value;
- p[0] = ubyte_to_float(src[0]);
- p[1] = ubyte_to_float(src[1]);
- p[2] = ubyte_to_float(src[2]);
- value = float3_to_rgb9e5(p);
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- *(uint32_t *)dst = value;
- src += 4;
- dst += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-
-void
-util_format_r11g11b10_float_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- float *dst = dst_row;
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- r11g11b10f_to_float3(value, dst);
- dst[3] = 1; /* a */
- src += 4;
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-void
-util_format_r11g11b10_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- const float *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = float3_to_r11g11b10f(src);
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- *(uint32_t *)dst = value;
- src += 4;
- dst += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-void
-util_format_r11g11b10_float_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j)
-{
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- r11g11b10f_to_float3(value, dst);
- dst[3] = 1; /* a */
-}
-
-
-void
-util_format_r11g11b10_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- float p[3];
- for(y = 0; y < height; y += 1) {
- uint8_t *dst = dst_row;
- const uint8_t *src = src_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value = *(const uint32_t *)src;
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- r11g11b10f_to_float3(value, p);
- dst[0] = float_to_ubyte(p[0]); /* r */
- dst[1] = float_to_ubyte(p[1]); /* g */
- dst[2] = float_to_ubyte(p[2]); /* b */
- dst[3] = 255; /* a */
- src += 4;
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-
-void
-util_format_r11g11b10_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- float p[3];
- for(y = 0; y < height; y += 1) {
- const uint8_t *src = src_row;
- uint8_t *dst = dst_row;
- for(x = 0; x < width; x += 1) {
- uint32_t value;
- p[0] = ubyte_to_float(src[0]);
- p[1] = ubyte_to_float(src[1]);
- p[2] = ubyte_to_float(src[2]);
- value = float3_to_r11g11b10f(p);
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
- *(uint32_t *)dst = value;
- src += 4;
- dst += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-
-void
-util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
-
-}
-
-
-void
-util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
-
-}
-
-
-void
-util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j)
-{
-
-}
-
-
-void
-util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
-
-}
-
-
-void
-util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
-}
-
-
-/*
- * PIPE_FORMAT_R8G8Bx_SNORM
- *
- * A.k.a. D3DFMT_CxV8U8
- */
-
-static uint8_t
-r8g8bx_derive(int16_t r, int16_t g)
-{
- /* Derive blue from red and green components.
- * Apparently, we must always use integers to perform calculations,
- * otherwise the results won't match D3D's CxV8U8 definition.
- */
- return (uint8_t)sqrtf(0x7f * 0x7f - r * r - g * g) * 0xff / 0x7f;
-}
-
-void
-util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
-
- for(y = 0; y < height; y += 1) {
- float *dst = dst_row;
- const uint16_t *src = (const uint16_t *)src_row;
- for(x = 0; x < width; x += 1) {
- uint16_t value = *src++;
- int16_t r, g;
-
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
-
- r = ((int16_t)(value << 8)) >> 8;
- g = ((int16_t)(value << 0)) >> 8;
-
- dst[0] = (float)(r * (1.0f/0x7f)); /* r */
- dst[1] = (float)(g * (1.0f/0x7f)); /* g */
- dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */
- dst[3] = 1.0f; /* a */
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-
-void
-util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- uint8_t *dst = dst_row;
- const uint16_t *src = (const uint16_t *)src_row;
- for(x = 0; x < width; x += 1) {
- uint16_t value = *src++;
- int16_t r, g;
-
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
-
- r = ((int16_t)(value << 8)) >> 8;
- g = ((int16_t)(value << 0)) >> 8;
-
- dst[0] = (uint8_t)(((uint16_t)MAX2(r, 0)) * 0xff / 0x7f); /* r */
- dst[1] = (uint8_t)(((uint16_t)MAX2(g, 0)) * 0xff / 0x7f); /* g */
- dst[2] = r8g8bx_derive(r, g); /* b */
- dst[3] = 255; /* a */
- dst += 4;
- }
- src_row += src_stride;
- dst_row += dst_stride/sizeof(*dst_row);
- }
-}
-
-
-void
-util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
- for(y = 0; y < height; y += 1) {
- const float *src = src_row;
- uint16_t *dst = (uint16_t *)dst_row;
- for(x = 0; x < width; x += 1) {
- uint16_t value = 0;
-
- value |= (uint16_t)(((int8_t)(CLAMP(src[0], -1, 1) * 0x7f)) & 0xff) ;
- value |= (uint16_t)((((int8_t)(CLAMP(src[1], -1, 1) * 0x7f)) & 0xff) << 8) ;
-
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
-
- *dst++ = value;
-
- src += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-
-void
-util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height)
-{
- unsigned x, y;
-
- for(y = 0; y < height; y += 1) {
- const uint8_t *src = src_row;
- uint16_t *dst = (uint16_t *)dst_row;
- for(x = 0; x < width; x += 1) {
- uint16_t value = 0;
-
- value |= src[0] >> 1;
- value |= (src[1] >> 1) << 8;
-
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
-
- *dst++ = value;
-
- src += 4;
- }
- dst_row += dst_stride;
- src_row += src_stride/sizeof(*src_row);
- }
-}
-
-
-void
-util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j)
-{
- uint16_t value = *(const uint16_t *)src;
- int16_t r, g;
-
-#ifdef PIPE_ARCH_BIG_ENDIAN
- value = util_bswap32(value);
-#endif
-
- r = ((int16_t)(value << 8)) >> 8;
- g = ((int16_t)(value << 0)) >> 8;
-
- dst[0] = r * (1.0f/0x7f); /* r */
- dst[1] = g * (1.0f/0x7f); /* g */
- dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */
- dst[3] = 1.0f; /* a */
-}
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#include "u_math.h" +#include "u_format_other.h" +#include "u_format_rgb9e5.h" +#include "u_format_r11g11b10f.h" + + +void +util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint8_t *src = src_row; + for(x = 0; x < width; x += 1) { + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + rgb9e5_to_float3(value, dst); + dst[3] = 1; /* a */ + src += 4; + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + const float *src = src_row; + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 1) { + uint32_t value = float3_to_rgb9e5(src); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *(uint32_t *)dst = value; + src += 4; + dst += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + rgb9e5_to_float3(value, dst); + dst[3] = 1; /* a */ +} + + +void +util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + float p[3]; + for(y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint8_t *src = src_row; + for(x = 0; x < width; x += 1) { + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + rgb9e5_to_float3(value, p); + dst[0] = float_to_ubyte(p[0]); /* r */ + dst[1] = float_to_ubyte(p[1]); /* g */ + dst[2] = float_to_ubyte(p[2]); /* b */ + dst[3] = 255; /* a */ + src += 4; + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + float p[3]; + for(y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 1) { + uint32_t value; + p[0] = ubyte_to_float(src[0]); + p[1] = ubyte_to_float(src[1]); + p[2] = ubyte_to_float(src[2]); + value = float3_to_rgb9e5(p); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *(uint32_t *)dst = value; + src += 4; + dst += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r11g11b10_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint8_t *src = src_row; + for(x = 0; x < width; x += 1) { + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + r11g11b10f_to_float3(value, dst); + dst[3] = 1; /* a */ + src += 4; + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_r11g11b10_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + const float *src = src_row; + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 1) { + uint32_t value = float3_to_r11g11b10f(src); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *(uint32_t *)dst = value; + src += 4; + dst += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_r11g11b10_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + r11g11b10f_to_float3(value, dst); + dst[3] = 1; /* a */ +} + + +void +util_format_r11g11b10_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + float p[3]; + for(y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint8_t *src = src_row; + for(x = 0; x < width; x += 1) { + uint32_t value = *(const uint32_t *)src; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + r11g11b10f_to_float3(value, p); + dst[0] = float_to_ubyte(p[0]); /* r */ + dst[1] = float_to_ubyte(p[1]); /* g */ + dst[2] = float_to_ubyte(p[2]); /* b */ + dst[3] = 255; /* a */ + src += 4; + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r11g11b10_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + float p[3]; + for(y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 1) { + uint32_t value; + p[0] = ubyte_to_float(src[0]); + p[1] = ubyte_to_float(src[1]); + p[2] = ubyte_to_float(src[2]); + value = float3_to_r11g11b10f(p); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *(uint32_t *)dst = value; + src += 4; + dst += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + +} + + +void +util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ +} + + +/* + * PIPE_FORMAT_R8G8Bx_SNORM + * + * A.k.a. D3DFMT_CxV8U8 + */ + +static uint8_t +r8g8bx_derive(int16_t r, int16_t g) +{ + /* Derive blue from red and green components. + * Apparently, we must always use integers to perform calculations, + * otherwise the results won't match D3D's CxV8U8 definition. + */ + return (uint8_t)sqrtf(0x7f * 0x7f - r * r - g * g) * 0xff / 0x7f; +} + +void +util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for(y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; x += 1) { + uint16_t value = *src++; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = (float)(r * (1.0f/0x7f)); /* r */ + dst[1] = (float)(g * (1.0f/0x7f)); /* g */ + dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; x += 1) { + uint16_t value = *src++; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = (uint8_t)(((uint16_t)MAX2(r, 0)) * 0xff / 0x7f); /* r */ + dst[1] = (uint8_t)(((uint16_t)MAX2(g, 0)) * 0xff / 0x7f); /* g */ + dst[2] = r8g8bx_derive(r, g); /* b */ + dst[3] = 255; /* a */ + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + const float *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; x += 1) { + uint16_t value = 0; + + value |= (uint16_t)(((int8_t)(CLAMP(src[0], -1, 1) * 0x7f)) & 0xff) ; + value |= (uint16_t)((((int8_t)(CLAMP(src[1], -1, 1) * 0x7f)) & 0xff) << 8) ; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for(y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; x += 1) { + uint16_t value = 0; + + value |= src[0] >> 1; + value |= (src[1] >> 1) << 8; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint16_t value = *(const uint16_t *)src; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = r * (1.0f/0x7f); /* r */ + dst[1] = g * (1.0f/0x7f); /* g */ + dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */ + dst[3] = 1.0f; /* a */ +} diff --git a/mesalib/src/gallium/auxiliary/util/u_format_other.h b/mesalib/src/gallium/auxiliary/util/u_format_other.h index d8237da5e..2f6a908bb 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_other.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_other.h @@ -1,134 +1,134 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#ifndef U_FORMAT_OTHER_H_
-#define U_FORMAT_OTHER_H_
-
-
-#include "pipe/p_compiler.h"
-
-
-void
-util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j);
-
-void
-util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-
-void
-util_format_r11g11b10_float_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r11g11b10_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r11g11b10_float_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j);
-
-void
-util_format_r11g11b10_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r11g11b10_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-
-void
-util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j);
-
-void
-util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride,
- const float *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src,
- unsigned i, unsigned j);
-
-void
-util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-void
-util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,
- const uint8_t *src_row, unsigned src_stride,
- unsigned width, unsigned height);
-
-#endif /* U_FORMAT_OTHER_H_ */
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_FORMAT_OTHER_H_ +#define U_FORMAT_OTHER_H_ + + +#include "pipe/p_compiler.h" + + +void +util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + + +void +util_format_r11g11b10_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r11g11b10_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r11g11b10_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r11g11b10_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r11g11b10_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + + +void +util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +#endif /* U_FORMAT_OTHER_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_format_rgb9e5.h b/mesalib/src/gallium/auxiliary/util/u_format_rgb9e5.h index 01f4e2108..c2a3f6f3e 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_rgb9e5.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_rgb9e5.h @@ -1,164 +1,164 @@ -/*
- * Copyright (C) 2011 Marek Olšák <maraeo@gmail.com>
- *
- * 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.
- */
-
-/* Copied from EXT_texture_shared_exponent and edited. */
-
-#ifndef RGB9E5_H
-#define RGB9E5_H
-
-#include <math.h>
-#include <assert.h>
-
-#define RGB9E5_EXPONENT_BITS 5
-#define RGB9E5_MANTISSA_BITS 9
-#define RGB9E5_EXP_BIAS 15
-#define RGB9E5_MAX_VALID_BIASED_EXP 31
-
-#define MAX_RGB9E5_EXP (RGB9E5_MAX_VALID_BIASED_EXP - RGB9E5_EXP_BIAS)
-#define RGB9E5_MANTISSA_VALUES (1<<RGB9E5_MANTISSA_BITS)
-#define MAX_RGB9E5_MANTISSA (RGB9E5_MANTISSA_VALUES-1)
-#define MAX_RGB9E5 (((float)MAX_RGB9E5_MANTISSA)/RGB9E5_MANTISSA_VALUES * (1<<MAX_RGB9E5_EXP))
-#define EPSILON_RGB9E5 ((1.0/RGB9E5_MANTISSA_VALUES) / (1<<RGB9E5_EXP_BIAS))
-
-typedef union {
- unsigned int raw;
- float value;
- struct {
-#if defined(MESA_BIG_ENDIAN) || defined(PIPE_ARCH_BIG_ENDIAN)
- unsigned int negative:1;
- unsigned int biasedexponent:8;
- unsigned int mantissa:23;
-#else
- unsigned int mantissa:23;
- unsigned int biasedexponent:8;
- unsigned int negative:1;
-#endif
- } field;
-} float754;
-
-typedef union {
- unsigned int raw;
- struct {
-#if defined(MESA_BIG_ENDIAN) || defined(PIPE_ARCH_BIG_ENDIAN)
- unsigned int biasedexponent:RGB9E5_EXPONENT_BITS;
- unsigned int b:RGB9E5_MANTISSA_BITS;
- unsigned int g:RGB9E5_MANTISSA_BITS;
- unsigned int r:RGB9E5_MANTISSA_BITS;
-#else
- unsigned int r:RGB9E5_MANTISSA_BITS;
- unsigned int g:RGB9E5_MANTISSA_BITS;
- unsigned int b:RGB9E5_MANTISSA_BITS;
- unsigned int biasedexponent:RGB9E5_EXPONENT_BITS;
-#endif
- } field;
-} rgb9e5;
-
-static INLINE float rgb9e5_ClampRange(float x)
-{
- if (x > 0.0) {
- if (x >= MAX_RGB9E5) {
- return MAX_RGB9E5;
- } else {
- return x;
- }
- } else {
- /* NaN gets here too since comparisons with NaN always fail! */
- return 0.0;
- }
-}
-
-/* Ok, FloorLog2 is not correct for the denorm and zero values, but we
- are going to do a max of this value with the minimum rgb9e5 exponent
- that will hide these problem cases. */
-static INLINE int rgb9e5_FloorLog2(float x)
-{
- float754 f;
-
- f.value = x;
- return (f.field.biasedexponent - 127);
-}
-
-static INLINE unsigned float3_to_rgb9e5(const float rgb[3])
-{
- rgb9e5 retval;
- float maxrgb;
- int rm, gm, bm;
- float rc, gc, bc;
- int exp_shared, maxm;
- double denom;
-
- rc = rgb9e5_ClampRange(rgb[0]);
- gc = rgb9e5_ClampRange(rgb[1]);
- bc = rgb9e5_ClampRange(rgb[2]);
-
- maxrgb = MAX3(rc, gc, bc);
- exp_shared = MAX2(-RGB9E5_EXP_BIAS-1, rgb9e5_FloorLog2(maxrgb)) + 1 + RGB9E5_EXP_BIAS;
- assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP);
- assert(exp_shared >= 0);
- /* This pow function could be replaced by a table. */
- denom = pow(2, exp_shared - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS);
-
- maxm = (int) floor(maxrgb / denom + 0.5);
- if (maxm == MAX_RGB9E5_MANTISSA+1) {
- denom *= 2;
- exp_shared += 1;
- assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP);
- } else {
- assert(maxm <= MAX_RGB9E5_MANTISSA);
- }
-
- rm = (int) floor(rc / denom + 0.5);
- gm = (int) floor(gc / denom + 0.5);
- bm = (int) floor(bc / denom + 0.5);
-
- assert(rm <= MAX_RGB9E5_MANTISSA);
- assert(gm <= MAX_RGB9E5_MANTISSA);
- assert(bm <= MAX_RGB9E5_MANTISSA);
- assert(rm >= 0);
- assert(gm >= 0);
- assert(bm >= 0);
-
- retval.field.r = rm;
- retval.field.g = gm;
- retval.field.b = bm;
- retval.field.biasedexponent = exp_shared;
-
- return retval.raw;
-}
-
-static INLINE void rgb9e5_to_float3(unsigned rgb, float retval[3])
-{
- rgb9e5 v;
- int exponent;
- float scale;
-
- v.raw = rgb;
- exponent = v.field.biasedexponent - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS;
- scale = (float) pow(2, exponent);
-
- retval[0] = v.field.r * scale;
- retval[1] = v.field.g * scale;
- retval[2] = v.field.b * scale;
-}
-
-#endif
+/* + * Copyright (C) 2011 Marek Olšák <maraeo@gmail.com> + * + * 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. + */ + +/* Copied from EXT_texture_shared_exponent and edited. */ + +#ifndef RGB9E5_H +#define RGB9E5_H + +#include <math.h> +#include <assert.h> + +#define RGB9E5_EXPONENT_BITS 5 +#define RGB9E5_MANTISSA_BITS 9 +#define RGB9E5_EXP_BIAS 15 +#define RGB9E5_MAX_VALID_BIASED_EXP 31 + +#define MAX_RGB9E5_EXP (RGB9E5_MAX_VALID_BIASED_EXP - RGB9E5_EXP_BIAS) +#define RGB9E5_MANTISSA_VALUES (1<<RGB9E5_MANTISSA_BITS) +#define MAX_RGB9E5_MANTISSA (RGB9E5_MANTISSA_VALUES-1) +#define MAX_RGB9E5 (((float)MAX_RGB9E5_MANTISSA)/RGB9E5_MANTISSA_VALUES * (1<<MAX_RGB9E5_EXP)) +#define EPSILON_RGB9E5 ((1.0/RGB9E5_MANTISSA_VALUES) / (1<<RGB9E5_EXP_BIAS)) + +typedef union { + unsigned int raw; + float value; + struct { +#if defined(MESA_BIG_ENDIAN) || defined(PIPE_ARCH_BIG_ENDIAN) + unsigned int negative:1; + unsigned int biasedexponent:8; + unsigned int mantissa:23; +#else + unsigned int mantissa:23; + unsigned int biasedexponent:8; + unsigned int negative:1; +#endif + } field; +} float754; + +typedef union { + unsigned int raw; + struct { +#if defined(MESA_BIG_ENDIAN) || defined(PIPE_ARCH_BIG_ENDIAN) + unsigned int biasedexponent:RGB9E5_EXPONENT_BITS; + unsigned int b:RGB9E5_MANTISSA_BITS; + unsigned int g:RGB9E5_MANTISSA_BITS; + unsigned int r:RGB9E5_MANTISSA_BITS; +#else + unsigned int r:RGB9E5_MANTISSA_BITS; + unsigned int g:RGB9E5_MANTISSA_BITS; + unsigned int b:RGB9E5_MANTISSA_BITS; + unsigned int biasedexponent:RGB9E5_EXPONENT_BITS; +#endif + } field; +} rgb9e5; + +static INLINE float rgb9e5_ClampRange(float x) +{ + if (x > 0.0) { + if (x >= MAX_RGB9E5) { + return MAX_RGB9E5; + } else { + return x; + } + } else { + /* NaN gets here too since comparisons with NaN always fail! */ + return 0.0; + } +} + +/* Ok, FloorLog2 is not correct for the denorm and zero values, but we + are going to do a max of this value with the minimum rgb9e5 exponent + that will hide these problem cases. */ +static INLINE int rgb9e5_FloorLog2(float x) +{ + float754 f; + + f.value = x; + return (f.field.biasedexponent - 127); +} + +static INLINE unsigned float3_to_rgb9e5(const float rgb[3]) +{ + rgb9e5 retval; + float maxrgb; + int rm, gm, bm; + float rc, gc, bc; + int exp_shared, maxm; + double denom; + + rc = rgb9e5_ClampRange(rgb[0]); + gc = rgb9e5_ClampRange(rgb[1]); + bc = rgb9e5_ClampRange(rgb[2]); + + maxrgb = MAX3(rc, gc, bc); + exp_shared = MAX2(-RGB9E5_EXP_BIAS-1, rgb9e5_FloorLog2(maxrgb)) + 1 + RGB9E5_EXP_BIAS; + assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP); + assert(exp_shared >= 0); + /* This pow function could be replaced by a table. */ + denom = pow(2, exp_shared - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS); + + maxm = (int) floor(maxrgb / denom + 0.5); + if (maxm == MAX_RGB9E5_MANTISSA+1) { + denom *= 2; + exp_shared += 1; + assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP); + } else { + assert(maxm <= MAX_RGB9E5_MANTISSA); + } + + rm = (int) floor(rc / denom + 0.5); + gm = (int) floor(gc / denom + 0.5); + bm = (int) floor(bc / denom + 0.5); + + assert(rm <= MAX_RGB9E5_MANTISSA); + assert(gm <= MAX_RGB9E5_MANTISSA); + assert(bm <= MAX_RGB9E5_MANTISSA); + assert(rm >= 0); + assert(gm >= 0); + assert(bm >= 0); + + retval.field.r = rm; + retval.field.g = gm; + retval.field.b = bm; + retval.field.biasedexponent = exp_shared; + + return retval.raw; +} + +static INLINE void rgb9e5_to_float3(unsigned rgb, float retval[3]) +{ + rgb9e5 v; + int exponent; + float scale; + + v.raw = rgb; + exponent = v.field.biasedexponent - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS; + scale = (float) pow(2, exponent); + + retval[0] = v.field.r * scale; + retval[1] = v.field.g * scale; + retval[2] = v.field.b * scale; +} + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_format_rgtc.h b/mesalib/src/gallium/auxiliary/util/u_format_rgtc.h index 723c9c89a..67ac4728e 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_rgtc.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_rgtc.h @@ -1,114 +1,114 @@ -/**************************************************************************
- *
- * Copyright 2011 Red Hat Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-#ifndef U_FORMAT_RGTC_H_
-#define U_FORMAT_RGTC_H_
-
-void
-util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-
-void
-util_format_rgtc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_rgtc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rxtc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height, unsigned chan2off);
-
-void
-util_format_rgtc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_rgtc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_rgtc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rxtc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height, unsigned chan2off);
-
-void
-util_format_rgtc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_rgtc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-#endif
+/************************************************************************** + * + * Copyright 2011 Red Hat Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +#ifndef U_FORMAT_RGTC_H_ +#define U_FORMAT_RGTC_H_ + +void +util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + + +void +util_format_rgtc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_rgtc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rxtc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height, unsigned chan2off); + +void +util_format_rgtc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_rgtc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_rgtc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rxtc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height, unsigned chan2off); + +void +util_format_rgtc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_rgtc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_format_s3tc.h b/mesalib/src/gallium/auxiliary/util/u_format_s3tc.h index 887d11079..97770abd4 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_s3tc.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_s3tc.h @@ -1,218 +1,218 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#ifndef U_FORMAT_S3TC_H_
-#define U_FORMAT_S3TC_H_
-
-
-#include "pipe/p_compiler.h"
-
-
-enum util_format_dxtn {
- UTIL_FORMAT_DXT1_RGB = 0x83F0,
- UTIL_FORMAT_DXT1_RGBA = 0x83F1,
- UTIL_FORMAT_DXT3_RGBA = 0x83F2,
- UTIL_FORMAT_DXT5_RGBA = 0x83F3
-};
-
-
-typedef void
-(*util_format_dxtn_fetch_t)( int src_stride,
- const uint8_t *src,
- int col, int row,
- uint8_t *dst );
-
-typedef void
-(*util_format_dxtn_pack_t)( int src_comps,
- int width, int height,
- const uint8_t *src,
- enum util_format_dxtn dst_format,
- uint8_t *dst,
- int dst_stride);
-
-extern boolean util_format_s3tc_enabled;
-
-extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch;
-extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch;
-extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch;
-extern util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch;
-
-extern util_format_dxtn_pack_t util_format_dxtn_pack;
-
-
-void
-util_format_s3tc_init(void);
-
-
-void
-util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-void
-util_format_dxt1_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-void
-util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
-
-void
-util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
-
-
-#endif /* U_FORMAT_S3TC_H_ */
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_FORMAT_S3TC_H_ +#define U_FORMAT_S3TC_H_ + + +#include "pipe/p_compiler.h" + + +enum util_format_dxtn { + UTIL_FORMAT_DXT1_RGB = 0x83F0, + UTIL_FORMAT_DXT1_RGBA = 0x83F1, + UTIL_FORMAT_DXT3_RGBA = 0x83F2, + UTIL_FORMAT_DXT5_RGBA = 0x83F3 +}; + + +typedef void +(*util_format_dxtn_fetch_t)( int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ); + +typedef void +(*util_format_dxtn_pack_t)( int src_comps, + int width, int height, + const uint8_t *src, + enum util_format_dxtn dst_format, + uint8_t *dst, + int dst_stride); + +extern boolean util_format_s3tc_enabled; + +extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch; +extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch; + +extern util_format_dxtn_pack_t util_format_dxtn_pack; + + +void +util_format_s3tc_init(void); + + +void +util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_dxt1_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +#endif /* U_FORMAT_S3TC_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_format_srgb.h b/mesalib/src/gallium/auxiliary/util/u_format_srgb.h index a1b12e9de..43213fbeb 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_srgb.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_srgb.h @@ -1,106 +1,106 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-/**
- * @file
- * SRGB translation.
- *
- * @author Brian Paul <brianp@vmware.com>
- * @author Michal Krol <michal@vmware.com>
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#ifndef U_FORMAT_SRGB_H_
-#define U_FORMAT_SRGB_H_
-
-
-#include "pipe/p_compiler.h"
-#include "u_math.h"
-
-
-extern const float
-util_format_srgb_8unorm_to_linear_float_table[256];
-
-extern const uint8_t
-util_format_srgb_to_linear_8unorm_table[256];
-
-extern const uint8_t
-util_format_linear_to_srgb_8unorm_table[256];
-
-
-/**
- * Convert a unclamped linear float to srgb value in the [0,255].
- * XXX this hasn't been tested (render to srgb surface).
- * XXX this needs optimization.
- */
-static INLINE uint8_t
-util_format_linear_float_to_srgb_8unorm(float x)
-{
- if (x >= 1.0f)
- return 255;
- else if (x >= 0.0031308f)
- return float_to_ubyte(1.055f * powf(x, 0.41666f) - 0.055f);
- else if (x > 0.0f)
- return float_to_ubyte(12.92f * x);
- else
- return 0;
-}
-
-
-/**
- * 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 float
-util_format_srgb_8unorm_to_linear_float(uint8_t x)
-{
- return util_format_srgb_8unorm_to_linear_float_table[x];
-}
-
-
-/**
- * Convert a 8bit normalized value from linear to srgb.
- */
-static INLINE uint8_t
-util_format_linear_to_srgb_8unorm(uint8_t x)
-{
- return util_format_linear_to_srgb_8unorm_table[x];
-}
-
-
-/**
- * Convert a 8bit normalized value from srgb to linear.
- */
-static INLINE uint8_t
-util_format_srgb_to_linear_8unorm(uint8_t x)
-{
- return util_format_srgb_to_linear_8unorm_table[x];
-}
-
-
-#endif /* U_FORMAT_SRGB_H_ */
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +/** + * @file + * SRGB translation. + * + * @author Brian Paul <brianp@vmware.com> + * @author Michal Krol <michal@vmware.com> + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#ifndef U_FORMAT_SRGB_H_ +#define U_FORMAT_SRGB_H_ + + +#include "pipe/p_compiler.h" +#include "u_math.h" + + +extern const float +util_format_srgb_8unorm_to_linear_float_table[256]; + +extern const uint8_t +util_format_srgb_to_linear_8unorm_table[256]; + +extern const uint8_t +util_format_linear_to_srgb_8unorm_table[256]; + + +/** + * Convert a unclamped linear float to srgb value in the [0,255]. + * XXX this hasn't been tested (render to srgb surface). + * XXX this needs optimization. + */ +static INLINE uint8_t +util_format_linear_float_to_srgb_8unorm(float x) +{ + if (x >= 1.0f) + return 255; + else if (x >= 0.0031308f) + return float_to_ubyte(1.055f * powf(x, 0.41666f) - 0.055f); + else if (x > 0.0f) + return float_to_ubyte(12.92f * x); + else + return 0; +} + + +/** + * 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 float +util_format_srgb_8unorm_to_linear_float(uint8_t x) +{ + return util_format_srgb_8unorm_to_linear_float_table[x]; +} + + +/** + * Convert a 8bit normalized value from linear to srgb. + */ +static INLINE uint8_t +util_format_linear_to_srgb_8unorm(uint8_t x) +{ + return util_format_linear_to_srgb_8unorm_table[x]; +} + + +/** + * Convert a 8bit normalized value from srgb to linear. + */ +static INLINE uint8_t +util_format_srgb_to_linear_8unorm(uint8_t x) +{ + return util_format_srgb_to_linear_8unorm_table[x]; +} + + +#endif /* U_FORMAT_SRGB_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_format_srgb.py b/mesalib/src/gallium/auxiliary/util/u_format_srgb.py index c7b0464d4..cd63ae789 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_srgb.py +++ b/mesalib/src/gallium/auxiliary/util/u_format_srgb.py @@ -1,100 +1,100 @@ -#!/usr/bin/env python
-
-CopyRight = '''
-/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * SRGB translation.
- *
- * @author Brian Paul <brianp@vmware.com>
- * @author Michal Krol <michal@vmware.com>
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-'''
-
-
-import math
-
-
-def srgb_to_linear(x):
- if x <= 0.04045:
- return x / 12.92
- else:
- return math.pow((x + 0.055) / 1.055, 2.4)
-
-
-def linear_to_srgb(x):
- if x >= 0.0031308:
- return 1.055 * math.pow(x, 0.41666) - 0.055
- else:
- return 12.92 * x
-
-def generate_srgb_tables():
- print 'const float'
- print 'util_format_srgb_8unorm_to_linear_float_table[256] = {'
- for j in range(0, 256, 4):
- print ' ',
- for i in range(j, j + 4):
- print '%.7e,' % (srgb_to_linear(i / 255.0),),
- print
- print '};'
- print
- print 'const uint8_t'
- print 'util_format_srgb_to_linear_8unorm_table[256] = {'
- for j in range(0, 256, 16):
- print ' ',
- for i in range(j, j + 16):
- print '%3u,' % (int(srgb_to_linear(i / 255.0) * 255.0 + 0.5),),
- print
- print '};'
- print
- print 'const uint8_t'
- print 'util_format_linear_to_srgb_8unorm_table[256] = {'
- for j in range(0, 256, 16):
- print ' ',
- for i in range(j, j + 16):
- print '%3u,' % (int(linear_to_srgb(i / 255.0) * 255.0 + 0.5),),
- print
- print '};'
- print
-
-
-def main():
- print '/* This file is autogenerated by u_format_srgb.py. Do not edit directly. */'
- print
- # This will print the copyright message on the top of this file
- print CopyRight.strip()
- print
- print '#include "u_format_srgb.h"'
- print
- generate_srgb_tables()
-
-
-if __name__ == '__main__':
- main()
+#!/usr/bin/env python + +CopyRight = ''' +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * SRGB translation. + * + * @author Brian Paul <brianp@vmware.com> + * @author Michal Krol <michal@vmware.com> + * @author Jose Fonseca <jfonseca@vmware.com> + */ +''' + + +import math + + +def srgb_to_linear(x): + if x <= 0.04045: + return x / 12.92 + else: + return math.pow((x + 0.055) / 1.055, 2.4) + + +def linear_to_srgb(x): + if x >= 0.0031308: + return 1.055 * math.pow(x, 0.41666) - 0.055 + else: + return 12.92 * x + +def generate_srgb_tables(): + print 'const float' + print 'util_format_srgb_8unorm_to_linear_float_table[256] = {' + for j in range(0, 256, 4): + print ' ', + for i in range(j, j + 4): + print '%.7e,' % (srgb_to_linear(i / 255.0),), + print + print '};' + print + print 'const uint8_t' + print 'util_format_srgb_to_linear_8unorm_table[256] = {' + for j in range(0, 256, 16): + print ' ', + for i in range(j, j + 16): + print '%3u,' % (int(srgb_to_linear(i / 255.0) * 255.0 + 0.5),), + print + print '};' + print + print 'const uint8_t' + print 'util_format_linear_to_srgb_8unorm_table[256] = {' + for j in range(0, 256, 16): + print ' ', + for i in range(j, j + 16): + print '%3u,' % (int(linear_to_srgb(i / 255.0) * 255.0 + 0.5),), + print + print '};' + print + + +def main(): + print '/* This file is autogenerated by u_format_srgb.py. Do not edit directly. */' + print + # This will print the copyright message on the top of this file + print CopyRight.strip() + print + print '#include "u_format_srgb.h"' + print + generate_srgb_tables() + + +if __name__ == '__main__': + main() diff --git a/mesalib/src/gallium/auxiliary/util/u_format_tests.h b/mesalib/src/gallium/auxiliary/util/u_format_tests.h index 5de1cb237..f59563f4f 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format_tests.h +++ b/mesalib/src/gallium/auxiliary/util/u_format_tests.h @@ -1,71 +1,71 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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 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 COPYRIGHT HOLDERS, 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#ifndef U_FORMAT_TESTS_H_
-#define U_FORMAT_TESTS_H_
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-
-
-#define UTIL_FORMAT_MAX_PACKED_BYTES 16
-#define UTIL_FORMAT_MAX_UNPACKED_WIDTH 4
-#define UTIL_FORMAT_MAX_UNPACKED_HEIGHT 4
-
-
-/**
- * A (packed, unpacked) color pair.
- */
-struct util_format_test_case
-{
- enum pipe_format format;
-
- /**
- * Mask of the bits that actually meaningful data. Used to mask out the
- * "X" channels.
- */
- uint8_t mask[UTIL_FORMAT_MAX_PACKED_BYTES];
-
- uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
-
- /**
- * RGBA.
- */
- double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
-};
-
-
-extern const struct util_format_test_case
-util_format_test_cases[];
-
-
-extern const unsigned util_format_nr_test_cases;
-
-
-#endif /* U_FORMAT_TESTS_H_ */
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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 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 COPYRIGHT HOLDERS, 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_FORMAT_TESTS_H_ +#define U_FORMAT_TESTS_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + + +#define UTIL_FORMAT_MAX_PACKED_BYTES 16 +#define UTIL_FORMAT_MAX_UNPACKED_WIDTH 4 +#define UTIL_FORMAT_MAX_UNPACKED_HEIGHT 4 + + +/** + * A (packed, unpacked) color pair. + */ +struct util_format_test_case +{ + enum pipe_format format; + + /** + * Mask of the bits that actually meaningful data. Used to mask out the + * "X" channels. + */ + uint8_t mask[UTIL_FORMAT_MAX_PACKED_BYTES]; + + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + + /** + * RGBA. + */ + double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; +}; + + +extern const struct util_format_test_case +util_format_test_cases[]; + + +extern const unsigned util_format_nr_test_cases; + + +#endif /* U_FORMAT_TESTS_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_framebuffer.c b/mesalib/src/gallium/auxiliary/util/u_framebuffer.c index 8d89c81c7..7803ec6a8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_framebuffer.c +++ b/mesalib/src/gallium/auxiliary/util/u_framebuffer.c @@ -1,148 +1,148 @@ -/**************************************************************************
- *
- * Copyright 2009-2010 VMware, Inc. 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Framebuffer utility functions.
- *
- * @author Brian Paul
- */
-
-
-#include "pipe/p_screen.h"
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-
-#include "util/u_memory.h"
-#include "util/u_framebuffer.h"
-
-
-/**
- * Compare pipe_framebuffer_state objects.
- * \return TRUE if same, FALSE if different
- */
-boolean
-util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst,
- const struct pipe_framebuffer_state *src)
-{
- unsigned i;
-
- if (dst->width != src->width ||
- dst->height != src->height)
- return FALSE;
-
- for (i = 0; i < Elements(src->cbufs); i++) {
- if (dst->cbufs[i] != src->cbufs[i]) {
- return FALSE;
- }
- }
-
- if (dst->nr_cbufs != src->nr_cbufs) {
- return FALSE;
- }
-
- if (dst->zsbuf != src->zsbuf) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/**
- * Copy framebuffer state from src to dst, updating refcounts.
- */
-void
-util_copy_framebuffer_state(struct pipe_framebuffer_state *dst,
- const struct pipe_framebuffer_state *src)
-{
- unsigned i;
-
- dst->width = src->width;
- dst->height = src->height;
-
- for (i = 0; i < src->nr_cbufs; i++)
- pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]);
-
- for (i = src->nr_cbufs; i < dst->nr_cbufs; i++)
- pipe_surface_reference(&dst->cbufs[i], NULL);
-
- dst->nr_cbufs = src->nr_cbufs;
-
- pipe_surface_reference(&dst->zsbuf, src->zsbuf);
-}
-
-
-void
-util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb)
-{
- unsigned i;
-
- for (i = 0; i < fb->nr_cbufs; i++) {
- pipe_surface_reference(&fb->cbufs[i], NULL);
- }
-
- pipe_surface_reference(&fb->zsbuf, NULL);
-
- fb->width = fb->height = 0;
- fb->nr_cbufs = 0;
-}
-
-
-/* Where multiple sizes are allowed for framebuffer surfaces, find the
- * minimum width and height of all bound surfaces.
- */
-boolean
-util_framebuffer_min_size(const struct pipe_framebuffer_state *fb,
- unsigned *width,
- unsigned *height)
-{
- unsigned w = ~0;
- unsigned h = ~0;
- unsigned i;
-
- for (i = 0; i < fb->nr_cbufs; i++) {
- w = MIN2(w, fb->cbufs[i]->width);
- h = MIN2(h, fb->cbufs[i]->height);
- }
-
- if (fb->zsbuf) {
- w = MIN2(w, fb->zsbuf->width);
- h = MIN2(h, fb->zsbuf->height);
- }
-
- if (w == ~0) {
- *width = 0;
- *height = 0;
- return FALSE;
- }
- else {
- *width = w;
- *height = h;
- return TRUE;
- }
-}
+/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. 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. + * + **************************************************************************/ + +/** + * @file + * Framebuffer utility functions. + * + * @author Brian Paul + */ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "util/u_memory.h" +#include "util/u_framebuffer.h" + + +/** + * Compare pipe_framebuffer_state objects. + * \return TRUE if same, FALSE if different + */ +boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + if (dst->width != src->width || + dst->height != src->height) + return FALSE; + + for (i = 0; i < Elements(src->cbufs); i++) { + if (dst->cbufs[i] != src->cbufs[i]) { + return FALSE; + } + } + + if (dst->nr_cbufs != src->nr_cbufs) { + return FALSE; + } + + if (dst->zsbuf != src->zsbuf) { + return FALSE; + } + + return TRUE; +} + + +/** + * Copy framebuffer state from src to dst, updating refcounts. + */ +void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + dst->width = src->width; + dst->height = src->height; + + for (i = 0; i < src->nr_cbufs; i++) + pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]); + + for (i = src->nr_cbufs; i < dst->nr_cbufs; i++) + pipe_surface_reference(&dst->cbufs[i], NULL); + + dst->nr_cbufs = src->nr_cbufs; + + pipe_surface_reference(&dst->zsbuf, src->zsbuf); +} + + +void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb) +{ + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + pipe_surface_reference(&fb->cbufs[i], NULL); + } + + pipe_surface_reference(&fb->zsbuf, NULL); + + fb->width = fb->height = 0; + fb->nr_cbufs = 0; +} + + +/* Where multiple sizes are allowed for framebuffer surfaces, find the + * minimum width and height of all bound surfaces. + */ +boolean +util_framebuffer_min_size(const struct pipe_framebuffer_state *fb, + unsigned *width, + unsigned *height) +{ + unsigned w = ~0; + unsigned h = ~0; + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + w = MIN2(w, fb->cbufs[i]->width); + h = MIN2(h, fb->cbufs[i]->height); + } + + if (fb->zsbuf) { + w = MIN2(w, fb->zsbuf->width); + h = MIN2(h, fb->zsbuf->height); + } + + if (w == ~0) { + *width = 0; + *height = 0; + return FALSE; + } + else { + *width = w; + *height = h; + return TRUE; + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_framebuffer.h b/mesalib/src/gallium/auxiliary/util/u_framebuffer.h index 346672bc7..e7dc1e9e4 100644 --- a/mesalib/src/gallium/auxiliary/util/u_framebuffer.h +++ b/mesalib/src/gallium/auxiliary/util/u_framebuffer.h @@ -1,54 +1,54 @@ -/**************************************************************************
- *
- * Copyright 2009-2010 VMware, Inc. 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.
- *
- **************************************************************************/
-
-
-#ifndef U_FRAMEBUFFER_H
-#define U_FRAMEBUFFER_H
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-
-extern boolean
-util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst,
- const struct pipe_framebuffer_state *src);
-
-extern void
-util_copy_framebuffer_state(struct pipe_framebuffer_state *dst,
- const struct pipe_framebuffer_state *src);
-
-
-extern void
-util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb);
-
-
-extern boolean
-util_framebuffer_min_size(const struct pipe_framebuffer_state *fb,
- unsigned *width,
- unsigned *height);
-
-#endif /* U_FRAMEBUFFER_H */
+/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. 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. + * + **************************************************************************/ + + +#ifndef U_FRAMEBUFFER_H +#define U_FRAMEBUFFER_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + + +extern boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + +extern void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + + +extern void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb); + + +extern boolean +util_framebuffer_min_size(const struct pipe_framebuffer_state *fb, + unsigned *width, + unsigned *height); + +#endif /* U_FRAMEBUFFER_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_half.h b/mesalib/src/gallium/auxiliary/util/u_half.h index b19527981..ad030e90c 100644 --- a/mesalib/src/gallium/auxiliary/util/u_half.h +++ b/mesalib/src/gallium/auxiliary/util/u_half.h @@ -1,90 +1,90 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-
-#ifndef U_HALF_H
-#define U_HALF_H
-
-#include "pipe/p_compiler.h"
-#include "util/u_math.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const uint32_t util_half_to_float_mantissa_table[2048];
-extern const uint32_t util_half_to_float_exponent_table[64];
-extern const uint32_t util_half_to_float_offset_table[64];
-extern const uint16_t util_float_to_half_base_table[512];
-extern const uint8_t util_float_to_half_shift_table[512];
-
-/*
- * Note that if the half float is a signaling NaN, the x87 FPU will turn
- * it into a quiet NaN immediately upon loading into a float.
- *
- * Additionally, denormals may be flushed to zero.
- *
- * To avoid this, use the floatui functions instead of the float ones
- * when just doing conversion rather than computation on the resulting
- * floats.
- */
-
-static INLINE uint32_t
-util_half_to_floatui(uint16_t h)
-{
- unsigned exp = h >> 10;
- return util_half_to_float_mantissa_table[util_half_to_float_offset_table[exp] + (h & 0x3ff)] + util_half_to_float_exponent_table[exp];
-}
-
-static INLINE float
-util_half_to_float(uint16_t h)
-{
- union fi r;
- r.ui = util_half_to_floatui(h);
- return r.f;
-}
-
-static INLINE uint16_t
-util_floatui_to_half(uint32_t v)
-{
- unsigned signexp = v >> 23;
- return util_float_to_half_base_table[signexp] + ((v & 0x007fffff) >> util_float_to_half_shift_table[signexp]);
-}
-
-static INLINE uint16_t
-util_float_to_half(float f)
-{
- union fi i;
- i.f = f;
- return util_floatui_to_half(i.ui);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_HALF_H */
-
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + + +#ifndef U_HALF_H +#define U_HALF_H + +#include "pipe/p_compiler.h" +#include "util/u_math.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const uint32_t util_half_to_float_mantissa_table[2048]; +extern const uint32_t util_half_to_float_exponent_table[64]; +extern const uint32_t util_half_to_float_offset_table[64]; +extern const uint16_t util_float_to_half_base_table[512]; +extern const uint8_t util_float_to_half_shift_table[512]; + +/* + * Note that if the half float is a signaling NaN, the x87 FPU will turn + * it into a quiet NaN immediately upon loading into a float. + * + * Additionally, denormals may be flushed to zero. + * + * To avoid this, use the floatui functions instead of the float ones + * when just doing conversion rather than computation on the resulting + * floats. + */ + +static INLINE uint32_t +util_half_to_floatui(uint16_t h) +{ + unsigned exp = h >> 10; + return util_half_to_float_mantissa_table[util_half_to_float_offset_table[exp] + (h & 0x3ff)] + util_half_to_float_exponent_table[exp]; +} + +static INLINE float +util_half_to_float(uint16_t h) +{ + union fi r; + r.ui = util_half_to_floatui(h); + return r.f; +} + +static INLINE uint16_t +util_floatui_to_half(uint32_t v) +{ + unsigned signexp = v >> 23; + return util_float_to_half_base_table[signexp] + ((v & 0x007fffff) >> util_float_to_half_shift_table[signexp]); +} + +static INLINE uint16_t +util_float_to_half(float f) +{ + union fi i; + i.f = f; + return util_floatui_to_half(i.ui); +} + +#ifdef __cplusplus +} +#endif + +#endif /* U_HALF_H */ + diff --git a/mesalib/src/gallium/auxiliary/util/u_half.py b/mesalib/src/gallium/auxiliary/util/u_half.py index 88ee43c25..915cf3b92 100644 --- a/mesalib/src/gallium/auxiliary/util/u_half.py +++ b/mesalib/src/gallium/auxiliary/util/u_half.py @@ -1,179 +1,179 @@ -# Copyright 2010 Luca Barbieri
-#
-# 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 COPYRIGHT OWNER(S) 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.
-#
-# *************************************************************************
-
-# The code is a reimplementation of the algorithm in
-# www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
-# "Fast Half Float Conversions" by Jeroen van der Zijp, Nov 2008
-#
-# The table contents have been slightly changed so that the exponent
-# bias is now in the exponent table instead of the mantissa table (mostly
-# for cosmetic reasons, and because it theoretically allows a variant
-# that flushes denormal to zero but uses a mantissa table with 24-bit
-# entries).
-#
-# The tables are also constructed slightly differently.
-#
-
-# Note that using a 64K * 4 table is a terrible idea since it will not fit
-# in the L1 cache and will massively pollute the L2 cache as well
-#
-# These should instead fit in the L1 cache.
-#
-# TODO: we could use a denormal bias table instead of the mantissa/offset
-# tables: this would reduce the L1 cache usage from 8704 to 2304 bytes
-# but would involve more computation
-#
-# Note however that if denormals are never encountered, the L1 cache usage
-# is only about 4608 bytes anyway.
-
-table_index = None
-table_length = None
-
-def begin(t, n, l):
- global table_length
- global table_index
- table_index = 0
- table_length = l
- print
- print "const " + t + " " + n + "[" + str(l) + "] = {"
-
-def value(v):
- global table_index
- table_index += 1
- print "\t" + hex(v) + ","
-
-def end():
- global table_length
- global table_index
- print "};"
- assert table_index == table_length
-
-print "/* This file is autogenerated by u_half.py. Do not edit directly. */"
-print "#include \"util/u_half.h\""
-
-begin("uint32_t", "util_half_to_float_mantissa_table", 2048)
-# zero
-value(0)
-
-# denormals
-for i in xrange(1, 1024):
- m = i << 13
- e = 0
-
- # normalize number
- while (m & 0x00800000) == 0:
- e -= 0x00800000
- m <<= 1
-
- m &= ~0x00800000
- e += 0x38800000
- value(m | e)
-
-# normals
-for i in xrange(1024, 2048):
- value((i - 1024) << 13)
-end()
-
-begin("uint32_t", "util_half_to_float_exponent_table", 64)
-# positive zero or denormals
-value(0)
-
-# positive numbers
-for i in xrange(1, 31):
- value(0x38000000 + (i << 23))
-
-# positive infinity/NaN
-value(0x7f800000)
-
-# negative zero or denormals
-value(0x80000000)
-
-# negative numbers
-for i in range(33, 63):
- value(0xb8000000 + ((i - 32) << 23))
-
-# negative infinity/NaN
-value(0xff800000)
-end()
-
-begin("uint32_t", "util_half_to_float_offset_table", 64)
-# positive zero or denormals
-value(0)
-
-# positive normals
-for i in range(1, 32):
- value(1024)
-
-# negative zero or denormals
-value(0)
-
-# negative normals
-for i in xrange(33, 64):
- value(1024)
-end()
-
-begin("uint16_t", "util_float_to_half_base_table", 512)
-for sign in (0, 0x8000):
- # very small numbers mapping to zero
- for i in xrange(-127, -24):
- value(sign | 0)
-
- # small numbers mapping to denormals
- for i in xrange(-24, -14):
- value(sign | (0x400 >> (-14 -i)))
-
- # normal numbers
- for i in xrange(-14, 16):
- value(sign | ((i + 15) << 10))
-
- # large numbers mapping to infinity
- for i in xrange(16, 128):
- value(sign | 0x7c00)
-
- # infinity and NaNs
- value(sign | 0x7c00)
-end()
-
-begin("uint8_t", "util_float_to_half_shift_table", 512)
-for sign in (0, 0x8000):
- # very small numbers mapping to zero
- for i in xrange(-127, -24):
- value(24)
-
- # small numbers mapping to denormals
- for i in xrange(-24, -14):
- value(-1 - i)
-
- # normal numbers
- for i in xrange(-14, 16):
- value(13)
-
- # large numbers mapping to infinity
- for i in xrange(16, 128):
- value(24)
-
- # infinity and NaNs
- value(13)
-end()
-
+# Copyright 2010 Luca Barbieri +# +# 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 COPYRIGHT OWNER(S) 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. +# +# ************************************************************************* + +# The code is a reimplementation of the algorithm in +# www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf +# "Fast Half Float Conversions" by Jeroen van der Zijp, Nov 2008 +# +# The table contents have been slightly changed so that the exponent +# bias is now in the exponent table instead of the mantissa table (mostly +# for cosmetic reasons, and because it theoretically allows a variant +# that flushes denormal to zero but uses a mantissa table with 24-bit +# entries). +# +# The tables are also constructed slightly differently. +# + +# Note that using a 64K * 4 table is a terrible idea since it will not fit +# in the L1 cache and will massively pollute the L2 cache as well +# +# These should instead fit in the L1 cache. +# +# TODO: we could use a denormal bias table instead of the mantissa/offset +# tables: this would reduce the L1 cache usage from 8704 to 2304 bytes +# but would involve more computation +# +# Note however that if denormals are never encountered, the L1 cache usage +# is only about 4608 bytes anyway. + +table_index = None +table_length = None + +def begin(t, n, l): + global table_length + global table_index + table_index = 0 + table_length = l + print + print "const " + t + " " + n + "[" + str(l) + "] = {" + +def value(v): + global table_index + table_index += 1 + print "\t" + hex(v) + "," + +def end(): + global table_length + global table_index + print "};" + assert table_index == table_length + +print "/* This file is autogenerated by u_half.py. Do not edit directly. */" +print "#include \"util/u_half.h\"" + +begin("uint32_t", "util_half_to_float_mantissa_table", 2048) +# zero +value(0) + +# denormals +for i in xrange(1, 1024): + m = i << 13 + e = 0 + + # normalize number + while (m & 0x00800000) == 0: + e -= 0x00800000 + m <<= 1 + + m &= ~0x00800000 + e += 0x38800000 + value(m | e) + +# normals +for i in xrange(1024, 2048): + value((i - 1024) << 13) +end() + +begin("uint32_t", "util_half_to_float_exponent_table", 64) +# positive zero or denormals +value(0) + +# positive numbers +for i in xrange(1, 31): + value(0x38000000 + (i << 23)) + +# positive infinity/NaN +value(0x7f800000) + +# negative zero or denormals +value(0x80000000) + +# negative numbers +for i in range(33, 63): + value(0xb8000000 + ((i - 32) << 23)) + +# negative infinity/NaN +value(0xff800000) +end() + +begin("uint32_t", "util_half_to_float_offset_table", 64) +# positive zero or denormals +value(0) + +# positive normals +for i in range(1, 32): + value(1024) + +# negative zero or denormals +value(0) + +# negative normals +for i in xrange(33, 64): + value(1024) +end() + +begin("uint16_t", "util_float_to_half_base_table", 512) +for sign in (0, 0x8000): + # very small numbers mapping to zero + for i in xrange(-127, -24): + value(sign | 0) + + # small numbers mapping to denormals + for i in xrange(-24, -14): + value(sign | (0x400 >> (-14 -i))) + + # normal numbers + for i in xrange(-14, 16): + value(sign | ((i + 15) << 10)) + + # large numbers mapping to infinity + for i in xrange(16, 128): + value(sign | 0x7c00) + + # infinity and NaNs + value(sign | 0x7c00) +end() + +begin("uint8_t", "util_float_to_half_shift_table", 512) +for sign in (0, 0x8000): + # very small numbers mapping to zero + for i in xrange(-127, -24): + value(24) + + # small numbers mapping to denormals + for i in xrange(-24, -14): + value(-1 - i) + + # normal numbers + for i in xrange(-14, 16): + value(13) + + # large numbers mapping to infinity + for i in xrange(16, 128): + value(24) + + # infinity and NaNs + value(13) +end() + diff --git a/mesalib/src/gallium/auxiliary/util/u_handle_table.c b/mesalib/src/gallium/auxiliary/util/u_handle_table.c index 532d1ea6c..3703718a6 100644 --- a/mesalib/src/gallium/auxiliary/util/u_handle_table.c +++ b/mesalib/src/gallium/auxiliary/util/u_handle_table.c @@ -1,298 +1,298 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Generic handle table implementation.
- *
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-
-#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "util/u_memory.h"
-#include "util/u_handle_table.h"
-
-
-#define HANDLE_TABLE_INITIAL_SIZE 16
-
-
-struct handle_table
-{
- /** Object array. Empty handles have a null object */
- void **objects;
-
- /** Number of objects the handle can currently hold */
- unsigned size;
- /** Number of consecutive objects allocated at the start of the table */
- unsigned filled;
-
- /** Optional object destructor */
- void (*destroy)(void *object);
-};
-
-
-struct handle_table *
-handle_table_create(void)
-{
- struct handle_table *ht;
-
- ht = MALLOC_STRUCT(handle_table);
- if(!ht)
- return NULL;
-
- ht->objects = (void **)CALLOC(HANDLE_TABLE_INITIAL_SIZE, sizeof(void *));
- if(!ht->objects) {
- FREE(ht);
- return NULL;
- }
-
- ht->size = HANDLE_TABLE_INITIAL_SIZE;
- ht->filled = 0;
-
- ht->destroy = NULL;
-
- return ht;
-}
-
-
-void
-handle_table_set_destroy(struct handle_table *ht,
- void (*destroy)(void *object))
-{
- assert(ht);
- if (!ht)
- return;
- ht->destroy = destroy;
-}
-
-
-/**
- * Resize the table if necessary
- */
-static INLINE int
-handle_table_resize(struct handle_table *ht,
- unsigned minimum_size)
-{
- unsigned new_size;
- void **new_objects;
-
- if(ht->size > minimum_size)
- return ht->size;
-
- new_size = ht->size;
- while(!(new_size > minimum_size))
- new_size *= 2;
- assert(new_size);
-
- new_objects = (void **)REALLOC((void *)ht->objects,
- ht->size*sizeof(void *),
- new_size*sizeof(void *));
- if(!new_objects)
- return 0;
-
- memset(new_objects + ht->size, 0, (new_size - ht->size)*sizeof(void *));
-
- ht->size = new_size;
- ht->objects = new_objects;
-
- return ht->size;
-}
-
-
-static INLINE void
-handle_table_clear(struct handle_table *ht,
- unsigned index)
-{
- void *object;
-
- /* The order here is important so that the object being destroyed is not
- * present in the table when seen by the destroy callback, because the
- * destroy callback may directly or indirectly call the other functions in
- * this module.
- */
-
- object = ht->objects[index];
- if(object) {
- ht->objects[index] = NULL;
-
- if(ht->destroy)
- ht->destroy(object);
- }
-}
-
-
-unsigned
-handle_table_add(struct handle_table *ht,
- void *object)
-{
- unsigned index;
- unsigned handle;
-
- assert(ht);
- assert(object);
- if(!object || !ht)
- return 0;
-
- /* linear search for an empty handle */
- while(ht->filled < ht->size) {
- if(!ht->objects[ht->filled])
- break;
- ++ht->filled;
- }
-
- index = ht->filled;
- handle = index + 1;
-
- /* check integer overflow */
- if(!handle)
- return 0;
-
- /* grow the table if necessary */
- if(!handle_table_resize(ht, index))
- return 0;
-
- assert(!ht->objects[index]);
- ht->objects[index] = object;
- ++ht->filled;
-
- return handle;
-}
-
-
-unsigned
-handle_table_set(struct handle_table *ht,
- unsigned handle,
- void *object)
-{
- unsigned index;
-
- assert(ht);
- assert(handle);
- if(!handle || !ht)
- return 0;
-
- assert(object);
- if(!object)
- return 0;
-
- index = handle - 1;
-
- /* grow the table if necessary */
- if(!handle_table_resize(ht, index))
- return 0;
-
- handle_table_clear(ht, index);
-
- ht->objects[index] = object;
-
- return handle;
-}
-
-
-void *
-handle_table_get(struct handle_table *ht,
- unsigned handle)
-{
- void *object;
-
- assert(ht);
- assert(handle);
- if(!handle || !ht || handle > ht->size)
- return NULL;
-
- object = ht->objects[handle - 1];
-
- return object;
-}
-
-
-void
-handle_table_remove(struct handle_table *ht,
- unsigned handle)
-{
- void *object;
- unsigned index;
-
- assert(ht);
- assert(handle);
- if(!handle || !ht || handle > ht->size)
- return;
-
- index = handle - 1;
- object = ht->objects[index];
- if(!object)
- return;
-
- handle_table_clear(ht, index);
-
- if(index < ht->filled)
- ht->filled = index;
-}
-
-
-unsigned
-handle_table_get_next_handle(struct handle_table *ht,
- unsigned handle)
-{
- unsigned index;
-
- for(index = handle; index < ht->size; ++index) {
- if(ht->objects[index])
- return index + 1;
- }
-
- return 0;
-}
-
-
-unsigned
-handle_table_get_first_handle(struct handle_table *ht)
-{
- return handle_table_get_next_handle(ht, 0);
-}
-
-
-void
-handle_table_destroy(struct handle_table *ht)
-{
- unsigned index;
- assert(ht);
-
- if (!ht)
- return;
-
- if(ht->destroy)
- for(index = 0; index < ht->size; ++index)
- handle_table_clear(ht, index);
-
- FREE(ht->objects);
- FREE(ht);
-}
-
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * Generic handle table implementation. + * + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_memory.h" +#include "util/u_handle_table.h" + + +#define HANDLE_TABLE_INITIAL_SIZE 16 + + +struct handle_table +{ + /** Object array. Empty handles have a null object */ + void **objects; + + /** Number of objects the handle can currently hold */ + unsigned size; + /** Number of consecutive objects allocated at the start of the table */ + unsigned filled; + + /** Optional object destructor */ + void (*destroy)(void *object); +}; + + +struct handle_table * +handle_table_create(void) +{ + struct handle_table *ht; + + ht = MALLOC_STRUCT(handle_table); + if(!ht) + return NULL; + + ht->objects = (void **)CALLOC(HANDLE_TABLE_INITIAL_SIZE, sizeof(void *)); + if(!ht->objects) { + FREE(ht); + return NULL; + } + + ht->size = HANDLE_TABLE_INITIAL_SIZE; + ht->filled = 0; + + ht->destroy = NULL; + + return ht; +} + + +void +handle_table_set_destroy(struct handle_table *ht, + void (*destroy)(void *object)) +{ + assert(ht); + if (!ht) + return; + ht->destroy = destroy; +} + + +/** + * Resize the table if necessary + */ +static INLINE int +handle_table_resize(struct handle_table *ht, + unsigned minimum_size) +{ + unsigned new_size; + void **new_objects; + + if(ht->size > minimum_size) + return ht->size; + + new_size = ht->size; + while(!(new_size > minimum_size)) + new_size *= 2; + assert(new_size); + + new_objects = (void **)REALLOC((void *)ht->objects, + ht->size*sizeof(void *), + new_size*sizeof(void *)); + if(!new_objects) + return 0; + + memset(new_objects + ht->size, 0, (new_size - ht->size)*sizeof(void *)); + + ht->size = new_size; + ht->objects = new_objects; + + return ht->size; +} + + +static INLINE void +handle_table_clear(struct handle_table *ht, + unsigned index) +{ + void *object; + + /* The order here is important so that the object being destroyed is not + * present in the table when seen by the destroy callback, because the + * destroy callback may directly or indirectly call the other functions in + * this module. + */ + + object = ht->objects[index]; + if(object) { + ht->objects[index] = NULL; + + if(ht->destroy) + ht->destroy(object); + } +} + + +unsigned +handle_table_add(struct handle_table *ht, + void *object) +{ + unsigned index; + unsigned handle; + + assert(ht); + assert(object); + if(!object || !ht) + return 0; + + /* linear search for an empty handle */ + while(ht->filled < ht->size) { + if(!ht->objects[ht->filled]) + break; + ++ht->filled; + } + + index = ht->filled; + handle = index + 1; + + /* check integer overflow */ + if(!handle) + return 0; + + /* grow the table if necessary */ + if(!handle_table_resize(ht, index)) + return 0; + + assert(!ht->objects[index]); + ht->objects[index] = object; + ++ht->filled; + + return handle; +} + + +unsigned +handle_table_set(struct handle_table *ht, + unsigned handle, + void *object) +{ + unsigned index; + + assert(ht); + assert(handle); + if(!handle || !ht) + return 0; + + assert(object); + if(!object) + return 0; + + index = handle - 1; + + /* grow the table if necessary */ + if(!handle_table_resize(ht, index)) + return 0; + + handle_table_clear(ht, index); + + ht->objects[index] = object; + + return handle; +} + + +void * +handle_table_get(struct handle_table *ht, + unsigned handle) +{ + void *object; + + assert(ht); + assert(handle); + if(!handle || !ht || handle > ht->size) + return NULL; + + object = ht->objects[handle - 1]; + + return object; +} + + +void +handle_table_remove(struct handle_table *ht, + unsigned handle) +{ + void *object; + unsigned index; + + assert(ht); + assert(handle); + if(!handle || !ht || handle > ht->size) + return; + + index = handle - 1; + object = ht->objects[index]; + if(!object) + return; + + handle_table_clear(ht, index); + + if(index < ht->filled) + ht->filled = index; +} + + +unsigned +handle_table_get_next_handle(struct handle_table *ht, + unsigned handle) +{ + unsigned index; + + for(index = handle; index < ht->size; ++index) { + if(ht->objects[index]) + return index + 1; + } + + return 0; +} + + +unsigned +handle_table_get_first_handle(struct handle_table *ht) +{ + return handle_table_get_next_handle(ht, 0); +} + + +void +handle_table_destroy(struct handle_table *ht) +{ + unsigned index; + assert(ht); + + if (!ht) + return; + + if(ht->destroy) + for(index = 0; index < ht->size; ++index) + handle_table_clear(ht, index); + + FREE(ht->objects); + FREE(ht); +} + diff --git a/mesalib/src/gallium/auxiliary/util/u_handle_table.h b/mesalib/src/gallium/auxiliary/util/u_handle_table.h index a7320830e..d080135c9 100644 --- a/mesalib/src/gallium/auxiliary/util/u_handle_table.h +++ b/mesalib/src/gallium/auxiliary/util/u_handle_table.h @@ -1,116 +1,116 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Generic handle table.
- *
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-#ifndef U_HANDLE_TABLE_H_
-#define U_HANDLE_TABLE_H_
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
- * Abstract data type to map integer handles to objects.
- *
- * Also referred as "pointer array".
- */
-struct handle_table;
-
-
-struct handle_table *
-handle_table_create(void);
-
-
-/**
- * Set an optional destructor callback.
- *
- * If set, it will be called during handle_table_remove and
- * handle_table_destroy calls.
- */
-void
-handle_table_set_destroy(struct handle_table *ht,
- void (*destroy)(void *object));
-
-
-/**
- * Add a new object.
- *
- * Returns a zero handle on failure (out of memory).
- */
-unsigned
-handle_table_add(struct handle_table *ht,
- void *object);
-
-/**
- * Returns zero on failure (out of memory).
- */
-unsigned
-handle_table_set(struct handle_table *ht,
- unsigned handle,
- void *object);
-
-/**
- * Fetch an existing object.
- *
- * Returns NULL for an invalid handle.
- */
-void *
-handle_table_get(struct handle_table *ht,
- unsigned handle);
-
-
-void
-handle_table_remove(struct handle_table *ht,
- unsigned handle);
-
-
-void
-handle_table_destroy(struct handle_table *ht);
-
-
-unsigned
-handle_table_get_first_handle(struct handle_table *ht);
-
-
-unsigned
-handle_table_get_next_handle(struct handle_table *ht,
- unsigned handle);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_HANDLE_TABLE_H_ */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * Generic handle table. + * + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef U_HANDLE_TABLE_H_ +#define U_HANDLE_TABLE_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Abstract data type to map integer handles to objects. + * + * Also referred as "pointer array". + */ +struct handle_table; + + +struct handle_table * +handle_table_create(void); + + +/** + * Set an optional destructor callback. + * + * If set, it will be called during handle_table_remove and + * handle_table_destroy calls. + */ +void +handle_table_set_destroy(struct handle_table *ht, + void (*destroy)(void *object)); + + +/** + * Add a new object. + * + * Returns a zero handle on failure (out of memory). + */ +unsigned +handle_table_add(struct handle_table *ht, + void *object); + +/** + * Returns zero on failure (out of memory). + */ +unsigned +handle_table_set(struct handle_table *ht, + unsigned handle, + void *object); + +/** + * Fetch an existing object. + * + * Returns NULL for an invalid handle. + */ +void * +handle_table_get(struct handle_table *ht, + unsigned handle); + + +void +handle_table_remove(struct handle_table *ht, + unsigned handle); + + +void +handle_table_destroy(struct handle_table *ht); + + +unsigned +handle_table_get_first_handle(struct handle_table *ht); + + +unsigned +handle_table_get_next_handle(struct handle_table *ht, + unsigned handle); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HANDLE_TABLE_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_hash.c b/mesalib/src/gallium/auxiliary/util/u_hash.c index e0400c277..b67653ec7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_hash.c +++ b/mesalib/src/gallium/auxiliary/util/u_hash.c @@ -1,121 +1,121 @@ -/**************************************************************************
- *
- * Copyright 2008 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Hash functions implementation.
- *
- * @author Jose Fonseca
- */
-
-
-#include "u_hash.h"
-
-
-static const uint32_t
-util_crc32_table[256] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
-};
-
-
-/**
- * @sa http://www.w3.org/TR/PNG/#D-CRCAppendix
- */
-uint32_t
-util_hash_crc32(const void *data, size_t size)
-{
- uint8_t *p = (uint8_t *)data;
- uint32_t crc = 0xffffffff;
-
- while (size--)
- crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
-
- return crc;
-}
+/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Hash functions implementation. + * + * @author Jose Fonseca + */ + + +#include "u_hash.h" + + +static const uint32_t +util_crc32_table[256] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + + +/** + * @sa http://www.w3.org/TR/PNG/#D-CRCAppendix + */ +uint32_t +util_hash_crc32(const void *data, size_t size) +{ + uint8_t *p = (uint8_t *)data; + uint32_t crc = 0xffffffff; + + while (size--) + crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); + + return crc; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_hash.h b/mesalib/src/gallium/auxiliary/util/u_hash.h index feda08217..8d92b07c8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_hash.h +++ b/mesalib/src/gallium/auxiliary/util/u_hash.h @@ -1,55 +1,55 @@ -/**************************************************************************
- *
- * Copyright 2008 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Hash functions.
- *
- * @author Jose Fonseca <jfonseca@vmware.com>
- */
-
-#ifndef U_HASH_H_
-#define U_HASH_H_
-
-
-#include "pipe/p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-uint32_t
-util_hash_crc32(const void *data, size_t size);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_HASH_H_ */
+/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * @file + * Hash functions. + * + * @author Jose Fonseca <jfonseca@vmware.com> + */ + +#ifndef U_HASH_H_ +#define U_HASH_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +uint32_t +util_hash_crc32(const void *data, size_t size); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HASH_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_hash_table.c b/mesalib/src/gallium/auxiliary/util/u_hash_table.c index 417cc15be..5604e3ac3 100644 --- a/mesalib/src/gallium/auxiliary/util/u_hash_table.c +++ b/mesalib/src/gallium/auxiliary/util/u_hash_table.c @@ -1,293 +1,293 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * General purpose hash table implementation.
- *
- * Just uses the cso_hash for now, but it might be better switch to a linear
- * probing hash table implementation at some point -- as it is said they have
- * better lookup and cache performance and it appears to be possible to write
- * a lock-free implementation of such hash tables .
- *
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-
-#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "cso_cache/cso_hash.h"
-
-#include "util/u_memory.h"
-#include "util/u_hash_table.h"
-
-
-struct util_hash_table
-{
- struct cso_hash *cso;
-
- /** Hash function */
- unsigned (*hash)(void *key);
-
- /** Compare two keys */
- int (*compare)(void *key1, void *key2);
-
- /* TODO: key, value destructors? */
-};
-
-
-struct util_hash_table_item
-{
- void *key;
- void *value;
-};
-
-
-static INLINE struct util_hash_table_item *
-util_hash_table_item(struct cso_hash_iter iter)
-{
- return (struct util_hash_table_item *)cso_hash_iter_data(iter);
-}
-
-
-struct util_hash_table *
-util_hash_table_create(unsigned (*hash)(void *key),
- int (*compare)(void *key1, void *key2))
-{
- struct util_hash_table *ht;
-
- ht = MALLOC_STRUCT(util_hash_table);
- if(!ht)
- return NULL;
-
- ht->cso = cso_hash_create();
- if(!ht->cso) {
- FREE(ht);
- return NULL;
- }
-
- ht->hash = hash;
- ht->compare = compare;
-
- return ht;
-}
-
-
-static INLINE struct cso_hash_iter
-util_hash_table_find_iter(struct util_hash_table *ht,
- void *key,
- unsigned key_hash)
-{
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
-
- iter = cso_hash_find(ht->cso, key_hash);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
- if (!ht->compare(item->key, key))
- break;
- iter = cso_hash_iter_next(iter);
- }
-
- return iter;
-}
-
-
-static INLINE struct util_hash_table_item *
-util_hash_table_find_item(struct util_hash_table *ht,
- void *key,
- unsigned key_hash)
-{
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
-
- iter = cso_hash_find(ht->cso, key_hash);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
- if (!ht->compare(item->key, key))
- return item;
- iter = cso_hash_iter_next(iter);
- }
-
- return NULL;
-}
-
-
-enum pipe_error
-util_hash_table_set(struct util_hash_table *ht,
- void *key,
- void *value)
-{
- unsigned key_hash;
- struct util_hash_table_item *item;
- struct cso_hash_iter iter;
-
- assert(ht);
- if (!ht)
- return PIPE_ERROR_BAD_INPUT;
-
- key_hash = ht->hash(key);
-
- item = util_hash_table_find_item(ht, key, key_hash);
- if(item) {
- /* TODO: key/value destruction? */
- item->value = value;
- return PIPE_OK;
- }
-
- item = MALLOC_STRUCT(util_hash_table_item);
- if(!item)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- item->key = key;
- item->value = value;
-
- iter = cso_hash_insert(ht->cso, key_hash, item);
- if(cso_hash_iter_is_null(iter)) {
- FREE(item);
- return PIPE_ERROR_OUT_OF_MEMORY;
- }
-
- return PIPE_OK;
-}
-
-
-void *
-util_hash_table_get(struct util_hash_table *ht,
- void *key)
-{
- unsigned key_hash;
- struct util_hash_table_item *item;
-
- assert(ht);
- if (!ht)
- return NULL;
-
- key_hash = ht->hash(key);
-
- item = util_hash_table_find_item(ht, key, key_hash);
- if(!item)
- return NULL;
-
- return item->value;
-}
-
-
-void
-util_hash_table_remove(struct util_hash_table *ht,
- void *key)
-{
- unsigned key_hash;
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
-
- assert(ht);
- if (!ht)
- return;
-
- key_hash = ht->hash(key);
-
- iter = util_hash_table_find_iter(ht, key, key_hash);
- if(cso_hash_iter_is_null(iter))
- return;
-
- item = util_hash_table_item(iter);
- assert(item);
- FREE(item);
-
- cso_hash_erase(ht->cso, iter);
-}
-
-
-void
-util_hash_table_clear(struct util_hash_table *ht)
-{
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
-
- assert(ht);
- if (!ht)
- return;
-
- iter = cso_hash_first_node(ht->cso);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter));
- FREE(item);
- iter = cso_hash_first_node(ht->cso);
- }
-}
-
-
-enum pipe_error
-util_hash_table_foreach(struct util_hash_table *ht,
- enum pipe_error (*callback)
- (void *key, void *value, void *data),
- void *data)
-{
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
- enum pipe_error result;
-
- assert(ht);
- if (!ht)
- return PIPE_ERROR_BAD_INPUT;
-
- iter = cso_hash_first_node(ht->cso);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
- result = callback(item->key, item->value, data);
- if(result != PIPE_OK)
- return result;
- iter = cso_hash_iter_next(iter);
- }
-
- return PIPE_OK;
-}
-
-
-void
-util_hash_table_destroy(struct util_hash_table *ht)
-{
- struct cso_hash_iter iter;
- struct util_hash_table_item *item;
-
- assert(ht);
- if (!ht)
- return;
-
- iter = cso_hash_first_node(ht->cso);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
- FREE(item);
- iter = cso_hash_iter_next(iter);
- }
-
- cso_hash_delete(ht->cso);
-
- FREE(ht);
-}
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * General purpose hash table implementation. + * + * Just uses the cso_hash for now, but it might be better switch to a linear + * probing hash table implementation at some point -- as it is said they have + * better lookup and cache performance and it appears to be possible to write + * a lock-free implementation of such hash tables . + * + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "cso_cache/cso_hash.h" + +#include "util/u_memory.h" +#include "util/u_hash_table.h" + + +struct util_hash_table +{ + struct cso_hash *cso; + + /** Hash function */ + unsigned (*hash)(void *key); + + /** Compare two keys */ + int (*compare)(void *key1, void *key2); + + /* TODO: key, value destructors? */ +}; + + +struct util_hash_table_item +{ + void *key; + void *value; +}; + + +static INLINE struct util_hash_table_item * +util_hash_table_item(struct cso_hash_iter iter) +{ + return (struct util_hash_table_item *)cso_hash_iter_data(iter); +} + + +struct util_hash_table * +util_hash_table_create(unsigned (*hash)(void *key), + int (*compare)(void *key1, void *key2)) +{ + struct util_hash_table *ht; + + ht = MALLOC_STRUCT(util_hash_table); + if(!ht) + return NULL; + + ht->cso = cso_hash_create(); + if(!ht->cso) { + FREE(ht); + return NULL; + } + + ht->hash = hash; + ht->compare = compare; + + return ht; +} + + +static INLINE struct cso_hash_iter +util_hash_table_find_iter(struct util_hash_table *ht, + void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + iter = cso_hash_find(ht->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + if (!ht->compare(item->key, key)) + break; + iter = cso_hash_iter_next(iter); + } + + return iter; +} + + +static INLINE struct util_hash_table_item * +util_hash_table_find_item(struct util_hash_table *ht, + void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + iter = cso_hash_find(ht->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + if (!ht->compare(item->key, key)) + return item; + iter = cso_hash_iter_next(iter); + } + + return NULL; +} + + +enum pipe_error +util_hash_table_set(struct util_hash_table *ht, + void *key, + void *value) +{ + unsigned key_hash; + struct util_hash_table_item *item; + struct cso_hash_iter iter; + + assert(ht); + if (!ht) + return PIPE_ERROR_BAD_INPUT; + + key_hash = ht->hash(key); + + item = util_hash_table_find_item(ht, key, key_hash); + if(item) { + /* TODO: key/value destruction? */ + item->value = value; + return PIPE_OK; + } + + item = MALLOC_STRUCT(util_hash_table_item); + if(!item) + return PIPE_ERROR_OUT_OF_MEMORY; + + item->key = key; + item->value = value; + + iter = cso_hash_insert(ht->cso, key_hash, item); + if(cso_hash_iter_is_null(iter)) { + FREE(item); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + return PIPE_OK; +} + + +void * +util_hash_table_get(struct util_hash_table *ht, + void *key) +{ + unsigned key_hash; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return NULL; + + key_hash = ht->hash(key); + + item = util_hash_table_find_item(ht, key, key_hash); + if(!item) + return NULL; + + return item->value; +} + + +void +util_hash_table_remove(struct util_hash_table *ht, + void *key) +{ + unsigned key_hash; + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + key_hash = ht->hash(key); + + iter = util_hash_table_find_iter(ht, key, key_hash); + if(cso_hash_iter_is_null(iter)) + return; + + item = util_hash_table_item(iter); + assert(item); + FREE(item); + + cso_hash_erase(ht->cso, iter); +} + + +void +util_hash_table_clear(struct util_hash_table *ht) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter)); + FREE(item); + iter = cso_hash_first_node(ht->cso); + } +} + + +enum pipe_error +util_hash_table_foreach(struct util_hash_table *ht, + enum pipe_error (*callback) + (void *key, void *value, void *data), + void *data) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + enum pipe_error result; + + assert(ht); + if (!ht) + return PIPE_ERROR_BAD_INPUT; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + result = callback(item->key, item->value, data); + if(result != PIPE_OK) + return result; + iter = cso_hash_iter_next(iter); + } + + return PIPE_OK; +} + + +void +util_hash_table_destroy(struct util_hash_table *ht) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + FREE(item); + iter = cso_hash_iter_next(iter); + } + + cso_hash_delete(ht->cso); + + FREE(ht); +} diff --git a/mesalib/src/gallium/auxiliary/util/u_hash_table.h b/mesalib/src/gallium/auxiliary/util/u_hash_table.h index 5b14ff72d..51ec10a80 100644 --- a/mesalib/src/gallium/auxiliary/util/u_hash_table.h +++ b/mesalib/src/gallium/auxiliary/util/u_hash_table.h @@ -1,96 +1,96 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * General purpose hash table.
- *
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-#ifndef U_HASH_TABLE_H_
-#define U_HASH_TABLE_H_
-
-
-#include "pipe/p_defines.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
- * Generic purpose hash table.
- */
-struct util_hash_table;
-
-
-/**
- * Create an hash table.
- *
- * @param hash hash function
- * @param compare should return 0 for two equal keys.
- */
-struct util_hash_table *
-util_hash_table_create(unsigned (*hash)(void *key),
- int (*compare)(void *key1, void *key2));
-
-
-enum pipe_error
-util_hash_table_set(struct util_hash_table *ht,
- void *key,
- void *value);
-
-void *
-util_hash_table_get(struct util_hash_table *ht,
- void *key);
-
-
-void
-util_hash_table_remove(struct util_hash_table *ht,
- void *key);
-
-
-void
-util_hash_table_clear(struct util_hash_table *ht);
-
-
-enum pipe_error
-util_hash_table_foreach(struct util_hash_table *ht,
- enum pipe_error (*callback)
- (void *key, void *value, void *data),
- void *data);
-
-void
-util_hash_table_destroy(struct util_hash_table *ht);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_HASH_TABLE_H_ */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * General purpose hash table. + * + * @author José Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef U_HASH_TABLE_H_ +#define U_HASH_TABLE_H_ + + +#include "pipe/p_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Generic purpose hash table. + */ +struct util_hash_table; + + +/** + * Create an hash table. + * + * @param hash hash function + * @param compare should return 0 for two equal keys. + */ +struct util_hash_table * +util_hash_table_create(unsigned (*hash)(void *key), + int (*compare)(void *key1, void *key2)); + + +enum pipe_error +util_hash_table_set(struct util_hash_table *ht, + void *key, + void *value); + +void * +util_hash_table_get(struct util_hash_table *ht, + void *key); + + +void +util_hash_table_remove(struct util_hash_table *ht, + void *key); + + +void +util_hash_table_clear(struct util_hash_table *ht); + + +enum pipe_error +util_hash_table_foreach(struct util_hash_table *ht, + enum pipe_error (*callback) + (void *key, void *value, void *data), + void *data); + +void +util_hash_table_destroy(struct util_hash_table *ht); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HASH_TABLE_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_init.h b/mesalib/src/gallium/auxiliary/util/u_init.h index a1d4f1b04..7bc356a79 100644 --- a/mesalib/src/gallium/auxiliary/util/u_init.h +++ b/mesalib/src/gallium/auxiliary/util/u_init.h @@ -1,52 +1,52 @@ -/*
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#ifndef U_INIT_H
-#define U_INIT_H
-
-/* Use UTIL_INIT(f) to have f called at program initialization.
- Note that it is only guaranteed to be called if any symbol in the
- .c file it is in sis referenced by the program.
-
- UTIL_INIT functions are called in arbitrary order.
-*/
-
-#ifdef __cplusplus
-/* use a C++ global constructor */
-#define UTIL_INIT(f) struct f##__gctor_t {f##__gctor_t() {x();}} f##__gctor;
-#elif defined(_MSC_VER)
-/* add a pointer to the section where MSVC stores global constructor pointers */
-/* see http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx and
- http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc */
-#pragma section(".CRT$XCU",read)
-#define UTIL_INIT(f) static void __cdecl f##__init(void) {f();}; __declspec(allocate(".CRT$XCU")) void (__cdecl* f##__xcu)(void) = f##__init;
-#elif defined(__GNUC__)
-#define UTIL_INIT(f) static void f##__init(void) __attribute__((constructor)); static void f##__init(void) {f();}
-#else
-#error Unsupported compiler: please find out how to implement global initializers in C on it
-#endif
-
-#endif
-
+/* + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#ifndef U_INIT_H +#define U_INIT_H + +/* Use UTIL_INIT(f) to have f called at program initialization. + Note that it is only guaranteed to be called if any symbol in the + .c file it is in sis referenced by the program. + + UTIL_INIT functions are called in arbitrary order. +*/ + +#ifdef __cplusplus +/* use a C++ global constructor */ +#define UTIL_INIT(f) struct f##__gctor_t {f##__gctor_t() {x();}} f##__gctor; +#elif defined(_MSC_VER) +/* add a pointer to the section where MSVC stores global constructor pointers */ +/* see http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx and + http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc */ +#pragma section(".CRT$XCU",read) +#define UTIL_INIT(f) static void __cdecl f##__init(void) {f();}; __declspec(allocate(".CRT$XCU")) void (__cdecl* f##__xcu)(void) = f##__init; +#elif defined(__GNUC__) +#define UTIL_INIT(f) static void f##__init(void) __attribute__((constructor)); static void f##__init(void) {f();} +#else +#error Unsupported compiler: please find out how to implement global initializers in C on it +#endif + +#endif + diff --git a/mesalib/src/gallium/auxiliary/util/u_keymap.c b/mesalib/src/gallium/auxiliary/util/u_keymap.c index a06478b21..e161ccd88 100644 --- a/mesalib/src/gallium/auxiliary/util/u_keymap.c +++ b/mesalib/src/gallium/auxiliary/util/u_keymap.c @@ -1,318 +1,318 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * Key lookup/associative container.
- *
- * Like Jose's util_hash_table, based on CSO cache code for now.
- *
- * Author: Brian Paul
- */
-
-
-#include "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "cso_cache/cso_hash.h"
-
-#include "util/u_memory.h"
-#include "util/u_keymap.h"
-
-
-struct keymap
-{
- struct cso_hash *cso;
- unsigned key_size;
- unsigned max_entries; /* XXX not obeyed net */
- unsigned num_entries;
- keymap_delete_func delete_func;
-};
-
-
-struct keymap_item
-{
- void *key, *value;
-};
-
-
-/**
- * This the default key-delete function used when the client doesn't
- * provide one.
- */
-static void
-default_delete_func(const struct keymap *map,
- const void *key, void *data, void *user)
-{
- FREE((void*) data);
-}
-
-
-static INLINE struct keymap_item *
-hash_table_item(struct cso_hash_iter iter)
-{
- return (struct keymap_item *) cso_hash_iter_data(iter);
-}
-
-
-/**
- * Return 4-byte hash key for a block of bytes.
- */
-static unsigned
-hash(const void *key, unsigned keySize)
-{
- unsigned i, hash;
-
- keySize /= 4; /* convert from bytes to uints */
-
- hash = 0;
- for (i = 0; i < keySize; i++) {
- hash ^= (i + 1) * ((const unsigned *) key)[i];
- }
-
- /*hash = hash ^ (hash >> 11) ^ (hash >> 22);*/
-
- return hash;
-}
-
-
-/**
- * Create a new map.
- * \param keySize size of the keys in bytes
- * \param maxEntries max number of entries to allow (~0 = infinity)
- * \param deleteFunc optional callback to call when entries
- * are deleted/replaced
- */
-struct keymap *
-util_new_keymap(unsigned keySize, unsigned maxEntries,
- keymap_delete_func deleteFunc)
-{
- struct keymap *map = MALLOC_STRUCT(keymap);
- if (!map)
- return NULL;
-
- map->cso = cso_hash_create();
- if (!map->cso) {
- FREE(map);
- return NULL;
- }
-
- map->max_entries = maxEntries;
- map->num_entries = 0;
- map->key_size = keySize;
- map->delete_func = deleteFunc ? deleteFunc : default_delete_func;
-
- return map;
-}
-
-
-/**
- * Delete/free a keymap and all entries. The deleteFunc that was given at
- * create time will be called for each entry.
- * \param user user-provided pointer passed through to the delete callback
- */
-void
-util_delete_keymap(struct keymap *map, void *user)
-{
- util_keymap_remove_all(map, user);
- cso_hash_delete(map->cso);
- FREE(map);
-}
-
-
-static INLINE struct cso_hash_iter
-hash_table_find_iter(const struct keymap *map, const void *key,
- unsigned key_hash)
-{
- struct cso_hash_iter iter;
- struct keymap_item *item;
-
- iter = cso_hash_find(map->cso, key_hash);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct keymap_item *) cso_hash_iter_data(iter);
- if (!memcmp(item->key, key, map->key_size))
- break;
- iter = cso_hash_iter_next(iter);
- }
-
- return iter;
-}
-
-
-static INLINE struct keymap_item *
-hash_table_find_item(const struct keymap *map, const void *key,
- unsigned key_hash)
-{
- struct cso_hash_iter iter = hash_table_find_iter(map, key, key_hash);
- if (cso_hash_iter_is_null(iter)) {
- return NULL;
- }
- else {
- return hash_table_item(iter);
- }
-}
-
-
-/**
- * Insert a new key + data pointer into the table.
- * Note: we create a copy of the key, but not the data!
- * If the key is already present in the table, replace the existing
- * entry (calling the delete callback on the previous entry).
- * If the maximum capacity of the map is reached an old entry
- * will be deleted (the delete callback will be called).
- */
-boolean
-util_keymap_insert(struct keymap *map, const void *key,
- const void *data, void *user)
-{
- unsigned key_hash;
- struct keymap_item *item;
- struct cso_hash_iter iter;
-
- assert(map);
- if (!map)
- return FALSE;
-
- key_hash = hash(key, map->key_size);
-
- item = hash_table_find_item(map, key, key_hash);
- if (item) {
- /* call delete callback for old entry/item */
- map->delete_func(map, item->key, item->value, user);
- item->value = (void *) data;
- return TRUE;
- }
-
- item = MALLOC_STRUCT(keymap_item);
- if (!item)
- return FALSE;
-
- item->key = mem_dup(key, map->key_size);
- item->value = (void *) data;
-
- iter = cso_hash_insert(map->cso, key_hash, item);
- if (cso_hash_iter_is_null(iter)) {
- FREE(item);
- return FALSE;
- }
-
- map->num_entries++;
-
- return TRUE;
-}
-
-
-/**
- * Look up a key in the map and return the associated data pointer.
- */
-const void *
-util_keymap_lookup(const struct keymap *map, const void *key)
-{
- unsigned key_hash;
- struct keymap_item *item;
-
- assert(map);
- if (!map)
- return NULL;
-
- key_hash = hash(key, map->key_size);
-
- item = hash_table_find_item(map, key, key_hash);
- if (!item)
- return NULL;
-
- return item->value;
-}
-
-
-/**
- * Remove an entry from the map.
- * The delete callback will be called if the given key/entry is found.
- * \param user passed to the delete callback as the last param.
- */
-void
-util_keymap_remove(struct keymap *map, const void *key, void *user)
-{
- unsigned key_hash;
- struct cso_hash_iter iter;
- struct keymap_item *item;
-
- assert(map);
- if (!map)
- return;
-
- key_hash = hash(key, map->key_size);
-
- iter = hash_table_find_iter(map, key, key_hash);
- if (cso_hash_iter_is_null(iter))
- return;
-
- item = hash_table_item(iter);
- assert(item);
- if (!item)
- return;
- map->delete_func(map, item->key, item->value, user);
- FREE(item->key);
- FREE(item);
-
- map->num_entries--;
-
- cso_hash_erase(map->cso, iter);
-}
-
-
-/**
- * Remove all entries from the map, calling the delete callback for each.
- * \param user passed to the delete callback as the last param.
- */
-void
-util_keymap_remove_all(struct keymap *map, void *user)
-{
- struct cso_hash_iter iter;
- struct keymap_item *item;
-
- assert(map);
- if (!map)
- return;
-
- iter = cso_hash_first_node(map->cso);
- while (!cso_hash_iter_is_null(iter)) {
- item = (struct keymap_item *)
- cso_hash_take(map->cso, cso_hash_iter_key(iter));
- map->delete_func(map, item->key, item->value, user);
- FREE(item->key);
- FREE(item);
- iter = cso_hash_first_node(map->cso);
- }
-}
-
-
-extern void
-util_keymap_info(const struct keymap *map)
-{
- debug_printf("Keymap %p: %u of max %u entries\n",
- (void *) map, map->num_entries, map->max_entries);
-}
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * Key lookup/associative container. + * + * Like Jose's util_hash_table, based on CSO cache code for now. + * + * Author: Brian Paul + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "cso_cache/cso_hash.h" + +#include "util/u_memory.h" +#include "util/u_keymap.h" + + +struct keymap +{ + struct cso_hash *cso; + unsigned key_size; + unsigned max_entries; /* XXX not obeyed net */ + unsigned num_entries; + keymap_delete_func delete_func; +}; + + +struct keymap_item +{ + void *key, *value; +}; + + +/** + * This the default key-delete function used when the client doesn't + * provide one. + */ +static void +default_delete_func(const struct keymap *map, + const void *key, void *data, void *user) +{ + FREE((void*) data); +} + + +static INLINE struct keymap_item * +hash_table_item(struct cso_hash_iter iter) +{ + return (struct keymap_item *) cso_hash_iter_data(iter); +} + + +/** + * Return 4-byte hash key for a block of bytes. + */ +static unsigned +hash(const void *key, unsigned keySize) +{ + unsigned i, hash; + + keySize /= 4; /* convert from bytes to uints */ + + hash = 0; + for (i = 0; i < keySize; i++) { + hash ^= (i + 1) * ((const unsigned *) key)[i]; + } + + /*hash = hash ^ (hash >> 11) ^ (hash >> 22);*/ + + return hash; +} + + +/** + * Create a new map. + * \param keySize size of the keys in bytes + * \param maxEntries max number of entries to allow (~0 = infinity) + * \param deleteFunc optional callback to call when entries + * are deleted/replaced + */ +struct keymap * +util_new_keymap(unsigned keySize, unsigned maxEntries, + keymap_delete_func deleteFunc) +{ + struct keymap *map = MALLOC_STRUCT(keymap); + if (!map) + return NULL; + + map->cso = cso_hash_create(); + if (!map->cso) { + FREE(map); + return NULL; + } + + map->max_entries = maxEntries; + map->num_entries = 0; + map->key_size = keySize; + map->delete_func = deleteFunc ? deleteFunc : default_delete_func; + + return map; +} + + +/** + * Delete/free a keymap and all entries. The deleteFunc that was given at + * create time will be called for each entry. + * \param user user-provided pointer passed through to the delete callback + */ +void +util_delete_keymap(struct keymap *map, void *user) +{ + util_keymap_remove_all(map, user); + cso_hash_delete(map->cso); + FREE(map); +} + + +static INLINE struct cso_hash_iter +hash_table_find_iter(const struct keymap *map, const void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct keymap_item *item; + + iter = cso_hash_find(map->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct keymap_item *) cso_hash_iter_data(iter); + if (!memcmp(item->key, key, map->key_size)) + break; + iter = cso_hash_iter_next(iter); + } + + return iter; +} + + +static INLINE struct keymap_item * +hash_table_find_item(const struct keymap *map, const void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter = hash_table_find_iter(map, key, key_hash); + if (cso_hash_iter_is_null(iter)) { + return NULL; + } + else { + return hash_table_item(iter); + } +} + + +/** + * Insert a new key + data pointer into the table. + * Note: we create a copy of the key, but not the data! + * If the key is already present in the table, replace the existing + * entry (calling the delete callback on the previous entry). + * If the maximum capacity of the map is reached an old entry + * will be deleted (the delete callback will be called). + */ +boolean +util_keymap_insert(struct keymap *map, const void *key, + const void *data, void *user) +{ + unsigned key_hash; + struct keymap_item *item; + struct cso_hash_iter iter; + + assert(map); + if (!map) + return FALSE; + + key_hash = hash(key, map->key_size); + + item = hash_table_find_item(map, key, key_hash); + if (item) { + /* call delete callback for old entry/item */ + map->delete_func(map, item->key, item->value, user); + item->value = (void *) data; + return TRUE; + } + + item = MALLOC_STRUCT(keymap_item); + if (!item) + return FALSE; + + item->key = mem_dup(key, map->key_size); + item->value = (void *) data; + + iter = cso_hash_insert(map->cso, key_hash, item); + if (cso_hash_iter_is_null(iter)) { + FREE(item); + return FALSE; + } + + map->num_entries++; + + return TRUE; +} + + +/** + * Look up a key in the map and return the associated data pointer. + */ +const void * +util_keymap_lookup(const struct keymap *map, const void *key) +{ + unsigned key_hash; + struct keymap_item *item; + + assert(map); + if (!map) + return NULL; + + key_hash = hash(key, map->key_size); + + item = hash_table_find_item(map, key, key_hash); + if (!item) + return NULL; + + return item->value; +} + + +/** + * Remove an entry from the map. + * The delete callback will be called if the given key/entry is found. + * \param user passed to the delete callback as the last param. + */ +void +util_keymap_remove(struct keymap *map, const void *key, void *user) +{ + unsigned key_hash; + struct cso_hash_iter iter; + struct keymap_item *item; + + assert(map); + if (!map) + return; + + key_hash = hash(key, map->key_size); + + iter = hash_table_find_iter(map, key, key_hash); + if (cso_hash_iter_is_null(iter)) + return; + + item = hash_table_item(iter); + assert(item); + if (!item) + return; + map->delete_func(map, item->key, item->value, user); + FREE(item->key); + FREE(item); + + map->num_entries--; + + cso_hash_erase(map->cso, iter); +} + + +/** + * Remove all entries from the map, calling the delete callback for each. + * \param user passed to the delete callback as the last param. + */ +void +util_keymap_remove_all(struct keymap *map, void *user) +{ + struct cso_hash_iter iter; + struct keymap_item *item; + + assert(map); + if (!map) + return; + + iter = cso_hash_first_node(map->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct keymap_item *) + cso_hash_take(map->cso, cso_hash_iter_key(iter)); + map->delete_func(map, item->key, item->value, user); + FREE(item->key); + FREE(item); + iter = cso_hash_first_node(map->cso); + } +} + + +extern void +util_keymap_info(const struct keymap *map) +{ + debug_printf("Keymap %p: %u of max %u entries\n", + (void *) map, map->num_entries, map->max_entries); +} diff --git a/mesalib/src/gallium/auxiliary/util/u_keymap.h b/mesalib/src/gallium/auxiliary/util/u_keymap.h index e38e6fec6..8d60a76fc 100644 --- a/mesalib/src/gallium/auxiliary/util/u_keymap.h +++ b/mesalib/src/gallium/auxiliary/util/u_keymap.h @@ -1,68 +1,68 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#ifndef U_KEYMAP_H
-#define U_KEYMAP_H
-
-#include "pipe/p_compiler.h"
-
-
-/** opaque keymap type */
-struct keymap;
-
-
-/** Delete/callback function type */
-typedef void (*keymap_delete_func)(const struct keymap *map,
- const void *key, void *data,
- void *user);
-
-
-extern struct keymap *
-util_new_keymap(unsigned keySize, unsigned maxEntries,
- keymap_delete_func deleteFunc);
-
-extern void
-util_delete_keymap(struct keymap *map, void *user);
-
-extern boolean
-util_keymap_insert(struct keymap *map, const void *key,
- const void *data, void *user);
-
-extern const void *
-util_keymap_lookup(const struct keymap *map, const void *key);
-
-extern void
-util_keymap_remove(struct keymap *map, const void *key, void *user);
-
-extern void
-util_keymap_remove_all(struct keymap *map, void *user);
-
-extern void
-util_keymap_info(const struct keymap *map);
-
-
-#endif /* U_KEYMAP_H */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef U_KEYMAP_H +#define U_KEYMAP_H + +#include "pipe/p_compiler.h" + + +/** opaque keymap type */ +struct keymap; + + +/** Delete/callback function type */ +typedef void (*keymap_delete_func)(const struct keymap *map, + const void *key, void *data, + void *user); + + +extern struct keymap * +util_new_keymap(unsigned keySize, unsigned maxEntries, + keymap_delete_func deleteFunc); + +extern void +util_delete_keymap(struct keymap *map, void *user); + +extern boolean +util_keymap_insert(struct keymap *map, const void *key, + const void *data, void *user); + +extern const void * +util_keymap_lookup(const struct keymap *map, const void *key); + +extern void +util_keymap_remove(struct keymap *map, const void *key, void *user); + +extern void +util_keymap_remove_all(struct keymap *map, void *user); + +extern void +util_keymap_info(const struct keymap *map); + + +#endif /* U_KEYMAP_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_linear.c b/mesalib/src/gallium/auxiliary/util/u_linear.c index 8f8935d8a..f1aef2167 100644 --- a/mesalib/src/gallium/auxiliary/util/u_linear.c +++ b/mesalib/src/gallium/auxiliary/util/u_linear.c @@ -1,101 +1,101 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * Functions for converting tiled data to linear and vice versa.
- */
-
-
-#include "util/u_debug.h"
-#include "u_linear.h"
-
-void
-pipe_linear_to_tile(size_t src_stride, const void *src_ptr,
- struct pipe_tile_info *t, void *dst_ptr)
-{
- int x, y, z;
- char *ptr;
- size_t bytes = t->cols * t->block.size;
- char *dst_ptr2 = (char *) dst_ptr;
-
- assert(pipe_linear_check_tile(t));
-
- /* lets write lineary to the tiled buffer */
- for (y = 0; y < t->tiles_y; y++) {
- for (x = 0; x < t->tiles_x; x++) {
- /* this inner loop could be replace with SSE magic */
- ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x;
- for (z = 0; z < t->rows; z++) {
- memcpy(dst_ptr2, ptr, bytes);
- dst_ptr2 += bytes;
- ptr += src_stride;
- }
- }
- }
-}
-
-void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,
- size_t dst_stride, void *dst_ptr)
-{
- int x, y, z;
- char *ptr;
- size_t bytes = t->cols * t->block.size;
- const char *src_ptr2 = (const char *) src_ptr;
-
- /* lets read lineary from the tiled buffer */
- for (y = 0; y < t->tiles_y; y++) {
- for (x = 0; x < t->tiles_x; x++) {
- /* this inner loop could be replace with SSE magic */
- ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x;
- for (z = 0; z < t->rows; z++) {
- memcpy(ptr, src_ptr2, bytes);
- src_ptr2 += bytes;
- ptr += dst_stride;
- }
- }
- }
-}
-
-void
-pipe_linear_fill_info(struct pipe_tile_info *t,
- const struct u_linear_format_block *block,
- unsigned tile_width, unsigned tile_height,
- unsigned tiles_x, unsigned tiles_y)
-{
- t->block = *block;
-
- t->tile.width = tile_width;
- t->tile.height = tile_height;
- t->cols = t->tile.width / t->block.width;
- t->rows = t->tile.height / t->block.height;
- t->tile.size = t->cols * t->rows * t->block.size;
-
- t->tiles_x = tiles_x;
- t->tiles_y = tiles_y;
- t->stride = t->cols * t->tiles_x * t->block.size;
- t->size = t->tiles_x * t->tiles_y * t->tile.size;
-}
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * Functions for converting tiled data to linear and vice versa. + */ + + +#include "util/u_debug.h" +#include "u_linear.h" + +void +pipe_linear_to_tile(size_t src_stride, const void *src_ptr, + struct pipe_tile_info *t, void *dst_ptr) +{ + int x, y, z; + char *ptr; + size_t bytes = t->cols * t->block.size; + char *dst_ptr2 = (char *) dst_ptr; + + assert(pipe_linear_check_tile(t)); + + /* lets write lineary to the tiled buffer */ + for (y = 0; y < t->tiles_y; y++) { + for (x = 0; x < t->tiles_x; x++) { + /* this inner loop could be replace with SSE magic */ + ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x; + for (z = 0; z < t->rows; z++) { + memcpy(dst_ptr2, ptr, bytes); + dst_ptr2 += bytes; + ptr += src_stride; + } + } + } +} + +void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, + size_t dst_stride, void *dst_ptr) +{ + int x, y, z; + char *ptr; + size_t bytes = t->cols * t->block.size; + const char *src_ptr2 = (const char *) src_ptr; + + /* lets read lineary from the tiled buffer */ + for (y = 0; y < t->tiles_y; y++) { + for (x = 0; x < t->tiles_x; x++) { + /* this inner loop could be replace with SSE magic */ + ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x; + for (z = 0; z < t->rows; z++) { + memcpy(ptr, src_ptr2, bytes); + src_ptr2 += bytes; + ptr += dst_stride; + } + } + } +} + +void +pipe_linear_fill_info(struct pipe_tile_info *t, + const struct u_linear_format_block *block, + unsigned tile_width, unsigned tile_height, + unsigned tiles_x, unsigned tiles_y) +{ + t->block = *block; + + t->tile.width = tile_width; + t->tile.height = tile_height; + t->cols = t->tile.width / t->block.width; + t->rows = t->tile.height / t->block.height; + t->tile.size = t->cols * t->rows * t->block.size; + + t->tiles_x = tiles_x; + t->tiles_y = tiles_y; + t->stride = t->cols * t->tiles_x * t->block.size; + t->size = t->tiles_x * t->tiles_y * t->tile.size; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_linear.h b/mesalib/src/gallium/auxiliary/util/u_linear.h index 38a790e3f..81ffc9fb2 100644 --- a/mesalib/src/gallium/auxiliary/util/u_linear.h +++ b/mesalib/src/gallium/auxiliary/util/u_linear.h @@ -1,106 +1,106 @@ -/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-/**
- * Functions for converting tiled data to linear and vice versa.
- */
-
-
-#ifndef U_LINEAR_H
-#define U_LINEAR_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-
-struct u_linear_format_block
-{
- /** Block size in bytes */
- unsigned size;
-
- /** Block width in pixels */
- unsigned width;
-
- /** Block height in pixels */
- unsigned height;
-};
-
-
-struct pipe_tile_info
-{
- unsigned size;
- unsigned stride;
-
- /* The number of tiles */
- unsigned tiles_x;
- unsigned tiles_y;
-
- /* size of each tile expressed in blocks */
- unsigned cols;
- unsigned rows;
-
- /* Describe the tile in pixels */
- struct u_linear_format_block tile;
-
- /* Describe each block within the tile */
- struct u_linear_format_block block;
-};
-
-void pipe_linear_to_tile(size_t src_stride, const void *src_ptr,
- struct pipe_tile_info *t, void *dst_ptr);
-
-void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,
- size_t dst_stride, void *dst_ptr);
-
-/**
- * Convenience function to fillout a pipe_tile_info struct.
- * @t info to fill out.
- * @block block info about pixel layout
- * @tile_width the width of the tile in pixels
- * @tile_height the height of the tile in pixels
- * @tiles_x number of tiles in x axis
- * @tiles_y number of tiles in y axis
- */
-void pipe_linear_fill_info(struct pipe_tile_info *t,
- const struct u_linear_format_block *block,
- unsigned tile_width, unsigned tile_height,
- unsigned tiles_x, unsigned tiles_y);
-
-static INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t)
-{
- if (t->tile.size != t->block.size * t->cols * t->rows)
- return FALSE;
-
- if (t->stride != t->block.size * t->cols * t->tiles_x)
- return FALSE;
-
- if (t->size < t->stride * t->rows * t->tiles_y)
- return FALSE;
-
- return TRUE;
-}
-
-#endif /* U_LINEAR_H */
+/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +/** + * Functions for converting tiled data to linear and vice versa. + */ + + +#ifndef U_LINEAR_H +#define U_LINEAR_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +struct u_linear_format_block +{ + /** Block size in bytes */ + unsigned size; + + /** Block width in pixels */ + unsigned width; + + /** Block height in pixels */ + unsigned height; +}; + + +struct pipe_tile_info +{ + unsigned size; + unsigned stride; + + /* The number of tiles */ + unsigned tiles_x; + unsigned tiles_y; + + /* size of each tile expressed in blocks */ + unsigned cols; + unsigned rows; + + /* Describe the tile in pixels */ + struct u_linear_format_block tile; + + /* Describe each block within the tile */ + struct u_linear_format_block block; +}; + +void pipe_linear_to_tile(size_t src_stride, const void *src_ptr, + struct pipe_tile_info *t, void *dst_ptr); + +void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, + size_t dst_stride, void *dst_ptr); + +/** + * Convenience function to fillout a pipe_tile_info struct. + * @t info to fill out. + * @block block info about pixel layout + * @tile_width the width of the tile in pixels + * @tile_height the height of the tile in pixels + * @tiles_x number of tiles in x axis + * @tiles_y number of tiles in y axis + */ +void pipe_linear_fill_info(struct pipe_tile_info *t, + const struct u_linear_format_block *block, + unsigned tile_width, unsigned tile_height, + unsigned tiles_x, unsigned tiles_y); + +static INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t) +{ + if (t->tile.size != t->block.size * t->cols * t->rows) + return FALSE; + + if (t->stride != t->block.size * t->cols * t->tiles_x) + return FALSE; + + if (t->size < t->stride * t->rows * t->tiles_y) + return FALSE; + + return TRUE; +} + +#endif /* U_LINEAR_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_linkage.c b/mesalib/src/gallium/auxiliary/util/u_linkage.c index 89d67accc..2f6f41ba8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_linkage.c +++ b/mesalib/src/gallium/auxiliary/util/u_linkage.c @@ -1,149 +1,149 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#include "util/u_debug.h"
-#include "pipe/p_shader_tokens.h"
-#include "tgsi/tgsi_parse.h"
-#include "tgsi/tgsi_scan.h"
-#include "util/u_linkage.h"
-
-/* we must only record the registers that are actually used, not just declared */
-static INLINE boolean
-util_semantic_set_test_and_set(struct util_semantic_set *set, unsigned value)
-{
- unsigned mask = 1 << (value % (sizeof(long) * 8));
- unsigned long *p = &set->masks[value / (sizeof(long) * 8)];
- unsigned long v = *p & mask;
- *p |= mask;
- return !!v;
-}
-
-unsigned
-util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file)
-{
- struct tgsi_shader_info info;
- struct tgsi_parse_context parse;
- unsigned count = 0;
- ubyte *semantic_name;
- ubyte *semantic_index;
-
- tgsi_scan_shader(tokens, &info);
-
- if(file == TGSI_FILE_INPUT)
- {
- semantic_name = info.input_semantic_name;
- semantic_index = info.input_semantic_index;
- }
- else if(file == TGSI_FILE_OUTPUT)
- {
- semantic_name = info.output_semantic_name;
- semantic_index = info.output_semantic_index;
- }
- else
- {
- assert(0);
- semantic_name = NULL;
- semantic_index = NULL;
- }
-
- tgsi_parse_init(&parse, tokens);
-
- memset(set->masks, 0, sizeof(set->masks));
- while(!tgsi_parse_end_of_tokens(&parse))
- {
- tgsi_parse_token(&parse);
-
- if(parse.FullToken.Token.Type == TGSI_TOKEN_TYPE_INSTRUCTION)
- {
- const struct tgsi_full_instruction *finst = &parse.FullToken.FullInstruction;
- unsigned i;
- for(i = 0; i < finst->Instruction.NumDstRegs; ++i)
- {
- if(finst->Dst[i].Register.File == file)
- {
- unsigned idx = finst->Dst[i].Register.Index;
- if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC)
- {
- if(!util_semantic_set_test_and_set(set, semantic_index[idx]))
- ++count;
- }
- }
- }
-
- for(i = 0; i < finst->Instruction.NumSrcRegs; ++i)
- {
- if(finst->Src[i].Register.File == file)
- {
- unsigned idx = finst->Src[i].Register.Index;
- if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC)
- {
- if(!util_semantic_set_test_and_set(set, semantic_index[idx]))
- ++count;
- }
- }
- }
- }
- }
- tgsi_parse_free(&parse);
-
- return count;
-}
-
-#define UTIL_SEMANTIC_SET_FOR_EACH(i, set) for(i = 0; i < 256; ++i) if(set->masks[i / (sizeof(long) * 8)] & (1 << (i % (sizeof(long) * 8))))
-
-void
-util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots)
-{
- int first = -1;
- int last = -1;
- unsigned i;
-
- memset(layout, 0xff, num_slots);
-
- UTIL_SEMANTIC_SET_FOR_EACH(i, set)
- {
- if(first < 0)
- first = i;
- last = i;
- }
-
- if(last < efficient_slots)
- {
- UTIL_SEMANTIC_SET_FOR_EACH(i, set)
- layout[i] = i;
- }
- else if((last - first) < efficient_slots)
- {
- UTIL_SEMANTIC_SET_FOR_EACH(i, set)
- layout[i - first] = i;
- }
- else
- {
- unsigned idx = 0;
- UTIL_SEMANTIC_SET_FOR_EACH(i, set)
- layout[idx++] = i;
- }
-}
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" +#include "util/u_linkage.h" + +/* we must only record the registers that are actually used, not just declared */ +static INLINE boolean +util_semantic_set_test_and_set(struct util_semantic_set *set, unsigned value) +{ + unsigned mask = 1 << (value % (sizeof(long) * 8)); + unsigned long *p = &set->masks[value / (sizeof(long) * 8)]; + unsigned long v = *p & mask; + *p |= mask; + return !!v; +} + +unsigned +util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file) +{ + struct tgsi_shader_info info; + struct tgsi_parse_context parse; + unsigned count = 0; + ubyte *semantic_name; + ubyte *semantic_index; + + tgsi_scan_shader(tokens, &info); + + if(file == TGSI_FILE_INPUT) + { + semantic_name = info.input_semantic_name; + semantic_index = info.input_semantic_index; + } + else if(file == TGSI_FILE_OUTPUT) + { + semantic_name = info.output_semantic_name; + semantic_index = info.output_semantic_index; + } + else + { + assert(0); + semantic_name = NULL; + semantic_index = NULL; + } + + tgsi_parse_init(&parse, tokens); + + memset(set->masks, 0, sizeof(set->masks)); + while(!tgsi_parse_end_of_tokens(&parse)) + { + tgsi_parse_token(&parse); + + if(parse.FullToken.Token.Type == TGSI_TOKEN_TYPE_INSTRUCTION) + { + const struct tgsi_full_instruction *finst = &parse.FullToken.FullInstruction; + unsigned i; + for(i = 0; i < finst->Instruction.NumDstRegs; ++i) + { + if(finst->Dst[i].Register.File == file) + { + unsigned idx = finst->Dst[i].Register.Index; + if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC) + { + if(!util_semantic_set_test_and_set(set, semantic_index[idx])) + ++count; + } + } + } + + for(i = 0; i < finst->Instruction.NumSrcRegs; ++i) + { + if(finst->Src[i].Register.File == file) + { + unsigned idx = finst->Src[i].Register.Index; + if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC) + { + if(!util_semantic_set_test_and_set(set, semantic_index[idx])) + ++count; + } + } + } + } + } + tgsi_parse_free(&parse); + + return count; +} + +#define UTIL_SEMANTIC_SET_FOR_EACH(i, set) for(i = 0; i < 256; ++i) if(set->masks[i / (sizeof(long) * 8)] & (1 << (i % (sizeof(long) * 8)))) + +void +util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots) +{ + int first = -1; + int last = -1; + unsigned i; + + memset(layout, 0xff, num_slots); + + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + { + if(first < 0) + first = i; + last = i; + } + + if(last < efficient_slots) + { + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[i] = i; + } + else if((last - first) < efficient_slots) + { + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[i - first] = i; + } + else + { + unsigned idx = 0; + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[idx++] = i; + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_math.c b/mesalib/src/gallium/auxiliary/util/u_math.c index 3044f5da8..2811475fa 100644 --- a/mesalib/src/gallium/auxiliary/util/u_math.c +++ b/mesalib/src/gallium/auxiliary/util/u_math.c @@ -1,73 +1,73 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-
-
-#include "util/u_math.h"
-
-
-/** 2^x, for x in [-1.0, 1.0) */
-float pow2_table[POW2_TABLE_SIZE];
-
-
-static void
-init_pow2_table(void)
-{
- int i;
- for (i = 0; i < POW2_TABLE_SIZE; i++)
- pow2_table[i] = (float) pow(2.0, (i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE);
-}
-
-
-/** log2(x), for x in [1.0, 2.0) */
-float log2_table[LOG2_TABLE_SIZE];
-
-
-static void
-init_log2_table(void)
-{
- unsigned i;
- for (i = 0; i < LOG2_TABLE_SIZE; i++)
- log2_table[i] = (float) log2(1.0 + i * (1.0 / LOG2_TABLE_SCALE));
-}
-
-
-/**
- * One time init for math utilities.
- */
-void
-util_init_math(void)
-{
- static boolean initialized = FALSE;
- if (!initialized) {
- init_pow2_table();
- init_log2_table();
- initialized = TRUE;
- }
-}
-
-
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + + + +#include "util/u_math.h" + + +/** 2^x, for x in [-1.0, 1.0) */ +float pow2_table[POW2_TABLE_SIZE]; + + +static void +init_pow2_table(void) +{ + int i; + for (i = 0; i < POW2_TABLE_SIZE; i++) + pow2_table[i] = (float) pow(2.0, (i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE); +} + + +/** log2(x), for x in [1.0, 2.0) */ +float log2_table[LOG2_TABLE_SIZE]; + + +static void +init_log2_table(void) +{ + unsigned i; + for (i = 0; i < LOG2_TABLE_SIZE; i++) + log2_table[i] = (float) log2(1.0 + i * (1.0 / LOG2_TABLE_SCALE)); +} + + +/** + * One time init for math utilities. + */ +void +util_init_math(void) +{ + static boolean initialized = FALSE; + if (!initialized) { + init_pow2_table(); + init_log2_table(); + initialized = TRUE; + } +} + + diff --git a/mesalib/src/gallium/auxiliary/util/u_memory.h b/mesalib/src/gallium/auxiliary/util/u_memory.h index 4eb798469..53d56599f 100644 --- a/mesalib/src/gallium/auxiliary/util/u_memory.h +++ b/mesalib/src/gallium/auxiliary/util/u_memory.h @@ -1,100 +1,100 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-
-/*
- * Memory functions
- */
-
-
-#ifndef U_MEMORY_H
-#define U_MEMORY_H
-
-
-#include "util/u_pointer.h"
-#include "util/u_debug.h"
-#include "os/os_memory.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define MALLOC(_size) os_malloc(_size)
-
-#define CALLOC(_count, _size) os_calloc(_count, _size)
-
-#define FREE(_ptr ) os_free(_ptr)
-
-#define REALLOC(_ptr, _old_size, _size) os_realloc(_ptr, _old_size, _size)
-
-#define MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T))
-
-#define CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T))
-
-#define CALLOC_VARIANT_LENGTH_STRUCT(T,more_size) ((struct T *) CALLOC(1, sizeof(struct T) + more_size))
-
-
-#define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment)
-#define align_free(_ptr) os_free_aligned(_ptr)
-
-
-/**
- * Duplicate a block of memory.
- */
-static INLINE void *
-mem_dup(const void *src, uint size)
-{
- void *dup = MALLOC(size);
- if (dup)
- memcpy(dup, src, size);
- return dup;
-}
-
-
-/**
- * Number of elements in an array.
- */
-#ifndef Elements
-#define Elements(x) (sizeof(x)/sizeof((x)[0]))
-#endif
-
-
-/**
- * Offset of a field in a struct, in bytes.
- */
-#define Offset(TYPE, MEMBER) ((uintptr_t)&(((TYPE *)NULL)->MEMBER))
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* U_MEMORY_H */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + + +/* + * Memory functions + */ + + +#ifndef U_MEMORY_H +#define U_MEMORY_H + + +#include "util/u_pointer.h" +#include "util/u_debug.h" +#include "os/os_memory.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define MALLOC(_size) os_malloc(_size) + +#define CALLOC(_count, _size) os_calloc(_count, _size) + +#define FREE(_ptr ) os_free(_ptr) + +#define REALLOC(_ptr, _old_size, _size) os_realloc(_ptr, _old_size, _size) + +#define MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T)) + +#define CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T)) + +#define CALLOC_VARIANT_LENGTH_STRUCT(T,more_size) ((struct T *) CALLOC(1, sizeof(struct T) + more_size)) + + +#define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment) +#define align_free(_ptr) os_free_aligned(_ptr) + + +/** + * Duplicate a block of memory. + */ +static INLINE void * +mem_dup(const void *src, uint size) +{ + void *dup = MALLOC(size); + if (dup) + memcpy(dup, src, size); + return dup; +} + + +/** + * Number of elements in an array. + */ +#ifndef Elements +#define Elements(x) (sizeof(x)/sizeof((x)[0])) +#endif + + +/** + * Offset of a field in a struct, in bytes. + */ +#define Offset(TYPE, MEMBER) ((uintptr_t)&(((TYPE *)NULL)->MEMBER)) + + + +#ifdef __cplusplus +} +#endif + + +#endif /* U_MEMORY_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_mm.c b/mesalib/src/gallium/auxiliary/util/u_mm.c index 874f1f40f..82f83702d 100644 --- a/mesalib/src/gallium/auxiliary/util/u_mm.c +++ b/mesalib/src/gallium/auxiliary/util/u_mm.c @@ -1,296 +1,296 @@ -/**************************************************************************
- *
- * Copyright (C) 1999 Wittawat Yamwong
- *
- * 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
- * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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 "pipe/p_compiler.h"
-#include "util/u_debug.h"
-
-#include "util/u_memory.h"
-#include "util/u_mm.h"
-
-
-void
-u_mmDumpMemInfo(const struct mem_block *heap)
-{
- debug_printf("Memory heap %p:\n", (void *) heap);
- if (heap == 0) {
- debug_printf(" heap == 0\n");
- }
- else {
- const struct mem_block *p;
- int total_used = 0, total_free = 0;
-
- for (p = heap->next; p != heap; p = p->next) {
- debug_printf(" Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size,
- p->free ? 'F':'.',
- p->reserved ? 'R':'.');
- if (p->free)
- total_free += p->size;
- else
- total_used += p->size;
- }
-
- debug_printf("'\nMemory stats: total = %d, used = %d, free = %d\n",
- total_used + total_free, total_used, total_free);
- debug_printf("\nFree list:\n");
-
- for (p = heap->next_free; p != heap; p = p->next_free) {
- debug_printf(" FREE Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size,
- p->free ? 'F':'.',
- p->reserved ? 'R':'.');
- }
-
- }
- debug_printf("End of memory blocks\n");
-}
-
-
-struct mem_block *
-u_mmInit(int ofs, int size)
-{
- struct mem_block *heap, *block;
-
- if (size <= 0)
- return NULL;
-
- heap = CALLOC_STRUCT(mem_block);
- if (!heap)
- return NULL;
-
- block = CALLOC_STRUCT(mem_block);
- if (!block) {
- FREE(heap);
- return NULL;
- }
-
- heap->next = block;
- heap->prev = block;
- heap->next_free = block;
- heap->prev_free = block;
-
- block->heap = heap;
- block->next = heap;
- block->prev = heap;
- block->next_free = heap;
- block->prev_free = heap;
-
- block->ofs = ofs;
- block->size = size;
- block->free = 1;
-
- return heap;
-}
-
-
-static struct mem_block *
-SliceBlock(struct mem_block *p,
- int startofs, int size,
- int reserved, int alignment)
-{
- struct mem_block *newblock;
-
- /* break left [p, newblock, p->next], then p = newblock */
- if (startofs > p->ofs) {
- newblock = CALLOC_STRUCT(mem_block);
- if (!newblock)
- return NULL;
- newblock->ofs = startofs;
- newblock->size = p->size - (startofs - p->ofs);
- newblock->free = 1;
- newblock->heap = p->heap;
-
- newblock->next = p->next;
- newblock->prev = p;
- p->next->prev = newblock;
- p->next = newblock;
-
- newblock->next_free = p->next_free;
- newblock->prev_free = p;
- p->next_free->prev_free = newblock;
- p->next_free = newblock;
-
- p->size -= newblock->size;
- p = newblock;
- }
-
- /* break right, also [p, newblock, p->next] */
- if (size < p->size) {
- newblock = CALLOC_STRUCT(mem_block);
- if (!newblock)
- return NULL;
- newblock->ofs = startofs + size;
- newblock->size = p->size - size;
- newblock->free = 1;
- newblock->heap = p->heap;
-
- newblock->next = p->next;
- newblock->prev = p;
- p->next->prev = newblock;
- p->next = newblock;
-
- newblock->next_free = p->next_free;
- newblock->prev_free = p;
- p->next_free->prev_free = newblock;
- p->next_free = newblock;
-
- p->size = size;
- }
-
- /* p = middle block */
- p->free = 0;
-
- /* Remove p from the free list:
- */
- p->next_free->prev_free = p->prev_free;
- p->prev_free->next_free = p->next_free;
-
- p->next_free = 0;
- p->prev_free = 0;
-
- p->reserved = reserved;
- return p;
-}
-
-
-struct mem_block *
-u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch)
-{
- struct mem_block *p;
- const int mask = (1 << align2)-1;
- int startofs = 0;
- int endofs;
-
- assert(size >= 0);
- assert(align2 >= 0);
- assert(align2 <= 12); /* sanity check, 2^12 (4KB) enough? */
-
- if (!heap || align2 < 0 || size <= 0)
- return NULL;
-
- for (p = heap->next_free; p != heap; p = p->next_free) {
- assert(p->free);
-
- startofs = (p->ofs + mask) & ~mask;
- if ( startofs < startSearch ) {
- startofs = startSearch;
- }
- endofs = startofs+size;
- if (endofs <= (p->ofs+p->size))
- break;
- }
-
- if (p == heap)
- return NULL;
-
- assert(p->free);
- p = SliceBlock(p,startofs,size,0,mask+1);
-
- return p;
-}
-
-
-struct mem_block *
-u_mmFindBlock(struct mem_block *heap, int start)
-{
- struct mem_block *p;
-
- for (p = heap->next; p != heap; p = p->next) {
- if (p->ofs == start)
- return p;
- }
-
- return NULL;
-}
-
-
-static INLINE int
-Join2Blocks(struct mem_block *p)
-{
- /* XXX there should be some assertions here */
-
- /* NOTE: heap->free == 0 */
-
- if (p->free && p->next->free) {
- struct mem_block *q = p->next;
-
- assert(p->ofs + p->size == q->ofs);
- p->size += q->size;
-
- p->next = q->next;
- q->next->prev = p;
-
- q->next_free->prev_free = q->prev_free;
- q->prev_free->next_free = q->next_free;
-
- FREE(q);
- return 1;
- }
- return 0;
-}
-
-int
-u_mmFreeMem(struct mem_block *b)
-{
- if (!b)
- return 0;
-
- if (b->free) {
- debug_printf("block already free\n");
- return -1;
- }
- if (b->reserved) {
- debug_printf("block is reserved\n");
- return -1;
- }
-
- b->free = 1;
- b->next_free = b->heap->next_free;
- b->prev_free = b->heap;
- b->next_free->prev_free = b;
- b->prev_free->next_free = b;
-
- Join2Blocks(b);
- if (b->prev != b->heap)
- Join2Blocks(b->prev);
-
- return 0;
-}
-
-
-void
-u_mmDestroy(struct mem_block *heap)
-{
- struct mem_block *p;
-
- if (!heap)
- return;
-
- for (p = heap->next; p != heap; ) {
- struct mem_block *next = p->next;
- FREE(p);
- p = next;
- }
-
- FREE(heap);
-}
+/************************************************************************** + * + * Copyright (C) 1999 Wittawat Yamwong + * + * 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 + * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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 "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_memory.h" +#include "util/u_mm.h" + + +void +u_mmDumpMemInfo(const struct mem_block *heap) +{ + debug_printf("Memory heap %p:\n", (void *) heap); + if (heap == 0) { + debug_printf(" heap == 0\n"); + } + else { + const struct mem_block *p; + int total_used = 0, total_free = 0; + + for (p = heap->next; p != heap; p = p->next) { + debug_printf(" Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size, + p->free ? 'F':'.', + p->reserved ? 'R':'.'); + if (p->free) + total_free += p->size; + else + total_used += p->size; + } + + debug_printf("'\nMemory stats: total = %d, used = %d, free = %d\n", + total_used + total_free, total_used, total_free); + debug_printf("\nFree list:\n"); + + for (p = heap->next_free; p != heap; p = p->next_free) { + debug_printf(" FREE Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size, + p->free ? 'F':'.', + p->reserved ? 'R':'.'); + } + + } + debug_printf("End of memory blocks\n"); +} + + +struct mem_block * +u_mmInit(int ofs, int size) +{ + struct mem_block *heap, *block; + + if (size <= 0) + return NULL; + + heap = CALLOC_STRUCT(mem_block); + if (!heap) + return NULL; + + block = CALLOC_STRUCT(mem_block); + if (!block) { + FREE(heap); + return NULL; + } + + heap->next = block; + heap->prev = block; + heap->next_free = block; + heap->prev_free = block; + + block->heap = heap; + block->next = heap; + block->prev = heap; + block->next_free = heap; + block->prev_free = heap; + + block->ofs = ofs; + block->size = size; + block->free = 1; + + return heap; +} + + +static struct mem_block * +SliceBlock(struct mem_block *p, + int startofs, int size, + int reserved, int alignment) +{ + struct mem_block *newblock; + + /* break left [p, newblock, p->next], then p = newblock */ + if (startofs > p->ofs) { + newblock = CALLOC_STRUCT(mem_block); + if (!newblock) + return NULL; + newblock->ofs = startofs; + newblock->size = p->size - (startofs - p->ofs); + newblock->free = 1; + newblock->heap = p->heap; + + newblock->next = p->next; + newblock->prev = p; + p->next->prev = newblock; + p->next = newblock; + + newblock->next_free = p->next_free; + newblock->prev_free = p; + p->next_free->prev_free = newblock; + p->next_free = newblock; + + p->size -= newblock->size; + p = newblock; + } + + /* break right, also [p, newblock, p->next] */ + if (size < p->size) { + newblock = CALLOC_STRUCT(mem_block); + if (!newblock) + return NULL; + newblock->ofs = startofs + size; + newblock->size = p->size - size; + newblock->free = 1; + newblock->heap = p->heap; + + newblock->next = p->next; + newblock->prev = p; + p->next->prev = newblock; + p->next = newblock; + + newblock->next_free = p->next_free; + newblock->prev_free = p; + p->next_free->prev_free = newblock; + p->next_free = newblock; + + p->size = size; + } + + /* p = middle block */ + p->free = 0; + + /* Remove p from the free list: + */ + p->next_free->prev_free = p->prev_free; + p->prev_free->next_free = p->next_free; + + p->next_free = 0; + p->prev_free = 0; + + p->reserved = reserved; + return p; +} + + +struct mem_block * +u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) +{ + struct mem_block *p; + const int mask = (1 << align2)-1; + int startofs = 0; + int endofs; + + assert(size >= 0); + assert(align2 >= 0); + assert(align2 <= 12); /* sanity check, 2^12 (4KB) enough? */ + + if (!heap || align2 < 0 || size <= 0) + return NULL; + + for (p = heap->next_free; p != heap; p = p->next_free) { + assert(p->free); + + startofs = (p->ofs + mask) & ~mask; + if ( startofs < startSearch ) { + startofs = startSearch; + } + endofs = startofs+size; + if (endofs <= (p->ofs+p->size)) + break; + } + + if (p == heap) + return NULL; + + assert(p->free); + p = SliceBlock(p,startofs,size,0,mask+1); + + return p; +} + + +struct mem_block * +u_mmFindBlock(struct mem_block *heap, int start) +{ + struct mem_block *p; + + for (p = heap->next; p != heap; p = p->next) { + if (p->ofs == start) + return p; + } + + return NULL; +} + + +static INLINE int +Join2Blocks(struct mem_block *p) +{ + /* XXX there should be some assertions here */ + + /* NOTE: heap->free == 0 */ + + if (p->free && p->next->free) { + struct mem_block *q = p->next; + + assert(p->ofs + p->size == q->ofs); + p->size += q->size; + + p->next = q->next; + q->next->prev = p; + + q->next_free->prev_free = q->prev_free; + q->prev_free->next_free = q->next_free; + + FREE(q); + return 1; + } + return 0; +} + +int +u_mmFreeMem(struct mem_block *b) +{ + if (!b) + return 0; + + if (b->free) { + debug_printf("block already free\n"); + return -1; + } + if (b->reserved) { + debug_printf("block is reserved\n"); + return -1; + } + + b->free = 1; + b->next_free = b->heap->next_free; + b->prev_free = b->heap; + b->next_free->prev_free = b; + b->prev_free->next_free = b; + + Join2Blocks(b); + if (b->prev != b->heap) + Join2Blocks(b->prev); + + return 0; +} + + +void +u_mmDestroy(struct mem_block *heap) +{ + struct mem_block *p; + + if (!heap) + return; + + for (p = heap->next; p != heap; ) { + struct mem_block *next = p->next; + FREE(p); + p = next; + } + + FREE(heap); +} diff --git a/mesalib/src/gallium/auxiliary/util/u_mm.h b/mesalib/src/gallium/auxiliary/util/u_mm.h index 3818181db..6b158aae6 100644 --- a/mesalib/src/gallium/auxiliary/util/u_mm.h +++ b/mesalib/src/gallium/auxiliary/util/u_mm.h @@ -1,91 +1,91 @@ -/**************************************************************************
- *
- * Copyright (C) 1999 Wittawat Yamwong
- *
- * 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
- * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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.
- *
- **************************************************************************/
-
-
-/**
- * @file
- * Memory manager code. Primarily used by device drivers to manage texture
- * heaps, etc.
- */
-
-
-#ifndef _U_MM_H_
-#define _U_MM_H_
-
-
-struct mem_block {
- struct mem_block *next, *prev;
- struct mem_block *next_free, *prev_free;
- struct mem_block *heap;
- int ofs,size;
- unsigned int free:1;
- unsigned int reserved:1;
-};
-
-
-
-/**
- * input: total size in bytes
- * return: a heap pointer if OK, NULL if error
- */
-extern struct mem_block *u_mmInit(int ofs, int size);
-
-/**
- * Allocate 'size' bytes with 2^align2 bytes alignment,
- * restrict the search to free memory after 'startSearch'
- * depth and back buffers should be in different 4mb banks
- * to get better page hits if possible
- * input: size = size of block
- * align2 = 2^align2 bytes alignment
- * startSearch = linear offset from start of heap to begin search
- * return: pointer to the allocated block, 0 if error
- */
-extern struct mem_block *u_mmAllocMem(struct mem_block *heap, int size, int align2,
- int startSearch);
-
-/**
- * Free block starts at offset
- * input: pointer to a block
- * return: 0 if OK, -1 if error
- */
-extern int u_mmFreeMem(struct mem_block *b);
-
-/**
- * Free block starts at offset
- * input: pointer to a heap, start offset
- * return: pointer to a block
- */
-extern struct mem_block *u_mmFindBlock(struct mem_block *heap, int start);
-
-/**
- * destroy MM
- */
-extern void u_mmDestroy(struct mem_block *mmInit);
-
-/**
- * For debugging purposes.
- */
-extern void u_mmDumpMemInfo(const struct mem_block *mmInit);
-
-#endif
+/************************************************************************** + * + * Copyright (C) 1999 Wittawat Yamwong + * + * 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 + * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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. + * + **************************************************************************/ + + +/** + * @file + * Memory manager code. Primarily used by device drivers to manage texture + * heaps, etc. + */ + + +#ifndef _U_MM_H_ +#define _U_MM_H_ + + +struct mem_block { + struct mem_block *next, *prev; + struct mem_block *next_free, *prev_free; + struct mem_block *heap; + int ofs,size; + unsigned int free:1; + unsigned int reserved:1; +}; + + + +/** + * input: total size in bytes + * return: a heap pointer if OK, NULL if error + */ +extern struct mem_block *u_mmInit(int ofs, int size); + +/** + * Allocate 'size' bytes with 2^align2 bytes alignment, + * restrict the search to free memory after 'startSearch' + * depth and back buffers should be in different 4mb banks + * to get better page hits if possible + * input: size = size of block + * align2 = 2^align2 bytes alignment + * startSearch = linear offset from start of heap to begin search + * return: pointer to the allocated block, 0 if error + */ +extern struct mem_block *u_mmAllocMem(struct mem_block *heap, int size, int align2, + int startSearch); + +/** + * Free block starts at offset + * input: pointer to a block + * return: 0 if OK, -1 if error + */ +extern int u_mmFreeMem(struct mem_block *b); + +/** + * Free block starts at offset + * input: pointer to a heap, start offset + * return: pointer to a block + */ +extern struct mem_block *u_mmFindBlock(struct mem_block *heap, int start); + +/** + * destroy MM + */ +extern void u_mmDestroy(struct mem_block *mmInit); + +/** + * For debugging purposes. + */ +extern void u_mmDumpMemInfo(const struct mem_block *mmInit); + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_pointer.h b/mesalib/src/gallium/auxiliary/util/u_pointer.h index f75ce012b..cce0c7430 100644 --- a/mesalib/src/gallium/auxiliary/util/u_pointer.h +++ b/mesalib/src/gallium/auxiliary/util/u_pointer.h @@ -1,130 +1,130 @@ -/**************************************************************************
- *
- * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#ifndef U_POINTER_H
-#define U_POINTER_H
-
-#include "pipe/p_compiler.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static INLINE intptr_t
-pointer_to_intptr( const void *p )
-{
- union {
- const void *p;
- intptr_t i;
- } pi;
- pi.p = p;
- return pi.i;
-}
-
-static INLINE void *
-intptr_to_pointer( intptr_t i )
-{
- union {
- void *p;
- intptr_t i;
- } pi;
- pi.i = i;
- return pi.p;
-}
-
-static INLINE uintptr_t
-pointer_to_uintptr( const void *ptr )
-{
- union {
- const void *p;
- uintptr_t u;
- } pu;
- pu.p = ptr;
- return pu.u;
-}
-
-static INLINE void *
-uintptr_to_pointer( uintptr_t u )
-{
- union {
- void *p;
- uintptr_t u;
- } pu;
- pu.u = u;
- return pu.p;
-}
-
-/**
- * Return a pointer aligned to next multiple of N bytes.
- */
-static INLINE void *
-align_pointer( const void *unaligned, uintptr_t alignment )
-{
- uintptr_t aligned = (pointer_to_uintptr( unaligned ) + alignment - 1) & ~(alignment - 1);
- return uintptr_to_pointer( aligned );
-}
-
-
-/**
- * Return a pointer aligned to next multiple of 16 bytes.
- */
-static INLINE void *
-align16( void *unaligned )
-{
- return align_pointer( unaligned, 16 );
-}
-
-typedef void (*func_pointer)(void);
-
-static INLINE func_pointer
-pointer_to_func( void *p )
-{
- union {
- void *p;
- func_pointer f;
- } pf;
- pf.p = p;
- return pf.f;
-}
-
-static INLINE void *
-func_to_pointer( func_pointer f )
-{
- union {
- void *p;
- func_pointer f;
- } pf;
- pf.f = f;
- return pf.p;
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_POINTER_H */
+/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef U_POINTER_H +#define U_POINTER_H + +#include "pipe/p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static INLINE intptr_t +pointer_to_intptr( const void *p ) +{ + union { + const void *p; + intptr_t i; + } pi; + pi.p = p; + return pi.i; +} + +static INLINE void * +intptr_to_pointer( intptr_t i ) +{ + union { + void *p; + intptr_t i; + } pi; + pi.i = i; + return pi.p; +} + +static INLINE uintptr_t +pointer_to_uintptr( const void *ptr ) +{ + union { + const void *p; + uintptr_t u; + } pu; + pu.p = ptr; + return pu.u; +} + +static INLINE void * +uintptr_to_pointer( uintptr_t u ) +{ + union { + void *p; + uintptr_t u; + } pu; + pu.u = u; + return pu.p; +} + +/** + * Return a pointer aligned to next multiple of N bytes. + */ +static INLINE void * +align_pointer( const void *unaligned, uintptr_t alignment ) +{ + uintptr_t aligned = (pointer_to_uintptr( unaligned ) + alignment - 1) & ~(alignment - 1); + return uintptr_to_pointer( aligned ); +} + + +/** + * Return a pointer aligned to next multiple of 16 bytes. + */ +static INLINE void * +align16( void *unaligned ) +{ + return align_pointer( unaligned, 16 ); +} + +typedef void (*func_pointer)(void); + +static INLINE func_pointer +pointer_to_func( void *p ) +{ + union { + void *p; + func_pointer f; + } pf; + pf.p = p; + return pf.f; +} + +static INLINE void * +func_to_pointer( func_pointer f ) +{ + union { + void *p; + func_pointer f; + } pf; + pf.f = f; + return pf.p; +} + + +#ifdef __cplusplus +} +#endif + +#endif /* U_POINTER_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_pstipple.h b/mesalib/src/gallium/auxiliary/util/u_pstipple.h index 451e37417..1c2f5f48a 100644 --- a/mesalib/src/gallium/auxiliary/util/u_pstipple.h +++ b/mesalib/src/gallium/auxiliary/util/u_pstipple.h @@ -1,56 +1,56 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright 2010 VMware, Inc.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#ifndef U_PSTIPPLE_H
-#define U_PSTIPPLE_H
-
-#include "pipe/p_compiler.h"
-
-struct pipe_context;
-struct pipe_resource;
-struct pipe_shader_state;
-
-
-extern struct pipe_resource *
-util_pstipple_create_stipple_texture(struct pipe_context *pipe,
- const uint32_t pattern[32]);
-
-extern struct pipe_sampler_view *
-util_pstipple_create_sampler_view(struct pipe_context *pipe,
- struct pipe_resource *tex);
-
-extern void *
-util_pstipple_create_sampler(struct pipe_context *pipe);
-
-extern struct pipe_shader_state *
-util_pstipple_create_fragment_shader(struct pipe_context *pipe,
- struct pipe_shader_state *fs,
- unsigned *samplerUnitOut);
-
-
-#endif
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2010 VMware, Inc. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef U_PSTIPPLE_H +#define U_PSTIPPLE_H + +#include "pipe/p_compiler.h" + +struct pipe_context; +struct pipe_resource; +struct pipe_shader_state; + + +extern struct pipe_resource * +util_pstipple_create_stipple_texture(struct pipe_context *pipe, + const uint32_t pattern[32]); + +extern struct pipe_sampler_view * +util_pstipple_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *tex); + +extern void * +util_pstipple_create_sampler(struct pipe_context *pipe); + +extern struct pipe_shader_state * +util_pstipple_create_fragment_shader(struct pipe_context *pipe, + struct pipe_shader_state *fs, + unsigned *samplerUnitOut); + + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_rect.h b/mesalib/src/gallium/auxiliary/util/u_rect.h index d16f106bf..4cb90d3c3 100644 --- a/mesalib/src/gallium/auxiliary/util/u_rect.h +++ b/mesalib/src/gallium/auxiliary/util/u_rect.h @@ -1,103 +1,103 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-
-#ifndef U_RECT_H
-#define U_RECT_H
-
-#include "pipe/p_compiler.h"
-
-struct u_rect {
- int x0, x1;
- int y0, y1;
-};
-
-/* Do two rectangles intersect?
- */
-static INLINE boolean
-u_rect_test_intersection(const struct u_rect *a,
- const struct u_rect *b)
-{
- return (!(a->x1 < b->x0 ||
- b->x1 < a->x0 ||
- a->y1 < b->y0 ||
- b->y1 < a->y0));
-}
-
-/* Find the intersection of two rectangles known to intersect.
- */
-static INLINE void
-u_rect_find_intersection(const struct u_rect *a,
- struct u_rect *b)
-{
- /* Caller should verify intersection exists before calling.
- */
- if (b->x0 < a->x0) b->x0 = a->x0;
- if (b->x1 > a->x1) b->x1 = a->x1;
- if (b->y0 < a->y0) b->y0 = a->y0;
- if (b->y1 > a->y1) b->y1 = a->y1;
-}
-
-
-static INLINE void
-u_rect_possible_intersection(const struct u_rect *a,
- struct u_rect *b)
-{
- if (u_rect_test_intersection(a,b)) {
- u_rect_find_intersection(a,b);
- }
- else {
- b->x0 = b->x1 = b->y0 = b->y1 = 0;
- }
-}
-
-#include "pipe/p_format.h"
-#include "util/u_pack_color.h"
-
-
-
-/**********************************************************************
- * Pipe copy/fill rect helpers.
- */
-
-/* These really should move to a different file:
- */
-#include "pipe/p_format.h"
-
-extern void
-util_copy_rect(ubyte * dst, enum pipe_format format,
- unsigned dst_stride, unsigned dst_x, unsigned dst_y,
- unsigned width, unsigned height, const ubyte * src,
- int src_stride, unsigned src_x, unsigned src_y);
-
-extern void
-util_fill_rect(ubyte * dst, enum pipe_format format,
- unsigned dst_stride, unsigned dst_x, unsigned dst_y,
- unsigned width, unsigned height, union util_color *uc);
-
-
-#endif /* U_RECT_H */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + + +#ifndef U_RECT_H +#define U_RECT_H + +#include "pipe/p_compiler.h" + +struct u_rect { + int x0, x1; + int y0, y1; +}; + +/* Do two rectangles intersect? + */ +static INLINE boolean +u_rect_test_intersection(const struct u_rect *a, + const struct u_rect *b) +{ + return (!(a->x1 < b->x0 || + b->x1 < a->x0 || + a->y1 < b->y0 || + b->y1 < a->y0)); +} + +/* Find the intersection of two rectangles known to intersect. + */ +static INLINE void +u_rect_find_intersection(const struct u_rect *a, + struct u_rect *b) +{ + /* Caller should verify intersection exists before calling. + */ + if (b->x0 < a->x0) b->x0 = a->x0; + if (b->x1 > a->x1) b->x1 = a->x1; + if (b->y0 < a->y0) b->y0 = a->y0; + if (b->y1 > a->y1) b->y1 = a->y1; +} + + +static INLINE void +u_rect_possible_intersection(const struct u_rect *a, + struct u_rect *b) +{ + if (u_rect_test_intersection(a,b)) { + u_rect_find_intersection(a,b); + } + else { + b->x0 = b->x1 = b->y0 = b->y1 = 0; + } +} + +#include "pipe/p_format.h" +#include "util/u_pack_color.h" + + + +/********************************************************************** + * Pipe copy/fill rect helpers. + */ + +/* These really should move to a different file: + */ +#include "pipe/p_format.h" + +extern void +util_copy_rect(ubyte * dst, enum pipe_format format, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, const ubyte * src, + int src_stride, unsigned src_x, unsigned src_y); + +extern void +util_fill_rect(ubyte * dst, enum pipe_format format, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, union util_color *uc); + + +#endif /* U_RECT_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_resource.c b/mesalib/src/gallium/auxiliary/util/u_resource.c index 7efedef07..50a7cd4d5 100644 --- a/mesalib/src/gallium/auxiliary/util/u_resource.c +++ b/mesalib/src/gallium/auxiliary/util/u_resource.c @@ -1,88 +1,88 @@ -
-
-#include "util/u_inlines.h"
-#include "util/u_transfer.h"
-
-static INLINE struct u_resource *
-u_resource( struct pipe_resource *res )
-{
- return (struct u_resource *)res;
-}
-
-boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource,
- struct winsys_handle *handle)
-{
- struct u_resource *ur = u_resource(resource);
- return ur->vtbl->resource_get_handle(screen, resource, handle);
-}
-
-void u_resource_destroy_vtbl(struct pipe_screen *screen,
- struct pipe_resource *resource)
-{
- struct u_resource *ur = u_resource(resource);
- ur->vtbl->resource_destroy(screen, resource);
-}
-
-struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
-{
- struct u_resource *ur = u_resource(resource);
- return ur->vtbl->get_transfer(context, resource, level, usage, box);
-}
-
-void u_transfer_destroy_vtbl(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct u_resource *ur = u_resource(transfer->resource);
- ur->vtbl->transfer_destroy(pipe, transfer);
-}
-
-void *u_transfer_map_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct u_resource *ur = u_resource(transfer->resource);
- return ur->vtbl->transfer_map(pipe, transfer);
-}
-
-void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box)
-{
- struct u_resource *ur = u_resource(transfer->resource);
- ur->vtbl->transfer_flush_region(pipe, transfer, box);
-}
-
-void u_transfer_unmap_vtbl( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct u_resource *ur = u_resource(transfer->resource);
- ur->vtbl->transfer_unmap(pipe, transfer);
-}
-
-void u_transfer_inline_write_vtbl( struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box,
- const void *data,
- unsigned stride,
- unsigned layer_stride)
-{
- struct u_resource *ur = u_resource(resource);
- ur->vtbl->transfer_inline_write(pipe,
- resource,
- level,
- usage,
- box,
- data,
- stride,
- layer_stride);
-}
-
-
-
-
+ + +#include "util/u_inlines.h" +#include "util/u_transfer.h" + +static INLINE struct u_resource * +u_resource( struct pipe_resource *res ) +{ + return (struct u_resource *)res; +} + +boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->resource_get_handle(screen, resource, handle); +} + +void u_resource_destroy_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->resource_destroy(screen, resource); +} + +struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->get_transfer(context, resource, level, usage, box); +} + +void u_transfer_destroy_vtbl(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_destroy(pipe, transfer); +} + +void *u_transfer_map_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + return ur->vtbl->transfer_map(pipe, transfer); +} + +void u_transfer_flush_region_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_flush_region(pipe, transfer, box); +} + +void u_transfer_unmap_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_unmap(pipe, transfer); +} + +void u_transfer_inline_write_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->transfer_inline_write(pipe, + resource, + level, + usage, + box, + data, + stride, + layer_stride); +} + + + + diff --git a/mesalib/src/gallium/auxiliary/util/u_ringbuffer.c b/mesalib/src/gallium/auxiliary/util/u_ringbuffer.c index ad4066aa1..648b105b1 100644 --- a/mesalib/src/gallium/auxiliary/util/u_ringbuffer.c +++ b/mesalib/src/gallium/auxiliary/util/u_ringbuffer.c @@ -1,160 +1,160 @@ -
-#include "os/os_thread.h"
-#include "pipe/p_defines.h"
-#include "util/u_ringbuffer.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-/* Generic ringbuffer:
- */
-struct util_ringbuffer
-{
- struct util_packet *buf;
- unsigned mask;
-
- /* Can this be done with atomic variables??
- */
- unsigned head;
- unsigned tail;
- pipe_condvar change;
- pipe_mutex mutex;
-};
-
-
-struct util_ringbuffer *util_ringbuffer_create( unsigned dwords )
-{
- struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer);
- if (ring == NULL)
- return NULL;
-
- assert(util_is_power_of_two(dwords));
-
- ring->buf = MALLOC( dwords * sizeof(unsigned) );
- if (ring->buf == NULL)
- goto fail;
-
- ring->mask = dwords - 1;
-
- pipe_condvar_init(ring->change);
- pipe_mutex_init(ring->mutex);
- return ring;
-
-fail:
- FREE(ring->buf);
- FREE(ring);
- return NULL;
-}
-
-void util_ringbuffer_destroy( struct util_ringbuffer *ring )
-{
- pipe_condvar_destroy(ring->change);
- pipe_mutex_destroy(ring->mutex);
- FREE(ring->buf);
- FREE(ring);
-}
-
-/**
- * Return number of free entries in the ring
- */
-static INLINE unsigned util_ringbuffer_space( const struct util_ringbuffer *ring )
-{
- return (ring->tail - (ring->head + 1)) & ring->mask;
-}
-
-/**
- * Is the ring buffer empty?
- */
-static INLINE boolean util_ringbuffer_empty( const struct util_ringbuffer *ring )
-{
- return util_ringbuffer_space(ring) == ring->mask;
-}
-
-void util_ringbuffer_enqueue( struct util_ringbuffer *ring,
- const struct util_packet *packet )
-{
- unsigned i;
-
- /* XXX: over-reliance on mutexes, etc:
- */
- pipe_mutex_lock(ring->mutex);
-
- /* make sure we don't request an impossible amount of space
- */
- assert(packet->dwords <= ring->mask);
-
- /* Wait for free space:
- */
- while (util_ringbuffer_space(ring) < packet->dwords)
- pipe_condvar_wait(ring->change, ring->mutex);
-
- /* Copy data to ring:
- */
- for (i = 0; i < packet->dwords; i++) {
-
- /* Copy all dwords of the packet. Note we're abusing the
- * typesystem a little - we're being passed a pointer to
- * something, but probably not an array of packet structs:
- */
- ring->buf[ring->head] = packet[i];
- ring->head++;
- ring->head &= ring->mask;
- }
-
- /* Signal change:
- */
- pipe_condvar_signal(ring->change);
- pipe_mutex_unlock(ring->mutex);
-}
-
-enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring,
- struct util_packet *packet,
- unsigned max_dwords,
- boolean wait )
-{
- const struct util_packet *ring_packet;
- unsigned i;
- int ret = PIPE_OK;
-
- /* XXX: over-reliance on mutexes, etc:
- */
- pipe_mutex_lock(ring->mutex);
-
- /* Get next ring entry:
- */
- if (wait) {
- while (util_ringbuffer_empty(ring))
- pipe_condvar_wait(ring->change, ring->mutex);
- }
- else {
- if (util_ringbuffer_empty(ring)) {
- ret = PIPE_ERROR_OUT_OF_MEMORY;
- goto out;
- }
- }
-
- ring_packet = &ring->buf[ring->tail];
-
- /* Both of these are considered bugs. Raise an assert on debug builds.
- */
- if (ring_packet->dwords > ring->mask + 1 - util_ringbuffer_space(ring) ||
- ring_packet->dwords > max_dwords) {
- assert(0);
- ret = PIPE_ERROR_BAD_INPUT;
- goto out;
- }
-
- /* Copy data from ring:
- */
- for (i = 0; i < ring_packet->dwords; i++) {
- packet[i] = ring->buf[ring->tail];
- ring->tail++;
- ring->tail &= ring->mask;
- }
-
-out:
- /* Signal change:
- */
- pipe_condvar_signal(ring->change);
- pipe_mutex_unlock(ring->mutex);
- return ret;
-}
+ +#include "os/os_thread.h" +#include "pipe/p_defines.h" +#include "util/u_ringbuffer.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +/* Generic ringbuffer: + */ +struct util_ringbuffer +{ + struct util_packet *buf; + unsigned mask; + + /* Can this be done with atomic variables?? + */ + unsigned head; + unsigned tail; + pipe_condvar change; + pipe_mutex mutex; +}; + + +struct util_ringbuffer *util_ringbuffer_create( unsigned dwords ) +{ + struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer); + if (ring == NULL) + return NULL; + + assert(util_is_power_of_two(dwords)); + + ring->buf = MALLOC( dwords * sizeof(unsigned) ); + if (ring->buf == NULL) + goto fail; + + ring->mask = dwords - 1; + + pipe_condvar_init(ring->change); + pipe_mutex_init(ring->mutex); + return ring; + +fail: + FREE(ring->buf); + FREE(ring); + return NULL; +} + +void util_ringbuffer_destroy( struct util_ringbuffer *ring ) +{ + pipe_condvar_destroy(ring->change); + pipe_mutex_destroy(ring->mutex); + FREE(ring->buf); + FREE(ring); +} + +/** + * Return number of free entries in the ring + */ +static INLINE unsigned util_ringbuffer_space( const struct util_ringbuffer *ring ) +{ + return (ring->tail - (ring->head + 1)) & ring->mask; +} + +/** + * Is the ring buffer empty? + */ +static INLINE boolean util_ringbuffer_empty( const struct util_ringbuffer *ring ) +{ + return util_ringbuffer_space(ring) == ring->mask; +} + +void util_ringbuffer_enqueue( struct util_ringbuffer *ring, + const struct util_packet *packet ) +{ + unsigned i; + + /* XXX: over-reliance on mutexes, etc: + */ + pipe_mutex_lock(ring->mutex); + + /* make sure we don't request an impossible amount of space + */ + assert(packet->dwords <= ring->mask); + + /* Wait for free space: + */ + while (util_ringbuffer_space(ring) < packet->dwords) + pipe_condvar_wait(ring->change, ring->mutex); + + /* Copy data to ring: + */ + for (i = 0; i < packet->dwords; i++) { + + /* Copy all dwords of the packet. Note we're abusing the + * typesystem a little - we're being passed a pointer to + * something, but probably not an array of packet structs: + */ + ring->buf[ring->head] = packet[i]; + ring->head++; + ring->head &= ring->mask; + } + + /* Signal change: + */ + pipe_condvar_signal(ring->change); + pipe_mutex_unlock(ring->mutex); +} + +enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, + struct util_packet *packet, + unsigned max_dwords, + boolean wait ) +{ + const struct util_packet *ring_packet; + unsigned i; + int ret = PIPE_OK; + + /* XXX: over-reliance on mutexes, etc: + */ + pipe_mutex_lock(ring->mutex); + + /* Get next ring entry: + */ + if (wait) { + while (util_ringbuffer_empty(ring)) + pipe_condvar_wait(ring->change, ring->mutex); + } + else { + if (util_ringbuffer_empty(ring)) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto out; + } + } + + ring_packet = &ring->buf[ring->tail]; + + /* Both of these are considered bugs. Raise an assert on debug builds. + */ + if (ring_packet->dwords > ring->mask + 1 - util_ringbuffer_space(ring) || + ring_packet->dwords > max_dwords) { + assert(0); + ret = PIPE_ERROR_BAD_INPUT; + goto out; + } + + /* Copy data from ring: + */ + for (i = 0; i < ring_packet->dwords; i++) { + packet[i] = ring->buf[ring->tail]; + ring->tail++; + ring->tail &= ring->mask; + } + +out: + /* Signal change: + */ + pipe_condvar_signal(ring->change); + pipe_mutex_unlock(ring->mutex); + return ret; +} diff --git a/mesalib/src/gallium/auxiliary/util/u_ringbuffer.h b/mesalib/src/gallium/auxiliary/util/u_ringbuffer.h index 177199e94..85f0ad6c1 100644 --- a/mesalib/src/gallium/auxiliary/util/u_ringbuffer.h +++ b/mesalib/src/gallium/auxiliary/util/u_ringbuffer.h @@ -1,29 +1,29 @@ -
-#ifndef UTIL_RINGBUFFER_H
-#define UTIL_RINGBUFFER_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_defines.h" /* only for pipe_error! */
-
-/* Generic header
- */
-struct util_packet {
- unsigned dwords:8;
- unsigned data24:24;
-};
-
-struct util_ringbuffer;
-
-struct util_ringbuffer *util_ringbuffer_create( unsigned dwords );
-
-void util_ringbuffer_destroy( struct util_ringbuffer *ring );
-
-void util_ringbuffer_enqueue( struct util_ringbuffer *ring,
- const struct util_packet *packet );
-
-enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring,
- struct util_packet *packet,
- unsigned max_dwords,
- boolean wait );
-
-#endif
+ +#ifndef UTIL_RINGBUFFER_H +#define UTIL_RINGBUFFER_H + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" /* only for pipe_error! */ + +/* Generic header + */ +struct util_packet { + unsigned dwords:8; + unsigned data24:24; +}; + +struct util_ringbuffer; + +struct util_ringbuffer *util_ringbuffer_create( unsigned dwords ); + +void util_ringbuffer_destroy( struct util_ringbuffer *ring ); + +void util_ringbuffer_enqueue( struct util_ringbuffer *ring, + const struct util_packet *packet ); + +enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, + struct util_packet *packet, + unsigned max_dwords, + boolean wait ); + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_sampler.h b/mesalib/src/gallium/auxiliary/util/u_sampler.h index c7dc03c2f..f3dad7417 100644 --- a/mesalib/src/gallium/auxiliary/util/u_sampler.h +++ b/mesalib/src/gallium/auxiliary/util/u_sampler.h @@ -1,57 +1,57 @@ -/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * 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.
- *
- **************************************************************************/
-
-
-#ifndef U_SAMPLER_H
-#define U_SAMPLER_H
-
-
-#include "pipe/p_defines.h"
-#include "pipe/p_format.h"
-#include "pipe/p_state.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-void
-u_sampler_view_default_template(struct pipe_sampler_view *view,
- const struct pipe_resource *texture,
- enum pipe_format format);
-
-void
-u_sampler_view_default_dx9_template(struct pipe_sampler_view *view,
- const struct pipe_resource *texture,
- enum pipe_format format);
-
-
-#ifdef __cplusplus
-} /* extern "C" { */
-#endif
-
-#endif /* U_SAMPLER_H */
+/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * 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. + * + **************************************************************************/ + + +#ifndef U_SAMPLER_H +#define U_SAMPLER_H + + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format); + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format); + + +#ifdef __cplusplus +} /* extern "C" { */ +#endif + +#endif /* U_SAMPLER_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_list.h b/mesalib/src/gallium/auxiliary/util/u_simple_list.h index e8d12cced..fe5977137 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_list.h +++ b/mesalib/src/gallium/auxiliary/util/u_simple_list.h @@ -1,199 +1,199 @@ -/**
- * \file simple_list.h
- * Simple macros for type-safe, intrusive lists.
- *
- * Intended to work with a list sentinal which is created as an empty
- * list. Insert & delete are O(1).
- *
- * \author
- * (C) 1997, Keith Whitwell
- */
-
-/*
- * Mesa 3-D graphics library
- * Version: 3.5
- *
- * Copyright (C) 1999-2001 Brian Paul 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
- * BRIAN PAUL 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 _U_SIMPLE_LIST_H_
-#define _U_SIMPLE_LIST_H_
-
-/**
- * Remove an element from list.
- *
- * \param elem element to remove.
- */
-#define remove_from_list(elem) \
-do { \
- (elem)->next->prev = (elem)->prev; \
- (elem)->prev->next = (elem)->next; \
- (elem)->next = elem; \
- (elem)->prev = elem; \
-} while (0)
-
-/**
- * Insert an element to the list head.
- *
- * \param list list.
- * \param elem element to insert.
- */
-#define insert_at_head(list, elem) \
-do { \
- (elem)->prev = list; \
- (elem)->next = (list)->next; \
- (list)->next->prev = elem; \
- (list)->next = elem; \
-} while(0)
-
-/**
- * Insert an element to the list tail.
- *
- * \param list list.
- * \param elem element to insert.
- */
-#define insert_at_tail(list, elem) \
-do { \
- (elem)->next = list; \
- (elem)->prev = (list)->prev; \
- (list)->prev->next = elem; \
- (list)->prev = elem; \
-} while(0)
-
-/**
- * Move an element to the list head.
- *
- * \param list list.
- * \param elem element to move.
- */
-#define move_to_head(list, elem) \
-do { \
- remove_from_list(elem); \
- insert_at_head(list, elem); \
-} while (0)
-
-/**
- * Move an element to the list tail.
- *
- * \param list list.
- * \param elem element to move.
- */
-#define move_to_tail(list, elem) \
-do { \
- remove_from_list(elem); \
- insert_at_tail(list, elem); \
-} while (0)
-
-/**
- * Make a empty list empty.
- *
- * \param sentinal list (sentinal element).
- */
-#define make_empty_list(sentinal) \
-do { \
- (sentinal)->next = sentinal; \
- (sentinal)->prev = sentinal; \
-} while (0)
-
-/**
- * Get list first element.
- *
- * \param list list.
- *
- * \return pointer to first element.
- */
-#define first_elem(list) ((list)->next)
-
-/**
- * Get list last element.
- *
- * \param list list.
- *
- * \return pointer to last element.
- */
-#define last_elem(list) ((list)->prev)
-
-/**
- * Get next element.
- *
- * \param elem element.
- *
- * \return pointer to next element.
- */
-#define next_elem(elem) ((elem)->next)
-
-/**
- * Get previous element.
- *
- * \param elem element.
- *
- * \return pointer to previous element.
- */
-#define prev_elem(elem) ((elem)->prev)
-
-/**
- * Test whether element is at end of the list.
- *
- * \param list list.
- * \param elem element.
- *
- * \return non-zero if element is at end of list, or zero otherwise.
- */
-#define at_end(list, elem) ((elem) == (list))
-
-/**
- * Test if a list is empty.
- *
- * \param list list.
- *
- * \return non-zero if list empty, or zero otherwise.
- */
-#define is_empty_list(list) ((list)->next == (list))
-
-/**
- * Walk through the elements of a list.
- *
- * \param ptr pointer to the current element.
- * \param list list.
- *
- * \note It should be followed by a { } block or a single statement, as in a \c
- * for loop.
- */
-#define foreach(ptr, list) \
- for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
-
-/**
- * Walk through the elements of a list.
- *
- * Same as #foreach but lets you unlink the current value during a list
- * traversal. Useful for freeing a list, element by element.
- *
- * \param ptr pointer to the current element.
- * \param t temporary pointer.
- * \param list list.
- *
- * \note It should be followed by a { } block or a single statement, as in a \c
- * for loop.
- */
-#define foreach_s(ptr, t, list) \
- for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)
-
-#endif /* _U_SIMPLE_LIST_H_ */
+/** + * \file simple_list.h + * Simple macros for type-safe, intrusive lists. + * + * Intended to work with a list sentinal which is created as an empty + * list. Insert & delete are O(1). + * + * \author + * (C) 1997, Keith Whitwell + */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * Copyright (C) 1999-2001 Brian Paul 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 + * BRIAN PAUL 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 _U_SIMPLE_LIST_H_ +#define _U_SIMPLE_LIST_H_ + +/** + * Remove an element from list. + * + * \param elem element to remove. + */ +#define remove_from_list(elem) \ +do { \ + (elem)->next->prev = (elem)->prev; \ + (elem)->prev->next = (elem)->next; \ + (elem)->next = elem; \ + (elem)->prev = elem; \ +} while (0) + +/** + * Insert an element to the list head. + * + * \param list list. + * \param elem element to insert. + */ +#define insert_at_head(list, elem) \ +do { \ + (elem)->prev = list; \ + (elem)->next = (list)->next; \ + (list)->next->prev = elem; \ + (list)->next = elem; \ +} while(0) + +/** + * Insert an element to the list tail. + * + * \param list list. + * \param elem element to insert. + */ +#define insert_at_tail(list, elem) \ +do { \ + (elem)->next = list; \ + (elem)->prev = (list)->prev; \ + (list)->prev->next = elem; \ + (list)->prev = elem; \ +} while(0) + +/** + * Move an element to the list head. + * + * \param list list. + * \param elem element to move. + */ +#define move_to_head(list, elem) \ +do { \ + remove_from_list(elem); \ + insert_at_head(list, elem); \ +} while (0) + +/** + * Move an element to the list tail. + * + * \param list list. + * \param elem element to move. + */ +#define move_to_tail(list, elem) \ +do { \ + remove_from_list(elem); \ + insert_at_tail(list, elem); \ +} while (0) + +/** + * Make a empty list empty. + * + * \param sentinal list (sentinal element). + */ +#define make_empty_list(sentinal) \ +do { \ + (sentinal)->next = sentinal; \ + (sentinal)->prev = sentinal; \ +} while (0) + +/** + * Get list first element. + * + * \param list list. + * + * \return pointer to first element. + */ +#define first_elem(list) ((list)->next) + +/** + * Get list last element. + * + * \param list list. + * + * \return pointer to last element. + */ +#define last_elem(list) ((list)->prev) + +/** + * Get next element. + * + * \param elem element. + * + * \return pointer to next element. + */ +#define next_elem(elem) ((elem)->next) + +/** + * Get previous element. + * + * \param elem element. + * + * \return pointer to previous element. + */ +#define prev_elem(elem) ((elem)->prev) + +/** + * Test whether element is at end of the list. + * + * \param list list. + * \param elem element. + * + * \return non-zero if element is at end of list, or zero otherwise. + */ +#define at_end(list, elem) ((elem) == (list)) + +/** + * Test if a list is empty. + * + * \param list list. + * + * \return non-zero if list empty, or zero otherwise. + */ +#define is_empty_list(list) ((list)->next == (list)) + +/** + * Walk through the elements of a list. + * + * \param ptr pointer to the current element. + * \param list list. + * + * \note It should be followed by a { } block or a single statement, as in a \c + * for loop. + */ +#define foreach(ptr, list) \ + for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next ) + +/** + * Walk through the elements of a list. + * + * Same as #foreach but lets you unlink the current value during a list + * traversal. Useful for freeing a list, element by element. + * + * \param ptr pointer to the current element. + * \param t temporary pointer. + * \param list list. + * + * \note It should be followed by a { } block or a single statement, as in a \c + * for loop. + */ +#define foreach_s(ptr, t, list) \ + for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next) + +#endif /* _U_SIMPLE_LIST_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_split_prim.h b/mesalib/src/gallium/auxiliary/util/u_split_prim.h index 9c83d6461..7f80fc127 100644 --- a/mesalib/src/gallium/auxiliary/util/u_split_prim.h +++ b/mesalib/src/gallium/auxiliary/util/u_split_prim.h @@ -1,114 +1,114 @@ -/* Originally written by Ben Skeggs for the nv50 driver*/
-
-#ifndef U_SPLIT_PRIM_H
-#define U_SPLIT_PRIM_H
-
-#include "pipe/p_defines.h"
-#include "pipe/p_compiler.h"
-
-#include "util/u_debug.h"
-
-struct util_split_prim {
- void *priv;
- void (*emit)(void *priv, unsigned start, unsigned count);
- void (*edge)(void *priv, boolean enabled);
-
- unsigned mode;
- unsigned start;
- unsigned p_start;
- unsigned p_end;
-
- uint repeat_first:1;
- uint close_first:1;
- uint edgeflag_off:1;
-};
-
-static INLINE void
-util_split_prim_init(struct util_split_prim *s,
- unsigned mode, unsigned start, unsigned count)
-{
- if (mode == PIPE_PRIM_LINE_LOOP) {
- s->mode = PIPE_PRIM_LINE_STRIP;
- s->close_first = 1;
- } else {
- s->mode = mode;
- s->close_first = 0;
- }
- s->start = start;
- s->p_start = start;
- s->p_end = start + count;
- s->edgeflag_off = 0;
- s->repeat_first = 0;
-}
-
-static INLINE boolean
-util_split_prim_next(struct util_split_prim *s, unsigned max_verts)
-{
- int repeat = 0;
-
- if (s->repeat_first) {
- s->emit(s->priv, s->start, 1);
- max_verts--;
- if (s->edgeflag_off) {
- s->edge(s->priv, TRUE);
- s->edgeflag_off = FALSE;
- }
- }
-
- if ((s->p_end - s->p_start) + s->close_first <= max_verts) {
- s->emit(s->priv, s->p_start, s->p_end - s->p_start);
- if (s->close_first)
- s->emit(s->priv, s->start, 1);
- return TRUE;
- }
-
- switch (s->mode) {
- case PIPE_PRIM_LINES:
- max_verts &= ~1;
- break;
- case PIPE_PRIM_LINE_STRIP:
- repeat = 1;
- break;
- case PIPE_PRIM_POLYGON:
- max_verts--;
- s->emit(s->priv, s->p_start, max_verts);
- s->edge(s->priv, FALSE);
- s->emit(s->priv, s->p_start + max_verts, 1);
- s->p_start += max_verts;
- s->repeat_first = TRUE;
- s->edgeflag_off = TRUE;
- return FALSE;
- case PIPE_PRIM_TRIANGLES:
- max_verts = max_verts - (max_verts % 3);
- break;
- case PIPE_PRIM_TRIANGLE_STRIP:
- /* to ensure winding stays correct, always split
- * on an even number of generated triangles
- */
- max_verts = max_verts & ~1;
- repeat = 2;
- break;
- case PIPE_PRIM_TRIANGLE_FAN:
- s->repeat_first = TRUE;
- repeat = 1;
- break;
- case PIPE_PRIM_QUADS:
- max_verts &= ~3;
- break;
- case PIPE_PRIM_QUAD_STRIP:
- max_verts &= ~1;
- repeat = 2;
- break;
- case PIPE_PRIM_POINTS:
- break;
- default:
- /* TODO: implement adjacency primitives */
- assert(0);
- }
-
- s->emit (s->priv, s->p_start, max_verts);
- s->p_start += (max_verts - repeat);
- return FALSE;
-}
-
-#endif /* U_SPLIT_PRIM_H */
+/* Originally written by Ben Skeggs for the nv50 driver*/ + +#ifndef U_SPLIT_PRIM_H +#define U_SPLIT_PRIM_H + +#include "pipe/p_defines.h" +#include "pipe/p_compiler.h" + +#include "util/u_debug.h" + +struct util_split_prim { + void *priv; + void (*emit)(void *priv, unsigned start, unsigned count); + void (*edge)(void *priv, boolean enabled); + + unsigned mode; + unsigned start; + unsigned p_start; + unsigned p_end; + + uint repeat_first:1; + uint close_first:1; + uint edgeflag_off:1; +}; + +static INLINE void +util_split_prim_init(struct util_split_prim *s, + unsigned mode, unsigned start, unsigned count) +{ + if (mode == PIPE_PRIM_LINE_LOOP) { + s->mode = PIPE_PRIM_LINE_STRIP; + s->close_first = 1; + } else { + s->mode = mode; + s->close_first = 0; + } + s->start = start; + s->p_start = start; + s->p_end = start + count; + s->edgeflag_off = 0; + s->repeat_first = 0; +} + +static INLINE boolean +util_split_prim_next(struct util_split_prim *s, unsigned max_verts) +{ + int repeat = 0; + + if (s->repeat_first) { + s->emit(s->priv, s->start, 1); + max_verts--; + if (s->edgeflag_off) { + s->edge(s->priv, TRUE); + s->edgeflag_off = FALSE; + } + } + + if ((s->p_end - s->p_start) + s->close_first <= max_verts) { + s->emit(s->priv, s->p_start, s->p_end - s->p_start); + if (s->close_first) + s->emit(s->priv, s->start, 1); + return TRUE; + } + + switch (s->mode) { + case PIPE_PRIM_LINES: + max_verts &= ~1; + break; + case PIPE_PRIM_LINE_STRIP: + repeat = 1; + break; + case PIPE_PRIM_POLYGON: + max_verts--; + s->emit(s->priv, s->p_start, max_verts); + s->edge(s->priv, FALSE); + s->emit(s->priv, s->p_start + max_verts, 1); + s->p_start += max_verts; + s->repeat_first = TRUE; + s->edgeflag_off = TRUE; + return FALSE; + case PIPE_PRIM_TRIANGLES: + max_verts = max_verts - (max_verts % 3); + break; + case PIPE_PRIM_TRIANGLE_STRIP: + /* to ensure winding stays correct, always split + * on an even number of generated triangles + */ + max_verts = max_verts & ~1; + repeat = 2; + break; + case PIPE_PRIM_TRIANGLE_FAN: + s->repeat_first = TRUE; + repeat = 1; + break; + case PIPE_PRIM_QUADS: + max_verts &= ~3; + break; + case PIPE_PRIM_QUAD_STRIP: + max_verts &= ~1; + repeat = 2; + break; + case PIPE_PRIM_POINTS: + break; + default: + /* TODO: implement adjacency primitives */ + assert(0); + } + + s->emit (s->priv, s->p_start, max_verts); + s->p_start += (max_verts - repeat); + return FALSE; +} + +#endif /* U_SPLIT_PRIM_H */ diff --git a/mesalib/src/gallium/auxiliary/util/u_sse.h b/mesalib/src/gallium/auxiliary/util/u_sse.h index d000c0fd7..1df6c8726 100644 --- a/mesalib/src/gallium/auxiliary/util/u_sse.h +++ b/mesalib/src/gallium/auxiliary/util/u_sse.h @@ -1,255 +1,255 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * SSE intrinsics portability header.
- *
- * Although the SSE intrinsics are support by all modern x86 and x86-64
- * compilers, there are some intrisincs missing in some implementations
- * (especially older MSVC versions). This header abstracts that away.
- */
-
-#ifndef U_SSE_H_
-#define U_SSE_H_
-
-#include "pipe/p_config.h"
-
-#if defined(PIPE_ARCH_SSE)
-
-#include <emmintrin.h>
-
-
-/* MSVC before VC8 does not support the _mm_castxxx_yyy */
-#if defined(_MSC_VER) && _MSC_VER < 1500
-
-union __declspec(align(16)) m128_types {
- __m128 m128;
- __m128i m128i;
- __m128d m128d;
-};
-
-static __inline __m128
-_mm_castsi128_ps(__m128i a)
-{
- union m128_types u;
- u.m128i = a;
- return u.m128;
-}
-
-static __inline __m128i
-_mm_castps_si128(__m128 a)
-{
- union m128_types u;
- u.m128 = a;
- return u.m128i;
-}
-
-#endif /* defined(_MSC_VER) && _MSC_VER < 1500 */
-
-union m128i {
- __m128i m;
- ubyte ub[16];
- ushort us[8];
- uint ui[4];
-};
-
-static INLINE void u_print_epi8(const char *name, __m128i r)
-{
- union { __m128i m; ubyte ub[16]; } u;
- u.m = r;
-
- debug_printf("%s: "
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x/"
- "%02x\n",
- name,
- u.ub[0], u.ub[1], u.ub[2], u.ub[3],
- u.ub[4], u.ub[5], u.ub[6], u.ub[7],
- u.ub[8], u.ub[9], u.ub[10], u.ub[11],
- u.ub[12], u.ub[13], u.ub[14], u.ub[15]);
-}
-
-static INLINE void u_print_epi16(const char *name, __m128i r)
-{
- union { __m128i m; ushort us[8]; } u;
- u.m = r;
-
- debug_printf("%s: "
- "%04x/"
- "%04x/"
- "%04x/"
- "%04x/"
- "%04x/"
- "%04x/"
- "%04x/"
- "%04x\n",
- name,
- u.us[0], u.us[1], u.us[2], u.us[3],
- u.us[4], u.us[5], u.us[6], u.us[7]);
-}
-
-static INLINE void u_print_epi32(const char *name, __m128i r)
-{
- union { __m128i m; uint ui[4]; } u;
- u.m = r;
-
- debug_printf("%s: "
- "%08x/"
- "%08x/"
- "%08x/"
- "%08x\n",
- name,
- u.ui[0], u.ui[1], u.ui[2], u.ui[3]);
-}
-
-static INLINE void u_print_ps(const char *name, __m128 r)
-{
- union { __m128 m; float f[4]; } u;
- u.m = r;
-
- debug_printf("%s: "
- "%f/"
- "%f/"
- "%f/"
- "%f\n",
- name,
- u.f[0], u.f[1], u.f[2], u.f[3]);
-}
-
-
-#define U_DUMP_EPI32(a) u_print_epi32(#a, a)
-#define U_DUMP_EPI16(a) u_print_epi16(#a, a)
-#define U_DUMP_EPI8(a) u_print_epi8(#a, a)
-#define U_DUMP_PS(a) u_print_ps(#a, a)
-
-
-
-#if defined(PIPE_ARCH_SSSE3)
-
-#include <tmmintrin.h>
-
-#else /* !PIPE_ARCH_SSSE3 */
-
-/**
- * Describe _mm_shuffle_epi8() with gcc extended inline assembly, for cases
- * where -mssse3 is not supported/enabled.
- *
- * MSVC will never get in here as its intrinsics support do not rely on
- * compiler command line options.
- */
-static __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_shuffle_epi8(__m128i a, __m128i mask)
-{
- __m128i result;
- __asm__("pshufb %1, %0"
- : "=x" (result)
- : "xm" (mask), "0" (a));
- return result;
-}
-
-#endif /* !PIPE_ARCH_SSSE3 */
-
-
-
-
-/* Provide an SSE2 implementation of _mm_mullo_epi32() in terms of
- * _mm_mul_epu32().
- *
- * I suspect this works fine for us because one of our operands is
- * always positive, but not sure that this can be used for general
- * signed integer multiplication.
- *
- * This seems close enough to the speed of SSE4 and the real
- * _mm_mullo_epi32() intrinsic as to not justify adding an sse4
- * dependency at this point.
- */
-static INLINE __m128i mm_mullo_epi32(const __m128i a, const __m128i b)
-{
- __m128i a4 = _mm_srli_epi64(a, 32); /* shift by one dword */
- __m128i b4 = _mm_srli_epi64(b, 32); /* shift by one dword */
- __m128i ba = _mm_mul_epu32(b, a); /* multply dwords 0, 2 */
- __m128i b4a4 = _mm_mul_epu32(b4, a4); /* multiply dwords 1, 3 */
-
- /* Interleave the results, either with shuffles or (slightly
- * faster) direct bit operations:
- */
-#if 0
- __m128i ba8 = _mm_shuffle_epi32(ba, 8);
- __m128i b4a48 = _mm_shuffle_epi32(b4a4, 8);
- __m128i result = _mm_unpacklo_epi32(ba8, b4a48);
-#else
- __m128i mask = _mm_setr_epi32(~0,0,~0,0);
- __m128i ba_mask = _mm_and_si128(ba, mask);
- __m128i b4a4_mask_shift = _mm_slli_epi64(b4a4, 32);
- __m128i result = _mm_or_si128(ba_mask, b4a4_mask_shift);
-#endif
-
- return result;
-}
-
-
-static INLINE void
-transpose4_epi32(const __m128i * restrict a,
- const __m128i * restrict b,
- const __m128i * restrict c,
- const __m128i * restrict d,
- __m128i * restrict o,
- __m128i * restrict p,
- __m128i * restrict q,
- __m128i * restrict r)
-{
- __m128i t0 = _mm_unpacklo_epi32(*a, *b);
- __m128i t1 = _mm_unpacklo_epi32(*c, *d);
- __m128i t2 = _mm_unpackhi_epi32(*a, *b);
- __m128i t3 = _mm_unpackhi_epi32(*c, *d);
-
- *o = _mm_unpacklo_epi64(t0, t1);
- *p = _mm_unpackhi_epi64(t0, t1);
- *q = _mm_unpacklo_epi64(t2, t3);
- *r = _mm_unpackhi_epi64(t2, t3);
-}
-
-#define SCALAR_EPI32(m, i) _mm_shuffle_epi32((m), _MM_SHUFFLE(i,i,i,i))
-
-
-#endif /* PIPE_ARCH_SSE */
-
-#endif /* U_SSE_H_ */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * SSE intrinsics portability header. + * + * Although the SSE intrinsics are support by all modern x86 and x86-64 + * compilers, there are some intrisincs missing in some implementations + * (especially older MSVC versions). This header abstracts that away. + */ + +#ifndef U_SSE_H_ +#define U_SSE_H_ + +#include "pipe/p_config.h" + +#if defined(PIPE_ARCH_SSE) + +#include <emmintrin.h> + + +/* MSVC before VC8 does not support the _mm_castxxx_yyy */ +#if defined(_MSC_VER) && _MSC_VER < 1500 + +union __declspec(align(16)) m128_types { + __m128 m128; + __m128i m128i; + __m128d m128d; +}; + +static __inline __m128 +_mm_castsi128_ps(__m128i a) +{ + union m128_types u; + u.m128i = a; + return u.m128; +} + +static __inline __m128i +_mm_castps_si128(__m128 a) +{ + union m128_types u; + u.m128 = a; + return u.m128i; +} + +#endif /* defined(_MSC_VER) && _MSC_VER < 1500 */ + +union m128i { + __m128i m; + ubyte ub[16]; + ushort us[8]; + uint ui[4]; +}; + +static INLINE void u_print_epi8(const char *name, __m128i r) +{ + union { __m128i m; ubyte ub[16]; } u; + u.m = r; + + debug_printf("%s: " + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x\n", + name, + u.ub[0], u.ub[1], u.ub[2], u.ub[3], + u.ub[4], u.ub[5], u.ub[6], u.ub[7], + u.ub[8], u.ub[9], u.ub[10], u.ub[11], + u.ub[12], u.ub[13], u.ub[14], u.ub[15]); +} + +static INLINE void u_print_epi16(const char *name, __m128i r) +{ + union { __m128i m; ushort us[8]; } u; + u.m = r; + + debug_printf("%s: " + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x\n", + name, + u.us[0], u.us[1], u.us[2], u.us[3], + u.us[4], u.us[5], u.us[6], u.us[7]); +} + +static INLINE void u_print_epi32(const char *name, __m128i r) +{ + union { __m128i m; uint ui[4]; } u; + u.m = r; + + debug_printf("%s: " + "%08x/" + "%08x/" + "%08x/" + "%08x\n", + name, + u.ui[0], u.ui[1], u.ui[2], u.ui[3]); +} + +static INLINE void u_print_ps(const char *name, __m128 r) +{ + union { __m128 m; float f[4]; } u; + u.m = r; + + debug_printf("%s: " + "%f/" + "%f/" + "%f/" + "%f\n", + name, + u.f[0], u.f[1], u.f[2], u.f[3]); +} + + +#define U_DUMP_EPI32(a) u_print_epi32(#a, a) +#define U_DUMP_EPI16(a) u_print_epi16(#a, a) +#define U_DUMP_EPI8(a) u_print_epi8(#a, a) +#define U_DUMP_PS(a) u_print_ps(#a, a) + + + +#if defined(PIPE_ARCH_SSSE3) + +#include <tmmintrin.h> + +#else /* !PIPE_ARCH_SSSE3 */ + +/** + * Describe _mm_shuffle_epi8() with gcc extended inline assembly, for cases + * where -mssse3 is not supported/enabled. + * + * MSVC will never get in here as its intrinsics support do not rely on + * compiler command line options. + */ +static __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_shuffle_epi8(__m128i a, __m128i mask) +{ + __m128i result; + __asm__("pshufb %1, %0" + : "=x" (result) + : "xm" (mask), "0" (a)); + return result; +} + +#endif /* !PIPE_ARCH_SSSE3 */ + + + + +/* Provide an SSE2 implementation of _mm_mullo_epi32() in terms of + * _mm_mul_epu32(). + * + * I suspect this works fine for us because one of our operands is + * always positive, but not sure that this can be used for general + * signed integer multiplication. + * + * This seems close enough to the speed of SSE4 and the real + * _mm_mullo_epi32() intrinsic as to not justify adding an sse4 + * dependency at this point. + */ +static INLINE __m128i mm_mullo_epi32(const __m128i a, const __m128i b) +{ + __m128i a4 = _mm_srli_epi64(a, 32); /* shift by one dword */ + __m128i b4 = _mm_srli_epi64(b, 32); /* shift by one dword */ + __m128i ba = _mm_mul_epu32(b, a); /* multply dwords 0, 2 */ + __m128i b4a4 = _mm_mul_epu32(b4, a4); /* multiply dwords 1, 3 */ + + /* Interleave the results, either with shuffles or (slightly + * faster) direct bit operations: + */ +#if 0 + __m128i ba8 = _mm_shuffle_epi32(ba, 8); + __m128i b4a48 = _mm_shuffle_epi32(b4a4, 8); + __m128i result = _mm_unpacklo_epi32(ba8, b4a48); +#else + __m128i mask = _mm_setr_epi32(~0,0,~0,0); + __m128i ba_mask = _mm_and_si128(ba, mask); + __m128i b4a4_mask_shift = _mm_slli_epi64(b4a4, 32); + __m128i result = _mm_or_si128(ba_mask, b4a4_mask_shift); +#endif + + return result; +} + + +static INLINE void +transpose4_epi32(const __m128i * restrict a, + const __m128i * restrict b, + const __m128i * restrict c, + const __m128i * restrict d, + __m128i * restrict o, + __m128i * restrict p, + __m128i * restrict q, + __m128i * restrict r) +{ + __m128i t0 = _mm_unpacklo_epi32(*a, *b); + __m128i t1 = _mm_unpacklo_epi32(*c, *d); + __m128i t2 = _mm_unpackhi_epi32(*a, *b); + __m128i t3 = _mm_unpackhi_epi32(*c, *d); + + *o = _mm_unpacklo_epi64(t0, t1); + *p = _mm_unpackhi_epi64(t0, t1); + *q = _mm_unpacklo_epi64(t2, t3); + *r = _mm_unpackhi_epi64(t2, t3); +} + +#define SCALAR_EPI32(m, i) _mm_shuffle_epi32((m), _MM_SHUFFLE(i,i,i,i)) + + +#endif /* PIPE_ARCH_SSE */ + +#endif /* U_SSE_H_ */ diff --git a/mesalib/src/gallium/auxiliary/util/u_surfaces.c b/mesalib/src/gallium/auxiliary/util/u_surfaces.c index 9a42c9d29..b0cfec2a8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_surfaces.c +++ b/mesalib/src/gallium/auxiliary/util/u_surfaces.c @@ -1,124 +1,124 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#include "u_surfaces.h"
-#include "util/u_hash_table.h"
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-
-boolean
-util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size,
- struct pipe_context *ctx, struct pipe_resource *pt,
- unsigned level, unsigned layer, unsigned flags,
- struct pipe_surface **res)
-{
- struct pipe_surface *ps;
-
- if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- { /* or 2D array */
- if(!us->u.hash)
- us->u.hash = cso_hash_create();
-
- ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
- }
- else
- {
- if(!us->u.array)
- us->u.array = CALLOC(pt->last_level + 1, sizeof(struct pipe_surface *));
- ps = us->u.array[level];
- }
-
- if(ps && ps->context == ctx)
- {
- p_atomic_inc(&ps->reference.count);
- *res = ps;
- return FALSE;
- }
-
- ps = (struct pipe_surface *)CALLOC(1, surface_struct_size);
- if(!ps)
- {
- *res = NULL;
- return FALSE;
- }
-
- pipe_surface_init(ctx, ps, pt, level, layer, flags);
-
- if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- cso_hash_insert(us->u.hash, (layer << 8) | level, ps);
- else
- us->u.array[level] = ps;
-
- *res = ps;
- return TRUE;
-}
-
-void
-util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps)
-{
- struct pipe_resource *pt = ps->texture;
- if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- { /* or 2D array */
- cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level));
- }
- else
- us->u.array[ps->u.tex.level] = 0;
-}
-
-void
-util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *))
-{
- if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- { /* or 2D array */
- if(us->u.hash)
- {
- struct cso_hash_iter iter;
- iter = cso_hash_first_node(us->u.hash);
- while (!cso_hash_iter_is_null(iter)) {
- destroy_surface(cso_hash_iter_data(iter));
- iter = cso_hash_iter_next(iter);
- }
-
- cso_hash_delete(us->u.hash);
- us->u.hash = NULL;
- }
- }
- else
- {
- if(us->u.array)
- {
- unsigned i;
- for(i = 0; i <= pt->last_level; ++i)
- {
- struct pipe_surface *ps = us->u.array[i];
- if(ps)
- destroy_surface(ps);
- }
- FREE(us->u.array);
- us->u.array = NULL;
- }
- }
-}
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#include "u_surfaces.h" +#include "util/u_hash_table.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" + +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) +{ + struct pipe_surface *ps; + + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + if(!us->u.hash) + us->u.hash = cso_hash_create(); + + ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); + } + else + { + if(!us->u.array) + us->u.array = CALLOC(pt->last_level + 1, sizeof(struct pipe_surface *)); + ps = us->u.array[level]; + } + + if(ps && ps->context == ctx) + { + p_atomic_inc(&ps->reference.count); + *res = ps; + return FALSE; + } + + ps = (struct pipe_surface *)CALLOC(1, surface_struct_size); + if(!ps) + { + *res = NULL; + return FALSE; + } + + pipe_surface_init(ctx, ps, pt, level, layer, flags); + + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + cso_hash_insert(us->u.hash, (layer << 8) | level, ps); + else + us->u.array[level] = ps; + + *res = ps; + return TRUE; +} + +void +util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps) +{ + struct pipe_resource *pt = ps->texture; + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level)); + } + else + us->u.array[ps->u.tex.level] = 0; +} + +void +util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *)) +{ + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + if(us->u.hash) + { + struct cso_hash_iter iter; + iter = cso_hash_first_node(us->u.hash); + while (!cso_hash_iter_is_null(iter)) { + destroy_surface(cso_hash_iter_data(iter)); + iter = cso_hash_iter_next(iter); + } + + cso_hash_delete(us->u.hash); + us->u.hash = NULL; + } + } + else + { + if(us->u.array) + { + unsigned i; + for(i = 0; i <= pt->last_level; ++i) + { + struct pipe_surface *ps = us->u.array[i]; + if(ps) + destroy_surface(ps); + } + FREE(us->u.array); + us->u.array = NULL; + } + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_surfaces.h b/mesalib/src/gallium/auxiliary/util/u_surfaces.h index 2402e8841..9581feda7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_surfaces.h +++ b/mesalib/src/gallium/auxiliary/util/u_surfaces.h @@ -1,101 +1,101 @@ -/**************************************************************************
- *
- * Copyright 2010 Luca Barbieri
- *
- * 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 COPYRIGHT OWNER(S) 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.
- *
- **************************************************************************/
-
-#ifndef U_SURFACES_H_
-#define U_SURFACES_H_
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-#include "util/u_atomic.h"
-#include "cso_cache/cso_hash.h"
-
-struct util_surfaces
-{
- union
- {
- struct cso_hash *hash;
- struct pipe_surface **array;
- void* pv;
- } u;
-};
-
-/* Return value indicates if the pipe surface result is new */
-boolean
-util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size,
- struct pipe_context *ctx, struct pipe_resource *pt,
- unsigned level, unsigned layer, unsigned flags,
- struct pipe_surface **res);
-
-/* fast inline path for the very common case */
-static INLINE boolean
-util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size,
- struct pipe_context *ctx, struct pipe_resource *pt,
- unsigned level, unsigned layer, unsigned flags,
- struct pipe_surface **res)
-{
- if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array))
- {
- struct pipe_surface *ps = us->u.array[level];
- if(ps && ps->context == ctx)
- {
- p_atomic_inc(&ps->reference.count);
- *res = ps;
- return FALSE;
- }
- }
-
- return util_surfaces_do_get(us, surface_struct_size, ctx, pt, level, layer, flags, res);
-}
-
-static INLINE struct pipe_surface *
-util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned level, unsigned layer)
-{
- if(!us->u.pv)
- return 0;
-
- if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE))
- return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
- else
- return us->u.array[level];
-}
-
-void util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps);
-
-static INLINE void
-util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps)
-{
- if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT))
- {
- us->u.array[ps->u.tex.level] = 0;
- return;
- }
-
- util_surfaces_do_detach(us, ps);
-}
-
-void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *));
-
-#endif
+/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * 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 COPYRIGHT OWNER(S) 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. + * + **************************************************************************/ + +#ifndef U_SURFACES_H_ +#define U_SURFACES_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_atomic.h" +#include "cso_cache/cso_hash.h" + +struct util_surfaces +{ + union + { + struct cso_hash *hash; + struct pipe_surface **array; + void* pv; + } u; +}; + +/* Return value indicates if the pipe surface result is new */ +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res); + +/* fast inline path for the very common case */ +static INLINE boolean +util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) +{ + if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array)) + { + struct pipe_surface *ps = us->u.array[level]; + if(ps && ps->context == ctx) + { + p_atomic_inc(&ps->reference.count); + *res = ps; + return FALSE; + } + } + + return util_surfaces_do_get(us, surface_struct_size, ctx, pt, level, layer, flags, res); +} + +static INLINE struct pipe_surface * +util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned level, unsigned layer) +{ + if(!us->u.pv) + return 0; + + if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)) + return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); + else + return us->u.array[level]; +} + +void util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps); + +static INLINE void +util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps) +{ + if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT)) + { + us->u.array[ps->u.tex.level] = 0; + return; + } + + util_surfaces_do_detach(us, ps); +} + +void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *)); + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_texture.c b/mesalib/src/gallium/auxiliary/util/u_texture.c index 1e72843f0..d97e57a79 100644 --- a/mesalib/src/gallium/auxiliary/util/u_texture.c +++ b/mesalib/src/gallium/auxiliary/util/u_texture.c @@ -1,103 +1,103 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- * Copyright 2008 VMware, Inc. All rights reserved.
- * Copyright 2009 Marek Olšák <maraeo@gmail.com>
- *
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * Texture mapping utility functions.
- *
- * @author Brian Paul
- * Marek Olšák
- */
-
-#include "pipe/p_defines.h"
-
-#include "util/u_debug.h"
-#include "util/u_texture.h"
-
-void util_map_texcoords2d_onto_cubemap(unsigned face,
- const float *in_st, unsigned in_stride,
- float *out_str, unsigned out_stride)
-{
- int i;
- float rx, ry, rz;
-
- /* loop over quad verts */
- for (i = 0; i < 4; i++) {
- /* Compute sc = +/-scale and tc = +/-scale.
- * Not +/-1 to avoid cube face selection ambiguity near the edges,
- * though that can still sometimes happen with this scale factor...
- */
- const float scale = 0.9999f;
- const float sc = (2 * in_st[0] - 1) * scale;
- const float tc = (2 * in_st[1] - 1) * scale;
-
- switch (face) {
- case PIPE_TEX_FACE_POS_X:
- rx = 1;
- ry = -tc;
- rz = -sc;
- break;
- case PIPE_TEX_FACE_NEG_X:
- rx = -1;
- ry = -tc;
- rz = sc;
- break;
- case PIPE_TEX_FACE_POS_Y:
- rx = sc;
- ry = 1;
- rz = tc;
- break;
- case PIPE_TEX_FACE_NEG_Y:
- rx = sc;
- ry = -1;
- rz = -tc;
- break;
- case PIPE_TEX_FACE_POS_Z:
- rx = sc;
- ry = -tc;
- rz = 1;
- break;
- case PIPE_TEX_FACE_NEG_Z:
- rx = -sc;
- ry = -tc;
- rz = -1;
- break;
- default:
- rx = ry = rz = 0;
- assert(0);
- }
-
- out_str[0] = rx; /*s*/
- out_str[1] = ry; /*t*/
- out_str[2] = rz; /*r*/
-
- in_st += in_stride;
- out_str += out_stride;
- }
-}
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 VMware, Inc. All rights reserved. + * Copyright 2009 Marek Olšák <maraeo@gmail.com> + * + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * Texture mapping utility functions. + * + * @author Brian Paul + * Marek Olšák + */ + +#include "pipe/p_defines.h" + +#include "util/u_debug.h" +#include "util/u_texture.h" + +void util_map_texcoords2d_onto_cubemap(unsigned face, + const float *in_st, unsigned in_stride, + float *out_str, unsigned out_stride) +{ + int i; + float rx, ry, rz; + + /* loop over quad verts */ + for (i = 0; i < 4; i++) { + /* Compute sc = +/-scale and tc = +/-scale. + * Not +/-1 to avoid cube face selection ambiguity near the edges, + * though that can still sometimes happen with this scale factor... + */ + const float scale = 0.9999f; + const float sc = (2 * in_st[0] - 1) * scale; + const float tc = (2 * in_st[1] - 1) * scale; + + switch (face) { + case PIPE_TEX_FACE_POS_X: + rx = 1; + ry = -tc; + rz = -sc; + break; + case PIPE_TEX_FACE_NEG_X: + rx = -1; + ry = -tc; + rz = sc; + break; + case PIPE_TEX_FACE_POS_Y: + rx = sc; + ry = 1; + rz = tc; + break; + case PIPE_TEX_FACE_NEG_Y: + rx = sc; + ry = -1; + rz = -tc; + break; + case PIPE_TEX_FACE_POS_Z: + rx = sc; + ry = -tc; + rz = 1; + break; + case PIPE_TEX_FACE_NEG_Z: + rx = -sc; + ry = -tc; + rz = -1; + break; + default: + rx = ry = rz = 0; + assert(0); + } + + out_str[0] = rx; /*s*/ + out_str[1] = ry; /*t*/ + out_str[2] = rz; /*r*/ + + in_st += in_stride; + out_str += out_stride; + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_texture.h b/mesalib/src/gallium/auxiliary/util/u_texture.h index 3e03911ec..93b2f1e4c 100644 --- a/mesalib/src/gallium/auxiliary/util/u_texture.h +++ b/mesalib/src/gallium/auxiliary/util/u_texture.h @@ -1,54 +1,54 @@ -/**************************************************************************
- *
- * Copyright 2009 Marek Olšák <maraeo@gmail.com>
- *
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#ifndef U_TEXTURE_H
-#define U_TEXTURE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Convert 2D texture coordinates of 4 vertices into cubemap coordinates
- * in the given face.
- * Coordinates must be in the range [0,1].
- *
- * \param face Cubemap face.
- * \param in_st 4 pairs of 2D texture coordinates to convert.
- * \param in_stride Stride of in_st in floats.
- * \param out_str STR cubemap texture coordinates to compute.
- * \param out_stride Stride of out_str in floats.
- */
-void util_map_texcoords2d_onto_cubemap(unsigned face,
- const float *in_st, unsigned in_stride,
- float *out_str, unsigned out_stride);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/************************************************************************** + * + * Copyright 2009 Marek Olšák <maraeo@gmail.com> + * + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +#ifndef U_TEXTURE_H +#define U_TEXTURE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convert 2D texture coordinates of 4 vertices into cubemap coordinates + * in the given face. + * Coordinates must be in the range [0,1]. + * + * \param face Cubemap face. + * \param in_st 4 pairs of 2D texture coordinates to convert. + * \param in_stride Stride of in_st in floats. + * \param out_str STR cubemap texture coordinates to compute. + * \param out_stride Stride of out_str in floats. + */ +void util_map_texcoords2d_onto_cubemap(unsigned face, + const float *in_st, unsigned in_stride, + float *out_str, unsigned out_stride); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_time.h b/mesalib/src/gallium/auxiliary/util/u_time.h index a65cd59fe..15899c2c8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_time.h +++ b/mesalib/src/gallium/auxiliary/util/u_time.h @@ -1,150 +1,150 @@ -/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-/**
- * @file
- * OS independent time-manipulation functions.
- *
- * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-#ifndef U_TIME_H_
-#define U_TIME_H_
-
-
-#include "pipe/p_config.h"
-
-#include "os/os_time.h"
-
-#include "pipe/p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/**
- * Time abstraction.
- *
- * Do not access this structure directly. Use the provided function instead.
- */
-struct util_time
-{
- int64_t counter;
-};
-
-
-PIPE_DEPRECATED
-static INLINE void
-util_time_get(struct util_time *t)
-{
- t->counter = os_time_get();
-}
-
-
-/**
- * Return t2 = t1 + usecs
- */
-PIPE_DEPRECATED
-static INLINE void
-util_time_add(const struct util_time *t1,
- int64_t usecs,
- struct util_time *t2)
-{
- t2->counter = t1->counter + usecs;
-}
-
-
-/**
- * Return difference between times, in microseconds
- */
-PIPE_DEPRECATED
-static INLINE int64_t
-util_time_diff(const struct util_time *t1,
- const struct util_time *t2)
-{
- return t2->counter - t1->counter;
-}
-
-
-/**
- * Compare two time values.
- *
- * Not publicly available because it does not take in account wrap-arounds.
- * Use util_time_timeout instead.
- */
-static INLINE int
-_util_time_compare(const struct util_time *t1,
- const struct util_time *t2)
-{
- if (t1->counter < t2->counter)
- return -1;
- else if(t1->counter > t2->counter)
- return 1;
- else
- return 0;
-}
-
-
-/**
- * Returns non-zero when the timeout expires.
- */
-PIPE_DEPRECATED
-static INLINE boolean
-util_time_timeout(const struct util_time *start,
- const struct util_time *end,
- const struct util_time *curr)
-{
- return os_time_timeout(start->counter, end->counter, curr->counter);
-}
-
-
-/**
- * Return current time in microseconds
- */
-PIPE_DEPRECATED
-static INLINE int64_t
-util_time_micros(void)
-{
- return os_time_get();
-}
-
-
-PIPE_DEPRECATED
-static INLINE void
-util_time_sleep(int64_t usecs)
-{
- os_time_sleep(usecs);
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* U_TIME_H_ */
+/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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 TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca <jrfonseca@tungstengraphics.com> + */ + +#ifndef U_TIME_H_ +#define U_TIME_H_ + + +#include "pipe/p_config.h" + +#include "os/os_time.h" + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Time abstraction. + * + * Do not access this structure directly. Use the provided function instead. + */ +struct util_time +{ + int64_t counter; +}; + + +PIPE_DEPRECATED +static INLINE void +util_time_get(struct util_time *t) +{ + t->counter = os_time_get(); +} + + +/** + * Return t2 = t1 + usecs + */ +PIPE_DEPRECATED +static INLINE void +util_time_add(const struct util_time *t1, + int64_t usecs, + struct util_time *t2) +{ + t2->counter = t1->counter + usecs; +} + + +/** + * Return difference between times, in microseconds + */ +PIPE_DEPRECATED +static INLINE int64_t +util_time_diff(const struct util_time *t1, + const struct util_time *t2) +{ + return t2->counter - t1->counter; +} + + +/** + * Compare two time values. + * + * Not publicly available because it does not take in account wrap-arounds. + * Use util_time_timeout instead. + */ +static INLINE int +_util_time_compare(const struct util_time *t1, + const struct util_time *t2) +{ + if (t1->counter < t2->counter) + return -1; + else if(t1->counter > t2->counter) + return 1; + else + return 0; +} + + +/** + * Returns non-zero when the timeout expires. + */ +PIPE_DEPRECATED +static INLINE boolean +util_time_timeout(const struct util_time *start, + const struct util_time *end, + const struct util_time *curr) +{ + return os_time_timeout(start->counter, end->counter, curr->counter); +} + + +/** + * Return current time in microseconds + */ +PIPE_DEPRECATED +static INLINE int64_t +util_time_micros(void) +{ + return os_time_get(); +} + + +PIPE_DEPRECATED +static INLINE void +util_time_sleep(int64_t usecs) +{ + os_time_sleep(usecs); +} + + +#ifdef __cplusplus +} +#endif + +#endif /* U_TIME_H_ */ |