Commit graph

60 commits

Author SHA1 Message Date
Faith Ekstrand
76bba3ffba compiler/rust/cfg: Use DepthFirstSearch for find_back_edges()
Reviewed-by: Lorenzo Rossi <git@rossilorenzo.dev>
Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37536>
2025-10-14 22:47:40 +00:00
Faith Ekstrand
030005a772 compiler/rust/cfg: Use DepthFirstSearch for calc_dominance()
Reviewed-by: Lorenzo Rossi <git@rossilorenzo.dev>
Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37536>
2025-10-14 22:47:40 +00:00
Faith Ekstrand
7f73a027ae compiler/rust/cfg: Use DepthFirstSearch for rev_post_order_sort()
Reviewed-by: Lorenzo Rossi <git@rossilorenzo.dev>
Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37536>
2025-10-14 22:47:39 +00:00
Faith Ekstrand
993f5c9e30 compiler/rust: Add a DepthFirstSearch trait
There are four depth first searches in cfg.rs.  This adds a DFS
abstraction which we can later optimize.

Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Reviewed-by: Lorenzo Rossi <git@rossilorenzo.dev>
Reviewed-by: Mary Guillemard <mary@mary.zone>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37536>
2025-10-14 22:47:38 +00:00
Christian Gmeiner
5977c0026d nak: Move dataflow to compiler crate
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: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37348>
2025-09-13 07:30:50 +00:00
Mel Henning
611c5ebce5 compiler/rust: impl AsSlice for Box
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Seán de Búrca <leftmostcat@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37315>
2025-09-12 10:33:32 +00:00
Dave Airlie
c38170452d nir: add nir_intrinsic_cmat_load_shared_nv
This maps to NAK's OpLdsm

Reviewed-by: Mary Guillemard <mary@mary.zone>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36363>
2025-08-28 16:09:07 +02:00
Faith Ekstrand
a1d5e8bfdb compiler/rust: Fix the DFS loop detection algorithm
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
The previous algorithm just looked at the dominator's loop header.
However, if you have multiple consecutive loops like:

    function_impl {
        loop {
            // Stuff
        }
        loop {
            // Other stuff
        }
    }

then it will look like the second loop is contained in the first loop
because the first loop's header dominates the second loop.  This isn't
actually what we want.  Instead, we want a node N to be considered part
of a loop with header H if H dominates N and H is reachable from N.

Fixes: 741f7067f1 ("nak: Add loop detection to the CFG")
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36524>
2025-08-27 01:20:05 +00:00
Faith Ekstrand
70e7d72e7e compiler/rust/cfg: Use slices instead of &Vec
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
fcd6616624 compiler/rust/bitset: Don't use a vector for expected sets in tests
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
0cdd37b5ff compiler/rust: Stop using try_into() for u8 -> usize
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
511f747fb8 compiler/rust: Add a bunch of clippy lints
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
d3fc91d6c2 compiler/rust: Don't use assert_eq!() with booleans
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
e5f4d36192 compiler/rust/nir: Drop a bunch of explicit lifetimes
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
8324a14875 compiler/rust: Add Rust 2024 lints
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
3b102368ac compiler/rust: Stop using NonNull in the NIR bindings
Rust's core pointer type has an as_ref() which returns Option<&T>
already so there's no point in using NonNull.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Faith Ekstrand
d9ceefdcb6 compiler/rust: Use .as_ref().unwrap() instead of &*
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:50 +00:00
Antonio Ospite
8f84ae7de7 compiler/rust: fix errors about hiding elided lifetime
In some setups the rust compiler emits errors like the following:

-----------------------------------------------------------------------
error: hiding a lifetime that's elided elsewhere is confusing
   --> ../subprojects/proc-macro2-1.0.86/src/parse.rs:125:25
    |
125 | fn block_comment(input: Cursor) -> PResult<&str> {
    |                         ^^^^^^     -------------
    |                         |          |       |
    |                         |          |       the same lifetime is elided here
    |                         |          the same lifetime is hidden here
    |                         the lifetime is hidden here
    |
    = help: the same lifetime is referred to in inconsistent ways, making the signature confusing
    = note: `-D mismatched-lifetime-syntaxes` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(mismatched_lifetime_syntaxes)]`
help: use `'_` for type paths
    |
125 | fn block_comment(input: Cursor<'_>) -> PResult<'_, &str> {
    |                               ++++             +++
-----------------------------------------------------------------------

Follow the solution suggested by the compiler to silence the errors, for
all the observed occurrences.

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36849>
2025-08-20 17:06:47 +00:00
Qiang Yu
f972e76148 all: rename pipe_shader_type to mesa_shader_stage
Use command:
  find . -type f -not -path '*/.git/*' -exec sed -i 's/\benum pipe_shader_type\b/mesa_shader_stage/g' {} +
  find . -type f -not -path '*/.git/*' -exec sed -i 's/\bpipe_shader_type\b/mesa_shader_stage/g' {} +

Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36569>
2025-08-06 10:28:40 +08:00
Qiang Yu
196569b1a4 all: rename gl_shader_stage to mesa_shader_stage
It's not only for GL, change to a generic name.

Use command:
  find . -type f -not -path '*/.git/*' -exec sed -i 's/\bgl_shader_stage\b/mesa_shader_stage/g' {} +

Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36569>
2025-08-06 10:28:40 +08:00
Faith Ekstrand
0f81dd187f compiler/rust: Add a CFG::loop_depth() method
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36466>
2025-07-31 22:39:25 +00:00
Paolo Bonzini
8ea232a9ae meson: rename Rust subprojects to NAME-SEMVER-rs
Use the convention for Rust subprojects that was adopted by Meson 1.5.0
and newer.

Distros would prefer to avoid vendored crate sources, and instead use
local sources from e.g. /usr/share/cargo/registry.  While Meson does not
support a local registry, it can be emulated with MESON_PACKAGE_CACHE_DIR.

However, because the distro might not be using the exact version of the
package, but only one that has the same semver, packagers need to add
some hacks to rewrite the wrap files.  For example, in Fedora:

    export MESON_PACKAGE_CACHE_DIR="%{cargo_registry}/"
    # So... Meson can't actually find them without tweaks
    %define inst_crate_nameversion() %(basename %{cargo_registry}/%{1}-*)
    %define rewrite_wrap_file() sed -e "/source.*/d" -e "s/%{1}-.*/%{inst_crate_nameversion %{1}}/" -i subprojects/%{1}.wrap
    %rewrite_wrap_file proc-macro2
    %rewrite_wrap_file quote
    %rewrite_wrap_file syn
    %rewrite_wrap_file unicode-ident
    %rewrite_wrap_file paste

Having a common convention for the name of Rust wraps makes it possible
to perform this transformation with a script without listing
the wraps one by one, and to share the script across multiple packages
(which will be useful when QEMU starts using Rust in a similar way to Mesa).

For an example of such a script, see
https://lore.kernel.org/r/20250722083507.678542-1-pbonzini@redhat.com/.

Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36284>
2025-07-24 17:52:34 +00:00
Mel Henning
42ba492b88 compiler/rust/bitset: BitSetStream takes Key type
This was an oversight when BitSet was parameterized on a key type.
BitSetStream needs to also take a key type to prevent users from mixing
different key types in binary operators. Constraining this makes BitSet
usage more type safe.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35328>
2025-06-09 21:49:29 +00:00
Mel Henning
5f0e4a7605 nak,nir: Stop using std::mem::zeroed()
We can replace all of these with safe alternatives if we ask bindgen for
implementations of Default.

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35390>
2025-06-06 18:58:35 +00:00
Mel Henning
22401cd49e compiler/rust/bitset: find_aligned_unset_region()
Add a new helper and use it from within nak.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35033>
2025-05-21 19:40:02 +00:00
LingMan
3fbee8bae6 meson: Streamline silencing of warnings in bindgen generated code
Everyone was doing roughly the same.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34969>
2025-05-21 17:11:08 +00:00
Faith Ekstrand
56f06a072c compiler/rust/bitset: Make BitSet a generic container type
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34994>
2025-05-15 22:28:31 -04:00
Faith Ekstrand
323769d3bb compiler/rust,nak: Rename BitSet::get() to contains()
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34994>
2025-05-15 22:14:12 -04:00
Mel Henning
ed658a2d3a compiler/rust/cfg: Add a hash func type parameter
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
and switch nak over to rustc-hash for CFGBuilder

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34865>
2025-05-16 01:40:05 +00:00
Faith Ekstrand
13f9135e85 compiler/rust: Better document CFG
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34919>
2025-05-12 17:31:33 +00:00
Faith Ekstrand
6aa2c152b8 nak,nir: Add an image_load_raw_nv intrinsic
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34336>
2025-04-08 04:06:45 +00:00
Faith Ekstrand
c05565ce7b compiler/rust: Add more NIR intrinsic getters
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Reviewed-by: Benjamin Lee <benjamin.lee@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34126>
2025-03-29 03:02:17 +00:00
Faith Ekstrand
1355c71943 compiler/rust: Add a nir_alu_type wrapper
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Reviewed-by: Benjamin Lee <benjamin.lee@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34126>
2025-03-29 03:02:17 +00:00
Faith Ekstrand
61108eb1b5 compiler/rust: Add u_printf_info to the rust bindings
This both adds it to the compiler allowlist and adds it to the user
denylist.  This gets rid of a Rust compiler warning in NAK.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33402>
2025-03-01 08:44:15 +00:00
Mel Henning
c273ada502 compiler/rust/bitset: Test next_unset()
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
2bcb950865 compiler/rust/bitset: Don't expose words
This encapsulates the bitset's word size and word count, which means
consumers no longer need to be careful about word count. Users of the old
apis for writing expressions on bit sets should migrate to the new expression
API.

Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
86e5cb7c2d compiler/rust/bitset: Take a stream in union_with
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
47da213e19 compiler/rust/bitset: Add a lazy expression API
The new api doesn't require allocations for intermediate values in
expressions. It also has tests, which is nice because eg. the previous
implementation of the `&` operator was broken.

Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
e52b2ee4b9 compiler/rust/bitset: Remove impl Not
This is extremely difficult to use correctly for bitsets of
different sizes. Also, nobody uses it. Remove the footgun.

Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
8ec885da1d compiler/rust/bitset: impl FromIterator
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:48 +00:00
Mel Henning
de47702dde compiler/rust/bitset: Make BitSetIter private
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:47 +00:00
Mel Henning
06cd3c7fa3 compiler/rust/bitset: Removed unused start param
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:47 +00:00
Mel Henning
6ba317bd8c compiler/rust/bitset: Add a basic test
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:47 +00:00
Mel Henning
3b341366a6 compiler/rust: Fix running tests
`ninja test` wasn't actually running these tests, I guess because the
target name was duplicated in meson. Fix this so the tests actually run.

Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:47 +00:00
Mel Henning
639211dea8 compiler/rust/bitset: Fix the bitset iterator
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32812>
2025-01-02 20:52:47 +00:00
LingMan
0ff3e2a0f9 compiler/rust: Use std::mem::offset_of!()
It got stabilized with Rust 1.77.

Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31510>
2024-11-18 22:29:13 +00:00
David Heidelberg
1368ee5e1a compiler/rust: drop duplicated bindgen check
The same check is present in meson file in root directory.

Cc: mesa-stable # 24.3
Reviewed-by: Eric Engestrom <eric@igalia.com>
Signed-off-by: David Heidelberg <david@ixit.cz>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32101>
2024-11-14 20:12:31 +00:00
Christian Gmeiner
5fa4c1a191 compiler/rust: Copy NirInstrPrinter from NAK
Switch NAK to it.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: M Henning <drawoc@darkrefraction.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31706>
2024-10-18 12:43:52 +00:00
Faith Ekstrand
4cc9730307 compiler/rust: Fix a bad cast in the memstream abstraction
If you just do ref.cast(), it will cast the thing it's a reference to.
If you want to turn a reference into a pointer, you need to explicitly
use "as".

Fixes: 279f38918f ("nak: memstream: move into common code")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31718>
2024-10-17 18:59:02 +00:00
Faith Ekstrand
212e07a70e compiler/rust: Add a unit test for the memstream abstraction
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31718>
2024-10-17 18:59:02 +00:00