Skip to content

Commit

Permalink
Resolve issue #700: allow initializers on struct members.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkslang committed Feb 2, 2017
1 parent 32fd5d2 commit 18adbdb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
20 changes: 19 additions & 1 deletion Test/baseResults/hlsl.init.frag.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
hlsl.init.frag
WARNING: 0:40: 'typedef' : struct-member initializers ignored
WARNING: 0:40: 'typedef' : struct-member initializers ignored

Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
Expand Down Expand Up @@ -152,6 +155,7 @@ gl_FragCoord origin is upper left
0:? 'single2' (global structure{temp 2-component vector of uint v})
0:? 'single3' (global structure{temp structure{temp int f} s1})
0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1})
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(row_major std140 ) uniform float a, layout(row_major std140 ) uniform float b, layout(row_major std140 ) uniform float c})


Linked fragment stage:
Expand Down Expand Up @@ -310,10 +314,11 @@ gl_FragCoord origin is upper left
0:? 'single2' (global structure{temp 2-component vector of uint v})
0:? 'single3' (global structure{temp structure{temp int f} s1})
0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1})
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(row_major std140 ) uniform float a, layout(row_major std140 ) uniform float b, layout(row_major std140 ) uniform float c})

// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 97
// Id's are bound by 100

Capability Shader
1: ExtInstImport "GLSL.std.450"
Expand Down Expand Up @@ -361,8 +366,18 @@ gl_FragCoord origin is upper left
Name 90 "input"
Name 95 "c4"
Name 96 "b5"
Name 97 "Constants"
MemberName 97(Constants) 0 "a"
MemberName 97(Constants) 1 "b"
MemberName 97(Constants) 2 "c"
Name 99 ""
Decorate 88(@entryPointOutput) Location 0
Decorate 90(input) Location 0
MemberDecorate 97(Constants) 0 Offset 0
MemberDecorate 97(Constants) 1 Offset 4
MemberDecorate 97(Constants) 2 Offset 8
Decorate 97(Constants) Block
Decorate 99 DescriptorSet 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
Expand Down Expand Up @@ -437,6 +452,9 @@ gl_FragCoord origin is upper left
90(input): 89(ptr) Variable Input
95(c4): 22(ptr) Variable Private
96(b5): 22(ptr) Variable Private
97(Constants): TypeStruct 6(float) 6(float) 6(float)
98: TypePointer Uniform 97(Constants)
99: 98(ptr) Variable Uniform
4(ShaderFunction): 2 Function None 3
5: Label
62(a2): 61(ptr) Variable Function
Expand Down
5 changes: 5 additions & 0 deletions Test/hlsl.init.frag
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ float4 ShaderFunction(float4 input) : COLOR0

return input * a1;
}

cbuffer Constants
{
float a = 1.0f, b, c = 2.0f;
};
2 changes: 1 addition & 1 deletion glslang/Include/revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.1804"
#define GLSLANG_REVISION "Overload400-PrecQual.1805"
#define GLSLANG_DATE "02-Feb-2017"
10 changes: 10 additions & 0 deletions hlsl/hlslGrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,16 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList)

acceptPostDecls(member.type->getQualifier());

// EQUAL assignment_expression
if (acceptTokenClass(EHTokAssign)) {
parseContext.warn(idToken.loc, "struct-member initializers ignored", "typedef", "");
TIntermTyped* expressionNode = nullptr;
if (! acceptAssignmentExpression(expressionNode)) {
expected("initializer");
return false;
}
}

// success on seeing the SEMICOLON coming up
if (peekTokenClass(EHTokSemicolon))
break;
Expand Down

0 comments on commit 18adbdb

Please sign in to comment.