PP: Address #737: accept 'h'/'H' floating-point suffix more broadly.

This commit is contained in:
John Kessenich 2017-02-28 12:40:40 -07:00
parent f67f9d7e4d
commit b67b4a7072
8 changed files with 142 additions and 62 deletions

View File

@ -244,3 +244,5 @@ void voidTernary()
b ? foo121111() : 4; // ERROR b ? foo121111() : 4; // ERROR
b ? 3 : foo12111(); // ERROR b ? 3 : foo12111(); // ERROR
} }
float halfFloat1 = 1.0h; // syntax ERROR

View File

@ -52,7 +52,8 @@ ERROR: 0:209: 'assign' : cannot convert from 'const float' to 'temp 4-component
ERROR: 0:212: 'sampler2DRect' : Reserved word. ERROR: 0:212: 'sampler2DRect' : Reserved word.
ERROR: 0:244: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type 'global void' and a right operand of type 'const int' (or there is no acceptable conversion) ERROR: 0:244: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type 'global void' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 0:245: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type 'const int' and a right operand of type 'global void' (or there is no acceptable conversion) ERROR: 0:245: ':' : wrong operand types: no operation ':' exists that takes a left-hand operand of type 'const int' and a right operand of type 'global void' (or there is no acceptable conversion)
ERROR: 53 compilation errors. No code generated. ERROR: 0:248: '' : syntax error
ERROR: 54 compilation errors. No code generated.
Shader version: 120 Shader version: 120
@ -645,6 +646,7 @@ ERROR: node is still EOpNull!
0:? 's2DRbad' (uniform sampler2DRect) 0:? 's2DRbad' (uniform sampler2DRect)
0:? 's2DR' (uniform sampler2DRect) 0:? 's2DR' (uniform sampler2DRect)
0:? 's2DRS' (uniform sampler2DRectShadow) 0:? 's2DRS' (uniform sampler2DRectShadow)
0:? 'halfFloat1' (global float)
Linked fragment stage: Linked fragment stage:
@ -688,4 +690,5 @@ ERROR: node is still EOpNull!
0:? 's2DRbad' (uniform sampler2DRect) 0:? 's2DRbad' (uniform sampler2DRect)
0:? 's2DR' (uniform sampler2DRect) 0:? 's2DR' (uniform sampler2DRect)
0:? 's2DRS' (uniform sampler2DRectShadow) 0:? 's2DRS' (uniform sampler2DRectShadow)
0:? 'halfFloat1' (global float)

View File

@ -50,16 +50,36 @@ gl_FragCoord origin is upper left
0:15 'r08' (temp uint) 0:15 'r08' (temp uint)
0:15 Constant: 0:15 Constant:
0:15 58 (const uint) 0:15 58 (const uint)
0:18 move second child to first child (temp 4-component vector of float) 0:16 Sequence
0:18 color: direct index for structure (temp 4-component vector of float) 0:16 move second child to first child (temp float)
0:18 'ps_output' (temp structure{temp 4-component vector of float color}) 0:16 'r09' (temp float)
0:16 Constant:
0:16 1.000000
0:17 Sequence
0:17 move second child to first child (temp float)
0:17 'r10' (temp float)
0:17 Constant:
0:17 1.000000
0:18 Sequence
0:18 move second child to first child (temp float)
0:18 'r11' (temp float)
0:18 Constant: 0:18 Constant:
0:18 0 (const int) 0:18 1.100000
0:18 Construct vec4 (temp 4-component vector of float) 0:19 Sequence
0:18 Convert int to float (temp float) 0:19 move second child to first child (temp float)
0:18 'r07' (temp int) 0:19 'r12' (temp float)
0:19 Branch: Return with expression 0:19 Constant:
0:19 'ps_output' (temp structure{temp 4-component vector of float color}) 0:19 1.100000
0:22 move second child to first child (temp 4-component vector of float)
0:22 color: direct index for structure (temp 4-component vector of float)
0:22 'ps_output' (temp structure{temp 4-component vector of float color})
0:22 Constant:
0:22 0 (const int)
0:22 Construct vec4 (temp 4-component vector of float)
0:22 Convert int to float (temp float)
0:22 'r07' (temp int)
0:23 Branch: Return with expression
0:23 'ps_output' (temp structure{temp 4-component vector of float color})
0:5 Function Definition: main( (temp void) 0:5 Function Definition: main( (temp void)
0:5 Function Parameters: 0:5 Function Parameters:
0:? Sequence 0:? Sequence
@ -128,16 +148,36 @@ gl_FragCoord origin is upper left
0:15 'r08' (temp uint) 0:15 'r08' (temp uint)
0:15 Constant: 0:15 Constant:
0:15 58 (const uint) 0:15 58 (const uint)
0:18 move second child to first child (temp 4-component vector of float) 0:16 Sequence
0:18 color: direct index for structure (temp 4-component vector of float) 0:16 move second child to first child (temp float)
0:18 'ps_output' (temp structure{temp 4-component vector of float color}) 0:16 'r09' (temp float)
0:16 Constant:
0:16 1.000000
0:17 Sequence
0:17 move second child to first child (temp float)
0:17 'r10' (temp float)
0:17 Constant:
0:17 1.000000
0:18 Sequence
0:18 move second child to first child (temp float)
0:18 'r11' (temp float)
0:18 Constant: 0:18 Constant:
0:18 0 (const int) 0:18 1.100000
0:18 Construct vec4 (temp 4-component vector of float) 0:19 Sequence
0:18 Convert int to float (temp float) 0:19 move second child to first child (temp float)
0:18 'r07' (temp int) 0:19 'r12' (temp float)
0:19 Branch: Return with expression 0:19 Constant:
0:19 'ps_output' (temp structure{temp 4-component vector of float color}) 0:19 1.100000
0:22 move second child to first child (temp 4-component vector of float)
0:22 color: direct index for structure (temp 4-component vector of float)
0:22 'ps_output' (temp structure{temp 4-component vector of float color})
0:22 Constant:
0:22 0 (const int)
0:22 Construct vec4 (temp 4-component vector of float)
0:22 Convert int to float (temp float)
0:22 'r07' (temp int)
0:23 Branch: Return with expression
0:23 'ps_output' (temp structure{temp 4-component vector of float color})
0:5 Function Definition: main( (temp void) 0:5 Function Definition: main( (temp void)
0:5 Function Parameters: 0:5 Function Parameters:
0:? Sequence 0:? Sequence
@ -153,12 +193,12 @@ gl_FragCoord origin is upper left
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 49 // Id's are bound by 54
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 46 EntryPoint Fragment 4 "main" 51
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Name 4 "main" Name 4 "main"
Name 8 "PS_OUTPUT" Name 8 "PS_OUTPUT"
@ -173,9 +213,13 @@ gl_FragCoord origin is upper left
Name 28 "r06" Name 28 "r06"
Name 30 "r07" Name 30 "r07"
Name 32 "r08" Name 32 "r08"
Name 35 "ps_output" Name 34 "r09"
Name 46 "color" Name 35 "r10"
Decorate 46(color) Location 0 Name 36 "r11"
Name 38 "r12"
Name 40 "ps_output"
Name 51 "color"
Decorate 51(color) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -195,16 +239,17 @@ gl_FragCoord origin is upper left
29: 24(int) Constant 6 29: 24(int) Constant 6
31: 24(int) Constant 57 31: 24(int) Constant 57
33: 15(int) Constant 58 33: 15(int) Constant 58
34: TypePointer Function 8(PS_OUTPUT) 37: 6(float) Constant 1066192077
36: 24(int) Constant 0 39: TypePointer Function 8(PS_OUTPUT)
40: TypePointer Function 7(fvec4) 41: 24(int) Constant 0
45: TypePointer Output 7(fvec4) 45: TypePointer Function 7(fvec4)
46(color): 45(ptr) Variable Output 50: TypePointer Output 7(fvec4)
51(color): 50(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
47:8(PS_OUTPUT) FunctionCall 10(@main() 52:8(PS_OUTPUT) FunctionCall 10(@main()
48: 7(fvec4) CompositeExtract 47 0 53: 7(fvec4) CompositeExtract 52 0
Store 46(color) 48 Store 51(color) 53
Return Return
FunctionEnd FunctionEnd
10(@main():8(PS_OUTPUT) Function None 9 10(@main():8(PS_OUTPUT) Function None 9
@ -218,7 +263,11 @@ gl_FragCoord origin is upper left
28(r06): 25(ptr) Variable Function 28(r06): 25(ptr) Variable Function
30(r07): 25(ptr) Variable Function 30(r07): 25(ptr) Variable Function
32(r08): 16(ptr) Variable Function 32(r08): 16(ptr) Variable Function
35(ps_output): 34(ptr) Variable Function 34(r09): 12(ptr) Variable Function
35(r10): 12(ptr) Variable Function
36(r11): 12(ptr) Variable Function
38(r12): 12(ptr) Variable Function
40(ps_output): 39(ptr) Variable Function
Store 13(r00) 14 Store 13(r00) 14
Store 17(r01) 18 Store 17(r01) 18
Store 19(r02) 20 Store 19(r02) 20
@ -228,11 +277,15 @@ gl_FragCoord origin is upper left
Store 28(r06) 29 Store 28(r06) 29
Store 30(r07) 31 Store 30(r07) 31
Store 32(r08) 33 Store 32(r08) 33
37: 24(int) Load 30(r07) Store 34(r09) 14
38: 6(float) ConvertSToF 37 Store 35(r10) 14
39: 7(fvec4) CompositeConstruct 38 38 38 38 Store 36(r11) 37
41: 40(ptr) AccessChain 35(ps_output) 36 Store 38(r12) 37
Store 41 39 42: 24(int) Load 30(r07)
42:8(PS_OUTPUT) Load 35(ps_output) 43: 6(float) ConvertSToF 42
ReturnValue 42 44: 7(fvec4) CompositeConstruct 43 43 43 43
46: 45(ptr) AccessChain 40(ps_output) 41
Store 46 44
47:8(PS_OUTPUT) Load 40(ps_output)
ReturnValue 47
FunctionEnd FunctionEnd

View File

@ -13,6 +13,10 @@ PS_OUTPUT main()
int r06 = 6L; // upper long int int r06 = 6L; // upper long int
int r07 = 071; // octal int r07 = 071; // octal
uint r08 = 072u; // unsigned octal uint r08 = 072u; // unsigned octal
float r09 = 1.h; // half
float r10 = 1.H; // half
float r11 = 1.1h; // half
float r12 = 1.1H; // half
PS_OUTPUT ps_output; PS_OUTPUT ps_output;
ps_output.color = r07; // gets 71 octal = 57 decimal ps_output.color = r07; // gets 71 octal = 57 decimal

View File

@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1854" #define GLSLANG_REVISION "Overload400-PrecQual.1858"
#define GLSLANG_DATE "27-Feb-2017" #define GLSLANG_DATE "28-Feb-2017"

View File

@ -687,7 +687,7 @@ void TParseVersions::doubleCheck(const TSourceLoc& loc, const char* op)
} }
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
// Call for any operation needing GLSL float16 data-type support. // Call for any operation needing float16 data-type support.
void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn) void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn)
{ {
if (!builtIn) { if (!builtIn) {

View File

@ -101,9 +101,16 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
{ {
bool HasDecimalOrExponent = false; bool HasDecimalOrExponent = false;
int isDouble = 0; int isDouble = 0;
bool generateFloat16 = false;
bool acceptFloat16 = parseContext.intermediate.getSource() == EShSourceHlsl;
bool isFloat16 = false;
bool requireHF = false;
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
int isFloat16 = 0; if (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float)) {
bool enableFloat16 = parseContext.version >= 450 && parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float); acceptFloat16 = true;
generateFloat16 = true;
requireHF = true;
}
#endif #endif
const auto saveName = [&](int ch) { const auto saveName = [&](int ch) {
@ -158,11 +165,14 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
saveName(ch2); saveName(ch2);
isDouble = 1; isDouble = 1;
} }
} else if (acceptFloat16 && (ch == 'h' || ch == 'H')) {
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
} else if (enableFloat16 && (ch == 'h' || ch == 'H')) { if (generateFloat16)
parseContext.float16Check(ppToken->loc, "half floating-point suffix"); parseContext.float16Check(ppToken->loc, "half floating-point suffix");
#endif
if (!HasDecimalOrExponent) if (!HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (requireHF) {
int ch2 = getChar(); int ch2 = getChar();
if (ch2 != 'f' && ch2 != 'F') { if (ch2 != 'f' && ch2 != 'F') {
ungetChar(); ungetChar();
@ -170,9 +180,12 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
} else { } else {
saveName(ch); saveName(ch);
saveName(ch2); saveName(ch2);
isFloat16 = 1; isFloat16 = generateFloat16;
}
} else {
saveName(ch);
isFloat16 = generateFloat16;
} }
#endif
} else if (ch == 'f' || ch == 'F') { } else if (ch == 'f' || ch == 'F') {
parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix"); parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix");
if (! parseContext.relaxedErrors()) if (! parseContext.relaxedErrors())
@ -197,10 +210,8 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
// Return the right token type // Return the right token type
if (isDouble) if (isDouble)
return PpAtomConstDouble; return PpAtomConstDouble;
#ifdef AMD_EXTENSIONS
else if (isFloat16) else if (isFloat16)
return PpAtomConstFloat16; return PpAtomConstFloat16;
#endif
else else
return PpAtomConstFloat; return PpAtomConstFloat;
} }
@ -216,6 +227,15 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
int ii = 0; int ii = 0;
unsigned long long ival = 0; unsigned long long ival = 0;
bool enableInt64 = pp->parseContext.version >= 450 && pp->parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64); bool enableInt64 = pp->parseContext.version >= 450 && pp->parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64);
bool acceptHalf = pp->parseContext.intermediate.getSource() == EShSourceHlsl;
#ifdef AMD_EXTENSIONS
if (pp->parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float))
acceptHalf = true;
#endif
const auto floatingPointChar = [&](int ch) { return ch == '.' || ch == 'e' || ch == 'E' ||
ch == 'f' || ch == 'F' ||
(acceptHalf && (ch == 'h' || ch == 'H')); };
ppToken->ival = 0; ppToken->ival = 0;
ppToken->i64val = 0; ppToken->i64val = 0;
@ -380,7 +400,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
ch = getch(); ch = getch();
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
} }
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F') if (floatingPointChar(ch))
return pp->lFloatConst(len, ch, ppToken); return pp->lFloatConst(len, ch, ppToken);
// wasn't a float, so must be octal... // wasn't a float, so must be octal...
@ -435,9 +455,9 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
} }
ch = getch(); ch = getch();
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F') { if (floatingPointChar(ch))
return pp->lFloatConst(len, ch, ppToken); return pp->lFloatConst(len, ch, ppToken);
} else { else {
// Finish handling signed and unsigned integers // Finish handling signed and unsigned integers
int numericLen = len; int numericLen = len;
bool isUnsigned = false; bool isUnsigned = false;

View File

@ -127,9 +127,7 @@ enum EFixedAtoms {
PpAtomConstUint64, PpAtomConstUint64,
PpAtomConstFloat, PpAtomConstFloat,
PpAtomConstDouble, PpAtomConstDouble,
#ifdef AMD_EXTENSIONS
PpAtomConstFloat16, PpAtomConstFloat16,
#endif
PpAtomConstString, PpAtomConstString,
// Identifiers // Identifiers