Commit Graph

606 Commits

Author SHA1 Message Date
John Kessenich
c7a84a9247
Merge pull request #1567 from Igalia/apinheiro/xfb-1535
ParseHelper: assign global XfbBuffer to a block missing it
2018-11-27 07:17:10 -07:00
John Kessenich
d7baecfab7
Merge pull request #1595 from dgkoch/EXT_fragment_invocation_density
Implement GL_EXT_fragment_invocation_density
2018-11-27 06:41:36 -07:00
Daniel Koch
5154db5183 Implement GL_EXT_fragment_invocation_density
including SPV generation using SPV_EXT_fragment_invocation_density.
This is an alias of the functionality in SPV_NV_shading_rate, and thus in some
cases we can only have one set of the tokens present (switch statements), so
we have picked the EXT version. This required updating the expected test
results for SPV_NV_shading_rate.

Also updated the known-good for spirv-headers so that the validator in
spirv-tools knows about the new extension.
2018-11-26 10:01:58 -05:00
Neil Henning
81a63f1de0 Add conversion folding when the source is a constant.
This change adds unary conversion folding when the source is a constant.
This fixes an ISV issue whereby:

```
const float16_t f = float16_t(42.0);
```

Wouldn't compile because the conversion operator would always produce an
EvqTemporary when it could have produced an EvqConst.

I've also added a test case that proves out that all basic-type to
basic-type conversions work.
2018-11-26 12:45:33 +00:00
John Kessenich
f2675d4d6c GLSL: Fix #1591: Require the id in subgroupBroadcast to be constant. 2018-11-21 15:16:30 -07:00
John Kessenich
e3b76ed608 Merge branch 'scalar_block_layout' of https://github.com/jeffbolznv/glslang into jeffbolznv-scalar_block_layout 2018-11-16 09:57:33 -07:00
t.jung
b16bea801c [HLSL/Spir-V] fix for incorrect spir-v on int dot(int, int)
Decomposes OpDot into corresponding multiplies and additions.
2018-11-15 11:02:30 +01:00
Jeff Bolz
7da39ed968 Implement GL_EXT_scalar_block_layout 2018-11-14 09:30:53 -06:00
t.jung
8279f0728a Updated type conversion rules for HLSL frontend 2018-11-14 08:13:32 +01:00
Alejandro Piñeiro
adba7dfc68 ParseHelper: assign global XfbBuffer to a block missing it
If a block has assigned a XfbOffset it is assumed that it would
inherit the current global XfbBuffer. This commit fixes two use cases:

1) Getting the members of a Block with a XfbOffset to be assigned an
   offset, as explained on GLSL 4.60 spec, section "4.4.2 Output
   Layout Qualifiers", subsection "Transform Feedback Layout
   Qualifiers".

2) Compute properly an error on overlapping ranges if a block is
   assigned a XfbOffset and one of it members is assigned a explicit
   one. This gets working because when the members of a block get
   assigned a Offset/Buffer at fixBlockXfbOffsets, then the block is
   deassigned the Offsets, so ranges are computed only with the block
   members.

BTW, this is already done when redeclaring block builtins.

Fixes #1535
2018-11-10 11:35:50 +01:00
John Kessenich
918caa7ee4
Merge pull request #1547 from Igalia/apinheiro/xfb-struct-assignment
Apinheiro/xfb struct assignment
2018-11-09 12:27:39 -07:00
Jeff Bolz
02ed310ac3 Rename PCH macro to glslang_pch (to avoid name collision) and update to latest spirv-tools 2018-11-07 09:35:31 -06:00
Jeff Bolz
22d0b7cbad Use precompiled headers for some glslang projects 2018-10-31 15:38:08 -05:00
Ashwin Lele
ff1783db87 Multiple features and misc fixes for final raytracing non experimental version. 2018-10-31 07:55:24 -07:00
Alejandro Piñeiro
af8c1bdb16 ParseHelper: assign xfb_offset for struct members too
If the out variable is a struct type, with a xfb_offset explicitly
assigned, the members need to get their xfb_offset assigned. This is
specially relevant, as we cannot use layout qualifiers on struct
members.
2018-10-31 10:34:44 +01:00
John Kessenich
25ed3fce0c
Merge pull request #1542 from sheredom/fix_8bit_storagebuffer
Fix 8-bit storage nearly always using the UniformAndStorageBuffer8BitAccess capability.
2018-10-26 10:27:46 -06:00
Neil Henning
b6b01f067b Fix 8-bit storage nearly always using the
UniformAndStorageBuffer8BitAccess capability.

When using the 8-bit storage extension it basically always used the
`UniformAndStorageBuffer8BitAccess` capability, even in cases where it
wasn't required. For instance if we are targeting Vulkan 1.1 (SPIR-V 1.3
or higher), and we are only using 8-bit types in an SSBO, we only need
the `StorageBuffer8BitAccess` capability.

I fixed this by enabling storage buffer use in Vulkan 1.1 / SPIR-V 1.3
or higher, and then changing the logic to match.

I also added some tests that will output different capabilities when run
on Vulkan 1.0 and 1.1, thus they are added twice to the test list (one
for each version).

Fixes #1539
2018-10-26 14:23:41 +01:00
Sahil Parmar
38772c0434 Allow GL_NV_mesh_shader in fragment shaders for perprimitiveNV
- Emit relevant capability/extension for use of perprimitiveNV in fragment shader
- Remove redundant checks for mesh shader qualifiers in glslang.y
- Add profile version check for use of extension GL_NV_mesh_shader
- Add a new gtest for use of perprimitiveNV in fragment shader
2018-10-25 23:50:59 -07:00
Sahil Parmar
035cbbe3d0 Allow redeclaration of builtin interface blocks in mesh shader
Apart from allowing redeclaration of gl_MeshPerVertexNV and gl_MeshPerPrimitiveNV blocks, this change also -
- Resize clip/cull perview distances based on static index use
- Error out use of both single-view and per-view builtins
- Add new gtests with redeclared blocks and edit existing test output
- Fix couple of typos
2018-10-04 16:39:18 -07:00
Chao Chen
5b2203db04 Add-support-for-SPV_NV_shading_rate 2018-09-19 13:07:43 -07:00
Chao Chen
b50c02ef53 Add-support-for-SPV_NVX_raytracing 2018-09-19 13:07:43 -07:00
Chao Chen
3c3669904c Add-support-for-SPV_NV_mesh_shader 2018-09-19 13:07:43 -07:00
Chao Chen
3a1379667d 0003-Add-support-for-SPV_NV_shader_image_footprint 2018-09-19 13:07:42 -07:00
Chao Chen
beae2251b7 Add-support-for-SPV_NV_compute_shader_derivatives 2018-09-19 13:07:42 -07:00
Chao Chen
9eada4b971 Add-support-for-SPV_NV_fragment_shader_barycentric 2018-09-19 13:07:42 -07:00
Jeff Bolz
36831c9bad GL_KHR_memory_scope_semantics 2018-09-06 20:36:14 -05:00
John Kessenich
97068d8b30
Merge pull request #1465 from otakuto/remove-execute-permissions
Remove execute permissions
2018-08-31 08:14:47 -07:00
John Kessenich
c340425bb2 SPV: Add option for controling when the SPIRV-Tools validator is used. 2018-08-23 15:29:08 -06:00
John Kessenich
717c80a9de SPV: Isolate SPIRV-tools glue to its own file. 2018-08-23 15:17:10 -06:00
otakuto
d03da06ac1 Remove execute permissions 2018-08-07 03:16:20 +09:00
John Kessenich
41436ad204 Link/SPV: Correct symbol IDs on merging ASTs to a single coherent space
This is one step in providing full linker functionality for creating
correct SPIR-V from multiple compilation units for the same stage.
(This was the only remaining "hard" part. The rest should be simple.)
2018-07-18 18:07:41 -06:00
John Kessenich
cf6bd066b9 HLSL: Fix #1432: Globally initialize local static variables. 2018-07-11 01:09:14 -06:00
John Kessenich
312dcfb070 Implement GL_EXT_shader_16bit_storage and GL_EXT_shader_8bit_storage extensions.
These introduce limited support for 8/16-bit types such that they can only be accessed in buffer memory and converted to/from 32-bit types.

Contributed from Khronos-internal work.
2018-07-03 13:51:31 -06:00
John Kessenich
ab8960fd12
Merge pull request #1416 from aejsmith/samplerless-texture-functions
Add support for GL_EXT_samplerless_texture_functions
2018-07-02 18:35:41 -06:00
John Kessenich
802c62bca4 PP: Rationalize return values of MacroExpand.
This results in better error recovery, including fewer
crashes on badly formed PP input.
2018-07-02 13:47:31 -06:00
Alex Smith
e47bfaedf6 Add support for GL_EXT_samplerless_texture_functions 2018-07-01 10:58:53 +01:00
John Kessenich
1ea1b13f38 Testing: Add new tests, and new ways of testing, for floating-point.
- Adds a pragma to see binary output of double values (not portable)
- Print decimals that show more values, but in a portable way
  (lots of portability issues)
- Expand the tests to test more double values

Note: it is quite difficult to have 100% portable tests for floating point.
The current situation works by not printing full precision, and working around
several portability issues.
2018-05-24 18:18:22 -06:00
LoopDawg
c59916710e HLSL: allow self-type cast (as no-op passthrough)
Previously, casting an object of a struct type to an identical type
would produce an error.  This PR allows this case.

As a side-effect of the change, several self-type casts in existing
tests go away.  For example:

    0:10          Construct float ( temp float)
    0:10            'f' ( in float)

becomes this (without the unneeded constructor op):

    0:10          'f' ( in float)

For vector or array types this can result in somewhat less overall code.

Fixes: #1218
2018-05-17 13:03:12 -06:00
LoopDawg
4e6d3eaf5d HLSL: require coverage mask to be arrayed output.
SPIR-V requires the coverage mask to be an array of integers, but HLSL
allows scalar integers.  This adds the requisite type conversion and
wrapped entry point handling.

Fixes: #1202
2018-05-16 13:58:10 -06:00
John Kessenich
cfb05ec702
Merge pull request #1379 from LoopDawg/groupid-fix
HLSL: various SPIR-V compute shader IDs must be 3-vectors of integers
2018-05-16 10:36:16 -06:00
LoopDawg
91a8178efb HLSL: various SPIR-V compute shader IDs must be a 3-vector of integers.
This PR forces the external definition of SV_GroupID variables to 3-vectors.
The conversion process between the shader-declared type and the external type
happens in wrapped main IO variable conversion.

The same applies to SV_DispatchThreadID and SV_GroupThreadID.

Fixes: #1371
2018-05-16 06:48:02 -06:00
LoopDawg
1326b8c754 HLSL: Allow stream output Append() method after entry point.
Append() method is special: unlike most outputs, it does not copy
some temporary data to a symbol in the entry point epilogue, but
rather uses an emit builtin after each write to the output stream.

This had been handled by remembering the special output symbol for
the stream as it was declared in the shader entry point before
symbol sanitization.  However the prior code was too simple and
only handled cases where the Append() method happened after the
entry point, so that the output symbol had been seen.

This PR adds a patching step so that the Append()s may appear in
any order WRT the entry point.  They are patched in an epilogue,
whereupon it is guaranteed in a well formed shader that we have
seen the appropriate declaration.

Fixes #1217.
2018-05-15 15:13:09 -06:00
John Kessenich
b92ce60fc7 GLSL/SPV: Fix #1310: don't create unnecessary integer matrices. 2018-04-07 18:49:54 -06:00
John Kessenich
5611c6d27b GLSL/SPV: Implement SPV_EXT_descriptor_indexing and GL_EXT_nonuniform_qualifier 2018-04-05 11:25:02 -06:00
John Kessenich
6a4a427efe GLSL: Implement correct semantic checking for run-time sized arrays. 2018-04-02 14:52:15 -06:00
John Kessenich
5a867acad5 Linker: Fix #1329: correctly merge unsized arrays, and fix link tests. 2018-04-01 21:22:34 -06:00
Jeff Bolz
2abe9a4d34 Implement GL_NV_shader_subgroup_partitioned 2018-03-29 22:52:17 -05:00
GregF
fb03a55e0f Only print legalization warning if optimizer disabled 2018-03-29 13:17:54 -06:00
John Kessenich
859b0342b8 Types: Fix #1290: Rationalize and correct "mixed" style array dimensioning.
There a couple functional problems, which when reduced down also led to
some good simplifications and rationalization.  So, this commit:
 - corrects "mixed" functionality: int[A] f[B] -> f[B][A]
 - correct multi-identifier decls: int[A] f[B], g[C] -> f and g are independently sized.
 - increases symmetry between different places in the code that do this
 - makes fewer ways to do the same thing; several methods are just gone now
 - makes more clear when something is copied or shared
2018-03-26 00:38:53 -06:00
John Kessenich
7cec64fc42 Non functional: add EshTargetClientVersion alias for EShTargetClientVersion.
Fixes #1304.
2018-03-22 23:54:04 -06:00
John Kessenich
e7e081bda9 PP: don't give errors on some tokens under #if 0 (or similar).
Fixes #1295.

Tokens that are accepted by any version of HLSL or GLSL should be
allowed when #ifdef'd off, such that errors are not reported.
2018-03-19 00:43:18 -06:00
John Kessenich
cd23a47566
Merge pull request #1291 from ben-clayton/add-nv-nopersp
Add support for GL_NV_shader_noperspective_interpolation
2018-03-16 15:50:38 -06:00
Ben Clayton
f648083365 Add tests for GL_NV_shader_noperspective_interpolation 2018-03-16 16:49:29 +00:00
John Kessenich
647fccaf2f AST: Fix shift conversions, which don't require matching types.
The base and shift amount need to be integers, but not of the same type.
This fixes #1296 and replaces #1297.
2018-03-15 21:11:36 -06:00
John Kessenich
66011cb2c2 SPV: Implement Vulkan 1.1 features and extensions. 2018-03-06 16:12:04 -07:00
John Kessenich
b2ae1d0521 Revert "Merge pull request #1274 from greg-lunarg/legal2"
This reverts commit 2c65069ecd, reversing
changes made to fa9b465b92.
2018-03-06 14:50:41 -07:00
John Kessenich
663b90d908 Build: Fix build issues with previous commit. 2018-03-06 14:20:16 -07:00
GregF
fd50f6a4c3 Legalization: Omit legalization warning when spirv-opt is linked. 2018-03-06 13:00:08 -07:00
Rex Xu
1e5d7b0b27 Implement the extension GL_AMD_gpu_shader_half_float_fetch
- Support new opaque types: f16sampler*, f16image*, f16subpassInput*.
- Add new built-in GLSL texture/image functions.
2018-03-02 16:48:03 +08:00
John Kessenich
46413d5780 SPV: Fix #1258: cache constant structs by id, not opcode.
Constants were generally cached by type opcode, but all structures share the
same type opcode (OpTypeStruct), so they need to be cached by type id.
2018-02-26 19:35:39 -07:00
John Kessenich
9c9c4e90df GLSL/SPV: Fix #1196: Require resources to have layout(binding=X). 2018-02-22 11:47:41 -07:00
John Kessenich
2d9973de0e Tests: specExamples.vert is used twice, it needs two different output names. 2018-02-21 18:42:10 -07:00
LoopDawg
4425f245a5 HLSL: Add conversions for image ops during SPV construction
HLSL allows image and texture types to be templatized on sub-vec4 types,
or even structures.  This was mostly handled already during creation of
sampling operations.  However, for operator[] which can generate image
loads, this wasn't happening.

It also isn't very easy to do at that point in time, because operator[]
does not know where the results it produces will end up.  They may be
an lvalue or an rvalue, and there's a post-process to convert loads to
stores.  They may end up in atomic ops.

To bypass that difficulty, GlslangToSpv now looks for this case and
adds the appropriate conversion.  LIMITATION: this only works for
cases for which a simple conversion opcode suffices.  That is to say,
it will not work if the type is templatized on a struct.
2018-02-18 13:13:36 -07:00
John Kessenich
a2858d9bdd GLSL: Implement GL_EXT_control_flow_attributes.
See https://github.com/KhronosGroup/GLSL/pull/11.
2018-02-01 00:55:08 -07:00
John Kessenich
e18fd20d5c HLSL: Refactor attribute implementation.
- make it sharable with GLSL
- correct the case insensitivity
- remove the map; queries are not needed, all entries need processing
- make it easier to build bottom up (will help GLSL parsing)
- support semantic checking and reporting
- allow front-end dependent semantics and attribute name mapping
2018-02-01 00:30:34 -07:00
John Kessenich
eb2c0c72bf GLSL: XFB: more support for built-in block redeclarations with XFB.
- correct inheritence (or not) of the right XFB buffer
- compute implicit stride (fixes #1212)
- semantic check block-member redeclarations
- inherit stride from a member
2018-01-09 18:00:33 -07:00
John Kessenich
8297936dd6 SPV: Change barrier emission to conform to Khronos decisions.
The memory model group agreed to these definitions for how
to map GLSL barrier, memoryBarrier, etc. With HLSL following suit.
2017-12-16 00:30:10 -07:00
John Kessenich
edaf556778 SPV: Plumb through XFB buffer and stride information.
Also, only emit this XFB information where the SPIR-V spec says
it should be emitted: essentially, on objects.

This and the previous commit together fix #1185.
2017-12-15 06:25:14 -07:00
John Kessenich
be3842f6ae GLSL: Implement XFB for redeclared built-in blocks. 2017-12-15 04:43:59 -07:00
Piers Daniell
1c5443c693 Add implementation of SPV_EXT_fragment_fully_covered
This implementation uses the GLSL extension
GL_NV_conservative_raster_underestimation to generate the new SPIR-V
FullyCoveredEXT built in.
2017-12-14 07:42:23 -07:00
LoopDawg
280c75ca51 HLSL: Allow primitive id on hull shader inputs
Fixes #979
2017-12-08 12:01:16 -07:00
John Kessenich
471bfed062 HLSL: Fix #606: make layout() override register. 2017-12-06 08:17:21 -07:00
John Kessenich
cc951f8183 HLSL: Fix #1154: Support PointSize, as an attribute. 2017-12-06 07:33:36 -07:00
John Kessenich
1ce94b2d68
Merge pull request #1166 from tafuri/#1165-invalid_Store
#1165 invalid store
2017-11-28 19:41:52 -07:00
LoopDawg
7ee29ba730 HLSL: allow keyword-identifiers as cbuffer/struct names.
Issue #791 was partially fixed by PR #1161 (the mat mul implicit
truncations were its main point), but it still wouldn't compile due to
the use of ConstantBuffer as an identifier.  Apparently those fall into
the same class as "float float", where float is both a type and an
identifier.

This allows struct definitions with such keyword-identifiers,
and adds ConstantBuffer to the set.  'cbuffer int' is legal in HLSL,
and 'struct int' appears to only be rejected due to the redefinition
of the 'int' type.

Fixes #791
2017-11-28 10:17:19 -07:00
Sebastian Tafuri
66b319d30b Added new test to gtests and updated test data 2017-11-27 17:13:22 +01:00
LoopDawg
2e62910633 HLSL: matrix and vector truncations for m*v, v*m, m*m
HLSL truncates the vector, or one of the two matrix dimensions if there is a
dimensional mismatch in m*v, v*m, or m*m.

This PR adds that ability.  Conversion constructors are added as required.
2017-11-22 12:01:45 -07:00
John Kessenich
cbdf871d7f SPV: SampleMask does not depend on SampleRateShading.
Fixes #1158.
Fixes #1159.
2017-11-20 16:32:49 -07:00
John Kessenich
cb421ef991 Test: Add more legalization tests; those effected by flattening. 2017-11-16 15:02:06 -07:00
John Kessenich
ca4ef9f43b
Merge pull request #1156 from LoopDawg/snorm-uav
HLSL: Accept unorm and snorm on types
2017-11-15 15:30:59 -07:00
LoopDawg
7573a2ab7f HLSL: ignore geometry attributes on non-GS stages.
If a shader includes a mixture of several stages, such as HS and GS,
the non-stage output geometry should be ignored, lest it conflict
with the stage output.
2017-11-15 11:33:25 -07:00
LoopDawg
fa39cffd6a HLSL: Accept unorm and snorm on types
This is currently parsed and ignored, save for some minor validation.
2017-11-14 14:55:40 -07:00
LoopDawg
e5530b92ce HLSL: implement TextureBuffer<type>
Almost equivalent to tbuffer, except members not at global scope.
So, reference is "TextureBuffer_var.member", not simply "member".
2017-11-08 19:48:11 -07:00
John Kessenich
88e22a6090 Fix #1079: don't give error when macro() name used without open (. 2017-11-02 06:48:32 -06:00
John Kessenich
e8d21388ed Fix nondeterminism discussed in 258b700f59 2017-11-02 00:05:53 -06:00
John Kessenich
5866e67b8d Tests: Non-determinancy: Add back in the IntMin tests. 2017-10-28 13:03:49 -06:00
John Kessenich
258b700f59 Non-determinant tests: Remove recent tests, to see if things stabelize.
Both debug and release clang builds have segfaulted on recent
changes, non deterministically, while doing the single/multi-thread
test all test files. Removing recent test files, to see if it gives
a clue.
2017-10-27 04:15:57 -06:00
Aaron Muir Hamilton
f83e2f0690 GLSL: Fold constant SHRT_MIN/INT_MIN/LLONG_MIN % -1 to 0. 2017-10-25 01:32:20 +00:00
Aaron Muir Hamilton
437911af33 GLSL: Check for implicit inner dimension in array of atomic_uint. 2017-10-23 15:31:10 +00:00
Aaron Muir Hamilton
9028ed204d Check for hexadecimal literals exceeding MaxTokenLength. 2017-10-22 17:55:14 +00:00
John Kessenich
1b46f137f7 HLSL: Fix #1106. Support shader setting of binding/set for $Global. 2017-10-19 16:54:25 -06:00
John Kessenich
f0e35bf0ef GLSL: Make sampling operations have agnostic precision qualifiers for desktop.
Desktop defaults to highp for samplers, but this should not apply to the built-in
functions, so make it appy only to user declarations.
2017-10-19 00:32:59 -06:00
John Kessenich
3112b5686d Merge pull request #1113 from xorgy/preprocessor-int-min-over-negative-one
Preprocessor: Evaluate INT_MIN / -1 to 0.
2017-10-19 00:24:05 -06:00
John Kessenich
0b55e0f203 Merge pull request #1102 from KhronosGroup/partially-flatten
HLSL: Partially flatten hierarchies, instead of all or nothing.
2017-10-18 14:53:53 -06:00
Aaron Muir Hamilton
dc756a61c8 Preprocessor: Evaluate INT_MIN / -1 to 0.
This division is undefined behaviour which raises SIGFPE on x86.
  Most C++ preprocessors evaluate this silently to 0.
2017-10-18 19:56:19 +00:00
Aaron Muir Hamilton
5313613dd1 Don't try to swizzle void. 2017-10-17 09:04:38 +00:00
John Kessenich
7d67c6cbc2 PP: Fix #1104: Missing check for #if overflow.
Also, rationalized this to generally make it safer and more readable.
It could use a more modern approach, at some point...
2017-10-16 15:29:07 -06:00
John Kessenich
41aa19953f HLSL: Partially flatten hierarchies, instead of all or nothing.
Fixes #1092.  Allows arrays of opaques to keep arrayness, unless
needed by uniform array flattening.
Can handle assignments of mixed amounts of flattening.
2017-10-12 16:52:32 -06:00
John Kessenich
b27de0289c Merge pull request #1090 from tafuri/#1084-fix-segfault
Only track variables in the global scope
2017-10-07 07:19:21 +03:00
John Kessenich
592e8f0441 HLSL: Tests: Add subset of flattened opaque test to legalize results. 2017-10-06 21:01:07 -06:00
Sebastian Tafuri
4f6865f406 Added test for local structured buffer variable 2017-10-07 00:47:54 +02:00
LoopDawg
73c57bbe50 HLSL: split textures used for both shadow and non-shadow modes
A single texture can statically appear in code mixed with a shadow sampler
and a non-shadow sampler.  This would be create invalid SPIR-V, unless
one of them is provably dead.

The previous detection of this happened before DCE, so some shaders would
trigger the error even though they wouldn't after DCE.  To handle that
case, this PR splits the texture into two: one with each mode.  It sets
"needsLegalization" (if that happens for any texture) to warn that this shader
will need post-compilation legalization.

If the texture is only used with one of the two modes, behavior is as it
was before.
2017-10-06 11:23:16 -06:00
John Kessenich
700bdeb742 HLSL: Fix #954: Track/access subsets of flattened multi-level aggregates.
Works in conjuction with d1be754 to represent and modify a partially
dereferenced multi-level flattened aggregate.
2017-10-04 13:40:13 -06:00
LoopDawg
7f93d56ef2 HLSL: add subpass input types and methods
Add support for Subpass Input proposal of issue #1069.

Subpass input types are given as:

    layout(input_attachment_index = 1) SubpassInput<float4> subpass_f;
    layout(input_attachment_index = 2) SubpassInput<int4>   subpass_i;
    layout(input_attachment_index = 3) SubpassInput<uint4>  subpass_u;

    layout(input_attachment_index = 1) SubpassInputMS<float4> subpass_ms_f;
    layout(input_attachment_index = 2) SubpassInputMS<int4>   subpass_ms_i;
    layout(input_attachment_index = 3) SubpassInputMS<uint4>  subpass_ms_u;

The input attachment may also be specified using attribute syntax:

    [[vk::input_attachment_index(7)]] SubpassInput subpass_2;

The template type may be a shorter-than-vec4 vector, but currently user
structs are not supported.  (An unimplemented error will be issued).

The load operations are methods on objects of the above type:

    float4 result = subpass_f.SubpassLoad();
    int4   result = subpass_i.SubpassLoad();
    uint4  result = subpass_u.SubpassLoad();

    float4 result = subpass_ms_f.SubpassLoad(samp);
    int4   result = subpass_ms_i.SubpassLoad(samp);
    uint4  result = subpass_ms_u.SubpassLoad(samp);

Additionally, the AST printer could not print EOpSubpass* nodes.  Now it can.

Fixes #1069
2017-10-02 12:46:55 -06:00
John Kessenich
77ea30bdc9 HLSL: Additional attribute support: [[]], namespace, parameters:
- support C++11 style brackets [[...]]
- support namespaces [[vk::...]]
- support these on parameter declarations in functions
- support location, binding/set, input attachments
2017-09-30 14:34:50 -06:00
GregF
52fe3d598c Legalization: Fix warnings and disable tests when spirv-tools not present 2017-09-28 10:13:23 -06:00
GregF
cd1f169c6a Enable HLSL legalization
Also added known-good mechanism to fetch latest validated spirv-tools.
Also added -Od and -Os to disable optimizer and optimize for size.

Fetching spirv-tools is optional for both glsl and hlsl. Legalization
of hlsl is done by default if spirv-opt is present at cmake time.
Optimization for glsl is currently done through the option -Os.

Legalization testing is currently only done on four existing shaders.
A separate baseLegalResults directory holds those results. All previous
testing is done with the optimizer disabled.
2017-09-27 15:06:05 -06:00
Rex Xu
e8fe8b0de9 Implement extension GL_NV_shader_atomic_int64 2017-09-27 12:06:27 +08:00
John Kessenich
31365afaf4 Merge pull request #1044 from dsrbecky/image_external_essl3
Add support for GL_OES_EGL_image_external_essl3
2017-09-15 21:10:08 -06:00
LoopDawg
4a145dbf45 HLSL: handle split InputPatch templat type in patch constant functions
InputPatch parameters to patch constant functions were not using the
internal (temporary) variable type.  That could cause validation errors
if the input patch had a mixture of builtins and user qualified members.

This uses the entry point's internal form.

There is currently a limitation: if an InputPatch is used in a PCF,
it must also have appeared in the main entry point's parameter list.
That is not a limitation of HLSL.  Currently that situation is detected
and an "implemented" error results.  The limitation can be addressed,
but isn't yet in the current form of the PR.
2017-09-14 16:50:37 -06:00
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
amhagan
05506bb874 Implement the extension GL_AMD_shader_fragment_mask 2017-09-09 22:05:24 +08:00
LoopDawg
76117921b9 Fix lvalue check in SPIR-V generation
There were several locations in TGlslangToSpvTraverser::handleUserFunctionCall testing for
whether a fn argument should be in the lvalue or rvalue array.  They must get the same
result for indexing sanity, but had slightly different logic.

They're now forced into the same test.
2017-09-06 15:04:52 -06:00
David Srbecký
2c5b3d64af Add support for GL_OES_EGL_image_external_essl3 2017-09-05 14:56:26 +01: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
xavier
eb71cdd5bb HLSL: fix preprocessor concatenation behaviour.
Fix #772.
2017-08-29 00:35:01 +02: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
Rex Xu
129799a709 Implement extension GL_AMD_shader_image_load_store_lod 2017-08-24 06:56:39 +08: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
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
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
934d11b6db GLSL 4.6: Implement shader group vote. 2017-07-31 03:00:04 -06:00
John Kessenich
941f3bbd7a GLSL 4.6: Implement draw parameters. 2017-07-31 03:00:04 -06:00
John Kessenich
0d0c6d38f0 GLSL 4.6: Implement atomic counter ops and SPV_KHR_shader_atomic_counter_ops. 2017-07-31 03:00:04 -06:00
John Kessenich
de16e52b25 GLSL: Initiate version GLSL 460, including accept extraneous semicolons. 2017-07-31 03:00: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
53863a3a90 GLSL: Implement version 320 for ES. 2017-07-23 13:54:15 -06:00
John Kessenich
9353f1afab GLSL: Add version-number checking. 2017-07-23 11:49:42 -06:00
John Kessenich
0e392aa92e Merge pull request #996 from KhronosGroup/decorate-parameters
SPV: Decorate parameters
2017-07-18 03:51:02 -06:00
John Kessenich
961cd35b73 SPV: Fix #995: Include memory decorations on parameters. 2017-07-18 03:07:43 -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
John Kessenich
9645f78293 Merge pull request #965 from chaoc/spv-khr-post-depth-coverage
Implement SPV_KHR_post_depth_coverage
2017-07-05 14:48:19 -06:00
chaoc
c120452754 Implement SPV_KHR_post_depth_coverage
Added support for both extension GL_ARB_post_depth_coverage and GL_EXT_post_depth_coverage.
2017-07-05 12:27:15 -07:00
d3x0r
57a2b22d34 Update CMakeLists.txt 2017-07-04 05:59:03 -07:00
David Srbecký
0fbe02c6a0 Implement extensions GL_OVR_multiview and GL_OVR_multiview2
They are almost identical to the already supported GL_EXT_multiview
2017-06-30 19:11:56 +01: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
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
Rex Xu
cabbb788b4 Implement extension GL_AMD_gpu_shader_int16
- Add int16 types (int16_t, uint16_t, i16vec, u16vec).
- Add int16 support to GLSL operators.
- Add int16 type conversions (to int16, from int16).
- Add int16 built-in functions.
2017-06-09 17:11:23 +08:00
John Kessenich
4d5bcd3162 HLSL: Allow macro expansions to create the 'defined' operator. 2017-06-08 17:12:56 -06:00
Rex Xu
225e0fcadd Implement the extension GL_AMD_texture_gather_bias_lod 2017-06-05 16:41:06 +08:00
John Kessenich
0b94a31ee9 Merge pull request #915 from LoopDawg/subvec4-intrinsic
HLSL: add test coverage for sub-vec4 texture intrinsics
2017-06-03 15:28:11 -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
d66c5b1299 HLSL: iomapper: Fix #914. Tolerate user aliasing of bindings.
Because it is valid in HLSL to alias bindings:
A) remove validation that aliasing is not done
B) make the algorithms tolerate aliasing
2017-06-01 18:16:33 -06:00
LoopDawg
a696fd1a44 HLSL: add test coverage for sub-vec4 texture intrinsics
This changes no functional code.  There was a bit of a testing hole
in that textures templatized on sub-vec4 types were not being exercised
with any intrinsics.  This adds some basic sanity coverage of that case.
2017-06-01 13:28:12 -06:00
t.jung
baf570efa5 Pure Texture to Sampled Texture Transform
Adds a transformation step to the post processing step.
Two modes are available:
1) keep
- Keeps samplers, textures and sampled textures as is
2) transform pure texture into sampled texture and remove pure samplers
- removes all pure samplers
- transforms all pure textures into its sampled counter part

Change-Id: If54972e8052961db66c23f4b7e719d363cf6edbd
2017-05-29 18:29:45 +02: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
LoopDawg
132a28aac4 HLSL: allow name mangling based on texture template type
Name mangling did not account for the vector size in the template type of a texture.
This adds that.  The mangle is as it ever was for the vec4 case, which leaves
all GLSL behavior and most HLSL behavior uneffected.  For vec1-3 the size is added
to the mangle.

Current limitation: textures cannot presently be templatized on structured types,
so this works only for vectors of basic types.

Fixes #895.
2017-05-19 20:12:50 -06:00
John Kessenich
ab0847ef01 Merge pull request #896 from KhronosGroup/spv-location
SPV: Give error on not assigning locations to I/O when generating SPIR-V.
2017-05-18 21:12:04 -06:00
LoopDawg
65c2eed65d Remapper: handle embedded opcode in OpSpecConstantOp
OpSpecConstantOp contains an embedded opcode which is given as a literal
argument to the OpSpecConstantOp.  The subsequent arguments are as the
embedded op would expect, which may be a mixture of IDs and literals.  This
adds support for that to the remapper binary parser.  Upon seeing such an
embedded op, the parser flips over to parsing the argument list as
appropriate for that opcode.

Fixes #882.
2017-05-18 16:13:04 -06:00
John Kessenich
71facdf435 SPV: Give error on not assigning locations to I/O.
Also, provides an option to auto-assign locations.
Existing tests use this option, to avoid the error message,
however, it is not fully implemented yet.
2017-05-18 15:07:05 -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
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
John Kessenich
c10191d132 SPV: Support texelFetch() on a textureBuffer (no sampler).
Fixes Vulkan Khronos-internal issue 770.
2017-05-08 00:12:28 -06: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
David Seifert
22afc38b55 Modernise CMake #2
This reverts commit cfc69d95af.
* Change CMAKE_INSTALL_PREFIX default on Windows in order
  to prevent permission denied errors when trying to install
  to "Program Files".
2017-04-29 11:23:15 +02:00
John Kessenich
cfc69d95af Revert "Modernise CMake" 2017-04-28 22:04:24 -06:00
David Seifert
8f824265ea Make test suite optional by using CTest 2017-04-28 22:46:52 +02:00
David Seifert
5a5699bdbd Modernise CMake
* Use `GNUInstallDirs` in order to respect GNU conventions.
  This is especially important for multi-arch/multi-lib setups.
* Specify position independent mode building properly, without
  using the historic hack of adding `-fPIC` as a definition.
  This makes the build system more portable.
* Only detect C++ (and not C) to slightly speed up configuring.
* Specify C++11 mode using modern CMake idioms.
* Fix some whitespace issues.
2017-04-28 22:46:52 +02:00
steve-lunarg
c0043cda82 HLSL: Allow empty struct initializers
Review request: does this harm GLSL in any way?
2017-04-27 18:22:52 -06:00
steve-lunarg
a766b838f5 HLSL: Add ConstantBuffer<T> syntax
Note: multi-dimension arrays of ConstantBuffer objects will go through uniform flattening.
2017-04-25 09:30:28 -06: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
670271890d SPV: Support test #pragma for generating the StorageBuffer storage class.
Longer term, this storage class should be generated based on the mode
of compilation.
2017-04-19 18:34:49 -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
97366a0df0 HLSL: Fix #770: implicitly convert bool operands to numeric operators. 2017-04-12 22:38:24 -06:00
John Kessenich
a0c578a6df HLSL: Fix #758: Support character literals (except for numeric escape sequences). 2017-04-12 16:58:30 -06:00
John Kessenich
776c515ea5 HLSL: Support 1.#INF and -1.#INF syntax. 2017-04-12 13:40:53 -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
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
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
9ce76553b8 Merge pull request #797 from steve-lunarg/scalar-length
HLSL: allow length() on scalars
2017-03-31 09:26:47 -06:00
John Kessenich
18958f6cd2 HLSL: Fix #802: Preserve promoted child under ! operator. 2017-03-30 23:32:21 -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
John Kessenich
8f9fdc986a HLSL: Add namespace grammar and some basic semantics.
Unknown how extensive the semantics need to be yet. Need real
feedback from workloads. This is just done as part of unifying it
with the class/struct namespaces and grammar productions.
2017-03-30 16:30:17 -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
Rex Xu
86e49d1773 HLSL: Move frexp() to a separate test file. 2017-03-29 17:04:58 +08:00
John Kessenich
0e7378446b Fix #790: Don't emit NV-specific interface members unless enabled by extension. 2017-03-24 18:40:40 -06:00
steve-lunarg
1ca04c2bbd HLSL: allow length() on scalars 2017-03-24 10:12:53 -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
7a41f96d10 HLSL: Implement 'this' keyword. 2017-03-22 11:38:22 -06:00
John Kessenich
4960baaf66 HLSL: Basic turn on of non-static member functions.
Still need: pass by reference in SPIR-V and symbol-table level
for accessing 'this' members from member functions.
2017-03-19 18:09:59 -06: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
6e1d50a7a2 HLSL: Accept SV_Cull/ClipDistanceN, by refactoring the way semantics are mapped. 2017-03-09 14:37:32 -07: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
33f85b6e59 SPV: Allow push constant buffers to not have an instance name. 2017-03-06 08:51:35 -07: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
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
John Kessenich
6c8aaacd28 SPV: Implement new extensions GL_KHX_device_group and GL_KHX_multiview.
These correspond to SPV_KHR_device_group and SPV_KHR_multiview.
Also, bring tests up to date with Khronos internals, and some misc. related changes.
2017-02-27 01:20:51 -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
John Kessenich
4a57dced66 SPV: Handle nested opaque types as function parameters. 2017-02-24 19:22:54 -07:00
steve-lunarg
932bb5cc4e Add reflection queries for thread local size and ssbo auto-binding
New command line option --shift-ssbo-binding mirrors --shift-ubo-binding, etc.

New reflection query getLocalSize(int dim) queries local size, e.g, CS threads.
2017-02-22 09:40:28 -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
chaoc
df3956c50f Implement NVX_multiview_per_view_attributes 2017-02-14 15:04:33 -08: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
65ee230f1c HLSL: Add tests and refine what decorations are passed through per stage/in/out. 2017-02-06 23:13:16 -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
0fe106afd2 AST: Have type deepCopy() preserve type graphs as graphs.
Previously, a type graph would turn into a type tree. That is,
a deep node that is shared would have multiple copies made.

This is important when creating IO and non-IO versions of deep types.
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
Markus Tavenrath
7b89e75213 Use correct OriginUpperLeft when linking more than one shader. 2017-01-25 12:11:16 -08:00
chaoc
771d89fc36 support SPV_NV_viewport_array2 and SPV_NV_stereo_view_rendering 2017-01-20 16:48:26 -08: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
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
Rex Xu
430ef40ab4 Implement new revision of extension GL_AMD_shader_ballot
- Add support for invocation functions with "InclusiveScan" and
  "ExclusiveScan" modes.
- Add support for invocation functions taking int64/uint64/doube/float16
  as inout data types.
2017-01-19 12:09:51 +08: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
John Kessenich
dc1a8196cf Infrastructure: Support standard build with ENABLE_HLSL set to off. 2017-01-11 14:50:16 -07:00
John Kessenich
facde2c804 PP #include: address PR feedback. 2017-01-06 16:48:18 -07:00
John Kessenich
63204c2501 External interface change: PP: Full <> and "" semantics for the Includer.
Any previous use would only be for "", which would probably mean changing

    include(...)  -> includeLocal(...)

See comments about includeLocal() being an additional search over
includeSystem(), not a superset search.

This also removed ForbidIncluder, as
 - the message in ForbidIncluder was redundant: error results were
   already returned to the caller, which then gives the error it
   wants to
 - there is a trivial default implementation that a subclass can
   override any subset of (I still like abstract base classes though)
 - trying to get less implementation out of the interface file anyway
2017-01-06 15:08:54 -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
bf9a2f30c9 Merge pull request #648 from steve-lunarg/type-identifiers
HLSL: allow type keywords as identifiers, and add half type
2017-01-04 14:07:34 -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
faa720f14c PP: Fix issue #426, recover from bad-source macro expansion. 2017-01-02 17:56:08 -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
5ca85ad9de HLSL: allow scalar type keywords as identifiers, and add half type support.
HLSL allows type keywords to also be identifiers, so a sequence such as "float half = 3" is
valid, or more bizzarely, something like "float.float = int.uint + bool;"

There are places this is not supported.  E.g, it's permitted for struct members, but not struct
names or functions.  Also, vector or matrix types such as "float3" are not permitted as
identifiers.

This PR adds that support, as well as support for the "half" type.  In production shaders,
this was seen with variables named "half".  The PR attempts to support this without breaking
useful grammar errors such as "; expected" at the end of unterminated statements, so it errs
on that side at the possible expense of failing to accept valid constructs containing a type
keyword identifier.  If others are discovered, they can be added.

Also, half is now accepted as a valid type, alongside the min*float types.
2016-12-27 11:26:45 -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
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
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
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