diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 492c9120e8ffd57796474fe3181da533c3073cf8..eaa8cd3afd2499aec3ca174c27eb55e97a146b61 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -520,6 +520,10 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
             builder.addCapability(spv::CapabilityGeometry);
         return spv::BuiltInPrimitiveId;
 
+    case glslang::EbvFragStencilRef:
+        logger->missingFunctionality("shader stencil export");
+        return spv::BuiltInMax;
+
     case glslang::EbvInvocationId:         return spv::BuiltInInvocationId;
     case glslang::EbvTessLevelInner:       return spv::BuiltInTessLevelInner;
     case glslang::EbvTessLevelOuter:       return spv::BuiltInTessLevelOuter;
diff --git a/Test/baseResults/spv.shaderStencilExport.frag.out b/Test/baseResults/spv.shaderStencilExport.frag.out
new file mode 100644
index 0000000000000000000000000000000000000000..c0c72095256d7e19e4fd963bc35878c19506650d
--- /dev/null
+++ b/Test/baseResults/spv.shaderStencilExport.frag.out
@@ -0,0 +1,26 @@
+spv.shaderStencilExport.frag
+Missing functionality: shader stencil export
+// Module Version 10000
+// Generated by (magic number): 80001
+// Id's are bound by 10
+
+                              Capability Shader
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Fragment 4  "main" 8
+                              ExecutionMode 4 OriginUpperLeft
+                              Source GLSL 450
+                              SourceExtension  "GL_ARB_shader_stencil_export"
+                              Name 4  "main"
+                              Name 8  "gl_FragStencilRefARB"
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeInt 32 1
+               7:             TypePointer Output 6(int)
+8(gl_FragStencilRefARB):      7(ptr) Variable Output
+               9:      6(int) Constant 100
+         4(main):           2 Function None 3
+               5:             Label
+                              Store 8(gl_FragStencilRefARB) 9
+                              Return
+                              FunctionEnd
diff --git a/Test/spv.shaderStencilExport.frag b/Test/spv.shaderStencilExport.frag
new file mode 100644
index 0000000000000000000000000000000000000000..62e0f573ab5655644f28a05b8f38e66589f85350
--- /dev/null
+++ b/Test/spv.shaderStencilExport.frag
@@ -0,0 +1,8 @@
+#version 450 core
+
+#extension GL_ARB_shader_stencil_export: enable
+
+void main()
+{
+    gl_FragStencilRefARB = 100;
+}
diff --git a/glslang/Include/BaseTypes.h b/glslang/Include/BaseTypes.h
index 46392d05074dcce013d35c7394e3dbf25b11b0a3..08fb623ac4861d456c7dcda98a3e621ae3f7af5d 100644
--- a/glslang/Include/BaseTypes.h
+++ b/glslang/Include/BaseTypes.h
@@ -193,6 +193,7 @@ enum TBuiltInVariable {
     EbvFragColor,
     EbvFragData,
     EbvFragDepth,
+    EbvFragStencilRef,
     EbvSampleId,
     EbvSamplePosition,
     EbvSampleMask,
@@ -222,7 +223,6 @@ enum TBuiltInVariable {
     // to one of the above.
     EbvFragDepthGreater,
     EbvFragDepthLesser,
-    EbvStencilRef,
     EbvGsOutputStream,
     EbvOutputPatch,
     EbvInputPatch,
@@ -329,6 +329,7 @@ __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
     case EbvFragColor:            return "FragColor";
     case EbvFragData:             return "FragData";
     case EbvFragDepth:            return "FragDepth";
+    case EbvFragStencilRef:       return "FragStencilRef";
     case EbvSampleId:             return "SampleId";
     case EbvSamplePosition:       return "SamplePosition";
     case EbvSampleMask:           return "SampleMaskIn";
diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp
index fbd2281d67e753b0c6fe1541c72cca44e14dc91b..07fbcf766d55e76a19a8619e930d8c21706803f3 100644
--- a/glslang/MachineIndependent/Initialize.cpp
+++ b/glslang/MachineIndependent/Initialize.cpp
@@ -3753,6 +3753,10 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
             stageBuiltins[EShLangFragment].append(
                 "vec2 gl_PointCoord;"  // needs qualifier fixed later
                 );
+        if (version >= 140)
+            stageBuiltins[EShLangFragment].append(
+                "out int gl_FragStencilRefARB;"
+                );
         if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420))
             stageBuiltins[EShLangFragment].append(
                 "vec4 gl_FragColor;"   // needs qualifier fixed later
@@ -5473,6 +5477,11 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
         BuiltInVariable("gl_CullDistance",    EbvCullDistance,   symbolTable);
         BuiltInVariable("gl_PrimitiveID",     EbvPrimitiveId,    symbolTable);
 
+        if (profile != EEsProfile && version >= 140) {
+            symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
+            BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
+        }
+
         if ((profile != EEsProfile && version >= 400) ||
             (profile == EEsProfile && version >= 310)) {
             BuiltInVariable("gl_SampleID",        EbvSampleId,       symbolTable);
diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp
index 24fde2fbe4beea8eeaa26fc604cb844644328117..1763defabcf0b02934932e8ad7fbe94effe5c979 100644
--- a/glslang/MachineIndependent/Versions.cpp
+++ b/glslang/MachineIndependent/Versions.cpp
@@ -179,6 +179,7 @@ void TParseVersions::initializeExtensionBehavior()
     extensionBehavior[E_GL_ARB_shader_ballot]                = EBhDisable;
     extensionBehavior[E_GL_ARB_sparse_texture2]              = EBhDisable;
     extensionBehavior[E_GL_ARB_sparse_texture_clamp]         = EBhDisable;
+    extensionBehavior[E_GL_ARB_shader_stencil_export]        = EBhDisable;
 //    extensionBehavior[E_GL_ARB_cull_distance]                = EBhDisable;    // present for 4.5, but need extension control over block members
 
     extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable;
@@ -309,6 +310,7 @@ void TParseVersions::getPreamble(std::string& preamble)
             "#define GL_ARB_shader_ballot 1\n"
             "#define GL_ARB_sparse_texture2 1\n"
             "#define GL_ARB_sparse_texture_clamp 1\n"
+            "#define GL_ARB_shader_stencil_export 1\n"
 //            "#define GL_ARB_cull_distance 1\n"    // present for 4.5, but need extension control over block members
             "#define GL_EXT_shader_non_constant_global_initializers 1\n"
             "#define GL_EXT_shader_image_load_formatted 1\n"
diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h
index 08cf8e0ecd539e785c56132fb804752b54b50719..8a93964303286970263ad173d2e2424227641b60 100644
--- a/glslang/MachineIndependent/Versions.h
+++ b/glslang/MachineIndependent/Versions.h
@@ -133,6 +133,7 @@ const char* const E_GL_ARB_gpu_shader_int64             = "GL_ARB_gpu_shader_int
 const char* const E_GL_ARB_shader_ballot                = "GL_ARB_shader_ballot";
 const char* const E_GL_ARB_sparse_texture2              = "GL_ARB_sparse_texture2";
 const char* const E_GL_ARB_sparse_texture_clamp         = "GL_ARB_sparse_texture_clamp";
+const char* const E_GL_ARB_shader_stencil_export        = "GL_ARB_shader_stencil_export";
 // const char* const E_GL_ARB_cull_distance            = "GL_ARB_cull_distance";  // present for 4.5, but need extension control over block members
 
 const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp
index dc91486e84ec1f355041d39e4cdf9b4f47b563f7..64430656c9fa43b504001f05c46dc18baeb0966a 100644
--- a/gtests/Spv.FromFile.cpp
+++ b/gtests/Spv.FromFile.cpp
@@ -278,6 +278,7 @@ INSTANTIATE_TEST_CASE_P(
         "spv.shaderBallot.comp",
         "spv.shaderDrawParams.vert",
         "spv.shaderGroupVote.comp",
+        "spv.shaderStencilExport.frag",
         "spv.shiftOps.frag",
         "spv.simpleFunctionCall.frag",
         "spv.simpleMat.vert",
diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp
index 0454b5e1f44a17b6f4b268a4255da842ab13e97a..f20cbaecb42c1d5ac79c17b2448e32b0831f45db 100755
--- a/hlsl/hlslParseHelper.cpp
+++ b/hlsl/hlslParseHelper.cpp
@@ -5249,7 +5249,7 @@ void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, TBu
         if (language == EShLangFragment)
             builtIn = EbvFragCoord;
         break;
-    case EbvStencilRef:
+    case EbvFragStencilRef:
         error(loc, "unimplemented; need ARB_shader_stencil_export", "SV_STENCILREF", "");
         break;
     case EbvTessLevelInner:
diff --git a/hlsl/hlslScanContext.cpp b/hlsl/hlslScanContext.cpp
index 34f7b46593f48baf7f6e0204a7b689941967affa..351aace91d2ae3a15109de79a5c026423eac5084 100755
--- a/hlsl/hlslScanContext.cpp
+++ b/hlsl/hlslScanContext.cpp
@@ -466,7 +466,7 @@ void HlslScanContext::fillInKeywordMap()
     (*SemanticMap)["SV_COVERAGE"] =               EbvSampleMask;
     (*SemanticMap)["SV_DEPTHGREATEREQUAL"] =      EbvFragDepthGreater;
     (*SemanticMap)["SV_DEPTHLESSEQUAL"] =         EbvFragDepthLesser;
-    (*SemanticMap)["SV_STENCILREF"] =             EbvStencilRef;
+    (*SemanticMap)["SV_STENCILREF"] =             EbvFragStencilRef;
 }
 
 void HlslScanContext::deleteKeywordMap()