فهرست منبع

[spirv] support optional use of base vertex instance (#3478)

In DX12, `SV_InstanceID` always counts from 0. On the other hand,
Vulkan `gl_InstanceIndex` starts from the first instance. Thus it
doesn't emulate actual DX12 shader behavior. To make it equivalent,
we can set `SV_InstanceID = gl_InstanceIndex - gl_BaseInstance`.
However, it can break the existing working shaders (i.e., compatibility
issue). We want to provide an option for users to choose what they
exactly want by `SV_InstanceID`. This commit adds
`-fvk-support-nonzero-base-instance` option. If it is enabled, it emits
`SV_InstanceID = gl_InstanceIndex - gl_BaseInstance`. Otherwise,
`SV_InstanceID = gl_InstanceIndex`.
Jaebaek Seo 4 سال پیش
والد
کامیت
f913bde7d0

+ 162 - 159
docs/SPIR-V.rst

@@ -1268,165 +1268,168 @@ 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``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``Position``             | 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``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``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``            |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``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``                  |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | CSIn        | ``GlobalInvocationId``   | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-| SV_DispatchThreadID       | MSIn        | ``GlobalInvocationId``   | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | ASIn        | ``GlobalInvocationId``   | N/A                   | ``Shader``                  |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | CSIn        | ``WorkgroupId``          | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-| SV_GroupID                | MSIn        | ``WorkgroupId``          | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | ASIn        | ``WorkgroupId``          | N/A                   | ``Shader``                  |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | CSIn        | ``LocalInvocationId``    | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-| SV_GroupThreadID          | MSIn        | ``LocalInvocationId``    | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | ASIn        | ``LocalInvocationId``    | N/A                   | ``Shader``                  |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | CSIn        | ``LocalInvocationIndex`` | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-| SV_GroupIndex             | MSIn        | ``LocalInvocationIndex`` | N/A                   | ``Shader``                  |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | ASIn        | ``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``                |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``PrimitiveId``          | N/A                   | ``MeshShadingNV``           |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | 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``                |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``Layer``                | N/A                   | ``MeshShadingNV``           |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | GSOut       | ``ViewportIndex``        | N/A                   | ``MultiViewport``           |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-| SV_ViewportArrayIndex     | PSIn        | ``ViewportIndex``        | N/A                   | ``MultiViewport``           |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSOut       | ``ViewportIndex``        | N/A                   | ``MeshShadingNV``           |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-|                           | 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``               |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | DSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
-| SV_ViewID                 +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | GSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | PSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
-|                           +-------------+--------------------------+-----------------------+-----------------------------+
-|                           | MSIn        | ``ViewIndex``            | N/A                   | ``MultiView``               |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
-| SV_ShadingRate            | PSIn        | ``FragSizeEXT``          | N/A                   | ``FragmentDensityEXT``      |
-+---------------------------+-------------+--------------------------+-----------------------+-----------------------------+
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+| 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``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``Position``                           | 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``            |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``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``            |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``CullDistance``                       | N/A                   | ``CullDistance``            |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_VertexID               | VSIn        | ``VertexIndex``                        | N/A                   | ``Shader``                  |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_InstanceID             | VSIn        | ``InstanceIndex`` or                   | N/A                   | ``Shader``                  |
+|                           |             | ``InstanceIndex - BaseInstance``       |                       |                             |
+|                           |             | with                                   |                       |                             |
+|                           |             | ``-fvk-support-nonzero-base-instance`` |                       |                             |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+| 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``                  |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | CSIn        | ``GlobalInvocationId``                 | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_DispatchThreadID       | MSIn        | ``GlobalInvocationId``                 | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | ASIn        | ``GlobalInvocationId``                 | N/A                   | ``Shader``                  |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | CSIn        | ``WorkgroupId``                        | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_GroupID                | MSIn        | ``WorkgroupId``                        | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | ASIn        | ``WorkgroupId``                        | N/A                   | ``Shader``                  |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | CSIn        | ``LocalInvocationId``                  | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_GroupThreadID          | MSIn        | ``LocalInvocationId``                  | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | ASIn        | ``LocalInvocationId``                  | N/A                   | ``Shader``                  |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | CSIn        | ``LocalInvocationIndex``               | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_GroupIndex             | MSIn        | ``LocalInvocationIndex``               | N/A                   | ``Shader``                  |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | ASIn        | ``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``                |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``PrimitiveId``                        | N/A                   | ``MeshShadingNV``           |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | 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``                |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``Layer``                              | N/A                   | ``MeshShadingNV``           |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | GSOut       | ``ViewportIndex``                      | N/A                   | ``MultiViewport``           |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_ViewportArrayIndex     | PSIn        | ``ViewportIndex``                      | N/A                   | ``MultiViewport``           |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSOut       | ``ViewportIndex``                      | N/A                   | ``MeshShadingNV``           |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | 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``               |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | DSIn        | ``ViewIndex``                          | N/A                   | ``MultiView``               |
+| SV_ViewID                 +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | GSIn        | ``ViewIndex``                          | N/A                   | ``MultiView``               |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | PSIn        | ``ViewIndex``                          | N/A                   | ``MultiView``               |
+|                           +-------------+----------------------------------------+-----------------------+-----------------------------+
+|                           | MSIn        | ``ViewIndex``                          | N/A                   | ``MultiView``               |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
+| SV_ShadingRate            | PSIn        | ``FragSizeEXT``                        | N/A                   | ``FragmentDensityEXT``      |
++---------------------------+-------------+----------------------------------------+-----------------------+-----------------------------+
 
 For entities (function parameters, function return values, struct fields) with
 the above SV semantic strings attached, SPIR-V variables of the

+ 2 - 0
include/dxc/Support/HLSLOptions.td

@@ -304,6 +304,8 @@ def fvk_invert_y: Flag<["-"], "fvk-invert-y">, Group<spirv_Group>, Flags<[CoreOp
   HelpText<"Negate SV_Position.y before writing to stage output in VS/DS/GS to accommodate Vulkan's coordinate system">;
 def fvk_use_dx_position_w: Flag<["-"], "fvk-use-dx-position-w">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
   HelpText<"Reciprocate SV_Position.w after reading from stage input in PS to accommodate the difference between Vulkan and DirectX">;
+def fvk_support_nonzero_base_instance: Flag<["-"], "fvk-support-nonzero-base-instance">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
+  HelpText<"Follow Vulkan spec to use gl_BaseInstance as the first vertex instance, which makes SV_InstanceID = gl_InstanceIndex - gl_BaseInstance (without this option, SV_InstanceID = gl_InstanceIndex)">;
 def fvk_use_gl_layout: Flag<["-"], "fvk-use-gl-layout">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,
   HelpText<"Use strict OpenGL std140/std430 memory layout for Vulkan resources">;
 def fvk_use_dx_layout: Flag<["-"], "fvk-use-dx-layout">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>,

+ 1 - 0
include/dxc/Support/SPIRVOptions.h

@@ -56,6 +56,7 @@ struct SpirvCodeGenOptions {
   bool useScalarLayout;
   bool flattenResourceArrays;
   bool autoShiftBindings;
+  bool supportNonzeroBaseInstance;
   SpirvLayoutRule cBufferLayoutRule;
   SpirvLayoutRule sBufferLayoutRule;
   SpirvLayoutRule tBufferLayoutRule;

+ 3 - 0
lib/DxcSupport/HLSLOptions.cpp

@@ -794,6 +794,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
   opts.GenSPIRV = Args.hasFlag(OPT_spirv, OPT_INVALID, false);
   opts.SpirvOptions.invertY = Args.hasFlag(OPT_fvk_invert_y, OPT_INVALID, false);
   opts.SpirvOptions.invertW = Args.hasFlag(OPT_fvk_use_dx_position_w, OPT_INVALID, false);
+  opts.SpirvOptions.supportNonzeroBaseInstance =
+      Args.hasFlag(OPT_fvk_support_nonzero_base_instance, OPT_INVALID, false);
   opts.SpirvOptions.useGlLayout = Args.hasFlag(OPT_fvk_use_gl_layout, OPT_INVALID, false);
   opts.SpirvOptions.useDxLayout = Args.hasFlag(OPT_fvk_use_dx_layout, OPT_INVALID, false);
   opts.SpirvOptions.useScalarLayout = Args.hasFlag(OPT_fvk_use_scalar_layout, OPT_INVALID, false);
@@ -885,6 +887,7 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
   if (Args.hasFlag(OPT_spirv, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_invert_y, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_use_dx_position_w, OPT_INVALID, false) ||
+      Args.hasFlag(OPT_fvk_support_nonzero_base_instance, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_use_gl_layout, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_use_dx_layout, OPT_INVALID, false) ||
       Args.hasFlag(OPT_fvk_use_scalar_layout, OPT_INVALID, false) ||

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

@@ -2232,7 +2232,8 @@ bool DeclResultIdMapper::createStageVars(
     //   invocation. BaseInstance is the firstInstance parameter to a direct
     //   drawing command or the firstInstance member of a structure consumed by
     //   an indirect drawing command.
-    if (asInput && semanticKind == hlsl::Semantic::Kind::InstanceID &&
+    if (spirvOptions.supportNonzeroBaseInstance && asInput &&
+        semanticKind == hlsl::Semantic::Kind::InstanceID &&
         sigPointKind == hlsl::SigPoint::Kind::VSIn) {
       // The above call to createSpirvStageVar creates the gl_InstanceIndex.
       // We should now manually create the gl_BaseInstance variable and do the

+ 1 - 9
tools/clang/test/CodeGenSPIRV/semantic.instance-id.vs.hlsl

@@ -2,25 +2,17 @@
 
 // CHECK:                     OpEntryPoint Vertex %main "main"
 // CHECK-SAME:                %gl_InstanceIndex
-// CHECK-SAME:                %gl_BaseInstance
 // CHECK-SAME:                %out_var_SV_InstanceID
 
 // CHECK:                     OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
-// CHECK:                     OpDecorate %gl_BaseInstance BuiltIn BaseInstance
 // CHECK:                     OpDecorate %out_var_SV_InstanceID Location 0
 
 // CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_int Input
-// CHECK:  %gl_BaseInstance = OpVariable %_ptr_Input_int Input
 // CHECK: %out_var_SV_InstanceID = OpVariable %_ptr_Output_int Output
 
 // CHECK:                     %main = OpFunction
-// CHECK:            %SV_InstanceID = OpVariable %_ptr_Function_int Function
 // CHECK: [[gl_InstanceIndex:%\d+]] = OpLoad %int %gl_InstanceIndex
-// CHECK:  [[gl_BaseInstance:%\d+]] = OpLoad %int %gl_BaseInstance
-// CHECK:      [[instance_id:%\d+]] = OpISub %int [[gl_InstanceIndex]] [[gl_BaseInstance]]
-// CHECK:                             OpStore %SV_InstanceID [[instance_id]]
-// CHECK:      [[instance_id:%\d+]] = OpLoad %int %SV_InstanceID
-// CHECK:                             OpStore %param_var_input [[instance_id]]
+// CHECK:                             OpStore %param_var_input [[gl_InstanceIndex]]
 // CHECK:                  {{%\d+}} = OpFunctionCall %int %src_main %param_var_input
 
 int main(int input: SV_InstanceID) : SV_InstanceID {

+ 29 - 0
tools/clang/test/CodeGenSPIRV/semantic.nonzero-base-instance.vs.hlsl

@@ -0,0 +1,29 @@
+// Run: %dxc -T vs_6_0 -E main -fvk-support-nonzero-base-instance
+
+// CHECK:                     OpEntryPoint Vertex %main "main"
+// CHECK-SAME:                %gl_InstanceIndex
+// CHECK-SAME:                %gl_BaseInstance
+// CHECK-SAME:                %out_var_SV_InstanceID
+
+// CHECK:                     OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
+// CHECK:                     OpDecorate %gl_BaseInstance BuiltIn BaseInstance
+// CHECK:                     OpDecorate %out_var_SV_InstanceID Location 0
+
+// CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_int Input
+// CHECK:  %gl_BaseInstance = OpVariable %_ptr_Input_int Input
+// CHECK: %out_var_SV_InstanceID = OpVariable %_ptr_Output_int Output
+
+// CHECK:                     %main = OpFunction
+// CHECK:            %SV_InstanceID = OpVariable %_ptr_Function_int Function
+// CHECK: [[gl_InstanceIndex:%\d+]] = OpLoad %int %gl_InstanceIndex
+// CHECK:  [[gl_BaseInstance:%\d+]] = OpLoad %int %gl_BaseInstance
+// CHECK:      [[instance_id:%\d+]] = OpISub %int [[gl_InstanceIndex]] [[gl_BaseInstance]]
+// CHECK:                             OpStore %SV_InstanceID [[instance_id]]
+// CHECK:      [[instance_id:%\d+]] = OpLoad %int %SV_InstanceID
+// CHECK:                             OpStore %param_var_input [[instance_id]]
+// CHECK:                  {{%\d+}} = OpFunctionCall %int %src_main %param_var_input
+
+int main(int input: SV_InstanceID) : SV_InstanceID {
+    return input;
+}
+

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -658,6 +658,9 @@ TEST_F(FileTest, SemanticVertexIDVS) {
 TEST_F(FileTest, SemanticInstanceIDVS) {
   runFileTest("semantic.instance-id.vs.hlsl");
 }
+TEST_F(FileTest, SemanticNonzeroBaseInstanceVS) {
+  runFileTest("semantic.nonzero-base-instance.vs.hlsl");
+}
 TEST_F(FileTest, SemanticInstanceIDHS) {
   runFileTest("semantic.instance-id.hs.hlsl");
 }