Commit Graph

1218 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
1adc53b107
Merge pull request #1806 from KhronosGroup/fix-1777
CFG: Handle degenerate selection constructs.
2021-11-07 14:10:48 +01:00
Hans-Kristian Arntzen
21a15b90e5
Merge pull request #1804 from KhronosGroup/fix-1759
MSL: Handle non-thread storage class in Modf/Frexp pointer versions.
2021-11-07 13:36:32 +01:00
Hans-Kristian Arntzen
2714f5410c CFG: Handle degenerate selection constructs.
Apparently, it's legal to use a selection construct where both paths
branch to same location, but a different merge point is used.
This breaks many assumptions the variable scope analyzer makes.

The only logical way to generate code for this scenario is to treat the
selection construct as a trivial switch construct with only a default
case.
2021-11-07 13:32:29 +01:00
Hans-Kristian Arntzen
e40d19bdbf MSL: Handle non-thread storage class in Modf/Frexp pointer versions. 2021-11-07 12:51:15 +01:00
Hans-Kristian Arntzen
f1d4aff85e
Merge pull request #1805 from KhronosGroup/fix-1776
Handle Modf/Frexp in more cases.
2021-11-07 12:36:42 +01:00
Hans-Kristian Arntzen
4561ecddbd Handle Modf/Frexp in more cases.
Consider it a write to a variable, similar to OpStore.
2021-11-07 11:36:44 +01:00
Hans-Kristian Arntzen
05e8e5a953 Correctly reflect declared buffer size for out of order members.
Need to deduce size based on member with highest offset, not highest
index.
2021-11-07 10:08:17 +01:00
Bill Hollings
be812c45e5 MSL: Remove over-zealous check for struct packing compatibility.
Previous test for SPIRVCrossDecorationPhysicalTypePacked on parent struct
when unpacking member struct was too restrictive, and not needed as long
as padding compensates.
2021-10-28 19:36:32 -04:00
Bill Hollings
76cb807c19 MSL: Fix type redirection when struct members are reordered to align with offsets.
Populate member_type_index_redirection as reverse lookup, not forward lookup.
Move use of member_type_index_redirection from CompilerMSL::to_member_reference()
to CompilerGLSL::access_chain_internal() to access all redirected type info,
not just name.
2021-10-28 10:16:34 -04:00
Hans-Kristian Arntzen
edf247fb1c MSL: Workaround compiler crashes when using threadgroup bool.
Promote to short instead and do simple casts on load/store instead.

Not 100% complete fix since structs can contain booleans, but this is
getting into pretty ridiculously complicated territory.
2021-10-25 10:55:11 +02:00
Erfan Ahmadi
43eecb2360 SPIRV-Cross contribution needed for INTEL_fragment_shader_ordering 2021-10-25 10:50:10 +02:00
Hans-Kristian Arntzen
2b5e17eca5 MSL: Never used templated array for RayQuery objects.
Not supported and compiler derps out.
2021-10-21 22:02:01 +02:00
Hans-Kristian Arntzen
5afb3d313f MSL: Fix some trivial bugs not caught by CI when adding ray query. 2021-10-21 21:53:41 +02:00
丛越
d52ec1e196 Fix all requested changes, test_shaders.py supports compiling MSL 2.4 shaders, and the Intersection Query currently only supports MSL 2.4 on the iOS platform. 2021-10-21 17:46:45 +08:00
丛越
597f29d09d Support Metal 2.4 Intersection Query, Implement GL_EXT_ray_query. 2021-10-19 18:45:10 +08:00
Hans-Kristian Arntzen
6382f15470 Test behavior around OpSelect with matrices. 2021-10-13 16:08:29 +02:00
Hans-Kristian Arntzen
6071df5840 Fix wrong detection of trivial_mix_op.
Effectively, only the last component of the select was considered, need
to correctly early out if any case is hit.
2021-10-13 15:34:00 +02:00
Hans-Kristian Arntzen
97a438d214
Merge pull request #1757 from KhronosGroup/fix-1754
Improve handling of INT_MIN/INT64_MIN literals.
2021-09-30 17:04:30 +02:00
Hans-Kristian Arntzen
f72bb3c6f5 Improve handling of INT_MIN/INT64_MIN literals.
We cannot naively convert these to decimal literals. C/C++ (and thus
MSL) has extremely awkward literal promotion rules.
2021-09-30 16:29:30 +02:00
Hans-Kristian Arntzen
9b2a8c7622 HLSL: Ensure synthetic NumWorkgroups variable is considered active.
In SPIR-V 1.4+, active global variables must be marked as such.
2021-09-30 14:39:42 +02:00
Hans-Kristian Arntzen
bb04156d3c CLI/HLSL: Don't set explicit binding for synthesized NumWorkgroups CBV. 2021-09-30 14:30:49 +02:00
Bill Hollings
ec054dad7f MSL: Support synthetic functions in function constants.
Emit synthetic functions before function constants.
Support use of spvQuantizeToF16() in function constants for numerical
behavior consistency with the op code.
Ensure subnormal results from OpQuantizeToF16 are flushed to zero per SPIR-V spec.

Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
Any MSL reference shader that inclues a synthetic function is affected,
since the location it is emitted has changed.
2021-09-28 19:10:16 -04:00
Bill Hollings
ba66a91402 MSL: Use vec<T, n> in template SpvHalfTypeSelector for function spvQuantizeToF16().
Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-25 14:36:42 -04:00
Bill Hollings
a2671e35b0 MSL: Consolidate spvQuantizeToF16() functions into a single template function.
Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-24 14:41:15 -04:00
Bill Hollings
5742047b24 MSL: Honor infinities in OpQuantizeToF16 when compiling using fast-math.
Add spvQuantizeToF16() family of synthetic functions to convert
from float to half and back again, and add function attribute
[[clang::optnone]] to honor infinities during conversions.

Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-24 11:22:05 -04:00
Bill Hollings
fb3defc9ef MSL: Honor DecorationNoContraction when compiling using fast-math.
Add [[clang::optnone]] attribute to spvF*() functions used for handling
floating point operations decorated with DecorationNoContraction.

Just using precise::fma() did not work.

Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-23 14:37:08 -04:00
Bill Hollings
40141ffddf MSL: Selectively enable fast-math in MSL code to match Vulkan CTS results.
Based on CTS testing, math optimizations between MSL and Vulkan are inconsistent.
In some cases, enabling MSL's fast-math compilation option matches Vulkan's math
results. In other cases, disabling it does. Broadly enabling or disabling fast-math
across all shaders results in some CTS test failures either way.

To fix this, selectively enable/disable fast-math optimizations in the MSL code,
using metal::fast and metal::precise function namespaces, where supported, and
the [[clang::optnone]] function attribute otherwise.

Adjust SPIRV-Cross unit test reference shaders to accommodate these changes.
2021-09-22 18:58:31 -04:00
Bill Hollings
35e92e6ffb MSL: Return fragment function value even when last SPIR-V Op is discard (OpKill).
Add test shader for new functionality.
Add legacy test reference shader for unrelated buffer-bitcast
test, that doesn't seem to have been added previously.
2021-09-12 16:28:21 -04:00
Bill Hollings
472f9d4f6d Add tests for OpSpecConstantOp ops OpQuantizeToF16 and OpSRem.
Tests provided by @cdavis5e.
2021-09-05 16:51:04 -04:00
Hans-Kristian Arntzen
b8f1e71907 GLSL: Emit GL_EXT_buffer_reference_uvec2 as required. 2021-09-02 13:17:13 +02:00
Hans-Kristian Arntzen
23c4480d8e Fix switch fallthrough case in some cases. 2021-08-31 17:24:09 +02:00
Hans-Kristian Arntzen
2eea6a579b MSL: Consider that function/private variables can be block-like.
Handles a special case with array copies.
The implementation of this fix is not perfect, but should be good
enough for time being.
2021-08-23 13:26:45 +02:00
Hans-Kristian Arntzen
c062b6b852
Merge pull request #1725 from billhollings/fix-duplicate-glposition
MSL: Fix duplicate gl_Position outputs when gl_Position defined but unused.
2021-08-23 11:37:10 +02:00
Hans-Kristian Arntzen
fad1590786
Merge pull request #1722 from billhollings/row-maj-mtx-store-from-const
MSL: Support row-major transpose when storing matrix from constant RHS matrix.
2021-08-23 11:29:01 +02:00
Bill Hollings
e76fcf9309 MSL: Add test for fixes to MSL constant expression type down-casting. 2021-08-16 13:56:05 -04:00
Bill Hollings
3105e82b2e MSL: Fix duplicate gl_Position outputs when gl_Position defined but unused.
When gl_Position is defined by SPIR-V, but neither used nor initialized,
it appeared twice in the MSL output, as gl_Position and glPosition_1.

The existing tests for whether an output is active check only that it is
used by an op, or initialized. Adding the implicit gl_Position also marked
the existing gl_Position as active, duplicating the output variable.

Fix is that when checking for the need to add an implicit gl_Position
output, also check if the var is already defined in the shader,
and just needs to be marked as active.
Add test shader.
2021-08-16 11:23:15 -04:00
Bill Hollings
9552ca5473 MSL: Support row-major transpose when storing matrix from constant RHS matrix.
Remove test and exception when storing row-major matrix
from RHS that is not a SPIRExpression.
Add test shaders.
2021-08-12 09:08:35 -04:00
Hans-Kristian Arntzen
cb613eb675 Handle value access in terminators.
Fixes case where value is created inside loop body and consumed by a
return outside it.
2021-07-29 15:27:52 +02:00
Hans-Kristian Arntzen
cd22336a38
Merge pull request #1712 from cdavis5e/msl-subgroup-ballot-simplify
MSL: Simplify spvSubgroupBallot().
2021-07-22 12:15:33 +02:00
Chip Davis
03ad13bae6 MSL: Simplify spvSubgroupBallot().
A bitcast to `uint2` will do just fine. I honestly don't know why I
didn't do it this way earlier.
2021-07-21 00:25:09 -05:00
Hans-Kristian Arntzen
18f3cd6810 GLSL: Ensure ray query object decls are flushed if allocated in Function.
glslang always emits Private variables, but DXC not so much.
2021-07-20 12:04:00 +02:00
Hans-Kristian Arntzen
5b227cc57c GLSL: Implement GL_EXT_ray_query. 2021-07-19 14:01:21 +02:00
Bill Hollings
ebb5098def MSL: Adjust gl_SampleMaskIn for sample-shading and/or fixed sample mask.
Vulkan specifies that the Sample Mask Test occurs before fragment shading.
This means gl_SampleMaskIn should be influenced by both sample-shading and
VkPipelineMultisampleStateCreateInfo::pSampleMask.

CTS tests dEQP-VK.pipeline.multisample_shader_builtin.* bear this out.

For sample-shading, gl_SampleMaskIn should only have a single bit set,
Since Metal does not filter for this, apply a bitmask based on gl_SampleID.

For a fixed sample mask, since Metal is unaware of
VkPipelineMultisampleStateCreateInfo::pSampleMask, we need to ensure that
we apply it to both gl_SampleMaskIn and gl_SampleMask. This has the side
effect of a redundant application of pSampleMask if the shader already
includes gl_SampleMaskIn when setting gl_SampleMask, but I don't see an
easy way around this.

Also, simplify the logic for including the fixed sample mask in gl_ShaderMask,
and print the fixed sample mask as a hex value for readability of bits.
2021-07-13 21:22:13 -04:00
Hans-Kristian Arntzen
71b83a18f4 MSL: Add test for scalar access chain pull interpolant. 2021-07-13 12:25:18 +02:00
Hans-Kristian Arntzen
206ee8f171 GLSL: Support pervertexNV in NV barycentric extension. 2021-06-30 16:27:46 +02:00
Hans-Kristian Arntzen
d6b29ab017 HLSL: Rewrite how block IO is emitted.
Emit block members directly in the IO structs and sort them.
Ensures we can get some kind of stable order between stages.

To complete the story, we'll need to be able to inject unused inputs /
builtins, or eliminate unused outputs (probably easiest solution).
2021-06-28 15:04:49 +02:00
Hans-Kristian Arntzen
8216e87f02 Handle SPIR-V 1.4 selection constructs.
Fix bug in to_trivial_mix_op, where we made a pre-1.4 assumption that
component count of selector is equal to value component count.
2021-06-28 12:23:44 +02:00
Hans-Kristian Arntzen
2e1b5fb39e
Merge pull request #1686 from KhronosGroup/fix-1684
GLSL: Support control flow hints
2021-06-03 14:13:18 +02:00
Hans-Kristian Arntzen
449f68ef3b Ensure loop control flow hints only appear above loops. 2021-06-03 12:19:10 +02:00
Hans-Kristian Arntzen
d62b3c2b92 GLSL: Implement control flow hints. 2021-06-03 12:01:49 +02:00
Hans-Kristian Arntzen
165dbff228 Handle odd type for textureGather component. 2021-06-03 11:37:45 +02:00
xndcn
02fb8f2a24 Add comment after inf/nan float number for clarifying. 2021-05-27 02:40:41 +08:00
Hans-Kristian Arntzen
bf3793dd35 MSL: Improve handling of split tessellation access chains. 2021-05-21 16:32:03 +02:00
Hans-Kristian Arntzen
a6c9514856
Merge pull request #1676 from KhronosGroup/fix-1671
GLSL: Implement noncoherent framebuffer fetch.
2021-05-21 15:43:58 +02:00
Hans-Kristian Arntzen
26a4986009 GLSL: Implement noncoherent framebuffer fetch. 2021-05-21 14:22:57 +02:00
Hans-Kristian Arntzen
99ae0d32e9 MSL: Handle array with component when we cannot rely on user() attrib.
In these cases, we emit one variable per location, and so we must
flatten stuff.
2021-05-21 13:46:33 +02:00
Hans-Kristian Arntzen
b8115ffbe0 HLSL: Implement invariant as precise.
Only option we have.
2021-05-07 13:15:55 +02:00
Hans-Kristian Arntzen
e47a30e807 Honor NoContraction qualifier.
We'll need to force a temporary and mark it as precise.
MSL is a little weird here, but we can piggyback on top of the invariant
float math option here to force fma() operations everywhere.
2021-05-07 12:59:47 +02:00
Hans-Kristian Arntzen
6dbab0df47 Update reference output. 2021-05-07 11:12:22 +02:00
Lukas Taparauskas
72a2ec4c1b
MSL: Fix '--msl-multi-patch-workgroup' out of bounds reads when dispatching more threads than control points (#1662)
* Fix '--msl-multi-patch-workgroup' cases where thread count exceeds data bounds

*Fix gl_PrimitiveID off by one error when computing last valid index
*Point gl_out to the last patch's data when threads exceed input data bounds
*Point patchOut to the last patch's data when threads exceed input data bounds

* Update MSL test expectations.

* Undo change to MSL multi-patch hull output bound checks

* Update MSL multi-patch test expectations.
2021-04-29 20:01:26 +02:00
Hans-Kristian Arntzen
c624d5387c
Merge pull request #1660 from KhronosGroup/fix-1658
MSL: Use proper array for quad tess levels.
2021-04-23 15:21:00 +02:00
Hans-Kristian Arntzen
82a77e534e MSL: Use proper array for quad tess levels.
We need to handle loads from array as well, so the float4 hack doesn't
work.
2021-04-23 14:12:00 +02:00
Hans-Kristian Arntzen
0e963c62b6 HLSL: Support Shuffle wave ops.
WaveReadLaneAt is no longer restricted to dynamically uniform index,
so can implement the other shuffle ops.
2021-04-23 13:03:35 +02:00
Hans-Kristian Arntzen
532f65583e Rewrite how non-uniform qualifiers are handled.
Remove all shenanigans with propagation, and only consume nonuniform
qualifiers exactly where needed (last minute).
2021-04-22 16:03:08 +02:00
Hans-Kristian Arntzen
d137abeef5
Merge pull request #1655 from KhronosGroup/fix-1640
GLSL: Support shading rate builtins.
2021-04-20 16:35:02 +02:00
Hans-Kristian Arntzen
8e24e0b224
Merge pull request #1654 from KhronosGroup/fix-1641
GLSL: Implement gl_FragFullyCoveredNV.
2021-04-20 16:34:53 +02:00
Hans-Kristian Arntzen
71eb1754e3
Merge pull request #1653 from KhronosGroup/fix-1638
GLSL: Support GL_EXT_shader_image_load_formatted.
2021-04-20 16:34:44 +02:00
Hans-Kristian Arntzen
c89b5a1a3f GLSL: Support shading rate builtins. 2021-04-20 13:58:07 +02:00
Hans-Kristian Arntzen
3fd148450a GLSL: Implement gl_FragFullyCoveredNV. 2021-04-20 13:44:52 +02:00
Hans-Kristian Arntzen
f93a8fb1fe GLSL: Support GL_EXT_shader_image_load_formatted. 2021-04-20 13:36:51 +02:00
Hans-Kristian Arntzen
96ba044f01 HLSL: Fix automatic location assignment in block IO. 2021-04-20 13:04:26 +02:00
Hans-Kristian Arntzen
ae9ca7d73c MSL: Fix copy of arrays to/from stage IO variables.
Need to take into account effective storage classes and whether or not
we target stage IO blocks since native arrays are conditionally enabled.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
986196030d MSL: Don't use native arrays for tess level inputs. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
4a379a00f3 MSL: Don't emit native array for masked clip/cull distance. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
682a227f4b MSL: Make builtin argument type declaration context sensitive.
Sometimes we'll need array template, sometimes not 🤷.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
c1edd35d57 MSL: Use spvUnsafeArray for builtin arrays after all.
It will get too messy to deal with constant initializers any other way,
so just deal with complexity in argument_decl instead ...
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
7b9a591aa7 MSL: Hoist out to_tesc_invocation_id() in more places.
When emitting fixup code, we might not have gl_InvocationID yet.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
75ed73818c MSL: Handle loading Clip/CullDistance in TESE.
Need to allow the flattened space to go through in some edge cases where
we cannot reasonably unflatten.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
a159334895 MSL: Correctly analyze if builtin block is active.
Need to consider all members, bi_type is invalid for Blocks, need to
look at member decorations.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
cea934c03f MSL: Test that we can capture cull distance to buffer. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
5826298697 MSL: Handle CullDistance better. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
23da445bd4 MSL: Emit multiple threadgroup slices for multi-patch.
Multiple patches can run in the same workgroup when using multi-patch
mode, so we need to allocate enough storage to avoid false sharing.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
b442500204 MSL: Unroll initializations of CullDistance/ClipDistance control points. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
c9946296dd MSL: Fix initialization of masked threadgroup variables. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
5e9c2d060e MSL: Cleanup fallback IO block emission.
Need to emit in add_variable_to_iface(). Unifies the code paths a fair
bit.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
e32c474911 MSL: Handle masking of TESC IO block members. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
dc54f75eec MSL: Fixup gl_PerVertex names if we're emitting masked builtins. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
40f628f49c MSL: Add test for complex control point outputs. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
46c48ee6b5 MSL: Rewrite how IO blocks are emitted in multi-patch mode.
Firstly, never flatten inputs or outputs in multi-patch mode.
The main scenario where we do need to care is Block IO.
In this case, we should only flatten the top-level member, and after
that we use access chains as normal.

Using structs in Input storage class is now possible as well. We don't
need to consider per-location fixups at all here. In Vulkan, IO structs
must match exactly. Only plain vectors can have smaller vector sizes as
a special case.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
ff3f5bcba5 MSL: Handle masking of builtin control points. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
436b1250da MSL: Do not perform scalar fixups for control-point outputs. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
74b2acab9b MSL: Always emit block variable for block types. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
ae7bb41ef4 MSL: Test that we can mask location writes in TESC. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
ba93b6518d MSL: Fix masking of vertex block outputs. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
857295a9ab MSL: Add tests for masking with --for-tess. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
43b6ea2c9a MSL: Remove position mask tests. They will fail compilation. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
65b5ff7ece MSL: Don't emit weird reference type for spvUnsafeArray types. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
50a6bc058a MSL: Force builtin arrays for builtin array types.
Handles argument_decl() correctly.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
88b54f5dab MSL: Add tests for vertex output masking. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
0997e81118 MSL: Sort builtin IO block members by builtin type.
Ensures consistent block matching.
2021-04-19 12:10:49 +02:00