HLSL: Fix #1154: Support PointSize, as an attribute.

This commit is contained in:
John Kessenich 2017-12-06 07:33:36 -07:00
parent b0159f8565
commit cc951f8183
9 changed files with 255 additions and 5 deletions

View File

@ -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

View File

@ -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

11
Test/hlsl.PointSize.geom Normal file
View File

@ -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<S> OutputStream)
{
S s;
OutputStream.Append(s);
}

4
Test/hlsl.PointSize.vert Normal file
View File

@ -0,0 +1,4 @@
[[vk::builtin("PointSize")]] float main()
{
return 2.3;
}

View File

@ -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"},

View File

@ -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;

View File

@ -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);

View File

@ -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
@ -2323,6 +2323,10 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode*
// 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 {

View File

@ -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;
}
}
//