Commit Graph

838 Commits

Author SHA1 Message Date
steve-lunarg
a2e7531057 HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs
are passed, and thus become input arrays of structs in the GS inputs.  That is a common GS case.

The salient points of this PR are:

* Structure splitting has been changed from "always between stages" to "only into the VS and out of
  the PS".  It had previously happened between stages because it's not legal to pass a struct
  containing a builtin IO variable.

* Structs passed between stages are now split into a struct containing ONLY user types, and a
  collection of loose builtin IO variables, if any.  The user-part is passed as a normal struct
  between stages, which is valid SPIR-V now that the builtin IO is removed.

* Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g,
  functions can work unmodified.

* If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS,
  the array reference is moved to the split-off loose variable, which is given the array dimension
  itself.

When passing things around inside the shader, such as over a function call, the the original type
is used in a sanitized form that removes the builtIn qualifications and makes them temporaries.
This means internal function calls do not have to change.  However, the type when returned from
the shader will be member-wise copied from the internal sanitized one to the external type.
The sanitized type is used in variable declarations.

When copying split types and unsplit, if a sub-struct contains only user variables, it is copied
as a single entity to avoid more AST verbosity.

Above strategy arrived at with talks with @johnkslang.

This is a big complex change.  I'm inclined to leave it as a WIP until it can get some exposure to
real world cases.
2016-12-26 10:11:15 -07:00
John Kessenich
807a0d9e2f Merge pull request #640 from chaoc/modify-shader-ballot
Modify shader ballot extension by adding OpSubgroupReadInvocationKHR
2016-12-21 17:40:29 -07:00
chaoc
f200da8631 Modify shader ballot extension by adding OpSubgroupReadInvocationKHR 2016-12-21 12:08:09 -08:00
John Kessenich
224b1f733b PP: Support operator creation with token pasting. 2016-12-21 12:32:56 -07:00
John Kessenich
2dcdda921f Merge pull request #641 from chaoc/passthrough
Add support for SPV_NV_geometry_shader_passthrough
2016-12-21 10:59:07 -07:00
John Kessenich
54af2de761 PP: Non-functional: rationalize TPpToken.
Always keep 'token' outside.
Always return the string to upper levels inside.
2016-12-20 19:42:53 -07:00
chaoc
6e5acae144 Add support for SPV_NV_geometry_shader_passthrough 2016-12-20 13:28:52 -08:00
chaoc
0ad6a4e60d Add support for SPV_NV_sample_mask_override_coverage 2016-12-19 16:29:34 -08:00
John Kessenich
0955b1cb35 Merge pull request #637 from KhronosGroup/token-paste
PP: Implement token pasting for PP identifiers.
2016-12-19 14:31:57 -07:00
John Kessenich
e6cbc5b19d Merge pull request #624 from steve-lunarg/remapper-strip-removed
WIP: Remapper: remove debug info for IDs stripped in other passes
2016-12-19 14:07:58 -07:00
John Kessenich
d485e0b710 PP: Implement token pasting for PP identifiers.
Implement token pasting as per the C++ specification, within the current
style of the PP code.
Non-identifiers (turning 12 ## 10 into the numeral 1210) is not yet covered;
they should be a simple incremental change built on this one.
Addresses issue #255.
2016-12-19 09:19:43 -07:00
steve-lunarg
a64ed3eba0 HLSL: allow "sample" in expressions.
Unlike other qualifiers, HLSL allows "sample" to be either a qualifier keyword or an
identifier (e.g, a variable or function name).

A fix to allow this was made a while ago, but that fix was insufficient when 'sample'
was used in an expression.  The problem was around the initial ambiguity between:

   sample float a; // "sample" is part of a fully specified type
and
   sample.xyz;     // sample is a keyword in a dot expression

Both start the same.  The "sample" was being accepted as a qualifier before enough
further parsing was done to determine we were not a declaration after all.  This
consumed the token, causing it to fail for its real purpose.

Now, when accepting a fully specified type, the token is pushed back onto the stack if
the thing is not a fully specified type.  This leaves it available for subsequent
purposes.

Changed the "hlsl.identifier.sample.frag" test to exercise this situation, distilled
down from a production shaders.
2016-12-18 18:01:34 -07:00
John Kessenich
1e275c8486 HLSL: More robust handling of bad shader input, catching a few more things. 2016-12-14 17:02:32 -07:00
steve-lunarg
297754cfe8 Remapper: remove debug info for IDs stripped in other passes
If some DCE is performed such as removing dead functions, then even
if we are NOT stripping debug info, we still must remove the debug
opcodes that refer to the now-dead IDs.

Also, this adds a small change to perform no ID remapping if none
is requested, making spirv-remap properly be a no-op if no options
are given.
2016-12-12 09:01:11 -07:00
John Kessenich
906cc21816 Linker: Eliminate uncalled functions, because they can be ill-defined.
Fixes issue #610. Also provides a testing option to keep uncalled functions.
2016-12-09 19:22:20 -07:00
John Kessenich
4b6ce415ef GLSL Linker: Track entry point across compilation units.
This wasn't needed until the recent generalization of "main" to "entry point",
so makes some HLSL-specific code be generic now, for GLSL functional correctness.
2016-12-09 17:14:27 -07:00
John Kessenich
6a60c2f9ea Linker: Walk the call graph to report an error on missing bodies. 2016-12-08 23:22:21 -07:00
John Kessenich
e795cc915c Merge pull request #621 from steve-lunarg/recursive-flattening
HLSL: Recursive composite flattening
2016-12-08 11:18:07 -07:00
steve-lunarg
a2b01a0da8 HLSL: Recursive composite flattening
This PR implements recursive type flattening.  For example, an array of structs of other structs
can be flattened to individual member variables at the shader interface.

This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient
for geometry shader arrayed inputs.  That will be handled separately with structure splitting,
 which is not implemented by this PR.  In the meantime, that case is detected and triggers an error.

The recursive flattening extends the following three aspects of single-level flattening:

- Flattening of structures to individual members with names such as "foo[0].samp[1]";

- Turning constant references to the nested composite type into a reference to a particular
  flattened member.

- Shadow copies between arrays of flattened members and the nested composite type.

Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR.
Internally, shadow copies are, such as if the type is passed to a function.

Also, the reasons for flattening are unchanged.  Uniforms containing opaque types, and interface struct
types are flattened.  (The latter will change with structure splitting).

One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be
flattened.

Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently
issues an error until type splitting is online).

The process of arriving at the individual member from chained postfix expressions is more complex than
it was with one level.  See large-ish comment above HlslParseContext::flatten() for details.
2016-12-07 14:40:01 -07:00
steve-lunarg
05f75142d6 HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.

Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object.  It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself.  Rather, you can convert other arguments,
but want to stay in the same "family" of functions.  E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.

This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda.  The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.

Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL.  The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions.  In effect
this always uses an upconversion if there is one.
2016-12-07 12:00:32 -07:00
John Kessenich
b56f4ac72c Merge pull request #615 from dneto0/consistent-location-for-test-files
runtests should refer to test files in current directory
2016-12-06 00:48:11 -07:00
John Kessenich
9df6aa5361 GLSL: Allow desktop shaders to call functions from outside main().
Fixes issue #239.
2016-12-05 21:36:48 -07:00
David Neto
5cc92c5623 runtests should refer to test files in current directory
Recently added entry point renaming file referred to
test source file hlsl.entry.rename.frag via relative directory.

Change it to be consistent with other tests: assume test
sources are in the current directory.
2016-12-05 11:31:18 -05:00
John Kessenich
fb06e9552e Don't print the "Linked stage" message unless the AST is being dumped. 2016-12-03 13:59:51 -07:00
John Kessenich
21b11f4cc1 Merge branch 'intrinsic-promotion' of https://github.com/steve-lunarg/glslang into steve-lunarg-intrinsic-promotion 2016-12-03 13:27:22 -07:00
steve-lunarg
f1e0c87127 allow renaming of shader entry point when creating SPIR-V
Use "--source-entrypoint name" on the command line, or the
TShader::setSourceEntryPoint(char*) API.

When the name given to the above interfaces is detected in the
shader source, it will be renamed to the entry point name supplied
to the -e option or the TShader::setEntryPoint() method.
2016-12-01 08:51:43 -07:00
John Kessenich
f97f2ce603 HLSL: Support the constructor idiom "(struct type)0".
This highly leverages the previous commit to handle partial initializers.
2016-11-27 22:51:36 -07:00
John Kessenich
98ad485321 HLSL: Support {...} initializer lists that are too short. 2016-11-27 17:39:07 -07:00
John Kessenich
509c4216e6 Non-functional: Fix typos. 2016-11-27 17:26:21 -07:00
John Kessenich
e50dc536ff Warn on HLSL not finding entry point. Issue #588. 2016-11-26 13:45:18 -07:00
John Kessenich
fca826212c Always correctly terminate main. Issue #588, PR #600. 2016-11-26 13:23:20 -07:00
steve-lunarg
ef33ec0925 HLSL: add intrinsic function implicit promotions
This PR handles implicit promotions for intrinsics when there is no exact match,
such as for example clamp(int, bool, float).  In this case the int and bool will
be promoted to a float, and the clamp(float, float, float) form used.

These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2).

Output conversions are handled either via the existing addOutputArgumentConversion
function, which this PR generalizes to handle either aggregates or unaries, or by
intrinsic decomposition.  If there are methods or intrinsics to be decomposed,
then decomposition is responsible for any output conversions, which turns out to
happen automatically in all current cases.  This can be revisited once inout
conversions are in place.

Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.*

Some intrinsics with only uint versions were expanded to signed ints natively, where the
underlying AST and SPIR-V supports that.  E.g, countbits.  This avoids extraneous
conversion nodes.

A new function promoteAggregate is added, and used by findFunction.  This is essentially
a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary.

The actual selection proceeds in three steps, as described in the comments in
hlslParseContext::findFunction:

1. Attempt an exact match.  If found, use it.
2. If not, obtain the operator from step 1, and promote arguments.
3. Re-select the intrinsic overload from the results of step 2.
2016-11-23 10:36:34 -07:00
John Kessenich
e122f053bb Merge pull request #599 from steve-lunarg/gs
HLSL: Add GS support
2016-11-23 00:29:30 -07:00
John Kessenich
6e848daf45 Merge pull request #596 from steve-lunarg/hlsl-intrinsic-parsing
HLSL: use HLSL parser for HLSL intrinsic prototypes, enable int/bool mats
2016-11-23 00:19:40 -07:00
steve-lunarg
f49cdf4183 WIP: HLSL: Add GS support
This PR adds:

[maxvertexcount(n)] attributes

point/line/triangle/lineadj/triangleadj qualifiers

PointStream/LineStream/TriangleStream templatized types

Append method on above template types

RestartStrip method on above template types.
2016-11-21 18:25:08 -07:00
steve-lunarg
75fd223f03 HLSL: allow "sample" as a valid identifier.
HLSL has keywords for various interpolation modifiers such as "linear",
"centroid", "sample", etc.  Of these, "sample" appears to be special,
as it is also accepted as an identifier string, where the others are not.

This PR adds this ability, so the construct "int sample = 42;" no longer
produces a compilation error.

New test = hlsl.identifier.sample.frag
2016-11-16 13:22:11 -07:00
steve-lunarg
0842dbb39a HLSL: use HLSL parser to parse HLSL intrinsic prototypes, enable int/bool mats
This PR adds a CreateParseContext() fn analogous to CreateBuiltInParseables(),
to create a language specific built in parser.  (This code was present before
but not encapsualted in a fn).  This can now be used to create a source language
specific parser for builtins.

Along with this, the code creating HLSL intrinsic prototypes can now produce
them in HLSL syntax, rather than GLSL syntax.  This relaxes certain prior
restrictions at the parser level.  Lower layers (e.g, SPIR-V) may still have
such restrictions, such as around Nx1 matrices: this code does not impact
that.

This PR also fleshes out matrix types for bools and ints, both of which were
partially in place before.  This was easier than maintaining the restrictions
in the HLSL prototype generator to avoid creating protoypes with those types.

Many tests change because the result type from intrinsics moves from "global"
to "temp".

Several new tests are added for the new types.
2016-11-16 11:19:22 -07:00
John Kessenich
fabe7d6a61 Test results: Fix incorrect test result caused by parallel development. Issue #594. 2016-11-14 21:22:05 -07:00
John Kessenich
0bf06d3cf5 Merge pull request #576 from steve-lunarg/uav-registers
Add UAV (image) binding offset and HLSL register class support
2016-11-14 09:39:46 -07:00
chrgau01@arm.com
c3f1cdfa57 GLSL: The execution scope for barriers should be Workgroup. 2016-11-14 10:10:05 +01:00
steve-lunarg
d9cb832f9c HLSL: allow promotion from 1-vector types to scalars, e.g, float<-float1
Previously, an error was thrown when assigning a float1 to a scalar float,
or similar for other basic types.  This allows that.

Also, this allows calling functions accepting scalars with float1 params,
so for example sin(float1) will work.  This is a minor change in
HlslParseContext::findFunction().
2016-11-13 14:44:46 -07:00
steve-lunarg
a22f7dbb71 HLSL: Allow expressions in attributes
For example:

[numthreads(2+2, 2*3, (1+FOO)*BAR)]

This will result in a thread count (4, 6, 8).
2016-11-11 08:23:03 -07:00
John Kessenich
d3f1122a44 Whole stack: Fix stale types in the AST linker object nodes, fixing #557.
Rationalizes the entire tracking of the linker object nodes, effecting
GLSL, HLSL, and SPIR-V, to allow tracked objects to be fully edited before
their type snapshot for linker objects.

Should only effect things when the rest of the AST contained no reference to
the symbol, because normal AST nodes were not stale. Also will only effect such
objects when their types were edited.
2016-11-05 10:22:33 -06:00
steve-lunarg
9088be4c07 Add UAV (image) binding offset and HLSL register support
This PR adds:

1. The "u" register class for RW* objects.

2. --shift-image-bindings (== --sib), analogous to --shift-texture-bindings etc.

3. Case insensitive reg classes.

4. Tests for above.
2016-11-01 14:44:54 -06:00
John Kessenich
89df3c2dcb Merge pull request #572 from steve-lunarg/numthreads
HLSL: implement numthreads for compute shaders
2016-11-01 00:25:06 -06:00
John Kessenich
1061accfac Merge pull request #562 from TiemoJung/io_map_control_publish
HLSL -> Spir-V: Resource mapping handler
2016-11-01 00:24:01 -06:00
steve-lunarg
3226b0835c HLSL: Add min*{float,int,uint} types
These HLSL types are guaranteed to have at least the given number of bits, but may have more.

min{16,10}float is mapped to EbtFloat at medium precision -> SPIRV RelaxedPrecision
min{16,12}int and min16uint are mapped to mediump -> SPIR-V RelaxedPrecision
2016-10-31 12:46:05 -06:00
steve-lunarg
1868b14435 HLSL: implement numthreads for compute shaders
This PR adds handling of the numthreads attribute for compute shaders, as well as a general
infrastructure for returning attribute values from acceptAttributes, which may be needed in other
cases, e.g, unroll(x), or merely to know if some attribute without params was given.

A map of enum values from TAttributeType to TIntermAggregate nodes is built and returned.  It
can be queried with operator[] on the map.  In the future there may be a need to also handle
strings (e.g, for patchconstantfunc), and those can be easily added into the class if needed.

New test is in hlsl.numthreads.comp.
2016-10-31 09:28:17 -06:00
t.jung
c2016a52d2 New uniform mapping handling
- add optional callback to handle mapping of uniform variables in linking phase
- if no resolver is provided, it uses the internal default resolver with all shifts and auto bind settings

Change-Id: Icfe38a9eabe8bfc8f8bb6d8150c06f7ed38bb762
2016-10-28 15:43:14 +02:00
John Kessenich
51634468da Merge pull request #568 from steve-lunarg/logicalop-fix
HLSL: allow component-wise operations for logical || and &&.
2016-10-26 23:01:16 -06:00