Commit Graph

348 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
4e7777c443 Update to latest glslang/SPIRV-Tools.
Fix various bugs along the way.
2019-01-30 13:41:57 +01:00
Hans-Kristian Arntzen
3e09879131 Support initializers on StorageClassOutput. 2019-01-30 10:29:08 +01:00
Hans-Kristian Arntzen
912fde95f1 MSL: Use correct size for structs.
Need to align the size of structs to the natural alignment.
2019-01-28 15:20:30 +01:00
Hans-Kristian Arntzen
217eb5b5f9 MSL: Add a preliminary check for bad arrays of structs.
ArrayStride can be larger than the declared struct size.
We have no obvious solution for now, but warn about it in the MSL output
for the time being.
2019-01-28 15:20:30 +01:00
Hans-Kristian Arntzen
8c632da461 MSL: Use correct alignment rule for whole structs.
Structs are aligned as you would expect in MSL (maximum member
alignment), and it is not minimum 16 bytes like in std140.

Also rename the dummy "pad" members to a reserved naming scheme.
2019-01-28 15:20:30 +01:00
Hans-Kristian Arntzen
18a4accd2f HLSL/MSL: Fix texture projection with Dref.
We need to divide the Dref by q.
2019-01-28 10:25:13 +01:00
Hans-Kristian Arntzen
437fc87a89 MSL: Deal with resource name aliasing.
Apparently we didn't use those yet. MSL seems to be able to alias struct
types and variable types to a degree, so that's why it has escaped
testing until now.
2019-01-18 16:27:57 +01:00
Hans-Kristian Arntzen
1040cf6cc1
Merge pull request #831 from cdavis5e/force-recompile-hooks
MSL: Hoist fixup hooks in entry_point_args() out of the compile loop.
2019-01-17 19:42:05 +01:00
Chip Davis
f500d2f70c MSL: Hoist fixup hooks in entry_point_args() out of the compile loop.
Otherwise, in the event of a forced recompile, we could end up adding
them twice.
2019-01-17 10:18:38 -06:00
Hans-Kristian Arntzen
3aa08f764e MSL: Fix image load/store for short vectors.
Same fixes as for GLSL.
2019-01-17 14:54:29 +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
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
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
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
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
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
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
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
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
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
649ce3c7bb MSL: Workaround missing gradient2d() for sampler_compare. 2019-01-07 10:01:00 +01: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
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
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
04f410d35c Fix unsigned switch case selectors. 2018-11-26 10:36:50 +01:00
Hans-Kristian Arntzen
510e1475c6
Merge pull request #756 from cdavis5e/relaxed-block-layout-2
MSL: Also pack 2- and 4- element vectors when necessary.
2018-11-15 10:09:09 +01:00
Chip Davis
a5882da091 Test loading from and storing to packed vectors. 2018-11-14 10:47:20 -06:00
Chip Davis
6d675ae6a2 Correct carry/borrow bit checks.
Don't use `addsat()`/`subsat()`; that'll erroneously flag cases where
the sum is exactly the maximum integer value, or the difference is
exactly 0. Also, correct the condition for the `select()` function; it's
basically `mix()` with a boolean factor.

(What was I *thinking*?)
2018-11-14 10:13:56 -06:00
Chip Davis
cf2a890e4f MSL: Support extended arithmetic opcodes. 2018-11-13 17:33:03 -06:00
Chip Davis
bed4918cb5 MSL: Also pack 2- and 4- element vectors when necessary.
This is also needed for `VK_KHR_relaxed_block_layout` support.
2018-11-13 17:31:47 -06:00
Hans-Kristian Arntzen
d6be21543d MSL: Split out early_fragment_tests.
Was causing compilation failures, jumped the merge a bit too soon.
2018-11-12 16:20:49 +01:00
Hans-Kristian Arntzen
4e5c8d7199 Deal with depth_greater/depth_less qualifiers.
Adds support on HLSL SM 5.0, and fixes bug on GLSL.
Makes sure early fragment tests is tested on MSL as well.
2018-11-12 10:35:36 +01:00
Connor McLaughlin
1dd676c1de MSL: Emit wrapper for SSign (sign() for int types)
Metal does not define the sign() function for integer types, only
floating-point types.
2018-11-08 13:08:34 +10:00
Chip Davis
e50eecfeeb MSL: Also pack members at unaligned offsets.
This is necessary to support `VK_KHR_relaxed_block_layout`.
2018-11-07 09:42:54 -06:00
Chip Davis
0d949e11ff Support bitcasts of 16-bit types. 2018-11-05 14:56:36 -06:00
Chip Davis
ca4744ab72 Support constants of 16-bit integral type in GLSL and MSL.
Constants of 8-bit type aren't supported in GLSL, since there's no
extension letting you use them.
2018-11-02 14:39:55 -05:00
Chip Davis
1fb27b4cda Add support for 8- and 16-bit types to GLSL and MSL.
In GLSL, 8-bit types require GL_EXT_shader_8bit_storage. 16-bit types
can use either GL_AMD_gpu_shader_int16/GL_AMD_gpu_shader_half_float or
GL_EXT_shader_16bit_storage.
2018-11-01 10:20:57 -05:00
Hans-Kristian Arntzen
480acdad18 Deal with OpSpecConstantOp used as array size.
When trying to validate buffer sizes, we usually need to bail out when
using SpecConstantOps, but for some very specific cases where we allow
unsized arrays currently, we can safely allow "unknown" sized arrays as
well.

This is probably the best we can do, when we have even more difficult
cases than this, we throw a more sensible error message.
2018-11-01 14:58:02 +01:00
Hans-Kristian Arntzen
d4ad1e266a Add test case for local_size_x_id and some complex cases. 2018-11-01 11:23:48 +01:00
Hans-Kristian Arntzen
62db535b3f Update tests. 2018-11-01 11:23:48 +01:00
Hans-Kristian Arntzen
6157bf3cae Add Windows support in Travis CI.
- Add new Windows support
- Use CMake/CTest instead of Make + shell scripts
- Use --parallel in CTest
- Fix CTest on Windows
- Cleanups in test_shaders.py
- Force specific commit for SPIRV-Headers
- Fix Inf/NaN odd-ball case by moving to ASM
2018-10-27 00:22:30 +02:00
Chip Davis
47089a48a0 Make the test case a lot simpler. 2018-10-04 11:26:46 -05:00
Chip Davis
9919fbbe0d MSL: Handle OpImage on OpSampledImage expressions.
I have seen this happen. The included test case is one such case.
2018-10-03 11:48:46 -05:00
Chip Davis
b7433c01ee Minor cleanups.
Throw an error for cases we don't support. Add a blank line after each
local array declaration.
2018-09-27 11:01:46 -05:00
Chip Davis
2506046cb4 Merge remote-tracking branch 'origin' into resource-arrays-msl 2018-09-27 10:50:16 -05:00
Hans-Kristian Arntzen
af75ef005f Update glslang and SPIRV-Tools.
A lot of changes in spirv-opt output.
Some new invalid SPIR-V was found but most of them were not significant
for SPIRV-Cross, so just marked them as invalid.
2018-09-27 11:10:22 +02:00
Chip Davis
3a9af9681c MSL: Expand arrays of buffers passed as input.
Even as of Metal 2.1, MSL still doesn't support arrays of buffers
directly. Therefore, we must manually expand them. In the prologue, we
define arrays holding the argument pointers; these arrays are what the
transpiled code ends up referencing. We might be able to do similar
things for textures and samplers prior to MSL 2.0.

Speaking of which, also enable texture arrays on iOS MSL 1.2.
2018-09-26 20:48:09 -05:00
Chip Davis
7cb817e40e Add spvTexelBufferCoord for buffer image reads, too.
I should've caught this when I fixed this for writes.
2018-09-23 14:37:03 -05:00
Chip Davis
ec857f6778 Cast uses of Layer and ViewportIndex to the expected type. 2018-09-19 09:13:30 -05:00
Chip Davis
0e9ad14ba6 MSL: Handle the ViewportIndex builtin.
This requires MSL 2.0+.

Also, force `ViewportIndex` and `Layer` to be defined as the correct
type, which is always `uint` in MSL.

Since Metal doesn't yet have geometry shaders, the vertex shader (or
tessellation evaluation shader == "post-tessellation vertex shader" in
Metal jargon) is the only kind of shader that can set this output. This
currently requires an extension to Vulkan, which causes validation of
the SPIR-V binaries for the test cases to fail. Therefore, the test
cases are marked "invalid", even though they're actually perfectly valid
SPIR-V--they just won't work without the
`SPV_EXT_shader_viewport_index_layer` extension.
2018-09-18 09:52:30 -05:00
Chip Davis
7dcfed888a Use a hook to emit a local for the sample position.
That way, we don't have to handle it specially when constructing a call.
2018-09-17 11:51:09 -05:00
Chip Davis
72fc1cce53 Merge remote-tracking branch 'origin' into msl-sample-pos 2018-09-17 11:20:34 -05:00
Hans-Kristian Arntzen
a77880787d
Merge pull request #698 from KhronosGroup/fix-695
MSL: Support global I/O block and struct Input/Output usage.
2018-09-17 14:54:58 +02:00
Chip Davis
39bc101e82 MSL: Handle the SamplePosition builtin.
This is somewhat tricky, because in MSL this value is obtained through a
function, `get_sample_position()`. Since the call expression is an
rvalue, it can't be passed by reference, so functions get a copy
instead.

This was the last piece preventing us from turning on sample-rate
shading support in MoltenVK.
2018-09-13 09:34:28 -05:00
Hans-Kristian Arntzen
1bbb4032c8
Merge pull request #693 from cdavis5e/msl-atomic-inc-dec
MSL: Fix OpAtomicIIncrement and OpAtomicIDecrement.
2018-09-13 16:19:27 +02:00
Hans-Kristian Arntzen
d310060f92 MSL: Support global I/O block and struct Input/Output usage.
Implement this by flattening outputs and unflattening inputs explicitly.
This allows us to pass down a single struct instead of dealing with the
insanity that would be passing down each flattened member separately.

Remove stage_uniforms_var_id.
Seems to be dead code. Naked uniforms do not exist in SPIR-V for Vulkan,
which this seems to have been intended for. It was also unused elsewhere.
2018-09-13 16:04:24 +02:00
Chip Davis
986345c754 Fix tests for changes to my last patch. 2018-09-12 09:43:12 -05:00
Hans-Kristian Arntzen
2f65a1583e MSL: Support array-of-arrays composite construction. 2018-09-12 10:25:51 +02:00
Hans-Kristian Arntzen
38d19821d4 MSL: Support copying array of arrays. 2018-09-12 09:54:55 +02:00
Chip Davis
41eb5c43b5 MSL: Fix OpAtomicIIncrement and OpAtomicIDecrement.
We were passing a constant '1' to `emit_atomic_func_op()`--which caused
us to refer to SPIR-V value `%1`, which is almost certainly not what we
want! What we really want is to add/subtract the literal constant '1'
to/from the memory location.
2018-09-11 17:29:54 -05:00
Hans-Kristian Arntzen
403011e973
Merge pull request #684 from cdavis5e/msl-builtin-vector-cast
MSL: Cast uses of builtin vectors to their declared SPIR-V type.
2018-09-11 19:59:58 +02:00
Chip Davis
6757ef8512 Use bitcast_to_builtin_load() instead of hacking to_expression().
This only affects the builtin when it is used, and not when it's passed
to a function. It's a lot cleaner than the way I was doing it before.

Remove the `to_expression()` hack.
2018-09-11 11:15:17 -05:00
Chip Davis
acb3fac747 Opt for a simple value cast in lieu of a bitcast. 2018-09-10 14:05:36 -05:00
Hans-Kristian Arntzen
aa17a02efb Add test shader for composite array initialization. 2018-09-10 10:05:00 +02:00
Hans-Kristian Arntzen
b114889102 Only declare typed initializer list for non-array types.
Also, cleanup now redundant constant_expression virtualization for MSL.
2018-09-10 10:04:17 +02:00
Chip Davis
f7dad9da66 MSL: Cast uses of builtin vectors to their declared SPIR-V type.
In SPIR-V, builtin integral vectors can be either signed or unsigned,
but in MSL they're always unsigned. Unfortunately, the MSL spec forbids
implicit conversions between vector types--even if the corresponding
scalar types would implicitly convert. If you try, the result is a
cryptic error message such as:

```
program_source:37:60: error: cannot convert between vector values of different size ('int4' (aka 'vector_int4') and 'vector_uint4' (vector of 4 'unsigned int' values))
            float4 r3 = as_type<float4>((as_type<int4>(r0) * gl_LocalInvocationID.xyyy) + as_type<int4>(r2));
                                         ~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
```

Therefore, uses of these builtins must be explicitly cast, since the
rest of the binary likely assumes that the builtin is of its declared
type.
2018-09-08 21:17:54 -05:00
Hans-Kristian Arntzen
9ffd4172b4
Merge pull request #680 from cdavis5e/msl-varying-components
MSL: Account for components when assigning locations to varyings.
2018-09-07 16:01:53 +02:00
Hans-Kristian Arntzen
652d8263e5 Use correct spirv-cross version when testing MSL 1.1 shaders. 2018-09-07 09:45:25 +02:00
Hans-Kristian Arntzen
32823b0838 MSL: Do not emit function constants for version < 1.2. 2018-09-07 09:33:34 +02:00
Hans-Kristian Arntzen
9572276a95 Add missing reference file. 2018-09-07 09:29:10 +02:00
Chip Davis
4b99fdd5d0 MSL: Account for components when assigning locations to varyings.
Two varyings (vertex outputs/fragment inputs) might have the same
location but be in different components--e.g. the compiler may have
packed what were two different varyings into a single varying vector.
Giving both varyings the same `[[user]]` attribute won't work--it may
yield unexpected results, or flat out fail to link. We could eventually
pack such varyings into a single vector, but that would require us to
handle the case where the varyings are different types--e.g. a `float`
and a `uint` packed into the same vector. For now, it seems most
prudent to give them unique `[[user]]` locations and let Apple's
compiler work out the best way to pack them.
2018-09-06 13:52:33 -05:00
Chip Davis
674f97a40e Handle interpolation qualifiers on the entire struct, too. 2018-09-06 12:29:42 -05:00
Chip Davis
1e51b235af Add tests showing we don't emit interpolation qualifiers in vertex shaders.
In MSL, these only have an effect on fragment `[[stage_in]]` members.
They have no effect in vertex shaders. The Khronos front end doesn't
even emit the SPIR-V decorations for them.
2018-09-06 12:28:22 -05:00
Chip Davis
9e6469bd40 MSL: Handle interpolation qualifiers. 2018-09-05 12:02:07 -05:00
Chip Davis
1958438f69 Add optimized reference output for added test case. 2018-09-05 10:15:40 -05:00
Chip Davis
9fbe39c9c0 MSL: Emit spvTexelBufferCoord() on ImageWrite to a Buffer as well.
This is necessary to get the coordinates to give to the texture's
`write()` method.
2018-09-04 12:14:34 -05:00
Hans-Kristian Arntzen
917ca818ed
Merge pull request #673 from cdavis5e/min-max-clamp
MSL: Emit F{Min,Max,Clamp} as fast:: and N{Min,Max,Clamp} as precise::.
2018-09-04 15:15:18 +02:00
Chip Davis
b76a330baf Update a bunch of test cases that I missed. 2018-09-03 17:31:15 -05:00
Hans-Kristian Arntzen
93e167eb0f Add some uncommitted reference files. 2018-09-03 12:39:40 +02:00
Hans-Kristian Arntzen
0c1d4d8b6a MSL: Support texture2d_ms_array. 2018-09-03 11:02:31 +02:00
Hans-Kristian Arntzen
778f998cd2 MSL: Throw error on multisampled array textures. 2018-09-03 10:21:59 +02:00
Hans-Kristian Arntzen
f284acae5f MSL: Add test case for gl_FragDepth when used in function. 2018-08-29 09:21:48 +02:00
Hans-Kristian Arntzen
87de951105 MSL: Fix naming issue of aliased global variables.
When the name of an alias global variable collides with a global
declaration, MSL would emit inconsistent names, sometimes with the
naming fix, sometimes without, because names were being tracked in two
separate meta blocks. Fix this by always redirecting parameter naming to
the original base variable as necessary.
2018-08-27 09:59:55 +02:00
Hans-Kristian Arntzen
981d7c1d85 Need to make sure the fetch expression is uint. 2018-08-07 16:02:17 +02:00
Hans-Kristian Arntzen
eee290a029 MSL: Fix support for texelFetchOffset.
Just apply the offset directly, MSL has no immediate offset parameter.
2018-08-07 15:28:04 +02:00
Hans-Kristian Arntzen
361fe52c9d MSL: Properly support passing parameters by value.
MSL would force thread const& which would not work if the input argument
came from a different storage class.

Emit proper non-reference arguments for such values.
2018-08-06 15:43:51 +02:00
Bill Hollings
c3d74e1e14 CompilerMSL disable rasterization on buffer writes in vertex shader. 2018-07-27 16:53:36 -04:00
Bill Hollings
ac238b858b CompilerMSL vertex entry point return void when rasterization disabled.
Add CompilerMSL::Options::disable_rasterization input/output API flag.
Disable rasterization via API flag or when writing to textures.
Disable rasterization when shader declares no output.
Add test shaders for vertex no output and write texture forcing void output.
2018-07-26 00:50:33 -04:00
Hans-Kristian Arntzen
2bf57d6dff Deal with composite constants in variable initializer. 2018-07-05 15:29:49 +02:00
Hans-Kristian Arntzen
dcddd5326e Add LUT test cases for OpVariable with initializer. 2018-07-05 14:51:07 +02:00
Hans-Kristian Arntzen
af290ede87 Remove some redundant spvArrayCopy declarations. 2018-07-05 14:43:12 +02:00
Hans-Kristian Arntzen
5582523d9a Add some tests for LUT promotion.
Also, update other tests.
2018-07-05 14:14:18 +02:00
Hans-Kristian Arntzen
d29f48ef06 Deduce constant LUTs from read-write variables. 2018-07-05 13:25:57 +02:00
Hans-Kristian Arntzen
e044732896 Support OpTypeImage with depth == 2 (unknown) properly.
Track which OpSampledImages are ever used with Dref opcodes.
2018-07-04 14:26:23 +02:00
Bill Hollings
4c5142b9d3 CompilerMSL support larger texel buffers by using 2D Metal textures.
Add CompilerMSL::Options::texture_width_max.
Emit and use spvTexelBufferCoord() function to convert 1D
texel buffer coordinates to 2D Metal texture coordinates.
2018-06-26 17:30:21 -04:00
Bill Hollings
4beefe756c Fixes from PR 621 code review. 2018-06-25 11:40:20 -04:00
Bill Hollings
f66507a701 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2018-06-25 10:52:15 -04:00
Hans-Kristian Arntzen
ffa9133d77 Support ternary expressions in OpSpecConstantOp. 2018-06-25 09:49:13 +02:00
Bill Hollings
e091031613 CompilerMSL pass builtin struct members into functions.
Add and use Compiler::get_non_pointer_type() convenience functions.
2018-06-24 15:06:12 -04:00
Hans-Kristian Arntzen
d94d20f4f3 Deal with some builtins being declared with wrong signedness. 2018-06-22 11:30:56 +02:00
Bill Hollings
ac57a30ad6 Regenerate MSL shaders to fix conflicts from merge. 2018-06-12 11:51:56 -04:00
Bill Hollings
ab2ea93e35 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2018-06-12 11:42:56 -04:00
Bill Hollings
9b4defe202 CompilerMSL support matrices & arrays in stage-in & stage-out.
Support flattening StorageOutput & StorageInput matrices and arrays.
No longer move matrix & array inputs to separate buffer.
Add separate SPIRFunction::fixup_statements_in & SPIRFunction::fixup_statements_out
instead of just  SPIRFunction::fixup_statements.
Emit SPIRFunction::fixup_statements at beginning of functions.
CompilerMSL track vars_needing_early_declaration.
Pass global output variables as variables to functions that access them.
Sort input structs by location, same as output structs.
Emit struct declarations in order output, input, uniforms.
Regenerate reference shaders to new formats defined by above.
2018-06-12 11:41:35 -04:00
Hans-Kristian Arntzen
58fab58e5e Do not unpack transposed matrices. 2018-06-12 09:43:47 +02:00
Hans-Kristian Arntzen
192a882df3 Also unpack regular unary/binary operations on MSL.
Apparently MSL gets confused when you have packed_float3 op float3 ...
2018-06-11 16:23:09 +02:00
Hans-Kristian Arntzen
b86bd0a265 Unpack expressions when used in functions on MSL.
OSX 10.14 broke (?) how overload resolution works,
so overloading e.g. dot(float3, packed_float3) no longer works.

Fix this by unpacking expressions before various func ops.
This fix might need to be applied elsewhere, but do so later if needed.
2018-06-11 10:56:45 +02:00
Hans-Kristian Arntzen
04b149feb0 Fix image load/store on cube arrays in MSL. 2018-05-25 12:43:25 +02:00
Hans-Kristian Arntzen
f65120c147 Deal with packed expressions in more scenarios.
Make a new "to_extract_component_expression" helper.
2018-05-25 10:57:02 +02:00
Hans-Kristian Arntzen
280fb93204 Add test for reading SSBO from fragment shader on MSL. 2018-05-25 10:20:17 +02:00
Hans-Kristian Arntzen
6b3da831be Declare read-only SSBOs as const device in MSL. 2018-05-25 10:14:05 +02:00
Hans-Kristian Arntzen
46bf17c5d3 Add SREM tests for HLSL/MSL. 2018-05-24 10:34:36 +02:00
Hans-Kristian Arntzen
bcaae84c76 Deal with scoping for Private variables. 2018-05-16 10:49:30 +02:00
Hans-Kristian Arntzen
26b887ec99 Fix atomic_compare_exchange_weak_explicit.
Need to emit a CAS loop.
Fix shared memory declaration.
Declare atomic ops with correct memory scope.
2018-05-15 16:04:21 +02:00
Hans-Kristian Arntzen
991b655c72 Declare OpSpecConstantOp up-front on relevant targets.
Required, since spec constants can include results from constant ops.
2018-05-15 14:20:16 +02:00
Hans-Kristian Arntzen
7eba247864 Handle inout properly with split access chains.
Found some other issues. Had some bugs with variable writes not properly
invalidating if writes came from split access chains.
2018-05-11 10:15:42 +02:00
Pascal Muetschard
aced6058b4 Don't limit GLSL identifiers with HLSL keywords.
- The HLSL compiler now has its own list of keywords in addition to
   the ones from GLSL.
 - Added "buffer", "precise", and "shared" to the GLSL keywords.
2018-05-07 10:58:52 -07:00
Hans-Kristian Arntzen
85a8f066f4 Do not use RMW rewrite for matrices.
Does not work on MSL.
2018-05-04 10:35:56 +02:00
Hans-Kristian Arntzen
d2df067dd4 Force recompile if we add row-major transpose functions in MSL. 2018-05-04 09:43:34 +02:00
Hans-Kristian Arntzen
3187d89c31 Reduce test case ... MSL can't deal with certain unusual cases yet. 2018-05-02 10:01:08 +02:00
Hans-Kristian Arntzen
f3e810b8b3 Fix OpCompositeConstruct with arrays in MSL. 2018-05-02 09:38:41 +02:00
Bill Hollings
57213cb7ca Compiler MSL default gather offset when component specified. 2018-04-30 16:30:29 -04:00
Hans-Kristian Arntzen
47081f810a Fix GatherDref on GLSL. 2018-04-30 12:45:23 +02:00
Hans-Kristian Arntzen
d93807a625 Deal with OpImageFetch without explicit LOD. 2018-04-30 10:54:44 +02:00
Hans-Kristian Arntzen
aaf397cd1f Fix usage tracking issue for OpImage. 2018-04-27 11:11:24 +02:00
Hans-Kristian Arntzen
0280800a8f Fix case where SampledImage would get flushed to temporary. 2018-04-27 10:06:30 +02:00
Hans-Kristian Arntzen
146ea76f52 Add test shader for subgroup.
Update SPIRV-Tools/glslang commits.
Use vulkan1.1 environment for testing.
Found new "errors" in SPIRV-Tools, so disable validation on those shaders
for now.
2018-04-11 10:29:47 +02:00
Hans-Kristian Arntzen
8175e2e200 Fix depth compare textures when used in functions without argument. 2018-04-10 12:31:13 +02:00
Hans-Kristian Arntzen
694b314f87 Support empty structs.
Need to fake it by pretending it has one dummy member.
2018-04-05 16:26:54 +02:00
Hans-Kristian Arntzen
ac81a0ce68 Use declared binding in SPIR-V as a fallback for explicit MSL binds. 2018-04-04 12:25:11 +02:00
Hans-Kristian Arntzen
e8ca39b7b5 Add test for sampler image arrays. 2018-04-04 09:41:20 +02:00
Hans-Kristian Arntzen
81eb72a9a0 Ignore LOD when sampling 1D textures in MSL.
Not supported.
2018-04-04 09:26:53 +02:00
Hans-Kristian Arntzen
65be63fd04
Merge pull request #521 from KhronosGroup/fix-516
Support dual-source blending on GLSL and MSL.
2018-04-03 16:54:32 +02:00
Hans-Kristian Arntzen
a6e211e00b Support dual-source blending on GLSL and MSL. 2018-04-03 16:04:49 +02:00
Hans-Kristian Arntzen
3229e6efb6 Add more illegal name replacement in MSL. 2018-04-03 15:36:35 +02:00
Hans-Kristian Arntzen
c1947aa447 Update glslang/SPIRV-Tools on Travis. 2018-03-24 04:16:18 +01:00
Hans-Kristian Arntzen
8e90382675 Properly flatten MRT outputs in MSL. 2018-03-13 14:03:35 +01:00
Hans-Kristian Arntzen
6e6ca0b237 Attempt MRT-as-array in MSL. 2018-03-13 13:17:17 +01:00
Hans-Kristian Arntzen
b46910e9f5 Access chain into packed vectors as arrays.
Cleaner and should be more compatible with storing to packed vector
elements.

Fix CompositeExtract bug with packed vectors on MSL.
2018-03-13 12:13:33 +01:00
Hans-Kristian Arntzen
e7bf8d2f48 Refactor out noopt shaders to their own folders.
Makes maintenance easier with less clutter.
2018-03-13 10:39:49 +01:00
Hans-Kristian Arntzen
4979d10b54 Implement packHalf2x16/unpackHalf2x16 on MSL. 2018-03-12 17:51:14 +01:00
Hans-Kristian Arntzen
938c7debed Handle control-dependent temporaries.
Derivatives, subgroup and implicit-lod instructions all need to happen
in the block they were created.
2018-03-12 17:34:54 +01:00
Hans-Kristian Arntzen
9fbd8b789e Update tests for latest SPIRV-Tools and glslang. 2018-03-12 15:11:55 +01:00
Hans-Kristian Arntzen
e3b8e9455c Add test shader where a phi variable invalidates a temporary.
The temporary in question is used to flush a phi variable.
2018-03-09 14:42:26 +01:00
Hans-Kristian Arntzen
e0efa737ca Expand the implementation of inherit_expression_dependencies. 2018-03-09 13:21:38 +01:00
Hans-Kristian Arntzen
922420e346 Disallow arrays and structs from becoming loop variables.
Fixes awkward code-gen issue.
2018-03-07 14:54:11 +01:00
Hans-Kristian Arntzen
bdabd0c73a Disable double test in MSL FP16 tests. 2018-03-07 11:36:26 +01:00
Hans-Kristian Arntzen
18ad1be3c3 Add FP16 test for MSL as well. 2018-03-07 10:29:11 +01:00
Hans-Kristian Arntzen
38d9d8af68 Add some more MSL test shaders. 2018-03-05 16:42:38 +01:00
Hans-Kristian Arntzen
5fe79eb59c Update tests.
Adds an earlier reported shader packing failure into regression suite.
2018-03-05 16:34:42 +01:00
Hans-Kristian Arntzen
6a12ff7fb7 Fix multiple declaration of spvDet2x2 on MSL. 2018-02-23 16:52:11 +01:00
Hans-Kristian Arntzen
dd603eab58 Support spec constant array size in blocks.
Won't really be correct if the spec constant is changed outside
SPIRV-Cross, but nothing we can do about that, really.
2018-02-23 15:11:45 +01:00
Hans-Kristian Arntzen
a04bdcc7f7 Handle overloaded functions which share the same OpName.
Awkward, but legal SPIR-V.
2018-02-23 14:15:51 +01:00
Hans-Kristian Arntzen
047ad7df0f Support special float constants (NaN/Inf). 2018-02-23 13:06:20 +01:00
Bill Hollings
50ef6cd95f CompilerMSL remove incorrect packing of non-interface type-aliased structs. 2018-02-21 17:52:03 -05:00
Hans-Kristian Arntzen
8a3bef2bd6 Add OpFRem tests. 2018-02-15 13:36:59 +01:00
Hans-Kristian Arntzen
843e34b604 Add IsFrontFace support to HLSL. 2018-02-15 12:42:56 +01:00
Bill Hollings
2964e328e6 CompilerMSL support gl_SampleMask and convert it to scalar uint from array. 2018-02-13 14:44:40 -05:00
Bill Hollings
b453348370 Merge branch 'master' of https://github.com/billhollings/SPIRV-Cross 2018-02-11 16:54:25 -05:00
Bill Hollings
607b0d6d42 CompilerMSL support smaller offsets for 3-row row-major matrices.
Support MSL typedefs to declare 3-row row-major matrices as 3-column matrices.
Allow those matrices to be decorated as packed.
Support transposing those matrices when used.
Modify how member alignments are calculated.
2018-02-11 16:52:57 -05:00
Hans-Kristian Arntzen
a3ae861844 Fix depth image usage in MSL for separate image/samplers. 2018-02-10 10:55:10 +01:00
Hans-Kristian Arntzen
702e08671b Support passing implicit frag_coord arguments down to functions. 2018-02-10 10:55:09 +01:00
Hans-Kristian Arntzen
c9db3e5521 Overload on constant storage. 2018-02-08 17:58:46 +01:00
Hans-Kristian Arntzen
b2c9487b0f Attempt to deduce constant/thread storage. 2018-02-08 17:07:50 +01:00
Hans-Kristian Arntzen
1a9c960058 MSL cannot declare inline arrays except in certain cases. 2018-02-08 13:06:29 +01:00
Hans-Kristian Arntzen
00ccd590ee Return arrays in HLSL/MSL by writing to an output variable instead. 2018-02-08 12:22:08 +01:00
Hans-Kristian Arntzen
9fa91f7e1c Support returning arrays from functions in GLSL/MSL.
Not possible in HLSL apparently, need workaround ...
2018-02-08 12:22:08 +01:00
Hans-Kristian Arntzen
5d9df6a31c Do not declare constant composites inline in HLSL.
Move arrays and structs out to their own global static constants.

Also, replace illegal names in HLSL as well.
2018-02-02 10:12:26 +01:00
Hans-Kristian Arntzen
d1399f01ab Update reference file after merge. 2018-02-01 09:14:45 +01:00
Hans-Kristian Arntzen
4c1e57ee03
Merge pull request #413 from zeux/master
MSL: Order resources by type and binding index in the output
2018-02-01 09:01:34 +01:00
Arseny Kapoulkine
5cbed7a69f Update test files 2018-01-29 06:40:45 -08:00
Hans-Kristian Arntzen
38b8f733d1 Fix passing arrays of arrays to functions in MSL. 2018-01-29 10:57:52 +01:00
Hans-Kristian Arntzen
6714a9fa23 Need to sort declared temporaries to ensure stable output. 2018-01-29 10:24:15 +01:00
Bill Hollings
e43f244399 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2018-01-24 17:34:50 -05:00
Bill Hollings
fe3683eefa CompilerMSL declare threadgroup variables accessed in called functions. 2018-01-24 15:38:17 -05:00
Hans-Kristian Arntzen
b3f6e3de8e Fix CFG::update_common_dominator.
The algorithm was too conservative causing lots of unnecessary
temporaries to be created.
2018-01-24 20:32:11 +01:00
Hans-Kristian Arntzen
09f550f718 Handle exponential explosion of code-gen during first phase of compile.
Certain patterns with OpVectorShuffle (and probably others) will cascade
to so large, that they can cause OOM. After we have observed
force_recompile, don't spend unnecessary memory emitting code which will
never be used.
2018-01-24 18:12:41 +01:00
Hans-Kristian Arntzen
af0a887997 Add test for false loop init.
Clean up how for loop variables are declared.
2018-01-23 21:15:09 +01:00
Hans-Kristian Arntzen
7d223b8987 Fix CFG for forwarded temporaries.
Forwarded temporaries would never declare a temporary.
Figure out all result types ahead of time so we can deal with those
temporaries as well.
2018-01-18 12:11:33 +01:00
Hans-Kristian Arntzen
168bcc7b3b Add unreachable tests for MSL/HLSL. 2018-01-15 09:39:15 +01:00
Hans-Kristian Arntzen
d4e470babd Analyze the CFG for temporaries as well.
Normally, temporary declaration must dominate any use of it,
so we generally did not need to analyze the CFG for these variables,
but there is an edge case where you have an inliner doing:

do {
	create_temporary;
	break;
} while(0);

use_temporary;

The inside of the loop dominates the outer scope, but we cannot emit
code like this in GLSL, so make sure we hoist these temporaries outside
the "loop".
2018-01-12 10:56:11 +01:00
Hans-Kristian Arntzen
39e7ddea94 Disable mem_texture checks on MSL.
Doesn't seem to work on Travis even though spec says it should, oh well
:)
2018-01-09 14:09:29 +01:00
Hans-Kristian Arntzen
cfe568f237 Add exhaustive barrier tests for MSL.
Seems incorrect, need to be fixed later.
2018-01-09 12:55:46 +01:00
Bill Hollings
27d4af75a0 Revert to not forcing gl_in/gl_out block for MSL, and add MSL gl_ClipDistance tests. 2018-01-08 16:18:34 -05:00
Bill Hollings
5ee6b46087 Fixes from review of PR #373.
Code fixes from review.
Refactor MSL tests back to using the SPIRV-Tools
and glslang loaded by checkout_glslang_spirv_tools.sh.
2018-01-05 23:22:36 -05:00
Bill Hollings
d8d2da9d8d CompilerMSL allow swizzle of packed_float3 vectors by unpacking to float3.
Pass packed indicator back through OpAccessChain and OpLoad.
Unpack packed vector before applying swizzle.
Add packed swizzle test.
2018-01-05 17:46:56 -05:00
Bill Hollings
95910ddd5a MSL test shader refactoring to avoid optimization crashes. 2017-12-26 18:40:46 -05:00
Hans-Kristian Arntzen
aa2557c7df Fixups for PR #353. 2017-12-05 09:58:12 +01:00
Bill Hollings
12988801c4 Update reference shaders in reference/opt/shaders-msl.
Remove shaders-msl/comp/bake_gradient.comp, which now breaks spirv-opt.
2017-12-04 18:17:06 -05:00
Hans-Kristian Arntzen
f929078f1e Disable --opt for in_block_assign for now.
Bug: OpLoad fails when loading an interface struct directly, followed by
OpCompositeExtract. This should be fixed, but not critical enough to
block this PR.
2017-11-23 09:59:25 +01:00
Hans-Kristian Arntzen
8e14eadb95 Disable opts for loop on MSL as well. 2017-11-23 09:59:25 +01:00
Hans-Kristian Arntzen
65cd417630 Do not hoist OpUndef variables. 2017-11-23 09:59:25 +01:00
Hans-Kristian Arntzen
3ce6b2a23b Make bitfield test noopt for now.
SPIRV-Tools trips assertion.
2017-11-23 09:59:25 +01:00
Hans-Kristian Arntzen
7238e57933 Enforce stable order for dominated phi variables. 2017-11-23 09:59:25 +01:00
Hans-Kristian Arntzen
c52776af78 Update to correct SPIRV-Tools revision. 2017-11-23 09:59:21 +01:00
Hans-Kristian Arntzen
b39e829fc2 Add reference output for --opt. 2017-11-23 09:50:11 +01:00