Commit Graph

156 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
b0b2fd8d90 MSL: Add test for bool-in-struct edge cases. 2023-06-06 15:17:23 +02:00
Hans-Kristian Arntzen
cfd1618e31 MSL: Use templated array type when emitting BDA to arrays.
Handling native array types is not really feasible since we need to fuse
the variable declaration with the type declaration.

This is feasible in something like variable_decl, but for plain SSA
pointers, this breaks down.
2023-05-10 13:33:54 +02:00
Hans-Kristian Arntzen
e57b901dd1 MSL: Use name_id consistently in argument declaration. 2023-04-11 17:06:56 +02:00
Hans-Kristian Arntzen
884e5c0e06 MSL: Add test for block IO output with function use. 2023-03-30 18:30:44 +02: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
Hans-Kristian Arntzen
4de9d6c2b6 MSL: Handle implicit integer promotion rules.
MSL inherits the behavior of C where arithmetic on small types are
implicitly converted to int. SPIR-V does not have this behavior, so make
sure that arithmetic results are handled correctly.
2022-10-31 13:33:46 +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
Hans-Kristian Arntzen
04af769e85 MSL: Handle partial access chains with array-of-UBO/SSBO.
Need to consider the backing variable, not just plain SPIRVariable.
2022-10-26 11:33:04 +02:00
Bill Hollings
0a1127aa50 MSL: Emit correct address space when casting during OpStore.
When storing to local variable (eg. OpCopyLogical), the
default device address space used during casts is illegal.
Determine correct address space based on variable type.
2022-09-22 21:28:42 -04: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
Hans-Kristian Arntzen
bc3987e59a MSL: Fix various bugs with Ptr/U bitcasts. 2022-08-09 13:49:40 +02:00
Hans-Kristian Arntzen
4b9e60273c Add tests for OpCompositeInsert edge cases. 2022-05-18 16:43:32 +02:00
Hans-Kristian Arntzen
7b9eaf0b5e MSL: Handle awkward mix and match of Offset / ArrayStride in constants.
In normal buffer blocks, every member must be declared, but for
constants, you can technically mix and match, causing much pain and
suffering ...
2022-03-22 12:25:09 +01:00
Hans-Kristian Arntzen
4ab5bbb4e5 Fixup names of anonymous inner structs.
Just like we try to fixup struct names for block types, inner structs
can be "anonymous" structs. HLSL codegen from DXC tends to emit this,
and emitting dummy struct names tends to break GL linkage on some
drivers.
2022-03-10 15:45:38 +01:00
Hans-Kristian Arntzen
1ec9d018fd MSL: Handle aliased variable names for resources placed in IB struct.
Just remember to register the names.
2022-03-07 12:00:40 +01:00
Hans-Kristian Arntzen
15d29f00e2 Add test for SPIR-V 1.6 Volatile HelperInvocation. 2022-03-04 11:19:33 +01:00
Hans-Kristian Arntzen
31be74a853 Add relax_nan_checks options.
Makes codegen from typical D3D emulation SPIR-V more readable.
Also makes cross compilation with NotEqual more sensible.
It's very rare to actually need the strict NaN-checks in practice.

Also, glslang now emits UnordNotEqual by default it seems, so give up
trying to assume OrdNotEqual. Harmonize for UnordNotEqual as the sane
default.
2022-03-03 14:50:56 +01:00
Hans-Kristian Arntzen
ac46140ba3 Test aliased names in declared LUTs. 2022-01-18 12:39:16 +01:00
Hans-Kristian Arntzen
48b5a9069f Handle aliased names in spec constants.
Need to register resource name.
2022-01-18 12:31:28 +01:00
Hans-Kristian Arntzen
9b25581d49 MSL: Handle constant construct of block-like array types.
Need this to be context sensitive, since array of block-like struct is
template, but struct of block-like array is C-style.

Also, test a mix and match, so we have constant array of block-like
struct with array inside. :v
2022-01-17 18:28:25 +01:00
Hans-Kristian Arntzen
5a5be7f9b9 MSL: Handle signed atomic min/max.
C++ deduces this based on the pointer type, so cast to atomic_uint/int
if we have to.
2022-01-17 15:40:58 +01:00
Hans-Kristian Arntzen
7c83fc22fa Add support for LocalSizeId.
WorkgroupSize builtin is deprecated in 1.6 and LocalSizeId is supported
in Vulkan starting with maintenance4.
2022-01-06 13:57:10 +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
e40d19bdbf MSL: Handle non-thread storage class in Modf/Frexp pointer versions. 2021-11-07 12:51:15 +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
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
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
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
71b83a18f4 MSL: Add test for scalar access chain pull interpolant. 2021-07-13 12:25:18 +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
165dbff228 Handle odd type for textureGather component. 2021-06-03 11:37:45 +02:00
Hans-Kristian Arntzen
bf3793dd35 MSL: Improve handling of split tessellation access chains. 2021-05-21 16:32:03 +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
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
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
c9946296dd MSL: Fix initialization of masked threadgroup variables. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
fb1f295aaf
Merge pull request #1635 from KhronosGroup/fix-1627
Handle edge cases in OpCopyMemory.
2021-03-09 10:21:35 +01:00
Hans-Kristian Arntzen
4ca06c7278 Handle edge cases in OpCopyMemory.
Implement this by synthesizing an OpLoad/OpStore pair instead.
2021-03-08 14:15:27 +01:00
Hans-Kristian Arntzen
aea6d29aa8 MSL: Add test for logical subgroup arith ops. 2021-03-08 12:57:37 +01:00
Hans-Kristian Arntzen
97796e0609 MSL: Deal with pointer-to-pointer qualifier ordering. 2021-02-26 13:37:14 +01:00
Hans-Kristian Arntzen
621884d709
Merge pull request #1622 from KhronosGroup/fix-1619
MSL: Handle load and store to TessLevel array in TESC.
2021-02-17 20:46:06 +01:00
Hans-Kristian Arntzen
85704f70bc MSL: Handle load and store to TessLevel array in TESC.
More edge cases ... :(
2021-02-17 13:26:08 +01:00
Hans-Kristian Arntzen
ce552f4f91 MSL: Gracefully assign automatic input locations to builtin attributes. 2021-02-17 12:29:19 +01:00
Hans-Kristian Arntzen
daddbd4078 MSL: Fixup type when using tessellation levels in TESC functions.
Need to rewrite array size depending on execution mode.
2021-02-15 13:28:11 +01:00
Hans-Kristian Arntzen
ea02a0c03a Check entry point variables in is_hidden_variables.
Need to be careful not to emit globals we're not supposed to.
2021-01-22 13:53:22 +01:00
Hans-Kristian Arntzen
893a011299 MSL: Fix various bugs with framebuffer fetch on macOS and argument buffers.
Introduce a helper to make it clearer if a resource can be
considered for argument buffers or not.
2021-01-08 10:19:18 +01:00