Add-support-for-SPV_NV_shading_rate
diff --git a/SPIRV/GLSL.ext.NV.h b/SPIRV/GLSL.ext.NV.h
index 1904bac..6abc469 100644
--- a/SPIRV/GLSL.ext.NV.h
+++ b/SPIRV/GLSL.ext.NV.h
@@ -33,7 +33,7 @@
 enum Capability;
 
 static const int GLSLextNVVersion = 100;
-static const int GLSLextNVRevision = 10;
+static const int GLSLextNVRevision = 11;
 
 //SPV_NV_sample_mask_override_coverage
 const char* const E_SPV_NV_sample_mask_override_coverage = "SPV_NV_sample_mask_override_coverage";
@@ -69,4 +69,7 @@
 //SPV_NVX_raytracing
 const char* const E_SPV_NVX_raytracing = "SPV_NVX_raytracing";
 
+//SPV_NV_shading_rate
+const char* const E_SPV_NV_shading_rate = "SPV_NV_shading_rate";
+
 #endif  // #ifndef GLSLextNV_H
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index d1b23d8..f0040b8 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -864,6 +864,14 @@
         builder.addExtension(spv::E_SPV_EXT_fragment_fully_covered);
         builder.addCapability(spv::CapabilityFragmentFullyCoveredEXT);
         return spv::BuiltInFullyCoveredEXT;
+    case glslang::EbvFragmentSizeNV:
+        builder.addExtension(spv::E_SPV_NV_shading_rate);
+        builder.addCapability(spv::CapabilityShadingRateNV);
+        return spv::BuiltInFragmentSizeNV;
+    case glslang::EbvInvocationsPerPixelNV:
+        builder.addExtension(spv::E_SPV_NV_shading_rate);
+        builder.addCapability(spv::CapabilityShadingRateNV);
+        return spv::BuiltInInvocationsPerPixelNV;
 
     // raytracing
     case glslang::EbvLaunchIdNV:
diff --git a/SPIRV/doc.cpp b/SPIRV/doc.cpp
index 57d23d6..dbbe97d 100644
--- a/SPIRV/doc.cpp
+++ b/SPIRV/doc.cpp
@@ -385,6 +385,8 @@
     case BuiltInSecondaryViewportMaskNV:    return "SecondaryViewportMaskNV";
     case BuiltInPositionPerViewNV:          return "PositionPerViewNV";
     case BuiltInViewportMaskPerViewNV:      return "ViewportMaskPerViewNV";
+    case BuiltInFragmentSizeNV:             return "FragmentSizeNV";
+    case BuiltInInvocationsPerPixelNV:      return "InvocationsPerPixelNV";
     case BuiltInBaryCoordNV:                return "BaryCoordNV";
     case BuiltInBaryCoordNoPerspNV:         return "BaryCoordNoPerspNV";
 #endif
@@ -892,6 +894,7 @@
     case CapabilityComputeDerivativeGroupLinearNV:  return "ComputeDerivativeGroupLinearNV";
     case CapabilityFragmentBarycentricNV:           return "FragmentBarycentricNV";
     case CapabilityMeshShadingNV:                   return "MeshShadingNV";
+    case CapabilityShadingRateNV:                   return "ShadingRateNV";
 #endif
 
     case CapabilityFragmentFullyCoveredEXT: return "FragmentFullyCoveredEXT";
diff --git a/Test/baseResults/spv.shadingRate.frag.out b/Test/baseResults/spv.shadingRate.frag.out
new file mode 100644
index 0000000..2b6bd31
--- /dev/null
+++ b/Test/baseResults/spv.shadingRate.frag.out
@@ -0,0 +1,48 @@
+spv.shadingRate.frag
+// Module Version 10000
+// Generated by (magic number): 80007
+// Id's are bound by 21
+
+                              Capability Shader
+                              Capability ShadingRateNV
+                              Extension  "SPV_NV_shading_rate"
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Fragment 4  "main" 9 13 17 19
+                              ExecutionMode 4 OriginUpperLeft
+                              Source GLSL 450
+                              SourceExtension  "GL_NV_shading_rate_image"
+                              Name 4  "main"
+                              Name 9  "FragmentSize"
+                              Name 13  "gl_FragmentSizeNV"
+                              Name 17  "InvocationsPerPixel"
+                              Name 19  "gl_InvocationsPerPixelNV"
+                              Decorate 9(FragmentSize) Location 0
+                              Decorate 13(gl_FragmentSizeNV) Flat
+                              Decorate 13(gl_FragmentSizeNV) BuiltIn FragmentSizeNV
+                              Decorate 17(InvocationsPerPixel) Location 2
+                              Decorate 19(gl_InvocationsPerPixelNV) Flat
+                              Decorate 19(gl_InvocationsPerPixelNV) BuiltIn InvocationsPerPixelNV
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeFloat 32
+               7:             TypeVector 6(float) 2
+               8:             TypePointer Output 7(fvec2)
+ 9(FragmentSize):      8(ptr) Variable Output
+              10:             TypeInt 32 1
+              11:             TypeVector 10(int) 2
+              12:             TypePointer Input 11(ivec2)
+13(gl_FragmentSizeNV):     12(ptr) Variable Input
+              16:             TypePointer Output 10(int)
+17(InvocationsPerPixel):     16(ptr) Variable Output
+              18:             TypePointer Input 10(int)
+19(gl_InvocationsPerPixelNV):     18(ptr) Variable Input
+         4(main):           2 Function None 3
+               5:             Label
+              14:   11(ivec2) Load 13(gl_FragmentSizeNV)
+              15:    7(fvec2) ConvertSToF 14
+                              Store 9(FragmentSize) 15
+              20:     10(int) Load 19(gl_InvocationsPerPixelNV)
+                              Store 17(InvocationsPerPixel) 20
+                              Return
+                              FunctionEnd
diff --git a/Test/spv.shadingRate.frag b/Test/spv.shadingRate.frag
new file mode 100644
index 0000000..8fbd4ba
--- /dev/null
+++ b/Test/spv.shadingRate.frag
@@ -0,0 +1,11 @@
+#version 450
+
+#extension GL_NV_shading_rate_image : require
+
+layout (location = 0) out vec2 FragmentSize;
+layout (location = 2) out int InvocationsPerPixel;
+
+void main () {
+    FragmentSize = gl_FragmentSizeNV;
+    InvocationsPerPixel = gl_InvocationsPerPixelNV;
+}
\ No newline at end of file
diff --git a/glslang/Include/BaseTypes.h b/glslang/Include/BaseTypes.h
index d1a8908..fc3a19f 100644
--- a/glslang/Include/BaseTypes.h
+++ b/glslang/Include/BaseTypes.h
@@ -237,6 +237,8 @@
     EbvPositionPerViewNV,
     EbvViewportMaskPerViewNV,
     EbvFragFullyCoveredNV,
+    EbvFragmentSizeNV,
+    EbvInvocationsPerPixelNV,
     // raytracing
     EbvLaunchIdNV,
     EbvLaunchSizeNV,
@@ -404,6 +406,8 @@
     case EbvPositionPerViewNV:          return "PositionPerViewNV";
     case EbvViewportMaskPerViewNV:      return "ViewportMaskPerViewNV";
     case EbvFragFullyCoveredNV:         return "FragFullyCoveredNV";
+    case EbvFragmentSizeNV:             return "FragmentSizeNV";
+    case EbvInvocationsPerPixelNV:      return "InvocationsPerPixelNV";
     case EbvLaunchIdNV:                 return "LaunchIdNVX";
     case EbvLaunchSizeNV:               return "LaunchSizeNVX";
     case EbvInstanceCustomIndexNV:      return "InstanceCustomIndexNVX";
diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp
index 24697d3..cf5b2fe 100644
--- a/glslang/MachineIndependent/Initialize.cpp
+++ b/glslang/MachineIndependent/Initialize.cpp
@@ -5949,6 +5949,8 @@
                 );
         if (version >= 450)
             stageBuiltins[EShLangFragment].append(
+                "flat in ivec2 gl_FragmentSizeNV;"
+                "flat in int   gl_InvocationsPerPixelNV;"
                 "in vec3 gl_BaryCoordNV;"
                 "in vec3 gl_BaryCoordNoPerspNV;"
                 );
@@ -5995,6 +5997,11 @@
             "highp float gl_FragDepthEXT;"       // GL_EXT_frag_depth
             );
 #ifdef NV_EXTENSIONS
+        if (version >= 320)
+            stageBuiltins[EShLangFragment].append(
+                "flat in ivec2 gl_FragmentSizeNV;"
+                "flat in int   gl_InvocationsPerPixelNV;"
+            );
        if (version >= 320)
             stageBuiltins[EShLangFragment].append(
                 "in vec3 gl_BaryCoordNV;"
@@ -8286,6 +8293,10 @@
         }
         if ((profile != EEsProfile && version >= 450) ||
             (profile == EEsProfile && version >= 320)) {
+            symbolTable.setVariableExtensions("gl_FragmentSizeNV",        1, &E_GL_NV_shading_rate_image);
+            symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
+            BuiltInVariable("gl_FragmentSizeNV",        EbvFragmentSizeNV, symbolTable);
+            BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
             symbolTable.setVariableExtensions("gl_BaryCoordNV",        1, &E_GL_NV_fragment_shader_barycentric);
             symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
             BuiltInVariable("gl_BaryCoordNV",        EbvBaryCoordNV,        symbolTable);
diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp
index b73880d..250f325 100644
--- a/glslang/MachineIndependent/Versions.cpp
+++ b/glslang/MachineIndependent/Versions.cpp
@@ -235,6 +235,7 @@
     extensionBehavior[E_GL_NV_conservative_raster_underestimation]   = EBhDisable;
     extensionBehavior[E_GL_NV_shader_noperspective_interpolation]    = EBhDisable;
     extensionBehavior[E_GL_NV_shader_subgroup_partitioned]           = EBhDisable;
+    extensionBehavior[E_GL_NV_shading_rate_image]                    = EBhDisable;
     extensionBehavior[E_GL_NVX_raytracing]                           = EBhDisable;
     extensionBehavior[E_GL_NV_fragment_shader_barycentric]           = EBhDisable;
     extensionBehavior[E_GL_NV_compute_shader_derivatives]            = EBhDisable;
@@ -410,6 +411,7 @@
             "#define GL_NV_shader_atomic_int64 1\n"
             "#define GL_NV_conservative_raster_underestimation 1\n"
             "#define GL_NV_shader_subgroup_partitioned 1\n"
+            "#define GL_NV_shading_rate_image 1\n"
             "#define GL_NVX_raytracing 1\n"
             "#define GL_NV_fragment_shader_barycentric 1\n"
             "#define GL_NV_compute_shader_derivatives 1\n"
diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h
index 5e577dc..e4cbbbb 100644
--- a/glslang/MachineIndependent/Versions.h
+++ b/glslang/MachineIndependent/Versions.h
@@ -207,6 +207,7 @@
 const char* const E_GL_NV_conservative_raster_underestimation   = "GL_NV_conservative_raster_underestimation";
 const char* const E_GL_NV_shader_noperspective_interpolation    = "GL_NV_shader_noperspective_interpolation";
 const char* const E_GL_NV_shader_subgroup_partitioned           = "GL_NV_shader_subgroup_partitioned";
+const char* const E_GL_NV_shading_rate_image                    = "GL_NV_shading_rate_image";
 const char* const E_GL_NVX_raytracing                           = "GL_NVX_raytracing";
 const char* const E_GL_NV_fragment_shader_barycentric           = "GL_NV_fragment_shader_barycentric";
 const char* const E_GL_NV_compute_shader_derivatives            = "GL_NV_compute_shader_derivatives";
diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp
index cf56c4c..29e75bb 100644
--- a/gtests/Spv.FromFile.cpp
+++ b/gtests/Spv.FromFile.cpp
@@ -501,6 +501,7 @@
     "spv.multiviewPerViewAttributes.vert",
     "spv.multiviewPerViewAttributes.tesc",
     "spv.atomicInt64.comp",
+    "spv.shadingRate.frag",
     "spv.RayGenShader.rgen",
     "spv.RayGenShader_Errors.rgen",
     "spv.RayConstants.rgen",