Commit Graph

741 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
8c509fec7b HLSL: Update rayquery reference. 2023-03-21 12:23:40 +01:00
Hans-Kristian Arntzen
3550a54ae0
Merge pull request #2105 from goki/main
add support for OpAtomicFAddEXT atomic add, and also Min, Max
2023-02-21 13:05:31 +01:00
Chip Davis
41007cdc7d MSL: Deduplicate function constants.
It is possible in SPIR-V to declare multiple specialization constants
with the same constant ID. The most common cause of this in GLSL is
defining a spec constant, then declaring the workgroup size to use that
spec constant by its ID. But, MSL forbids defining multiple function
constants with the same function constant ID. So, we must only emit one
definition of the actual function constant (with the
`[[function_constant(id)]]` attribute); but we can point the other
variables at this one definition.

Fixes three tests in the Vulkan CTS under
`dEQP-VK.compute.basic.max_local_size_*`.
2023-02-17 10:43:50 -08:00
Randall C. O'Reilly
8e20860b9e added tests and added msl3 to test_shaders.py 2023-02-15 00:04:44 -08:00
Hans-Kristian Arntzen
388431604a
Merge pull request #2103 from cdavis5e/msl-sample-dref-lod-array-workaround
MSL: Add a workaround for broken `level()` arguments.
2023-02-03 16:36:44 +01:00
Chip Davis
e8d419854f MSL: Add a workaround for broken level() arguments.
Some Metal devices have a bug with depth array textures using comparison
with explicit LoD, where the LoD given will be biased by some amount.
For these devices, we can use a gradient instead, which does not exhibit
this problem. As with the fragment demote workaround, this is only
expected to be needed until the bug is fixed in Metal.
2023-02-02 22:01:46 -08:00
rdb
c356dd6220 GLSL: Fix missing precision qualifier in spvDeterminant return value
Follow-up to #2100
2023-01-27 21:44:47 +01:00
rdb
20981666cc GLSL: Legacy matrix inverse/determinant polyfills, outerProduct()
Also refactors polyfill mechanism in GLSL and fixes transpose() lowering precision.
2023-01-27 13:51:47 +01:00
Hans-Kristian Arntzen
86a985f28c
Merge pull request #2093 from rdb/emulate-unsupported-hyperbolic-funcs
GLSL/HLSL: Add emulated fallbacks for hyperbolic math functions
2023-01-27 12:15:28 +01:00
rdb
53974b4fae GLSL/HLSL: Add emulated fallbacks for sinh/cosh/tanh/asinh/acosh/atanh
The inverse hyperbolic functions are not supported in HLSL, and none of them are supported in legacy GLSL.
2023-01-26 19:40:42 +01:00
rdb
d10044b23e GLSL: Add support for modf, isnan and isinf in legacy GLSL 2023-01-26 19:14:25 +01:00
Hans-Kristian Arntzen
9de5abaf78 GLSL: Minor fixes for shader clock implementation. 2023-01-26 15:41:51 +01:00
rdb
dff276989b GLSL: Multiplying matrix with scalar shouldn't force transpose 2023-01-21 11:42:55 +01:00
Chip Davis
2a9091ce53 MSL: Use rint() instead of round() to round array coordinates.
Vulkan specifies round-to-nearest-even mode to round array coordinates.
But we were using `round()`, which is round-to-nearest-away-from-zero.
Instead, use `rint()`, which is specified to perform nearest-even
rounding in MSL.
2023-01-18 19:34:29 -08:00
rdb
26da9c58a6 HLSL: Support PointSize output in vertex shader in SM 3.0 2023-01-17 23:42:04 +01:00
rdb
4ba13e0c1a GLSL/HLSL: Add legacy handling for int vertex attributes 2023-01-14 18:57:24 +01:00
Hans-Kristian Arntzen
03b1f66ef1 GLSL: Fix row-major workaround wrapper for ES.
By default, the matrix would be declared as mediump, causing precision
issues. Need to dispatch to two separate functions since GLSL does not
support overload based on precision.
2022-12-13 15:44:03 +01:00
Hans-Kristian Arntzen
451ed10e91
Merge pull request #2062 from cdavis5e/msl-spirv-assembly-fixes
MSL: SPIR-V assembly fixes
2022-11-21 13:53:17 +01:00
Chip Davis
061cdd2052 MSL: Don't dereference forwarded copies of OpVariable pointers.
Fixes two more CTS tests under
`dEQP-VK.spirv_assembly.instruction.compute.empty_struct.copying`.
2022-11-20 02:08:37 -08:00
Chip Davis
5547b25afe Interleave undef values with constants and types.
Undef values may be of struct type and may be used in constants.
Therefore, they must be interleaved with constants and types.

Fixes the rest of the Vulkan CTS test
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_spec_constant_composite`.

(Please excuse the churn in the reference output; it's an inevitable
result of this change.)
2022-11-20 02:08:37 -08:00
Chip Davis
06ef3de002 GLSL, MSL: Handle OpUndef as part of a constant composite.
Fixes the CTS test
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_constant_composite`
and helps with another,
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_spec_constant_composite`.
Unfortunately, fixing the latter requires another change.
2022-11-20 02:08:33 -08:00
Chip Davis
aa5a8c482e MSL: Prevent stores to storage resources in discarded fragments.
Some Metal devices have a bug where storage resources can still be
written to even if the fragment is discarded. This is obviously a bug in
Metal, but bothering Apple to fix it will only fix it for newer
versions; therefore, a workaround is needed for older versions. I have
made this an option so that, in case the bug is ever fixed, the
workaround can be disabled.

This workaround is simple: if a fragment shader may discard its fragment
and writes to a storage resource, a variable representing the
`HelperInvocation` built-in is created and passed to all functions. The
flag is checked on all resource writes; writes do not occur when
`HelperInvocation` is `true`. This relies on the earlier workaround to
update `HelperInvocation` when the fragment is discarded.

Fixes at least 3 failures in the CTS.
2022-11-20 01:29:41 -08:00
Chip Davis
51d2dfe02a MSL: Add missing casts to Op?MulExtended.
It is possible to pass unsigned integers to `OpSMulExtended`. In that
case, we want to do a signed multiply with sign extension, so make sure
the operands are forced to be interpreted as signed.

This was an oversight on my part when I added these instructions.

Fixes the CTS test
`dEQP-VK.spirv_assembly.instruction.compute.signed_op.uint_smulextended`.
2022-11-20 00:20:49 -08:00
Chip Davis
c7ce92a95b MSL: Manually update BuiltInHelperInvocation when a fragment is discarded.
Some Metal devices have a bug where `simd_is_helper_thread()` won't
return true after a fragment has been discarded. We can work around this
by manually setting `gl_HelperInvocation` upon discarding a fragment.
This is fairly unintrusive, so it is enabled by default. I've made it an
option so that, when the bug is fixed, we can disable it.
2022-11-19 23:48:26 -08:00
Hans-Kristian Arntzen
ebf779dcfb HLSL: Do not support ClipCull size > 4 in mesh shaders.
The array mechanism breaks DXC which needs to observe that all
components have been written.

Uninitialized outputs will be undefined. Resort to simple vector
instead.
2022-11-02 13:34:11 +01:00
Hans-Kristian Arntzen
f5ef0a74fb HLSL: Make sure to test deeply nested functions in mesh shaders. 2022-11-02 12:56:10 +01:00
Hans-Kristian Arntzen
e418266d25 HLSL: Some cleanups and fixes in analyze_meshlet_writes. 2022-11-02 12:56:04 +01:00
Hans-Kristian Arntzen
10f55a11eb HLSL: Add missing reference for mesh shader test. 2022-11-02 11:52:02 +01:00
Hans-Kristian Arntzen
744279ec78
Merge pull request #2050 from cdavis5e/op-spec-constant-op-composite-insert
MSL: Implement `CompositeInsert` `OpSpecConstantOp`.
2022-11-02 11:13:17 +01:00
Chip Davis
8cf99e7d44 MSL: Implement CompositeInsert OpSpecConstantOp.
This op creates a new composite constant with one element replaced. So,
we reconstruct the `SPIRConstant` for the composite constant, but with
one of the IDs replaced. Constant initializer lists are memoized for
when the result of a `CompositeInsert` is used in another
`CompositeInsert`.

(I wanted to add a test case for GLSL as well, but for two things:
1. `glslang` in Vulkan mode chokes on the first constant array,
   insisting that its initializer needs to be a constant. [Bug in
   glslang?]
2. The declarations for the buffers used by the shader aren't emitted,
   regardless of whether Vulkan mode is enabled.)

Fixes five tests under
`dEQP-VK.spirv_assembly.instruction.*.opspecconstantop.vector_related`.
2022-11-01 18:11:39 -07:00
Hans-Kristian Arntzen
605bce39d7 Roll glslang dependency. 2022-11-01 12:47:56 +01:00
Hans-Kristian Arntzen
2a49f7e82d MSL: Fix restrict vs __restrict incompatibility.
restrict was supported, but it broke in MSL 3.0. __restrict works on all
versions, so opt for that instead.

Also check for RestrictPointer decoration and refactor to_restrict() to
not take optional parameter to make it more obvious when implied space
character is added.
2022-10-26 17:52:47 +02:00
Chip Davis
0b679334e4 MSL: Don't flatten arrayed per-patch output blocks in tessellation shaders.
Flattening doesn't play well with dynamic indices. In this case, it's
better to leave it as an array of structs.

(I wanted to do this for named blocks generally. Trouble is, the builtin
`gl_out` block is *also* a named block...)

Fixes six more CTS tests, under
`dEQP-VK.tessellation.user_defined_io.per_patch_block_array.*`.
2022-10-18 15:04:42 -07:00
Chip Davis
a171087180 MSL: Support "raw" buffer input in tessellation evaluation shaders.
Using vertex-style stage input is complex, and it doesn't support
nesting of structures or arrays. By using raw buffer input instead, we
get this support "for free," and everything becomes much simpler.
Arguably, this is the way I should've done this in the first place.

Eventually, I'd like to make this the default, and then remove the
option altogether. (And I still need to do that with
`multi_patch_workgroup`...)

Should help fix 66 tests in the Vulkan CTS, under the following trees:

 - `dEQP-VK.pipeline.*.interface_matching.*`
 - `dEQP-VK.tessellation.user_defined_io.*`
 - `dEQP-VK.clipping.user_defined.*`
2022-10-18 14:58:59 -07:00
Hans-Kristian Arntzen
a915e0bd4b MSL: Do not attempt to alias push constants. 2022-09-21 11:01:42 +02:00
Hans-Kristian Arntzen
24dc49e692 MSL: Handle descriptor aliasing of raw buffer descriptors.
It is allowed to redeclare descriptors with different types in Vulkan.
MSL in general does not allow this, but for raw buffers, we can cast the
reference type at the very least.

For typed resources we are kinda hosed. Without descriptor indexing's
PARTIALLY_BOUND_BIT, descriptors must be valid if they are statically
accessed, so it would not be valid to access differently typed aliases
unless that flag is used. There might be a way to reinterpret cast
descriptors, but that seems very sketchy.

Implements support for:

- Single discrete descriptor
- Single argument buffer descriptor
- Array of argument buffer descriptors

Other cases are unimplemented for now since they are extremely painful
to unroll.
2022-09-20 15:21:56 +02:00
Yuwen Wu
1b9296e1a5 MSL: only fix up gl_FragCoord if really necessary. 2022-09-13 18:50:57 +08:00
Hans-Kristian Arntzen
a5a7999666 Update mesh/task test references. 2022-09-12 12:46:14 +02:00
Hans-Kristian Arntzen
4c345166dc GLSL: Implement task shaders.
Due to bugged glslang / spirv-tools w.r.t. terminator instructions,
add a hack to ignore invalid SPIR-V for the time being.
2022-09-05 12:31:22 +02:00
Hans-Kristian Arntzen
5762617729 GLSL: Implement GL_EXT_mesh_shader. 2022-09-05 11:25:04 +02:00
Hans-Kristian Arntzen
6a73e68d30 Update glslang reference. 2022-09-05 11:18:44 +02:00
Hans-Kristian Arntzen
d24f41f1d5 Update dependencies. 2022-09-02 14:58:04 +02:00
Hans-Kristian Arntzen
bc3987e59a MSL: Fix various bugs with Ptr/U bitcasts. 2022-08-09 13:49:40 +02:00
Chip Davis
fc4a12fd4f MSL: Use a wrapper type for matrices in workgroup storage.
The standard `matrix` type in MSL lacked a constructor in the
`threadgroup` AS. This means that it was impossible to declare a
`threadgroup` variable that contains a matrix. This appears to have been
an oversight that was corrected in macOS 13/Xcode 14 beta 4. This
workaround continues to be required, however, for older systems.

To avoid changing interfaces unnecessarily (which shouldn't be a problem
regardless because the old and new types take up the same amount of
storage), only do this for structs if the struct is positively
identified as being used for workgroup storage.

I'm entirely aware this is inconsistent with the way packed matrices are
handled. One of them should be changed to match the other. Not sure
which one.

Fixes 23 CTS tests under `dEQP-VK.memory_model.shared`.
2022-08-07 17:31:41 -07:00
Chip Davis
faea931de3 MSL: Also replace bool with short in structures.
Since `bool` is a logical type, it cannot be used in uniform or storage
buffers. Therefore, replacing it in structures should not change the
shader interface.

We leave it alone for builtins. (FIXME: Should we also leave it for
I/O varyings?)

Fixes 24 CTS tests under `dEQP-VK.memory_model.shared`.
2022-08-05 11:43:21 -07:00
Bill Hollings
4185acc70d MSL: Fixes from review for SPV_KHR_physical_storage_buffer extension.
- Assign ulongn physical type to buffer pointers in short arrays
  when array stride is larger than pointer size.
- Support GL_EXT_buffer_reference_uvec2 casting
  buffer reference pointers to and from uvec2 values.
- When packing structs, include structs inside physical buffers.
- Update mechanism for traversing pointer arrays when calculating type sizes.
- Added unit test shaders.
2022-07-01 16:10:41 -04:00
Bill Hollings
78eb5043f9 MSL: Fixes from review for SPV_KHR_physical_storage_buffer extension.
- For physical storage pointers, emit forward reference
  declarations in addition to definitions.
- Minor syntax corrections.
2022-06-24 17:28:17 -04:00
Bill Hollings
52c7c2dab6 MSL: Add support for SPV_KHR_physical_storage_buffer extension.
- Determine sizing and alignments of pointers to types as
  distinct from the size and alignment of the types themselves.
- Declare all buffer pointers in the MSL device address space.
- Support struct pointer recursion, where structs can
  contain pointers to themselves or to a parent struct.
- Add SPIRType::was_forward_referenced to track if a type was forward
  referenced, to help emit MSL structs in the correct dependency order.
- Handle pointers to pointers that are not just arrays of arrays.
2022-06-20 20:21:00 -04:00
Hans-Kristian Arntzen
df21a99d1a GLSL: Add more extension ladder fallbacks for unusual integer sizes. 2022-06-07 18:30:10 +02:00
Hans-Kristian Arntzen
533aab00b6 GLSL: Add missing KHR barycentric references. 2022-06-07 15:17:34 +02:00