Commit graph

9480 commits

Author SHA1 Message Date
David Heidelberg
68215332a8 build: pass licensing information in SPDX form
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Dylan Baker <dylan.c.baker@intel.com>
Acked-by: Eric Engestrom <eric@igalia.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: David Heidelberg <david@ixit.cz>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29972>
2024-06-29 12:42:49 -07:00
Jesse Natalie
c2b53d7bd0 nir: Remove assert-only variable by inlining its single use
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29970>
2024-06-28 20:44:36 +00:00
Alyssa Rosenzweig
30db807f79 nir/algebraic: explicitly suffix constants
Make our intentions super duper clear.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Suggested-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29952>
2024-06-28 19:53:36 +00:00
Alyssa Rosenzweig
270446ee21 nir: fix miscompiles with rules with INT32_MIN
812b3415 added rules for upcasts with comparisons with a variety of
types. The float & unsigned rules should be ok, but the signed integer rules are
unsound as currently implemented. This can cause end-to-end miscompiles.

I originally hit this issue while debugging a large real world OpenCL kernel. I
found the bug symptoms changed when disabling loop unrolling, which tipped me
off to a compiler bug. I've reduced it to a minimal test case. Imagine my
surprise when I find out the NIR my backend ingested was already constant folded
to be wrong.

In the minimal test case, during optimization we have NIR:

        32     %6 = ....
        64     %9 = i2i64 %6
        64    %44 = load_const (0x0000000000000001)
        1     %45 = ilt %9, %44 (0x1)

This is a simple check (int64_t)%6 < 1.

nir_opt_algebraic turns this into:

        32     %6 = ...
        64     %9 = i2i64 %6
        64    %44 = load_const (0x0000000000000001)
        64    %55 = load_const (0x0000000080000000 = 2147483648)
        1     %56 = ilt %55 (0x80000000), %44 (0x1)
        64    %57 = load_const (0x000000007fffffff = 2147483647)
        1     %58 = ilt %57 (0x7fffffff), %44 (0x1)
        32    %59 = i2i32 %44 (0x1)
        1     %60 = ilt %6, %59
        1     %61 = ior %58, %60
        1     %62 = iand %56, %61

This pile of math constant-folds to an unconditional "false"!  The problem is
%56. At first glance, INT32_MIN < 1 is true so %56 should be true. Indeed, it
should. But here's the kicker: both constants are 64-bit here, so the ilt
operation is a 64-bit comparison -- that left-hand side is INT32_MIN
zero-extended to 64-bit for the signed comparison at 64-bit. So in fact, it
evaluates to false, causing the whole expression to go false.  If we're going to
do a 64-bit comparison for %56, then we need to sign-extend the bound.  So we'll
just adjust the Python and be on our way, right?

Unfortunately the issue is deeper. According to the comment in the generated
nir_opt_algebraic.c file, the guilty algebraic rule is:

   ('ilt', ('i2i64', 'a@32'), '#b') =>
   ('iand', ('ilt', -2147483648, 'b'), ('ior', ('ilt', 2147483647, 'b'), ('ilt', 'a', ('i2i32', 'b'))))

From a Python perspective? That rule is correct. -2147483648 < 1 is a true
statement. Adjusting the Python rule is not the appropriate solution here, since
the issue is more fundamental and might affect other rules.  The real problem is
the translation of that Python replacement tree into C, incorrectly
zero-extending -2147483648 into 0x0000000080000000 instead of sign-extending to
0xffffffff80000000.

Crawling down the rabbit hole of the generated algebraic file, we see the
constant encoded as:

   { .constant = {
      { nir_search_value_constant, 64 },
      nir_type_int, { -0x80000000 /* -2147483648 */ },
   } },

NIR correctly translates the negative constant to a C level negate operation of
its absolute value. This maps to the correct sign-extension...

...for all constants except for INT_MIN. Because that constant lacks a ULL
suffix, it is a 32-bit integer. And for this integer (only), negating it hits
signed integer overflow (UB!) and then we end up with an effective
zero-extension when going to 64-bit.

This patch fixes the end-to-end miscompile.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Closes: #11402
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29952>
2024-06-28 19:53:36 +00:00
Georg Lehmann
3e86d2452f nir/opt_algebraic: add various unordered/ordered patterns from aco
Foz-DB Navi21:
Totals from 6747 (8.50% of 79395) affected shaders:
MaxWaves: 134646 -> 134642 (-0.00%)
Instrs: 7830299 -> 7828851 (-0.02%); split: -0.03%, +0.01%
CodeSize: 43045532 -> 43010260 (-0.08%); split: -0.09%, +0.00%
VGPRs: 378960 -> 378968 (+0.00%)
SpillSGPRs: 1209 -> 1208 (-0.08%)
Latency: 74667977 -> 74670405 (+0.00%); split: -0.02%, +0.02%
InvThroughput: 20124981 -> 20124768 (-0.00%); split: -0.02%, +0.02%
VClause: 162870 -> 162868 (-0.00%); split: -0.00%, +0.00%
SClause: 277280 -> 277315 (+0.01%); split: -0.00%, +0.02%
Copies: 528627 -> 528667 (+0.01%); split: -0.00%, +0.01%
PreSGPRs: 319526 -> 319508 (-0.01%)
PreVGPRs: 334264 -> 334265 (+0.00%); split: -0.00%, +0.00%
VALU: 5485412 -> 5485408 (-0.00%); split: -0.02%, +0.02%
SALU: 743882 -> 742301 (-0.21%); split: -0.21%, +0.00%

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29467>
2024-06-27 08:12:30 +00:00
Georg Lehmann
434dfb51ca nir/opt_algebraic: optimize cmp(fneg(a), #b) and feq with fabs
Foz-DB Navi21:
Totals from 2483 (3.13% of 79395) affected shaders:
Instrs: 4067533 -> 4067756 (+0.01%); split: -0.00%, +0.01%
CodeSize: 22525156 -> 22499904 (-0.11%); split: -0.12%, +0.01%
Latency: 51967223 -> 51963654 (-0.01%); split: -0.01%, +0.00%
InvThroughput: 16685020 -> 16683045 (-0.01%); split: -0.01%, +0.00%
SClause: 131890 -> 131907 (+0.01%)
Copies: 402557 -> 402510 (-0.01%); split: -0.01%, +0.00%
Branches: 146962 -> 146958 (-0.00%)
PreSGPRs: 118404 -> 118401 (-0.00%)
PreVGPRs: 123791 -> 123787 (-0.00%)
VALU: 2709846 -> 2710174 (+0.01%); split: -0.00%, +0.01%
SALU: 565883 -> 565786 (-0.02%)

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29467>
2024-06-27 08:12:30 +00:00
Georg Lehmann
98cc57bccb nir/optimize cmp(a, -0.0)
+0.0 can use an inline constant for AMD hardware,
-0.0 needs a literal.

Foz-DB Navi21:
Totals from 1014 (1.28% of 79395) affected shaders:
Instrs: 3037490 -> 3036849 (-0.02%); split: -0.02%, +0.00%
CodeSize: 17060228 -> 17051276 (-0.05%); split: -0.05%, +0.00%
Latency: 45916788 -> 45916600 (-0.00%); split: -0.00%, +0.00%
InvThroughput: 12982201 -> 12982187 (-0.00%); split: -0.00%, +0.00%
VClause: 79475 -> 79478 (+0.00%)
SClause: 119935 -> 119934 (-0.00%); split: -0.00%, +0.00%
Copies: 301641 -> 300964 (-0.22%); split: -0.23%, +0.00%
PreSGPRs: 59155 -> 59144 (-0.02%)
VALU: 2032016 -> 2032034 (+0.00%)
SALU: 386424 -> 385729 (-0.18%)

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29467>
2024-06-27 08:12:30 +00:00
Georg Lehmann
8e6bf596cb nir/opt_algebraic: look through fabs/fneg when matching fmulz/ffmaz
Prevents regressions when removing input modifiers from a == 0.0.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29467>
2024-06-27 08:12:30 +00:00
Georg Lehmann
99372c1ed7 nir: add ford, funord, fneo, fequ, fltu, fgeu
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29467>
2024-06-27 08:12:29 +00:00
Timothy Arceri
6006588ad8 glsl: remove out of date TODO
The TODO was complete when the glsl version of this function was removed
in 318d8ce6fc

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29887>
2024-06-27 01:02:25 +00:00
Eli Schwartz
a4e0eb55ce meson: create libglsl declared dependency to propagate order-only deps
https://mesonbuild.com/FAQ.html#how-do-i-tell-meson-that-my-sources-use-generated-headers

A few locations had underspecified deps on the header files, and this
caused builds to fail given sufficient parallelism. Fix this by creating
an interface library that can be linked against, instead.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29115>
2024-06-26 22:54:50 +00:00
Alyssa Rosenzweig
dd85b50d18 treewide: use nir_break_if
Via Coccinelle patch and some manual hunk editing:

    @@
    expression b, E;
    @@

    -nir_push_if(b, E);
    -{
    -nir_jump(b, nir_jump_break);
    -}
    -nir_pop_if(b, NULL);
    +nir_break_if(b, E);

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29877>
2024-06-26 19:07:35 +00:00
Alyssa Rosenzweig
d57934fdec nir: add nir_break_if helper
I see people open-coding this all over the tree and it makes nir_builder loops
really annoying. Make them slightly less annoying with a helper.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29877>
2024-06-26 19:07:35 +00:00
Karol Herbst
3482ea599b nir/schedule: add write dep also for shared_atomic
Otherwise it might change the order between a load_shared and a
shared_atomic on the same location.

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29918>
2024-06-26 18:20:14 +00:00
Connor Abbott
ec37e65a2d ir3: Introduce elect_any_ir3
For preambles, we don't actually care which invocation we get, so we
don't have to enable helper invocations when the preamble uses "getone."
Introduce a new intrinsic with the right semantics and plumb it through.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29914>
2024-06-26 17:40:15 +00:00
Karol Herbst
d5da434851 nir/opt_sink: add load_kernel_input
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25362>
2024-06-26 10:04:02 +00:00
Karol Herbst
535e617ccd nir/lower_alu: support 8 and 16 bit bit_count
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25362>
2024-06-26 10:04:02 +00:00
Qiang Yu
93f790b04a nir: fix clip cull distance lowering metadata preserve
indirect store lowering will use if/else which changes
the control flow of the shader.

Fixes: 110887de2b ("nir: Add a new pass to lower array dereferences on vectors")
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29894>
2024-06-26 01:22:12 +00:00
Qiang Yu
09b4ba27a3 nir: fix lower array to vec metadata preserve
indirect store lowering will change control flow,
so we should not preserve control flow metadate
when it's present.

Fixes: 35b8f6f40b ("nir: Add a new pass to lower array dereferences on vectors")
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29894>
2024-06-26 01:22:12 +00:00
Ian Romanick
6b678d32cb nir: dpas_intel second source can have different number of components
The number of components for the second source is -1 to avoid validation of
its value. Some supported configurations will have the component count of
that matrix different than the others.

Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28834>
2024-06-25 14:17:47 -07:00
Timothy Arceri
539aaad6a3 glsl: remove unused symbol table functionality
Added in a8f52647b0 and c17c790387 but not used since b04ef3c08a
over 10 years ago.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29868>
2024-06-25 00:18:42 +00:00
Caio Oliveira
a0877c132c glsl: Fix warning related to tg4_offsets in release mode
Compiler can't know that array_size() of the offsets parameter in
textureGatherOffsets is (at most) 4,  so use a MIN2() to make the limit
visible.  Just adding an assert() gets ignored in Release builds.

This fixes the following warning in Release compilation:

```
  ../src/compiler/glsl/glsl_to_nir.cpp: In member function ‘virtual void {anonymous}::nir_visitor::visit(ir_texture*)’:
  ../src/compiler/glsl/glsl_to_nir.cpp:2453:41: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   2453 |                instr->tg4_offsets[i][j] = val;
        |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
  In file included from ../src/compiler/glsl/glsl_to_nir.h:31,
                   from ../src/compiler/glsl/glsl_to_nir.cpp:29:
  ../src/compiler/nir/nir.h:2470:11: note: at offset 8 into destination object ‘nir_tex_instr::tg4_offsets’ of size 8
   2470 |    int8_t tg4_offsets[4][2];
        |           ^~~~~~~~~~~
  ../src/compiler/glsl/glsl_to_nir.cpp:2453:41: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   2453 |                instr->tg4_offsets[i][j] = val;
        |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
  ../src/compiler/nir/nir.h:2470:11: note: at offset 9 into destination object ‘nir_tex_instr::tg4_offsets’ of size 8
   2470 |    int8_t tg4_offsets[4][2];
        |           ^~~~~~~~~~~
```

This is from: `gcc (GCC) 14.1.1 20240522 (Red Hat 14.1.1-4)`.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29508>
2024-06-21 17:37:46 -07:00
Juan A. Suarez Romero
ee1ced9dc5 glsl: fix downcasting addresses to wrong object types
This fixes several downcasting of address to object types when the
original object types were either different or invalid.

This has been detected throught Undefined Behaviour Sanitizer (UBSan).
An example of such issue were:

`downcast of address 0x55559c0cbcc0 which does not point to an object of
type 'ir_variable' 0x55559c0cbcc0: note: object is of type 'ir_constant'

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29772>
2024-06-21 21:07:05 +00:00
Juan A. Suarez Romero
60e7cb7654 nir: use unsigned types when performing bitshifting
Ensure unsigned integers are used instead of signed ones when performing
left bit shifts.

This has been detected by the Undefined Behaviour Sanitizer (UBSan).

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29772>
2024-06-21 21:07:05 +00:00
Juan A. Suarez Romero
e43cc49806 nir: fix overflow when negating maxint in constant expressions
Undefined Behaviour Sanitizer (UBSan) detected the following when
running testing `dEQP-VK.graphicsfuzz.cov-fold-negate-min-int-value`:

`negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself`

SPIR-V spec states that OpSNegate(0x80000000) has to return 0x80000000;
in our case, -2147483648 should be -2147483648.

While this is not causing any issue because compilers seem to be
behaving like that, it is still undefined behaviour, so it expects to be
this handled explicitly, which is the purpose of this commit.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29772>
2024-06-21 21:07:05 +00:00
Jesse Natalie
d9eacb05c9 nir_range_analysis: Use fmin/fmax to fix NAN handling
The following probable MSVC bug clued us in to some probably-unexpected behavior:
https://developercommunity.visualstudio.com/t/Incorrect-SSE-code-for-minmax-with-NaNs/10687862

Change the logic here so that we're always starting with NANs and use
fmin/fmax, which have more-deterministic handling of NANs. If one argument
is NAN, the non-NAN argument is returned. The previous code would've returned
the second argument if one was NAN.

Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29822>
2024-06-21 20:13:46 +00:00
Rhys Perry
21f8410191 vtn: ensure TCS control barriers have a large enough memory scope
A workgroup or larger scope is necessary for writes to be visible to other
invocations.

Fixes incorrect snow rendering in Indika.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11299
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29735>
2024-06-21 16:24:08 +00:00
Alyssa Rosenzweig
da752ed7c1 treewide: use nir_def_replace sometimes
Two Coccinelle patches here. Didn't catch nearly as much as I would've liked but
it's a start.

Coccinelle patch:

    @@
    expression intr, repl;
    @@

    -nir_def_rewrite_uses(&intr->def, repl);
    -nir_instr_remove(&intr->instr);
    +nir_def_replace(&intr->def, repl);

Coccinelle patch:

    @@
    identifier intr;
    expression instr, repl;
    @@

    nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
    ...
    -nir_def_rewrite_uses(&intr->def, repl);
    -nir_instr_remove(instr);
    +nir_def_replace(&intr->def, repl);

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Juan A. Suarez Romero <jasuarez@igalia.com> [broadcom]
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com> [lima]
Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com> [etna]
Reviewed-by: Pavel Ondračka <pavel.ondracka@gmail.com> [r300]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29817>
2024-06-21 15:36:56 +00:00
Alyssa Rosenzweig
bbdd34b4ad nir: add nir_def_replace helper
"Rewrite and remove" is a super common idiom in NIR passes. Let's add a helper
to make it more ergonomic.

More the point, I expect that /most/ of the time when a pass rewrites uses, they
also want to remove the parent instruction. The principle reason not to is
because it takes extra effort to add in the nir_instr_remove and nir_opt_dce
will clean up after you eventually, right? From a compile time perspective, it's
better to remove earlier to reduce the redundant processing between the pass and
the next DCE run. So ... we want to be doing *more* removes. From a UX
perspective - the way to nudge devs towards that is to make the
preferred "rewrite-and-remove" pattern more ergonomic than the "rewrite but
keep". That justifies the simple "replace" name rather than something silly like
"rewrite_uses_and_remove".

---

Something else I've wanted for a while.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29817>
2024-06-21 15:36:56 +00:00
Alyssa Rosenzweig
535823682d nir/format_convert: remove unorm bit size assert
Yes, we're losing precision if this assert fails and it's wrong. It's also
necessary to implement GL in a reasonable way on Asahi. Remove the assert that
was recently added and add more comment context on the mess.

Fixes debug build regression on asahi:

   dEQP-GLES3.functional.vertex_arrays.single_attribute.normalize.int.components4_quads1

Fixes: 22f1b04a99 ("nir/format_convert: Assert that UNORM formats are <= 16 bits")
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Suggested-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29820>
2024-06-21 14:50:59 +00:00
Dylan Baker
656b8bb340 compiler/glcpp: don't recalculate macro
The original code has a private helper called in one place doing a
lookup that it's parent has already done, which could be null, except
that the parent verified that it isn't. Instead, let's pass the pointer
from the parent and assert it's non-null in the child for good
measure/documentation.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29666>
2024-06-21 03:19:26 +00:00
Dylan Baker
e67a8dc59a clc: remove check for null pointer that cannot be true in llvm_mod_to_spirv
Snce the *args parameter was added it's assumed to be non-null. If it is
null then the function is going off to UB land. As such, a later check
added for args being NULL is useless, and confuses coverity.

fixes: 3a752256f5

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29664>
2024-06-21 00:41:28 +00:00
Erik Faye-Lund
a1c220fd93 nir: fix utf-8 encoding-issue
This UTF-8 encoding issue seems to cause issues with the doxygen
docs-integration.

Fixes: 2111551485 ("Convert a few files to UTF-8")
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29801>
2024-06-20 14:51:31 +00:00
Timothy Arceri
0ac0fbc19e glsl: make glsl_to_nir() more generic
Here we move anything that expects the IR to have already been linked
so that in a future patch we can use glsl_to_nir() to convert IR that
has only been compiled.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29761>
2024-06-20 00:56:10 +00:00
Faith Ekstrand
22f1b04a99 nir/format_convert: Assert that UNORM formats are <= 16 bits
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:23 +00:00
Faith Ekstrand
5f5f4474f6 nir: Add a format unpack helper and tests
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
faf4c2edfe nir: Add a format pack helper and tests
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
1ffb0c5af4 nir: Support 0 and 32 bits in some format conversion helpers
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
34161d3fda nir: Move most of nir_format_convert to a C file
There's no good reason for this to be header-only besides laziness on my
part when I first wrote a few "small" helpers.  Some of those are pretty
good sized and don't need to be inlined.

Keeping the original copyright since this is just moving code.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
9d3b144018 nir: Add a nir_intrinsic_use for unit tests
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
5b9ac9a68f nir/format_convert: Use fmin/fmax to clamp R9G9B9E5 data
As long as drivers implement an fmin/fmax that do the right thing with
NaN, there's no reason for the integer comparison.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Faith Ekstrand
86aad90e2a nir/format_convert: Smash NaN to 0 in pack_r9g9b9e5()
I have no idea why I flipped the order of these to checks vs. the C
code when I wrote the NIR helper.  We need to deal with NaN first or
else the fmin will smash NaN to MAX_RGB9E5 and it won't get handled as
NaN.

Fixes: 9981709d8f ("nir/format_convert: Add a function to pack RGB9_E5 formats")
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28793>
2024-06-19 01:56:22 +00:00
Adam Jackson
10d21d4100 mesa: Enable EXT_shadow_samplers for GLES2
I thought this was just the funny GLES spelling of the extn name, but
there's also some ESSL bits you need to add. Most of which you could
probably yoink from the old Unity glsl-optimizer (which itself yoinked
most of the GLSL compiler from Mesa):

94a9b2959b

Signed-off-by: Adam Jackson <ajax@redhat.com>
Co-authored-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6691>
2024-06-18 14:40:33 +00:00
Timothy Arceri
ef21df917f glsl: remove do_function_inlining()
This no longer has any users. nir based inlining should be used for any
new code.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29519>
2024-06-18 12:34:52 +00:00
Timothy Arceri
f1ef6517e8 glsl: remove Par-linking from the standalone linker
lima was the last user of this feature so lets remove it. This will
allow us to drop more soon to be unused glsl ir code once full nir
linker support lands.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29519>
2024-06-18 12:34:52 +00:00
Timothy Arceri
7df492923a glsl: drop dump-builder support from standalone compiler
The support is incomplete and largely untested, but more importantly
glsl ir is depreciated at this point. This feature was added to support
building additional passes but that shouldn't ever be needed from here
on.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29469>
2024-06-18 08:12:45 +00:00
Marek Olšák
75777f1dc8 nir: add a NIR option flag nir_io_prefer_scalar_fs_inputs
It's a NIR option because passing flags from radeonsi to the GLSL linker is
complicated.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29406>
2024-06-17 23:48:35 +00:00
Marek Olšák
3622092614 glsl/linker: vectorize lowered IO
Since we scalarize all IO for nir_opt_varyings, we should re-vectorize it.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29406>
2024-06-17 23:48:35 +00:00
Marek Olšák
2514999c9c nir: add nir_opt_vectorize_io, vectorizing lowered IO
Since nir_opt_varyings requires scalar IO and thus all drivers have to
scalarize it, this gives the option to re-vectorize IO after that.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29406>
2024-06-17 23:48:35 +00:00
Marek Olšák
0058989357 nir/lower_io_to_scalar: don't create output stores that have no effect
This fixes NIR validation errors that happen with certain shaders.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29406>
2024-06-17 23:48:35 +00:00