From 3e783f9b49062f8f1ec10b61090a3366e2b40f23 Mon Sep 17 00:00:00 2001
From: Rex Xu <rex.xu@amd.com>
Date: Wed, 22 Feb 2017 16:44:48 +0800
Subject: [PATCH] SPV: Unexpected declarations of capabilities from NV
 extensions.

---
 SPIRV/GlslangToSpv.cpp                        | 31 ++++++++++++-------
 SPIRV/doc.cpp                                 |  1 +
 .../spv.multiviewPerViewAttributes.tesc.out   |  2 +-
 .../spv.multiviewPerViewAttributes.vert.out   |  2 +-
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 4014525a7..738d1d7d2 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -472,12 +472,12 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
     //
     case glslang::EbvClipDistance:
         if (!memberDeclaration)
-        builder.addCapability(spv::CapabilityClipDistance);
+            builder.addCapability(spv::CapabilityClipDistance);
         return spv::BuiltInClipDistance;
 
     case glslang::EbvCullDistance:
         if (!memberDeclaration)
-        builder.addCapability(spv::CapabilityCullDistance);
+            builder.addCapability(spv::CapabilityCullDistance);
         return spv::BuiltInCullDistance;
 
     case glslang::EbvViewportIndex:
@@ -635,23 +635,32 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
         builder.addCapability(spv::CapabilityShaderViewportMaskNV);
         return spv::BuiltInViewportMaskNV;
     case glslang::EbvSecondaryPositionNV:
-        builder.addExtension(spv::E_SPV_NV_stereo_view_rendering);
-        builder.addCapability(spv::CapabilityShaderStereoViewNV);
+        if (!memberDeclaration) {
+            builder.addExtension(spv::E_SPV_NV_stereo_view_rendering);
+            builder.addCapability(spv::CapabilityShaderStereoViewNV);
+        }
         return spv::BuiltInSecondaryPositionNV;
     case glslang::EbvSecondaryViewportMaskNV:
-        builder.addExtension(spv::E_SPV_NV_stereo_view_rendering);
-        builder.addCapability(spv::CapabilityShaderStereoViewNV);
+        if (!memberDeclaration) {
+            builder.addExtension(spv::E_SPV_NV_stereo_view_rendering);
+            builder.addCapability(spv::CapabilityShaderStereoViewNV);
+        }
         return spv::BuiltInSecondaryViewportMaskNV;
     case glslang::EbvPositionPerViewNV:
-        builder.addExtension(spv::E_SPV_NVX_multiview_per_view_attributes);
-        builder.addCapability(spv::CapabilityPerViewAttributesNV);
+        if (!memberDeclaration) {
+            builder.addExtension(spv::E_SPV_NVX_multiview_per_view_attributes);
+            builder.addCapability(spv::CapabilityPerViewAttributesNV);
+        }
         return spv::BuiltInPositionPerViewNV;
     case glslang::EbvViewportMaskPerViewNV:
-        builder.addExtension(spv::E_SPV_NVX_multiview_per_view_attributes);
-        builder.addCapability(spv::CapabilityPerViewAttributesNV);
+        if (!memberDeclaration) {
+            builder.addExtension(spv::E_SPV_NVX_multiview_per_view_attributes);
+            builder.addCapability(spv::CapabilityPerViewAttributesNV);
+        }
         return spv::BuiltInViewportMaskPerViewNV;
 #endif 
-    default:                               return spv::BuiltInMax;
+    default:
+        return spv::BuiltInMax;
     }
 }
 
diff --git a/SPIRV/doc.cpp b/SPIRV/doc.cpp
index b497bba7e..91e3b8934 100755
--- a/SPIRV/doc.cpp
+++ b/SPIRV/doc.cpp
@@ -835,6 +835,7 @@ const char* CapabilityString(int info)
     case 5254: return "ShaderViewportIndexLayerNV";
     case 5255: return "ShaderViewportMaskNV";
     case 5259: return "ShaderStereoViewNV";
+    case 5262: return "PerViewAttributesNV";
 #endif
 
     }
diff --git a/Test/baseResults/spv.multiviewPerViewAttributes.tesc.out b/Test/baseResults/spv.multiviewPerViewAttributes.tesc.out
index 61b38c8bc..22e1def8c 100644
--- a/Test/baseResults/spv.multiviewPerViewAttributes.tesc.out
+++ b/Test/baseResults/spv.multiviewPerViewAttributes.tesc.out
@@ -6,7 +6,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre
 // Id's are bound by 37
 
                               Capability Tessellation
-                              Capability Bad
+                              Capability PerViewAttributesNV
                               Extension  "SPV_NVX_multiview_per_view_attributes"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
diff --git a/Test/baseResults/spv.multiviewPerViewAttributes.vert.out b/Test/baseResults/spv.multiviewPerViewAttributes.vert.out
index 2f3df9b54..350944a85 100644
--- a/Test/baseResults/spv.multiviewPerViewAttributes.vert.out
+++ b/Test/baseResults/spv.multiviewPerViewAttributes.vert.out
@@ -6,7 +6,7 @@ Warning, version 450 is not yet complete; most version-specific features are pre
 // Id's are bound by 29
 
                               Capability Shader
-                              Capability Bad
+                              Capability PerViewAttributesNV
                               Extension  "SPV_NVX_multiview_per_view_attributes"
                1:             ExtInstImport  "GLSL.std.450"
                               MemoryModel Logical GLSL450
-- 
GitLab