Commit Graph

539 Commits

Author SHA1 Message Date
Rex Xu
827b23b8a1 Parser: Redeclare gl_ClipDistance/gl_CullDistance should update their array sizes. 2016-05-11 15:50:41 +08:00
John Kessenich
3357d870e4 Merge pull request #222 from Qining/support-precise
Full stack: Support *precise* qualifier
2016-05-09 20:18:33 -06:00
John Kessenich
7b3096a93d Merge pull request #270 from scyganINTEL/bitfield_buildins
Use proper precision qualifiers for bitfield build-in functions on ES
2016-05-09 20:17:40 -06:00
GregF
5bdf49cdc8 fix check for non-positive array size 2016-05-09 17:07:04 -06:00
scygan
9c56d84b73 Use proper precision qualifiers for bitfield build-in functions on ES
This change causes ES shaders to precision qualifiers for build-in functions as defined in ESSL spec. It especially mattersfor functions that are defined as highp or taking a highp.

Fixes vulkanCTS dEQP-VK.glsl.builtin.function.integer.bitfieldreverse.*, where bitfieldReverse() retval was wrongly marked as RelaxedPrecision.

Note: floatBitsToInt/floatBitsToUInt precision is also broken, but in different way - so it is not addressed here.
2016-05-09 17:51:25 +02:00
qining
5bec2b5619 integer type operation should not be noContraction 2016-05-09 10:46:40 -04:00
qining
0c96db5a4c add a test for matrix, fix a variable name 2016-05-09 10:46:40 -04:00
qining
1a0d93f416 Fix the test of precise output function parameter
Rebase to 5cc344d8ce and update the
expected test result.
2016-05-09 10:46:40 -04:00
qining
9220dbb078 Precise and noContraction propagation
Reimplement the whole workflow to make that: precise'ness of struct
    members won't spread to other non-precise members of the same struct
    instance.

    Approach:
    1. Build the map from symbols to their defining nodes. And for each
    object node (StructIndex, DirectIndex, Symbol nodes, etc), generates an
    accesschain path. Different AST nodes that indicating a same object
    should have the same accesschain path.

    2. Along the building phase in step 1, collect the initial set of
    'precise' (AST qualifier: 'noContraction') objects' accesschain paths.

    3. Start with the initial set of 'precise' accesschain paths, use it as
    a worklist, do as the following steps until the worklist is empty:

        1) Pop an accesschain path from worklist.
        2) Get the symbol part from the accesschain path.
        3) Find the defining nodes of that symbol.
        4) For each defining node, check whether it is defining a 'precise'
        object, or its assignee has nested 'precise' object. Get the
        incremental path from assignee to its nested 'precise' object (if
        any).
        5) Traverse the right side of the defining node, obtain the
        accesschain paths of the corresponding involved 'precise' objects.
        Update the worklist with those new objects' accesschain paths.
        Label involved operations with 'noContraction'.

    In each step, whenever we find the parent object of an nested object is
    'precise' (has 'noContraction' qualifier), we let the nested object
    inherit the 'precise'ness from its parent object.
2016-05-09 10:46:40 -04:00
John Kessenich
baa9fa5df7 Merge branch 'feature2' of https://github.com/amdrexu/glslang into amdrexu-feature2 2016-05-05 16:32:39 -06:00
John Kessenich
5cc344d8ce Front-End: precise: capture noContraction on output parameter declarations. 2016-05-05 13:36:55 -06:00
John Kessenich
c8a5676025 Merge branch 'feature' of https://github.com/amdrexu/glslang into amdrexu-feature 2016-05-05 12:04:22 -06:00
Lei Zhang
17535f7d55 Create a new logger class for all messages w.r.t. SPIR-V build. 2016-05-05 10:15:06 -04:00
Rex Xu
338b185a2b Implement the extension GL_ARB_shader_group_vote. 2016-05-05 20:38:33 +08:00
Rex Xu
574ab04caa Implement the extension GL_ARB_shader_ballot
Add new built-in variables and functions to the parser (SPIR-V tokens are missing).
2016-05-05 19:02:35 +08:00
John Kessenich
3c1e08057e Front-end precise: Propagate noContraction up the AST when dereferencing structs.
This should be the last commit in this sequence to form the base of the work
in pull request #222.
2016-05-04 13:29:21 -06:00
John Kessenich
17f0786418 Parser: Precise: Recognize 'precise', tag types, and do related semantic checking.
This partly overlaps pull request #222, we have divided the work on this one.
2016-05-04 12:54:56 -06:00
John Kessenich
34fb036a9c HLSL: Add (almost) full expression grammar: Binary, unary (pre/post-fix), assign, ... 2016-05-03 23:33:00 -06:00
John Kessenich
e512cd943e Vulkan: Add the #define VULKAN 100 when compiled for Vulkan.
Note this requires test-based piecing together of the preamble string,
so it changed to being a std::string to make it easier to do.

This closes issue #254.
2016-05-03 21:18:59 -06:00
John Kessenich
af459216a1 Correct precision qualification on built-in functions.
This is a replacement commit for pull request #238.

This is a design change, followed by implementation change that
A) fixes the changes caused by the design change, and
B) fixes some cases that were originally incorrect.

The design change is to not give built-in functions default precision qualification.
This is to allow the rule that the precision of some built-in functions adopt their
precision qualification from the calling arguments.  This is A above.

A consequence of this design change is that all built-ins that are supposed to have
an explicit precision qualifier must now be declared that way.  So, a lot more
built-in declarations now have precision qualifiers, just to keep things the same.
This is B above.
2016-05-03 19:34:00 -06:00
Rex Xu
8ff43de891 Implement the extension GL_ARB_gpu_shader_int64
- Add new keyword int64_t/uint64_t/i64vec/u64vec.
- Support 64-bit integer literals (dec/hex/oct).
- Support built-in operators for 64-bit integer type.
- Add implicit and explicit type conversion for 64-bit integer type.
- Add new built-in functions defined in this extension.
2016-04-30 13:34:34 +08:00
qining
94a89d51f3 add .err file for eof_missing test 2016-04-27 10:22:22 -04:00
qining
19647a32b9 Fix the infinite loop when an input file lacks EOF
The input scanner can be trapped in an infinite loop if the given input
file does not have EOF (and is not ended with a 'whitespace').

The problem is caused by unget(), which keeps rolling back the scanner
pointer without hitting an EOF at the end of the file. This makes getch()
function keep returning the last character of the file and never ends,
and the effect of advance() is always counteracted by unget().
2016-04-27 10:05:57 -04:00
Rex Xu
c7d3656dde SPV: Use OpLogicalEqual/OpLogicalNotEqual for boolean type comparison. 2016-04-27 08:15:37 +08:00
qining
1f2820a3d3 fix the problem that spec constant composite instruction being used when only front-end constants are used in the constructor 2016-04-14 18:34:27 -04:00
qining
27e04a004d Fix spec const construtor for matrix and vector
Fix issue: #237

1. The code generated for matrix constructor should 1) build column
vectors first, 2) build matrix with the vectors.

2. When there is only one scalar type constituent in vector's
constructor, we should populate the constituent to fill all the slots in
the vector. As for matrix, the single constituent should be populated to
the diagonal positions (top-left to bottom-right diagonal).

remove createSpvConstantFromConstSubTree()
2016-04-14 17:52:57 -04:00
qining
189b2033a4 Refine the code and address comments 2016-04-12 23:19:28 -04:00
qining
e24aa5edbb SpecOp bool->uint/int and uint<->int conversion
Bool -> uint/int with OpSpecConstantOp OpSelect instruction.

uint <-> int conversion with OpSpecConstantOp OpIAdd instruction.

Note, implicit conversion: `const uint = an_int_spec_constant` is not
supported. Explicit type casting is required: `const uint =
uint(an_int_spec_constant)`
2016-04-12 22:01:55 -04:00
John Kessenich
78a6b78810 Front-end: Get the right set of nodes marked as spec-const.
This is according to the expected KHR_vulkan_glsl without floating point.
So, floating-point spec-const operations no longer work, and that's
reflected in the tests.
2016-04-06 13:32:44 -06:00
qining
75d1d80109 add SpecConstantOpModeGuard to GlslangToSpvTraverser::visitSymbol() 2016-04-06 14:42:01 -04:00
qining
408876600f Turn on SpecConstantOpMode based on node qualifier
Move SpecConstantOpModeGuard from makeSpvConstantFromConstSubTree() to
visitbinary() and visitunary(). Checking if the visiting node is a spec
constants, if so, turn on the SpecConstantOpMode, otherwise, stay in the
normal mode.
2016-04-06 12:56:31 -04:00
qining
4c9126153d fix the wrong generated code when a non-constant array is declared with its size derived from spec constant operations 2016-04-06 12:51:50 -04:00
John Kessenich
aa0298bfde Merge pull request #220 from Qining/fix-built-in-spec-constants
Handle built-in constants redeclared with a specialization constant id.
2016-04-04 15:43:58 -06:00
qining
4f4bb81cd9 Built-in values declared as specialization constant
Support declaring built-in values as spec constants.

Refine the code in createSpvConstant().
2016-04-04 11:10:41 -04:00
John Kessenich
1c7e70763b Merge branch 'master' into hlsl-frontend 2016-04-03 20:36:48 -06:00
John Kessenich
a42533eca1 Merge pull request #190 from antiagainst/gtest
Add Google Test as the new test framework
2016-03-31 12:31:45 -06:00
John Kessenich
af59197ba4 Merge pull request #214 from amdrexu/bugfix
Parser: Update array size of gl_ClipDistance/gl_CullDistance in gl_in[].
2016-03-31 12:28:47 -06:00
qining
5c61d8e0f9 fix format; remove unnecessary parameters; rename some spec op mode guard class; remove support of float point comparison and composite type comparison; update the tests. 2016-03-31 13:57:28 -04:00
Lei Zhang
414eb60482 Link in Google Test framework.
The existing test harness is a homemade shell script. All the tests
and the expected results are written in plain text files. The harness
just reads in a test, invoke the glslangValidator binary on it, and
compare the result with the golden file. All tests are kinda
integration tests.

This patch add Google Test as an external project, which provides a
new harness for reading shader source files, compile to SPIR-V, and
then compare with the expected output.
2016-03-31 10:31:30 -04:00
qining
135452061a Spec Constant Operations
Approach:
Add a flag in `Builder` to indicate 'spec constant mode' and 'normal
mode'. When the builder is in 'normal mode', nothing changed. When the
builder is in 'spec constant mode', binary, unary and other instruction
creation rountines will be redirected to `createSpecConstantOp()` to
create instrution at module level with `OpSpecConstantOp <original
opcode> <operands>`.

'spec constant mode' should be enabled if and only if we are creating
spec constants. So a flager setter/recover guard is added when handling
binary/unary nodes in `createSpvConstantsFromConstSubTree()`.

Note when handling spec constants which are represented as ConstantUnion
Node, we should not use `OpSpecConstantOp` to initialize the composite
constant, so builder is set to 'normal mode'.

Tests:
Tests are added in Test/spv.specConstantOperations.vert, including:

1) Arithmetic, shift opeations for both scalar and composite type spec constants.
2) Size conversion from/to float and double for both scalar and vector.
3) Bitwise and/or/xor for both scalar and vector.
4) Unary negate/not for both scalar and vector.
5) Vector swizzles.
6) Comparisons for scalars.
7) == and != for composite type spec constants

Issues:
1) To implement == and != for composite type spec constants, the Spec needs
to allow OpAll, OpAny, OpFOrdEqual, OpFUnordEqual, OpOrdNotEqual,
OpFUnordNotEqual. Currently none of them are allowed in the Spec.
2016-03-30 16:18:26 -04:00
Rex Xu
cb0e471ad4 Parser: Update array size of gl_ClipDistance/gl_CullDistance in gl_in[]. 2016-03-27 08:47:43 +08:00
qining
0840838d17 Support specialization composite constants
Fix issue #163, support creation and reference of composite type
specialization constants.

e.g.:
```
layout(constant_id = 200) const float myfloat = 1.25;
layout(constant_id = 201) const int myint = 14;
struct structtype {
  float f;
  int i;
};
const structtype outer_struct_var = {myfloat, myint};
void main(){}
```
generated code (use glslangValidator):
```
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 12

                              Capability Shader
               1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint Vertex 4  "main"
                              Source GLSL 450
                              Name 4  "main"
                              Name 10  "structtype"
                              MemberName 10(structtype) 0  "f"
                              MemberName 10(structtype) 1  "i"
                              Decorate 7 SpecId 200
                              Decorate 9 SpecId 201
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeFloat 32
               7:    6(float) SpecConstant 1067450368
               8:             TypeInt 32 1
               9:      8(int) SpecConstant 14
  10(structtype):             TypeStruct 6(float) 8(int)
              11:10(structtype) SpecConstantComposite 7 9
         4(main):           2 Function None 3
               5:             Label
                              Return
                              FunctionEnd
```

Rname two function names to match their functionalities.
1) Rename `GlslangToSpvTraverser::createSpvSpecConstant()` to
`createSpvConstant()`;
2) Rename `GlslangToSpvTraverser::createSpvConstant()` to
`createSpvConstantFromConstUnionArray()`

Add function `GlslangToSpvTraverser::createSpvConstantFromSubTree()` to
handle constant creation from sub trees (e.g.: specialization constants).

Related PR: #208
2016-03-24 18:04:00 -04:00
John Kessenich
7cc0e2896e Front-end infrastructure: Encapsulate semantic-level questions/actions about const/temp.
Much about const or temp is mechanical, about actual declaration,
while much is semantic, about something higher level.  This commit
checks every use everywhere, and for the high-level ones, substitutes
an encapsulated version instead.
2016-03-20 00:46:02 -06:00
Rex Xu
644c21025d Parser: Type promotion for operator modulus(%) is missing. 2016-03-18 16:26:23 +08:00
Rex Xu
d715adc0f2 SPV: Implement boolean selection for mix().
Use OpSelect to implement boolean selection of mix(). FMix is applicable
to linear blending of mix().
2016-03-15 18:19:26 +08:00
John Kessenich
5f934b039a HLSL: Accept basic funtion definitions. (Not yet mapping input/output for entry point.) 2016-03-13 17:58:25 -06:00
John Kessenich
d016be19fb HLSL: Hook up constructor expressions through the AST. 2016-03-13 11:24:20 -06:00
John Kessenich
87142c71fb HLSL: Add basic declaration syntax and AST generation. 2016-03-12 21:40:38 -07:00
John Kessenich
e01a9bc8c0 HLSL: Plumb in HLSL parse context and keywords, and most basic HLSL parser and test. 2016-03-12 21:40:08 -07:00
Dejan Mircevski
2677d918f1 Test dead-decoration removal. 2016-03-11 12:06:41 -05:00