Commit Graph

174 Commits

Author SHA1 Message Date
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
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
680ef9d773 MSL: Correct number of words to skip in OpImageWrite.
The length field in `Instruction` doesn't include the initial
opcode/length word. We only need to skip three words instead of four.
2018-09-05 10:02:25 -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
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
Chip Davis
27af716c3a MSL: Emit F{Min,Max,Clamp} as fast:: and N{Min,Max,Clamp} as precise::.
This roughly matches their semantics in SPIR-V and MSL. For `FMin`,
`FMax`, and `FClamp`, and the Metal functions `fast::min()`,
`fast::max()`, and `fast::clamp()`, the result is undefined if any
operand is NaN. For the 'N' operations and their corresponding MSL
`precise::` functions, the result is consistent with IEEE 754 (first
non-NaN wins; result is NaN if all operands are NaN).

We can only do this with 32-bit floats, though, because Metal only
provides these variants for `float`. `half` only has one variant of
these functions that is presumably consistent with IEEE 754. I guess
that's OK; the SPIR-V spec only says that `F{Min,Max,Clamp}` are
undefined for NaNs. Performance might suffer, though.
2018-09-01 23:01:46 -05:00
Chip Davis
0829a786d2 Add tests for FUnord comparisons of vectors. 2018-09-01 12:42:07 -05:00
Chip Davis
d3233690cb MSL: Support unordered relational operators.
The SPIR-V spec says that these check if the operands either are
unordered or satisfy the given condition. So that's just what we'll do,
using Metal's `isunordered()` stdlib function. Apple's optimizers ought
to be able to collapse that to a single unordered compare.
2018-08-31 13:54:42 -05:00
Chip Davis
94f33dc566 Fix MSL shader_draw_parameters reference output. 2018-08-29 14:17:11 -05:00
Chip Davis
e00e5b3b2c Appease tests that check for exact matches and not equivalent semantics. 2018-08-29 13:53:12 -05:00
Chip Davis
84eb889d73 Fix reference output of shader_draw_parameters tests. 2018-08-29 13:31:43 -05:00
Chip Davis
56a9b73685 Add test cases for SPV_KHR_shader_draw_parameters. 2018-08-29 12:04:29 -05: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