Commit Graph

161 Commits

Author SHA1 Message Date
Emma Anholt f6c5b1d6c6 nir: Split usub_sat lowering flag from uadd_sat.
Intel vec4 would like to do uadd_sat, but use lowering for usub_sat.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17637>
2022-07-22 17:54:28 +00:00
Boris Brezillon e9c37e5ba8 microsoft/compiler: Fix emit_ubo_var()
get_dword_size() is misleading, its name implies it's returning
a size in dwords, but it's actually returning a size in bytes.
This led to a wrong size passed to emit_cbv(). Instead of fixing
get_dword_size(), let's inline the code in emit_ubo_var().

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17230>
2022-06-24 17:56:56 +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
Boris Brezillon e11035bf6d microsoft/compiler: Support gl_Layer
Maps pretty nicely to SV_RenderTargetArrayIndex, so nothing complicated
here.

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 9c45ee3f86 microsoft/compiler: Fix Layer type
DXIL wants a uint, but we get passed an int.

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 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 cd4bc4893b microsoft/compiler: Support load_sample_id_no_per_sample
It's like load_sample_id except it shouldn't force per-sample shading
when not already enabled. In that case, we simply return 0.

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/16926>
2022-06-14 22:44:42 +00:00
Boris Brezillon 65309dab45 microsoft/compiler: s/assert()/unreachable()/ in emit_intrinsic()
Use an unreachable() statement instead of the incorrect assertion in the
unsupported intrinsic path.

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/16926>
2022-06-14 22:44:42 +00:00
Boris Brezillon 82d3433d2a microsoft/compiler: Set typed_uav_load_additional_formats when appropriate
This flag should be set to true when the RWTexture is attached a vector,
and we always declare a vec4 right now, so it should always be true.
Might be worth reworking the dxil_module_get_res_type() to use a scalar
when the image only has one component.

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/16926>
2022-06-14 22:44:42 +00:00
Boris Brezillon 303175cfec microsoft/compiler: Images are no longer reprensented by uniform vars
emit_barrier_impl() was still checking the nir_var_uniform flag to
detect images, which is no longer correct.

Fixes: cfdc7ee066 ("spirv: Use nir_var_mem_image")
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/16926>
2022-06-14 22:44:42 +00:00
Boris Brezillon bd4c8f562c microsoft/compiler: Truncate function names when needed
DXIL metadata strings and function names have a limited size. Truncate
the name when they don't fit. This is a quick&dirty workaround since it
doesn't address the problem for all kind of strings, and doesn't ensure
there's no collision in the function names after the truncation. That's
not an issue right now because I don't think we have implementations
keeping more than one function (the entrypoint), but it might be a
problem at some point.

Acked-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16961>
2022-06-14 14:15:55 +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
Boris Brezillon 35dd4ac886 microsoft/compiler: Drop the auto_link parameter passed to nir_to_dxil()
Now that all nir_to_dxil() have transitioned to explicit linking, we
can drop the auto_link parameter and simplify the signature logic along
the way.

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 ca5520c3cb microsoft/compiler: Make sure all SV_Position components are written
Not entirely sure if writing to only some components of
gl_Position/SPIRV-PositionBuiltin from a vertex-processing stage is
allowed, but
https://github.com/dneto0/spirv-samples/blob/main/spvasm/SpvModuleScopeVarParserTest_BuiltinPosition_StorePositionMember_OneAccessChain.spvasm
does exactly that.

Let's make sure all SV_Position components are written, otherwise the
DXIL validator complains.

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
Timothy Arceri 2a2a2e58d1 d3d12: switch to NIR loop unrolling
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16543>
2022-05-17 02:12:21 +00:00
Boris Brezillon cacc3f03e6 microsoft/compiler: Add a dunmmy SV_SampleIndex when needed
When per-sample shading is forced and all input variables have a flat
interpolation, DXIL validation detects a mismatch between the
SampleFrequency property and the fact that no variables are per-sample
and SV_SampleIndex is never read. When that happens, add a dummy
SV_SampleIndex.

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 0e91dd2f3e microsoft/compiler: Add support for unnamed ubos
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/14988>
2022-04-15 00:19:55 +00:00
Enrico Galli 6073c74bfd microsoft/compiler: Fix for arrays of 1 element
The DXIL validator doesn't like dynamic indexing into resources if the
resource was not declared as an array type. This commit makes it so that
we always generate array resource types if the original type was
declared as an array instead, not just when the number of elements is
greater than 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
Erik Faye-Lund f7e92c8869 microsoft/compiler: remove phi-value limit
There's no guarantee that we don't have more than 128 PHI values either,
so let's stop asuming so.

We do this by changing dxil_phi_set_incoming to dxil_phi_add_incoming,
which lets us add more incoming phi-values to the current one instead of
setting a new set of them.

This also lets us reduce these stack-arrays a bit, down to something
much more reasonable.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15519>
2022-03-23 16:33:21 +00:00
Erik Faye-Lund d752c4bc7c microsoft/compiler: ralloc incoming phi-values
Reserving 127 incoming values for every phi instruction is neither
robust nor memory efficient.

Let's ralloc this array instead when filling it. This way, we only pay
for what we use here.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15519>
2022-03-23 16:33:21 +00:00
Jesse Natalie 918647000f microsoft/compiler: Set flag for VP/RT array index from VS/DS
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14881>
2022-02-04 20:49:23 +00:00
Jesse Natalie 5954c8e524 microsoft/compiler: Handle SV_ViewportArrayIndex
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14881>
2022-02-04 20:49:23 +00:00
Jesse Natalie eb0cefae6d microsoft/compiler: Map I/O base locations to input IDs
When dealing with a vertex input that takes multiple rows, the value of
nir_intrinsic_base points to a driver-location-based index, but we need
to emit a location-based index (or more specifically, an index that
increments once per input, not once per register). Add a mapping to
the module of base -> ID.

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 efe5c2d6f3 microsoft/compiler: Process signatures before the shader code
This lets us set up some metadata based on I/O vars without having
to do multiple passes over them.

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 cdc49fb605 microsoft/compiler: Lower 64bit I/O to 32 and then run lower_pack
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 b24cfd0d40 microsoft/compiler: Handle b2f64
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 4d17393ba0 microsoft/compiler: Set dx11_1_double_extensions flag for dfma/ddiv
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 c8bd830dfb microsoft/compiler: Fix make_double and split_double to respect swizzles
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 dde3b04d44 microsoft/compiler: It's possible to have doubles without int64
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 3b9483e89d microsoft/compiler: Add never-supported double ops to lower_doubles bitmask
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 ce6dbbabf9 microsoft/compiler: Only treat tess level location as special if it's a patch constant
Fixes: a550c059 ("microsoft/compiler: For load_input from DS, use loadPatchConstant")
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 0c711dc823 microsoft/compiler: Only prep phis for the current function
Fixes: 41af9620 ("microsoft/compiler: Emit all NIR functions into the DXIL module")
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 87d22c2465 microsoft/compiler: Lower mul_2x32_64
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 895cdbd6f0 microsoft/compiler: Correctly support I/O on variables with location_frac
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
Jesse Natalie 2d4ee41df0 microsoft/compiler: Fix UAV resource ID counting for static indexed handles
Skip resource space 2 after computing the ID it would've used.

Fixes: e5f353f2 ("microsoft/compiler: Emit statically-indexed resource handles and scratch later")
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14787>
2022-01-31 13:13:12 -08:00
Boris Brezillon a4c8508c37 microsoft/compiler: textureLoad() doesn't take a LOD on MS textures
Make sure the LOD is zero in that case.

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/13993>
2022-01-31 16:37:47 +00:00
Boris Brezillon 678b94c2d8 microsoft/compiler: Fix sampler/texture array emission
Those need to be declared as sampler/SRV arrays, as we do for UAVs and
CBVs.

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/13993>
2022-01-31 16:37:47 +00:00
Louis-Francis Ratté-Boulianne 54c32aeba6 microsoft/compiler: Use SRVs for read-only images
Acked-by: Enrico Galli <enrico.galli@intel.com>
Reviewed-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
Louis-Francis Ratté-Boulianne ef5283d37d microsoft/compiler: add support for load_layer_id
We simply return 0 for now as we don't support multi-view yet.

Reviewed-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 4da51aa88f microsoft/compiler: Primitive ID should only be added as a sysval in geometry shaders
Docs say that its presence in signatures as a "shadow" element (meaning it's not
accessed via load/store, but with a dedicated opcode) is legacy. It seems it
wasn't carried forward when HS/DS were added in D3D11.

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 ec415a274e microsoft/compiler: Emit DS PSV validation and entrypoint metadata
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 9aca56b137 microsoft/compiler: Handle domain location intrinsic
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 8524d04783 microsoft/compiler: Handle load_output in the HS stage as reading a previously written patch constant
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 a39881b788 microsoft/compiler: Handle load_per_vertex_output as LoadOutputControlPoint
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 a550c059c7 microsoft/compiler: For load_input from DS, use loadPatchConstant
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 cc6104dd3f microsoft/compiler: For store_output from HS, use storePatchConstant
In HS, store_per_vertex_output maps to storeOutput in DXIL. The data
that isn't per-vertex is patch constants.

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 97b6ea71a0 microsoft/compiler: Add a pass for hull and domain shaders to shrink tess level vars
DXIL validation will complain if the tess factor signature entries have the
wrong number of components for the shader's domain. Make sure that both
hull and domain shaders have the right number, and drop loads and stores
from the removed components.

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 bd2a4fb1b8 microsoft/compiler: Add patch constant signature into PSV and as container blob
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