Commit Graph

1654 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
76bf6d0c34 Fixup some MSL comments. 2019-01-17 11:47:37 +01:00
Hans-Kristian Arntzen
432aaed737 Need to know the original packed type when unpacking loads. 2019-01-17 11:39:46 +01:00
Hans-Kristian Arntzen
40e7723051 Run format_all.sh. 2019-01-17 11:29:50 +01:00
Hans-Kristian Arntzen
f4b74f2f4f Add basic test for std140 small vector arrays. 2019-01-17 11:29:09 +01:00
Hans-Kristian Arntzen
de7e5ccd8b Refactor out packed expressions to extended decorations.
Can't safely just cast to the original enum without lots of hacks.
2019-01-17 11:28:51 +01:00
Hans-Kristian Arntzen
72377366d3 Replace custom use of DecorationCPacked with an explicit one.
Will need to use more variants of this decoration, so might as well make
it clearer what is going on with CPacked.
2019-01-17 10:36:56 +01:00
Hans-Kristian Arntzen
f4026a5618 Refactor access_chain_internal to be more readable from callsite. 2019-01-17 10:30:13 +01:00
Hans-Kristian Arntzen
15b52bee48 Deal with packing/unpacking on store.
Still a bit buggy, since we cannot deduce between float2[] and
packed_float2. Need a deeper refactor to plumb this through ...
2019-01-17 10:06:23 +01:00
Hans-Kristian Arntzen
64ca1ec677 MSL: Start considering float[] and float2[] in std140 layout. 2019-01-16 16:16:39 +01:00
Hans-Kristian Arntzen
9e3a41ad00
Merge pull request #821 from cdavis5e/pass-sampled-images
MSL: Fix passing a sampled image to a function.
2019-01-15 09:05:54 +01:00
Hans-Kristian Arntzen
11b7c5975a
Merge pull request #825 from KhronosGroup/fix-819
MSL: Add option to pad fragment outputs.
2019-01-14 16:34:12 +01:00
Chip Davis
664df22d12 MSL: Fix passing a sampled image to a function.
In the past, SPIRV-Cross threw an error in this case because it couldn't
work out which swizzle from the auxiliary buffer needs to be passed.
Now, we pass the swizzle around with the texture object, like a combined
image-sampler and its associated sampler.
2019-01-14 09:29:31 -06:00
Hans-Kristian Arntzen
b8033d7525 MSL: Add option to pad fragment outputs.
If not enough components are provided in the shader,
the shader MSL compiler throws an error rather than make components
undefined. This hurts portability, so we need to add explicit padding
here.
2019-01-14 15:11:52 +01:00
Hans-Kristian Arntzen
b0f0fb7b7c
Merge pull request #824 from KhronosGroup/fix-751
Fix deadlock on Travis with --parallel.
2019-01-14 14:24:36 +01:00
Hans-Kristian Arntzen
b4faf13c86
Merge pull request #823 from KhronosGroup/fix-818
MSL: Fix case where we pass arrays to functions by value.
2019-01-14 14:24:24 +01:00
Hans-Kristian Arntzen
973b3155c4 Fix deadlock on Travis with --parallel.
We cannot throw any exception or call exit() in an async task, or Python deadlocks.
Catch any errors and propagate them to top thread.
2019-01-14 11:23:46 +01:00
Hans-Kristian Arntzen
7ee04936ac MSL: Fix case where we pass arrays to functions by value.
MSL does not support value semantics for arrays (sigh), so we need to
force constant references and deal with copies if we have a different
address space than what we end up guessing.
2019-01-14 11:00:14 +01:00
Hans-Kristian Arntzen
afb81e036b
Merge pull request #822 from cdavis5e/illegal-identifiers-msl
MSL: Add more illegal identifiers.
2019-01-14 08:57:13 +01:00
Chip Davis
c4b08bd770 MSL: Add more illegal identifiers.
Add most macros from the Metal standard library headers that aren't in
the reserved namespace (i.e. those that don't start with `_`).
2019-01-14 00:08:09 -06:00
Hans-Kristian Arntzen
0d63e89404
Change reference to AppVeyor status 2019-01-11 13:08:05 +01:00
Hans-Kristian Arntzen
6e1c3ccb72 Run format_all.sh. 2019-01-11 12:56:00 +01:00
Hans-Kristian Arntzen
81cb8b54a3
Merge pull request #816 from KhronosGroup/fix-794
HLSL: Support BaseVertex/BaseInstance offsets.
2019-01-11 12:52:50 +01:00
Hans-Kristian Arntzen
4394249b86
Merge pull request #815 from KhronosGroup/fix-811
HLSL: Support dual-source blending.
2019-01-11 12:52:26 +01:00
Hans-Kristian Arntzen
e4e53e8443
Merge pull request #813 from KhronosGroup/fix-781
Optimize SPIR-V ID traversal, make it more correct and be more robust against large ID bounds.
2019-01-11 12:52:11 +01:00
Hans-Kristian Arntzen
a2a44d944e HLSL: Support BaseVertex/BaseInstance offsets.
Opt-in, since user need to know about a cbuffer.
Conflicts a bit with the GLSL option for base instance,
since that one is enabled by default, but the HLSL one isn't (because
user needs to know about a magic cbuffer, whereas GLSL can only get
default initialized uniform).
2019-01-11 10:32:14 +01:00
Hans-Kristian Arntzen
a365ff17bd HLSL: Support dual-source blending. 2019-01-11 10:03:45 +01:00
Hans-Kristian Arntzen
2fb9aa251e Workaround bugs on MSVC.
Bug:
https://developercommunity.visualstudio.com/content/problem/303996/c-error-c2668-ambiguous-overloaded-in-lambda-with.html
2019-01-11 09:29:28 +01:00
Hans-Kristian Arntzen
b82cede208 Iterate over just types in reflection backend. 2019-01-10 14:42:17 +01:00
Hans-Kristian Arntzen
57be90321b Use hashmaps in CFG as well.
The arrays are incredibly sparse for the most part as we only need
entires per basic block.

For a small shader with ID bound of 8 million, we now have about 30x
uplift.
2019-01-10 14:35:34 +01:00
Hans-Kristian Arntzen
b629878f45 Make meta a hashmap.
A flat array was consuming way too much memory and was far too slow to
initialize properly with a very large ID bound (8 million IDs, showed up as #1 hotspot in perf).

Meta struct does not have to be in-order as we never iterate over it in
a meaningful way, so using a hashmap here is reasonable. Very few IDs
should need decorations or meta-data, so this should also be a quite
decent memory save.

For the pathological case, a 6x uplift was observed.
2019-01-10 14:04:01 +01:00
Hans-Kristian Arntzen
d92de00cc1 Rewrite how IDs are iterated over.
This is a fairly fundamental change on how IDs are handled.
It serves many purposes:

- Improve performance. We only need to iterate over IDs which are
  relevant at any one time.
- Makes sure we iterate through IDs in SPIR-V module declaration order
  rather than ID space. IDs don't have to be monotonically increasing,
  which was an assumption SPIRV-Cross used to have. It has apparently
  never been a problem until now.
- Support LUTs of structs. We do this by interleaving declaration of
  constants and struct types in SPIR-V module order.

To support this, the ParsedIR interface needed to change slightly.
Before setting any ID with variant_set<T> we let ParsedIR know
that an ID with a specific type has been added. The surface for change
should be minimal.

ParsedIR will maintain a per-type list of IDs which the cross-compiler
will need to consider for later.

Instead of looping over ir.ids[] (which can be extremely large), we loop
over types now, using:

ir.for_each_typed_id<SPIRVariable>([&](uint32_t id, SPIRVariable &var) {
	handle_variable(var);
});

Now we make sure that we're never looking at irrelevant types.
2019-01-10 12:52:56 +01:00
Hans-Kristian Arntzen
a57b93f6b7
Merge pull request #810 from KhronosGroup/tese-input-array
Fix input array size in tessellation evaluation shaders.
2019-01-09 10:48:25 +01:00
Hans-Kristian Arntzen
ddfd261776 Fix input array size in tessellation evaluation shaders. 2019-01-09 10:47:16 +01:00
Hans-Kristian Arntzen
ff7c4838f9
Merge pull request #809 from KhronosGroup/fix-797
MSL: Add support for emitting structs and arrays within I/O blocks.
2019-01-09 10:35:11 +01:00
Hans-Kristian Arntzen
5345756cab MSL: Support composites inside I/O blocks
I had to refactor the existing add_interface_block as it was
getting extremely large. Now it's all split up into different readable
functions.
2019-01-09 09:33:10 +01:00
Hans-Kristian Arntzen
9c47b2837e
Merge pull request #807 from cdavis5e/variable-pointers
MSL: Support SPV_KHR_variable_pointers.
2019-01-09 09:07:43 +01:00
Chip Davis
d6aa911156 Flush all variables after storing through a variable pointer.
Since we can't know which variable was modified, we therefore have to
conservatively assume that any variable might have been modified.
2019-01-08 15:16:33 -06:00
Chip Davis
fc02b3d656 Rename get_non_pointer_type() methods.
This better reflects their purpose now.
2019-01-08 12:55:22 -06:00
Chip Davis
a046f7a878 Add missing break. 2019-01-08 12:55:22 -06:00
Hans-Kristian Arntzen
a16a181f42
Merge pull request #808 from cdavis5e/fix-identity-mapping
MSL: Fix mapping of identity-swizzled components.
2019-01-08 08:58:54 +01:00
Chip Davis
3394f53734 MSL: Fix mapping of identity-swizzled components.
Before, if any component was not identity-mapped, those components that
were still identity-mapped were set to 0. Now we properly leave them
alone.
2019-01-07 11:20:13 -06:00
Chip Davis
3bfb2f94d4 MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.

This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.

One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.

I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2019-01-07 11:19:10 -06:00
Hans-Kristian Arntzen
b30d21bafd
Merge pull request #806 from KhronosGroup/fix-793
Fix case where OpPhi is used to swap values.
2019-01-07 15:36:23 +01:00
Hans-Kristian Arntzen
d4926a0405 Deal with phi copies which happen inside continue blocks. 2019-01-07 14:24:07 +01:00
Hans-Kristian Arntzen
c8ddf7e7d5 Fix case where OpPhi is used to swap values. 2019-01-07 13:54:16 +01:00
Hans-Kristian Arntzen
9f0a38f191
Merge pull request #805 from KhronosGroup/fix-786
Handle FPRoundingMode decoration.
2019-01-07 13:52:05 +01:00
Hans-Kristian Arntzen
cacfeef89e
Merge pull request #804 from KhronosGroup/fix-788
Forward meta information in OpCompositeExtract.
2019-01-07 11:43:43 +01:00
Hans-Kristian Arntzen
e6cce63679
Merge pull request #803 from KhronosGroup/fix-796
MSL: Workaround missing gradient2d() on macOS for typical cascaded shadow mapping
2019-01-07 10:53:11 +01:00
Hans-Kristian Arntzen
6e5df7a7dd Handle FPRoundingMode decoration.
Doesn't do anything, but we can parse it correctly for now.
2019-01-07 10:51:44 +01:00
Hans-Kristian Arntzen
66263d4569 Forward meta information in OpCompositeExtract.
Just like OpAccessChain we need to make use of the meta information
available to use from access_chain_internal as we can extract a packed
vector or transposed vector from a composite, not just memory load.
2019-01-07 10:43:55 +01:00