Mark Satterthwaite
97a66ff906
On iOS sub-passes can be implemented using the frame-buffer fetch API which is much more efficient than binding the textures. Change was made in three parts. 1. Use Metal's native frame-buffer fetch API for subpass inputs. 2. Make sure that frame-buffer-fetch is only available on iOS. 3. Default to using Metal's native frame-buffer fetch for subpass inputs on iOS.
2019-09-09 15:02:11 -04:00
Mark Satterthwaite
32557e9093
SPIRV doesn't distinguish depth textures from regular textures, but Metal does, so if we've ever seen a depth comparison operation we must ensure that the texture is specified as a depth-texture.
2019-09-06 16:58:27 -04:00
Mark Satterthwaite
5e8590a23d
Emulate texture atomics in Metal by binding the underlying buffer that backs the resource to a separate binding point and using that for Metal's atomic operations. This will work with texture_buffer and texture2d created from an MTLBuffer, so is perfect for emulating HLSL atomics on RWBuffer and sufficient, but not ideal, for RWTexture2D with some restrictions (limited format support and can't be used for render-targets).
2019-09-05 15:13:28 -04:00
Mark Satterthwaite
239e04762b
Support Metal 2.1's texture_buffer type which is the equivalent to HLSL's Buffer/RWBuffer, so doesn't require modifying buffer sizes to match alignments.
2019-09-05 14:46:15 -04:00
Mark Satterthwaite
8596bf5ee2
In order to use Metal shader libraries properly you have to ensure that you have no duplicated global symbol names for different entities, otherwise 'metallib' won't be able to combine multiple shaders into a single library. This is broken into two parts. 1. Constant arrays of non-primitive types (i.e. matrices) won't link properly into Metal libraries. 2. Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib.
2019-09-05 14:39:06 -04:00
Mark Satterthwaite
d50659af92
Rework the way arrays are handled in Metal to remove the array copies as they are unnecessary from Metal 1.2. There were cases where copies were not being inserted and others appeared unncessary, using the template type should allow the 'metal' compiler to do the best possible optimisation. The changes are broken into three stages. 1. Allow Metal to use the array<T> template to make arrays a value type. 2. Force the use of C style array declaration for some cases which cannot be wrapped with a template. 3. Threadgroup arrays can't have a wrapper type. 4. Tweak the code to use unsafe_array in a few more places so that we can handle passing arrays of resources into the shader and then through shaders into sub-functions. 5. Handle packed matrix types inside arrays within structs. 6. Make sure that builtin arguments still retain their array qualifiers when used in leaf functions. 7. Fix declaration of array-of-array constants for Metal so we can use the array<T> template.
2019-09-05 12:39:44 -04:00
Chip Davis
39dce88d3b
MSL: Add support for sampler Y'CbCr conversion.
...
This change introduces functions and in one case, a class, to support
the `VK_KHR_sampler_ycbcr_conversion` extension. Except in the case of
GBGR8 and BGRG8 formats, for which Metal natively supports implicit
chroma reconstruction, we're on our own here. We have to do everything
ourselves. Much of the complexity comes from the need to support
multiple planes, which must now be passed to functions that use the
corresponding combined image-samplers. The rest is from the actual
Y'CbCr conversion itself, which requires additional post-processing of
the sample retrieved from the image.
Passing sampled images to a function was a particular problem. To
support this, I've added a new class which is emitted to MSL shaders
that pass sampled images with Y'CbCr conversions attached around. It
can handle sampled images with or without Y'CbCr conversion. This is an
awful abomination that should not exist, but I'm worried that there's
some shader out there which does this. This support requires Metal 2.0
to work properly, because it uses default-constructed texture objects,
which were only added in MSL 2. I'm not even going to get into arrays of
combined image-samplers--that's a whole other can of worms. They are
deliberately unsupported in this change.
I've taken the liberty of refactoring the support for texture swizzling
while I'm at it. It's now treated as a post-processing step similar to
Y'CbCr conversion. I'd like to think this is cleaner than having
everything in `to_function_name()`/`to_function_args()`. It still looks
really hairy, though. I did, however, get rid of the explicit type
arguments to `spvGatherSwizzle()`/`spvGatherCompareSwizzle()`.
Update the C API. In addition to supporting this new functionality, add
some compiler options that I added in previous changes, but for which I
neglected to update the C API.
2019-09-01 18:35:53 -05:00
Hans-Kristian Arntzen
9b845a4788
Merge pull request #1141 from troughton/inline-everything
...
MSL: Inline all non-entry-point functions
2019-08-30 11:05:04 +02:00
Thomas Roughton
6b5403206e
Clang-format changes
2019-08-30 20:25:40 +12:00
Hans-Kristian Arntzen
07c76f66b5
MSL: Add {Base,}{Vertex,Instance}Index to bitcast_from_builtin_load.
...
Totally missed these, so float(index) would not work correctly for
negative numbers.
2019-08-29 13:56:37 +02:00
Thomas Roughton
e5f9e2c203
Inline all non-entry-point functions
2019-08-29 17:07:57 +12:00
Thomas Roughton
6338f0aa0f
MSL: inline all emitted functions
...
# Conflicts:
# spirv_msl.cpp
2019-08-29 17:07:27 +12:00
Hans-Kristian Arntzen
3ccfbce264
Run format_all.sh.
2019-08-28 14:25:26 +02:00
Hans-Kristian Arntzen
9436cd3036
MSL: Deal with array copies from and to threadgroup.
2019-08-27 13:18:01 +02:00
Hans-Kristian Arntzen
b3305799a8
Deal correctly with sign on bitfield operations.
...
Need a lot of special purpose implementation functions for these.
2019-08-26 11:36:36 +02:00
Hans-Kristian Arntzen
ffca8735ff
Merge pull request #1105 from cdavis5e/msl-unify-as
...
MSL: Unify the get_*_address_space() methods.
2019-07-29 10:19:12 +02:00
Chip Davis
df18d98bea
MSL: Unify the get_*_address_space() methods.
...
These methods have largely the same logic, with minor differences. That
I felt compelled to duplicate the logic into another method was one of
the things that bothered me about the variable pointers change. This
cleans that part of the code up; now we don't have two places to change.
2019-07-26 09:43:28 -05:00
Hans-Kristian Arntzen
d378413040
Merge pull request #1103 from KhronosGroup/fix-1100
...
MSL: Cleanup temporary use with emit_uninitialized_temporary.
2019-07-26 14:35:18 +02:00
Hans-Kristian Arntzen
c3e8e728d8
MSL: Cleanup temporary use with emit_uninitialized_temporary.
2019-07-26 11:16:43 +02:00
Hans-Kristian Arntzen
abb345d0b3
MSL: Deal with Modf/Frexp where output is access chain to scalar.
...
This is not allowed as we cannot take mutable reference to a
vec.{x,y,z,w}. We only care about scalar since entire vectors are fine.
2019-07-26 11:02:38 +02:00
Hans-Kristian Arntzen
3c03b55c46
Workaround MSVC 2013 compiler issues.
2019-07-25 10:28:11 +02:00
Chip Davis
fb5ee4cb5c
MSL: Adjust BuiltInWorkgroupId for vkCmdDispatchBase().
...
This command allows the caller to set the base value of
`BuiltInWorkgroupId`, and thus of `BuiltInGlobalInvocationId`. Metal
provides no direct support for this... but it does provide a builtin,
`[[grid_origin]]`, normally used to pass the base values for the stage
input region, which we will now abuse to pass the dispatch base and
avoid burning a buffer binding.
`[[grid_origin]]`, as part of Metal's support for compute stage input,
requires MSL 1.2. For 1.0 and 1.1, we're forced to provide a buffer.
(Curiously, this builtin was undocumented until the MSL 2.2 release. Go
figure.)
2019-07-24 08:56:15 -05:00
Hans-Kristian Arntzen
c62503bca7
Do not attempt to pack types which are already scalar.
2019-07-24 11:52:28 +02:00
Hans-Kristian Arntzen
646e04294a
Fix some warnings when building in MoltenVK.
2019-07-23 16:39:13 +02:00
Hans-Kristian Arntzen
5c1cb7accf
Recursively pack struct types when we find scalar packed structs.
2019-07-23 15:24:53 +02:00
Hans-Kristian Arntzen
3fa2b14634
Run format_all.sh.
2019-07-23 12:23:41 +02:00
Hans-Kristian Arntzen
7277c7ac46
Use to_unpacked_row_major_expression to unify row-major in MSL/GLSL.
2019-07-23 11:36:54 +02:00
Hans-Kristian Arntzen
47a18b9f1b
Simplify row-major matrix/vector multiplies.
2019-07-23 10:56:57 +02:00
Hans-Kristian Arntzen
6224199c76
Add struct size padding tests.
2019-07-23 10:30:37 +02:00
Hans-Kristian Arntzen
2172b19be2
Remove obsolete matrix workaround code.
2019-07-22 16:27:47 +02:00
Hans-Kristian Arntzen
609d087f8f
Only transpose unpacked expressions.
2019-07-22 16:06:09 +02:00
Hans-Kristian Arntzen
6057ffcbb1
Deal correctly with complete stores to row_major matrices.
2019-07-22 15:49:17 +02:00
Hans-Kristian Arntzen
19f5cd3e90
Declare correct matrix type when unpacking.
2019-07-22 13:25:45 +02:00
Hans-Kristian Arntzen
f2d6a77c95
Don't forget to register a write to LHS expression in certain case.
2019-07-22 13:06:30 +02:00
Hans-Kristian Arntzen
745a2f7b0e
Deal with swizzled stores to std140 matrices.
2019-07-22 13:05:23 +02:00
Hans-Kristian Arntzen
180a6b38c5
Fix some row-major column store cases.
2019-07-22 12:56:14 +02:00
Hans-Kristian Arntzen
4ab2829cf6
Fix more stray parens.
2019-07-22 12:13:07 +02:00
Hans-Kristian Arntzen
d6004bfc97
Fixup stray parent in output.
2019-07-22 12:08:56 +02:00
Hans-Kristian Arntzen
14afb968dd
Correctly unpack row-major matrices when storing to LHS.
2019-07-22 12:03:12 +02:00
Hans-Kristian Arntzen
249f8e5180
MSL: Support storing to row-major column.
...
Defer transposes to actual Load or Store.
2019-07-22 11:13:44 +02:00
Hans-Kristian Arntzen
be2fccd837
Tests run clean.
2019-07-22 10:23:39 +02:00
Hans-Kristian Arntzen
b66a53a979
Traverse correct types when checking scalar layout.
2019-07-19 14:43:42 +02:00
Hans-Kristian Arntzen
e90d816cdd
Deal with scalar layout of entire structs.
...
Mark all candidate struct types.
2019-07-19 14:18:14 +02:00
Hans-Kristian Arntzen
12c5020854
Pass down row-major state to unpacking functions.
2019-07-19 13:03:08 +02:00
Hans-Kristian Arntzen
27b75c2c5a
Deal with all forms of matrix writes ...
2019-07-19 12:53:10 +02:00
Hans-Kristian Arntzen
f6251e4699
Can deal with std140 matrices now.
...
Refactor is coming together.
2019-07-19 11:21:02 +02:00
Hans-Kristian Arntzen
dd7ebaf9f7
Start considering how to emit physical type ID.
2019-07-19 10:06:19 +02:00
Hans-Kristian Arntzen
b09b8d3fa9
Deal more cleanly with matrices and row-major.
2019-07-19 10:06:19 +02:00
Hans-Kristian Arntzen
c160d5227f
Reintroduce struct_member_* MSL queries.
...
Need to remap to physical type + packed qualifier, and this is handy to
do in a helper function.
2019-07-19 10:06:19 +02:00
Hans-Kristian Arntzen
a86308bce1
MSL: Begin rewrite of buffer packing logic.
2019-07-19 10:06:19 +02:00