Give new scopes to non-compound (simple) if-then-else substatements, correcting scoping for declarations they contain.

Also, updated several tests and the Todo list.


git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22845 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-08-27 03:59:04 +00:00
parent 3af0d53dac
commit d46b31fdc5
6 changed files with 272 additions and 55 deletions

View File

@ -80,6 +80,7 @@ void main()
}
gl_FragColor.xr; // ERROR, swizzlers not from same field space
gl_FragColor.xyxyx.xy; // ERROR, cannot make a vec5, even temporarily
centTexCoord.z; // ERROR, swizzler out of range
(a,b) = true; // ERROR, not an l-value
}
@ -103,4 +104,13 @@ bool gen(vec3 v)
{
if (abs(v[0]) < 1e-4 && abs(v[1]) < 1e-4)
return true;
}
}
void v1()
{
}
void v2()
{
return v1(); // ERROR, no expression allowed, even though void
}

View File

@ -11,3 +11,22 @@ void bar2(highp in float b);
smooth flat out vec4 rep; // ERROR, replicating interpolation qualification
centroid sample out vec4 rep2; // ERROR, replicating auxiliary qualification
in uniform vec4 rep3; // ERROR, replicating storage qualification
void main()
{
int i;
if (i == 3)
int j = i;
else
int k = j; // ERROR, j is undeclared
int m = k; // ERROR, k is undeclared
int n = j; // ERROR, j is undeclared
while (true)
int jj;
int kk = jj; // ERROR, jj is undeclared
}
void bar(in highp volatile vec4 v)
{
}

View File

@ -15,16 +15,19 @@ ERROR: 0:63: 'assign' : cannot convert from 'bool' to 'float'
ERROR: 0:79: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type '4-component vector of float' and a right operand of type '4X4 matrix of float' (or there is no acceptable conversion)
ERROR: 0:79: 'assign' : cannot convert from '4X4 matrix of float' to 'fragColor 4-component vector of float'
ERROR: 0:82: 'xr' : illegal - vector component fields not from the same set
ERROR: 0:83: 'z' : vector field selection out of range
ERROR: 0:84: 'assign' : l-value required
ERROR: 0:90: 'int' : overloaded functions must have the same return type
ERROR: 0:90: 'main' : function already has a body
ERROR: 0:90: 'int' : main function cannot return a value
ERROR: 0:91: 'main' : function cannot take any parameter(s)
ERROR: 0:93: 'a' : variables with qualifier 'const' must be initialized
ERROR: 0:96: 'out' : overloaded functions must have the same parameter qualifiers
ERROR: 0:98: 'return' : function return is not matching type:
ERROR: 26 compilation errors. No code generated.
ERROR: 0:83: 'xyxyx' : illegal vector field selection
ERROR: 0:83: 'xy' : dot operator requires structure, array, vector, or matrix on left hand side
ERROR: 0:84: 'z' : vector field selection out of range
ERROR: 0:85: 'assign' : l-value required
ERROR: 0:91: 'int' : overloaded functions must have the same return type
ERROR: 0:91: 'main' : function already has a body
ERROR: 0:91: 'int' : main function cannot return a value
ERROR: 0:92: 'main' : function cannot take any parameter(s)
ERROR: 0:94: 'a' : variables with qualifier 'const' must be initialized
ERROR: 0:97: 'out' : overloaded functions must have the same parameter qualifiers
ERROR: 0:99: 'return' : function return is not matching type:
ERROR: 0:115: 'return' : void function cannot return a value
ERROR: 29 compilation errors. No code generated.
ERROR: node is still EOpNull!
0:21 Function Definition: main( (void)
@ -210,48 +213,58 @@ ERROR: node is still EOpNull!
0:82 'gl_FragColor' (fragColor 4-component vector of float)
0:82 0 (const int)
0:83 direct index (float)
0:83 'centTexCoord' (centroid smooth in 2-component vector of float)
0:83 'gl_FragColor' (fragColor 4-component vector of float)
0:83 0 (const int)
0:84 move second child to first child (bool)
0:84 Comma (bool)
0:84 'a' (int)
0:84 'b' (bool)
0:84 true (const bool)
0:90 Function Definition: main( (int)
0:90 Function Parameters:
0:91 Function Definition: main(i1; (void)
0:84 direct index (float)
0:84 'centTexCoord' (centroid smooth in 2-component vector of float)
0:84 0 (const int)
0:85 move second child to first child (bool)
0:85 Comma (bool)
0:85 'a' (int)
0:85 'b' (bool)
0:85 true (const bool)
0:91 Function Definition: main( (int)
0:91 Function Parameters:
0:91 'a' (in int)
0:96 Function Definition: foo(f1; (int)
0:96 Function Parameters:
0:96 'a' (out float)
0:98 Sequence
0:98 Branch: Return with expression
0:98 3.200000
0:99 Function Call: foo(f1; (int)
0:99 'a' (out float)
0:102 Function Definition: gen(vf3; (bool)
0:102 Function Parameters:
0:102 'v' (in 3-component vector of float)
0:104 Sequence
0:104 Test condition and select (void)
0:104 Condition
0:104 logical-and (bool)
0:104 Compare Less Than (bool)
0:104 Absolute value (float)
0:104 direct index (in float)
0:104 'v' (in 3-component vector of float)
0:104 0 (const int)
0:104 0.000100
0:104 Compare Less Than (bool)
0:104 Absolute value (float)
0:104 direct index (in float)
0:104 'v' (in 3-component vector of float)
0:104 1 (const int)
0:104 0.000100
0:104 true case
0:105 Branch: Return with expression
0:105 true (const bool)
0:92 Function Definition: main(i1; (void)
0:92 Function Parameters:
0:92 'a' (in int)
0:97 Function Definition: foo(f1; (int)
0:97 Function Parameters:
0:97 'a' (out float)
0:99 Sequence
0:99 Branch: Return with expression
0:99 3.200000
0:100 Function Call: foo(f1; (int)
0:100 'a' (out float)
0:103 Function Definition: gen(vf3; (bool)
0:103 Function Parameters:
0:103 'v' (in 3-component vector of float)
0:105 Sequence
0:105 Test condition and select (void)
0:105 Condition
0:105 logical-and (bool)
0:105 Compare Less Than (bool)
0:105 Absolute value (float)
0:105 direct index (in float)
0:105 'v' (in 3-component vector of float)
0:105 0 (const int)
0:105 0.000100
0:105 Compare Less Than (bool)
0:105 Absolute value (float)
0:105 direct index (in float)
0:105 'v' (in 3-component vector of float)
0:105 1 (const int)
0:105 0.000100
0:105 true case
0:106 Branch: Return with expression
0:106 true (const bool)
0:109 Function Definition: v1( (void)
0:109 Function Parameters:
0:113 Function Definition: v2( (void)
0:113 Function Parameters:
0:115 Sequence
0:115 Branch: Return with expression
0:115 Function Call: v1( (void)
0:? Linker Objects
0:? 'i' (smooth in 4-component vector of float)
0:? 'o' (out 4-component vector of float)

View File

@ -75,7 +75,6 @@ numeral.frag
../../LunarGLASS/test/Operations.frag
../../LunarGLASS/test/prepost.frag
../../LunarGLASS/test/simpleFunctionCall.frag
../../LunarGLASS/test/solidworks.frag
../../LunarGLASS/test/structAssignment.frag
../../LunarGLASS/test/structDeref.frag
../../LunarGLASS/test/structure.frag

172
Todo.txt
View File

@ -12,6 +12,31 @@ Testing
Interfacing
- finish putting into a glslang namespace
Shader Linking Validation
- ensure no static references thrown away
Cross-stage linking
- type consistency check of uniform and ins <-> outs, both variables and blocks, stage-specific arrayness matching
- location/binding/index check
- matching initializers for uniforms
- mixed es/non-es profiles
- statically consumed input not produced by previous stage
- matching between gl_PerVertex blocks and gl_PerFragment blocks
- compute shader not with other stages
Intra-stage linking
- exactly one main
- type consistency check of uniforms, globals, ins, and outs, both variables and blocks
- location/component/binding/index/offset match check
- location/component aliasing (except desktop vertex shader inputs)
- geometry shader input array sizes and input layout qualifier declaration
- compute shader layout(local_size_*) matching
- mixed es/non-es profiles
- matching initializers for globals
- recursion for both functions and subroutines
- matching redeclarations of interface blocks
- read or write to both gl_ClipVertex and gl_ClipDistance
- write to only one of gl_FragColor, gl_FragData, or user-declared
- 4.4: overlapping transform/feedback offsets, offset/stride overflow checks, and stride matching
Functionality to Implement/Finish
ESSL 3.0
- "const" compile-time constant propagation in the front-end has to be complete, for all built-in functions
@ -46,6 +71,7 @@ Functionality to Implement/Finish
rather than relying on gl_MaxVaryingComponents. Also, corrected gl_MaxVaryingComponents to be 60 instead of 64.
- Added gl_PrimitiveID as an input to fragment shaders.
- Added gl_FragCoord qualifiers origin_upper_left, and pixel_center_integer to modify the values returned by gl_FragCoord (and have no affect on any other aspect of the pipeline or language).
- including redeclaration of gl_FragCoord that adds nothing
- Added support for multi-sample textures through sampler2DMS and sampler2DMSArray support in texelFetch() and textureSize().
- Broadened interface blocks from just uniforms to in and out interfaces as well.
- Broaden array usage to include vertex shader inputs (vertex in).
@ -55,7 +81,153 @@ Functionality to Implement/Finish
- gl_FragCoord qualifiers use the layout(): origin_upper_left and pixel_center_integer.
- Broaden structure usage to include geometry inputs and geometry outputs.
GLSL 4.0
- tessellation control stage and tessellation evaluation stage. Includes barrier() built-in for synchronization.
- Polymorphic functions: Run-time selection of what function gets called, through the new keyword subroutine.
- 64bit floating point numbers with the new type keyword double. Built-in functions extended for doubles, and new function matching rules are added to both allow implicit conversions when calling a function and preserve most existing function matching once doubles are included.
+ More implicit conversions
+ float to double, and similarly for all floating-point vector and matrix types
+ int to uint, and similarly for all integer vector types
+ int to double, and similarly for all vectors of integers and doubles.
+ uint to double, and similarly for all vectors of integers and doubles.
- Cube map array textures and texture functions texture(), textureSize(), textureLod(), and textureGrad().
- Sampler arrays can take a variable index now, as long as it's value is uniform for all uses.
- Per-sample shading. Including sample input mask gl_SampleMaskIn[] and per-sample interpolation, with explicit interpolation built-ins interpolateAtCentroid(), interpolateAtSample(), and interpolateAtOffset().
- New precise qualifier to disallow optimizations that re-order operations or treat different instances of the same operator with different precision.
- Add a fused multiply andadd built-in, fma(), in relation to the new precise qualifier. (Because “a * b + c” will require two operations under new rules for precise.)
- Added new built-in floating-point functions
- frexp() and ldexp()
- packUnorm2x16(), packUnorm4x8(),packSnorm4x8(), and packDouble2x32()
- unpackUnorm2x16(), unpackUnorm4x8(),unpackSnorm4x8(), and unpackDouble2x32()
- Add new built-in integer functions
- uaddCarry() andusubBorrow()
- umulExtended() andimulExtended()
- bitfieldExtract() andbitfieldInsert()
- bitfieldReverse()
- bitCount(),findLSB(), andfindMSB()
- New built-in to query LOD, textureQueryLod().
- New overloaded function matching algorithm, handling selection from many valid multiple choices.
- Texture gather functions that return four texels with a single call.
- textureGather()
- textureGatherOffset()
- textureGatherOffsets()
- Add streams out from geometry shader. Output can be directed to streams through
- EmitStreamVertex() and EndStreamPrimitive().
GLSL 4.1
- Support for partitioning shaders into multiple programs to provide light-weight mixing of different shader stages.
(GL_ARB_separate_shader_objects)
- layout qualifiers
- redeclaration of input/output blocks
- ...
- Add 64-bit floating-point attributes for vertex shader inputs.
- Support viewport arrays so where the geometry shader selects which viewport array will transform its output.
GLSL 4.2
- Add 420-style function signature matching rules
+ Move these previously deprecated features to be only in the compatibility profile:
+ The keyword attribute for vertex shader inputs. (Use in instead.)
+ The keyword varying for inputs and outputs. (Use in and out instead.)
+ The original texturing built-in functions. (Use the new forms instead.)
+ The built-in variables gl_FragColor and gl_FragData. (Use out instead.)
+ Built-in constants related to these.
+ Change from ASCII to UTF-8 for the language character set and also allow any characters inside comments (except the byte value 0),
including '\'.
+ Add line-continuation using '\', as in C++.
+ ES convergence
+ Clarify that .xyzwxy.xy is illegal, as it temporarily makes a “vec6”.
+ Clarify that return statements only accept values (no return of a void function).
- Add image types (GL_ARB_shader_image_load_store)
+ 33 new types, all with “image” in their name, correspond to the non-shadow texture types
+ addition of memory qualifiers: coherent,volatile, restrict, readonly, and writeonly
- can read/write/modify images from a shader, through new built-in functions
- qualifiers can act independently on the opaque shader variable and the backing image, so extra qualifiers can be used to separately qualify these
+ Variables declared in if and else statements are scoped only to the end of those statements, especially for non-compound statements
Note, this is not backward compatible, it may depend on #version.
- Allow implicit conversions of return values to the declared type of the function.
- The const keyword can be used to declare variables within a function body with initializer expressions that are not constant expressions.
+ Qualifiers on variable declarations no longer have to follow a strict order. The layout qualifier can be used multiple times, and multiple parameter qualifiers can be used.
+ Parameter qualifiers can include precision and memory qualifiers.
- Add a new atomic_uint type to support atomic counters. Also, add built-in functions for manipulating atomic counters.
- atomicCounterIncrement, atomicCounterDecrement, and atomicCounter
- Add layout qualifier identifiers binding and offset to bind units to sampler and image variable declarations, atomic counters, and uniform blocks.
- Add built-in functions to pack/unpack 16 bit floating-point numbers (ARB_shading_language_pack2f).
- packHalf2x16 and unpackHalf2x16
- packSnorm2x16and unpackSnorm2x16
- Add gl_FragDepthlayout qualifiers to communicate what kind of changes will be made to gl_FragDepth(GL_AMD_conservative depth).
- Add C-style curly brace initializer lists syntax for initializers. Full initialization of aggregates is required when these are used.
- Allow .length() to be applied to vectors and matrices, returning the number of components or columns.
+ Clarify that .length() returns an int type and can be used as a constant integer expression.
- Allow swizzle operations on scalars.
- Even the potential for recursion through subroutine uniforms is an error.
- Positive signed decimal literals, as well as octal and hexadecimal, can set all 32 bits. This includes setting the sign bit to create a negative value.
- Make GLSL consistent with the API regarding user clipping, by no longer referring to gl_Positionwhen gl_ClipVertex is not written. Rather, user clipping becomes undefined.
- Minor consistency fixes, corrections
- Consistently state structures have members not fields. The period ( . ) is still called the field selector, for all its multiple uses.
- Remove comment that there is no communication between instantiations of a shader.
- Clarified that a comma sequence-operator expression cannot be a constant expression. E.g., “(2,3)” is not allowed, semantically, as a valid constant expression 3, even though it is an expression that will evaluate to 3.
- Use vec2instead of vec3for coordinate in textureGather*(sampler2DRect,...).
- Clarify that textureGatherOffset() can take non-constants for the offsets.
GLSL 4.3
- Add shader storage bufferobjects, as per the ARB_shader_storage_buffer_object extension.
This includes 1) allowing the last member of a storage buffer block to be an array that does not
know its size until render time, and 2) read/write memory shared with the application and other
shader invocations. It also adds the std430layout qualifier for shader storage blocks.
- Allow .length() on all arrays; returning a compile-time constant or not, depending on how the
array is sized, as per the ARB_shader_storage_buffer_object extension.
- Be clear that implicit array sizing is only within a stage, not cross stage.
- Array clarifications: 1) All arrays are inherently homogeneous, except for arrays of the new
shader storage buffer objects. 2) Arrays of shader storage buffer objects will be dereferenced
when the .length() method is used on an unsized array member, so that must a have valid index.
3) Arrays of other objects (uniform blocks) containing implicitly sized arrays will have the same
implicit size for all elements of the array.
- Arrays of arrays are now supported, as per the GL_ARB_arrays_of_arraysextension.
- Compute shaders are now supported, as per the GL_ARB_compute_shader extension.
- Added imageSize() built-ins to query the dimensions of an image.
- Define robust out-of-bounds access behavior when enabled, as per the GL_ARB_robust_buffer_access_behavior extension.
- All choice of depth or stencil texturing, for a packed depth-stencil texture, as per the
GL_ARB_stencil_texturing extension.
- Allow explicit locations/indexes to be assigned to uniform variables and subroutines, as per the
GL_ARB_explicit_uniform_location extension.
- Accept ES GLSL shader #version statements, which will request ES functionality for ES GLSL
versions 100 and 300, as per the GL_ARB_ES3_compatibility extension.
- Clarified about 90 errors as being either compile time, link time, or either.
- Clarify and correct scoping rules to what would normally be expected and what was intended.
(Function parameters and body nest inside global space. Loop variables and body nest inside
loop scope.)
- There are no digraphs (trigraphs were already disallowed).
- Remove the CPP difference that it is a compile-time error to use #if or #elif on expressions
containing undefined macro names. This reverts back to following expected CPP behavior.
- Set both gl_MaxFragmentImageUniformsand gl_MaxCombinedImageUniformsto 8.
- Clarify textureSize() for cube map arrays.
- For layout qualifiers,
- make negative output locations a compile-time error, and
- make indexes outside the range [0,1] a compile-time error.
- Allow mismatches in interpolation and auxiliary qualification across stages.
- Remove cross-version linking restrictions.
- Add textureQueryLevels() built-ins to query the number of mipmap levels, as per the
GL_ARB_texture_query_levels extension.
- Make gl_Layer and gl_ViewportIndex also be inputs to the fragment shader, as per the
GL_ARB_fragment_layer_viewport extension.
- Be explicit that compile-time constant expressions evaluating on the host may get a different
value than the same expression on the target. Also reinforce that compile-time constant
expressions are evaluated as if precise and invariantwere used.
- Add more examples and rules to be more specific about the required behavior of the precise
qualifier.
- Clarify fragment output variables cannot be double precision.
- Clarify that “floating-point” generally means both single- and double-precision and be more
consistent with that.
- Be clear that early_fragment_tests is only needed in one fragment-stage compilation unit.
- Allow the new shared keyword to be in layout-qualifier-id, allowing backward compatibility
with the shared identifier that was previously used.
+ Added overlooked texture function float textureOffset (sampler2DArrayShadow sampler, vec4 P, vec2 offset [, float bias] ).
+ Add missing type in grammar, ATOMIC_UINT, and missing qualifiers COHERENT, VOLATILE, RESTRICT, READONLY, and WRITEONLY.
- do version checking for the above
+ Add missing initializer lists to grammar.
GLSL 4.4
- Incorporate the ARB_enhanced_layouts extension, which adds
- compile-time constant expressions for layout qualifier integers
- new offset and align layout qualifiers for control over buffer block layouts
- add location layout qualifier for input and output blocks and block members
- new componentlayout qualifier for finer-grained layout control of input and output variables and blocks
- new xfb_buffer, xfb_stride, and xfb_offsetlayout qualifiers to allow the shader to control
transform feedback buffering.
+ Bug 10530: To be consistent with ES, include sample types as valid in a precision statement.
Note the defaults are irrelevant, as precision qualifiers are not required or have any meaning.

View File

@ -187,7 +187,7 @@ extern int yylex(YYSTYPE*, TParseContext&);
%type <interm.intermNode> declaration external_declaration
%type <interm.intermNode> for_init_statement compound_statement_no_new_scope
%type <interm.nodePair> selection_rest_statement for_rest_statement
%type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope
%type <interm.intermNode> iteration_statement jump_statement statement_no_new_scope statement_scoped
%type <interm> single_declaration init_declarator_list
%type <interm> parameter_declaration parameter_declarator parameter_type_specifier
@ -2599,6 +2599,10 @@ statement_no_new_scope
| simple_statement { $$ = $1; }
;
statement_scoped
: compound_statement { $$ = $1; }
| { parseContext.symbolTable.push(); } simple_statement { parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]); } { $$ = $2; }
compound_statement_no_new_scope
// Statement that doesn't create a new scope, for selection_statement, iteration_statement
: LEFT_BRACE RIGHT_BRACE {
@ -2643,11 +2647,11 @@ selection_statement
;
selection_rest_statement
: statement ELSE statement {
: statement_scoped ELSE statement_scoped {
$$.node1 = $1;
$$.node2 = $3;
}
| statement {
| statement_scoped {
$$.node1 = $1;
$$.node2 = 0;
}