Commit graph

12179 commits

Author SHA1 Message Date
Caio Oliveira
992b35704e nir/instr_set: Consider normalization when calculating hash
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
The nir_instrs_equal normalizes the some indices but hash_intrinsic
wasn't normalizing them.  Reorganize the code so both do it using the
same helper.

Fixes: b2bc57551a ("nir/instr_set: allow cse with fp_math_ctrl mismatches for intrinsics")
Assisted-by: Pi coding agent (GPT-5.5)
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41606>
2026-05-20 05:24:21 +00:00
Karol Herbst
e9c1cce35f nir: remove ffma_old
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:42 +00:00
Karol Herbst
099e876a38 vtn_bindgen2: keep ffma_weak
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:42 +00:00
Karol Herbst
a140781aec vtn/opencl: map mad to ffma_weak and fma to ffma
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:42 +00:00
Karol Herbst
09d50cc7a3 vtn: use ffma_weak
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:42 +00:00
Karol Herbst
d534a2057f vtn: handle OpFmaKHR
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:42 +00:00
Karol Herbst
3e158b713c vtn/glsl: translate fma as ffma_weak
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:41 +00:00
Karol Herbst
ac679a8504 glsl: translate fma as fma_weak
Our glsl compiler only supports OpenGL GLSL and there ffma is not
guaranteed to be fused.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:41 +00:00
Karol Herbst
e1aaaf4ed0 nir: make lowering use new ffma opcodes
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:41 +00:00
Karol Herbst
109d93dd98 nir: update ffma helpers to use new opcodes
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:41 +00:00
Karol Herbst
aeea2e7c1f nir: add fmad_or_ffma helpers and use it in lower_double_ops
We skip emitting ffma_weak here, because otherwise we'd require a lowering
loop with opt_algebraic and lower_double_ops and this way it's also
cheaper.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:40 +00:00
Karol Herbst
688e5cda94 nir/tests: use ffma_weak
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:31 +00:00
Karol Herbst
b7094546f4 nir: duplicate old ffma opts where necessary for new multadd ones
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:30 +00:00
Karol Herbst
86007ae1ad nir: handle new multadd opcodes in helpers
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:30 +00:00
Karol Herbst
68dc336af7 nir: handle new multadd opcodes in lowerings and opts
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:30 +00:00
Karol Herbst
bb2b7c58fc nir/opt_algebraic: add fmad and ffma_weak lowering rules
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:28 +00:00
Karol Herbst
9ffa7c826f nir/tests: handle new multadd opcodes
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:28 +00:00
Karol Herbst
7ce841cb71 nir: validate new float_mul_add options
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:28 +00:00
Karol Herbst
32e91a7467 nir: add new float multiply-add opcodes
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:28 +00:00
Karol Herbst
0251be32cb nir: rename nir_fmad to nir_fmad_old
We'll add a new opcode called fmad and this would conflict with the
helper.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:27 +00:00
Karol Herbst
a9b18f8607 nir: rename ffma to ffma_old
We'll get three new opcodes to properly model float multiply-add.
ffma_old is temporary and will be deleted at the end of this series.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:27 +00:00
Karol Herbst
337018fcbb glsl/softfp: rename ffma to fmad
They were always implemented as unfused.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41165>
2026-05-19 18:13:25 +00:00
Marek Olšák
63deaf3bfe nir: add nir_frag_coord_use_pixel_coord for OpenGL
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41461>
2026-05-19 15:03:50 +00:00
Marek Olšák
2d8d200c70 nir: change nir_frag_coord_form options to a bitmask
this makes it easier to add more options

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41461>
2026-05-19 15:03:50 +00:00
Marek Olšák
7f5a307c12 nir: handle load_frag_coord_w_rcp in multiple passes, same as non-rcp
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41461>
2026-05-19 15:03:50 +00:00
Marek Olšák
cbdbdd50ad nir: add missing SYSTEM_VALUE_FRAG_COORD_W_RCP
for nir_intrinsic_load_frag_coord_w_rcp.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41461>
2026-05-19 15:03:50 +00:00
Georg Lehmann
4df9d03e7a spirv: always preserve infinities for FMin, FMax and FClamp
Don't ask me why these game engines do not use NMin and friends,
maybe they don't know those exist.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/15481
Backport-to: 26.1

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41661>
2026-05-19 11:45:17 +00:00
Marek Olšák
2d44e1b907 nir/tests: use ASSERT_EQ instead of ASSERT_TRUE in nir_opt_varyings tests
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
2026-05-19 04:26:55 +00:00
Marek Olšák
09edd9fea5 nir/opt_varyings: always report progress when calling nir_remove_varying
It changes IO semantics even if it doesn't remove the instruction.

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
2026-05-19 04:26:55 +00:00
Marek Olšák
5dc54432d0 nir/tests: test new output deduplication cases
Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
2026-05-19 04:26:55 +00:00
Marek Olšák
24e0226058 nir/tests: don't leave "namespace {" unclosed in nir_opt_varyings_tests.h
Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
2026-05-19 04:26:55 +00:00
Marek Olšák
ca137e545c nir/opt_varyings: rewrite elimination of duplicated outputs
to strengthen it and fix a rare case of incorrect behavior.

This is the incorrect behavior that's fixed:

    if (invocation_id == 0)
       patch_output[0] = invocation_id;
    else if (invocation_id == 1)
       patch_output[1] = invocation_id;
    else
       patch_output[2] = invocation_id;

The stored SSA defs are the same, but each invocation writes a different
value to different outputs, so they are not duplicated, but the code
incorrectly treated them as duplicated and removed [1] and [2].

The requirement for correctness is that if an output is duplicated,
it must have stores in the same blocks as the output it duplicates.

To fix the incorrect behavior, awareness of blocks is added to the algorithm,
which leads to the following new cases that are optimized:

    1. Different blocks store different SSA defs, but equal in each block:
        if (..) {
           output[0] = a;
           output[1] = a; // eliminated
        } else {
           output[0] = b;
           output[1] = b; // eliminated
        }

    2. Different GS emit sections store different SSA defs, but equal in each
       section:
        output[0] = a;
        output[1] = a; // eliminated
        emit_vertex;
        output[0] = b;
        output[1] = b; // eliminated
        emit_vertex;

    3. A weird case that could be duplicated but is left alone due to
       the counterexample above:
        if (..)
           output[0] = a;
        else
           output[1] = a;

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41329>
2026-05-19 04:26:54 +00:00
Simon Perretta
1821309b54 pvr, pco: add support for spilling shared memory to global memory
Add a PCO_DEBUG option to force spilling to begin with.

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41545>
2026-05-18 12:43:51 +00:00
Daniel Schürmann
3749db73f4 nir/lower_bit_size: skip conversion for more opcodes
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41388>
2026-05-18 11:01:06 +00:00
Daniel Schürmann
01c9311cfb nir/lower_bit_size: use nir_def_replace() instead of nir_def_rewrite_uses()
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41388>
2026-05-18 11:01:06 +00:00
Daniel Schürmann
16bf0a2047 nir/lower_bit_size: use nir_builder::constant_fold_alu
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41388>
2026-05-18 11:01:06 +00:00
Daniel Schürmann
bc941eb4ff nir/builder: constant-fold nir_mov_alu() if requested
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41388>
2026-05-18 11:01:06 +00:00
Calder Young
768f4782e3 spirv: Fix debugPrintfEXT not working with multiple arguments
The struct field offsets weren't getting initialized.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
CC: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41590>
2026-05-18 08:21:19 +00:00
Ian Romanick
e76abd1e3a nir/opt_constant_folding: Don't fight with nir_lower_bit_size
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
Intel uses nir_lower_bit_size to convert 8-bit integer values to 16-bit
for most instructions. By constant folding u2u8 or i2i8 through a bcsel,
this lowering is undone.

Fixes assertion failure in fossils/parallel-rdp/small_subgroup.foz.

fossilize-replay: src/intel/compiler/brw/brw_from_nir.cpp:852: void brw_from_nir_emit_alu(nir_to_brw_state&, nir_alu_instr*, bool): Assertion `brw_type_size_bytes(op[i].type) > 1' failed.

v2: Reject all integer conversions. Suggested by Daniel Schürmann.

Fixes: f4812dc11d ("nir/opt_constant_folding: constant-fold op(bcsel(), #c) -> bcsel(.., #c1, #c2)")
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41412>
2026-05-15 23:36:25 +00:00
Karol Herbst
c3832060a4 clc: do not use std::filesystem
It seems like davinci resolve conflicts on those symbols and we got
regressions from our static libstdc++ linking workaround.

Cc: mesa-stable
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41488>
2026-05-15 22:59:58 +00:00
Caio Oliveira
0281eb2e98 nir/instr_set: Fix multi-slot intrinsic index equality
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
nir_intrinsic_index_size() expects a nir_intrinsic_index_flag, not
the position in the intrinsic's index list.  This could cause
part of a multi-slot index to be ignored.

Fixes: b2bc57551a ("nir/instr_set: allow cse with fp_math_ctrl mismatches for intrinsics")
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41593>
2026-05-15 18:13:15 +00:00
Georg Lehmann
0be2d71ad1 nir/opt_uniform_subgroup: preserve divergence during optimization
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
nir_def_init sets divergent = true, this means for something like
reduce(reduce(convergent)) we previously only optimized the inner
reduce.

No fossil changes at the moment, but I hit this when trying to
optimize shared memory to subgroup operations.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41542>
2026-05-15 08:42:18 +00:00
Samuel Pitoiset
dc398afb27 nir: fix shuffling local IDs for quad derivatives with larger workgroup sizes
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
This was fundamentally broken for workgroup sizes >= 8x8.

This fixes new VKCTS coverage
dEQP-VK.glsl.texture_functions.texture.*_compute, and also few tests
from the vkd3d-proton testsuite (note that quad derivatives is
currently disabled for < GFX12).

Cc: mesa-stable
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41483>
2026-05-15 07:04:32 +00:00
Marek Olšák
e966c1bdec nir/opt_varyings: use workgroup divergence to identify convergent mesh outputs
It turns out we do have workgroup divergence, hidden behind
nir_divergence_across_subgroups, if I understand it correctly.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41225>
2026-05-15 00:09:42 +00:00
Marek Olšák
edb60c76e2 nir: generalize nir_vertex_divergence_analysis -> nir_custom_divergence_analysis
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41225>
2026-05-15 00:09:42 +00:00
Marek Olšák
3831935818 nir/opt_move_to_top: add an option to exclude moving at_offset/at_sample loads
This splits the nir_move_to_top_input_loads option into 2 options. The latter
option is mainly for at_offset/at_sample loads. Then it updates most places to
use only the first option.

The rationale is that moving at_sample loads makes Control (game) shaders
worse, as per the code comment.

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41167>
2026-05-14 16:48:39 -04:00
Arzaq Naufail Khan
e2cd37e422 spirv: fix resource leak in spirv shader replacement
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39512>
2026-05-14 17:09:28 +00:00
Lionel Landwerlin
df5a6d7b87 brw/jay: move some coarse lowering to NIR
We add a pass to allow testing partially known fs config bits (main
user is DX11 always disabling VRS/coarse).

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41529>
2026-05-14 14:05:06 +00:00
David Airlie
6a7a46ac21 nir/coopmat: rename the box split variables.
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
When we add workgroup support we have to add inner box splits as well
so name the outer splits correctly.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41500>
2026-05-14 02:15:05 +00:00
David Airlie
6062bcde56 nir/coopmat: move the row/col into a box and add some helpers.
This makes adding workgroup scope easier, this just creates the
split_box and moves things into it and adds some helpers.

This also rewrites some loops from r/c into i which calc r/c

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41500>
2026-05-14 02:15:05 +00:00