HLSL: inter-stage structure splitting.
authorsteve-lunarg <steve_gh@khasekhemwy.net>
Wed, 14 Dec 2016 22:22:25 +0000 (15:22 -0700)
committersteve-lunarg <steve_gh@khasekhemwy.net>
Mon, 26 Dec 2016 17:11:15 +0000 (10:11 -0700)
commita2e7531057488de0329a562eb28667dd3e2f5c28
tree15c602c0baacbe680b86196f538398756997d41e
parent807a0d9e2f4e176f75d62ac3c179c81800ec2608
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.
18 files changed:
Test/baseResults/hlsl.basic.geom.out
Test/baseResults/hlsl.entry-in.frag.out
Test/baseResults/hlsl.struct.frag.out
Test/baseResults/hlsl.struct.split-1.vert.out [new file with mode: 0644]
Test/baseResults/hlsl.struct.split.call.vert.out [new file with mode: 0644]
Test/baseResults/hlsl.struct.split.trivial.vert.out [new file with mode: 0644]
Test/baseResults/hlsl.structarray.flatten.geom.out
Test/baseResults/hlsl.structin.vert.out
Test/hlsl.flatten.return.frag
Test/hlsl.pp.tokenpasting.frag [new file with mode: 0644]
Test/hlsl.struct.split-1.vert [new file with mode: 0644]
Test/hlsl.struct.split.call.vert [new file with mode: 0644]
Test/hlsl.struct.split.trivial.vert [new file with mode: 0644]
Test/hlsl.structarray.flatten.geom
glslang/Include/Types.h
gtests/Hlsl.FromFile.cpp
hlsl/hlslParseHelper.cpp
hlsl/hlslParseHelper.h