Commit Graph

428 Commits

Author SHA1 Message Date
LoopDawg
a5d8616478 HLSL: allow mixed user & builtin members in hull shader output structure
Hull shaders have an implicitly arrayed output.  This is handled by creating an arrayed form of the
provided output type, and writing to the element of it indexed by InvocationID.

The implicit indirection into that array was causing some troubles when copying to a split
structure.  handleAssign was able to handle simple symbol lvalues, but not an lvalue composed
of an indirection into an array.
2017-09-14 16:50:37 -06:00
John Kessenich
9855bdad00 GLSL: Promote HLSL entry-point renaming code to be used by GLSL as well.
Fixes #1045.
2017-09-12 09:40:54 -06:00
mchock-nv
933c10cd4b Delete unused 'this' capture
Remove an unused 'this' entry from a lambda capture list.

This cleans up a unused-lambda-capture warning.
2017-09-11 15:20:52 -07:00
John Kessenich
75e057f980 Merge pull request #1037 from LoopDawg/clip-cull-geom
HLSL: add geometry stage support for clip/cull distance
2017-08-31 12:36:06 -06:00
LoopDawg
5e5b12e931 HLSL: add geometry stage support for clip/cull distance
Changes:

(1) Allow clip/cull builtins as both input and output in the same shader stage.  Previously,
not enough data was tracked to handle this.

(2) Handle the extra array dimension in GS inputs.  The synthesized external variable can
now be created with the extra array dimension if needed, and the form conversion code is
able to handle it as well.

For example, both of these GS inputs would result in the same synthesized external type:

    triangle in float4 clip[3] : SV_ClipDistance

    triangle in float2 clip[3][2] : SV_ClipDistance

In the second case, the inner array dimension packs with the 2-vector of floats into an array[4],
which there is an array[3] of due to the triangle geometry.
2017-08-31 10:37:46 -06:00
John Kessenich
4e2f05da41 Build: Fix #1036: size_t warning. 2017-08-29 12:36:09 -06:00
LoopDawg
d6f4d9b48c HLSL: fix type on clip/cull index result
While adding geometry stage support for clip/cull, it transpired that the
existing clip/cull support was not setting the type of the result of indexing
into the clup/cull variable.  That's a defect independent of the geometry
support, so to simplify the geometry PR, this is addressed separately.

It doesn't appear to change the generated SPIR-V, but that's probably down to
something else tolerating a bad input.
2017-08-28 14:05:41 -06:00
John Kessenich
1f312f9078 Merge pull request #1028 from LoopDawg/clip-cull-input
HLSL: handle clip and cull distance input builtin type conversion
2017-08-24 12:15:00 -06:00
LoopDawg
e2cda3c2d7 HLSL: handle clip and cull distance input builtin type conversion
HLSL allows a range of types for clip and cull distances.  There are
three dimensions, including arrayness, vectorness, and semantic ID.
SPIR-V requires clip and cull distance be a single array of floats in
all cases.

This code provides input side conversion between the SPIR-V form and
the HLSL form.  (Output conversion was added in PR #947 and #997).

This PR extends HlslParseContext::assignClipCullDistance to cope with
the input side conversion.  Not as much changed as appears: there was
also a lot of renaming to reflect the fact that the code now handles
either direction.

Currently, non-{frag,vert} stages are not handled, and are explicitly
rejected.

Fixes #1026.
2017-08-24 08:35:40 -06:00
John Kessenich
3d1b709676 HLSL: Fix #1027. 2017-08-23 14:33:31 -06:00
John Kessenich
778806a692 HLSL: Fix #1018: Give an error for mismatched return type. 2017-08-19 17:29:44 -06:00
LoopDawg
5ee05891cf HLSL: add methods to track user structure in texture return type.
Some languages allow a restricted set of user structure types returned from texture sampling
operations.  Restrictions include the total vector size of all components may not exceed 4,
and the basic types of all members must be identical.

This adds underpinnings for that ability.  Because storing a whole TType or even a simple
TTypeList in the TSampler would be expensive, the structure definition is held in a
table outside the TType.  The TSampler contains a small bitfield index, currently 4 bits
to support up to 15 separate texture template structure types, but that can be adjusted
up or down.  Vector returns are handled as before.

There are abstraction methods accepting and returning a TType (such as may have been parsed
from a grammar).  The new methods will accept a texture template type and set the
sampler to the structure if possible, checking a range of error conditions such as whether
the total structure vector components exceed 4, or whether their basic types differe, or
whether the struct contains non-vector-or-scalar members.  Another query returns the
appropriate TType for the sampler.

High level summary of design:

In the TSampler, this holds an index into the texture structure return type table:

    unsigned int structReturnIndex : structReturnIndexBits;

These are the methods to set or get the return type from the TSampler.  They work for vector or structure returns, and potentially could be expanded to handle other things (small arrays?) if ever needed.

    bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc);
    void getTextureReturnType(const TSampler& sampler, const TType& retType, const TSourceLoc& loc) const;

The ``convertReturn`` lambda in ``HlslParseContext::decomposeSampleMethods`` is greatly expanded to know how to copy a vec4 sample return to whatever the structure type should be.  This is a little awkward since it involves introducing a comma expression to return the proper aggregate value after a set of memberwise copies.
2017-08-15 16:40:21 -06:00
John Kessenich
03e63fa805 HLSL: Add fall-back for opaque initializers to just generate long-term expected code.
This generated code needs an optimization pass to eliminate the assignments
to the opaque members.
2017-08-15 10:18:32 -06:00
John Kessenich
e29ff3cd65 HLSL: Flatten structs for all non-arrayed I/O interfaces. 2017-08-11 00:17:26 -06:00
John Kessenich
01109546d8 HLSL: Make fresh array sizes for TessLevelOuter and TessLevelInner arrays.
This prevents potentional sharing from inadvertently affecting other arrays.
2017-08-11 00:14:46 -06:00
John Kessenich
e516d4335f HLSL: Move debug naming to a simpler, more consistent, scheme.
This will help in expanding flattening and reducing splitting.
2017-08-09 14:29:29 -06:00
John Kessenich
3322dd8f99 HLSL: Include built-in processing for vertex input and fragment output flattening. 2017-08-09 11:03:49 -06:00
John Kessenich
ecd08bc36c Non-functional HLSL: Factor out built-ins from splitting and related simplifications. 2017-08-08 17:32:38 -06:00
John Kessenich
eaed06823a Merge pull request #1011 from LoopDawg/pragma-pack-matrix
HLSL: implement #pragma pack_matrix(layout)
2017-08-08 06:35:29 +09:00
LoopDawg
6a264bed88 HLSL: implement #pragma pack_matrix(layout)
This adds support for #pragma pack_matrix() to the HLSL front end.

The pragma sets the default matrix layout for subsequent unqualified matrices
in structs or buffers. Explicit qualification overrides the pragma value. Matrix
layout is not permitted at the structure level in HLSL, so only leaves which are
matrix types can be so qualified.

Note that due to the semantic (not layout) difference in first matrix indirections
between HLSL and SPIR-V, the sense of row and column major are flipped.  That's
independent of this PR: just a factor to note.  A column_major qualifier appears
as a RowMajor member decoration in SPIR-V modules, and vice versa.
2017-08-07 12:41:44 -06:00
John Kessenich
d5aedc199f HLSL: Correct which things flattening tracks for linkage, based on caller, not type.
Includes related trackLinkage() code removal and name improvements.
2017-08-06 21:18:56 -06:00
LoopDawg
898f5fbef7 HLSL: fix qualifier propagation from user struct types to block definitions.
The HLSL FE tracks four versions of a declared type to avoid losing information, since it
is not (at type-decl time) known how the type will be used downstream.  If such a type
was used in a cbuffer declaration, the cbuffer type's members should have been using
the uniform form of the original user structure type, but were not.

This would manifest as matrix qualifiers (and other things, such as pack offsets) on user struct
members going missing in the SPIR-V module if the struct type was a member of a cbuffer, like so:

    struct MyBuffer
    {
        row_major float4x4 mat1;
        column_major float4x4 mat2;
    };

    cbuffer Example
    {
        MyBuffer g_MyBuffer;
    };

Fixes: #789
2017-08-04 15:50:10 -06:00
John Kessenich
2b4f77f2dc HLSL: Correct use of isPerVertexBuiltIn() to be isClipOrCullDistance().
This allows removal of isPerVertexBuiltIn(). It also leads to
removal of addInterstageIoToLinkage(), which is no longer needed.

Includes related name improvements.
2017-08-04 15:32:24 -06:00
John Kessenich
b6be80f44e HLSL: Flatten more I/O: non-arrayed user-only structures.
The goal is to flatten all I/O, but there are multiple categories and
steps to complete, likely including a final unification of splitting
and flattening.
2017-08-04 12:19:58 -06:00
John Kessenich
cca42a8ea6 HLSL: Stop including empty structures in the I/O interface. Fix #785. 2017-08-03 18:41:48 -06:00
John Kessenich
6042eb475b Non-functional: HLSL: Simplify I/O logic for splitting. 2017-08-02 17:08:43 -06:00
John Kessenich
318a379b1f Non-functional: HLSL further simplications to base I/O flattening on. 2017-07-30 23:51:35 -06:00
John Kessenich
8bcdf2eaf5 Non-functional: HLSL: clean up dead code for splitting.
Most of this was obsoleted by entry-point wrapping.
Some other is just unnecessary.
Also, includes some spelling/name improvements.

This is to help lay ground work for flattening user I/O.
2017-07-30 18:53:16 -06:00
LoopDawg
7a3cef10dc HLSL: Non-functional: warning fix, remove unused member.
Two non-functional changes:

1. Remove flattenLevel, which is unneeded since at or around d1be7545c6.

2. Fix build warining about unused variable in executeInitializer.
2017-07-28 18:41:53 -06:00
John Kessenich
2ceec68109 Nonfunctional: Shorten some lines to the coding standard, to retrigger failed test run. 2017-07-28 16:21:04 -06:00
LoopDawg
307b6507b3 HLSL: handle multiple clip/cull semantic IDs
HLSL allows several variables to be declared.  There are packing rules involved:
e.g, a float3 and a float1 can be packed into a single array[4], while for a
float3 and another float3, the second one will skip the third array entry to
avoid straddling

This is implements that ability.  Because there can be multiple variables involved,
and the final output array will often be a different type altogether (to fuse
the values into a single destination), a new variable is synthesized, unlike the prior
clip/cull support which used the declared variable.  The new variable name is
taken from one of the declared ones, so the old tests are unchanged.

Several new tests are added to test various packing scenarios.

Only two semantic IDs are supported: 0, and 1, per HLSL rules.  This is
encapsulated in

     static const int maxClipCullRegs = 2;

and the algorithm (probably :) ) generalizes to larger values, although there
are a few issues around how HLSL would pack (e.g, would 4 scalars be packed into
a single HLSL float4 out reg?  Probably, and this algorithm assumes so).
2017-07-26 11:18:09 -06:00
John Kessenich
ab0086754e Merge pull request #991 from LoopDawg/resource-set-binding-fix
HLSL: Fix crash with --resource-set-binding [n] (global form, not per-register form)
2017-07-22 01:59:42 +09:00
LoopDawg
52017192e5 Fix crash with --resource-set-binding [n] (common set form, not per-register form)
--resource-set-binding has a mode which allows per-register assignments of
bindings and descriptor sets on the command line, and another accepting a
single descriptor set value to assign to all variables.

The former worked, but the latter would crash when assigning the values.
This fixes it, and makes the former case a bit more robust against premature
termination of the pre-register values, which must come in (regname,set,binding)
triples.

This also allows the form "--resource-set-binding stage setnum", which was
mentioned in the usage message, but did not parse.

The operation of the per-register form of this option is unchanged.
2017-07-18 11:15:40 -06:00
John Kessenich
0e6e2ffd9c Fix #980: flatten opaque initializers to use aliases. 2017-07-16 05:46:13 -06:00
LoopDawg
0fca0bafaf WIP: HLSL: support global const initializers from non-constant rvalues
Semantic test left over from other source languages is removed, since this is permitted by HLSL.
Also, to support the functionality, a targeted test is performed for this case and it is
turned into a EvqGlobal qualifier to create an AST initialization segment when needed.

Constness is now propagated up aggregate chains during initializer construction.  This
handles hierarchical cases such as the distinction between:

    static const float2 a[2] = { { 1, 2 }, { 3, 4} };

vs

    static const float2 a[2] = { { 1, 2 }, { cbuffer_member, 4} };

The first of which can use a first class constant initalization, and the second cannot.
2017-07-11 13:41:39 -06:00
Rex Xu
57e65929e4 HLSL: Translate directive [flatten] and [branch] to SPV control mask. 2017-07-06 11:31:33 +08:00
LoopDawg
54b9ff9c34 HLSL: handle type conversion for any/all intrinsics
HLSL allows float/etc types for any/all intrinsics, while the
SPIR-V opcode requires bool.  This adds a simple decomposition
to type convert the argument.  It could get a little more clever
in some of the type cases if it ever had to.
2017-07-05 12:19:39 -06:00
John Kessenich
d1be7545c6 HLSL: Non-functional: Move partial flattened access into symbol node.
Lays the groundwork for fixing issue #954.

Partial flattenings were previously tracked through a stack of active subsets
in the parse context, but full functionality needs AST nodes to represent
this across time, removing the need for parsecontext tracking.
2017-07-03 21:49:09 -06:00
John Kessenich
02a14e7c99 HLSL: Non-functional: some coding convention tweaks (120 columns, nullptr).
This commit, and next one, are specifically to make a future commit
handling partial dereferences of flattening objects easier to see.
2017-07-03 21:49:09 -06:00
Rex Xu
37cdceed41 Implement extension GL_ARB_shader_stencil_export 2017-06-29 17:50:46 +08:00
John Kessenich
89f8d1e64f HLSL: Fix #942: Map SV_TargetN to SPV Location N. 2017-06-27 15:17:38 -06:00
John Kessenich
fe6689c6c4 HLSL: support point mode. 2017-06-26 17:52:22 -06:00
LoopDawg
c44b95fdec WIP: HLSL: handle clip/cull distance array semantic matching
In HLSL, there are three (TODO: ??) dimensions of clip and cull
distance values:

  * The semantic's value N, ala SV_ClipDistanceN.
  * The array demension, if the value is an array.
  * The vector element, if the value is a vector or array of vectors.

In SPIR-V, clip and cull distance are arrays of scalar floats, always.

This PR currently ignores the semantic N axis, and handles the other
two axes by sequentially copying each vector element of each array member
into sequential floats in the output array.

Fixes: #946
2017-06-23 13:06:53 -06:00
John Kessenich
4329d555ad HLSL: Broaden solution for #940, editing integer input for 'flat'. 2017-06-21 01:35:57 -06:00
John Kessenich
f0bc598dd7 HLSL: Force flat interpolation for structure members. Fixes #940. 2017-06-20 13:19:53 -06:00
John Kessenich
54596ff99e HLSL: Force flat (nointerp) onto integer fragment inputs.
Addresses #940.
2017-06-20 03:20:59 -06:00
John Kessenich
f02c8e6ba1 Non-functional: Attempt to reset Travis error, while adding more nullptr use.
Top of master is listing a test error, not from glslang, but internally
within Travis itself.  Seeing if another run gets it to work again.
2017-06-19 16:25:44 -06:00
LoopDawg
e2713125b9 HLSL: fix several issues in mat construction from scalars
This fixes:

1. A compilation error when assigning scalars to matricies

2. A semantic error in matrix construction from scalars.  This was
initializing the diagonal, where HLSL semantics require the scalar be
replicated to every matrix element.

3. Functions accepting mats can be called with scalars, which will
be shape-converted to the matrix type.  This was previously failing
to match the function signature.

NOTE: this does not yet handle complex scalars (a function call,
say) used to construct matricies.  That'll be added when the
node replicator service is available.  For now, there's an assert.

There's one new test (hlsl.scalar2matrix.frag).  An existing test
lsl.type.half.frag changes, because of (2) above, and a negative
test error message changes due to (3) above.

Fixes #923.
2017-06-14 14:11:18 -06:00
John Kessenich
82ae8c31e0 HLSL: Fix #924: Convert between two different arrays with cast. 2017-06-13 23:13:10 -06:00
LoopDawg
1892886ae1 HLSL: compilation warning fix: no functional change
One liner to eliminate a compile warning.
2017-06-10 07:42:03 -06:00
John Kessenich
f6deacd579 HLSL: Track control-flow nesting and warn on aliasing under it. 2017-06-06 19:53:24 -06:00
John Kessenich
9b2531ba23 Infrastructure: Move nesting counters, etc., to base class.
This lets all languages share the same definitions.
2017-06-06 19:53:24 -06:00
John Kessenich
f31507421b HLSL: Convert run-time sampler assignments to compile-time aliases.
For "s.m = t", a sampler member assigned a sampler, make t an alias
for s.m, and when s.m is flattened, it will flatten to the alias t.
Normally, assignments to samplers are disallowed.
2017-06-02 18:27:21 -06:00
John Kessenich
750c2d07f7 SPV: When passing structs of opaque types, flatten and pass the members instead.
This avoids either A) needing uniformConstant struct, or
B) initializing a struct with opaque members, as writing them is not
allowed.
2017-06-01 18:49:04 -06:00
John Kessenich
d6af18f621 Merge pull request #901 from LoopDawg/imat-construct
HLSL: Add imat, umat, and bmat constructors
2017-05-24 23:12:58 -06:00
John Kessenich
6e2295d340 HLSL: Fix #902: Incorrect protection against zero arguments. 2017-05-24 16:02:56 -06:00
LoopDawg
174ccb8f1d HLSL: Add imat, umat, and bmat constructors
Fixes #894
2017-05-20 21:54:16 -06:00
John Kessenich
24e895b4a3 Merge pull request #860 from steve-lunarg/sb-counter-args.2
HLSL: add ability to pass struct buffers with counters to fns
2017-05-17 10:55:22 -06:00
steve-lunarg
2bb1f39fa7 WIP: HLSL: add ability to pass struct buffers with counters to fns
This modifies function parameter passing to pass the counter
buffer associated with a struct buffer to a function as a
hidden parameter.  Similarly function declarations will have
hidden parameters added to accept the associated counter buffers.

There is a limitation: if a SB type may or may not have an associated
counter, passing it as a function parameter will assume that it does, and
the counter will appear in the linkage whether or not there is a counter
method used on the object.
2017-05-17 09:18:53 -06:00
John Kessenich
0a2a0cd3a4 HLSL: Implement member functions calling member functions. 2017-05-17 02:20:34 -06:00
steve-lunarg
a4bfed129f WIP: track declared builtin type [proposal]
Marking as WIP since it might deserve discussion or at least explicit consideration.

During type sanitization, the TQualifier's TBuiltInVariable type is lost.  However,
sometimes it's needed downstream.  There were already two methods in use to track
it through to places it was needed: one in the TParameter, and one in a map in the
HlslParseContext used for structured buffers.

The latter was going to be insufficient when SB types with counters are passed to
user functions, and it's proving awkward to track the data to where it's needed.
This PR holds a proposal: track the original declared builtin type in the TType,
so it's trivially available where needed.

This lets the other two mechanisms be removed (and they are in this PR).  There's a
side benefit of not losing certain types of information before the reflection interface.

This PR is only that proposal, so it changes no test results.  If it's acceptable,
I'll use it for the last piece of SB counter functionality.
2017-05-15 15:44:00 -06:00
LoopDawg
726bf96a72 HLSL: add .mips[][] operator for texture types
This implements mytex.mips[mip][coord] for texture types.  There is
some error testing, but not comprehensive.  The constructs can be
nested, e.g in this case the inner .mips is parsed before the completion
of the outer [][] operator.

   tx.mips[tx.mips[a][b].x][c]
2017-05-15 09:13:58 -06:00
LoopDawg
c6510a33ff HLSL: allow GS-specific methods in other stages
Using GS methods such as Append() in non-GS stages should be ignored, but was
creating errors due to the lack of a stream output symbol for the non-GS stage.
2017-05-13 09:20:11 -06:00
John Kessenich
02c4728a83 Merge pull request #874 from xlpiao/DescriptorSet-and-Binding
HLSL: Manually configure descriptor set and binding number for resources
2017-05-10 11:10:53 -06:00
Hyangran Park
36dc82908f HLSL: Manually configure descriptor set and binding number for resources 2017-05-10 16:50:18 +09:00
steve-lunarg
f1709e7146 HLSL: implement [unroll] and [loop] attributes
This adds infrastructure suitable for any front end to create SPIR-V loop
control flags.  The only current front end doing so is HLSL.

[unroll] turns into spv::LoopControlUnrollMask
[loop] turns into spv::LoopControlDontUnrollMask
no specification means spv::LoopControlMaskNone
2017-05-03 13:44:40 -06:00
steve-lunarg
d4d0b29752 HLSL: add standard sample position return form of GetSamplePosition method
Multisample textures support a GetSamplePosition() method intended to query
positions given a sample index.  This cannot be truly implemented in SPIR-V,
but #753 requested returning standard positions for the 1..16 cases, which
this PR adds.  Anything besides that returns (0,0).  If the standard positions
are not used, this will be wrong.

This should be revisited when there is a real query available.
2017-04-26 08:31:56 -06:00
Daniel Koch
15bb43703c Fix Android build errors
glslang/MachineIndependent/iomapper.cpp:207:9: error: field 'resolver' will be initialized after field 'stage' [-Werror,-Wreorder]
      : resolver(r)
        ^
glslang/MachineIndependent/iomapper.cpp:263:9: error: field 'resolver' will be initialized after field 'stage' [-Werror,-Wreorder]
      : resolver(r)
        ^
hlsl/hlslParseHelper.cpp:70:5: error: field 'gsStreamOutput' will be initialized after field 'inputPatch' [-Werror,-Wreorder]
    gsStreamOutput(nullptr),
    ^
2017-04-21 16:16:43 -04:00
steve-lunarg
3cbc32f472 HLSL: add error for expected comparison sampler in SampleCmp* ops
This adds an error message if a non-comparison sampler is used with
comparison sampling methods.  There's no functional change for correct shaders.
2017-04-21 09:54:53 -06:00
John Kessenich
0603a383c1 Merge pull request #847 from steve-lunarg/sb-param-fix
HLSL: fix for byte address buffers in fn parmeters
2017-04-20 20:36:06 -06:00
steve-lunarg
e404e088b1 HLSL: fix for byte address buffers in fn parmeters
Byte address buffers were failing to detect that they were byte address
buffers when used as fn parameters.

Note: this detection is a little awkward, and could be simplified if
it was easy to obtain the declared builtin type for an object.
2017-04-20 16:37:14 -06:00
steve-lunarg
f8203a0acd HLSL: cast non-int types to uint on Load/Store indexes
Some texture and SB operations can take non-integer indexes, which should be
cast to integers before use if they are not already.  This adds makeIntegerIndex()
for the purpose.  Int types are left alone.

(This was done before for operator[], but needs to apply to some other things
too, hence its extraction into common function now)
2017-04-20 09:00:56 -06:00
John Kessenich
a8d3db6b32 Merge pull request #835 from steve-lunarg/sb-counters
HLSL: structuredbuffer counter functionality
2017-04-19 17:42:22 -06:00
John Kessenich
d5d9ffbdfd HLSL: vector shape conversions for all ops: Fix #839. Fix #653. Fix #631. 2017-04-18 21:07:05 -06:00
steve-lunarg
350b94856a WIP: HLSL: add refection queries for structuredbuffer counter blocks
This adds TProgram::getUniformBlockCounterIndex(int index), which returns the
index the block of the counter buffer associated with the block of the passed in
index, if any, or -1 if none.
2017-04-18 12:58:15 -06:00
steve-lunarg
12bc9aa9ce WIP: HLSL: add Append/ConsumeBuffer support 2017-04-13 19:09:05 -06:00
steve-lunarg
8e26feb8f2 WIP: HLSL: structuredbuffer counter functionality
This is WIP, heavy on the IP part.  There's not yet enough to use in real workloads.

Currently present:

* Creation of separate counter buffers for structured buffer types needing them.
* IncrementCounter / DecrementCounter methods
* Postprocess to remove unused counter buffers from linkage
* Associated counter buffers are given @count suffix (invalid as a user identifier)

Not yet present:

* reflection queries to obtain bindings for counter buffers
* Append/Consume buffers
* Ability to use SB references passed as fn parameters
2017-04-13 18:43:26 -06:00
John Kessenich
2051815bcc HLSL: Fix #803: Add shape conversions to the constant-initializer path. 2017-04-12 14:56:52 -06:00
John Kessenich
b5e739c20e HLSL: Fix boolean conversion bug and add more tests for ?:.
Null-conversion needs the right sized vectors to kick out with matching types.
2017-04-11 20:21:45 -06:00
John Kessenich
636b62db8b HLSL: Support vector 'cond ? :' -> EOpMix -> OpSelect. 2017-04-11 19:45:00 -06:00
steve-lunarg
9e5a19fd3a HLSL: fix return type for isfinite
The prior decomposition of isfinite was not setting the return type on the
sequence node.  (Sequence was used because there's an internal temporary
to avoid the complex rvalue problem).
2017-04-10 08:27:34 -06:00
John Kessenich
6fa17641b5 HLSL: Emit the OpSource HLSL instruction for HLSL, using new headers. 2017-04-07 15:40:01 -06:00
steve-lunarg
2efd6c6d0c HLSL: cast bracket dereference index to int type if not.
HLSL can index arrays using operator[] with non-integer types, and
inserts a conversion to a uint if needed.
2017-04-06 20:27:10 -06:00
steve-lunarg
ccb076ac9b HLSL: allow non-vec3 tessellation coordinate declarations
HLSL requires vec2 tessellation coordinate declarations in some cases
(e.g, isoline topology), where SPIR-V requires the TessCoord qualified
builtin to be a vec3 in all cases.  This alters the IO form of the
variable to be a vec3, which will be copied to the shader's declared
type if needed.  This is not a validation; the shader type must be correct.
2017-04-05 11:03:02 -06:00
John Kessenich
82460b5e21 HLSL: Fix #805: Support cast of scalars to structures.
Somewhat complex due to recognizing a general scalar, but not
replicating it for each member to avoid side effects.
2017-04-04 11:49:33 -06:00
John Kessenich
5ce1e4aff8 Merge pull request #817 from steve-lunarg/isfinite
HLSL: Decompose OpIsFinite to avoid capability restrictions
2017-04-03 22:32:35 -06:00
John Kessenich
c633f644da HLSL: Non-functional: rationalize making constructors.
Improves foundation for adding scalar casts.

Makes handle/make names more sane, better commented, uses more
precise subclass typing, and removes mutual recursion between
converting initializer lists and making constructors.
2017-04-03 22:17:57 -06:00
steve-lunarg
13975525d7 Decompose OpIsFinite to avoid capability restrictions
OpIsFinite is not available everywhere: decompose isfinite
to !isinf && !isnan.
2017-04-03 20:05:21 -06:00
steve-lunarg
067eb9b48a WIP: HLSL: Support InputPatch variables in patch constant functions
Previously, patch constant functions only accepted OutputPatch.  This
adds InputPatch support, via a pseudo-builtin variable type, so that
the patch can be tracked clear through from the qualifier.
2017-04-03 19:39:44 -06:00
steve-lunarg
08e0c086c8 HLSL: fix GS implementation for EP wrapping
The prior implementation of GS did not work with the new EP wrapping architecture.
This fixes it: the Append() method now looks up the actual output rather
than the internal sanitized temporary type, and writes to that.
2017-04-03 14:50:39 -06:00
steve-lunarg
f38cca3ccf HLSL: handle PCF input to DS in arbitrary argument position
In the hull shader, the PCF output does not participate in an argument list,
so has no defined ordering.  It is always put at the end of the linkage.  That
means the DS input reading PCF data must be be at the end of the DS linkage
as well, no matter where it may appear in the argument list.  This change
makes sure that happens.

The detection is by looking for arguments that contain tessellation factor
builtins, even as a struct member.  The whole struct is taken as the PCF output
if any members are so qualified.
2017-04-03 10:14:50 -06:00
John Kessenich
84a30c8bae Merge pull request #774 from steve-lunarg/tess-ctrlpt-pcf
HLSL: support per control point patch const fn invocation
2017-03-31 13:37:52 -06:00
steve-lunarg
db2e3b4169 HLSL: fix crash on empty sequence node passed to intrinsic expansions 2017-03-31 12:47:34 -06:00
steve-lunarg
e741249b72 HLSL: pass tessellation execution modes through to SPIR-V
The SPIR-V generator had assumed tessellation modes such as
primitive type and vertex order would only appear in tess eval
(domain) shaders.  SPIR-V allows either, and HLSL allows and
possibly requires them to be in the hull shader.

This change:

1. Passes them through for either tessellation stage, and,

2. Does not set up defaults in the domain stage for HLSl compilation,
to avoid conflicting definitions.
2017-03-31 11:47:18 -06:00
John Kessenich
7e997e2612 HLSL: Implicit bool conversions for conditional expressions and related.
Covers if(cond), while(cond), do-while(cond), for(;cond;), and (cond ? :).
Fixes #778.
2017-03-30 22:52:33 -06:00
steve-lunarg
e752f463c5 HLSL: HS return is arrayed to match SPIR-V semantics
HLSL HS outputs a per ctrl point value, and the DS reads an array
of that type.  (It also has a per patch frequency).  The per-ctrl-pt
frequency is arrayed on just one side, as opposed to SPIR-V which
is arrayed on both.  To match semantics, the compiler creates an
array behind the scenes and indexes it by invocation ID, assigning
the HS return value to it.
2017-03-30 14:37:08 -06:00
steve-lunarg
7afe1344ca HLSL: strip off array dimension when assign locations of arrayed IO. 2017-03-30 14:37:05 -06:00
steve-lunarg
194f0f39ec HLSL: require tessellation factors to be fixed size arrays
SPIR-V requires that tessellation factor arrays be size 4 (outer) or 2 (inner).
HLSL allows other sizes such as 3, or even scalars.  This commit converts
between them by forcing the IO types to be the SPIR-V size, and allowing
copies between the internal and IO types to handle these cases.
2017-03-30 14:37:02 -06:00
steve-lunarg
9cee73e028 HLSL: support per control point patch const fn invocation
This PR emulates per control point inputs to patch constant functions.
Without either an extension to look across SIMD lanes or a dedicated
stage, the emulation must use separate invocations of the wrapped
entry point to obtain the per control point values.  This is provided
since shaders are wanting this functionality now, but such an extension
is not yet available.

Entry point arguments qualified as an invocation ID are replaced by the
current control point number when calling the wrapped entry point.  There
is no particular optimization for the case of the entry point not having
such an input but the PCF still accepting ctrl pt frequency data.  It'll
work, but anyway makes no so much sense.

The wrapped entry point must return the per control point data by value.
At this time it is not supported as an output parameter.
2017-03-30 14:36:56 -06:00
John Kessenich
4dc835c369 Non-functional: Round of adding 'const', related to more efficient getFullNamespaceName(). 2017-03-30 10:16:22 -06:00
steve-lunarg
d8e34c5119 HLSL: fix crash on empty struct return from entry point 2017-03-24 08:56:37 -06:00
John Kessenich
000c818efb HLSL: Allow use of $Global members in between function calls.
This allows global initializers to use $Global members.
2017-03-22 23:21:34 -06:00
John Kessenich
7a41f96d10 HLSL: Implement 'this' keyword. 2017-03-22 11:38:22 -06:00
John Kessenich
3778979cd4 HLSL: non-static member functions: track and find active anonymous 'this' scopes and members.
Thanks to @steve-lunarg for his input and discussions on handling member functions.
2017-03-21 23:56:40 -06:00
John Kessenich
f4ba25e009 HLSL: Non-functional: the symbol field of a token was in practice unused; remove it.
Another precurser to getting member non-static functions working.
2017-03-21 18:36:04 -06:00
steve-lunarg
e7d0752a33 HLSL: use prefix for builtin functions names to avoid namespace collisions
It would have been possible for globally scoped user functions to collide
with builtin method names.  This adds a prefix to avoid polluting the
namespace.

Ideally this would be an invalid character to use in user identifiers, but
as that requires changing the scanner, for the moment it's an unlikely yet
valid prefix.
2017-03-19 18:22:11 -06:00
John Kessenich
f3d88bd498 HLSL non-functional: Generalize namespace nesting.
Also use this to move deferred member-function-body parsing to a better
place.

This should also be well poised for implementing the 'namespace' keyword.
2017-03-19 13:01:58 -06:00
John Kessenich
2dd643ff03 Merge branch 'TiemoJung-semantic_handling' 2017-03-14 22:44:24 -06:00
John Kessenich
2dc50ff372 Merge branch 'semantic_handling' of https://github.com/TiemoJung/glslang into TiemoJung-semantic_handling 2017-03-14 21:49:42 -06:00
Rex Xu
d41a696c30 HLSL: Additional channel value for textureGatherXXX().
When mapping HLSL gather intrinsics to GLSL textureGatherXXX() built-in
function, the channel selection value is only valid for non-shadow samplers.
2017-03-13 17:07:18 +08:00
John Kessenich
088d52bac2 HLSL: Non-functional: consolidate function declarator information. 2017-03-11 19:37:29 -07:00
John Kessenich
54ee28f4d0 HLSL: Add scoping operator, accept static member functions, and support calling them. 2017-03-11 14:13:00 -07:00
John Kessenich
5f12d2f752 HLSL: non-functional: simplify handleBuiltInMethod() to isBuiltInMethod(). 2017-03-11 10:15:47 -07:00
steve-lunarg
4198b8bfc4 WIP: HLSL: preserve empty structures after splitting 2017-03-09 19:10:57 -07:00
John Kessenich
6e1d50a7a2 HLSL: Accept SV_Cull/ClipDistanceN, by refactoring the way semantics are mapped. 2017-03-09 14:37:32 -07:00
John Kessenich
229a6f7f7b Merge pull request #761 from baldurk/vs2010-compile-fixes
Compile fixes for VS2010
2017-03-09 11:28:21 -07:00
baldurk
5d5db80d35 Compile fixes for VS2010
* Removed range-based for
* Added explicit return type to non-trivial lambda
* Added explicit scope for tInterstageIoData
2017-03-09 17:48:59 +00:00
steve-lunarg
d00b026111 Enable GatherCmpRed. Green/Blue/Alpha cannot be supported.
This implements GatherCmpRed in terms of OpImageDrefGather.

There appears to be no way to implement the Green/Blue/Apha forms: see #673.
2017-03-09 08:59:45 -07:00
John Kessenich
88e88e59cb HLSL: Non-functional: Remove dead .length() code. 2017-03-08 21:16:35 -07:00
John Kessenich
516d92d3c5 HLSL: Non-functional: Drive existing method recognition by syntax, not by name.
This (and previous commit) is a better foundation to build real methods on.
2017-03-08 20:09:03 -07:00
John Kessenich
b7201f8ee6 Merge pull request #756 from steve-lunarg/getdimensions-fix
HLSL: use LOD form of ImageQuerySize when needed.
2017-03-07 20:57:49 -07:00
John Kessenich
ca71d946d7 HLSL: Grammar: Generalize accepting a declaration to accept an aggregate of subtrees.
This is slightly cleaner today for entry-point wrapping, which sometimes made
two subtrees for a function definition instead of just one subtree.  It will be
critical though for recognizing a struct with multiple member functions.
2017-03-07 20:44:09 -07:00
steve-lunarg
3ce4536ac8 HLSL: use LOD form of ImageQuerySize when needed.
The non-LOD form of image size query is prohibited in certain cases:
see the OpImageQuerySize and OpImageQuerySizeLod sections of the SPIR-V
spec for details.  Sometimes we were generating the non-LOD form when
we should have been using the LOD form.  Sometimes the LOD form is required
even if the underlying HLSL query did not supply a MIP level itself,
in which case level 0 is now queried.
2017-03-07 19:30:25 -07:00
steve-lunarg
40efe5cee8 WIP: HLSL: Fix ordering defect if global SB decl after fn param
This change propagates the storage qualifier from the buffer object to its contained
array type so that isStructBufferType() realizes it is one.  That propagation was
happening before only for global variable declarations, so compilation defects would
result if the use of a function parameter happened before a global declaration.

This fixes that case, whether or not there ever is a global declaration, and
regardless of the relative order.

This changes the hlsl.structbuffer.fn.frag test to exercise the alternate order.

There are no differences to generated SPIR-V for the cases which successfully compiled before.
2017-03-06 12:08:41 -07:00
John Kessenich
c18cae2145 Merge pull request #748 from dgkoch/dgkoch_build_fixes2
More build fixes
2017-03-03 09:20:43 -07:00
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
John Kessenich
854fe24786 HLSL: Fix #747: accept 'struct' in front of previously user-defined type name. 2017-03-02 14:30:59 -07: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
t.jung
8bb3ee53c5 added semantic handling and support for remapping variables with semantics
Change-Id: I3c6b5fc1d4f1da6ec6f436fea72849453a13559d
2017-02-14 17:58:37 +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