From cc951f818361c0d135fbfff505e70fa9473a1b9b Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Wed, 6 Dec 2017 07:33:36 -0700 Subject: [PATCH] HLSL: Fix #1154: Support PointSize, as an attribute. --- Test/baseResults/hlsl.PointSize.geom.out | 143 +++++++++++++++++++++++ Test/baseResults/hlsl.PointSize.vert.out | 69 +++++++++++ Test/hlsl.PointSize.geom | 11 ++ Test/hlsl.PointSize.vert | 4 + gtests/Hlsl.FromFile.cpp | 2 + hlsl/hlslAttributes.cpp | 4 +- hlsl/hlslAttributes.h | 5 +- hlsl/hlslGrammar.cpp | 12 +- hlsl/hlslParseHelper.cpp | 10 ++ 9 files changed, 255 insertions(+), 5 deletions(-) create mode 100755 Test/baseResults/hlsl.PointSize.geom.out create mode 100755 Test/baseResults/hlsl.PointSize.vert.out create mode 100644 Test/hlsl.PointSize.geom create mode 100644 Test/hlsl.PointSize.vert diff --git a/Test/baseResults/hlsl.PointSize.geom.out b/Test/baseResults/hlsl.PointSize.geom.out new file mode 100755 index 00000000..1aa0846f --- /dev/null +++ b/Test/baseResults/hlsl.PointSize.geom.out @@ -0,0 +1,143 @@ +hlsl.PointSize.geom +Shader version: 500 +invocations = -1 +max_vertices = 4 +input primitive = triangles +output primitive = line_strip +0:? Sequence +0:8 Function Definition: @main(u1[3];struct-S-f11; ( temp void) +0:8 Function Parameters: +0:8 'ps' ( in 3-element array of uint) +0:8 'OutputStream' ( out structure{ temp float ps}) +0:? Sequence +0:10 Sequence +0:10 Sequence +0:10 move second child to first child ( temp float) +0:? 'OutputStream.ps' ( out float PointSize) +0:10 ps: direct index for structure ( temp float) +0:10 's' ( temp structure{ temp float ps}) +0:10 Constant: +0:10 0 (const int) +0:10 EmitVertex ( temp void) +0:8 Function Definition: main( ( temp void) +0:8 Function Parameters: +0:? Sequence +0:8 move second child to first child ( temp 3-element array of uint) +0:? 'ps' ( temp 3-element array of uint) +0:? 'ps' ( in 3-element array of uint PointSize) +0:8 Function Call: @main(u1[3];struct-S-f11; ( temp void) +0:? 'ps' ( temp 3-element array of uint) +0:? 'OutputStream' ( temp structure{ temp float ps}) +0:? Linker Objects +0:? 'ps' ( in 3-element array of uint PointSize) +0:? 'OutputStream.ps' ( out float PointSize) + + +Linked geometry stage: + + +Shader version: 500 +invocations = 1 +max_vertices = 4 +input primitive = triangles +output primitive = line_strip +0:? Sequence +0:8 Function Definition: @main(u1[3];struct-S-f11; ( temp void) +0:8 Function Parameters: +0:8 'ps' ( in 3-element array of uint) +0:8 'OutputStream' ( out structure{ temp float ps}) +0:? Sequence +0:10 Sequence +0:10 Sequence +0:10 move second child to first child ( temp float) +0:? 'OutputStream.ps' ( out float PointSize) +0:10 ps: direct index for structure ( temp float) +0:10 's' ( temp structure{ temp float ps}) +0:10 Constant: +0:10 0 (const int) +0:10 EmitVertex ( temp void) +0:8 Function Definition: main( ( temp void) +0:8 Function Parameters: +0:? Sequence +0:8 move second child to first child ( temp 3-element array of uint) +0:? 'ps' ( temp 3-element array of uint) +0:? 'ps' ( in 3-element array of uint PointSize) +0:8 Function Call: @main(u1[3];struct-S-f11; ( temp void) +0:? 'ps' ( temp 3-element array of uint) +0:? 'OutputStream' ( temp structure{ temp float ps}) +0:? Linker Objects +0:? 'ps' ( in 3-element array of uint PointSize) +0:? 'OutputStream.ps' ( out float PointSize) + +// Module Version 10000 +// Generated by (magic number): 80002 +// Id's are bound by 36 + + Capability Geometry + Capability GeometryPointSize + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Geometry 4 "main" 19 28 + ExecutionMode 4 Triangles + ExecutionMode 4 Invocations 1 + ExecutionMode 4 OutputLineStrip + ExecutionMode 4 OutputVertices 4 + Source HLSL 500 + Name 4 "main" + Name 11 "S" + MemberName 11(S) 0 "ps" + Name 16 "@main(u1[3];struct-S-f11;" + Name 14 "ps" + Name 15 "OutputStream" + Name 19 "OutputStream.ps" + Name 20 "s" + Name 26 "ps" + Name 28 "ps" + Name 30 "OutputStream" + Name 31 "param" + Name 33 "param" + Decorate 19(OutputStream.ps) BuiltIn PointSize + Decorate 28(ps) BuiltIn PointSize + 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(S): TypeStruct 10(float) + 12: TypePointer Function 11(S) + 13: TypeFunction 2 9(ptr) 12(ptr) + 18: TypePointer Output 10(float) +19(OutputStream.ps): 18(ptr) Variable Output + 21: TypeInt 32 1 + 22: 21(int) Constant 0 + 23: TypePointer Function 10(float) + 27: TypePointer Input 8 + 28(ps): 27(ptr) Variable Input + 4(main): 2 Function None 3 + 5: Label + 26(ps): 9(ptr) Variable Function +30(OutputStream): 12(ptr) Variable Function + 31(param): 9(ptr) Variable Function + 33(param): 12(ptr) Variable Function + 29: 8 Load 28(ps) + Store 26(ps) 29 + 32: 8 Load 26(ps) + Store 31(param) 32 + 34: 2 FunctionCall 16(@main(u1[3];struct-S-f11;) 31(param) 33(param) + 35: 11(S) Load 33(param) + Store 30(OutputStream) 35 + Return + FunctionEnd +16(@main(u1[3];struct-S-f11;): 2 Function None 13 + 14(ps): 9(ptr) FunctionParameter +15(OutputStream): 12(ptr) FunctionParameter + 17: Label + 20(s): 12(ptr) Variable Function + 24: 23(ptr) AccessChain 20(s) 22 + 25: 10(float) Load 24 + Store 19(OutputStream.ps) 25 + EmitVertex + Return + FunctionEnd diff --git a/Test/baseResults/hlsl.PointSize.vert.out b/Test/baseResults/hlsl.PointSize.vert.out new file mode 100755 index 00000000..2baafc13 --- /dev/null +++ b/Test/baseResults/hlsl.PointSize.vert.out @@ -0,0 +1,69 @@ +hlsl.PointSize.vert +Shader version: 500 +0:? Sequence +0:2 Function Definition: @main( ( temp float) +0:2 Function Parameters: +0:? Sequence +0:3 Branch: Return with expression +0:3 Constant: +0:3 2.300000 +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 move second child to first child ( temp float) +0:? '@entryPointOutput' ( out float PointSize) +0:2 Function Call: @main( ( temp float) +0:? Linker Objects +0:? '@entryPointOutput' ( out float PointSize) + + +Linked vertex stage: + + +Shader version: 500 +0:? Sequence +0:2 Function Definition: @main( ( temp float) +0:2 Function Parameters: +0:? Sequence +0:3 Branch: Return with expression +0:3 Constant: +0:3 2.300000 +0:2 Function Definition: main( ( temp void) +0:2 Function Parameters: +0:? Sequence +0:2 move second child to first child ( temp float) +0:? '@entryPointOutput' ( out float PointSize) +0:2 Function Call: @main( ( temp float) +0:? Linker Objects +0:? '@entryPointOutput' ( out float PointSize) + +// Module Version 10000 +// Generated by (magic number): 80002 +// Id's are bound by 16 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 14 + Source HLSL 500 + Name 4 "main" + Name 8 "@main(" + Name 14 "@entryPointOutput" + Decorate 14(@entryPointOutput) BuiltIn PointSize + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeFunction 6(float) + 10: 6(float) Constant 1075000115 + 13: TypePointer Output 6(float) +14(@entryPointOutput): 13(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 15: 6(float) FunctionCall 8(@main() + Store 14(@entryPointOutput) 15 + Return + FunctionEnd + 8(@main(): 6(float) Function None 7 + 9: Label + ReturnValue 10 + FunctionEnd diff --git a/Test/hlsl.PointSize.geom b/Test/hlsl.PointSize.geom new file mode 100644 index 00000000..d2a04a48 --- /dev/null +++ b/Test/hlsl.PointSize.geom @@ -0,0 +1,11 @@ +struct S { + [[vk::builtin("PointSize")]] float ps; +}; + +[maxvertexcount(4)] +void main([[vk::builtin("PointSize")]] triangle in uint ps[3], + inout LineStream OutputStream) +{ + S s; + OutputStream.Append(s); +} diff --git a/Test/hlsl.PointSize.vert b/Test/hlsl.PointSize.vert new file mode 100644 index 00000000..4b357e07 --- /dev/null +++ b/Test/hlsl.PointSize.vert @@ -0,0 +1,4 @@ +[[vk::builtin("PointSize")]] float main() +{ + return 2.3; +} \ No newline at end of file diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index fbb1e6e2..9688f79c 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -252,6 +252,8 @@ INSTANTIATE_TEST_CASE_P( {"hlsl.params.default.negative.frag", "main"}, {"hlsl.partialInit.frag", "PixelShaderFunction"}, {"hlsl.partialFlattenLocal.vert", "main"}, + {"hlsl.PointSize.geom", "main"}, + {"hlsl.PointSize.vert", "main"}, {"hlsl.pp.vert", "main"}, {"hlsl.pp.line.frag", "main"}, {"hlsl.precise.frag", "main"}, diff --git a/hlsl/hlslAttributes.cpp b/hlsl/hlslAttributes.cpp index fccf6c18..a7840da1 100644 --- a/hlsl/hlslAttributes.cpp +++ b/hlsl/hlslAttributes.cpp @@ -60,6 +60,8 @@ namespace glslang { return EatBinding; else if (lowername == "global_cbuffer_binding") return EatGlobalBinding; + else if (lowername == "builtin") + return EatBuiltIn; } else if (lowernameSpace.size() > 0) return EatNone; @@ -177,7 +179,7 @@ namespace glslang { const TConstUnion* constVal = &attrAgg->getSequence()[argNum]->getAsConstantUnion()->getConstArray()[0]; if (constVal == nullptr || constVal->getType() != basicType) return nullptr; - + return constVal; } diff --git a/hlsl/hlslAttributes.h b/hlsl/hlslAttributes.h index 1fdb4ba0..5210ca3b 100644 --- a/hlsl/hlslAttributes.h +++ b/hlsl/hlslAttributes.h @@ -66,7 +66,8 @@ namespace glslang { EatBinding, EatGlobalBinding, EatLocation, - EatInputAttachment + EatInputAttachment, + EatBuiltIn }; } @@ -84,6 +85,8 @@ namespace glslang { class TAttributeMap { public: + int size() const { return (int)attributes.size(); } + // Search for and potentially add the attribute into the map. Return the // attribute type enum for it, if found, else EatNone. TAttributeType setAttribute(const TString& nameSpace, const TString* name, TIntermAggregate* value); diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp index 369667cf..314a540b 100755 --- a/hlsl/hlslGrammar.cpp +++ b/hlsl/hlslGrammar.cpp @@ -2302,8 +2302,8 @@ bool HlslGrammar::acceptStructBufferType(TType& type) // : struct_declaration SEMI_COLON struct_declaration SEMI_COLON ... // // struct_declaration -// : fully_specified_type struct_declarator COMMA struct_declarator ... -// | fully_specified_type IDENTIFIER function_parameters post_decls compound_statement // member-function definition +// : attributes fully_specified_type struct_declarator COMMA struct_declarator ... +// | attributes fully_specified_type IDENTIFIER function_parameters post_decls compound_statement // member-function definition // // struct_declarator // : IDENTIFIER post_decls @@ -2322,7 +2322,11 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode* break; // struct_declaration - + + // attributes + TAttributeMap attributes; + acceptAttributes(attributes); + bool declarator_list = false; // fully_specified_type @@ -2332,6 +2336,8 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode* return false; } + parseContext.transferTypeAttributes(attributes, memberType); + // struct_declarator COMMA struct_declarator ... bool functionDefinitionAccepted = false; do { diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index c4187452..40229402 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -1854,6 +1854,9 @@ void HlslParseContext::handleEntryPointAttributes(const TSourceLoc& loc, const T // attributes. void HlslParseContext::transferTypeAttributes(const TAttributeMap& attributes, TType& type) { + if (attributes.size() == 0) + return; + // location int value; if (attributes.getInt(EatLocation, value)) @@ -1880,6 +1883,13 @@ void HlslParseContext::transferTypeAttributes(const TAttributeMap& attributes, T // input attachment if (attributes.getInt(EatInputAttachment, value)) type.getQualifier().layoutAttachment = value; + + // PointSize built-in + TString builtInString; + if (attributes.getString(EatBuiltIn, builtInString, 0, false)) { + if (builtInString == "PointSize") + type.getQualifier().builtIn = EbvPointSize; + } } //