Commit graph

317 commits

Author SHA1 Message Date
Timothy Arceri
8142797721 glsl: move _mesa_glsl_compile_shader() declaration
The function is in glsl_parser_extras.cpp so move the declaration to
glsl_parser_extras.h

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32402>
2024-11-29 14:30:03 +11:00
Timothy Arceri
7469f99ea1 glsl: remove more now unused params from glsl_to_nir()
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32239>
2024-11-21 03:21:08 +00:00
Timothy Arceri
44de5f1c46 Revert "glsl: Move ForceGLSLAbsSqrt handling to glsl-to-nir."
This reverts commit 46bf687882.

We wont be removing this lowering file and having this workaround in
glsl_to_nir() creates a dependency on the const values that we could
otherwise avoid, so lets just move this back. Dropping the consts
will be useful in a follow up series that aims to drop all the glsl
ir function inlining code by converting builtin functions to nir.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32239>
2024-11-21 03:21:08 +00:00
Timothy Arceri
10c292acf6 glsl: remove unused member
Unused since 063d62f142

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32239>
2024-11-21 03:21:08 +00:00
Timothy Arceri
8ac81c5bb4 glsl: tidy up glsl_to_nir() params
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32239>
2024-11-21 03:21:08 +00:00
Alyssa Rosenzweig
3da8444be5 nir: add names to function parameters
SPIR-V has this information. We should try to preserve it.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32208>
2024-11-20 16:53:51 +00:00
Timothy Arceri
e34357015c glsl: fix compiler global temp collisions
glsl ir creates these temps to copy global initialiser values for
example. To avoid collisions during linking due to 2 shaders in the same
stage having temps with the same name we make sure to define these as
function variables not shader globals. This will put the temps into the
global instructions wrapper created in 7c5b21c032.

Fixes: cbfc225e2b ("glsl: switch to a full nir based linker")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12136

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32202>
2024-11-20 03:20:47 +00:00
Timothy Arceri
cbfc225e2b glsl: switch to a full nir based linker
This commit does 3 things at once (3 squashed commits) as required
to make sure the commit doesn't break things.

1. convert to nir at compile time
2. enable full nir linking
3. switch standalone compiler to nir linker

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:44 +00:00
Timothy Arceri
6bb6b0e5ad nir: add nir_intrinsic_deref_implicit_array_length intrinsic
This will be used to handle .length() calls on unsized arrays

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:44 +00:00
Timothy Arceri
60937b5286 nir: add implicit_conversion_prohibited field to nir_parameter
Will be used in link time validation in following patches.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:44 +00:00
Timothy Arceri
5645495156 nir: store variable mode in nir_parameter
This will be used by the nir glsl linker in following patches.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:44 +00:00
Timothy Arceri
7a1061e0dd nir: add max_ifc_array_access field to vars
This will be used in following patches by the nir based glsl
linker code.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:43 +00:00
Timothy Arceri
7c5b21c032 glsl: add support for converting global instructions to NIR
NIR doesn't really support global instructions such as global val
initilisation. So here we add functionality to glsl_to_nir() to
put these instructions into a temporary function that will be
later inlined into main.

We give the function a name starting with gl_mesa_tmp_ as functions
starting with gl_ are reserved and will not have any clashes with
user functions, we finish the name with the blake3 of the shader
source to avoid conflicts with multiple shaders attached to a single
stage.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31137>
2024-09-25 09:39:43 +00:00
Dylan Baker
99f1b7d732 compiler/glsl: explicitly delete copy constructor and copy-assign
Most of our visitors have custom destructors because they wrap C types,
and need to manually call destructors for those types. Because of this,
the implicitly generated copy constructors and copy-assignment operators
are not safe due copying pointers rather than data. Since we don't need
these features just delete them, so any attempt to use them would be a
compilation error. This doesn't fix any existing issue except stopping
coverity from complaining, but it does prevent new issues in the future.

Acked-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29662>
2024-09-16 21:08:04 +00:00
Qiang Yu
40fdd97de3 glsl: set shader_info.subgroup_size for KHR_shader_subgroup
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:20 +08:00
Qiang Yu
7538edf706 glsl: add KHR_shader_subgroup_quad builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:19 +08:00
Qiang Yu
72517a8be9 glsl: add KHR_shader_subgroup_clustered builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:19 +08:00
Qiang Yu
db41c09e17 glsl: add KHR_shader_subgroup_arithmetic builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:19 +08:00
Qiang Yu
ac0bbb5b3f glsl: add KHR_shader_subgroup_shuffle_relative builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:19 +08:00
Qiang Yu
eee3091e3e glsl: add KHR_shader_subgroup_shuffle builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:19 +08:00
Qiang Yu
a496d84ac8 glsl: add KHR_shader_subgroup_ballot builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:18 +08:00
Qiang Yu
5f212a190b glsl: add KHR_shader_subgroup_vote builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:18 +08:00
Qiang Yu
f0c8520a90 glsl: add KHR_shader_subgroup_basic builtin functions
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:18 +08:00
Qiang Yu
6ae013a032 glsl: use generic convertion code for some intrinsics
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30610>
2024-08-26 10:46:18 +08:00
Timothy Arceri
d681cf96fb nir/glsl: set deref cast mode during function inlining
See code comment for details.

Issue: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11535
Fixes: c6c150b4cd ("glsl_to_nir: support conversion of opaque function params")

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30338>
2024-08-19 23:54:49 +00:00
Alyssa Rosenzweig
530498cb83 treewide: use new-style derivative builders
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30565>
2024-08-08 15:26:07 +00:00
Timothy Arceri
140ca7e5d7 glsl: fix glsl to nir support for lower precision builtins
When we switch to the full nir based glsl linker in an upcomming merge
request this is required for existing tests from 8fcf8e7fd4 to
continue to pass, this is because they never exercised glsl to nir so
the missing support went unnoticed.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11456
Fixes: 8fcf8e7fd4 ("glsl: lower builtins to mediump that ignore precision of certain parameters ")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30395>
2024-08-05 22:59:59 +00:00
Timothy Arceri
a629d829dc glsl: make use of new tex src deref intrinsic
The bindless spec has no language requiring functions params to be
defined as bindless so we need to be able to look at the values being
passed to functions to decide if they are bindless or not. This
intrinsic allows us to wait until function inlining is complete to make
this assessment.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11535
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30315>
2024-07-29 00:06:10 +00:00
Timothy Arceri
355a1f2058 glsl: remove out of date comment
GLSL 4.40 changed the relevant language in Section 8.13.2 (Interpolation
Functions) to:

   "Component selection operators (e.g., .xy) may be used when specifying
    interpolant."

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30239>
2024-07-19 10:59:11 +00:00
Timothy Arceri
063d62f142 glsl: move call to create explicit ifc layout out of glsl_to_nir
We move this later so that we can call glsl_to_nir() on glsl ir that
has not set the array size on unsized ifc members. Later patches will
move sizing of the arrays out of glsl ir and into the nir linker.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29991>
2024-07-03 01:20:02 +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
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
Timothy Arceri
fe2e60a4d3 glsl: add some data members to nir_variable
These will be used in the following patch.

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/28690>
2024-04-12 12:15:48 +10:00
Timothy Arceri
baf13bff29 nir: add subroutine fields to nir_function
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
2024-04-06 05:56:04 +00:00
Timothy Arceri
c46827d52a nir: add variable field from_ssbo_unsized_array
This will be used for validation in following patches

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
2024-04-06 05:56:03 +00:00
Timothy Arceri
a18e06f694 nir: add implicit_sized_array data field
Will be used in following patches for glsl linking validation.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
2024-04-06 05:56:03 +00:00
Timothy Arceri
f24e6a5062 nir: add max_array_access data field
Will be used in following patches for glsl linking validation.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
2024-04-06 05:56:03 +00:00
Timothy Arceri
1391bc3721 glsl_to_nir: never convert instructions after jump
Unlike in GLSL IR it is illegal to add an instruction to a block
following a jump in NIR. Here we add code to the glsl_to_ir pass
to remove any such instructions before they are processed i.e.
we remove them as soon as we process the jumps.

Handling this in glsl to nir allows us to avoid depending on the
lower_jumps() pass being called directly before glsl to nir when
it otherwise doesn't need to be called an additional time.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27288>
2024-03-12 01:43:03 +00:00
Timothy Arceri
38eb850883 glsl: move function inlining out of glsl_to_nir()
This will allow us to do more of the function linking work in nir
in the future.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27841>
2024-03-04 05:40:55 +00:00
Timothy Arceri
edf242f825 nir: add some nir_parameter fields
These will be used in future to do more validation on functions as
the glsl nir linker is expanded. The first use is in the following
patch.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27841>
2024-03-04 05:40:55 +00:00
Timothy Arceri
c6c150b4cd glsl_to_nir: support conversion of opaque function params
Here we can assume anything that is not an input is bindless.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27108>
2024-03-04 11:31:21 +11:00
Timothy Arceri
de7574f70a glsl_to_nir: support conversion of struct/array function returns
This adds support for array and struct function returns in the glsl
to nir pass allowing us to avoid extra calls to the glsl IR
optimisation loop.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27108>
2024-03-04 11:31:20 +11:00
Timothy Arceri
fac9b1c594 glsl_to_nir: support conversion of struct/array function params
This adds support for array and struct function params in the glsl
to nir pass allowing us to avoid extra calls to the glsl IR
optimisation loop.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27108>
2024-03-04 11:31:20 +11:00
Timothy Arceri
7afce96b80 glsl_to_nir: merge function param handling
Here we remove the special handling for input params that was hard
to work with and unite it with the output and inout params.

Here a mediump test needs to be updated to what is a more expected
outcome anyway.

We also need to update the code that inserts software f64 to the
new way input params are handled.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27108>
2024-03-04 11:31:20 +11:00
Timothy Arceri
b2a7717717 glsl: add explicit half float conversion support
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18540>
2024-02-12 13:23:13 +00:00
Alyssa Rosenzweig
854b6020bd glsl: don't use NIR_PASS_V
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26976>
2024-01-12 01:13:02 +00:00
Caio Oliveira
d06f0305f6 glsl: Use glsl_type C helpers
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26707>
2023-12-22 06:51:01 -08:00
Timothy Arceri
52dbf44d2e glsl: add support for inout params to glsl_to_nir()
Supporting these means we don't have to depend on calling the GLSL
IR optimisation loop for shaders that contain these parameter types.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26755>
2023-12-20 01:47:27 +00:00
Timothy Arceri
3d3ba9f428 glsl: move glsl ir lowering out of glsl_to_nir()
The main motivation for doing this is that some tests and even the
st tracker linking code dump out the GLSL IR for debugging before
glsl_to_nir() is called expecting it to already be in its final
form. Moving these to the linker makes those assumptions true.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26755>
2023-12-20 01:47:27 +00:00