Fix #790: Don't emit NV-specific interface members unless enabled by extension.

This commit is contained in:
John Kessenich 2017-03-24 18:38:16 -06:00
parent 93750bc0a4
commit 0e7378446b
10 changed files with 216 additions and 59 deletions

View File

@ -129,6 +129,7 @@ protected:
void convertSwizzle(const glslang::TIntermAggregate&, std::vector<unsigned>& swizzle);
spv::Id convertGlslangToSpvType(const glslang::TType& type);
spv::Id convertGlslangToSpvType(const glslang::TType& type, glslang::TLayoutPacking, const glslang::TQualifier&);
bool filterMember(const glslang::TType& member);
spv::Id convertGlslangStructToSpvType(const glslang::TType&, const glslang::TTypeList* glslangStruct,
glslang::TLayoutPacking, const glslang::TQualifier&);
void decorateStructType(const glslang::TType&, const glslang::TTypeList* glslangStruct, glslang::TLayoutPacking,
@ -2263,6 +2264,24 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
return spvType;
}
// TODO: this functionality should exist at a higher level, in creating the AST
//
// Identify interface members that don't have their required extension turned on.
//
bool TGlslangToSpvTraverser::filterMember(const glslang::TType& member)
{
auto& extensions = glslangIntermediate->getRequestedExtensions();
if (member.getFieldName() == "gl_SecondaryPositionNV" &&
extensions.find("GL_NV_stereo_view_rendering") == extensions.end())
return true;
if (member.getFieldName() == "gl_PositionPerViewNV" &&
extensions.find("GL_NVX_multiview_per_view_attributes") == extensions.end())
return true;
return false;
};
// Do full recursive conversion of a glslang structure (or block) type to a SPIR-V Id.
// explicitLayout can be kept the same throughout the hierarchical recursive walk.
// Mutually recursive with convertGlslangToSpvType().
@ -2282,8 +2301,11 @@ spv::Id TGlslangToSpvTraverser::convertGlslangStructToSpvType(const glslang::TTy
if (type.getBasicType() == glslang::EbtBlock)
memberRemapper[glslangMembers][i] = -1;
} else {
if (type.getBasicType() == glslang::EbtBlock)
if (type.getBasicType() == glslang::EbtBlock) {
memberRemapper[glslangMembers][i] = i - memberDelta;
if (filterMember(glslangMember))
continue;
}
// modify just this child's view of the qualifier
glslang::TQualifier memberQualifier = glslangMember.getQualifier();
InheritQualifiers(memberQualifier, qualifier);
@ -2322,8 +2344,11 @@ void TGlslangToSpvTraverser::decorateStructType(const glslang::TType& type,
for (int i = 0; i < (int)glslangMembers->size(); i++) {
glslang::TType& glslangMember = *(*glslangMembers)[i].type;
int member = i;
if (type.getBasicType() == glslang::EbtBlock)
if (type.getBasicType() == glslang::EbtBlock) {
member = memberRemapper[glslangMembers][i];
if (filterMember(glslangMember))
continue;
}
// modify just this child's view of the qualifier
glslang::TQualifier memberQualifier = glslangMember.getQualifier();

View File

@ -0,0 +1,54 @@
spv.450.geom
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 24
Capability Geometry
Capability GeometryPointSize
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Geometry 4 "main" 14 23
ExecutionMode 4 Triangles
ExecutionMode 4 Invocations 4
ExecutionMode 4 OutputLineStrip
ExecutionMode 4 OutputVertices 127
Source GLSL 450
Name 4 "main"
Name 8 "p"
Name 9 "gl_PerVertex"
MemberName 9(gl_PerVertex) 0 "gl_PointSize"
Name 14 "gl_in"
Name 21 "gl_PerVertex"
MemberName 21(gl_PerVertex) 0 "gl_PointSize"
Name 23 ""
MemberDecorate 9(gl_PerVertex) 0 BuiltIn PointSize
Decorate 9(gl_PerVertex) Block
MemberDecorate 21(gl_PerVertex) 0 BuiltIn PointSize
Decorate 21(gl_PerVertex) Block
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Function 6(float)
9(gl_PerVertex): TypeStruct 6(float)
10: TypeInt 32 0
11: 10(int) Constant 3
12: TypeArray 9(gl_PerVertex) 11
13: TypePointer Input 12
14(gl_in): 13(ptr) Variable Input
15: TypeInt 32 1
16: 15(int) Constant 1
17: 15(int) Constant 0
18: TypePointer Input 6(float)
21(gl_PerVertex): TypeStruct 6(float)
22: TypePointer Output 21(gl_PerVertex)
23: 22(ptr) Variable Output
4(main): 2 Function None 3
5: Label
8(p): 7(ptr) Variable Function
19: 18(ptr) AccessChain 14(gl_in) 16 17
20: 6(float) Load 19
Store 8(p) 20
Return
FunctionEnd

View File

@ -0,0 +1,49 @@
spv.450.noRedecl.tesc
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 21
Capability Tessellation
Capability TessellationPointSize
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 15 20
ExecutionMode 4 OutputVertices 4
Source GLSL 450
Name 4 "main"
Name 11 "gl_PerVertex"
MemberName 11(gl_PerVertex) 0 "gl_Position"
MemberName 11(gl_PerVertex) 1 "gl_PointSize"
MemberName 11(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 11(gl_PerVertex) 3 "gl_CullDistance"
Name 15 "gl_in"
Name 20 "patchOut"
MemberDecorate 11(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 11(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 11(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 11(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 11(gl_PerVertex) Block
Decorate 20(patchOut) Patch
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeInt 32 0
9: 8(int) Constant 1
10: TypeArray 6(float) 9
11(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 10 10
12: 8(int) Constant 32
13: TypeArray 11(gl_PerVertex) 12
14: TypePointer Input 13
15(gl_in): 14(ptr) Variable Input
16: TypeInt 32 1
17: 16(int) Constant 0
18: 16(int) Constant 1
19: TypePointer Output 7(fvec4)
20(patchOut): 19(ptr) Variable Output
4(main): 2 Function None 3
5: Label
Return
FunctionEnd

View File

@ -25,7 +25,6 @@ Warning, version 450 is not yet complete; most version-specific features are pre
MemberName 27(gl_PerVertex) 1 "gl_PointSize"
MemberName 27(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 27(gl_PerVertex) 3 "gl_CullDistance"
MemberName 27(gl_PerVertex) 4 "gl_SecondaryPositionNV"
MemberName 27(gl_PerVertex) 5 "gl_PositionPerViewNV"
Name 31 "gl_in"
MemberDecorate 13(gl_PerVertex) 0 BuiltIn PositionPerViewNV
@ -57,7 +56,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre
22: 11(int) Constant 0
23: TypePointer Output 11(int)
26: TypeArray 6(float) 9
27(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 26 26 7(fvec4) 10
27(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 26 26 10
28: 8(int) Constant 32
29: TypeArray 27(gl_PerVertex) 28
30: TypePointer Input 29

View File

@ -3,7 +3,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 39
// Id's are bound by 38
Capability Tessellation
Capability ShaderViewportMaskNV
@ -12,7 +12,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre
Extension "SPV_NV_viewport_array2"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 16 18 33
EntryPoint TessellationControl 4 "main" 16 18 32
ExecutionMode 4 OutputVertices 4
Source GLSL 450
SourceExtension "GL_NV_stereo_view_rendering"
@ -24,14 +24,13 @@ Warning, version 450 is not yet complete; most version-specific features are pre
MemberName 12(gl_PerVertex) 2 "gl_SecondaryViewportMaskNV"
Name 16 "gl_out"
Name 18 "gl_InvocationID"
Name 29 "gl_PerVertex"
MemberName 29(gl_PerVertex) 0 "gl_Position"
MemberName 29(gl_PerVertex) 1 "gl_PointSize"
MemberName 29(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 29(gl_PerVertex) 3 "gl_CullDistance"
MemberName 29(gl_PerVertex) 4 "gl_SecondaryPositionNV"
MemberName 29(gl_PerVertex) 5 "gl_PositionPerViewNV"
Name 33 "gl_in"
Name 28 "gl_PerVertex"
MemberName 28(gl_PerVertex) 0 "gl_Position"
MemberName 28(gl_PerVertex) 1 "gl_PointSize"
MemberName 28(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 28(gl_PerVertex) 3 "gl_CullDistance"
MemberName 28(gl_PerVertex) 4 "gl_SecondaryPositionNV"
Name 32 "gl_in"
MemberDecorate 12(gl_PerVertex) 0 BuiltIn Layer
MemberDecorate 12(gl_PerVertex) 0 ViewportRelativeNV
MemberDecorate 12(gl_PerVertex) 0 SecondaryViewportRelativeNV 1
@ -39,11 +38,11 @@ Warning, version 450 is not yet complete; most version-specific features are pre
MemberDecorate 12(gl_PerVertex) 2 BuiltIn SecondaryViewportMaskNV
Decorate 12(gl_PerVertex) Block
Decorate 18(gl_InvocationID) BuiltIn InvocationId
MemberDecorate 29(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 29(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 29(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 29(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 29(gl_PerVertex) Block
MemberDecorate 28(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 28(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 28(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 28(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 28(gl_PerVertex) Block
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
@ -65,23 +64,22 @@ Warning, version 450 is not yet complete; most version-specific features are pre
23: TypePointer Output 6(int)
26: 9(int) Constant 1
27: TypeArray 7(float) 26
28: TypeArray 8(fvec4) 26
29(gl_PerVertex): TypeStruct 8(fvec4) 7(float) 27 27 8(fvec4) 28
30: 9(int) Constant 32
31: TypeArray 29(gl_PerVertex) 30
32: TypePointer Input 31
33(gl_in): 32(ptr) Variable Input
34: TypePointer Input 8(fvec4)
37: TypePointer Output 8(fvec4)
28(gl_PerVertex): TypeStruct 8(fvec4) 7(float) 27 27 8(fvec4)
29: 9(int) Constant 32
30: TypeArray 28(gl_PerVertex) 29
31: TypePointer Input 30
32(gl_in): 31(ptr) Variable Input
33: TypePointer Input 8(fvec4)
36: TypePointer Output 8(fvec4)
4(main): 2 Function None 3
5: Label
19: 6(int) Load 18(gl_InvocationID)
24: 23(ptr) AccessChain 16(gl_out) 19 20 21
Store 24 22
25: 6(int) Load 18(gl_InvocationID)
35: 34(ptr) AccessChain 33(gl_in) 22 21
36: 8(fvec4) Load 35
38: 37(ptr) AccessChain 16(gl_out) 25 22
Store 38 36
34: 33(ptr) AccessChain 32(gl_in) 22 21
35: 8(fvec4) Load 34
37: 36(ptr) AccessChain 16(gl_out) 25 22
Store 37 35
Return
FunctionEnd

20
Test/spv.450.geom Normal file
View File

@ -0,0 +1,20 @@
#version 450 core
layout(triangles) in;
in gl_PerVertex {
float gl_PointSize;
} gl_in[];
out gl_PerVertex {
float gl_PointSize;
};
layout(line_strip) out;
layout(max_vertices = 127) out;
layout(invocations = 4) in;
void main()
{
float p = gl_in[1].gl_PointSize;
}

View File

@ -0,0 +1,10 @@
#version 450 core
layout(vertices = 4) out;
patch out vec4 patchOut;
void main()
{
gl_in[0].gl_PointSize;
}

View File

@ -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.1932"
#define GLSLANG_DATE "23-Mar-2017"
#define GLSLANG_REVISION "Overload400-PrecQual.1933"
#define GLSLANG_DATE "24-Mar-2017"

View File

@ -3256,11 +3256,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
stageBuiltins[EShLangVertex].append(
"out int gl_ViewportIndex;"
"out int gl_Layer;"
"out int gl_ViewportMask[];"
"out int gl_SecondaryViewportMaskNV[];"
"out vec4 gl_SecondaryPositionNV;"
"out vec4 gl_PositionPerViewNV[];"
"out int gl_ViewportMaskPerViewNV[];"
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
#endif
@ -3333,8 +3333,8 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
stageBuiltins[EShLangGeometry].append(
"float gl_CullDistance[];"
#ifdef NV_EXTENSIONS
"vec4 gl_SecondaryPositionNV;"
"vec4 gl_PositionPerViewNV[];"
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
#endif
);
stageBuiltins[EShLangGeometry].append(
@ -3384,11 +3384,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
#ifdef NV_EXTENSIONS
if (version >= 450)
stageBuiltins[EShLangGeometry].append(
"out int gl_ViewportMask[];"
"out int gl_SecondaryViewportMaskNV[];"
"out vec4 gl_SecondaryPositionNV;"
"out vec4 gl_PositionPerViewNV[];"
"out int gl_ViewportMaskPerViewNV[];"
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
#endif
@ -3458,11 +3458,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
#ifdef NV_EXTENSIONS
"int gl_ViewportIndex;"
"int gl_Layer;"
"int gl_ViewportMask[];"
"vec4 gl_SecondaryPositionNV;"
"int gl_SecondaryViewportMaskNV[];"
"vec4 gl_PositionPerViewNV[];"
"int gl_ViewportMaskPerViewNV[];"
"int gl_ViewportMask[];" // GL_NV_viewport_array2
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
#endif
);
stageBuiltins[EShLangTessControl].append(
@ -3547,11 +3547,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
stageBuiltins[EShLangTessEvaluation].append(
"out int gl_ViewportIndex;"
"out int gl_Layer;"
"out int gl_ViewportMask[];"
"out vec4 gl_SecondaryPositionNV;"
"out int gl_SecondaryViewportMaskNV[];"
"out vec4 gl_PositionPerViewNV[];"
"out int gl_ViewportMaskPerViewNV[];"
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
#endif
@ -4505,8 +4505,8 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
#ifdef NV_EXTENSIONS
"highp vec4 gl_SecondaryPositionNV;"
"highp vec4 gl_PositionPerViewNV[];"
"highp vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"highp vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
#endif
"} gl_in[gl_MaxPatchVertices];"
"\n");
@ -4695,8 +4695,8 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
s.append(
"float gl_CullDistance[];"
#ifdef NV_EXTENSIONS
"vec4 gl_SecondaryPositionNV;"
"vec4 gl_PositionPerViewNV[];"
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
#endif
);
s.append(

View File

@ -210,6 +210,8 @@ INSTANTIATE_TEST_CASE_P(
"spv.430.frag",
"spv.430.vert",
"spv.450.tesc",
"spv.450.geom",
"spv.450.noRedecl.tesc",
"spv.accessChain.frag",
"spv.aggOps.frag",
"spv.always-discard.frag",