Commit Graph

521 Commits

Author SHA1 Message Date
Rex Xu
eaf31ab98c Add 8-bit/16-bit transform feedback support for future use 2019-02-03 23:31:32 +08:00
John Kessenich
c9e03360e2
Merge pull request #1675 from nicebyte/ext_yuv_target
Add support for GL_EXT_YUV_target
2019-01-29 19:03:11 -08:00
John Kessenich
31fbc11f5d Build: Remove extra commas in calling INSTANTIATE_TEST_SUITE_P.
Hopefully, this fixes the sudden new breakage with the bots.
2019-01-29 16:00:42 -07:00
nicebyte
c28369b75f Add support for GL_EXT_YUV_target 2019-01-29 13:17:47 -08:00
John Kessenich
544c039d26 HLSL: Fix #1679: Add HLSL earlydepthstencil -> SPV EarlyFragmentTests. 2019-01-28 22:19:43 -07:00
Jeff Bolz
9f2aec49e9 GL_EXT_buffer_reference 2019-01-07 12:36:13 -06:00
John Kessenich
9ed38739b9
Merge pull request #1627 from greg-lunarg/lines8
Add passes to spirv-opt passes to preserve source line info when compiling -g.
2018-12-18 10:38:32 -07:00
Alan Baker
3b656c79f4 Move memory model scope tests to Vulkan 1.1 batch
Fixes #1610

* Updated expected result due to version change
2018-12-17 17:07:55 -05:00
Greg Fischer
5620a2f95e Add passes to legalization to preserve source line info when generated. 2018-12-16 13:13:46 -07:00
Jeff Bolz
61a0cd19cc Fix bug where shaderRecordNV buffers were using StorageBuffer storage class 2018-12-14 20:59:53 -06:00
Rémi Verschelde
ebfd91a719 Remove Unix executable permission from text files 2018-12-10 10:49:16 +01:00
John Kessenich
bd1c1831d5 Manually merge ClemensRognerSD-dx9-sampler and resolve conflicts. 2018-12-07 18:38:26 -07:00
greg-lunarg
5d43c4aac7 SPV: Fix #1575, fix #1593: Support HLSL #line
SPIR-V OpLines now contain filenames from HLSL-style #lines.
2018-12-07 17:36:33 -07:00
Alan Baker
ed777b0fbd Modify testing to only record validation pass/fail
* Changed unit tests to only record known the validation pass/fail
status
 * errors are output as part of the failure message if the result is
 unexpected
 * can turn off validation for each test individually
* Moved some SPV_KHR_vulkan_memory_model tests to be compiled for Vulkan
1.1
2018-12-07 13:58:46 -05:00
Alejandro Piñeiro
16ef9da372 GlslangToSpv: prevent add XfbStride twice
Without this commit, if the XfbStride was explicitly set, the
decoration was added twice on the shader.

v2 (changes after Jonh Kessenich first review)
   * Simplified by just removing the firs assignment
   * Removed assert
2018-11-29 11:49:04 +01:00
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