Commit Graph

408 Commits

Author SHA1 Message Date
Bill Hollings
ab1f9f4d7f MSL: Support ConstOffsets on image gather.
- Add TextureFunctionArguments::has_array_offsets.
- Add support functions spvGatherConstOffsets() &
  spvGatherCompareConstOffsets().
- Add SPVFuncImpl::SPVFuncImplGatherConstOffsets &
  SPVFuncImplGatherCompareConstOffsets.
- Add unit tests.
2024-05-20 12:10:35 -04:00
Hans-Kristian Arntzen
dc6db52356 MSL: Inherit interpolation qualifiers through recursive composites. 2024-04-15 15:44:21 +02:00
Hans-Kristian Arntzen
4f17bf76b1 MSL: Handle Atomic{S,U}{Min,Max} with mismatched image sign.
Gross reinterpret_cast, but gotta do what you gotta do.
2024-04-15 14:29:01 +02:00
Hans-Kristian Arntzen
56f24d86ec
Merge pull request #2304 from etang-cw/ArrayCleanup
Use recursive template for spvArrayCopy
2024-04-15 11:47:10 +02:00
Hans-Kristian Arntzen
061bf6b445 Fix tabbing nits. 2024-04-03 13:49:41 +02:00
Hans-Kristian Arntzen
ee77265ae5 MSL: Workaround compiler issue with image fence when used as reference. 2024-04-03 13:28:12 +02:00
Hans-Kristian Arntzen
218a8bfd86 MSL: Improve argument buffer descriptor aliasing implementation. 2024-04-03 13:15:51 +02:00
Hans-Kristian Arntzen
f9393f44d3 MSL: Get rid of obsolete "is pointer" methods.
Just use the common ones.
2024-04-02 11:47:54 +02:00
Evan Tang
cc542f8147 Use recursive template for spvArrayCopy
Comment claims we can't, but I tested a number of older Metal compilers (Xcode 8 targeting macOS 10.11, macOS 10.13 online compiler, Xcode 14 targeting iOS 8) and none of them had any issues with it
2024-04-01 17:11:31 -05:00
Hans-Kristian Arntzen
9d87a014f0 MSL: Handle volatile properly for emulated image atomics. 2024-01-23 13:09:41 +01:00
sean
6c24be197f MSL: Add support for SPV_EXT_integer_dot_product 2024-01-16 14:42:56 +01:00
Hans-Kristian Arntzen
ec87a03655 MSL: Plumb through member state to image/sampler types. 2024-01-05 16:08:29 +01:00
Bill Hollings
d47183c0db MSL: Ensure discrete runtime arrays of buffers have known length.
An entry-point array of buffers, that is not part of a Metal argument
buffer, requires a known length, so it can be emitted as discrete buffers.
For runtime arrays of resources, this can be retrieved from the resource
binding information added via add_msl_resource_binding().

- Redefine get_resource_array_size() to consolidate array sizing using both var
  type, and runtime array sizing from resource bindings, if not found in type.
- Use get_resource_array_size() to fix issue for runtime arrays of buffers.
- Update runtime arrays of images and samplers to use get_resource_array_size().
- Add .DS_Store to .gitignore (unrelated).
2023-12-22 09:12:44 -05:00
Hans-Kristian Arntzen
2603fbe520 MSL: Remove special case for threadgroup array wrapper.
I cannot find any evidence that this does not actually work.
The original case here was from Epic's PR series in 2019, but I cannot see why it doesn't work.
It might have been a bug in a very old compiler at some point.
2023-12-07 14:41:42 +01:00
Hans-Kristian Arntzen
9c054b1f34 MSL: Implement Metal 3.1 image atomics natively.
The check_discard code was too annoying to deal with,
and there is no requirement to return anything meaningful.
Vulkan specs state that values returned by atomic instructions are undefined.
2023-11-29 13:53:23 +01:00
Hans-Kristian Arntzen
50e90dd74e
Merge pull request #2233 from cdavis5e/agx-cube-grad-fixup
MSL: Work around broken cube texture gradients on Apple Silicon.
2023-11-28 12:05:55 +01:00
Chip Davis
7ef52b04c3 MSL: Work around broken cube texture gradients on Apple Silicon.
To date, all released Apple Silicon GPUs incorrectly interpret the
gradient vectors when sampling a cube texture. Specifically, they ignore
one of the three partial derivatives in each gradient depending on the
selected major axis, and they expect the remaining derivatives to be
partially transformed.

h/t @lexaknyazev for the code used in the `spvGradientCube()` function.

Fixes 8 tests under `dEQP-VK.glsl.texture_functions.texturegrad.*`.
2023-11-27 15:03:26 -08:00
Hans-Kristian Arntzen
81c047c3ed MSL: Use more appropriate padded types. 2023-11-27 16:30:24 +01:00
Hans-Kristian Arntzen
57dbfa0400 MSL: Support std140 half matrices and arrays.
Super awkward since there is no clean way to express this.
2023-11-27 15:28:20 +01:00
Bill Hollings
4a42191240 MSL: Fix regression error in argument buffer runtime arrays.
Argument buffers can contain multiple runtime arrays if they have fixed
lengths as specified by the binding API. Regression error had assumed each
runtime array is in separate argument buffer with undefined array length.

- Add CompilerMSL::is_var_runtime_size_array() to include test for
  setting of array length via CompilerMSL::add_msl_resource_binding().

- Fixed unrelated test case MSL compile syntax failure when acceleration
  structure is the first entry point function argument (unrelated).
2023-11-02 23:53:59 -04:00
Bill Hollings
16fbf8872a MSL: Workaround Metal 3.1 regression bug on recursive input structs.
Metal 3.1 introduced a Metal regression bug which causes an infinite recursion
crash during Metal's analysis of an entry point input structure that itself
contains internal recursion. This patch works around this by replacing the
recursive input declaration with a alternate variable of type void*, and
then casting to the correct type at the top of the entry point function.

- Add CompilerMSL::Options::replace_recursive_inputs to enable
  replacing recursive input.
- Add Compiler::type_contains_recursion() to determine if a struct
  contains internal recursion, and add custom Decorations to mark
  such structs, to short-cut future similar checks.
- Replace recursive input struct declarations with void*,
  and emit a recast to correct type at top of entry function.
- Add unit test.
- Compiler::type_is_top_level_block() remove hardcode reference to spirv_cross
  namespace, as it interferes with configurable namespaces (unrelated).
2023-10-14 14:46:47 -04:00
Try
844cb59cd6 MSL: runtime array over argument buffers 2023-08-17 11:37:29 +02:00
Evan Tang
894113f55b MSL: Make rw texture fences optional 2023-08-15 11:32:33 -05:00
Try
62331b6ac6 + spvMakeIntersectionParams
#2115
2023-07-03 19:57:46 +02:00
Hans-Kristian Arntzen
bbcd8de9a3 MSL: Handle more complex array copy scenarios with bool <-> short. 2023-06-06 15:05:56 +02:00
Hans-Kristian Arntzen
01b98264ce MSL: Handle stores to struct bool[]. 2023-06-06 13:55:29 +02: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
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
Bill Hollings
643b7be196 MSL: Add support for writable images in iOS Tier2 argument buffers.
- Add CompilerMSL::Options::argument_buffers_tier as an enumeration to
  allow calling app to specify platform argument buffer tier capabilities.
- Support iOS writable images in Tier2 argument buffers when specified.

Tier capabilities based on recommendations from Apple engineering.
2022-12-28 12:40:37 -05:00
Hans-Kristian Arntzen
c77b09b57c
Merge pull request #2063 from KhronosGroup/fix-2060
Merge #2061
2022-11-21 14:29:47 +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
Hans-Kristian Arntzen
df76a14056 MSL: Refactor member reference in terms of one boolean.
ptr_chain was really just masking the proper i == 0 check.
Be more explicit about what the check is actually doing and comment
this.
2022-11-21 13:40:27 +01:00
Dunfan Lu
e75c496ec6 Fix MSL Access Chain 2022-11-21 13:29:18 +01: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
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
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
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
4ecdb24e59 MSL: Expose way to query if a buffer needs array length. 2022-10-03 12:30:15 +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
Bill Hollings
5493b3030e MSL: Support OpPtrEqual, OpPtrNotEqual, and OpPtrDiff.
- Add CompilerMSL::emit_binary_ptr_op() and to_ptr_expression()
  to emit binary pointer op. Compare matrix addresses without automatic
  transpose() conversion, to avoid error taking address of temporary copy.
- Add Compiler::add_active_interface_variable() to also track active
  interface vars in the entry point for SPIR-V 1.4 and above.
- For OpPtrAccessChain that ends in array element, use Element
  as offset to existing index, otherwise it will access into
  array dimension that doesn't exist.
- Dereference pointer function call arguments. Ultimately, this
  dereferencing is actually backwards, and in future, we should aim
  to properly support passing pointer variables between functions,
  but such a refactoring was beyond the scope here.
- Use [] to declare array of pointers, as array<T*> is not supported in MSL.
- Add unit test shaders.
2022-09-14 15:19:15 -04:00
Chip Davis
064eaebe72 MSL: Add a mechanism to fix up shader outputs.
This is analogous to the existing support for fixing up shader inputs.
It is intended to be used with tessellation to add implicit builtins
that are read from a later stage, despite not being written in an
earlier stage. (Believe it or not, this is in fact legal in Vulkan.)

Helps fix 8 CTS tests under `dEQP-VK.pipeline.*.no_position`. (Eight
other tests work solely by accident without this change.)
2022-09-09 17:06:34 -07: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
Roy.li
749be80389 Use types have same widths in loop condition.
In case comparisons between types of different widths in a loop condition
caused the loop to behave unexpectedly.
2022-03-24 14:26:03 +08:00
Hans-Kristian Arntzen
7b594c125e Fix formatting nits from review. 2022-03-03 10:26:09 +01:00
Bill Hollings
3bb3b22b34 MSL: Non-functional fixes from PR code review. 2022-03-03 10:19:03 +01:00