HLSL: allow "sample" in expressions.

Unlike other qualifiers, HLSL allows "sample" to be either a qualifier keyword or an
identifier (e.g, a variable or function name).

A fix to allow this was made a while ago, but that fix was insufficient when 'sample'
was used in an expression.  The problem was around the initial ambiguity between:

   sample float a; // "sample" is part of a fully specified type
and
   sample.xyz;     // sample is a keyword in a dot expression

Both start the same.  The "sample" was being accepted as a qualifier before enough
further parsing was done to determine we were not a declaration after all.  This
consumed the token, causing it to fail for its real purpose.

Now, when accepting a fully specified type, the token is pushed back onto the stack if
the thing is not a fully specified type.  This leaves it available for subsequent
purposes.

Changed the "hlsl.identifier.sample.frag" test to exercise this situation, distilled
down from a production shaders.
This commit is contained in:
steve-lunarg
2016-12-18 17:51:14 -07:00
parent abf5057948
commit a64ed3eba0
3 changed files with 71 additions and 41 deletions

View File

@@ -12,7 +12,7 @@ float4 main() : SV_Target0
{
// HLSL allows this as an identifier as well.
// However, this is not true of other qualifier keywords such as "linear".
int sample = 3;
float4 sample = float4(3,4,5,6);
return float4(0,0,0,0);
return sample.rgba; // 'sample' can participate in an expression.
}