[Mesa-dev] [PATCH 00/28] Make use of utils functions more

Dylan Baker dylan at pnwbakers.com
Fri Nov 9 18:39:53 UTC 2018


Mesa has a lot of internal code duplication, sometimes it's exactly the same
code in two different places, sometimes it's code where one copy has a fast path
and the other doesn't.

After I imported u_math into src/utils I realized just how much of this
duplication there was, and started looking at cleaning it up. In the process I
managed to delete about 500 lines of code and completely delete imports.c and
imports.h from mesa. There's more work to be done, but this is already a pretty
big chunk, so I'll send this out for review.

I've put this through our CI, I've also built some other configurations like
class swrast and osmesa, and built the mingw target with scons.

Dylan Baker (28):
  replace _mesa_is_pow_two with util_is_power_of_two_*
  replace _mesa_next_pow_two_* with util_next_power_of_two_*
  replace _mesa_logbase2 with util_logbase2
  r200: use preprocessor for big vs little endian checks
  r100: Use preprocessor to select big vs little endian paths
  dri/osmesa: use preprocessor for selecting endian code paths
  util/u_endian: set PIPE_ARCH_*_ENDIAN to 1
  mesa/main: replace uses of _mesa_little_endian with preprocessor
  mesa/swrast: replace instances of _mesa_little_endian with
    preprocessor
  mesa/main: delete now unused _mesa_little_endian
  replace LOG2 with util_fast_log2
  u_math: add x86 optimized version of ifloor
  replace IFLOOR with util_ifloor
  replace _mesa_vsnprtinf with util_vsnprtinf
  replace _mesa_snprintf with util_snprintf
  Replace IROUND_POS with _mesa_roundevenf
  mesa/main: remove unused IROUNDD
  use util_strcasecmp in places that may be compiled on msvc
  replace IROUND with util functions
  move windows strtok_r define to u_string
  Replace IS_INF_OR_NAN with util_is_inf_or_nan
  util: promote u_memory to src/util
  amd/vulkan: Remove FREE alias for free
  replace malloc macros in imports.h with u_memory.h versions
  util: Add an aligned realloc function
  replace imports memory functions with utils memory functions
  mesa: move ADD_POINTERS to macros.h
  remove final imports.h bits

 src/Makefile.am                               |   1 -
 src/amd/vulkan/radv_radeon_winsys.h           |   2 -
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c |   9 +-
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c |   8 +-
 .../vulkan/winsys/amdgpu/radv_amdgpu_winsys.c |   2 +-
 src/compiler/SConscript.glsl                  |   2 -
 src/compiler/glsl/glsl_parser.yy              |   3 +-
 src/compiler/glsl/glsl_to_nir.cpp             |   1 -
 src/compiler/glsl/linker.cpp                  |   1 -
 src/compiler/nir/nir_opt_copy_propagate.c     |   1 -
 src/gallium/auxiliary/Makefile.sources        |   5 -
 src/gallium/auxiliary/meson.build             |   5 -
 src/gallium/auxiliary/util/u_debug_memory.c   |   4 +-
 src/gallium/auxiliary/util/u_format.c         |   2 +-
 src/gallium/auxiliary/util/u_format_tests.c   |   2 +-
 src/gallium/auxiliary/util/u_log.c            |   2 +-
 src/gallium/auxiliary/util/u_prim_restart.c   |   2 +-
 src/gallium/state_trackers/dri/dri_context.c  |   2 +
 src/gallium/state_trackers/glx/xlib/glx_api.c |   2 +-
 src/gallium/state_trackers/glx/xlib/xm_api.c  |   2 +-
 src/intel/compiler/brw_eu_emit.c              |   4 +-
 src/intel/compiler/brw_fs.cpp                 |   2 +-
 src/intel/compiler/brw_fs_generator.cpp       |   2 +-
 src/intel/compiler/brw_fs_reg_allocate.cpp    |   4 +-
 src/intel/compiler/brw_ir_fs.h                |   4 +-
 src/intel/compiler/brw_reg.h                  |   2 +-
 src/intel/compiler/brw_vec4_generator.cpp     |   3 +-
 src/mapi/glapi/gen/gl_enums.py                |   4 +-
 src/mapi/glapi/gen/gl_genexec.py              |   2 +-
 src/mapi/glapi/gen/gl_table.py                |   1 +
 src/mesa/Android.libmesa_glsl_utils.mk        |   2 -
 src/mesa/Makefile.sources                     |   3 +-
 src/mesa/drivers/common/driverfuncs.c         |   1 -
 src/mesa/drivers/common/meta.c                |   7 +-
 src/mesa/drivers/common/meta_blit.c           |   7 +-
 src/mesa/drivers/dri/i915/i830_context.c      |   1 -
 src/mesa/drivers/dri/i915/i915_context.c      |   1 -
 src/mesa/drivers/dri/i915/i915_debug_fp.c     |   4 +-
 src/mesa/drivers/dri/i915/i915_texstate.c     |   2 +-
 src/mesa/drivers/dri/i915/i915_vtbl.c         |   1 -
 .../drivers/dri/i915/intel_buffer_objects.c   |  20 +-
 src/mesa/drivers/dri/i915/intel_context.c     |   1 -
 src/mesa/drivers/dri/i915/intel_fbo.c         |   2 +-
 src/mesa/drivers/dri/i915/intel_render.c      |   1 -
 src/mesa/drivers/dri/i915/intel_screen.c      |   1 +
 src/mesa/drivers/dri/i915/intel_syncobj.c     |   2 -
 src/mesa/drivers/dri/i915/intel_tex.c         |   1 +
 src/mesa/drivers/dri/i965/brw_clip.c          |   2 +-
 .../drivers/dri/i965/brw_conditional_render.c |   1 -
 src/mesa/drivers/dri/i965/brw_context.c       |   1 -
 .../drivers/dri/i965/brw_object_purgeable.c   |   1 -
 .../drivers/dri/i965/brw_primitive_restart.c  |   1 -
 src/mesa/drivers/dri/i965/brw_program.c       |   1 -
 src/mesa/drivers/dri/i965/brw_program_cache.c |   2 +-
 src/mesa/drivers/dri/i965/brw_queryobj.c      |   2 -
 src/mesa/drivers/dri/i965/brw_sync.c          |   2 -
 src/mesa/drivers/dri/i965/brw_vs.c            |   2 +-
 src/mesa/drivers/dri/i965/gen6_queryobj.c     |   2 -
 src/mesa/drivers/dri/i965/gen6_sol.c          |   1 +
 src/mesa/drivers/dri/i965/hsw_queryobj.c      |   2 -
 .../drivers/dri/i965/intel_buffer_objects.c   |   2 +-
 src/mesa/drivers/dri/i965/intel_fbo.c         |   2 +-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c |   9 +-
 src/mesa/drivers/dri/i965/intel_screen.c      |   1 +
 src/mesa/drivers/dri/i965/intel_tex.c         |   1 +
 src/mesa/drivers/dri/i965/intel_upload.c      |   1 -
 .../drivers/dri/nouveau/nouveau_bufferobj.c   |   1 +
 src/mesa/drivers/dri/nouveau/nouveau_driver.h |   1 -
 src/mesa/drivers/dri/nouveau/nouveau_fbo.c    |   1 +
 src/mesa/drivers/dri/nouveau/nouveau_screen.c |   1 +
 .../drivers/dri/nouveau/nouveau_texture.c     |   1 +
 src/mesa/drivers/dri/nouveau/nv04_context.c   |   1 +
 src/mesa/drivers/dri/nouveau/nv04_surface.c   |   4 +-
 src/mesa/drivers/dri/nouveau/nv10_context.c   |   1 +
 src/mesa/drivers/dri/nouveau/nv20_context.c   |   1 +
 src/mesa/drivers/dri/r200/r200_blit.c         |  76 ++--
 src/mesa/drivers/dri/r200/r200_cmdbuf.c       |   1 -
 src/mesa/drivers/dri/r200/r200_context.c      |   1 -
 src/mesa/drivers/dri/r200/r200_ioctl.c        |   1 -
 src/mesa/drivers/dri/r200/r200_maos_arrays.c  |   1 -
 src/mesa/drivers/dri/r200/r200_sanity.c       |   1 -
 src/mesa/drivers/dri/r200/r200_state.c        |   1 -
 src/mesa/drivers/dri/r200/r200_state_init.c   |   1 -
 src/mesa/drivers/dri/r200/r200_swtcl.c        |   1 -
 src/mesa/drivers/dri/r200/r200_tcl.c          |   1 -
 src/mesa/drivers/dri/r200/r200_tex.c          |   2 +-
 src/mesa/drivers/dri/r200/r200_texstate.c     |   8 +-
 src/mesa/drivers/dri/radeon/radeon_blit.c     |  49 ++-
 .../dri/radeon/radeon_buffer_objects.c        |   2 +-
 src/mesa/drivers/dri/radeon/radeon_common.c   |   1 -
 src/mesa/drivers/dri/radeon/radeon_context.c  |   1 -
 src/mesa/drivers/dri/radeon/radeon_dma.c      |   1 +
 src/mesa/drivers/dri/radeon/radeon_fbo.c      |   2 +-
 src/mesa/drivers/dri/radeon/radeon_fog.c      |   1 -
 src/mesa/drivers/dri/radeon/radeon_ioctl.c    |   1 -
 .../drivers/dri/radeon/radeon_maos_arrays.c   |   1 -
 .../drivers/dri/radeon/radeon_maos_verts.c    |   1 -
 .../drivers/dri/radeon/radeon_mipmap_tree.c   |   5 +-
 src/mesa/drivers/dri/radeon/radeon_queryobj.c |   2 -
 src/mesa/drivers/dri/radeon/radeon_queryobj.h |   1 -
 src/mesa/drivers/dri/radeon/radeon_screen.c   |  23 +-
 src/mesa/drivers/dri/radeon/radeon_state.c    |   1 -
 .../drivers/dri/radeon/radeon_state_init.c    |   1 -
 src/mesa/drivers/dri/radeon/radeon_swtcl.c    |   1 -
 src/mesa/drivers/dri/radeon/radeon_tcl.c      |   1 -
 src/mesa/drivers/dri/radeon/radeon_tex.c      |   2 +-
 src/mesa/drivers/dri/radeon/radeon_texstate.c |   1 -
 src/mesa/drivers/dri/radeon/radeon_texture.c  |  34 +-
 src/mesa/drivers/dri/swrast/swrast.c          |   2 +-
 src/mesa/drivers/osmesa/osmesa.c              |  17 +-
 src/mesa/drivers/x11/fakeglx.c                |   1 -
 src/mesa/drivers/x11/xfonts.c                 |   1 -
 src/mesa/drivers/x11/xm_api.c                 |   4 +-
 src/mesa/drivers/x11/xm_buffer.c              |   2 +-
 src/mesa/drivers/x11/xm_dd.c                  |   2 +-
 src/mesa/drivers/x11/xm_tri.c                 |   1 -
 src/mesa/main/accum.c                         |   1 -
 src/mesa/main/api_arrayelt.c                  |   1 -
 src/mesa/main/arbprogram.c                    |   1 -
 src/mesa/main/arrayobj.c                      |   2 +-
 src/mesa/main/atifragshader.c                 |   2 +-
 src/mesa/main/attrib.c                        |   2 +-
 src/mesa/main/bufferobj.c                     |   8 +-
 src/mesa/main/context.c                       |   2 +-
 src/mesa/main/context.h                       |   1 -
 src/mesa/main/cpuinfo.c                       |   5 +-
 src/mesa/main/debug.c                         |   8 +-
 src/mesa/main/debug_output.c                  |   2 +-
 src/mesa/main/depth.c                         |   1 -
 src/mesa/main/dlist.c                         |   6 +-
 src/mesa/main/draw.c                          |   4 +-
 src/mesa/main/draw_validate.c                 |   1 -
 src/mesa/main/drawpix.c                       |  23 +-
 src/mesa/main/drawtex.c                       |   1 -
 src/mesa/main/errors.c                        |  20 +-
 src/mesa/main/es1_conversion.c                |   1 -
 src/mesa/main/eval.c                          |  15 +-
 src/mesa/main/execmem.c                       |   1 -
 src/mesa/main/execmem.h                       |   1 +
 src/mesa/main/extensions.c                    |   1 -
 src/mesa/main/externalobjects.c               |   1 +
 src/mesa/main/ff_fragment_shader.cpp          |   1 -
 src/mesa/main/format_utils.c                  |  24 +-
 src/mesa/main/format_utils.h                  |   1 -
 src/mesa/main/formats.c                       |  69 ++--
 src/mesa/main/framebuffer.c                   |   2 +-
 src/mesa/main/get.c                           |  44 +--
 src/mesa/main/hash.c                          |   1 +
 src/mesa/main/hash.h                          |   2 +-
 src/mesa/main/hint.c                          |   1 -
 src/mesa/main/image.c                         |   1 -
 src/mesa/main/imports.c                       | 235 ------------
 src/mesa/main/imports.h                       | 336 ------------------
 src/mesa/main/light.c                         |   9 +-
 src/mesa/main/macros.h                        |  16 +-
 src/mesa/main/matrix.c                        |   1 -
 src/mesa/main/{execmem.h => mesa_private.h}   |  35 +-
 src/mesa/main/mipmap.c                        |   1 -
 src/mesa/main/objectpurge.c                   |   1 -
 src/mesa/main/pack.c                          |   2 -
 src/mesa/main/pbo.c                           |   2 +-
 src/mesa/main/pipelineobj.c                   |   1 +
 src/mesa/main/pixel.c                         |   9 +-
 src/mesa/main/pixelstore.c                    |   5 +-
 src/mesa/main/pixeltransfer.c                 |   1 -
 src/mesa/main/polygon.c                       |   1 -
 src/mesa/main/queryobj.c                      |   2 +-
 src/mesa/main/readpix.c                       |   1 -
 src/mesa/main/remap.c                         |   2 +-
 src/mesa/main/renderbuffer.c                  |   2 +-
 src/mesa/main/samplerobj.c                    |   9 +-
 src/mesa/main/shared.c                        |   2 +-
 src/mesa/main/stencil.c                       |   1 -
 src/mesa/main/streaming-load-memcpy.h         |   2 +
 src/mesa/main/syncobj.c                       |   2 +-
 src/mesa/main/texcompress.c                   |   1 -
 src/mesa/main/texcompress_bptc.c              |   7 +-
 src/mesa/main/texcompress_cpal.c              |   1 -
 src/mesa/main/texcompress_fxt1.c              |   8 +-
 src/mesa/main/texcompress_rgtc.c              |  15 +-
 src/mesa/main/texcompress_s3tc.c              |  22 +-
 src/mesa/main/teximage.c                      |  54 +--
 src/mesa/main/texobj.c                        |   2 +-
 src/mesa/main/texparam.c                      |   8 +-
 src/mesa/main/texstorage.c                    |   1 -
 src/mesa/main/texstore.c                      |   5 +-
 src/mesa/main/texturebindless.c               |   2 +-
 src/mesa/main/textureview.c                   |   1 -
 src/mesa/main/transformfeedback.c             |   2 +
 src/mesa/main/uniform_query.cpp               |   7 +-
 src/mesa/main/varray.c                        |   1 -
 src/mesa/main/vdpau.c                         |   1 +
 src/mesa/main/version.c                       |  18 +-
 src/mesa/main/vtxfmt.c                        |   1 -
 src/mesa/math/m_debug_clip.c                  |   1 -
 src/mesa/math/m_debug_norm.c                  |   5 +-
 src/mesa/math/m_debug_xform.c                 |   5 +-
 src/mesa/math/m_matrix.c                      |  11 +-
 src/mesa/math/m_vector.c                      |   7 +-
 src/mesa/meson.build                          |   3 +-
 src/mesa/program/arbprogparse.c               |   1 -
 src/mesa/program/prog_cache.c                 |   2 +-
 src/mesa/program/prog_execute.c               |  30 +-
 src/mesa/program/prog_instruction.c           |   5 +-
 src/mesa/program/prog_noise.c                 |   1 -
 src/mesa/program/prog_parameter.c             |  17 +-
 src/mesa/program/prog_parameter.h             |   1 +
 src/mesa/program/prog_parameter_layout.c      |   1 -
 src/mesa/program/prog_print.c                 |   9 +-
 src/mesa/program/prog_statevars.c             |   1 -
 src/mesa/program/prog_to_nir.c                |   1 -
 src/mesa/program/program_lexer.l              |   1 -
 src/mesa/program/program_parse.y              |  19 +-
 src/mesa/program/symbol_table.c               |   3 +-
 src/mesa/state_tracker/st_atom_atomicbuf.c    |   1 -
 src/mesa/state_tracker/st_atom_constbuf.c     |   1 -
 src/mesa/state_tracker/st_atom_image.c        |   1 -
 src/mesa/state_tracker/st_atom_shader.c       |   1 -
 src/mesa/state_tracker/st_atom_storagebuf.c   |   1 -
 src/mesa/state_tracker/st_cb_bitmap.c         |   5 +-
 src/mesa/state_tracker/st_cb_blit.c           |   1 -
 src/mesa/state_tracker/st_cb_bufferobjects.c  |   1 -
 src/mesa/state_tracker/st_cb_condrender.c     |   1 -
 src/mesa/state_tracker/st_cb_drawpixels.c     |   1 -
 src/mesa/state_tracker/st_cb_drawtex.c        |   1 -
 src/mesa/state_tracker/st_cb_fbo.c            |   1 -
 src/mesa/state_tracker/st_cb_feedback.c       |   1 -
 src/mesa/state_tracker/st_cb_memoryobjects.c  |   1 -
 src/mesa/state_tracker/st_cb_msaa.c           |   1 -
 src/mesa/state_tracker/st_cb_queryobj.c       |   1 -
 src/mesa/state_tracker/st_cb_rasterpos.c      |   1 -
 src/mesa/state_tracker/st_cb_readpixels.c     |   1 -
 .../state_tracker/st_cb_semaphoreobjects.c    |   1 -
 src/mesa/state_tracker/st_cb_syncobj.c        |   1 +
 src/mesa/state_tracker/st_cb_texture.c        |   3 +-
 src/mesa/state_tracker/st_cb_texturebarrier.c |   1 -
 src/mesa/state_tracker/st_cb_xformfb.c        |   1 +
 src/mesa/state_tracker/st_context.c           |   1 -
 src/mesa/state_tracker/st_draw.c              |   1 -
 src/mesa/state_tracker/st_draw_feedback.c     |   1 -
 src/mesa/state_tracker/st_extensions.c        |   1 -
 src/mesa/state_tracker/st_format.c            |   1 -
 src/mesa/state_tracker/st_gen_mipmap.c        |   1 -
 src/mesa/state_tracker/st_manager.c           |   1 +
 src/mesa/state_tracker/st_program.c           |   3 +-
 src/mesa/swrast/s_aaline.c                    |   3 +-
 src/mesa/swrast/s_aalinetemp.h                |   2 +-
 src/mesa/swrast/s_aatriangle.c                |   3 +-
 src/mesa/swrast/s_aatritemp.h                 |   2 +-
 src/mesa/swrast/s_blit.c                      |  16 +-
 src/mesa/swrast/s_clear.c                     |   1 -
 src/mesa/swrast/s_context.c                   |   1 -
 src/mesa/swrast/s_context.h                   |   3 +-
 src/mesa/swrast/s_copypix.c                   |   1 -
 src/mesa/swrast/s_depth.c                     |   1 -
 src/mesa/swrast/s_drawpix.c                   |   1 -
 src/mesa/swrast/s_linetemp.h                  |   2 +-
 src/mesa/swrast/s_logic.c                     |   1 -
 src/mesa/swrast/s_points.c                    |   2 +-
 src/mesa/swrast/s_renderbuffer.c              |  11 +-
 src/mesa/swrast/s_span.c                      |   5 +-
 src/mesa/swrast/s_stencil.c                   |   1 -
 src/mesa/swrast/s_texcombine.c                |   1 -
 src/mesa/swrast/s_texfilter.c                 |  67 ++--
 src/mesa/swrast/s_texture.c                   |  12 +-
 src/mesa/swrast/s_triangle.c                  |   7 +-
 src/mesa/swrast/s_tritemp.h                   |   3 +-
 src/mesa/swrast/s_zoom.c                      |   1 -
 src/mesa/swrast_setup/ss_context.c            |   1 -
 src/mesa/tnl/t_context.c                      |   2 +-
 src/mesa/tnl/t_context.h                      |   1 -
 src/mesa/tnl/t_draw.c                         |   1 -
 src/mesa/tnl/t_pipeline.c                     |   1 -
 src/mesa/tnl/t_rebase.c                       |   2 +-
 src/mesa/tnl/t_split_copy.c                   |   3 +-
 src/mesa/tnl/t_vb_cliptmp.h                   |   8 +-
 src/mesa/tnl/t_vb_fog.c                       |   1 -
 src/mesa/tnl/t_vb_light.c                     |   3 +-
 src/mesa/tnl/t_vb_normals.c                   |   1 -
 src/mesa/tnl/t_vb_points.c                    |   1 -
 src/mesa/tnl/t_vb_program.c                   |   8 +-
 src/mesa/tnl/t_vb_render.c                    |   1 -
 src/mesa/tnl/t_vb_texgen.c                    |   1 -
 src/mesa/tnl/t_vb_texmat.c                    |   1 -
 src/mesa/tnl/t_vb_vertex.c                    |   6 +-
 src/mesa/tnl/t_vertex.c                       |   5 +-
 src/mesa/vbo/vbo_context.c                    |   1 +
 src/mesa/vbo/vbo_exec.h                       |   2 +-
 src/mesa/vbo/vbo_exec_api.c                   |   7 +-
 src/mesa/vbo/vbo_minmax_index.c               |   1 +
 src/mesa/vbo/vbo_primitive_restart.c          |   1 -
 src/mesa/vbo/vbo_private.h                    |   1 +
 src/mesa/vbo/vbo_save_api.c                   |   1 +
 src/mesa/vbo/vbo_save_draw.c                  |   2 +-
 src/mesa/vbo/vbo_save_loopback.c              |   2 +-
 src/mesa/x86/common_x86.c                     |   1 -
 src/mesa/x86/rtasm/x86sse.c                   |   1 -
 src/meson.build                               |   5 +-
 src/util/Makefile.sources                     |   5 +
 src/util/debug.c                              |   9 +-
 src/util/hash_table.c                         |   1 +
 .../auxiliary/os => util}/os_memory.h         |   3 +
 .../auxiliary/os => util}/os_memory_aligned.h |  35 ++
 .../auxiliary/os => util}/os_memory_debug.h   |   0
 .../auxiliary/os => util}/os_memory_stdc.h    |  18 +-
 src/util/register_allocate.c                  |   1 -
 src/util/rounding.h                           |  10 +
 src/util/u_endian.h                           |  18 +-
 src/util/u_math.h                             |  18 +
 src/{gallium/auxiliary => }/util/u_memory.h   |   4 +-
 src/util/u_string.h                           |   4 +
 311 files changed, 743 insertions(+), 1305 deletions(-)
 delete mode 100644 src/mesa/main/imports.c
 delete mode 100644 src/mesa/main/imports.h
 copy src/mesa/main/{execmem.h => mesa_private.h} (60%)
 rename src/{gallium/auxiliary/os => util}/os_memory.h (95%)
 rename src/{gallium/auxiliary/os => util}/os_memory_aligned.h (78%)
 rename src/{gallium/auxiliary/os => util}/os_memory_debug.h (100%)
 rename src/{gallium/auxiliary/os => util}/os_memory_stdc.h (84%)
 rename src/{gallium/auxiliary => }/util/u_memory.h (94%)

-- 
2.19.1



More information about the mesa-dev mailing list