Commit Graph

1719 Commits

Author SHA1 Message Date
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
Hans-Kristian Arntzen
5b8762223d Run format_all.sh. 2019-01-07 10:01:28 +01:00
Hans-Kristian Arntzen
649ce3c7bb MSL: Workaround missing gradient2d() for sampler_compare. 2019-01-07 10:01:00 +01:00
Hans-Kristian Arntzen
169607cd28 Merge branch 'master' of git://github.com/JustSid/SPIRV-Cross 2019-01-07 09:07:55 +01:00
Sidney Just
fbb4df3f1a Added support for sampler2DRect and legacy texture2DRect() sampling function 2019-01-06 12:21:59 -08:00
Hans-Kristian Arntzen
211abfb7ef
Merge pull request #799 from KhronosGroup/fix-780
Use correct block-name / other-name aliasing rules.
2019-01-04 16:08:10 +01:00
Hans-Kristian Arntzen
a1249ecc60
Merge pull request #801 from KhronosGroup/fix-787
Register implied expression reads in OpLoad/OpAccessChain.
2019-01-04 16:07:56 +01:00
Hans-Kristian Arntzen
9728f9c1b7 Use correct block-name / other-name aliasing rules.
A block name cannot alias with any name in its own scope,
and it cannot alias with any other "global" name.

To solve this, we need to complicate the name cache updates a little bit
where we have a "primary" namespace and "secondary" namespace.
2019-01-04 15:02:54 +01:00
Hans-Kristian Arntzen
acae607703 Register implied expression reads in OpLoad/OpAccessChain.
This is required to avoid relying on complex sub-expression elimination
in compilers, and generates cleaner code.

The problem case is if a complex expression is used in an access chain,
like:

Composite comp = buffer[texture(...)];
vec4 a = comp.a + comp.b + comp.c;

Before, we did not have common subexpression tracking for
OpLoad/OpAccessChain, so we easily ended up with code like:

vec4 a = buffer[texture(...)].a + buffer[texture(...)].b + buffer[texture(...)].c;

A good compiler will optimize this, but we should not rely on it, and
forcing texture(...) to a temporary also looks better.

The solution is to add a vector "implied_expression_reads", which works
similarly to expression_dependencies. We also need an extra mechanism in
to_expression which lets us skip expression read checking and do it
later. E.g. for expr -> access chain -> load, we should only trigger
a read of expr when using the loaded expression.
2019-01-04 14:56:12 +01:00
Hans-Kristian Arntzen
2154d7f064
Merge pull request #800 from KhronosGroup/update-copyright
Nonfunctional: Update copyright headers for 2019.
2019-01-04 14:16:29 +01:00
Hans-Kristian Arntzen
318c17cbb2 Nonfunctional: Update copyright headers for 2019. 2019-01-04 12:38:35 +01:00
Bill Hollings
ed16b3e699
Merge pull request #785 from billhollings/master
MSL don't emit memory_scope after MSL 2.0.
2018-12-11 17:57:15 -05:00
Bill Hollings
ab329a7906 MSL don't emit memory_scope after MSL 2.0. 2018-12-11 16:28:29 -05:00
Bill Hollings
52f26ee736
Merge pull request #782 from cdavis5e/force-signedness-2
MSL: Use an enum instead of two mutually exclusive booleans.
2018-12-04 22:02:39 +01:00
Chip Davis
6db79b80c1 MSL: Use an enum instead of two mutually exclusive booleans.
NFCI.
2018-12-04 13:54:29 -06:00
Bill Hollings
2cd54e4e6d
Merge pull request #779 from cdavis5e/force-signedness
MSL: Force signedness of shader vertex attributes to match the host.
2018-12-04 09:37:55 -05:00
Chip Davis
06d483459b MSL: Force signedness of shader vertex attributes to match the host.
Based on a patch by Stefan Dösinger.

Metal cannot do signedness conversion on vertex attributes, and for good
reason. Putting a `uint4` into an `int4`, or a `char4` into a `uint4`,
would lose those values that are outside the range of the target type.
But putting a `uchar4` into a `short4` or an `int4`, or a `ushort4` into
an `int4`, should work. In that case, force the signedness in the shader
to match the declared type of the host.

Unfortunately, I don't really know how to automatically test this. This
remapping is done based on input parameters normally supplied by
MoltenVK. I'm not sure how we'd set this up for the command-line
`spirv-cross` tool.
2018-11-28 17:53:56 -06:00
Hans-Kristian Arntzen
1830f7ae8b
Merge pull request #778 from KhronosGroup/fix-777
Support gl_HelperInvocation on GLSL and MSL.
2018-11-28 17:11:19 +01:00
Hans-Kristian Arntzen
61f1d8b2cf Support gl_HelperInvocation on GLSL and MSL.
There is no obvious builtin for this on HLSL.
2018-11-28 15:18:43 +01:00
Hans-Kristian Arntzen
fbae10db15
Merge pull request #776 from lifpan/master
Fix build warning.
2018-11-28 11:34:32 +01:00
lifpan
b21525bcce Fix build warning. 2018-11-28 14:20:24 +08:00
Hans-Kristian Arntzen
2c029fcd49
Merge pull request #775 from KhronosGroup/fix-746
CPP: declare constants.
2018-11-27 12:39:34 +01:00
Hans-Kristian Arntzen
7cb04c7582 CPP: declare constants. 2018-11-27 10:49:19 +01:00
Hans-Kristian Arntzen
84588753dc
Merge pull request #774 from KhronosGroup/fix-770
Keep track of pointer-to-pointer depth in parser.
2018-11-26 13:35:27 +01:00
Hans-Kristian Arntzen
d0b937206f Keep track of pointer-to-pointer depth in parser.
Defer failure of pointer-to-pointer to compilation time, so we can still
reflect VK_KHR_variable_pointer shaders.
2018-11-26 12:23:28 +01:00
Hans-Kristian Arntzen
a89ebba827
Merge pull request #772 from KhronosGroup/fix-771
Fix unsigned switch case selectors.
2018-11-26 11:24:02 +01:00
Hans-Kristian Arntzen
04f410d35c Fix unsigned switch case selectors. 2018-11-26 10:36:50 +01:00
Hans-Kristian Arntzen
cd5cdda13d
Merge pull request #769 from KhronosGroup/fix-761
Handle invariant decoration more robustly.
2018-11-22 22:30:58 +01:00
Hans-Kristian Arntzen
816c1167ce Handle invariant decoration more robustly.
Avoids certain cases of variance between translation units by forcing
every dependent expression of a store to be temporary.
Should avoid the major failure cases where invariance matters.
2018-11-22 11:55:57 +01:00
Hans-Kristian Arntzen
f247b05ffd
Merge pull request #768 from KhronosGroup/fix-764
Remove old hack for dealing with HLSL counter buffers.
2018-11-22 11:17:13 +01:00
Hans-Kristian Arntzen
9aa623a553 Remove old hack for dealing with HLSL counter buffers.
No longer needed.
2018-11-22 10:23:58 +01:00
Hans-Kristian Arntzen
2588309290
Merge pull request #763 from trzecieu/patch-2
Adding C++ syntax coloring for missed snippet
2018-11-19 10:54:15 +01:00
Piotr Paczkowski (trzeci.eu)
30743aa931
Adding C++ syntax coloring for missed snippet 2018-11-19 10:49:49 +01:00
Hans-Kristian Arntzen
7611dc0967
Merge pull request #762 from trzecieu/patch-1
Syntax coloring for C++ snippets in README.md
2018-11-19 10:13:06 +01:00
Piotr Paczkowski (trzeci.eu)
bc6011b512
Syntax coloring for C++ snippets in README.md 2018-11-19 08:52:12 +01:00
Hans-Kristian Arntzen
ea6bdacd05
Merge pull request #760 from KhronosGroup/fix-758
Parser: Handle group decorations.
2018-11-15 12:01:51 +01:00