From 6e1d50a7a25d52f95c576e11214c02e8c0f8c3e8 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Thu, 9 Mar 2017 14:37:32 -0700 Subject: [PATCH] HLSL: Accept SV_Cull/ClipDistanceN, by refactoring the way semantics are mapped. --- Test/baseResults/hlsl.semantic.geom.out | 246 ++++++++++++++++ Test/baseResults/hlsl.semantic.vert.out | 373 ++++++++++++++++++++++++ Test/hlsl.semantic.geom | 15 + Test/hlsl.semantic.vert | 15 + glslang/Include/BaseTypes.h | 1 + glslang/Include/revision.h | 4 +- gtests/Hlsl.FromFile.cpp | 2 + hlsl/hlslGrammar.cpp | 2 +- hlsl/hlslParseHelper.cpp | 121 +------- hlsl/hlslParseHelper.h | 2 +- hlsl/hlslScanContext.cpp | 85 +++++- hlsl/hlslScanContext.h | 1 + hlsl/hlslTokenStream.h | 1 + 13 files changed, 754 insertions(+), 114 deletions(-) create mode 100755 Test/baseResults/hlsl.semantic.geom.out create mode 100755 Test/baseResults/hlsl.semantic.vert.out create mode 100644 Test/hlsl.semantic.geom create mode 100644 Test/hlsl.semantic.vert diff --git a/Test/baseResults/hlsl.semantic.geom.out b/Test/baseResults/hlsl.semantic.geom.out new file mode 100755 index 00000000..76a69f35 --- /dev/null +++ b/Test/baseResults/hlsl.semantic.geom.out @@ -0,0 +1,246 @@ +hlsl.semantic.geom +Shader version: 450 +invocations = -1 +max_vertices = 4 +input primitive = triangles +output primitive = line_strip +0:? Sequence +0:12 Function Definition: @main(u1[3];struct-S-f1-f1-u1-u1-i11; (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Parameters: +0:12 'VertexID' (in 3-element array of uint) +0:12 'OutputStream' (out structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:? Sequence +0:14 Branch: Return with expression +0:14 's' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Definition: main( (temp void) +0:12 Function Parameters: +0:? Sequence +0:12 move second child to first child (temp 3-element array of uint) +0:? 'VertexID' (temp 3-element array of uint) +0:? 'VertexID' (layout(location=0 ) in 3-element array of uint) +0:12 Sequence +0:12 move second child to first child (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Call: @main(u1[3];struct-S-f1-f1-u1-u1-i11; (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:? 'VertexID' (temp 3-element array of uint) +0:? 'OutputStream' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip0' (out float ClipDistance) +0:12 clip0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull0' (out float CullDistance) +0:12 cull0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:12 move second child to first child (temp uint) +0:? '@entryPointOutput_vpai' (out uint ViewportIndex) +0:12 vpai: direct index for structure (temp uint) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:12 move second child to first child (temp uint) +0:? '@entryPointOutput_rtai' (out uint Layer) +0:12 rtai: direct index for structure (temp uint) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:12 '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 ii: direct index for structure (temp int) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:? Linker Objects +0:? '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:? 'VertexID' (layout(location=0 ) in 3-element array of uint) +0:? '@entryPointOutput_vpai' (out uint ViewportIndex) + + +Linked geometry stage: + + +Shader version: 450 +invocations = 1 +max_vertices = 4 +input primitive = triangles +output primitive = line_strip +0:? Sequence +0:12 Function Definition: @main(u1[3];struct-S-f1-f1-u1-u1-i11; (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Parameters: +0:12 'VertexID' (in 3-element array of uint) +0:12 'OutputStream' (out structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:? Sequence +0:14 Branch: Return with expression +0:14 's' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Definition: main( (temp void) +0:12 Function Parameters: +0:? Sequence +0:12 move second child to first child (temp 3-element array of uint) +0:? 'VertexID' (temp 3-element array of uint) +0:? 'VertexID' (layout(location=0 ) in 3-element array of uint) +0:12 Sequence +0:12 move second child to first child (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Function Call: @main(u1[3];struct-S-f1-f1-u1-u1-i11; (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:? 'VertexID' (temp 3-element array of uint) +0:? 'OutputStream' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip0' (out float ClipDistance) +0:12 clip0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull0' (out float CullDistance) +0:12 cull0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:12 move second child to first child (temp uint) +0:? '@entryPointOutput_vpai' (out uint ViewportIndex) +0:12 vpai: direct index for structure (temp uint) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:12 move second child to first child (temp uint) +0:? '@entryPointOutput_rtai' (out uint Layer) +0:12 rtai: direct index for structure (temp uint) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:12 '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 ii: direct index for structure (temp int) +0:12 'flattenTemp' (temp structure{temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:? Linker Objects +0:? '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:? 'VertexID' (layout(location=0 ) in 3-element array of uint) +0:? '@entryPointOutput_vpai' (out uint ViewportIndex) + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 62 + + Capability Geometry + Capability ClipDistance + Capability CullDistance + Capability MultiViewport + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Geometry 4 "main" 25 34 39 44 49 55 + ExecutionMode 4 Triangles + ExecutionMode 4 Invocations 1 + ExecutionMode 4 OutputLineStrip + ExecutionMode 4 OutputVertices 4 + Name 4 "main" + Name 12 "S" + MemberName 12(S) 0 "clip0" + MemberName 12(S) 1 "cull0" + MemberName 12(S) 2 "vpai" + MemberName 12(S) 3 "rtai" + MemberName 12(S) 4 "ii" + Name 17 "@main(u1[3];struct-S-f1-f1-u1-u1-i11;" + Name 15 "VertexID" + Name 16 "OutputStream" + Name 19 "s" + Name 23 "VertexID" + Name 25 "VertexID" + Name 27 "flattenTemp" + Name 28 "OutputStream" + Name 29 "param" + Name 31 "param" + Name 34 "@entryPointOutput_clip0" + Name 39 "@entryPointOutput_cull0" + Name 44 "@entryPointOutput_vpai" + Name 49 "@entryPointOutput_rtai" + Name 53 "S" + MemberName 53(S) 0 "ii" + Name 55 "@entryPointOutput" + Decorate 25(VertexID) Location 0 + Decorate 34(@entryPointOutput_clip0) BuiltIn ClipDistance + Decorate 39(@entryPointOutput_cull0) BuiltIn CullDistance + Decorate 44(@entryPointOutput_vpai) BuiltIn ViewportIndex + Decorate 49(@entryPointOutput_rtai) BuiltIn Layer + Decorate 55(@entryPointOutput) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 0 + 7: 6(int) Constant 3 + 8: TypeArray 6(int) 7 + 9: TypePointer Function 8 + 10: TypeFloat 32 + 11: TypeInt 32 1 + 12(S): TypeStruct 10(float) 10(float) 6(int) 6(int) 11(int) + 13: TypePointer Function 12(S) + 14: TypeFunction 12(S) 9(ptr) 13(ptr) + 24: TypePointer Input 8 + 25(VertexID): 24(ptr) Variable Input + 33: TypePointer Output 10(float) +34(@entryPointOutput_clip0): 33(ptr) Variable Output + 35: 11(int) Constant 0 + 36: TypePointer Function 10(float) +39(@entryPointOutput_cull0): 33(ptr) Variable Output + 40: 11(int) Constant 1 + 43: TypePointer Output 6(int) +44(@entryPointOutput_vpai): 43(ptr) Variable Output + 45: 11(int) Constant 2 + 46: TypePointer Function 6(int) +49(@entryPointOutput_rtai): 43(ptr) Variable Output + 50: 11(int) Constant 3 + 53(S): TypeStruct 11(int) + 54: TypePointer Output 53(S) +55(@entryPointOutput): 54(ptr) Variable Output + 56: 11(int) Constant 4 + 57: TypePointer Function 11(int) + 60: TypePointer Output 11(int) + 4(main): 2 Function None 3 + 5: Label + 23(VertexID): 9(ptr) Variable Function + 27(flattenTemp): 13(ptr) Variable Function +28(OutputStream): 13(ptr) Variable Function + 29(param): 9(ptr) Variable Function + 31(param): 13(ptr) Variable Function + 26: 8 Load 25(VertexID) + Store 23(VertexID) 26 + 30: 8 Load 23(VertexID) + Store 29(param) 30 + 32: 12(S) FunctionCall 17(@main(u1[3];struct-S-f1-f1-u1-u1-i11;) 29(param) 31(param) + Store 27(flattenTemp) 32 + 37: 36(ptr) AccessChain 27(flattenTemp) 35 + 38: 10(float) Load 37 + Store 34(@entryPointOutput_clip0) 38 + 41: 36(ptr) AccessChain 27(flattenTemp) 40 + 42: 10(float) Load 41 + Store 39(@entryPointOutput_cull0) 42 + 47: 46(ptr) AccessChain 27(flattenTemp) 45 + 48: 6(int) Load 47 + Store 44(@entryPointOutput_vpai) 48 + 51: 46(ptr) AccessChain 27(flattenTemp) 50 + 52: 6(int) Load 51 + Store 49(@entryPointOutput_rtai) 52 + 58: 57(ptr) AccessChain 27(flattenTemp) 56 + 59: 11(int) Load 58 + 61: 60(ptr) AccessChain 55(@entryPointOutput) 35 + Store 61 59 + Return + FunctionEnd +17(@main(u1[3];struct-S-f1-f1-u1-u1-i11;): 12(S) Function None 14 + 15(VertexID): 9(ptr) FunctionParameter +16(OutputStream): 13(ptr) FunctionParameter + 18: Label + 19(s): 13(ptr) Variable Function + 20: 12(S) Load 19(s) + ReturnValue 20 + FunctionEnd diff --git a/Test/baseResults/hlsl.semantic.vert.out b/Test/baseResults/hlsl.semantic.vert.out new file mode 100755 index 00000000..7ed8d8be --- /dev/null +++ b/Test/baseResults/hlsl.semantic.vert.out @@ -0,0 +1,373 @@ +hlsl.semantic.vert +Shader version: 450 +0:? Sequence +0:12 Function Definition: @main(struct-S-f1-f1-f1-f1-f1-f1-i11; (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Parameters: +0:12 'ins' (in structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:? Sequence +0:14 Branch: Return with expression +0:14 's' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Definition: main( (temp void) +0:12 Function Parameters: +0:? Sequence +0:12 Sequence +0:12 move second child to first child (temp float) +0:12 clip: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:? 'clip' (layout(location=0 ) in float) +0:12 move second child to first child (temp float) +0:12 clip0: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:? 'clip0' (layout(location=1 ) in float) +0:12 move second child to first child (temp float) +0:12 clip7: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:? 'clip7' (layout(location=2 ) in float) +0:12 move second child to first child (temp float) +0:12 cull: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:? 'cull' (layout(location=3 ) in float) +0:12 move second child to first child (temp float) +0:12 cull2: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:? 'cull2' (layout(location=4 ) in float) +0:12 move second child to first child (temp float) +0:12 cull5: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 5 (const int) +0:? 'cull5' (layout(location=5 ) in float) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 6 (const int) +0:? 'ii' (in int InstanceIndex) +0:12 Sequence +0:12 move second child to first child (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Call: @main(struct-S-f1-f1-f1-f1-f1-f1-i11; (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip7: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull2: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull5: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 5 (const int) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:12 '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 ii: direct index for structure (temp int) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 6 (const int) +0:? Linker Objects +0:? '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:? 'clip' (layout(location=0 ) in float) +0:? 'clip0' (layout(location=1 ) in float) +0:? 'clip7' (layout(location=2 ) in float) +0:? 'cull' (layout(location=3 ) in float) +0:? 'cull2' (layout(location=4 ) in float) +0:? 'cull5' (layout(location=5 ) in float) +0:? 'ii' (in int InstanceIndex) + + +Linked vertex stage: + + +Shader version: 450 +0:? Sequence +0:12 Function Definition: @main(struct-S-f1-f1-f1-f1-f1-f1-i11; (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Parameters: +0:12 'ins' (in structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:? Sequence +0:14 Branch: Return with expression +0:14 's' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Definition: main( (temp void) +0:12 Function Parameters: +0:? Sequence +0:12 Sequence +0:12 move second child to first child (temp float) +0:12 clip: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:? 'clip' (layout(location=0 ) in float) +0:12 move second child to first child (temp float) +0:12 clip0: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:? 'clip0' (layout(location=1 ) in float) +0:12 move second child to first child (temp float) +0:12 clip7: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:? 'clip7' (layout(location=2 ) in float) +0:12 move second child to first child (temp float) +0:12 cull: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:? 'cull' (layout(location=3 ) in float) +0:12 move second child to first child (temp float) +0:12 cull2: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:? 'cull2' (layout(location=4 ) in float) +0:12 move second child to first child (temp float) +0:12 cull5: direct index for structure (temp float) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 5 (const int) +0:? 'cull5' (layout(location=5 ) in float) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 6 (const int) +0:? 'ii' (in int InstanceIndex) +0:12 Sequence +0:12 move second child to first child (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Function Call: @main(struct-S-f1-f1-f1-f1-f1-f1-i11; (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:? 'ins' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip0: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 1 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_clip7' (out float ClipDistance) +0:12 clip7: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 2 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 3 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull2: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 4 (const int) +0:12 move second child to first child (temp float) +0:? '@entryPointOutput_cull5' (out float CullDistance) +0:12 cull5: direct index for structure (temp float) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 5 (const int) +0:12 move second child to first child (temp int) +0:12 ii: direct index for structure (temp int) +0:12 '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:12 Constant: +0:12 0 (const int) +0:12 ii: direct index for structure (temp int) +0:12 'flattenTemp' (temp structure{temp float clip, temp float clip0, temp float clip7, temp float cull, temp float cull2, temp float cull5, temp int ii}) +0:12 Constant: +0:12 6 (const int) +0:? Linker Objects +0:? '@entryPointOutput' (layout(location=0 ) out structure{temp int ii}) +0:? 'clip' (layout(location=0 ) in float) +0:? 'clip0' (layout(location=1 ) in float) +0:? 'clip7' (layout(location=2 ) in float) +0:? 'cull' (layout(location=3 ) in float) +0:? 'cull2' (layout(location=4 ) in float) +0:? 'cull5' (layout(location=5 ) in float) +0:? 'ii' (in int InstanceIndex) + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 77 + + Capability Shader + Capability ClipDistance + Capability CullDistance + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 21 26 30 34 38 42 47 56 63 72 + Name 4 "main" + Name 8 "S" + MemberName 8(S) 0 "clip" + MemberName 8(S) 1 "clip0" + MemberName 8(S) 2 "clip7" + MemberName 8(S) 3 "cull" + MemberName 8(S) 4 "cull2" + MemberName 8(S) 5 "cull5" + MemberName 8(S) 6 "ii" + Name 12 "@main(struct-S-f1-f1-f1-f1-f1-f1-i11;" + Name 11 "ins" + Name 14 "s" + Name 18 "ins" + Name 21 "clip" + Name 26 "clip0" + Name 30 "clip7" + Name 34 "cull" + Name 38 "cull2" + Name 42 "cull5" + Name 47 "ii" + Name 51 "flattenTemp" + Name 52 "param" + Name 56 "@entryPointOutput_clip7" + Name 63 "@entryPointOutput_cull5" + Name 70 "S" + MemberName 70(S) 0 "ii" + Name 72 "@entryPointOutput" + Decorate 21(clip) Location 0 + Decorate 26(clip0) Location 1 + Decorate 30(clip7) Location 2 + Decorate 34(cull) Location 3 + Decorate 38(cull2) Location 4 + Decorate 42(cull5) Location 5 + Decorate 47(ii) BuiltIn InstanceIndex + Decorate 56(@entryPointOutput_clip7) BuiltIn ClipDistance + Decorate 63(@entryPointOutput_cull5) BuiltIn CullDistance + Decorate 72(@entryPointOutput) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeInt 32 1 + 8(S): TypeStruct 6(float) 6(float) 6(float) 6(float) 6(float) 6(float) 7(int) + 9: TypePointer Function 8(S) + 10: TypeFunction 8(S) 9(ptr) + 19: 7(int) Constant 0 + 20: TypePointer Input 6(float) + 21(clip): 20(ptr) Variable Input + 23: TypePointer Function 6(float) + 25: 7(int) Constant 1 + 26(clip0): 20(ptr) Variable Input + 29: 7(int) Constant 2 + 30(clip7): 20(ptr) Variable Input + 33: 7(int) Constant 3 + 34(cull): 20(ptr) Variable Input + 37: 7(int) Constant 4 + 38(cull2): 20(ptr) Variable Input + 41: 7(int) Constant 5 + 42(cull5): 20(ptr) Variable Input + 45: 7(int) Constant 6 + 46: TypePointer Input 7(int) + 47(ii): 46(ptr) Variable Input + 49: TypePointer Function 7(int) + 55: TypePointer Output 6(float) +56(@entryPointOutput_clip7): 55(ptr) Variable Output +63(@entryPointOutput_cull5): 55(ptr) Variable Output + 70(S): TypeStruct 7(int) + 71: TypePointer Output 70(S) +72(@entryPointOutput): 71(ptr) Variable Output + 75: TypePointer Output 7(int) + 4(main): 2 Function None 3 + 5: Label + 18(ins): 9(ptr) Variable Function + 51(flattenTemp): 9(ptr) Variable Function + 52(param): 9(ptr) Variable Function + 22: 6(float) Load 21(clip) + 24: 23(ptr) AccessChain 18(ins) 19 + Store 24 22 + 27: 6(float) Load 26(clip0) + 28: 23(ptr) AccessChain 18(ins) 25 + Store 28 27 + 31: 6(float) Load 30(clip7) + 32: 23(ptr) AccessChain 18(ins) 29 + Store 32 31 + 35: 6(float) Load 34(cull) + 36: 23(ptr) AccessChain 18(ins) 33 + Store 36 35 + 39: 6(float) Load 38(cull2) + 40: 23(ptr) AccessChain 18(ins) 37 + Store 40 39 + 43: 6(float) Load 42(cull5) + 44: 23(ptr) AccessChain 18(ins) 41 + Store 44 43 + 48: 7(int) Load 47(ii) + 50: 49(ptr) AccessChain 18(ins) 45 + Store 50 48 + 53: 8(S) Load 18(ins) + Store 52(param) 53 + 54: 8(S) FunctionCall 12(@main(struct-S-f1-f1-f1-f1-f1-f1-i11;) 52(param) + Store 51(flattenTemp) 54 + 57: 23(ptr) AccessChain 51(flattenTemp) 19 + 58: 6(float) Load 57 + Store 56(@entryPointOutput_clip7) 58 + 59: 23(ptr) AccessChain 51(flattenTemp) 25 + 60: 6(float) Load 59 + Store 56(@entryPointOutput_clip7) 60 + 61: 23(ptr) AccessChain 51(flattenTemp) 29 + 62: 6(float) Load 61 + Store 56(@entryPointOutput_clip7) 62 + 64: 23(ptr) AccessChain 51(flattenTemp) 33 + 65: 6(float) Load 64 + Store 63(@entryPointOutput_cull5) 65 + 66: 23(ptr) AccessChain 51(flattenTemp) 37 + 67: 6(float) Load 66 + Store 63(@entryPointOutput_cull5) 67 + 68: 23(ptr) AccessChain 51(flattenTemp) 41 + 69: 6(float) Load 68 + Store 63(@entryPointOutput_cull5) 69 + 73: 49(ptr) AccessChain 51(flattenTemp) 45 + 74: 7(int) Load 73 + 76: 75(ptr) AccessChain 72(@entryPointOutput) 19 + Store 76 74 + Return + FunctionEnd +12(@main(struct-S-f1-f1-f1-f1-f1-f1-i11;): 8(S) Function None 10 + 11(ins): 9(ptr) FunctionParameter + 13: Label + 14(s): 9(ptr) Variable Function + 15: 8(S) Load 14(s) + ReturnValue 15 + FunctionEnd diff --git a/Test/hlsl.semantic.geom b/Test/hlsl.semantic.geom new file mode 100644 index 00000000..c4d7abad --- /dev/null +++ b/Test/hlsl.semantic.geom @@ -0,0 +1,15 @@ +struct S { + float clip0 : SV_ClipDistance0; + float cull0 : SV_CullDistance0; + uint vpai : SV_ViewportArrayIndex; + uint rtai : SV_RenderTargetArrayIndex; + int ii : SV_InstanceID; +}; + +[maxvertexcount(4)] +S main(triangle in uint VertexID[3] : VertexID, + inout LineStream OutputStream) +{ + S s; + return s; +} diff --git a/Test/hlsl.semantic.vert b/Test/hlsl.semantic.vert new file mode 100644 index 00000000..16bba37f --- /dev/null +++ b/Test/hlsl.semantic.vert @@ -0,0 +1,15 @@ +struct S { + float clip : SV_ClipDistance; + float clip0 : SV_ClipDistance0; + float clip7 : SV_ClipDistance7; + float cull : SV_CullDistance; + float cull2 : SV_CullDistance2; + float cull5 : SV_CullDistance5; + int ii : SV_InstanceID; +}; + +S main(S ins) +{ + S s; + return s; +} diff --git a/glslang/Include/BaseTypes.h b/glslang/Include/BaseTypes.h index 9ac587f4..e9a6ac1b 100644 --- a/glslang/Include/BaseTypes.h +++ b/glslang/Include/BaseTypes.h @@ -218,6 +218,7 @@ enum TBuiltInVariable { // to one of the above. EbvFragDepthGreater, EbvFragDepthLesser, + EbvStencilRef, EbvLast }; diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 342c5d1f..c96734ff 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // 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). -#define GLSLANG_REVISION "Overload400-PrecQual.1887" -#define GLSLANG_DATE "08-Mar-2017" +#define GLSLANG_REVISION "Overload400-PrecQual.1892" +#define GLSLANG_DATE "09-Mar-2017" diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 16c44557..3ac6585d 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -240,6 +240,8 @@ INSTANTIATE_TEST_CASE_P( {"hlsl.max.frag", "PixelShaderFunction"}, {"hlsl.precedence.frag", "PixelShaderFunction"}, {"hlsl.precedence2.frag", "PixelShaderFunction"}, + {"hlsl.semantic.geom", "main"}, + {"hlsl.semantic.vert", "main"}, {"hlsl.scope.frag", "PixelShaderFunction"}, {"hlsl.sin.frag", "PixelShaderFunction"}, {"hlsl.struct.frag", "PixelShaderFunction"}, diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index 4b4b0de0..fd88c619 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -3401,7 +3401,7 @@ bool HlslGrammar::acceptPostDecls(TQualifier& qualifier) parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string); } else { // semantic, in idToken.string - parseContext.handleSemantic(idToken.loc, qualifier, *idToken.string); + parseContext.handleSemantic(idToken.loc, qualifier, mapSemantic(*idToken.string)); } } else if (peekTokenClass(EHTokLeftAngle)) { found = true; diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 7f751dad..0779ec33 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -4194,118 +4194,23 @@ TFunction* HlslParseContext::handleConstructorCall(const TSourceLoc& loc, const // Handle seeing a "COLON semantic" at the end of a type declaration, // by updating the type according to the semantic. // -void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, const TString& semantic) +void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, TBuiltInVariable builtIn) { - // TODO: need to know if it's an input or an output - // The following sketches what needs to be done, but can't be right - // without taking into account stage and input/output. + // adjust for stage in/out - TString semanticUpperCase = semantic; - std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper); - // in DX9, all outputs had to have a semantic associated with them, that was either consumed - // by the system or was a specific register assignment - // in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration - // Fxc will only accept DX9 style semantics in compat mode - // Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that - // stage, it would just be ignored as it is likely there as part of an output struct from one stage - // to the next - - bool bParseDX9 = false; - if (bParseDX9) { - if (semanticUpperCase == "PSIZE") - qualifier.builtIn = EbvPointSize; - else if (semantic == "FOG") - qualifier.builtIn = EbvFogFragCoord; - else if (semanticUpperCase == "DEPTH") - qualifier.builtIn = EbvFragDepth; - else if (semanticUpperCase == "VFACE") - qualifier.builtIn = EbvFace; - else if (semanticUpperCase == "VPOS") - qualifier.builtIn = EbvFragCoord; + switch(builtIn) { + case EbvPosition: + if (language == EShLangFragment) + builtIn = EbvFragCoord; + break; + case EbvStencilRef: + error(loc, "unimplemented; need ARB_shader_stencil_export", "SV_STENCILREF", ""); + break; + default: + break; } - // SV Position has a different meaning in vertex vs fragment - if (semanticUpperCase == "SV_POSITION" && language != EShLangFragment) - qualifier.builtIn = EbvPosition; - else if (semanticUpperCase == "SV_POSITION" && language == EShLangFragment) - qualifier.builtIn = EbvFragCoord; - else if (semanticUpperCase == "SV_CLIPDISTANCE") - qualifier.builtIn = EbvClipDistance; - else if (semanticUpperCase == "SV_CULLDISTANCE") - qualifier.builtIn = EbvCullDistance; - else if (semanticUpperCase == "SV_VERTEXID") - qualifier.builtIn = EbvVertexIndex; - else if (semanticUpperCase == "SV_VIEWPORTARRAYINDEX") - qualifier.builtIn = EbvViewportIndex; - else if (semanticUpperCase == "SV_TESSFACTOR") - qualifier.builtIn = EbvTessLevelOuter; - - // Targets are defined 0-7 - else if (semanticUpperCase == "SV_TARGET") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 0; - } else if (semanticUpperCase == "SV_TARGET0") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 0; - } else if (semanticUpperCase == "SV_TARGET1") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 1; - } else if (semanticUpperCase == "SV_TARGET2") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 2; - } else if (semanticUpperCase == "SV_TARGET3") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 3; - } else if (semanticUpperCase == "SV_TARGET4") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 4; - } else if (semanticUpperCase == "SV_TARGET5") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 5; - } else if (semanticUpperCase == "SV_TARGET6") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 6; - } else if (semanticUpperCase == "SV_TARGET7") { - qualifier.builtIn = EbvNone; - // qualifier.layoutLocation = 7; - } else if (semanticUpperCase == "SV_SAMPLEINDEX") - qualifier.builtIn = EbvSampleId; - else if (semanticUpperCase == "SV_RENDERTARGETARRAYINDEX") - qualifier.builtIn = EbvLayer; - else if (semanticUpperCase == "SV_PRIMITIVEID") - qualifier.builtIn = EbvPrimitiveId; - else if (semanticUpperCase == "SV_OUTPUTCONTROLPOINTID") - qualifier.builtIn = EbvInvocationId; - else if (semanticUpperCase == "SV_ISFRONTFACE") - qualifier.builtIn = EbvFace; - else if (semanticUpperCase == "SV_INSTANCEID") - qualifier.builtIn = EbvInstanceIndex; - else if (semanticUpperCase == "SV_INSIDETESSFACTOR") - qualifier.builtIn = EbvTessLevelInner; - else if (semanticUpperCase == "SV_GSINSTANCEID") - qualifier.builtIn = EbvInvocationId; - else if (semanticUpperCase == "SV_DISPATCHTHREADID") - qualifier.builtIn = EbvGlobalInvocationId; - else if (semanticUpperCase == "SV_GROUPTHREADID") - qualifier.builtIn = EbvLocalInvocationId; - else if (semanticUpperCase == "SV_GROUPINDEX") - qualifier.builtIn = EbvLocalInvocationIndex; - else if (semanticUpperCase == "SV_GROUPID") - qualifier.builtIn = EbvWorkGroupId; - else if (semanticUpperCase == "SV_DOMAINLOCATION") - qualifier.builtIn = EbvTessCoord; - else if (semanticUpperCase == "SV_DEPTH") - qualifier.builtIn = EbvFragDepth; - else if( semanticUpperCase == "SV_COVERAGE") - qualifier.builtIn = EbvSampleMask; - - // TODO, these need to get refined to be more specific - else if( semanticUpperCase == "SV_DEPTHGREATEREQUAL") - qualifier.builtIn = EbvFragDepthGreater; - else if( semanticUpperCase == "SV_DEPTHLESSEQUAL") - qualifier.builtIn = EbvFragDepthLesser; - else if( semanticUpperCase == "SV_STENCILREF") - error(loc, "unimplemented; need ARB_shader_stencil_export", "SV_STENCILREF", ""); + qualifier.builtIn = builtIn; } // diff --git a/hlsl/hlslParseHelper.h b/hlsl/hlslParseHelper.h index ecfdaa7c..747862f0 100755 --- a/hlsl/hlslParseHelper.h +++ b/hlsl/hlslParseHelper.h @@ -91,7 +91,7 @@ public: TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&); void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&); TFunction* handleConstructorCall(const TSourceLoc&, const TType&); - void handleSemantic(TSourceLoc, TQualifier&, const TString& semantic); + void handleSemantic(TSourceLoc, TQualifier&, TBuiltInVariable); void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location, const glslang::TString* component); void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc, diff --git a/hlsl/hlslScanContext.cpp b/hlsl/hlslScanContext.cpp index a80ee93f..297f2639 100755 --- a/hlsl/hlslScanContext.cpp +++ b/hlsl/hlslScanContext.cpp @@ -47,7 +47,6 @@ #include "../glslang/MachineIndependent/ParseHelper.h" #include "hlslScanContext.h" #include "hlslTokens.h" -//#include "Scan.h" // preprocessor includes #include "../glslang/MachineIndependent/preprocessor/PpContext.h" @@ -82,6 +81,7 @@ struct str_hash // After a single process-level initialization, this is read only and thread safe std::unordered_map* KeywordMap = nullptr; std::unordered_set* ReservedSet = nullptr; +std::unordered_map* SemanticMap = nullptr; }; @@ -381,6 +381,73 @@ void HlslScanContext::fillInKeywordMap() ReservedSet->insert("unsigned"); ReservedSet->insert("using"); ReservedSet->insert("virtual"); + + SemanticMap = new std::unordered_map; + + // in DX9, all outputs had to have a semantic associated with them, that was either consumed + // by the system or was a specific register assignment + // in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration + // Fxc will only accept DX9 style semantics in compat mode + // Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that + // stage, it would just be ignored as it is likely there as part of an output struct from one stage + // to the next + bool bParseDX9 = false; + if (bParseDX9) { + (*SemanticMap)["PSIZE"] = EbvPointSize; + (*SemanticMap)["FOG"] = EbvFogFragCoord; + (*SemanticMap)["DEPTH"] = EbvFragDepth; + (*SemanticMap)["VFACE"] = EbvFace; + (*SemanticMap)["VPOS"] = EbvFragCoord; + } + + (*SemanticMap)["SV_POSITION"] = EbvPosition; + (*SemanticMap)["SV_CLIPDISTANCE"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE0"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE1"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE2"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE3"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE4"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE5"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE6"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE7"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE8"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE9"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE10"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE11"] = EbvClipDistance; + (*SemanticMap)["SV_CULLDISTANCE"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE0"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE1"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE2"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE3"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE4"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE5"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE6"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE7"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE8"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE9"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE10"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE11"] = EbvCullDistance; + (*SemanticMap)["SV_VERTEXID"] = EbvVertexIndex; + (*SemanticMap)["SV_VIEWPORTARRAYINDEX"] = EbvViewportIndex; + (*SemanticMap)["SV_TESSFACTOR"] = EbvTessLevelOuter; + (*SemanticMap)["SV_SAMPLEINDEX"] = EbvSampleId; + (*SemanticMap)["SV_RENDERTARGETARRAYINDEX"] = EbvLayer; + (*SemanticMap)["SV_PRIMITIVEID"] = EbvPrimitiveId; + (*SemanticMap)["SV_OUTPUTCONTROLPOINTID"] = EbvInvocationId; + (*SemanticMap)["SV_ISFRONTFACE"] = EbvFace; + (*SemanticMap)["SV_INSTANCEID"] = EbvInstanceIndex; + (*SemanticMap)["SV_INSIDETESSFACTOR"] = EbvTessLevelInner; + (*SemanticMap)["SV_GSINSTANCEID"] = EbvInvocationId; + (*SemanticMap)["SV_DISPATCHTHREADID"] = EbvGlobalInvocationId; + (*SemanticMap)["SV_GROUPTHREADID"] = EbvLocalInvocationId; + (*SemanticMap)["SV_GROUPINDEX"] = EbvLocalInvocationIndex; + (*SemanticMap)["SV_GROUPID"] = EbvWorkGroupId; + (*SemanticMap)["SV_DOMAINLOCATION"] = EbvTessCoord; + (*SemanticMap)["SV_DEPTH"] = EbvFragDepth; + (*SemanticMap)["SV_COVERAGE"] = EbvSampleMask; + (*SemanticMap)["SV_DEPTHGREATEREQUAL"] = EbvFragDepthGreater; + (*SemanticMap)["SV_DEPTHLESSEQUAL"] = EbvFragDepthLesser; + (*SemanticMap)["SV_STENCILREF"] = EbvStencilRef; } void HlslScanContext::deleteKeywordMap() @@ -389,15 +456,29 @@ void HlslScanContext::deleteKeywordMap() KeywordMap = nullptr; delete ReservedSet; ReservedSet = nullptr; + delete SemanticMap; + SemanticMap = nullptr; } -// Wrapper for tokenizeClass()"] = to get everything inside the token. +// Wrapper for tokenizeClass() to get everything inside the token. void HlslScanContext::tokenize(HlslToken& token) { EHlslTokenClass tokenClass = tokenizeClass(token); token.tokenClass = tokenClass; } +glslang::TBuiltInVariable HlslScanContext::mapSemantic(const TString& semantic) +{ + TString semanticUpperCase = semantic; + std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper); + + auto it = SemanticMap->find(semanticUpperCase.c_str()); + if (it != SemanticMap->end()) + return it->second; + else + return glslang::EbvNone; +} + // // Fill in token information for the next token, except for the token class. // Returns the enum value of the token class of the next token found. diff --git a/hlsl/hlslScanContext.h b/hlsl/hlslScanContext.h index b931d9be..bb8b09e8 100755 --- a/hlsl/hlslScanContext.h +++ b/hlsl/hlslScanContext.h @@ -82,6 +82,7 @@ public: static void deleteKeywordMap(); void tokenize(HlslToken&); + glslang::TBuiltInVariable mapSemantic(const TString& semantic); protected: HlslScanContext(HlslScanContext&); diff --git a/hlsl/hlslTokenStream.h b/hlsl/hlslTokenStream.h index 95589988..70cfc446 100755 --- a/hlsl/hlslTokenStream.h +++ b/hlsl/hlslTokenStream.h @@ -52,6 +52,7 @@ namespace glslang { bool acceptTokenClass(EHlslTokenClass); EHlslTokenClass peek() const; bool peekTokenClass(EHlslTokenClass) const; + glslang::TBuiltInVariable mapSemantic(const TString& semantic) { return scanner.mapSemantic(semantic); } protected: HlslToken token; // the token we are currently looking at, but have not yet accepted