Commit Graph

201 Commits

Author SHA1 Message Date
Daniel Koch
d9b7a850a8 More build fixes
Fix another build warning on some platforms

Use an explicit cast from size_t to int to avoid warning.
2017-03-03 10:35:02 -05:00
Daniel Koch
197082ca34 Fix build warnings on some platforms
Use an explicit cast from size_t to int to avoid errors like the following:
glslang\glslang\MachineIndependent\preprocessor\Pp.cpp(1053) : error C2220: warning treated as error - no 'object' file generated
glslang\glslang\MachineIndependent\preprocessor\Pp.cpp(1053) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

affects Pp.cpp, hlslParseHelper.cpp.

Initialize local variable to get rid of warningsa about potentially
uninitialized variables:
glslang\hlsl\hlslparsehelper.cpp(3667) : error C2220: warning treated as error - no 'object' file generated
glslang\hlsl\hlslparsehelper.cpp(3667) : warning C4701: potentially uninitialized local variable 'builtIn' used

affects hlslParseHelper.cpp
2017-03-01 09:50:42 -05:00
steve-lunarg
fdbfb65ec7 HLSL: small fix for index type in f16tof32 opcode
The f16tof32 opcode was indexing a vector with a float 0, rather
than an int 0.  It may have made no functional difference due to the
identical bit pattern, but code looking at the type could be
confused.
2017-02-28 14:15:32 -07:00
John Kessenich
69a2c69649 Merge pull request #736 from steve-lunarg/structbuffer-params
HLSL: add structuredbuffer pass by reference in fn params
2017-02-28 13:10:51 -07:00
steve-lunarg
86b510efd1 WIP: HLSL: add f16tof32 and f32tof16 decompositions. 2017-02-27 15:19:49 -07:00
steve-lunarg
dd8287a109 WIP: HLSL: add structuredbuffer pass by reference in fn params
This PR adds the ability to pass structuredbuffer types by reference
as function parameters.

It also changes the representation of structuredbuffers from anonymous
blocks with named members, to named blocks with pseudonymous members.
That should not be an externally visible change.
2017-02-26 11:13:42 -07:00
steve-lunarg
5da1f038d8 HLSL: implement 4 (of 6) structuredbuffer types
This is a partial implemention of structurebuffers supporting:

* structured buffer types of:
*   StructuredBuffer
*   RWStructuredBuffer
*   ByteAddressBuffer
*   RWByteAddressBuffer

* Atomic operations on RWByteAddressBuffer

* Load/Load[234], Store/Store[234], GetDimensions methods (where allowed by type)

* globallycoherent flag

But NOT yet supporting:

* AppendStructuredBuffer / ConsumeStructuredBuffer types
* IncrementCounter/DecrementCounter methods

Please note: the stride returned by GetDimensions is as calculated by glslang for std430,
and may not match other environments in all cases.
2017-02-21 15:51:49 -07:00
Graham Wihlidal
6f332f3ac6 Warning fixes 2017-02-17 19:05:14 +01:00
Graham Wihlidal
005120cce8 HLSL - Support for SV_GroupIndex 2017-02-17 19:03:25 +01:00
steve-lunarg
858c928ac7 Add basic HS/DS implementation.
This obsoletes WIP PR #704, which was built on the pre entry point wrapping master.  New version
here uses entry point wrapping.

This is a limited implementation of tessellation shaders.  In particular, the following are not functional,
and will be added as separate stages to reduce the size of each PR.

* patchconstantfunctions accepting per-control-point input values, such as
  const OutputPatch <hs_out_t, 3> cpv are not implemented.

* patchconstantfunctions whose signature requires an aggregate input type such as
  a structure containing builtin variables.  Code to synthesize such calls is not
  yet present.

These restrictions will be relaxed as soon as possible.  Simple cases can compile now: see for example
Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors.

PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on
invocation ID == 0.  If there is an existing invocation ID variable it will be used, otherwise one is
added to the linkage.  The PCF and the shader EP interfaces are unioned and builtins appearing in
the PCF but not the EP are also added to the linkage and synthesized as shader inputs.
Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type.  Any user
variables in the PCF signature will result in an error.  Overloaded PCF functions will also result in
an error.

[domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()]
attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-02-10 16:59:09 -07:00
John Kessenich
dd40260b63 HLSL: don't do a deepCopy() for typedef, as we still want to share the type graph.
This enables the IO type mapping to work transparently for typedefs.
2017-02-08 13:59:30 -07:00
John Kessenich
65ee230f1c HLSL: Add tests and refine what decorations are passed through per stage/in/out. 2017-02-06 23:13:16 -07:00
John Kessenich
bf47286fe7 HLSL: Move to fine-grained control for defining input/output/uniform IO types. 2017-02-06 23:13:16 -07:00
John Kessenich
727b374fd3 HLSL: Build IO types bottom up, as parsed, and cache the original (IO).
Previously, this was done recursively, per object, and the nonIO version
was cached. This reverses both those approaches.
2017-02-06 23:00:51 -07:00
John Kessenich
88c4464df5 HLSL: Have loose uniforms also go through the makeTypeNonIo() path. 2017-02-06 23:00:51 -07:00
steve-lunarg
2c5ab9c8fc HLSL: remove pervertex output blocks
This removes pervertex output blocks, in favor of using only
loose variables.  The pervertex blocks are not required and were
only partly implemented, and were adding some complication.

This change goes with wrap-entry-point.
2017-02-06 23:00:51 -07:00
steve-lunarg
ec712ebea1 HLSL: fix copies between arrays of structs of builtins, and arrayed builtins.
Structs are split to remove builtin members to create valid SPIR-V.  In this
process, an outer structure array dimension may be propegated onto the
now-removed builtin variables.  For example, a mystruct[3].position ->
position[3].  The copy between the split and unsplit forms would handle
this in some cases, but not if the array dimension was at different levels
of aggregate.

It now does this, but may not handle arbitrary composite types.  Unclear if
that has any semantic meaning for builtins though.
2017-02-06 23:00:51 -07:00
John Kessenich
abd8dca86d HLSL: Make the entry-point shadow function have non-IO params and return.
This also removes an no longer needed makeTemporary() and rationalizes
makeTypeNonIo()'s interface.
2017-02-06 22:58:32 -07:00
steve-lunarg
5d3023af03 HLSL: Type sanitization: create non-IO types for var decl and fn param/ret
This introduces parallel types for IO-type containing aggregates used as
non-entry point function parameters or return types, or declared as variables.
Further uses of the same original type will share the same sanitized deep
structure.

This is intended to be used with the wrap-entry-point branch.
2017-02-06 22:58:32 -07:00
John Kessenich
02467d8d94 HLSL: Wrap the entry-point; need to write 'in' args, and support 'inout' args.
This needs some render testing, but is destined to be part of master.

This also leads to a variety of other simplifications.
 - IO are global symbols, so only need one list of linkage nodes (deferred)
 - no longer need parse-context-wide 'inEntryPoint' state, entry-point is localized
 - several parts of splitting/flattening are now localized
2017-02-06 22:58:32 -07:00
rdb
a2f0e0e791 Fix compilation with MSVC 2010 2017-01-20 20:51:25 +01:00
John Kessenich
22f25d80c6 Merge pull request #682 from steve-lunarg/split-copy-fix
HLSL: fix dereferencing when copying split structures with arrays
2017-01-19 16:56:06 -07:00
John Kessenich
e48b8d74e2 Infrastructure: remove potential memory leaks. 2017-01-19 15:30:56 -07:00
steve-lunarg
65cdff9a54 HLSL: fix dereferencing when copying split structures with arrays
When copying split types with mixtures of user variables and buitins,
where the builtins are extracted, there is a parallel structures traversal.
The traversal was not obtaining the derefenced types in the array case.
2017-01-19 15:18:00 -07:00
John Kessenich
94dfb7a523 Non-functional: Factor out entry-point logic from handleFunctionDefinition(). 2017-01-18 16:50:47 -07:00
John Kessenich
33dadd1287 Fix build break for non-VS. 2017-01-13 20:22:00 -07:00
John Kessenich
c142c88967 Front-ends: Non-functional: Rationalize vector and matrix swizzles.
This reduces code duplication in a few ways, and better encapsulates
vector swizzle representation.
2017-01-13 19:35:29 -07:00
John Kessenich
0a76a1870c Merge pull request #656 from TiemoJung/overload_fix
HLSL: Improved overload handling
2017-01-13 15:10:20 -07:00
John Kessenich
fdf6347f0a HLSL: Add EOpMatrixSwizzle, selectively decomposed to other ops, for issue #670.
Since EOpMatrixSwizzle is a new op, existing back-ends only work when the
front end first decomposes it to other operations. So far, this is only
being done for simple assignment into matrix swizzles.
2017-01-13 12:35:01 -07:00
John Kessenich
001dfa1c5c HLSL: matrix swizzle (_12, _m23) syntax, partial semantics.
This partially addressess issue #670, for when the matrix swizzle
degenerates to a component or column: m[c], m[c][r] (where HLSL
swaps rows and columns for user's view).

An error message is given for the arbitrary cases not covered.

These cases will work for arbitrary use of l-values.

Future work will handle more arbitrary swizzles, which might
not work as arbitrary l-values.
2017-01-12 16:51:18 -07:00
steve-lunarg
46d5428422 WIP: add other builtins to interstage IO
(Still adding tests: do not commit)

This fixes PR #632 so that:

(a) The 4 PerVertex builtins are added to an interface block for all stages except fragment.

(b) Other builtin qualified variables are added as "loose" linkage members.

(c) Arrayness from the PerVertex builtins is moved to the PerVertex block.

(d) Sometimes, two PerVertex blocks are created, one for in, one for out (e.g, for some GS that
    both reads and writes a Position)
2017-01-09 13:58:05 -07:00
Alex Szpakowski
5f316d9b17 Reorder initializer fields to match variable declaration order (or vice versa) for several class constructors. 2017-01-08 18:21:17 -04:00
John Kessenich
927608b393 Non-functional: White space after "//", mostly for copyrights. 2017-01-06 12:34:14 -07:00
John Kessenich
ecba76fe73 Non-Functional: Whitespace, comments, replace accidentally deleted comment.
- fixed ParseHelper.cpp newlines (crlf -> lf)
- removed trailing white space in most source files
- fix some spelling issues
- extra blank lines
- tabs to spaces
- replace #include comment about no location
2017-01-06 11:24:14 -07:00
John Kessenich
64285c9e69 Non-functional: Very minor clean up. 2017-01-05 10:45:32 -07:00
John Kessenich
acb9076a27 Merge pull request #650 from steve-lunarg/lvalue-swizzle-fix
HLSL: allow destination swizzles when writing RWTexture/RWBuffer
2017-01-05 10:40:14 -07:00
John Kessenich
085b833490 HLSL: Fix issue #658: Don't adopt initializer constness from declaration.
This also makes it match how GLSL handles the same thing.
2017-01-05 10:28:26 -07:00
John Kessenich
ddfbbe26f2 Merge pull request #632 from steve-lunarg/structure-splitting
HLSL: inter-stage structure splitting.
2017-01-04 11:41:36 -07:00
John Kessenich
5abd308e71 Merge pull request #659 from steve-lunarg/d3dcolortoubyte4
Add D3DCOLORtoUBYTE4 decomposition
2017-01-03 15:34:33 -07:00
John Kessenich
c4ed950057 Merge pull request #647 from steve-lunarg/default-fn-params
HLSL: default function parameters
2017-01-03 15:30:05 -07:00
steve-lunarg
7ea7ff4cd4 Add EOpD3DCOLORtoUBYTE4 decomposition 2017-01-03 14:42:18 -07:00
steve-lunarg
cd6829ba81 HLSL: allow destination swizzles when writing RWTexture/RWBuffer objects.
Reads and write syntax to UAV objects is turned into EOpImageLoad/Store
operations.  This translation did not support destination swizzles,
for example, "mybuffer[tc].zyx = 3;", so such statements would fail to
compile.  Now they work.

Parial updates are explicitly prohibited.

New test: hlsl.rw.swizzle.frag
2017-01-03 10:31:09 -07:00
John Kessenich
f37f4d23fc HLSL: Fix issue #646: map SV_DispatchThreadID -> GlobalInvocationID. 2017-01-02 14:59:19 -07:00
t.jung
84e59203b7 updates overload handling to be more careful when allowing overloads over texture types
Change-Id: I60cf0b0e03da89b0e415125f1a9ffb1de7db71d4
2017-01-02 17:18:36 +01:00
John Kessenich
aa6d56298d HLSL: Handle const with no initializer. Fixes issue #651. 2016-12-30 16:42:57 -07:00
John Kessenich
53864846a9 HLSL: Support empty {} initializers for arrays and scalars. 2016-12-30 16:39:18 -07:00
steve-lunarg
26d3145334 HLSL default function parameters
This PR adds support for default function parameters in the following cases:

1. Simple constants, such as void fn(int x, float myparam = 3)
2. Expressions that can be const folded, such a ... myparam = sin(some_const)
3. Initializer lists that can be const folded, such as ... float2 myparam = {1,2}

New tests are added: hlsl.params.default.frag and hlsl.params.default.err.frag
(for testing error situations, such as ambiguity or non-const-foldable).

In order to avoid sampler method ambiguity, the hlsl better() lambda now
considers sampler matches.  Previously, all sampler types looked identical
since only the basic type of EbtSampler was considered.
2016-12-29 12:15:48 -07:00
steve-lunarg
132d331870 HLSL: struct splitting: assignments of hierarchical split types
This commit adds support for copying nested hierarchical types of split
types.  E.g, a struct of a struct containing both user and builtin interstage
IO variables.

When copying split types, if any subtree does NOT contain builtin interstage
IO, we can copy the whole subtree with one assignment, which saves a bunch
of AST verbosity for memberwise copies of that subtree.
2016-12-26 20:17:13 -07:00
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
1e275c8486 HLSL: More robust handling of bad shader input, catching a few more things. 2016-12-14 17:02:32 -07:00