Commit Graph

53 Commits

Author SHA1 Message Date
Jesse Natalie 6af22121cf microsoft/compiler: Add a max validator version
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17603>
2022-07-23 14:48:17 +00:00
Jesse Natalie c8f63e07da microsoft/compiler: Add a max shader model option
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17603>
2022-07-23 14:48:17 +00:00
Yonggang Luo beaaa84cea dxil: Fixes warning about comparing different enum value and enum literal
warnings:
../../src/microsoft/spirv_to_dxil/spirv_to_dxil.c: In function 'spirv_to_dxil':
../../src/microsoft/spirv_to_dxil/spirv_to_dxil.c:101:14: warning: comparison between 'dxil_spirv_shader_stage' and 'enum <anonymous>' [-Wenum-compare]
  101 |    if (stage == MESA_SHADER_NONE || stage == MESA_SHADER_KERNEL)
      |              ^~
../../src/microsoft/spirv_to_dxil/spirv_to_dxil.c:101:43: warning: comparison between 'dxil_spirv_shader_stage' and 'enum <anonymous>' [-Wenum-compare]
  101 |    if (stage == MESA_SHADER_NONE || stage == MESA_SHADER_KERNEL)
      |                                           ^~

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16671>
2022-06-15 11:38:24 +00:00
Yonggang Luo 0d0283f698 dxil: Sync dxil_spirv_shader_stage with gl_shader_stage
Add STATIC_ASSERT to guard `dxil_spirv_shader_stage` and `gl_shader_stage`
to be same for each enum value.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16671>
2022-06-15 11:38:24 +00:00
Boris Brezillon 74c94faf32 microsoft/spirv_to_dxil: Let spirv_to_dxil() handle the linking
That's still a dummy linking we do here, and it's likely to be
incorrect for complex scenarios. Not sure the previous situation
was any better though, and at least, doing that allows us to
get rid of the special cases we have in dxil_signature.c.

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16221>
2022-06-08 15:17:05 +00:00
Boris Brezillon 45f8b2ee50 microsoft/compiler: Allow vulkan users to handle varyings linking
Letting the compiler decide which slot should be used for varyings when
it doesn't know about the varyings written/read by the previous/next
stage doesn't work well. So let's the caller decide when it wants
automatic index/register assignment through a dedicated parameter,
instead of assuming Vulkan users always want that.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16221>
2022-06-08 15:17:05 +00:00
Boris Brezillon c86ea7daa3 microsoft/spirv_to_dxil: Extract NIR passes out of spirv_to_dxil()
Extract NIR passes out of spirv_to_dxil() so we can re-use them
without separately and do the varying linking in Dozen. This way
we will also be able to use vk_shader_module_to_nir() which
takes care of the SPIRV -> NIR translation, plus a bunch of
common lowering passes.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16221>
2022-06-08 15:17:05 +00:00
Boris Brezillon 2feef505c1 microsoft/spirv_to_dxil: Fix the push_constant UBO size calculation
Right now, we just consider the size of the accessed portion of the
push constant array, but it doesn't necessarily reflect the size
of the UBO we should declare.

Fixes: de1e941c59 ("microsoft/spirv_to_dxil: Lower push constant loads to UBO loads")
Reviewed-by: Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16703>
2022-06-03 10:43:18 +00:00
Boris Brezillon 6783a88455 microsoft/spirv_to_dxil: Fix push_constants type declaration
We're not declaring an array of bytes but an array of uint32. Let's
fix the element_count we pass to glsl_array_type().

Fixes: de1e941c59 ("microsoft/spirv_to_dxil: Lower push constant loads to UBO loads")
Reviewed-by: Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16703>
2022-06-03 10:43:17 +00:00
Emma Anholt 536c8ee96d nir/lower_tex: Make the adding a 0 LOD to nir_op_tex in the VS optional.
This controls the whole lowering of "make tex ops with implicit
derivatives on non-implicit-derivative stages be tex ops with an explicit
lod of 0 instead", but it's really hard to describe that in a git commit
summary.

All existing callers get it added except:
- nir_to_tgsi which didn't want it.
- nouveau, which didn't want it (fixes regressions in shadowcube and
  shadow2darray with NIR, since the shading languages don't expose txl of
  those sampler types and thus it's not supported in HW)
- optional lowering passes in mesa/st (lower_rect, YUV lowering, etc)

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16156>
2022-04-28 21:26:08 +00:00
Boris Brezillon 7673697256 microsoft/spirv_to_dxil: Add a draw_id field to vertex_runtime_data
So we can support the draw_id system value.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15912>
2022-04-22 07:31:44 +00:00
Boris Brezillon 80a5deee62 microsoft/spirv_to_dxil: Allow forcing per-sample shading
Needed to support VkPipelineMultisampleStateCreateInfo::sampleShadingEnable.

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15916>
2022-04-19 08:49:50 +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
Enrico Galli 6635d011cb microsoft/spirv_to_dxil: Add missing ralloc_free
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Acked-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14766>
2022-03-25 16:21:45 +00:00
Boris Brezillon ef47a6800b microsoft/spirv_to_dxil: Make sure the SampleMask is a uint
DXIL doesn't like when SV_Coverage (AKA SampleMask in DXIL) is a
signed integer. Fix the type while we're in the NIR domain.

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/14765>
2022-01-31 20:21:25 +00:00
Boris Brezillon 7e56d8c393 microsoft/spirv_to_dxil: Lower atomics to their dxil variants
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/14765>
2022-01-31 20:21:25 +00:00
Boris Brezillon c2eeba04c3 microsoft/spirv_to_dxil: Discard PSIZ accesses
D3D12 doesn't support gl_PointSize, so let's consider PointSize is
always 1.0 and discard any PointSize access.

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/14765>
2022-01-31 20:21:25 +00:00
Louis-Francis Ratté-Boulianne 5cd2bf837d microsoft/spirv_to_dxil: Allow passing a vulkan -> d3d12 binding mapping table
Vulkan bindings take only one slot per variable, but d3d12 ones take one
slot per entry when the variable is an array. This forces us to pass
an explicit vulkan -> d3d12 mapping table when dealing with vulkan
shaders.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14765>
2022-01-31 20:21:25 +00:00
Louis-Francis Ratté-Boulianne de1e941c59 microsoft/spirv_to_dxil: Lower push constant loads to UBO loads
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14765>
2022-01-31 20:21:25 +00:00
Louis-Francis Ratté-Boulianne d11a417ded microsoft/spirv_to_dxil: lower input attachments
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14765>
2022-01-31 20:21:25 +00:00
Louis-Francis Ratté-Boulianne e65303c6e6 microsoft/spirv_to_dxil: check for variables r/w access
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14765>
2022-01-31 20:21:25 +00:00
Boris Brezillon 39592f8ad4 microsoft/spirv_to_dxil: Support [un]conditional YZ-flip
The unconditional Y-flip is needed for Vulkan 1.0 since D3D12 and
Vulkan coordinate systems differ. Conditional YZ-flip is needed if
we want to support negative viewport height/depth.

Prepare spirv_to_dxil() to support that, and while at it, prepare
things for multi-viewport: the Y/Z flips are per-viewport and encoded
in a 32bit bitmask, with the upper 16bits reserved for Z flips, and the
lower 16bits reserved for Y flips.

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/14765>
2022-01-31 20:21:25 +00:00
Boris Brezillon 225867684a microsoft/spirv_to_dxil: Allow dumping NIR
Dumping NIR shaders is a useful debug feature. Let's tweak the
spirv_to_nir() helper so we can pass debugging options and
add one to allow dumping NIR.

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/14765>
2022-01-31 20:21:25 +00:00
Boris Brezillon 27790c4a7a microsoft/spirv_to_dxil: Remove dead variables after the struct split pass
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/14765>
2022-01-31 20:21:25 +00:00
Jesse Natalie 8a4b443c5b microsoft/compiler: Change vulkan_environment bool to an enum
There are currently 3 different "environments" supported by this backend,
and they have slightly different semantics for how resources are accessed,
which is only going to get a little weirder when GL images start getting
supported. To try to make things less confusing, use an explicit enum
with heavy documentation on what's different between them.

Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14342>
2022-01-07 03:31:16 +00: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
Michael Tang 3094524621 microsoft/spirv_to_dxil: turn sysvals into input varyings
Fixes: b47090c5b3 ("spirv: Always declare FragCoord as a sysval")
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13276>
2021-10-26 16:18:09 +00:00
Michael Tang c0e45dd882 microsoft/spirv_to_dxil: use dxil_nir_lower_bool_input pass
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
Enrico Galli 398d591b65 spirv_to_dxil: Add support for non-zero vertex and instance indices
Since DXIL does not have a way to get the base/first vertex and base
instance as well as using a zero-based vertex index, these values need
to be passed in via a constant buffer.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12707>
2021-09-03 16:21:03 +00:00
Enrico Galli 49ef896a5e spirv_to_dxil: Add support for nir_intrinsic_load_num_workgroups
Since DXIL does not have a way to get the number of workgroups used
during dispatch with a system-value, these numbers need to be passed in
via a constant buffer.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12707>
2021-09-03 16:21:03 +00:00
Enrico Galli ada05759e1 spirv_to_dxil: Convert out parameters to a single object
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12707>
2021-09-03 16:21:03 +00:00
Michael Tang 4237aa3a7e spirv_to_dxil: Run nir_lower_tex during compilation
We need this to get e.g. a default lod for some instructions when it is
not provided.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12462>
2021-08-24 22:18:30 +00:00
Enrico Galli f9f3713c84 microsoft/spirv_to_dxil: Enable support for shared memory
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12228>
2021-08-05 23:54:26 +00:00
Michael Tang 92b0cf8e77 spirv_to_dxil: expose version number
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12227>
2021-08-05 13:30:42 -07:00
Enrico Galli 73262d4bd4 microsoft/spirv_to_dxil: Adding continue opt pass to fix DXIL loop gen
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12048>
2021-07-24 14:47:41 +00:00
Enrico Galli ddad83fc97 microsoft/compiler: Add support for get_ssbo_size to translator
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11629>
2021-06-29 23:15:28 +00:00
Enrico Galli d0cbd39a5c microsoft/spirv_to_dxil: Add drive_location assignment
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10989>
2021-06-24 20:05:13 +00:00
Jesse Natalie 46bc7cf678 microsoft/compiler: Rewrite sampler splitting pass to be smarter and handle derefs
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10298>
2021-04-27 23:13:19 +00:00
Enrico Galli 3a3ab2f8ee microsoft/compiler: zero out unused WebGPU system values
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10439>
2021-04-27 01:53:16 +00:00
Jesse Natalie 7e905bd00f microsoft/spirv_to_dxil: Treat read-only storage images as SRVs
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10356>
2021-04-23 23:16:15 +00:00
Jesse Natalie 53c97f92cd microsoft/compiler: For Vulkan environment, don't create resource handles upfront
Creating resource handles upfront works well while we have fixed-size resource
counts, but once we start talking about bindless, having arrays or even sets
of handles becomes prohibitive. It also precludes dynamic indexing for textures.

Instead, rely on the load_vulkan_descriptor instruction for UBO/SSBO, and undo
nir_lower_samplers so we continue to have deref chains for image/sampler accesses.
Then, emit handles at the end of a deref chain - the chain should only have
array offsets, so once we get to a type that's not an array anymore, we can
emit the handle.

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10288>
2021-04-22 02:43:30 +00:00
Jesse Natalie 0c8220685e microsoft/spirv_to_dxil: Lower loads/stores to DXIL
This adjusts UBO loads to be float4 loads, and handles SSBO accesses
that are larger/smaller than 32bit.

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10149>
2021-04-16 17:08:17 +00:00
Jesse Natalie 14997c7e96 microsoft/spirv_to_dxil: Lower samplers from deref to index
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10149>
2021-04-16 17:08:17 +00:00
Jesse Natalie ca08e74525 microsoft/spirv_to_dxil: Support doubles
First, we need to lower alu to scalar so that all alu ops on doubles
only take one input. Then, we can use our new double lowering pass.

Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Reviewed-by: Michael Tang <tangm@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10063>
2021-04-09 01:54:33 +00:00
Jesse Natalie 79bcefa8d9 microsoft/spirv_to_dxil: Lower io arrays
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Reviewed-by: Michael Tang <tangm@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10063>
2021-04-09 01:54:33 +00:00
Jesse Natalie cac3aedb0f microsoft/spirv_to_dxil: Lower globals to function_temp
Reviewed-by: Enrico Galli <enrico.galli@intel.com>
Reviewed-by: Michael Tang <tangm@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10063>
2021-04-09 01:54:33 +00:00
Enrico Galli 5756f2cd2c microsoft/spirv_to_dxil: Add support for load_vulkan_descriptor
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10064>
2021-04-07 23:50:39 +00:00
Jesse Natalie f447c69653 spirv_to_dxil: Handle clip/cull distance
Clip/cull only needs a little bit of lowering before nir_to_dxil can
handle it. Specifically, we just need to split apart arrays that
straddle the 4-component boundary of location, so that the signature
builder can handle it.

To do that cleanly, we need to add some lowering and optimization passes:
* nir_lower_clip_cull_distance_arrays: Merge clip/cull into a single array,
  which is similar to DXIL's requirements here.
* nir_lower_io_to_temporaries: Ensure that we only have one non-indirect write
  to the clip/cull output.
* nir_split_var_copies and nir_lower_var_copies: Ensure that each array entry
  has an independent write with a constant index
* Optimization loop: Make sure that there's no extra derefs in the way between
  deref_var for the output, deref_array for the component, and store_deref.
Then we can actually lower the clip/cull array cleanly.

Still to do is to sort the variables and add driver_location.

Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Reviewed-by: Michael Tang <tangm@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9846>
2021-04-02 17:16:48 +00:00
Jesse Natalie 39aa32b838 microsoft/spirv_to_dxil: Implement TODO for removing dead functions
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Reviewed-by: Michael Tang <tangm@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9846>
2021-04-02 17:16:48 +00:00
Michael Tang cb5120bcf7 microsoft/spirv_to_dxil: Add extra lowering functions according to the docs on nir_inline_functions
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9846>
2021-04-02 17:16:48 +00:00