mesa/src/compiler
Alyssa Rosenzweig b3da29ae58 nir/opt_preamble: Respect ACCESS_CAN_SPECULATE
In general, it is unsafe to speculatively hoist conditionally executed loads
into the preamble. For example, if the shader does:

   if (ptr is valid) {
      foo(*ptr)
   }

we cannot dereference ptr in the preamble without knowing that the pointer is
valid (which may not be determinable, since it might not be uniform).
nir_opt_preamble needs to stop speculating in this case, or otherwise using
preambles can cause faults on legal shaders.

However, some platforms may be able to speculate loads safely. For example,
Apple hardware is able to suppress MMU faults, making speculation safe.  This is
controlled global register to control this behaviour, set at boot-time by the
kernel.  (macOS suppresses these faults unconditionally, this feature may be
used in their implementation of sparse textures. Currently Linux does not
suppress any faults but this may change later.)

Since nir_opt_preamble should work soundly and optimally on a variety of
platforms, we need to respect the ACCESS flag.

Thanks to the if-else hoisting implemented earlier in the series, this isn't too
terrible of a band-aid on Asahi:

    total instructions in shared programs: 1499674 -> 1507699 (0.54%)
    instructions in affected programs: 78865 -> 86890 (10.18%)
    helped: 0
    HURT: 337
    Instructions are HURT.

    total bytes in shared programs: 10238284 -> 10279308 (0.40%)
    bytes in affected programs: 554504 -> 595528 (7.40%)
    helped: 3
    HURT: 334
    Bytes are HURT.

    total halfregs in shared programs: 452049 -> 454015 (0.43%)
    halfregs in affected programs: 7569 -> 9535 (25.97%)
    helped: 7
    HURT: 150
    Halfregs are HURT.

There are no shader-db changes on ir3 as expected, since ir3 can safely
speculate all instructions in my shader-db.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24011>
2023-10-10 13:51:00 +00:00
..
clc meson: Remove unnecessary inc_compiler mentions 2023-09-22 14:52:50 +00:00
glsl glsl: remove now unused varying linker code 2023-09-28 13:55:16 +00:00
isaspec isaspec: Add BitSetEnumValue object 2023-10-03 12:07:04 +00:00
nir nir/opt_preamble: Respect ACCESS_CAN_SPECULATE 2023-10-10 13:51:00 +00:00
spirv spirv: Track when a shader has a cooperative matrix 2023-09-28 07:35:02 +00:00
builtin_types.py compiler/types: Use Python to generate code for builtin types 2023-09-16 15:17:01 +00:00
builtin_types_c.py compiler/types: Use a string table for builtin type names 2023-09-16 15:17:01 +00:00
builtin_types_cpp_h.py compiler/types: Use Python to generate code for builtin types 2023-09-16 15:17:01 +00:00
builtin_types_h.py compiler/types: Use Python to generate code for builtin types 2023-09-16 15:17:01 +00:00
glsl_types.cpp compiler/types: Flip wrapping of convenience accessors for vector types 2023-10-07 00:42:54 +00:00
glsl_types.h compiler/types: Flip wrapping of basic "get type" functions 2023-10-07 00:42:55 +00:00
glsl_types_impl.h compiler/types: Flip wrapping of convenience accessors for vector types 2023-10-07 00:42:54 +00:00
meson.build compiler/types: Move the C++ inline functions in glsl_type out of the struct body 2023-10-07 00:42:54 +00:00
nir_gl_types.h mesa: #include "util/glheader.h" instead GL/gl.h in shared code 2022-11-03 16:07:31 +00:00
nir_types.cpp compiler/types: Flip wrapping of basic "get type" functions 2023-10-07 00:42:55 +00:00
nir_types.h compiler/types: Move C declarations into glsl_types.h 2023-10-07 00:42:54 +00:00
shader_enums.c nir: Add shader enqueue data structures and handling 2023-08-18 16:57:22 +00:00
shader_enums.h nir: Add ACCESS_CAN_SPECULATE 2023-10-10 13:51:00 +00:00
shader_info.h nir: gather dual slot input information 2023-10-07 11:18:40 +00:00