Commit Graph

1090 Commits

Author SHA1 Message Date
Bill Hollings
eadf9d340a MSL: Support a runtime array with dynamic offset in an argument buffer.
- Retrieve size of runtime array from get_resource_array_size().
- Move validation assertion to after retrieval of array size.
2024-06-19 17:06:13 -04:00
Hans-Kristian Arntzen
bc105b6ad0 MSL: Consider pointer arithmetic for OpPtrAccessChain.
If the stride is weird for non-struct types you gotta do what you gotta
do.
2024-06-19 13:43:08 +02:00
Hans-Kristian Arntzen
4b27b458c5 MSL: Fix invalid packing for pointer-to-vector.
Normally BDA is pointer to block, but there are use cases with
OpPtrAccessChain.
2024-06-19 12:22:16 +02:00
Hans-Kristian Arntzen
5d127b917f
Merge pull request #2344 from billhollings/gather-constoffsts-arg-buffs
MSL: Image gather ConstOffsets supports multiple address spaces.
2024-06-18 17:12:18 +02:00
Bill Hollings
b5ccb0cf2c MSL: Image gather ConstOffsets supports multiple address spaces.
Required when using descriptor set argument buffers.

- Output overloaded functions for each address space.
- Update test shaders.
2024-06-18 10:55:43 -04:00
Hans-Kristian Arntzen
ab608ac89c
Merge pull request #2343 from billhollings/recurs-desc-set-arg-buff
MSL: Support descriptor sets with recursive content when using argument buffers.
2024-06-17 12:45:23 +02:00
Hans-Kristian Arntzen
d7ad3d7257
Apply suggestions from code review
Fix nits
2024-06-17 12:44:22 +02:00
Bill Hollings
488559ff4c MSL: Support descriptor sets with recursive content when using argument buffers.
When using argument buffers, handle descriptor set entry points with
recursive content, similar to discrete entry points with recursive content.

- For descriptor sets entry points with recursive content, add
  descriptor set to recursive_inputs, and create a local var for it.

- For recursive entry points that are contained in a descriptor set
  argument buffer, don't add entry point to recursive_inputs, or create
  a local var for that content entry point.

- Add test shader.
2024-06-14 13:35:11 -04:00
Bill Hollings
495e5b0913 MSL: Fixes for constexpr sampler use with argument buffers.
Constexpr samplers are defined as local variables,
but were treated as held within an argument buffer.

- CompilerMSL::to_sampler_expression() support constexpr samplers
  when using argument buffers, plus refactor to minimize generating
  expression text that may not be used.

- Handle padding around multi-plane images that require multiple textures.
  Only check for padding on the first plane, but include plane count in
  total argument buffer slots consumed.
2024-06-11 16:52:07 -04:00
Hans-Kristian Arntzen
2d990d355a MSL: Add median3 to list of banned func names. 2024-06-03 16:47:44 +02:00
Aitor Camacho
a43fabbe2a MSL: Add option to force depth write in fragment shaders
Metal writes to the depth/stencil attachment before fragment
shader execution if the execution does not modify the depth
value. However, Vulkan expects the write to happen after
fragment shader execution. To circumvent the issue we add
a simple depth passthrough if the user opts in. Only
required when the depth/stencil attachment is used as
input attachment at the same time. It seems Metal does not
correctly detect the dependency.
2024-05-24 12:13:17 +02:00
Hans-Kristian Arntzen
8b3aa21944 Pass down orig_id to type_to_array_glsl as well.
Allows UBO/SSBO resources in MSL to get the layout-derived size as well.
2024-05-21 15:43:04 +02:00
Hans-Kristian Arntzen
b236352fef MSL: Always use layout-declared array size for argument buffers. 2024-05-21 15:41:56 +02:00
Hans-Kristian Arntzen
ffdcefe250 MSL: Only consider padding for non-aliased resources. 2024-05-21 15:41:56 +02:00
Hans-Kristian Arntzen
854759fd64 MSL: Do not overwrite rez_bind when padding. 2024-05-21 15:41:56 +02:00
Hans-Kristian Arntzen
e680b72416 MSL: Don't bother supporting invalid multi-dimensional dynamic buffers.
This was never legal in any API and I'm not sure why I ever bothered.
2024-05-21 14:05:33 +02:00
Aitor Camacho
cd8865deab Add option to enforce fragment execution with side effects in MSL
Metal will incorrectly discard fragments with side effects under
certain circumstances prematurely. The conditions are the following:
 - Fragment will always be discarded after side effect operation
 - Pre fragment depth fails
 - Modifies depth value for a constant value in the fragment shader.
   This constant value will also fail the depth test.

However, Metal will also discard the fragment even if it has
operations with side effects inside the fragment shader before the
discard operation.

Vulkan states the graphics pipeline to execute in the following
order:
 - Pre fragment depth test (cannot discard here due to modifying
   depth value in fragment shader)
 - Fragment shader (where the depth is modified and fragment
   discarded)
 - Post fragment depth test

Therefore, we need to enforce fragment shader execution and not
let Metal discard the fragment before that for such cases. This
change adds an option to provide such utility.
2024-05-21 11:24:56 +02:00
Hans-Kristian Arntzen
641b92fa8f MSL: Clean up some nits for review. 2024-05-21 11:10:55 +02:00
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
Bill Hollings
84cdc3b68e MSL: Fix argument buffer padding.
- After padding a resource, retrieve either the next padded slot,
  or the next resource, in order to correctly offset the slot index.
2024-05-06 09:57:31 +02:00
Hans-Kristian Arntzen
cbaa86982a MSL: Handle missing FP16 trancendental overloads. 2024-04-29 11:49:28 +02:00
Jan Sikorski
298c2315f5 MSL: Remove pointer wrapper stored in spvDescriptorArray.
This works around what looks like a compiler bug which can cause GPU crashes.
2024-04-18 09:13:29 +02: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
eef4c2af9c MSL: Fix SUMulExtended for 64-bit inputs. 2024-04-15 13:37:00 +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
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
32e33e40b5 Cleanup overlap tag from review. 2024-04-02 12:42:12 +02:00
Jan Sikorski
221a517be5 MSL: Pass variable id when emitting image entry point declarations. 2024-04-02 12:01:07 +02:00
Jan Sikorski
064186e474 MSL: Check for device argument buffers for overlapping bindings. 2024-04-02 12:01:07 +02:00
Jan Sikorski
760a659f5c MSL: Avoid emitting multiple declaration of the same variable. 2024-04-02 12:01:07 +02:00
Jan Sikorski
44a5f1fc3e MSL: Add support for overlapping bindings.
This adds support for bindings which share the same DescriptorSet/Binding pair.

The motivating example is vkd3d, which uses overlapping arrays of resources to
emulate D3D12 descriptor tables. The generated MSL argument buffer only
includes the first resource (in this example 't0'):

struct spvDescriptorSetBuffer2
{
    array<texture2d<float>, 499968> t0 [[id(0)]];
    // Overlapping binding: array<texture3d<float>, 499968> t2 [[id(0)]];
};

When t2 is referenced, we cast the instantiated member:

float4 r1 = spvDescriptorSet2.t0[_79].sample(...);
float4 r2 = (*(constant array<texture3d<float>, 499968>*)&spvDescriptorSet2.t0)[_97].sample(...);
2024-04-02 12:01:07 +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
Bill Hollings
5e6500466c MSL: atomic_compare_exchange_weak() support CompilerMSL:msl_options.texture_1D_as_2D.
CompilerMSL:msl_options.texture_1D_as_2D emulates a Metal 1D texture
as a 2D texture in order to expand features available for 1D textures.
Support accessing such textures as 2D for atomic_compare_exchange_weak().
2024-03-11 22:42:43 -04:00
Hans-Kristian Arntzen
261589a5b2 MSL: Fix type hierarchy for extended vectors. 2024-03-06 14:33:02 +01:00
Hans-Kristian Arntzen
c524e3396f MSL: Improve handling of BDA + atomics. 2024-03-05 14:30:46 +01:00
Hans-Kristian Arntzen
7e0c9ab9ed MSL: Nit from review. 2024-02-26 15:51:32 +01:00
Jan Sikorski
052c57e2f2 MSL: Pass texture array index separately to atomic texture operations. 2024-02-26 15:51:32 +01:00
Try
ed7a3e3ebb fix codegen for shader with only bindless ssbo 2024-02-04 23:28:58 +01:00
Hans-Kristian Arntzen
9d87a014f0 MSL: Handle volatile properly for emulated image atomics. 2024-01-23 13:09:41 +01:00
Hans-Kristian Arntzen
e9851cc6aa MSL: Fix misc sign issues with dot product impl and add more coverage. 2024-01-16 16:17:43 +01:00
Hans-Kristian Arntzen
b9abac5024 Fix nits from review. 2024-01-16 14:46:16 +01:00
sean
6c24be197f MSL: Add support for SPV_EXT_integer_dot_product 2024-01-16 14:42:56 +01:00
Hans-Kristian Arntzen
57e28e3f58 MSL: Implement spvDescriptorArray path for SSBO/UBO. 2024-01-08 14:15:23 +01:00
Hans-Kristian Arntzen
e10bf53324 MSL: Support variable sized descriptor array in argument buffer. 2024-01-08 12:37:01 +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