Commit graph

2939 commits

Author SHA1 Message Date
Janne Grunau
f912db3f8d util/driconf/asahi: Override GL renderer for web browsers
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Several web sites block clients with "Apple" in the WebGL renderer
string if the reported OS is not one of Apple's.
This check seems to implemented via a 3rd party product which is slowly
rolled out over more web sites. Instead of playing whack-a-mole with
web sites in multiple browsers override the OpenGL renderer in mesa for
known browsers.

Backport-to: 25.3
Signed-off-by: Janne Grunau <j@jannau.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38845>
2025-12-08 16:23:54 +00:00
Job Noorman
0574bfd5f4 tu: add UBO lowering workaround for Yooka-Laylee
A vertex shader performs OOB UBO reads causing vertex corruption.
Disable UBO to const lowering to force bounds checking which fixes the
corruption.

Signed-off-by: Job Noorman <jnoorman@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38781>
2025-12-05 00:19:46 +00:00
Timothy Arceri
b75cd07265 util/driconf: add Cursemark workaround
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Fixes gpu hang on radeonsi and corrupt rendering on iris.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14392
Cc: mesa-stable

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38777>
2025-12-03 23:58:15 +00:00
Gurchetan Singh
1997987b58 util: fix error about missing include
When building with linux_glibc_x86_64 in AOSP, this is
observed.

src/util/u_debug_stack.h:66:4: error: unknown type name 'uint64_t'
   66 |    uint64_t start_ip;
      |    ^

Adding <stdint.h> fixes it.

Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38644>
2025-12-02 20:03:02 +00:00
Dorinda Bassey
4ace478545 util/rust: Add handle type detection to descriptor API
This enhances the DescriptorType enum to include the
memory handle type (DMABUF vs SHM) alongside the size,
allowing consumers to differentiate between DMA-BUF and
shared memory file descriptors without redundant code.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38677>
2025-12-02 16:24:56 +00:00
Tapani Pälli
b2b5e83894 anv: add vk_wsi_disable_unordered_submits and enable for GTK
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
See radv change 0d9d45db4e for further explanation.

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14354
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38765>
2025-12-02 10:22:02 +02:00
Gurchetan Singh
14cfe14626 util: fix arithmetic on a pointer to void warning
Otherwise, the following error is observed:

src/util/cache_ops_x86_clflushopt.c:40:22:
   error: arithmetic on a pointer to void is a GNU extension [-Werror,-Wgnu-pointer-arith]
   40 |    void *end = start + size;
      |                ~~~~~ ^
src/util/cache_ops_x86_clflushopt.c:44:9:
  error: arithmetic on a pointer to void is a GNU extension [-Werror,-Wgnu-pointer-arith]
   44 |       p += cpu_caps->cacheline;
      |       ~ ^

This works with GNU extension enabled, but does lead to warnings
with Clang.

v2: Add to trial_c + trial_cpp checks (Erik)
v3: use c_msvc_compat_args to avoid fixing other instances of this issue (Erik)

Fixes: 555881e574 ("util/cache_ops: Add some cache flush helpers")
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38752>
2025-12-02 00:12:44 +00:00
Timothy Arceri
d10036362f util/driconf: Add linux version of Penumbra fixes
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38563>
2025-11-28 08:49:55 +00:00
Emma Anholt
959520e227 tu: Add a loop count to VK_pipeline_executable_properties.
This will improve the report-fossil summaries I'm looking at for loop
unrolling, by showing me that loop count changed.  With a followup change
for my report-fossil to bring over behavior from GL report.py where we
ignore other counters when loop count changes (yeah, you expected to
increase instruction counts, it's fine), we go from:

    Totals:
    Instrs: 73000 -> 73242 (+0.33%)
    CodeSize: 142250 -> 142506 (+0.18%)
    NOPs: 13896 -> 13964 (+0.49%)
    MOVs: 2440 -> 2438 (-0.08%)
    Full: 1489 -> 1490 (+0.07%)
    (ss): 1742 -> 1754 (+0.69%)
    (ss)-stall: 7226 -> 7354 (+1.77%)
    Number of hardware loops: 79 -> 78 (-1.27%)
    [...]

    Totals from 1 (0.60% of 168) affected shaders:
    Instrs: 184 -> 426 (+131.52%)
    CodeSize: 288 -> 544 (+88.89%)
    NOPs: 80 -> 148 (+85.00%)
    MOVs: 9 -> 7 (-22.22%)
    Full: 11 -> 12 (+9.09%)
    (ss): 14 -> 26 (+85.71%)
    (ss)-stall: 58 -> 186 (+220.69%)
    Number of hardware loops: 2 -> 1 (-50.00%)
    [...]

     PERCENTAGE DELTAS                              Shaders   Instrs   CodeSize    NOPs      MOVs      Full [...]
     app_name               168       +0.33%    +0.18%    +0.49%    -0.08%    +0.07%    +0.69%    +1.77%    [...]
     -------------------------------------------------------------------------------------------------------[...]
     All affected           1        +131.52%  +88.89%   +85.00%   -22.22%    +9.09%   +85.71%   +220.69%   [...]
     -------------------------------------------------------------------------------------------------------[...]
     Total                  168       +0.33%    +0.18%    +0.49%    -0.08%    +0.07%    +0.69%    +1.77%    [...]

to:

    Totals:
    Number of hardware loops: 79 -> 78 (-1.27%)

    Totals from 1 (0.60% of 168) affected shaders:
    Number of hardware loops: 2 -> 1 (-50.00%)

     PERCENTAGE DELTAS      Shaders Number of hardware loops
     app_name               168              -1.27%
     ---------------------------------------------------------
     All affected           1                -50.00%
     ---------------------------------------------------------
     Total                  168              -1.27%

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38667>
2025-11-28 05:42:50 +00:00
Yonggang Luo
9d3d15f871 util,wgl: Replace usage of putenv with os_unset_option,os_set_option
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:34 +00:00
Yonggang Luo
0a32d5e6fd treewide: Use regexp to replace usage of setenv with os_set_option.
setenv\((.*), 1\);
=>
os_set_option($1, true);

setenv\((.*), 0\);
=>
os_set_option($1, false);

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:34 +00:00
Yonggang Luo
1825715623 treewide: Use regexp to replace usage of unsetenv with os_unset_option.
unsetenv\((.*)\);
=>
os_unset_option($1);

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:33 +00:00
Yonggang Luo
d277dfdd76 treewide: Replace the usage of setenv manually and #include "util/os_misc.h" when needed
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:33 +00:00
Yonggang Luo
5ab8148f23 util: Update os_get_option* comments to match os_set_option
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:32 +00:00
Yonggang Luo
2771eb39fd util: Add function os_unset_option/os_set_option for latter use
It's will be used to replace SetEnvironmentVariableA,putenv on windows
and putenv,setenv on non-windows

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:32 +00:00
Yonggang Luo
123a66fc43 util,asahi,vulkan,panfrost: Replace the remaining usage of getenv with os_get_option
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38640>
2025-11-27 18:22:32 +00:00
Samuel Pitoiset
f14e0d9f09 radv: add radv_hide_rebar_on_dgpu and enable for Red Dead Redemption 2
RDR2 VRAM memory management when resizable BAR is enabled seems
incorrect because it keeps allocating VRAM without freeing anything.

This introduces a drirc option to emulate a fake carveout of 256MiB to
workaround this game bug. This also adjust memory budgets by
distributing it between visible and invisible because AMDGPU reports
the same value for both when REBAR is enabled.

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12091
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38627>
2025-11-26 10:12:45 +00:00
Tapani Pälli
21f646d196 drirc: set intel_disable_threaded_context for Amnesia The Bunker
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14084
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38567>
2025-11-25 05:40:10 +00:00
Tapani Pälli
4daabf76b4 drirc/iris: add drirc to disable threaded context
Cc: mesa-stable
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38567>
2025-11-25 05:40:10 +00:00
Samuel Pitoiset
6ab9e69d2f radv: ignore radv_disable_dcc{_mips} drirc options on GFX12
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
They shouldn't have any effects because on GFX12 DCC is transparent
to the userspace driver, and they should improve performance for the
games listed below:

- DOOM (2016)
- Wolfenstein II
- Red Dead Redemption 2
- WWE 2k23

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38481>
2025-11-24 17:40:33 +00:00
Gurchetan Singh
01bb498e16 util: be consistent about transitive dependencies
A transitive dependency is a dependency of a dependency.
So if, for example, mesa3d_util does explicitly use
zerocopy-derive, it should not need to a depend on it.

The package that pulls in transitive should already
include it has a dependency.  This provides clearer
methodologies in maintaining Rust code, similiar to
how Cargo.toml handles it.

Reviewed-by: David Gilhooley <djgilhooley.gmail.com>
2025-11-24 06:56:07 -08:00
Gurchetan Singh
5eece7596e util: rust: more rust support for windows/MacOS
Need the same dependencies as Linux.

The RustixError type compiles on Windows.

Reviewed-by: David Gilhooley <djgilhooley.gmail.com>
2025-11-24 06:56:07 -08:00
Benjamin Otte
f493f5c88d radv: Limit GTK workaround to affected versions
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
GTK 4.20.3 includes a fix for the problem, so limit the workaround to
GTK <= 4.20.2.
The version number encoding is due to VK_MAKE_VERSION().

Fixes: 0d9d45db4e
Related: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/9128
Related: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/9164
Signed-off-by: Benjamin Otte <otte@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38550>
2025-11-21 16:11:50 +00:00
Connor Abbott
3b3954e2b8 util/glsl2spirv: Use better glslang flag for -Olib
--create-unlinked also creates entrypoints for the functions, and
obviates the need to create a dummy entrypoint. This is one step closer
to removing glsl2spirv and aligns us with other users of glslang.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38088>
2025-11-20 02:14:50 +00:00
Allen Ballway
bfee8d3a14 android: support longer property names
Property names no longer have a maximum length in Android 26+,
support longer names to fix truncated property names.

Signed-off-by: Allen Ballway <ballway@google.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13043
Test: vendor.mesa.custom.border.colors.without.format is untruncated
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38453>
2025-11-18 19:50:00 +00:00
Aitor Camacho
38fe7b7352 util: Add build_id for macOS
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38420>
2025-11-17 22:50:07 +00:00
Aitor Camacho
a77e09eaeb util: Introduce HAVE_BUILD_ID for build id utils
Build utilities to retrieve the build id are now exposed
through the new HAVE_BUILD_ID instead of HAVE_DL_ITERATE_PHDR
since this will allow adding support for platforms that do
not support HAVE_DL_ITERATE_PHDR

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38420>
2025-11-17 22:50:07 +00:00
Connor Abbott
b92f7c17da tu: Expose preserving fp32 denorms via softfloat32
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Microsoft required the ability to preserve fp32 denorms via a shader
flag in shader model 6.2, but Adreno does not support this. Instead
Qualcomm's DX12 driver uses soft floats. Implement something similar to
expose the equivalent Vulkan feature for vkd3d-proton. In practice no
apps should actually use this but it lets us go from SM6.0 to SM6.6 with
vkd3d-proton.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37608>
2025-11-14 19:31:17 +00:00
Yonggang Luo
54715e8989 util: Getting util_align_npot to be same with ALIGN_NPOT so it can be merged latter
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38431>
2025-11-13 21:02:44 -08:00
Yonggang Luo
8c427aae92 util: Remove unused ALIGN function to prevent future use
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
The #undef ALIGN is also not needed anymore, remove it.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38365>
2025-11-12 21:58:41 +00:00
Yonggang Luo
24a7d53329 util: Add PRAGMA_DIAGNOSTIC_IGNORED_CLANG PRAGMA_DIAGNOSTIC_IGNORED_GCC for latter use
gcc and clang do not have equal set of warnings, so when warning are specific to CLANG or GCC, using PRAGMA_DIAGNOSTIC_IGNORED_CLANG or PRAGMA_DIAGNOSTIC_GCC_IGNORED instead

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38313>
2025-11-12 21:22:10 +00:00
Alyssa Rosenzweig
583b25e806 util: fix container_of on MSVC
otherwise &container_of(..)->foo won't work, need extra parens. gcc version is
fine.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38313>
2025-11-12 21:22:10 +00:00
Andy Hsu
d226c0d97d u_trace: remove redundant char* to string conversion (v2)
Add the string length parameter to the set_name(),
set_value() function to remove the conversion from
char* to std::string which takes extra work like
calling strlen() to compute the string length.

From the callback sampling in the perfetto tracing,
the ratio of trace_payload_as_extra_intel_end_draw_indexed
to intel_ds_end_draw_indexed drops from 63.80% to 59.65%
with this change.

v2: Add the data of the callback sampling to the description.

Signed-off-by: Andy Hsu <hwandy@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38073>
2025-11-12 06:17:16 +00:00
Sviatoslav Peleshko
5af8abbf8b driconf: Add vertex_program_default_out option for Penumbra: Overture
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Penumbra's vertex program Diffuse_EnvMap_Reflect_vp.cg produces 3-component
texture coordinates and primitive colors while using the FF fragment
program. Add this WA to fix the misrenderings.

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14170
Signed-off-by: Sviatoslav Peleshko <sviatoslav.peleshko@globallogic.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38295>
2025-11-11 22:16:46 +00:00
Sviatoslav Peleshko
f03432c81a mesa,driconf: Add WA to initialize vertex program outputs to vec4(0,0,0,1)
Per ARB_vertex_program spec result registers are 4-component and initially
undefined, and the FF fragment program expects its intputs to be
4-component too. So, if the client's vertex program does not write the
whole vector it will cause misrenderings unless the same client also
supplies fragment program that expects less than 4 componens.

This commit adds a workaround that initializes results to vec4(0, 0, 0, 1)
which seems to be an expected behavior for such clients.

Cc: mesa-stable
Signed-off-by: Sviatoslav Peleshko <sviatoslav.peleshko@globallogic.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38295>
2025-11-11 22:16:46 +00:00
Samuel Pitoiset
0d9d45db4e radv: add vk_wsi_disable_unordered_submits and enable for GTK
GTK is missing a semaphore between QueueSubmit() and QueuePresent()
causing the WSI submit to be "unordered" and to immediately signal the
semaphores (because it's missing a wait semaphore in QueuePresent()).

The workaround is to disable unordered WSI submits until GTK fixes it
properly.

Cc: "25.3"
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14087
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38351>
2025-11-11 12:13:41 +00:00
Christian Gmeiner
c346f2b673 util/log: Add MESA_LOG_PREFIX environment variable to control log prefixes
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Add a new MESA_LOG_PREFIX environment variable that allows fine-grained
control over log prefixes in file logger output on Linux. The variable
accepts a comma-separated list of options:
- "tag": include the tag prefix (e.g., "MESA:")
- "level": include the level prefix (e.g., "info:")

By default, both tag and level are included. Users can customize the
prefix by setting MESA_LOG_PREFIX to any combination (e.g., "tag",
"level", "tag,level", or empty string for no prefix), making the output
more flexible and readable for different use cases.

Other loggers (syslog, Android logcat, Windows debugger) are unaffected
and continue to include tag and level information as appropriate for
their format.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38217>
2025-11-07 13:38:52 +00:00
Lucas Fryzek
06cb90c07c util: Move ASTC unpack routines to common util
Move ASTC decompression code from mesa/main to src/util to make it
available for use by Vulkan drivers. This allows the Intel ANV driver
to use CPU-based ASTC decompression for host image copy operations
on hardware that doesn't natively support ASTC formats.

The _mesa_unpack_astc_2d_ldr() function signature is updated to use
pipe_format instead of mesa_format for better integration with the
util format system.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37691>
2025-11-07 12:14:31 +00:00
Natalie Vock
a8b75dd0f4 util: Add sparse bitset data structure
Useful for potentially huge bitsets that are expected to be mostly
filled with zeroes, reducing memory consumption by assuming bits being
zero by default (without wasting memory to store zeroes).

Co-authored-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37908>
2025-11-06 21:34:33 +00:00
Natalie Vock
1920a99115 util/bitset: Wrap __size in braces
Otherwise funny things can happen with the < operator because of
precedence rules.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37908>
2025-11-06 21:34:33 +00:00
Antonio Ospite
222b85328e mesa: replace most occurrences of getenv() with os_get_option()
The standard way to query options in mesa is `os_get_option()` which
abstracts platform-specific mechanisms to get config variables.

However in quite a few places `getenv()` is still used and this may
preclude controlling some options on some systems.

For instance it is not generally possible to use `MESA_DEBUG` on
Android.

So replace most `getenv()` occurrences with  `os_get_option()` to
support configuration options more consistently across different
platforms.

Do the same with `secure_getenv()` replacing it with
`os_get_option_secure()`.

The bulk of the proposed changes are mechanically performed by the
following script:

-----------------------------------------------------------------------
  #!/bin/sh

  set -e

  replace() {

    # Don't replace in some files, for example where `os_get_option` is defined,
    # or in external files
    EXCLUDE_FILES_PATTERN='(src/util/os_misc.c|src/util/u_debug.h|src/gtest/include/gtest/internal/gtest-port.h)'

    # Don't replace some "system" variables
    EXCLUDE_VARS_PATTERN='("XDG|"DISPLAY|"HOME|"TMPDIR|"POSIXLY_CORRECT)'

    git grep "[=!( ]$1(" -- src/ | cut -d ':' -f 1 | sort | uniq | \
      grep -v -E "$EXCLUDE_FILES_PATTERN" | \
      while read -r file;
      do
        # Don't replace usages of XDG_* variables or HOME
        sed -E -e "/$EXCLUDE_VARS_PATTERN/!s/([=!\( ])$1\(/\1$2\(/g" -i "$file";
      done
  }

  # Add const to os_get_option results, to avoid warning about discarded qualifier:
  #   warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  # but also errors in some cases:
  #   error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
  add_const_results() {
    git grep -l -P '(?<!const )char.*os_get_option' | \
      while read -r file;
      do
        sed -e '/^\s*const/! s/\(char.*os_get_option\)/const \1/g' -i "$file"
      done
  }

  replace 'secure_getenv' 'os_get_option_secure'

  replace 'getenv' 'os_get_option'

  add_const_results
-----------------------------------------------------------------------

After this, the `#include "util/os_misc.h"` is also added in files where
`os_get_option()` was not used before.

And since the replacements from the script above generated some new
`-Wdiscarded-qualifiers` warnings, those have been addressed as well,
generally by declaring `os_get_option()` results as `const char *` and
adjusting some function declarations.

Finally some replacements caused new errors like:

-----------------------------------------------------------------------
../src/gallium/auxiliary/gallivm/lp_bld_misc.cpp:127:31: error: no matching function for call to 'strtok'
  127 |          for (n = 0, option = strtok(env_llc_options, " "); option; n++, option = strtok(NULL, " ")) {
      |                               ^~~~~~
/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/string.h:124:17: note: candidate function not viable: 1st argument ('const char *') would lose const qualifier
  124 | char* _Nullable strtok(char* _Nullable __s, const char* _Nonnull __delimiter);
      |                 ^      ~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------

Those have been addressed too, copying the const string returned by
`os_get_option()` so that it could be modified.

In particular, the error above has been fixed  by copying the `const
char *env_llc_options` variable in
`src/gallium/auxiliary/gallivm/lp_bld_misc.cpp` to a `char *` which can
be tokenized using `strtok()`.

Reviewed-by: Eric Engestrom <eric@igalia.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
2025-11-06 04:36:13 +00:00
Yonggang Luo
2eee9b79e8 util,vulkan,llvmpipe: Use os_get_option_dup instead getenv
Use os_get_option_dup in
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/util/tests/process_test.c
because the string is going to be modified.

Use os_get_option_dup in device_select_layer.c are because the string is being assigned to a
struct member (protection for the future), and also because the consecutive usages (protection for the present).

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
2025-11-06 04:36:13 +00:00
Yonggang Luo
eeb54aa92d util: Add function os_get_option_dup and os_get_option_secure_dup for latter use
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
2025-11-06 04:36:12 +00:00
Yonggang Luo
de36fed555 util: Add new function os_get_option_internal to improve os_get_option*
This is for take care of GetEnvironmentVariableA/getenv/secure_getenv/os_get_android_option
consistently across windows/posix/android

And also secure_getenv should not directly used in mesa, remove it from u_debug.h

os_get_option_secure is using getenv for windows before, that also pull the drawback of getenv, so convert it also
using GetEnvironmentVariableA on windows instead.

This is done the same as commit bed69133cd for os_get_option_secure

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
2025-11-06 04:36:12 +00:00
Yonggang Luo
95faaa4553 treewide: Use os_get_option_secure instead secure_getenv
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Acked-by: Antonio Ospite <antonio.ospite@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38128>
2025-11-06 04:36:11 +00:00
Alyssa Rosenzweig
9c2a2deee6 treewide: use BITSET_BYTES, BITSET_RZALLOC
Via Coccinelle patches:

    @@
    expression bits;
    typedef BITSET_WORD;
    @@

    -BITSET_WORDS(bits) * sizeof(BITSET_WORD)
    +BITSET_BYTES(bits)

    @@
    expression memctx, bits;
    typedef BITSET_WORD;
    @@

    -rzalloc_array(memctx, BITSET_WORD, BITSET_WORDS(bits))
    +BITSET_RZALLOC(memctx, bits)

     @@
     expression memctx, bits;
     @@

     -rzalloc_size(memctx, BITSET_BYTES(bits))
     +BITSET_RZALLOC(memctx, bits)

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
2025-11-05 18:44:23 +00:00
Alyssa Rosenzweig
ab4cff4f5c util: add BITSET_RZALLOC
to complement BITSET_CALLOC for when you want a memctx in there.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
2025-11-05 18:44:23 +00:00
Alyssa Rosenzweig
18eacdda3e util: add BITSET_BYTES helper
this comes up a lot.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
2025-11-05 18:44:23 +00:00
Christoph Pillmayer
bb7b0b6b1b pan: Add spill cost metric
Our SSA spilling logic should avoid inserting spill code inside loops.
Add a metric that reflects this goal.

Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38181>
2025-11-05 16:15:11 +00:00
Yiwei Zhang
8f7543e450 util: add os_map_memory_fd_placed for placed mapping support
This completes the opaque fd api coverage, and is needed by lavapipe for
sparse binding support with opaque fd external memory.

Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38074>
2025-11-05 08:26:40 +00:00