From 2de329112b8e214602db6524017a8da1b1ad4533 Mon Sep 17 00:00:00 2001 From: steve-lunarg Date: Thu, 28 Jul 2016 14:49:48 -0600 Subject: [PATCH] HLSL: allow uint literals, and add test for numeric suffixes --- Test/baseResults/hlsl.numericsuffixes.frag.out | 181 +++++++++++++++++++++++++ Test/hlsl.numericsuffixes.frag | 20 +++ gtests/Hlsl.FromFile.cpp | 1 + hlsl/hlslGrammar.cpp | 3 + hlsl/hlslParseHelper.h | 1 - 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 Test/baseResults/hlsl.numericsuffixes.frag.out create mode 100644 Test/hlsl.numericsuffixes.frag diff --git a/Test/baseResults/hlsl.numericsuffixes.frag.out b/Test/baseResults/hlsl.numericsuffixes.frag.out new file mode 100644 index 0000000..46fcddb --- /dev/null +++ b/Test/baseResults/hlsl.numericsuffixes.frag.out @@ -0,0 +1,181 @@ +hlsl.numericsuffixes.frag +Shader version: 450 +gl_FragCoord origin is upper left +0:? Sequence +0:21 Function Definition: main( (global structure{temp 4-component vector of float color}) +0:5 Function Parameters: +0:? Sequence +0:7 Sequence +0:7 move second child to first child (temp float) +0:7 'r00' (temp float) +0:7 Constant: +0:7 1.000000 +0:8 Sequence +0:8 move second child to first child (temp uint) +0:8 'r01' (temp uint) +0:8 Constant: +0:8 1 (const uint) +0:9 Sequence +0:9 move second child to first child (temp uint) +0:9 'r02' (temp uint) +0:9 Constant: +0:9 2 (const uint) +0:10 Sequence +0:10 move second child to first child (temp uint) +0:10 'r03' (temp uint) +0:10 Constant: +0:10 2748 (const uint) +0:11 Sequence +0:11 move second child to first child (temp uint) +0:11 'r04' (temp uint) +0:11 Constant: +0:11 2748 (const uint) +0:12 Sequence +0:12 move second child to first child (temp int) +0:12 'r05' (temp int) +0:12 Constant: +0:12 5 (const int) +0:13 Sequence +0:13 move second child to first child (temp int) +0:13 'r06' (temp int) +0:13 Constant: +0:13 6 (const int) +0:14 Sequence +0:14 move second child to first child (temp int) +0:14 'r07' (temp int) +0:14 Constant: +0:14 57 (const int) +0:15 Sequence +0:15 move second child to first child (temp uint) +0:15 'r08' (temp uint) +0:15 Constant: +0:15 58 (const uint) +0:19 Branch: Return with expression +0:19 'ps_output' (temp structure{temp 4-component vector of float color}) +0:? Linker Objects + + +Linked fragment stage: + + +Shader version: 450 +gl_FragCoord origin is upper left +0:? Sequence +0:21 Function Definition: main( (global structure{temp 4-component vector of float color}) +0:5 Function Parameters: +0:? Sequence +0:7 Sequence +0:7 move second child to first child (temp float) +0:7 'r00' (temp float) +0:7 Constant: +0:7 1.000000 +0:8 Sequence +0:8 move second child to first child (temp uint) +0:8 'r01' (temp uint) +0:8 Constant: +0:8 1 (const uint) +0:9 Sequence +0:9 move second child to first child (temp uint) +0:9 'r02' (temp uint) +0:9 Constant: +0:9 2 (const uint) +0:10 Sequence +0:10 move second child to first child (temp uint) +0:10 'r03' (temp uint) +0:10 Constant: +0:10 2748 (const uint) +0:11 Sequence +0:11 move second child to first child (temp uint) +0:11 'r04' (temp uint) +0:11 Constant: +0:11 2748 (const uint) +0:12 Sequence +0:12 move second child to first child (temp int) +0:12 'r05' (temp int) +0:12 Constant: +0:12 5 (const int) +0:13 Sequence +0:13 move second child to first child (temp int) +0:13 'r06' (temp int) +0:13 Constant: +0:13 6 (const int) +0:14 Sequence +0:14 move second child to first child (temp int) +0:14 'r07' (temp int) +0:14 Constant: +0:14 57 (const int) +0:15 Sequence +0:15 move second child to first child (temp uint) +0:15 'r08' (temp uint) +0:15 Constant: +0:15 58 (const uint) +0:19 Branch: Return with expression +0:19 'ps_output' (temp structure{temp 4-component vector of float color}) +0:? Linker Objects + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 35 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" + ExecutionMode 4 OriginUpperLeft + Source HLSL 450 + Name 4 "main" + Name 8 "r00" + Name 12 "r01" + Name 14 "r02" + Name 16 "r03" + Name 18 "r04" + Name 21 "r05" + Name 23 "r06" + Name 25 "r07" + Name 27 "r08" + Name 30 "PS_OUTPUT" + MemberName 30(PS_OUTPUT) 0 "color" + Name 32 "ps_output" + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypePointer Function 6(float) + 9: 6(float) Constant 1065353216 + 10: TypeInt 32 0 + 11: TypePointer Function 10(int) + 13: 10(int) Constant 1 + 15: 10(int) Constant 2 + 17: 10(int) Constant 2748 + 19: TypeInt 32 1 + 20: TypePointer Function 19(int) + 22: 19(int) Constant 5 + 24: 19(int) Constant 6 + 26: 19(int) Constant 57 + 28: 10(int) Constant 58 + 29: TypeVector 6(float) 4 + 30(PS_OUTPUT): TypeStruct 29(fvec4) + 31: TypePointer Function 30(PS_OUTPUT) + 4(main): 2 Function None 3 + 5: Label + 8(r00): 7(ptr) Variable Function + 12(r01): 11(ptr) Variable Function + 14(r02): 11(ptr) Variable Function + 16(r03): 11(ptr) Variable Function + 18(r04): 11(ptr) Variable Function + 21(r05): 20(ptr) Variable Function + 23(r06): 20(ptr) Variable Function + 25(r07): 20(ptr) Variable Function + 27(r08): 11(ptr) Variable Function + 32(ps_output): 31(ptr) Variable Function + Store 8(r00) 9 + Store 12(r01) 13 + Store 14(r02) 15 + Store 16(r03) 17 + Store 18(r04) 17 + Store 21(r05) 22 + Store 23(r06) 24 + Store 25(r07) 26 + Store 27(r08) 28 + 33:30(PS_OUTPUT) Load 32(ps_output) + ReturnValue 33 + FunctionEnd diff --git a/Test/hlsl.numericsuffixes.frag b/Test/hlsl.numericsuffixes.frag new file mode 100644 index 0000000..60b2572 --- /dev/null +++ b/Test/hlsl.numericsuffixes.frag @@ -0,0 +1,20 @@ + +struct PS_OUTPUT { float4 color : SV_Target0; }; + +PS_OUTPUT main() +{ + // Test numeric suffixes + float r00 = 1.0f; // float + uint r01 = 1u; // lower uint + uint r02 = 2U; // upper uint + uint r03 = 0xabcu; // lower hex uint + uint r04 = 0xABCU; // upper hex uint (upper 0X is not accepted) + int r05 = 5l; // lower long int + int r06 = 6L; // upper long int + int r07 = 071; // octal + uint r08 = 072u; // unsigned octal + + PS_OUTPUT ps_output; + ps_output.color = r07; // gets 71 octal = 57 decimal + return ps_output; +} diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index e4cb4b0..6128585 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -112,6 +112,7 @@ INSTANTIATE_TEST_CASE_P( {"hlsl.load.basic.dx10.vert", "main"}, {"hlsl.load.offset.dx10.frag", "main"}, {"hlsl.load.offsetarray.dx10.frag", "main"}, + {"hlsl.numericsuffixes.frag", "main"}, {"hlsl.pp.line.frag", "main"}, {"hlsl.sample.array.dx10.frag", "main"}, {"hlsl.sample.basic.dx10.frag", "main"}, diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index 3c96560..48e2672 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -1960,6 +1960,9 @@ bool HlslGrammar::acceptLiteral(TIntermTyped*& node) case EHTokIntConstant: node = intermediate.addConstantUnion(token.i, token.loc, true); break; + case EHTokUintConstant: + node = intermediate.addConstantUnion(token.u, token.loc, true); + break; case EHTokFloatConstant: node = intermediate.addConstantUnion(token.d, EbtFloat, token.loc, true); break; diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index a3ca85b..a5e7f72 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -51,7 +51,6 @@ public: void setLimits(const TBuiltInResource&); bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false); - void getPreamble(std::string&); void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, const char* szExtraInfoFormat, ...); -- 2.7.4