About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/util
AgeCommit message (Collapse)Author
2025-11-06util: Add sparse bitset data structureNatalie Vock
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-06util/bitset: Wrap __size in bracesNatalie Vock
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-06mesa: replace most occurrences of getenv() with os_get_option()Antonio Ospite
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-06util,vulkan,llvmpipe: Use os_get_option_dup instead getenvYonggang Luo
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-06util: Add function os_get_option_dup and os_get_option_secure_dup for latter useYonggang Luo
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-06util: Add new function os_get_option_internal to improve os_get_option*Yonggang Luo
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 bed69133cda5bb6e29beacd61a665ef653d4d1f9 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-06treewide: Use os_get_option_secure instead secure_getenvYonggang Luo
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-05treewide: use BITSET_BYTES, BITSET_RZALLOCAlyssa Rosenzweig
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-05util: add BITSET_RZALLOCAlyssa Rosenzweig
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-05util: add BITSET_BYTES helperAlyssa Rosenzweig
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-05pan: Add spill cost metricChristoph Pillmayer
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-05util: add os_map_memory_fd_placed for placed mapping supportYiwei Zhang
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-05util: add get_fd_header helper in os_memory_fdYiwei Zhang
Prepare for placed mapping. Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38074>
2025-11-04mesa: Add R16G16_R16B16_UNORM and related formatsEric R. Smith
Including the 10 bit variant X6R10X6G10_X6R10X6B10_UNORM. Only the RG_RB variants seem to have fourccs, so those are the only ones being added for now, although they would, obviously, be easy to add). These are used for Y210, Y212, and Y216 fourccs. In particular Y210 is interesting for panfrost, as it is the fourcc used to indicate a 10 bit single plane 4:2:2 encoded as AFBC (similar to how YUYV is the canonical AFBC for 10 bit 4:2:0). Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35771>
2025-11-04radv: do not report wave32 in gl_SubgroupSize for Doom Dark AgesGeorg Lehmann
The shaders in question use: (memory_load + (gl_SubgroupSize - 1)) & ~(gl_SubgroupSize - 1) My guess is that this is supposed to be the subgroup size of whatever produced the value, not the subgroup size in this shader. And because in the consumer the workgroup size is 32, we use wave32. Fixes: a2d3cbac2a1 ("radv: determine subgroup/wave size early") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14187 Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38214>
2025-11-04treewide: use UTIL_DYNARRAY_INITAlyssa Rosenzweig
Instead of util_dynarray_init(&dynarray, NULL), just use UTIL_DYNARRAY_INIT instead. This is more ergonomic. Via Coccinelle patch: @@ identifier dynarray; @@ -struct util_dynarray dynarray = {0}; -util_dynarray_init(&dynarray, NULL); +struct util_dynarray dynarray = UTIL_DYNARRAY_INIT; @@ identifier dynarray; @@ -struct util_dynarray dynarray; -util_dynarray_init(&dynarray, NULL); +struct util_dynarray dynarray = UTIL_DYNARRAY_INIT; @@ expression dynarray; @@ -util_dynarray_init(&(dynarray), NULL); +dynarray = UTIL_DYNARRAY_INIT; @@ expression dynarray; @@ -util_dynarray_init(dynarray, NULL); +(*dynarray) = UTIL_DYNARRAY_INIT; Followed by sed: bash -c "find . -type f -exec sed -i -e 's/util_dynarray_init(&\(.*\), NULL)/\1 = UTIL_DYNARRAY_INIT/g' \{} \;" bash -c "find . -type f -exec sed -i -e 's/util_dynarray_init( &\(.*\), NULL )/\1 = UTIL_DYNARRAY_INIT/g' \{} \;" bash -c "find . -type f -exec sed -i -e 's/util_dynarray_init(\(.*\), NULL)/*\1 = UTIL_DYNARRAY_INIT/g' \{} \;" Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38189>
2025-11-04util: add UTIL_DYNARRAY_INIT sentinelAlyssa Rosenzweig
We have the invariant that zero-initializing is legal but it's not obvious in the source code, so add a sentinel value for it to make code that uses it crystal clear. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38189>
2025-11-04u_trace: reserve chunk space before emitting copiesLionel Landwerlin
Some implementations can emit tracepoints when copying u_trace buffers. It's important to reserve the slots we want to copy into before emitting the copies so that both processes don't clash with one another. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Cc: mesa-stable Reviewed-by: Danylo Piliaiev <dpiliaiev@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38199>
2025-10-31radv: add a workaround for illegal depth/stencil descriptors with No Man's SkySamuel Pitoiset
Using descriptors with both depth and stencil aspects is illegal in Vulkan and this hangs the GPU. Use NULL descriptors to mitigate the issue. Note that AMDVLK also ignores them. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13325 Cc: mesa-stable Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38180>
2025-10-31util: add util_ptr_is_aligned helperAlyssa Rosenzweig
This composition comes up a bunch. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38169>
2025-10-31driconf: add a workaround for Investigation Stories : gunsoundPaul Gofman
CC: mesa-stable Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38152>
2025-10-30drirc: Add anv_assume_full_subgroups for Detroit: Become HumanSushma Venkatesh Reddy
Add workaround to assume full 32-thread subgroups. This fixes rendering corruption when running the Detriot: Become Human game using anv driver. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14120 Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38168>
2025-10-30util/meson: don't build libmesa_util_clflush unless neededEric Engestrom
Fixes: efbecd93baa35b4bbeb5 ("util: Build util/cache_ops_x86.c with -msse2") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38146>
2025-10-30util/meson: don't build libmesa_util_clflushopt unless neededEric Engestrom
Fixes: 555881e57499bc38f098 ("util/cache_ops: Add some cache flush helpers") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38146>
2025-10-28anv: use D3D-compatible texturing for ProtonAlyssa Rosenzweig
Intel & AMD Direct3D drivers modify their rounding behaviour for texturing to match Direct3D expectations. Such behaviour is not conformant in Vulkan, and Intel hardware lacks a reasonable way to get NVIDIA's behaviour (which uniquely works for Vulkan & Direct3D). The second best choice is to use Direct3D-compatible behaviour for Proton (via driconf) and our current Vulkan-conformant behaviour everywhere else. Given the APIs diverge and there is no Vulkan extension to control the behaviour explicitly, driconf'ing on the engineName is the reasonable solution. anv already has a anv_force_filter_addr_rounding driconf option to force Direct3D behaviour for certain Direct3D titles. Here we simply apply it to all D3D10+ titles, aligning us with the Windows driver. Note that D3D9 does not have this behaviour. We therefore use standard Vulkan behaviour for D3D9 to avoid breaking D3D9 titles, even though the engineName is the same as D3D10+. This is the same solution radv uses, they call it radv_disable_trunc_coord. We could unify the driconf entries later. See https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38098#note_3166306 for a more detailed analysis, as well as the linked references: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27337 https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25911 https://github.com/HansKristian-Work/vkd3d-proton/pull/1884 This fixes misrendering in piles of Direct3D games run on anv via Proton, including Assassin's Creed Valhalla. Cc: mesa-stable Closes: #13886 Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Co-authored-by: Calder Young <cgiacun@gmail.com> Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38114>
2025-10-27radv: add radv_wait_for_vm_map_updates drirc and enable for Forza Horizon 5Samuel Pitoiset
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13321 Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38031>
2025-10-25drirc/anv: force_vk_vendor=-1 for Wuthering WavesTaras Pisetskyi
Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12459 Signed-off-by: Taras Pisetskyi <taras.pisetskyi@globallogic.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38023>
2025-10-24util/dynarray: infer type in appendAlyssa Rosenzweig
Most of the time, we can infer the type to append in util_dynarray_append using __typeof__, which is standardized in C23 and support in Jesse's MSMSVCV. This patch drops the type argument most of the time, making util_dynarray a little more ergonomic to use. This is done in four steps. First, rename util_dynarray_append -> util_dynarray_append_typed bash -c "find . -type f -exec sed -i -e 's/util_dynarray_append(/util_dynarray_append_typed(/g' \{} \;" Then, add a new append that infers the type. This is much more ergonomic for what you want most of the time. Next, use type-inferred append as much as possible, via Coccinelle patch (plus manual fixup): @@ expression dynarray, element; type type; @@ -util_dynarray_append_typed(dynarray, type, element); +util_dynarray_append(dynarray, element); Finally, hand fixup cases that Coccinelle missed or incorrectly translated, of which there were several because we can't used the untyped append with a literal (since the sizeof won't do what you want). All four steps are squashed to produce a single patch changing every util_dynarray_append call site in tree to either drop a type parameter (if possible) or insert a _typed suffix (if we can't infer). As such, the final patch is best reviewed by hand even though it was tool-assisted. No Long Linguine Meals were involved in the making of this patch. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38038>
2025-10-24util: require typeof supportAlyssa Rosenzweig
It is in C23 and Jesse reports that his MSMSVCV has it. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Acked-by: Jesse Natalie <jenatali@microsoft.com> [over IRC] Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38038>
2025-10-23util: Fix gnu-empty-initializer errorMauro Rossi
Fixes the following building error happening with clang: ../src/util/os_file.c:291:29: error: use of GNU empty initializer extension [-Werror,-Wgnu-empty-initializer] struct epoll_event evt = {}; ^ 1 error generated. Fixes: 17e28652 ("util: mimic KCMP_FILE via epoll when KCMP is missing") Cc: "25.3" Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37944>
2025-10-22util: Build util/cache_ops_x86.c with -msse2Faith Ekstrand
__builtin_ia32_clflush() requires -msse2 so we need to set -msse2 at least for building that file. Fortunately, there are no GPUs that actually need userspace cache flushing that can ever be bolted onto a pre-SSE2 x86 CPUs. Fixes: 555881e57499 ("util/cache_ops: Add some cache flush helpers") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14134 Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37958>
2025-10-22util: Don't advertise cache ops on x86 without SSE2Faith Ekstrand
Fixes: 555881e57499 ("util/cache_ops: Add some cache flush helpers") Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37958>
2025-10-16anv: Add support for low latency hint on Xe KMDJosé Roberto de Souza
This hint tells KMD and firmware to turn into low latency but high power usage mode. i915 already had it now it was implemented in Xe KMD. Reviewed-by: Sushma Venkatesh Reddy <sushma.venkatesh.reddy@intel.com> Signed-off-by: José Roberto de Souza <jose.souza@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33214>
2025-10-16Revert "brw: add serialize send stats"Lionel Landwerlin
This reverts commit b8ae4ede60f2aa65aabd1d3d5339f8f98ff2a111 now that we have a cycle estimation accounting. Reviewed-by: Alyssa Anne Rosenzweig <alyssa.rosenzweig@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37816>
2025-10-16util/cache_ops/x86: Call util_get_cpu_caps() lessFaith Ekstrand
This also makes all the paths a bit more clear because we only ever clflushopt on the clflusopt paths and only ever clflush on the clflush paths. It's really not much more code or logic duplication. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37803>
2025-10-16util/cache_ops: Add some cache flush helpersFaith Ekstrand
The x86 implementation was shamelessly stolen from intel_mem.c and the aarch64 implementaiton was based on the code in Turnip. Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Tested-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Danylo Piliaiev <dpiliaiev@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37803>
2025-10-15treewide: don't check before freeAlyssa Rosenzweig
This was something that came up in the slop MR. Not sure it's actually a good idea or not but kind of curious what people think, given we have a sound tool (Coccinelle) to do the transform. Saves a redundant branch but means extra noninlined function calls.. likely no actual perf impact but saves some code. Via Coccinelle patches: @@ expression ptr; @@ -if (ptr) { -free(ptr); -} +free(ptr); @@ expression ptr; @@ -if (ptr) { -FREE(ptr); -} +FREE(ptr); @@ expression ptr; @@ -if (ptr) { -ralloc_free(ptr); -} +ralloc_free(ptr); @@ expression ptr; @@ -if (ptr != NULL) { -free(ptr); -} - +free(ptr); @@ expression ptr; @@ -if (ptr != NULL) { -FREE(ptr); -} - +FREE(ptr); @@ expression ptr; @@ -if (ptr != NULL) { -ralloc_free(ptr); -} - +ralloc_free(ptr); Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> [v3d] Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> [venus] Reviewed-by: Frank Binns <frank.binns@imgtec.com> [powervr] Reviewed-by: Janne Grunau <j@jannau.net> [asahi] Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> [radv] Reviewed-by: Job Noorman <jnoorman@igalia.com> [ir3] Acked-by: Marek Olšák <maraeo@gmail.com> Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Acked-by: Job Noorman <jnoorman@igalia.com> Acked-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Christian Gmeiner <cgmeiner@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37892>
2025-10-15util: use F_DUPFD_QUERY on LinuxPierre-Eric Pelloux-Prayer
F_DUPFD_QUERY has been introduced in 6.10 exactly for the purpose of telling if 2 fd points at the same file description so use it first. If it's not supported, we'll get r=-1 and errno=EINVAL, and we can fallback on KCMP or epoll. Acked-by: Simona Vetter <simona.vetter@ffwll.ch> Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34447>
2025-10-15util: mimic KCMP_FILE via epoll when KCMP is missingPierre-Eric Pelloux-Prayer
On Linux platforms where KCMP isn't allowed epoll can be used as a fallback mechanism to provide the same feature. Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34447>
2025-10-15util/range_remap: switch to using sorted arrayTimothy Arceri
Here we switch to using a sorted arrays for the binary search which significantly speeds up the lookups. For a shader with ~8000 uniforms its up to 10x faster and the godot-tps-gles3-high.trace in issue #13894 returns to its original runtime length before we switched to using range remap in e05225406617 Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-15util/range_remap: add util_range_switch_to_sorted_array() helperTimothy Arceri
This creates an array of the linked list elements to be used for faster binary searches in the following patch, and frees the old linked list. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-15util/range_remap: use child memory context for listTimothy Arceri
This will allow us to easily free the list when we switch to a sorted array in a following patch Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-15util/range_remap: split list node from range entryTimothy Arceri
This will allow us to create an array of entries without the node member in a following patch. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-15glsl/util: update util_range_remap to use range_remap structTimothy Arceri
This will allow us to use the linked list for validation of inserts during linking then switch to using an array for fast binary searches. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-15util/range_remap: dont overwrite entry if ptr is NULLTimothy Arceri
If the ptr value is NULL and we match an existing entry during an insert call we now just return the existing value. This allows us to drop an extra lookup, this will become important as the following patches change `util_range_remap()` lookups to use a sorted array that is not created until after we have added all entries to our linked list. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37754>
2025-10-14llvmpipe: Work around WSL 1 missing support for memfd_create()Rob Hughes
WSL version 1 has a known limitation that the kernel does not support the memfd_create() syscall, and it always returns -1 (see https://github.com/microsoft/WSL/issues/3542). This results in lavapipe/llvmpipe failing to create the anonymous file it needs for allocations from the pipe_screen object, which in turn results in results in failed application calls to Vulkan APIs (in the case I observed, vkMapMemory returned an invalid (0xffffffff) pointer along with VK_SUCCESS, leading to the application segfaulting). This issue can be reproduced by simply running `vkcube` (or, presumably any other simple Vulkan application) inside WSL 1, e.g.: xvfb-run -s '-screen 0 1024x768x24' vkcube --c 300 This patch addresses the issue with several changes: 1. llvmpipe_create_screen() now checks for errors from the os_create_anonymous_file function and errors out early, making it easier to track down issues similar to this. Previously, the invalid fd of -1 would be stored in the pipe_screen struct and the problems would only appear later. 2. os_create_anonymous_file() now attempts to handle the case where memfd_create() fails, by falling back to creating a file in a temporary directory. This fallback is the same as is already done for builds that don't have memfd_create available at build time - note that the difference here is that this is a _runtime_ fallback, as is needed for the case of WSL 1. 3. The fallback logic previously relied on the XDG_RUNTIME_DIR environment variable, which might not be set when running inside WSL because there is unlikely to be a desktop environment configured. This patch adds a fallback of creating a new directory inside /tmp in this case. Reviewed-by: Lucas Fryzek <lfryzek@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37679>
2025-10-10brw: add serialize send statsLionel Landwerlin
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com> Reviewed-by: Alyssa Anne Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Francisco Jerez <currojerez@riseup.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37394>
2025-10-10util/macros: coerce likely/unlikely to bool even without __builtin_expectOlivia Lee
Coercing the argument to a bool when we have __builtin_expect but leaving it unmodified otherwise is a recipe for really subtle bugs. I don't know if any bugs like that exist currently, but I almost introduced one in panfrost. Signed-off-by: Olivia Lee <olivia.lee@collabora.com> Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37801>
2025-10-09util: add BITSET_CALLOC helperAlyssa Rosenzweig
comes up a bunch. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37779>
2025-10-08u_trace: use os_get_option instead of getenvLionel Landwerlin
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Acked-by: Tim Van Patten <timvp@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37740>