Avoid spuriously adding Geometry capability for vert, tesc, tese (#2462)
Use of gl_Layer and gl_ViewportIndex in tessellation and vertex
shaders should not trigger the addition of the Geometry capability.
Fixes #2461
Added tests for use of gl_Layer and gl_ViewportIndex in a tessellation
evaluation shader.
Several tests for NVIDIA features for tessellation, vertex, or mesh
shaders now lose the Geometry or MultiViewport capabilities.
This is ok because the functionality is already covered by
the ShaderViewportIndexLayerNV capability.
The spv.meshShaderPerViewBuiltins.mesh test now fails validation
because the validator does not know that PrimitiveId (and possibly
other) builtins are enabled by the MeshShadingNV capability.
I filed https://github.com/KhronosGroup/SPIRV-Headers/issues/179 to
fix the grammar upstream.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index a24b522..e0b5a19 100644
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -725,7 +725,10 @@
return spv::BuiltInCullDistance;
case glslang::EbvViewportIndex:
- builder.addCapability(spv::CapabilityMultiViewport);
+ if (glslangIntermediate->getStage() == EShLangGeometry ||
+ glslangIntermediate->getStage() == EShLangFragment) {
+ builder.addCapability(spv::CapabilityMultiViewport);
+ }
if (glslangIntermediate->getStage() == EShLangVertex ||
glslangIntermediate->getStage() == EShLangTessControl ||
glslangIntermediate->getStage() == EShLangTessEvaluation) {
@@ -754,7 +757,10 @@
if (glslangIntermediate->getStage() == EShLangMeshNV) {
return spv::BuiltInLayer;
}
- builder.addCapability(spv::CapabilityGeometry);
+ if (glslangIntermediate->getStage() == EShLangGeometry ||
+ glslangIntermediate->getStage() == EShLangFragment) {
+ builder.addCapability(spv::CapabilityGeometry);
+ }
if (glslangIntermediate->getStage() == EShLangVertex ||
glslangIntermediate->getStage() == EShLangTessControl ||
glslangIntermediate->getStage() == EShLangTessEvaluation) {
diff --git a/Test/baseResults/spv.layer.tese.out b/Test/baseResults/spv.layer.tese.out
new file mode 100644
index 0000000..906340f
--- /dev/null
+++ b/Test/baseResults/spv.layer.tese.out
@@ -0,0 +1,30 @@
+spv.layer.tese
+// Module Version 10000
+// Generated by (magic number): 8000a
+// Id's are bound by 10
+
+ Capability Tessellation
+ Capability ShaderViewportIndexLayerNV
+ Extension "SPV_EXT_shader_viewport_index_layer"
+ 1: ExtInstImport "GLSL.std.450"
+ MemoryModel Logical GLSL450
+ EntryPoint TessellationEvaluation 4 "main" 8
+ ExecutionMode 4 Triangles
+ ExecutionMode 4 SpacingEqual
+ ExecutionMode 4 VertexOrderCcw
+ Source GLSL 450
+ SourceExtension "GL_ARB_shader_viewport_layer_array"
+ Name 4 "main"
+ Name 8 "gl_Layer"
+ Decorate 8(gl_Layer) BuiltIn Layer
+ 2: TypeVoid
+ 3: TypeFunction 2
+ 6: TypeInt 32 1
+ 7: TypePointer Output 6(int)
+ 8(gl_Layer): 7(ptr) Variable Output
+ 9: 6(int) Constant 1
+ 4(main): 2 Function None 3
+ 5: Label
+ Store 8(gl_Layer) 9
+ Return
+ FunctionEnd
diff --git a/Test/baseResults/spv.meshShaderBuiltins.mesh.out b/Test/baseResults/spv.meshShaderBuiltins.mesh.out
index f0c252a..b26122e 100644
--- a/Test/baseResults/spv.meshShaderBuiltins.mesh.out
+++ b/Test/baseResults/spv.meshShaderBuiltins.mesh.out
@@ -5,7 +5,6 @@
Capability ClipDistance
Capability CullDistance
- Capability MultiViewport
Capability DrawParameters
Capability ShaderViewportMaskNV
Capability MeshShadingNV
diff --git a/Test/baseResults/spv.meshShaderPerViewBuiltins.mesh.out b/Test/baseResults/spv.meshShaderPerViewBuiltins.mesh.out
index 907ae28..38a426c 100644
--- a/Test/baseResults/spv.meshShaderPerViewBuiltins.mesh.out
+++ b/Test/baseResults/spv.meshShaderPerViewBuiltins.mesh.out
@@ -1,9 +1,9 @@
spv.meshShaderPerViewBuiltins.mesh
+Validation failed
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 126
- Capability MultiViewport
Capability PerViewAttributesNV
Capability MeshShadingNV
Extension "SPV_NVX_multiview_per_view_attributes"
diff --git a/Test/baseResults/spv.meshShaderRedeclBuiltins.mesh.out b/Test/baseResults/spv.meshShaderRedeclBuiltins.mesh.out
index 66c3a0d..bfd2d85 100644
--- a/Test/baseResults/spv.meshShaderRedeclBuiltins.mesh.out
+++ b/Test/baseResults/spv.meshShaderRedeclBuiltins.mesh.out
@@ -5,7 +5,6 @@
Capability ClipDistance
Capability CullDistance
- Capability MultiViewport
Capability ShaderViewportMaskNV
Capability MeshShadingNV
Extension "SPV_NV_mesh_shader"
diff --git a/Test/baseResults/spv.stereoViewRendering.tesc.out b/Test/baseResults/spv.stereoViewRendering.tesc.out
index a357346..f01e53b 100644
--- a/Test/baseResults/spv.stereoViewRendering.tesc.out
+++ b/Test/baseResults/spv.stereoViewRendering.tesc.out
@@ -3,7 +3,6 @@
// Generated by (magic number): 8000a
// Id's are bound by 42
- Capability Geometry
Capability Tessellation
Capability ShaderViewportIndexLayerNV
Capability ShaderViewportMaskNV
diff --git a/Test/baseResults/spv.stereoViewRendering.vert.out b/Test/baseResults/spv.stereoViewRendering.vert.out
index 0667cb8..e74921a 100644
--- a/Test/baseResults/spv.stereoViewRendering.vert.out
+++ b/Test/baseResults/spv.stereoViewRendering.vert.out
@@ -4,7 +4,6 @@
// Id's are bound by 27
Capability Shader
- Capability Geometry
Capability ShaderViewportIndexLayerNV
Capability ShaderViewportMaskNV
Capability ShaderStereoViewNV
diff --git a/Test/baseResults/spv.viewportArray2.tesc.out b/Test/baseResults/spv.viewportArray2.tesc.out
index 6a9dccc..74235a5 100644
--- a/Test/baseResults/spv.viewportArray2.tesc.out
+++ b/Test/baseResults/spv.viewportArray2.tesc.out
@@ -4,9 +4,7 @@
// Generated by (magic number): 8000a
// Id's are bound by 25
- Capability Geometry
Capability Tessellation
- Capability MultiViewport
Capability ShaderViewportIndexLayerNV
Capability ShaderViewportMaskNV
Extension "SPV_EXT_shader_viewport_index_layer"
diff --git a/Test/baseResults/spv.viewportArray2.vert.out b/Test/baseResults/spv.viewportArray2.vert.out
index 96e5b07..cf29cd7 100644
--- a/Test/baseResults/spv.viewportArray2.vert.out
+++ b/Test/baseResults/spv.viewportArray2.vert.out
@@ -4,8 +4,6 @@
// Id's are bound by 19
Capability Shader
- Capability Geometry
- Capability MultiViewport
Capability ShaderViewportIndexLayerNV
Capability ShaderViewportMaskNV
Extension "SPV_EXT_shader_viewport_index_layer"
diff --git a/Test/baseResults/spv.viewportindex.tese.out b/Test/baseResults/spv.viewportindex.tese.out
new file mode 100644
index 0000000..12a30cf
--- /dev/null
+++ b/Test/baseResults/spv.viewportindex.tese.out
@@ -0,0 +1,30 @@
+spv.viewportindex.tese
+// Module Version 10000
+// Generated by (magic number): 8000a
+// Id's are bound by 10
+
+ Capability Tessellation
+ Capability ShaderViewportIndexLayerNV
+ Extension "SPV_EXT_shader_viewport_index_layer"
+ 1: ExtInstImport "GLSL.std.450"
+ MemoryModel Logical GLSL450
+ EntryPoint TessellationEvaluation 4 "main" 8
+ ExecutionMode 4 Triangles
+ ExecutionMode 4 SpacingEqual
+ ExecutionMode 4 VertexOrderCcw
+ Source GLSL 450
+ SourceExtension "GL_ARB_shader_viewport_layer_array"
+ Name 4 "main"
+ Name 8 "gl_ViewportIndex"
+ Decorate 8(gl_ViewportIndex) BuiltIn ViewportIndex
+ 2: TypeVoid
+ 3: TypeFunction 2
+ 6: TypeInt 32 1
+ 7: TypePointer Output 6(int)
+8(gl_ViewportIndex): 7(ptr) Variable Output
+ 9: 6(int) Constant 1
+ 4(main): 2 Function None 3
+ 5: Label
+ Store 8(gl_ViewportIndex) 9
+ Return
+ FunctionEnd
diff --git a/Test/spv.layer.tese b/Test/spv.layer.tese
new file mode 100644
index 0000000..b0ce079
--- /dev/null
+++ b/Test/spv.layer.tese
@@ -0,0 +1,8 @@
+#version 450
+
+#extension GL_ARB_shader_viewport_layer_array : require
+
+layout(triangles) in;
+void main() {
+ gl_Layer = 1;
+}
diff --git a/Test/spv.viewportindex.tese b/Test/spv.viewportindex.tese
new file mode 100644
index 0000000..0da4cc8
--- /dev/null
+++ b/Test/spv.viewportindex.tese
@@ -0,0 +1,8 @@
+#version 450
+
+#extension GL_ARB_shader_viewport_layer_array : require
+
+layout(triangles) in;
+void main() {
+ gl_ViewportIndex = 1;
+}
diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp
index 9cb3dba..0f6e9f8 100644
--- a/gtests/Spv.FromFile.cpp
+++ b/gtests/Spv.FromFile.cpp
@@ -352,6 +352,7 @@
"spv.int64.frag",
"spv.intcoopmat.comp",
"spv.intOps.vert",
+ "spv.layer.tese",
"spv.layoutNested.vert",
"spv.length.frag",
"spv.localAggregates.frag",
@@ -439,6 +440,7 @@
"spv.terminate.frag",
"spv.precise.tese",
"spv.precise.tesc",
+ "spv.viewportindex.tese",
"spv.volatileAtomic.comp",
"spv.vulkan100.subgroupArithmetic.comp",
"spv.vulkan100.subgroupPartitioned.comp",