2
0
Эх сурвалжийг харах

[spirv] Translate SV_InnerCoverage into FullyCoveredEXT (#1165)

Fixes https://github.com/Microsoft/DirectXShaderCompiler/issues/999
Lei Zhang 7 жил өмнө
parent
commit
66a8998f87

+ 127 - 127
docs/SPIR-V.rst

@@ -994,131 +994,133 @@ some system-value (SV) semantic strings will be translated into SPIR-V
 
 .. table:: Mapping from HLSL SV semantic to SPIR-V builtin and execution mode
 
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| HLSL Semantic             | SigPoint    | SPIR-V ``BuiltIn``       | SPIR-V Execution Mode |   SPIR-V Capability   |
-+===========================+=============+==========================+=======================+=======================+
-|                           | VSOut       | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPIn      | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPOut     | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSCPIn      | ``Position``             | N/A                   | ``Shader``            |
-| SV_Position               +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSOut       | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSVIn       | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``Position``             | N/A                   | ``Shader``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``FragCoord``            | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | VSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPIn      | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPOut     | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSCPIn      | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-| SV_ClipDistance           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSVIn       | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``ClipDistance``         | N/A                   | ``ClipDistance``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | VSOut       | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPIn      | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSCPOut     | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSCPIn      | ``CullDistance``         | N/A                   | ``CullDistance``      |
-| SV_CullDistance           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSOut       | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSVIn       | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``CullDistance``         | N/A                   | ``CullDistance``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``CullDistance``         | N/A                   | ``CullDistance``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_VertexID               | VSIn        | ``VertexIndex``          | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_InstanceID             | VSIn        | ``InstanceIndex``        | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_Depth                  | PSOut       | ``FragDepth``            | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_DepthGreaterEqual      | PSOut       | ``FragDepth``            | ``DepthGreater``      | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_DepthLessEqual         | PSOut       | ``FragDepth``            | ``DepthLess``         | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_IsFrontFace            | PSIn        | ``FrontFacing``          | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_DispatchThreadID       | CSIn        | ``GlobalInvocationId``   | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_GroupID                | CSIn        | ``WorkgroupId``          | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_GroupThreadID          | CSIn        | ``LocalInvocationId``    | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_GroupIndex             | CSIn        | ``LocalInvocationIndex`` | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_OutputControlPointID   | HSIn        | ``InvocationId``         | N/A                   | ``Tessellation``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_GSInstanceID           | GSIn        | ``InvocationId``         | N/A                   | ``Geometry``          |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_DomainLocation         | DSIn        | ``TessCoord``            | N/A                   | ``Tessellation``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PCIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``      |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DsIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``      |
-| SV_PrimitiveID            +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSIn        | ``PrimitiveId``          | N/A                   | ``Geometry``          |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``PrimitiveId``          | N/A                   | ``Geometry``          |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``PrimitiveId``          | N/A                   | ``Geometry``          |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | PCOut       | ``TessLevelOuter``       | N/A                   | ``Tessellation``      |
-| SV_TessFactor             +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSIn        | ``TessLevelOuter``       | N/A                   | ``Tessellation``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | PCOut       | ``TessLevelInner``       | N/A                   | ``Tessellation``      |
-| SV_InsideTessFactor       +-------------+--------------------------+-----------------------+-----------------------+
-|                           | DSIn        | ``TessLevelInner``       | N/A                   | ``Tessellation``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_SampleIndex            | PSIn        | ``SampleId``             | N/A                   | ``SampleRateShading`` |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_StencilRef             | PSOut       | ``FragStencilRefEXT``    | N/A                   | ``StencilExportEXT``  |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-| SV_Barycentrics           | PSIn        | ``BaryCoord*AMD``        | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``Layer``                | N/A                   | ``Geometry``          |
-| SV_RenderTargetArrayIndex +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``Layer``                | N/A                   | ``Geometry``          |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSOut       | ``ViewportIndex``        | N/A                   | ``MultiViewport``     |
-| SV_ViewportArrayIndex     +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``ViewportIndex``        | N/A                   | ``MultiViewport``     |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``SampleMask``           | N/A                   | ``Shader``            |
-| SV_Coverage               +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSOut       | ``SampleMask``           | N/A                   | ``Shader``            |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
-|                           | VSIn        | ``ViewIndex``            | N/A                   | ``MultiView``         |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | HSIn        | ``ViewIndex``            | N/A                   | ``MultiView``         |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-| SV_ViewID                 | DSIn        | ``ViewIndex``            | N/A                   | ``MultiView``         |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | GSIn        | ``ViewIndex``            | N/A                   | ``MultiView``         |
-|                           +-------------+--------------------------+-----------------------+-----------------------+
-|                           | PSIn        | ``ViewIndex``            | N/A                   | ``MultiView``         |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------+
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| HLSL Semantic             | SigPoint    | SPIR-V ``BuiltIn``       | SPIR-V Execution Mode |   SPIR-V Capability         |
++===========================+=============+==========================+=======================+=============================+
+|                           | VSOut       | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPIn      | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPOut     | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSCPIn      | ``Position``             | N/A                   | ``Shader``                  |
+| SV_Position               +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSOut       | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSVIn       | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``Position``             | N/A                   | ``Shader``                  |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``FragCoord``            | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | VSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPIn      | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPOut     | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSCPIn      | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+| SV_ClipDistance           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSVIn       | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``ClipDistance``         | N/A                   | ``ClipDistance``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | VSOut       | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPIn      | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSCPOut     | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSCPIn      | ``CullDistance``         | N/A                   | ``CullDistance``            |
+| SV_CullDistance           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSOut       | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSVIn       | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``CullDistance``         | N/A                   | ``CullDistance``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``CullDistance``         | N/A                   | ``CullDistance``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_VertexID               | VSIn        | ``VertexIndex``          | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_InstanceID             | VSIn        | ``InstanceIndex``        | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_Depth                  | PSOut       | ``FragDepth``            | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_DepthGreaterEqual      | PSOut       | ``FragDepth``            | ``DepthGreater``      | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_DepthLessEqual         | PSOut       | ``FragDepth``            | ``DepthLess``         | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_IsFrontFace            | PSIn        | ``FrontFacing``          | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_DispatchThreadID       | CSIn        | ``GlobalInvocationId``   | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_GroupID                | CSIn        | ``WorkgroupId``          | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_GroupThreadID          | CSIn        | ``LocalInvocationId``    | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_GroupIndex             | CSIn        | ``LocalInvocationIndex`` | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_OutputControlPointID   | HSIn        | ``InvocationId``         | N/A                   | ``Tessellation``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_GSInstanceID           | GSIn        | ``InvocationId``         | N/A                   | ``Geometry``                |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_DomainLocation         | DSIn        | ``TessCoord``            | N/A                   | ``Tessellation``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PCIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``            |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DsIn        | ``PrimitiveId``          | N/A                   | ``Tessellation``            |
+| SV_PrimitiveID            +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSIn        | ``PrimitiveId``          | N/A                   | ``Geometry``                |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``PrimitiveId``          | N/A                   | ``Geometry``                |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``PrimitiveId``          | N/A                   | ``Geometry``                |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PCOut       | ``TessLevelOuter``       | N/A                   | ``Tessellation``            |
+| SV_TessFactor             +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSIn        | ``TessLevelOuter``       | N/A                   | ``Tessellation``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PCOut       | ``TessLevelInner``       | N/A                   | ``Tessellation``            |
+| SV_InsideTessFactor       +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | DSIn        | ``TessLevelInner``       | N/A                   | ``Tessellation``            |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_SampleIndex            | PSIn        | ``SampleId``             | N/A                   | ``SampleRateShading``       |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_StencilRef             | PSOut       | ``FragStencilRefEXT``    | N/A                   | ``StencilExportEXT``        |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_Barycentrics           | PSIn        | ``BaryCoord*AMD``        | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``Layer``                | N/A                   | ``Geometry``                |
+| SV_RenderTargetArrayIndex +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``Layer``                | N/A                   | ``Geometry``                |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``ViewportIndex``        | N/A                   | ``MultiViewport``           |
+| SV_ViewportArrayIndex     +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``ViewportIndex``        | N/A                   | ``MultiViewport``           |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``SampleMask``           | N/A                   | ``Shader``                  |
+| SV_Coverage               +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSOut       | ``SampleMask``           | N/A                   | ``Shader``                  |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+| SV_InnerCoverage          | PSIn        | ``FullyCoveredEXT``      | N/A                   | ``FragmentFullyCoveredEXT`` |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
+|                           | VSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | HSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+| SV_ViewID                 | DSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | GSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
+|                           +-------------+--------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
++---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
 
 For entities (function parameters, function return values, struct fields) with
 the above SV semantic strings attached, SPIR-V variables of the
@@ -2652,8 +2654,6 @@ either because of no Vulkan equivalents at the moment, or because of deprecation
 * ``.CalculateLevelOfDetailUnclamped()`` intrinsic method: no Vulkan equivalent.
   (SPIR-V ``OpImageQueryLod`` returns the clamped LOD in Vulkan.) The compiler
   will emit an error.
-* ``SV_InnerCoverage`` semantic does not have a Vulkan equivalent. The compiler
-  will emit an error.
 * Since ``StructuredBuffer``, ``RWStructuredBuffer``, ``ByteAddressBuffer``, and
   ``RWByteAddressBuffer`` are not represented as image types in SPIR-V, using the
   output unsigned integer ``status`` argument in their ``Load*`` methods is not

+ 29 - 2
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -1256,6 +1256,8 @@ bool DeclResultIdMapper::createStageVars(const hlsl::SigPoint *sigPoint,
     //   SPIR-V for Vulkan.
     // * SV_Coverage is an uint value, but the builtin it corresponds to,
     //   SampleMask, must be an array of integers.
+    // * SV_InnerCoverage is an uint value, but the corresponding builtin,
+    //   FullyCoveredEXT, must be an boolean value.
 
     if (glPerVertex.tryToAccess(sigPoint->GetKind(), semanticKind,
                                 semanticToUse->index, invocationId, value,
@@ -1279,6 +1281,9 @@ bool DeclResultIdMapper::createStageVars(const hlsl::SigPoint *sigPoint,
     case hlsl::Semantic::Kind::Coverage:
       typeId = theBuilder.getArrayType(typeId, theBuilder.getConstantUint32(1));
       break;
+    case hlsl::Semantic::Kind::InnerCoverage:
+      typeId = theBuilder.getBoolType();
+      break;
     case hlsl::Semantic::Kind::Barycentrics:
       typeId = theBuilder.getVecType(theBuilder.getFloat32Type(), 2);
       break;
@@ -1380,6 +1385,22 @@ bool DeclResultIdMapper::createStageVars(const hlsl::SigPoint *sigPoint,
       else if (semanticKind == hlsl::Semantic::Kind::Coverage) {
         *value = theBuilder.createCompositeExtract(srcTypeId, *value, {0});
       }
+      // Special handling of SV_InnerCoverage, which is an uint value. We need
+      // to read FullyCoveredEXT, which is a boolean value, and convert it to an
+      // uint value. According to D3D12 "Conservative Rasterization" doc: "The
+      // Pixel Shader has a 32-bit scalar integer System Generate Value
+      // available: InnerCoverage. This is a bit-field that has bit 0 from the
+      // LSB set to 1 for a given conservatively rasterized pixel, only when
+      // that pixel is guaranteed to be entirely inside the current primitive.
+      // All other input register bits must be set to 0 when bit 0 is not set,
+      // but are undefined when bit 0 is set to 1 (essentially, this bit-field
+      // represents a Boolean value where false must be exactly 0, but true can
+      // be any odd (i.e. bit 0 set) non-zero value)."
+      else if (semanticKind == hlsl::Semantic::Kind::InnerCoverage) {
+        *value = theBuilder.createSelect(theBuilder.getUint32Type(), *value,
+                                         theBuilder.getConstantUint32(1),
+                                         theBuilder.getConstantUint32(0));
+      }
       // Special handling of SV_Barycentrics, which is a float3, but the
       // underlying stage input variable is a float2 (only provides the first
       // two components). Calculate the third element.
@@ -2118,9 +2139,15 @@ uint32_t DeclResultIdMapper::createSpirvStageVar(StageVar *stageVar,
     stageVar->setIsSpirvBuiltin();
     return theBuilder.addStageBuiltinVar(type, sc, BuiltIn::ViewIndex);
   }
+    // According to DXIL spec, the InnerCoverage SV can only be used as PSIn.
+    // According to Vulkan spec, the FullyCoveredEXT BuiltIn can only be used as
+    // PSIn.
   case hlsl::Semantic::Kind::InnerCoverage: {
-    emitError("no equivalent for semantic SV_InnerCoverage in Vulkan", srcLoc);
-    return 0;
+    theBuilder.addExtension("SPV_EXT_fragment_fully_covered");
+    theBuilder.requireCapability(spv::Capability::FragmentFullyCoveredEXT);
+
+    stageVar->setIsSpirvBuiltin();
+    return theBuilder.addStageBuiltinVar(type, sc, BuiltIn::FullyCoveredEXT);
   }
   default:
     emitError("semantic %0 unimplemented", srcLoc)

+ 11 - 2
tools/clang/test/CodeGenSPIRV/semantic.inner-coverage.ps.hlsl

@@ -1,7 +1,16 @@
 // Run: %dxc -T ps_6_0 -E main
 
+// CHECK:      OpCapability FragmentFullyCoveredEXT
+// CHECK:      OpExtension "SPV_EXT_fragment_fully_covered"
+
+// CHECK:      OpEntryPoint Fragment
+// CHECK-SAME: [[coverage:%\d+]]
+// CHECK:      [[coverage]] = OpVariable %_ptr_Input_bool Input
+
+
 float4 main(uint inCov : SV_InnerCoverage) : SV_Target {
+// CHECK:      [[boolv:%\d+]] = OpLoad %bool [[coverage]]
+// CHECK-NEXT:  [[intv:%\d+]] = OpSelect %uint [[boolv]] %uint_1 %uint_0
+// CHECK-NEXT:                  OpStore %param_var_inCov [[intv]]
     return 1.0;
 }
-
-// CHECK: 3:26: error: no equivalent for semantic SV_InnerCoverage in Vulkan

+ 1 - 1
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -607,7 +607,7 @@ TEST_F(FileTest, SemanticCoverageTypeMismatchPS) {
   runFileTest("semantic.coverage.type-mismatch.ps.hlsl");
 }
 TEST_F(FileTest, SemanticInnerCoveragePS) {
-  runFileTest("semantic.inner-coverage.ps.hlsl", Expect::Failure);
+  runFileTest("semantic.inner-coverage.ps.hlsl");
 }
 TEST_F(FileTest, SemanticViewIDVS) { runFileTest("semantic.view-id.vs.hlsl"); }
 TEST_F(FileTest, SemanticViewIDHS) { runFileTest("semantic.view-id.hs.hlsl"); }