Commit Graph

73 Commits

Author SHA1 Message Date
Jesse Natalie 01ccba0d8e microsoft/compiler: Don't split loads/stores that will be split by lower_explicit_io
Otherwise we can end up splitting push constant loads, which currently require
an unbroken (no-cast) deref chain up to the variable.

Fixes: 4c527f4f ("spirv2dxil: Lower unaligned loads and stores")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22371>
2023-04-10 18:43:12 +00:00
Jesse Natalie 4f56cede6d microsoft/compiler: Assign 1D wave IDs based on local thread ID
Fixes corruption/flickering seen in DOOM Eternal's decals/lighting.
It seems the shader has an implicit assumption about this property.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22225>
2023-04-06 22:08:28 +00:00
Jesse Natalie eeb67362da microsoft/compiler: Fix barrier for wave ID computation
Fixes: 2f8a8b59 ("microsoft/compiler: Add lowering passes for basic subgroup vars")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22225>
2023-04-06 22:08:28 +00:00
Jesse Natalie 477332a347 microsoft/compiler: Fix 8-bit loads and stores when supporting 16-bit DXIL
Shifts should always use 32bit shift values, and when lowering to
masked, we need to use 32-bit atomics. That means that we should also
treat 24bit stores as a single masked op rather than one 16bit unmasked
and one 8bit masked.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22225>
2023-04-06 22:08:28 +00:00
Jesse Natalie b723962418 d3d12: Move forward-front-face pass to common DXIL code
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22277>
2023-04-04 21:48:19 +00:00
Jesse Natalie ccc9540dae microsoft/compiler: Add a lowering pass for scan ops that aren't supported
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21996>
2023-03-18 02:33:42 +00:00
Jesse Natalie 58e7acb0e2 microsoft/compiler: Support lowering SSBO accesses to 16bit vectors
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie 196dc72838 microsoft/compiler: Handle 48-bit stores to SSBO/shared
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie c994c8b3fd microsoft/compiler: Pass an alignment to constant buffer load lowering
This means we can stop doing conditionals and shifts if we know the
alignment of a load for a small amount of data.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie 7fcb60be37 microsoft/compiler: Simplify bitpacking for load/store lowering with nir_extract_bits
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie 7830901751 microsoft/compiler: Pass deref modes to unaligned pass and handle push const
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie facd2e4fdb microsoft/compiler: Move unaligned load/store pass from CL
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21029>
2023-02-11 06:12:23 +00:00
Jesse Natalie 2f8a8b5949 microsoft/compiler: Add lowering passes for basic subgroup vars
DXIL doesn't have a "subgroup ID" or "num subgroups" construct,
so add lowering to construct them. Subgroup ID is done using
once-per-subgroup atomics on a workgroup-shared variable, and
then broadcasting that (using read_first_invocation) to the other
threads. Num subgroups is just a division with the workgroup size.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20777>
2023-01-20 18:50:57 +00:00
Jesse Natalie 58488b9d85 microsoft/compiler: Support view instancing
This adds support for D3D12-native view instancing to the compiler.
Essentially, it's just the ability to load SV_ViewID (dx.op.viewID),
set the right capability, and fill out some more PSV data. Note that
the PSV data is currently garbage. Ideally, we'd fill out a proper
input -> output and viewID -> output dependency table, but AFAIK
this is only used to enforce D3D API validation, and drivers ignore
it, so it's less critical to get it right.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20650>
2023-01-19 21:14:50 +00:00
Jesse Natalie 85f44304d8 microsoft/compiler: Set num_components to 4 when updating pos write instructions
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20614>
2023-01-17 12:47:16 +00:00
Jesse Natalie 638e375c19 microsoft/compiler: Sort all user varyings before any sysvals
User varyings are linked by both name and register. The name is based
on how many *variables* are before it in final driver_location sort
order, not necessarily how many registers are before it.

In some cases where clip/cull distance are involved, it's possible
for one shader to write into a part of the cull distance that's
ignored by a downstream shader, but because linking is done by
*whole* register locations, and clip/cull can be combined using
*fractional* register locations, this is hard to detect. Since no
non-sysvals end up using fractional locations, just put all non-sysvals
first so they always generate the same semantic names for the same
register locations.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20346>
2022-12-16 18:40:47 +00:00
Jesse Natalie 8c1af8854b microsoft/compiler: Make nir_var_to_dxil_sysvalue_type static
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20346>
2022-12-16 18:40:47 +00:00
Jesse Natalie f363504b42 microsoft/compiler: Handle both input and output clip/cull distances
For clip/cull coming into a GS and being written, this pass was wrong
and would modify variable types incorrectly. Track both inputs and
outputs separately.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20346>
2022-12-16 18:40:47 +00:00
Ian Romanick e34b8866b4 microsoft/compiler: Use nir_type_convert instead of nir_type_conversion_op
In a future commit, nit_type_conversion_op won't be able to handle i2b
(and in a much later commit f2b), so switch many users to the fully
featured function.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
2022-12-14 06:23:21 +00:00
Ian Romanick 1fae751d49 microsoft/compiler: Simplify nir_intrinsic_load_front_face handling
It is invalid to have Boolean variables as either shader inputs or
outputs, so there is no point to try to lower them in general.  The only
use for this was some two-phase lowering of
nir_intrinsic_load_front_face that could be done in a single phase.
Create the SYSTEM_VALUE_FRONT_FACE as a uint and compare it with zero at
the same time.

No shader-db or fossil-db changes on any Intel platform.

v2: Remove dxil_nir_lower_bool_input from dxil_nir.h and drop it from
the other caller in the spirv_to_dxil codepath.  Noticed by Jesse.  Fix
setting bit size when loading SYSTEM_VALUE_FRONT_FACE.  Caught by CI.

v3: Use nir_ine_imm.  Change type of gl_FrontFacing GS output in
d3d12_nir_passes from Boolean to integer.  Both suggested by Jesse.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
2022-12-14 06:23:21 +00:00
Ian Romanick 7a5e9df39d nir: Use nir_i2b wrapper everywhere instead of using nir_i2b1 directly
No shader-db or fossil-db changes on any Intel platform.

v2: Add missed i2b1 in ir3_nir_opt_preamble.c.

v3: Add missed i2b1 in ac_nir_lower_ngg.c.

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
2022-12-14 06:23:21 +00:00
Jesse Natalie 72d66aa987 microsoft/compiler: Delete now-unused memcpy lowering pass
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19752>
2022-11-15 18:29:26 +00:00
Jesse Natalie 1399f37a3b d3d12: Move lower_sample_pos to microsoft/compiler
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19471>
2022-11-04 01:40:17 +00:00
Jesse Natalie 80d35739ff microsoft/compiler: Ensure 4-component position writes via NIR
We're about to lower I/O to scalar, which means we'll end up with
multiple writes to position, and none of them has enough info to
fill in the blanks.

This causes a test that previously crashed on WARP (due to
StoreOutput with an undef not being handled) to fail more
gracefully - but that failure means that the test spends
forever just outputting errors, so explicitly skip it.

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17603>
2022-07-23 14:48:17 +00:00
Enrico Galli 1f0d27e45f microsoft/spirv_to_dxil: Fix discard to demote + return pass
While SPIR-V's OpKill is block terminating, the converted discard
intrinsic is not block terminating. This can lead to issues where
instruction could be placed after discard.

This patch adds an extra pass that drops all instructions after discard
before we convert discards.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17474>
2022-07-12 20:22:52 +00:00
Enrico Galli f367c55573 microsoft/spirv_to_dxil: Fix discard semantics
Unlike in nir, discard is not a super return in DXIL. Therefore, we
will lower discard and terminate to demote + return.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17179>
2022-06-23 22:04:32 +00:00
Vinson Lee 081b1eeacd microsoft/compiler: Fix assert.
Fix defect reported by Coverity Scan.

Side effect in assertion (ASSERT_SIDE_EFFECT)
assignment_where_comparison_intended: Assignment var->type =
glsl_int_type() has a side effect. This code will work differently in a
non-debug build.

Fixes: afb64e10c1 ("microsoft/compiler: Move d3d12_fix_io_uint_type() to dxil_nir.c")
Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17097>
2022-06-21 06:54:18 +00:00
Boris Brezillon afb64e10c1 microsoft/compiler: Move d3d12_fix_io_uint_type() to dxil_nir.c
We currently have two implementations of the same logic. Let's pick
the d3d12 one, move it to dxil_nir.c and let nir_to_dxil() call it
when appropriate.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17039>
2022-06-15 22:04:00 +00:00
Boris Brezillon b12417a2c7 microsoft/compiler: Lower fquantize2f16
As far as I can't tell, there's no native operation doing this
equivalent of fquantize2f16. Let's lower this operation to

   if (val < MIN_FLOAT16)
      return -INFINITY;
   else if (val > MAX_FLOAT16)
      return -INFINITY;
   else if (fabs(val) < SMALLER_NORMALIZED_FLOAT16)
      return 0;
   else
      return val;

which matches the definition of OpQuantizeToF16:

"
If Value is an infinity, the result is the same infinity.
If Value is a NaN, the result is a NaN, but not necessarily the same NaN.
If Value is positive with a magnitude too large to represent as a 16-bit
floating-point value, the result is positive infinity. If Value is negative
with a magnitude too large to represent as a 16-bit floating-point value,
the result is negative infinity. If the magnitude of Value is too small to
represent as a normalized 16-bit floating-point value, the result may be
either +0 or -0.
"

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16959>
2022-06-10 07:45:05 +00:00
Jesse Natalie a56d47b0ba microsoft/compiler: Fixup sampler derefs in tex instrs that don't *need* samplers
Sometimes you can end up with tex instructions that have sampler deref srcs, even though
they don't need them, e.g. a txs. In this case, still fix up those derefs in the sampler
splitting pass rather than leaving them pointing to a typed sampler.

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16639>
2022-05-30 07:28:50 +00:00
Erik Faye-Lund 41fcffeda0 microsoft/compiler: fixup indentation
Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16079>
2022-04-29 07:08:57 +00:00
Enrico Galli 0c4d1762de microsoft/compiler: Fix when using a shadow sampler more than once
Reusing the shadow sampler's variable causes problems when the sampler
is used more than once. The remaining `deref_var`s will be using the
wrong type.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14988>
2022-04-15 00:19:55 +00:00
Enrico Galli 0badd0547d microsoft/spirv_to_dxil: Add pass to lower dynamic accesses on ubo[1]
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14988>
2022-04-15 00:19:55 +00:00
Jesse Natalie 4c8935d325 microsoft/compiler: Fix dxil_nir_lower_double_math_instr pass for vectors
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Reviewed-By: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14837>
2022-02-04 00:07:53 +00:00
Jesse Natalie 36add3d002 microsoft/compiler: Support multiple GS output streams
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14787>
2022-01-31 13:34:27 -08:00
Boris Brezillon 951fd35012 microsoft/compiler: Skip images in redirect_texture_derefs()
The input attachment lowering pass turns input attachment loads into
texel fetch operation, and insert an image -> texture deref cast along
the way. In this situation, we can end up with a texture deref chain
pointing to an image variable, which is not a combined sampler+texture
object. Bail out when an image type is found, like we do for bare
textures.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13993>
2022-01-31 16:37:47 +00:00
Jesse Natalie 973bff335f microsoft/compiler: Handle clip/cull distance as an input to tess shaders
In order to get the semantics right, we need to know how many of the clip/
cull fields are designated for which purpose. In the case of a shader that
can receive these fields as both input and output, the shader_info property
is reserved to store the output info. We could add a dedicated input field
to shader_info, but since it'd probably only be useful for us, just send
it through a side channel during shader linking.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14399>
2022-01-26 01:31:35 +00:00
Jesse Natalie 1c4667bc9f microsoft/compiler: Location_frac needs to be included in sort order
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14399>
2022-01-26 01:31:35 +00:00
Jesse Natalie 8e42891f69 microsoft/compiler: When sorting patch varyings, adjust location to be in normal varying range
This way, patch varyings come before the patch sysvals (tess levels).

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14399>
2022-01-26 01:31:35 +00:00
Jesse Natalie 4bb4d0454d microsoft/compiler: Overlap patch and non-patch varyings so both are separately 0-indexed
Also add tess factors to the list of sysvals that can cause vars to be sorted last.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14399>
2022-01-26 01:31:35 +00:00
Jesse Natalie fd50ef046b microsoft/compiler: Move workgroup_size lowering from clc
It doesn't depend on the clc data being provided externally, so no
need to tie it there, we can re-use it for GL and Vulkan compute.

Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14367>
2022-01-11 01:36:56 +00:00
Jesse Natalie c375b05bfe microsoft/compiler: Handle write masks in SSBO lowering pass
Previously, the lowering was for 8/16/64-bit values, or 8/16-component
vectors. Now, it also handles write masks on 32-bit 1/2/3/4-component
vectors.

DXIL looks like it supports putting an interesting write mask in the
buffer store intrinsic, but DXC never generates stores with write
masks, and multiple drivers completely ignore the write mask.

Also, set the write mask properly on the output intrinsic.

Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14294>
2021-12-27 23:40:24 +00:00
Thomas H.P. Andersen e0ec818cfd microsoft/compiler: dxil_nir_opt_alu_deref_srcs: return progress
dxil_nir_opt_alu_deref_srcs will always return false because
the progress variable is declared both for the function and also
inside the loop.

Spotted by a unused-but-set-variable warning from clang

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14290>
2021-12-23 01:52:13 +00:00
Jesse Natalie 64991d44a8 microsoft/compiler: Load synthesized sysvals via lowered io
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14175>
2021-12-20 08:20:59 -08:00
Boris Brezillon 83280b8e23 microsoft/compiler: Fix dxil_nir_create_bare_samplers()
_mesa_hash_table_u64_search() returns the data directly, not an
hash_entry object. We also need to take the descriptor set into account
for this pass to work properly on Vulkan shaders.

Fixes: 46bc7cf678 ("microsoft/compiler: Rewrite sampler splitting pass to be smarter and handle derefs")
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13912>
2021-12-01 08:51:05 +01:00
Jesse Natalie 8d3a3e7a00 microsoft/compiler: Use textures for SRVs
After running the (renamed) dxil_nir_split_typed_samplers pass, the
shader will have either:
* Textures, which map to D3D SRVs
* Bare samplers, which map to D3D bare samplers
* Images, which map to D3D UAVs

There shouldn't be any remaining samplers with type information

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13390>
2021-11-02 11:02:22 -07:00
Enrico Galli aac47c4b24 microsoft/compiler: Shadow tex instructions always use shadow samplers
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13321>
2021-10-16 00:12:04 +00:00
Michael Tang 36aa1a2959 gallium/d3d12: move d3d12_lower_bool_input to microsoft/compiler
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13262>
2021-10-08 17:21:33 +00:00
Emma Anholt 673cc9323a nir: Move phi src setup to a helper.
Cleans up the ralloc/list push code all over the tree.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11772>
2021-08-13 16:11:57 +00:00
Marcin Ślusarz 65f9234f96 microsoft/compiler: use nir_shader_instructions_pass in dxil_nir_lower_double_math
No functional changes.

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12324>
2021-08-11 11:23:30 +00:00