[clang] 77b5878 - [HLSL] Add support for SV_RenderTargetArrayIndex (#237390)

via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 09:48:18 PST 2026


Author: Finn Plummer
Date: 2026-12-01T10:48:10-07:00
New Revision: 77b5878183c1bf813c9b971fba53d5c77bac0c46

URL: https://github.com/llvm/llvm-project/commit/77b5878183c1bf813c9b971fba53d5c77bac0c46
DIFF: https://github.com/llvm/llvm-project/commit/77b5878183c1bf813c9b971fba53d5c77bac0c46.diff

LOG: [HLSL] Add support for SV_RenderTargetArrayIndex (#237390)

Resolves: https://github.com/llvm/llvm-project/issues/136975

Assisted by: Claude Opus 5.5

Added: 
    clang/test/CodeGenHLSL/semantics/SV_RenderTargetArrayIndex.hlsl
    clang/test/SemaHLSL/Semantics/rendertargetarrayindex.stages.hlsl
    clang/test/SemaHLSL/Semantics/rendertargetarrayindex.vs-ps.hlsl
    llvm/test/CodeGen/DirectX/ContainerData/SemanticSignatures-render-target-array-index.ll
    llvm/test/CodeGen/DirectX/Metadata/semantic-signatures-render-target-array-index-errors.ll
    llvm/test/CodeGen/DirectX/ShaderFlags/render-target-array-index.ll
    llvm/test/CodeGen/SPIRV/semantics/layer.ll

Modified: 
    clang/lib/CodeGen/CGHLSLRuntime.cpp
    clang/lib/Sema/SemaHLSL.cpp
    llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
    llvm/lib/Frontend/HLSL/SemanticSignatures.cpp
    llvm/lib/Target/DirectX/DXILShaderFlags.cpp
    llvm/lib/Target/DirectX/DXILSignatureAnalysis.cpp
    llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
    llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
    llvm/test/CodeGen/SPIRV/semantics/viewport-index.ll
    llvm/unittests/Frontend/HLSLSemanticStagesTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5a941f835f5eaf..c9e974d37bd730 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -1893,6 +1893,19 @@ llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
       return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index,
                                       Signature);
     break;
+  case llvm::dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
+    assert(Stage == llvm::Triple::Pixel &&
+           "SV_RenderTargetArrayIndex is not available in this stage and "
+           "should have been diagnosed by Sema");
+    if (CGM.getTarget().getTriple().isSPIRV())
+      return createSPIRVInputLoad(
+          B, CGM.getModule(), Type, Semantic->getAttrName()->getName(),
+          llvm::hlsl::SPIRVInterfaceDecoration::BuiltIn,
+          static_cast<unsigned>(llvm::hlsl::SPIRVBuiltIn::Layer), InterpMode);
+    if (CGM.getTarget().getTriple().isDXIL())
+      return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index,
+                                      Signature);
+    break;
   case llvm::dxbc::PSV::SemanticKind::PrimitiveID:
     assert(Stage == llvm::Triple::Pixel &&
            "SV_PrimitiveID is in an unavailable stage and should have been "
@@ -2061,6 +2074,23 @@ void CGHLSLRuntime::emitSystemSemanticStore(
       return;
     }
     break;
+  case llvm::dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
+    assert(Stage == llvm::Triple::Vertex &&
+           "SV_RenderTargetArrayIndex is not available in this stage and "
+           "should have been diagnosed by Sema");
+    if (CGM.getTarget().getTriple().isDXIL()) {
+      emitDXILUserSemanticStore(B, Source, Decl, Semantic, Index, Signature);
+      return;
+    }
+    if (CGM.getTarget().getTriple().isSPIRV()) {
+      createSPIRVOutputStore(
+          B, CGM.getModule(), Source, Semantic->getAttrName()->getName(),
+          llvm::hlsl::SPIRVInterfaceDecoration::BuiltIn,
+          static_cast<unsigned>(llvm::hlsl::SPIRVBuiltIn::Layer), InterpMode,
+          IsSignedInt);
+      return;
+    }
+    break;
   case llvm::dxbc::PSV::SemanticKind::StencilRef:
     assert(Stage == llvm::Triple::Pixel &&
            "SV_StencilRef is in an unavailable stage and should have been "
@@ -2151,6 +2181,7 @@ static void makeSystemValueSignatureElementsUnsigned(
     case llvm::dxbc::PSV::SemanticKind::StencilRef:
     case llvm::dxbc::PSV::SemanticKind::ViewPortArrayIndex:
     case llvm::dxbc::PSV::SemanticKind::Coverage:
+    case llvm::dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
       if (Element.CompType == llvm::dxil::ElementType::I16)
         Element.CompType = llvm::dxil::ElementType::U16;
       else if (Element.CompType == llvm::dxil::ElementType::I32)

diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 5d84f00ffd74f6..a651b3bcdb89ec 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1034,6 +1034,7 @@ static bool isVkPipelineBuiltin(const ASTContext &AstContext, FunctionDecl *FD,
   case SemanticKind::StencilRef:
     return ST == llvm::Triple::Pixel && !IsInput;
   case SemanticKind::ViewPortArrayIndex:
+  case SemanticKind::RenderTargetArrayIndex:
     return (ST == llvm::Triple::Vertex && !IsInput) ||
            (ST == llvm::Triple::Pixel && IsInput);
   case SemanticKind::Coverage:
@@ -1524,6 +1525,7 @@ void SemaHLSL::diagnoseSemanticType(const Decl *D,
   case SemanticKind::PrimitiveID:
   case SemanticKind::StencilRef:
   case SemanticKind::ViewPortArrayIndex:
+  case SemanticKind::RenderTargetArrayIndex:
     // SPIR-V declares these built-ins as 32-bit integers and converts 16-bit
     // declarations.
     if (!DeclaredTy->isScalarType() || !isIntUpTo32Element(Ctx, DeclaredTy))
@@ -2392,7 +2394,6 @@ void SemaHLSL::handleSemanticAttr(Decl *D, const ParsedAttr &AL) {
 
   switch (Kind) {
   // FIXME: These semantics do not yet have CodeGen support.
-  case SemanticKind::RenderTargetArrayIndex:
   case SemanticKind::ClipDistance:
   case SemanticKind::CullDistance:
   case SemanticKind::OutputControlPointID:

diff  --git a/clang/test/CodeGenHLSL/semantics/SV_RenderTargetArrayIndex.hlsl b/clang/test/CodeGenHLSL/semantics/SV_RenderTargetArrayIndex.hlsl
new file mode 100644
index 00000000000000..838f6002a8ff11
--- /dev/null
+++ b/clang/test/CodeGenHLSL/semantics/SV_RenderTargetArrayIndex.hlsl
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-DXIL
+// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-library -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV
+// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-library -emit-llvm -finclude-default-header -fnative-half-type -fnative-int16-type -disable-llvm-passes -DINT16 -o - %s | FileCheck %s --check-prefix=SPIRV16
+
+#ifdef INT16
+#define OUT_TYPE int16_t
+#define IN_TYPE uint16_t
+#else
+#define OUT_TYPE int
+#define IN_TYPE uint
+#endif
+
+struct VSOut {
+  float4 Pos : SV_Position;
+  OUT_TYPE Layer : SV_RenderTargetArrayIndex;
+};
+
+// The vertex shader writes the render-target array index as a system value.
+// Its own input with the same name is an arbitrary semantic, which keeps its
+// declared signed type.
+[shader("vertex")]
+VSOut vs_main(int In : SV_RenderTargetArrayIndex) {
+  VSOut O;
+  O.Pos = 0;
+  O.Layer = In + 1;
+  return O;
+}
+
+[shader("pixel")]
+float4 ps_main(float4 Pos : SV_Position, IN_TYPE Layer : SV_RenderTargetArrayIndex)
+    : SV_Target {
+  return Pos * Layer;
+}
+
+// CHECK-DXIL-LABEL: define void @vs_main()
+// CHECK-DXIL: call i32 @llvm.dx.load.input.i32(i32 0, i32 0, i8 0, i32 poison)
+// CHECK-DXIL: call void @llvm.dx.store.output.v4f32(i32 0, i32 0, i8 0,
+// CHECK-DXIL: call void @llvm.dx.store.output.i32(i32 1, i32 0, i8 0,
+// CHECK-DXIL-LABEL: define void @ps_main()
+// CHECK-DXIL: call <4 x float> @llvm.dx.load.input.v4f32(i32 0, i32 0, i8 0, i32 poison)
+// CHECK-DXIL: call i32 @llvm.dx.load.input.i32(i32 1, i32 0, i8 0, i32 poison)
+
+// The vertex input is a signed (4), arbitrary (kind 0) element. The output and
+// the pixel input are unsigned (5), nointerpolation (1) RenderTargetArrayIndex
+// (kind 4) elements, even though the output is declared as int.
+// CHECK-DXIL-DAG: !{ptr @vs_main, ![[#VS_IN:]], ![[#VS_OUT:]]}
+// CHECK-DXIL-DAG: ![[#VS_IN]] = !{![[#VS_IN_VP:]]}
+// CHECK-DXIL-DAG: ![[#VS_IN_VP]] = !{i32 0, !"SV_RenderTargetArrayIndex", i32 4, i32 0, ![[#ZERO:]], i32 0, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+// CHECK-DXIL-DAG: ![[#VS_OUT]] = !{![[#VS_OUT_POS:]], ![[#VS_OUT_VP:]]}
+// CHECK-DXIL-DAG: ![[#VS_OUT_VP]] = !{i32 1, !"SV_RenderTargetArrayIndex", i32 5, i32 4, ![[#ZERO]], i32 1, i32 1, i8 1, i32 1, i8 0, i8 0, i8 0, i32 0}
+// The pixel input signature is identical to the vertex output signature.
+// CHECK-DXIL-DAG: !{ptr @ps_main, ![[#VS_OUT]], ![[#PS_OUT:]]}
+// CHECK-DXIL-DAG: ![[#ZERO]] = !{i32 0}
+
+// CHECK-SPIRV-DAG: @SV_RenderTargetArrayIndex0 = {{.*}} addrspace(7) {{.*}} i32, !spirv.Decorations ![[#VS_IN_LOC:]]
+// CHECK-SPIRV-DAG: @SV_RenderTargetArrayIndex = {{.*}} addrspace(8) global i32, !spirv.Decorations ![[#VS_OUT_BUILTIN:]]
+// The pixel input has the same flat Layer decorations as the output.
+// CHECK-SPIRV-DAG: @SV_RenderTargetArrayIndex.{{[0-9]+}} = {{.*}} addrspace(7) {{.*}} i32, !spirv.Decorations ![[#VS_OUT_BUILTIN]]
+// CHECK-SPIRV-DAG: ![[#VS_OUT_BUILTIN]] = !{![[#LAYER:]], ![[#FLAT:]]}
+// CHECK-SPIRV-DAG: ![[#LAYER]] = !{i32 11, i32 9}
+//                                        |       `-> BuiltIn Layer
+//                                        `-> SPIR-V decoration 'BuiltIn'
+// CHECK-SPIRV-DAG: ![[#FLAT]] = !{i32 14}
+
+// The SPIR-V built-in is a 32-bit integer, so a signed 16-bit output is sign
+// extended and a 16-bit input is truncated.
+// SPIRV16-LABEL: define void @vs_main()
+// SPIRV16: %[[OUT:.*]] = sext i16 %{{.*}} to i32
+// SPIRV16: store i32 %[[OUT]], ptr addrspace(8) @SV_RenderTargetArrayIndex
+// SPIRV16-LABEL: define void @ps_main()
+// SPIRV16: %[[IN:.*]] = load i32, ptr addrspace(7) @SV_RenderTargetArrayIndex.{{[0-9]+}}
+// SPIRV16: trunc i32 %[[IN]] to i16

diff  --git a/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.stages.hlsl b/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.stages.hlsl
new file mode 100644
index 00000000000000..dbc6cceb6c894d
--- /dev/null
+++ b/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.stages.hlsl
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-library -finclude-default-header -verify -o - %s
+// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-library -finclude-default-header -verify -o - %s
+
+// Stage and IO direction checks for SV_RenderTargetArrayIndex: a vertex output
+// and a pixel input. Type, index and interpolation checks are covered by
+// rendertargetarrayindex.vs-ps.hlsl.
+
+struct VSOut {
+  float4 p : SV_Position;
+  uint i : SV_RenderTargetArrayIndex;
+};
+
+[shader("vertex")]
+VSOut ok_vs_out() { return (VSOut)0; }
+
+// The render-target array index can be the only vertex output, without
+// SV_Position.
+[shader("vertex")]
+uint ok_vs_out_only(uint i : IDX) : SV_RenderTargetArrayIndex { return i; }
+
+[shader("pixel")]
+float4 ok_ps_in(uint i : SV_RenderTargetArrayIndex) : SV_Target {
+  return float4((float)i, 0, 0, 1);
+}
+
+// A vertex input with this name is an arbitrary semantic, so any type works.
+[shader("vertex")]
+float4 ok_vs_in_arbitrary(float4 i : SV_RenderTargetArrayIndex) : SV_Position {
+  return i;
+}
+
+[shader("pixel")]
+uint bad_ps_out() : SV_RenderTargetArrayIndex { return 0; }
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' is not supported in pixel shader outputs}}
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void bad_cs_in(uint i : SV_RenderTargetArrayIndex) {}
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' is not supported in compute shader inputs}}

diff  --git a/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.vs-ps.hlsl b/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.vs-ps.hlsl
new file mode 100644
index 00000000000000..878a9a18b21e02
--- /dev/null
+++ b/clang/test/SemaHLSL/Semantics/rendertargetarrayindex.vs-ps.hlsl
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-library -fnative-half-type -fnative-int16-type -finclude-default-header -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-library -fnative-half-type -fnative-int16-type -finclude-default-header -fsyntax-only -verify %s
+
+// Type, index and interpolation checks for SV_RenderTargetArrayIndex on vertex
+// outputs and pixel inputs. These are independent of the shader stage and IO
+// direction, which are covered by rendertargetarrayindex.stages.hlsl.
+
+struct VSOut {
+  float4 p : SV_Position;
+  uint vp : SV_RenderTargetArrayIndex;
+};
+[shader("vertex")]
+VSOut vertex_output() { return (VSOut)0; }
+[shader("vertex")]
+int vertex_return() : sv_rendertargetarrayindex0 { return 0; }
+[shader("pixel")]
+void pixel_input(uint vp : SV_RenderTargetArrayIndex) {}
+
+// 16-bit integers are allowed. SPIR-V converts them to and from the 32-bit
+// built-in.
+[shader("pixel")]
+void uint16(uint16_t vp : SV_RenderTargetArrayIndex) {}
+
+[shader("pixel")]
+void bad_float(float vp : SV_RenderTargetArrayIndex) {}
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' must be a scalar of 16 or 32 bit integer type (was 'float')}}
+[shader("vertex")]
+uint2 bad_vector() : SV_RenderTargetArrayIndex { return 0; }
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' must be a scalar of 16 or 32 bit integer type (was 'uint2' (aka 'vector<uint, 2>'))}}
+[shader("pixel")]
+void bad_bool(bool vp : SV_RenderTargetArrayIndex) {}
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' must be a scalar of 16 or 32 bit integer type (was 'bool')}}
+
+[shader("pixel")]
+void bad_index(uint vp : SV_RenderTargetArrayIndex1) {}
+// expected-error at -1 {{semantic 'SV_RenderTargetArrayIndex' does not allow indexing}}
+
+// Integer inputs can only use nointerpolation.
+[shader("pixel")]
+void bad_interpolation(linear uint vp : SV_RenderTargetArrayIndex) {}
+// expected-error at -1 {{interpolation modifiers other than 'nointerpolation' cannot be used with type 'uint' (aka 'unsigned int')}}

diff  --git a/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h b/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
index 3965535db8d910..9722ae3f75eca9 100644
--- a/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
+++ b/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
@@ -84,6 +84,7 @@ enum class SPIRVInterfaceDecoration : uint32_t {
 // SPIR-V BuiltIn enumerants used as the operand of a BuiltIn decoration. The
 // values match the SPIR-V specification.
 enum class SPIRVBuiltIn : uint32_t {
+  Layer = 9,
   ViewportIndex = 10,
   SampleMask = 20,
 };

diff  --git a/llvm/lib/Frontend/HLSL/SemanticSignatures.cpp b/llvm/lib/Frontend/HLSL/SemanticSignatures.cpp
index 656b8091418e2c..ab0102b515baf2 100644
--- a/llvm/lib/Frontend/HLSL/SemanticSignatures.cpp
+++ b/llvm/lib/Frontend/HLSL/SemanticSignatures.cpp
@@ -178,6 +178,7 @@ hlsl::getAvailableStages(dxbc::PSV::SemanticKind SemanticKind) {
         {Triple::Vertex, IOType::In, SemanticInterpretation::NotAllocated}};
     return Stages;
   }
+  case dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
   case dxbc::PSV::SemanticKind::ViewPortArrayIndex: {
     static constexpr SemanticStageInfo Stages[] = {
         {Triple::Vertex, IOType::In, SemanticInterpretation::Arbitrary},

diff  --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
index 9112ebaa11a367..33333e3fe301e2 100644
--- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
+++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp
@@ -492,7 +492,9 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
           CSF.ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer |=
               llvm::any_of(Sig->Outputs, [](const auto &E) {
                 return E.SemanticKind ==
-                       dxbc::PSV::SemanticKind::ViewPortArrayIndex;
+                           dxbc::PSV::SemanticKind::ViewPortArrayIndex ||
+                       E.SemanticKind ==
+                           dxbc::PSV::SemanticKind::RenderTargetArrayIndex;
               });
         // Unallocated elements do not occupy signature registers. Their type
         // requirements come from the instructions that access them.

diff  --git a/llvm/lib/Target/DirectX/DXILSignatureAnalysis.cpp b/llvm/lib/Target/DirectX/DXILSignatureAnalysis.cpp
index 28eae037806325..683a42a466be22 100644
--- a/llvm/lib/Target/DirectX/DXILSignatureAnalysis.cpp
+++ b/llvm/lib/Target/DirectX/DXILSignatureAnalysis.cpp
@@ -135,6 +135,12 @@ static Error diagnoseSemanticType(const SemanticSignatureElement &E) {
       return signatureError("SV_ViewportArrayIndex requires a scalar 16- or "
                             "32-bit unsigned integer");
     break;
+  case dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
+    if (E.Rows != 1 || E.Cols != 1 ||
+        (E.CompType != ElementType::U16 && E.CompType != ElementType::U32))
+      return signatureError("SV_RenderTargetArrayIndex requires a scalar 16- "
+                            "or 32-bit unsigned integer");
+    break;
   case dxbc::PSV::SemanticKind::Barycentrics:
     if (E.Rows != 1 || E.Cols != 3 ||
         (E.CompType != ElementType::F16 && E.CompType != ElementType::F32))
@@ -186,6 +192,11 @@ static Error diagnoseSemanticIndex(const SemanticSignatureElement &E) {
     if (E.SemanticIndices.front() != 0)
       return signatureError("SV_ViewportArrayIndex requires semantic index 0");
     break;
+  case dxbc::PSV::SemanticKind::RenderTargetArrayIndex:
+    if (E.SemanticIndices.front() != 0)
+      return signatureError(
+          "SV_RenderTargetArrayIndex requires semantic index 0");
+    break;
   default:
     break;
   }
@@ -612,6 +623,8 @@ static dxbc::D3DSystemValue getSystemValue(dxbc::PSV::SemanticKind Kind) {
     return dxbc::D3DSystemValue::ViewPortArrayIndex;
   case KindTy::Coverage:
     return dxbc::D3DSystemValue::Coverage;
+  case KindTy::RenderTargetArrayIndex:
+    return dxbc::D3DSystemValue::RenderTargetArrayIndex;
   default:
     llvm_unreachable("validated vertex/pixel signature semantic");
   }
@@ -654,6 +667,8 @@ static StringRef getContainerSemanticName(const SemanticSignatureElement &E) {
     return "SV_ViewportArrayIndex";
   case Kind::Coverage:
     return "SV_Coverage";
+  case Kind::RenderTargetArrayIndex:
+    return "SV_RenderTargetArrayIndex";
   default:
     llvm_unreachable("validated vertex/pixel signature semantic");
   }

diff  --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 844f82836d1246..67b4ed780f84b7 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -1128,8 +1128,8 @@ void RequirementHandler::initAvailableCapabilitiesForVulkan(
   // Became core in Vulkan 1.2
   if (ST.isAtLeastSPIRVVer(VersionTuple(1, 5))) {
     addAvailableCaps(
-        {Capability::Int64Atomics, Capability::ShaderNonUniformEXT,
-         Capability::RuntimeDescriptorArrayEXT,
+        {Capability::Int64Atomics, Capability::ShaderLayer,
+         Capability::ShaderNonUniformEXT, Capability::RuntimeDescriptorArrayEXT,
          Capability::InputAttachmentArrayDynamicIndexingEXT,
          Capability::UniformTexelBufferArrayDynamicIndexingEXT,
          Capability::StorageTexelBufferArrayDynamicIndexingEXT,
@@ -1183,8 +1183,9 @@ static bool isDecoratingOutputVariable(const MachineInstr &MI) {
 
 // Returns true if the module containing MI has an HLSL vertex, hull or
 // domain shader entry point. Outputs of these stages need
-// ShaderViewportIndexLayerEXT to write ViewportIndex or Layer, while a geometry
-// shader writes them with the base MultiViewport capability.
+// ShaderViewportIndexLayerEXT (or ShaderLayer for Layer from SPIR-V 1.5) to
+// write ViewportIndex or Layer, while a geometry shader writes them with the
+// base MultiViewport or Geometry capability.
 static bool hasVertexOrTessellationEntryPoint(const MachineInstr &MI) {
   return llvm::any_of(
       *MI.getMF()->getFunction().getParent(), [](const Function &F) {
@@ -1241,14 +1242,23 @@ static void addOpDecorateReqs(const MachineInstr &MI, unsigned DecIndex,
                                  SPIRV::Extension::SPV_KHR_multiview);
       break;
     case SPIRV::BuiltIn::ViewportIndex:
+    case SPIRV::BuiltIn::Layer:
       // Only vertex and tessellation outputs need the extension. Geometry
-      // outputs and fragment inputs use the base MultiViewport capability.
+      // outputs and fragment inputs use the base MultiViewport (ViewportIndex)
+      // or Geometry (Layer) capability.
       if (isDecoratingOutputVariable(MI) &&
           hasVertexOrTessellationEntryPoint(MI)) {
+        // SPIR-V 1.5 promoted writing Layer from these stages to the core
+        // ShaderLayer capability, which does not need the extension.
+        if (BuiltIn == SPIRV::BuiltIn::Layer &&
+            ST.isAtLeastSPIRVVer(VersionTuple(1, 5))) {
+          Reqs.addCapability(SPIRV::Capability::ShaderLayer);
+          break;
+        }
         if (!ST.canUseExtension(
                 SPIRV::Extension::SPV_EXT_shader_viewport_index_layer))
           report_fatal_error(
-              "Writing ViewportIndex requires the following SPIR-V "
+              "Writing ViewportIndex or Layer requires the following SPIR-V "
               "extension: SPV_EXT_shader_viewport_index_layer",
               false);
         Reqs.addCapability(SPIRV::Capability::ShaderViewportIndexLayerEXT);

diff  --git a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
index ed2032aa15c954..2004cde7e29958 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
+++ b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
@@ -510,6 +510,7 @@ defm GroupNonUniformShuffle : CapabilityOperand<65, 0x10300, 0, [], [GroupNonUni
 defm GroupNonUniformShuffleRelative : CapabilityOperand<66, 0x10300, 0, [], [GroupNonUniform]>;
 defm GroupNonUniformClustered : CapabilityOperand<67, 0x10300, 0, [], [GroupNonUniform]>;
 defm GroupNonUniformQuad : CapabilityOperand<68, 0x10300, 0, [], [GroupNonUniform]>;
+defm ShaderLayer : CapabilityOperand<69, 0x10500, 0, [], []>;
 defm FragmentShadingRateKHR : CapabilityOperand<4422, 0, 0, [SPV_KHR_fragment_shading_rate], [Shader]>;
 defm SubgroupBallotKHR : CapabilityOperand<4423, 0, 0, [SPV_KHR_shader_ballot], []>;
 defm DrawParameters : CapabilityOperand<4427, 0x10300, 0, [SPV_KHR_shader_draw_parameters], [Shader]>;

diff  --git a/llvm/test/CodeGen/DirectX/ContainerData/SemanticSignatures-render-target-array-index.ll b/llvm/test/CodeGen/DirectX/ContainerData/SemanticSignatures-render-target-array-index.ll
new file mode 100644
index 00000000000000..3a70c52af99260
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/SemanticSignatures-render-target-array-index.ll
@@ -0,0 +1,40 @@
+; RUN: llc -filetype=obj %s -o %t.dxbc
+; RUN: obj2yaml %t.dxbc | FileCheck %s --check-prefix=PARTS
+; RUN: llvm-objcopy --dump-section=DXIL=%t.bc %t.dxbc
+; RUN: llvm-dis %t.bc -o - | FileCheck %s --check-prefix=MD
+
+; A vertex shader writing SV_RenderTargetArrayIndex feeds the rasterizer, which
+; requires the ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer feature.
+target triple = "dxil-pc-shadermodel6.0-vertex"
+
+define void @main() #0 {
+  %p = call <4 x float> @llvm.dx.load.input.v4f32(i32 0, i32 0, i8 0, i32 poison)
+  call void @llvm.dx.store.output.v4f32(i32 0, i32 0, i8 0, <4 x float> %p)
+  call void @llvm.dx.store.output.i32(i32 1, i32 0, i8 0, i32 1)
+  ret void
+}
+attributes #0 = { "hlsl.shader"="vertex" }
+
+!dx.valver = !{!10}
+!10 = !{i32 1, i32 8}
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, !1, !2}
+!1 = !{!3}
+!2 = !{!4, !5}
+!3 = !{i32 0, !"POSITION", i32 9, i32 0, !7, i32 0, i32 1, i8 4, i32 0, i8 0, i8 0, i8 0, i32 0}
+!4 = !{i32 0, !"SV_Position", i32 9, i32 3, !7, i32 4, i32 1, i8 4, i32 0, i8 0, i8 0, i8 0, i32 0}
+!5 = !{i32 1, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !7, i32 1, i32 1, i8 1, i32 1, i8 0, i8 0, i8 0, i32 0}
+!7 = !{i32 0}
+
+; MD-DAG: !{i32 1, !"SV_RenderTargetArrayIndex", i8 5, i8 4, !{{[0-9]+}}, i8 1, i32 1, i8 1, i32 1, i8 0, !{{[0-9]+}}}
+; MD-DAG: !{i32 0, i64 512}
+
+; PARTS: Name: SFI0
+; PARTS: ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer: true
+; PARTS: Name: OSG1
+; PARTS:      Name: SV_RenderTargetArrayIndex
+; PARTS-NEXT: Index: 0
+; PARTS-NEXT: SystemValue: RenderTargetArrayIndex
+; PARTS-NEXT: CompType: UInt32
+; PARTS-NEXT: Register: 1
+; PARTS-NEXT: Mask: 1

diff  --git a/llvm/test/CodeGen/DirectX/Metadata/semantic-signatures-render-target-array-index-errors.ll b/llvm/test/CodeGen/DirectX/Metadata/semantic-signatures-render-target-array-index-errors.ll
new file mode 100644
index 00000000000000..d840e49e0c97fa
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/Metadata/semantic-signatures-render-target-array-index-errors.ll
@@ -0,0 +1,65 @@
+; RUN: split-file %s %t
+; RUN: not opt -disable-output -passes=dxil-translate-metadata %t/signed.ll 2>&1 | FileCheck %s --check-prefix=CHECK-SIGNED
+; RUN: not opt -disable-output -passes=dxil-translate-metadata %t/cols.ll 2>&1 | FileCheck %s --check-prefix=CHECK-COLS
+; RUN: not opt -disable-output -passes=dxil-translate-metadata %t/index.ll 2>&1 | FileCheck %s --check-prefix=CHECK-INDEX
+; RUN: not opt -disable-output -passes=dxil-translate-metadata %t/kind.ll 2>&1 | FileCheck %s --check-prefix=CHECK-KIND
+; RUN: not opt -disable-output -passes=dxil-translate-metadata %t/output.ll 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUT
+
+; Each case is a complete module with one invalid SV_RenderTargetArrayIndex
+; declaration.
+
+;--- signed.ll
+; CHECK-SIGNED: SV_RenderTargetArrayIndex requires a scalar 16- or 32-bit unsigned integer
+target triple = "dxil-pc-shadermodel6.0-pixel"
+define void @main() #0 { ret void }
+attributes #0 = { "hlsl.shader"="pixel" }
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, !1, null}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 4, i32 4, !3, i32 1, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{i32 0}
+
+;--- cols.ll
+; CHECK-COLS: SV_RenderTargetArrayIndex requires a scalar 16- or 32-bit unsigned integer
+target triple = "dxil-pc-shadermodel6.0-pixel"
+define void @main() #0 { ret void }
+attributes #0 = { "hlsl.shader"="pixel" }
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, !1, null}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !3, i32 1, i32 1, i8 2, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{i32 0}
+
+;--- index.ll
+; CHECK-INDEX: SV_RenderTargetArrayIndex requires semantic index 0
+target triple = "dxil-pc-shadermodel6.0-pixel"
+define void @main() #0 { ret void }
+attributes #0 = { "hlsl.shader"="pixel" }
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, !1, null}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !3, i32 1, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{i32 1}
+
+;--- kind.ll
+; A vertex input with this name is an arbitrary semantic.
+; CHECK-KIND: semantic name and kind disagree at this signature point
+target triple = "dxil-pc-shadermodel6.0-vertex"
+define void @main() #0 { ret void }
+attributes #0 = { "hlsl.shader"="vertex" }
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, !1, null}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !3, i32 0, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{i32 0}
+
+;--- output.ll
+; CHECK-OUTPUT: invalid or unsupported semantic for this stage and signature category
+target triple = "dxil-pc-shadermodel6.0-pixel"
+define void @main() #0 { ret void }
+attributes #0 = { "hlsl.shader"="pixel" }
+!dx.semantic.signatures = !{!0}
+!0 = !{ptr @main, null, !1}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !3, i32 0, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{i32 0}

diff  --git a/llvm/test/CodeGen/DirectX/ShaderFlags/render-target-array-index.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/render-target-array-index.ll
new file mode 100644
index 00000000000000..ce115a5b8334f6
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ShaderFlags/render-target-array-index.ll
@@ -0,0 +1,31 @@
+; RUN: opt -disable-output -passes=print-dx-shader-flags %s 2>&1 | FileCheck %s
+
+; Writing SV_RenderTargetArrayIndex from a vertex shader requires the
+; ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer feature. Reading it in
+; a pixel shader does not.
+
+target triple = "dxil-pc-shadermodel6.0-library"
+
+; CHECK: ; Shader Flags Value: [[FLAG:0x00000200]]
+; CHECK: ; Note: shader requires additional functionality:
+; CHECK-NEXT: ;       SV_RenderTargetArrayIndex or SV_ViewportArrayIndex from any shader feeding rasterizer
+; CHECK: Function vertex : [[FLAG]]
+; CHECK: Function pixel : 0x00000000
+define void @vertex() #0 {
+entry:
+  ret void
+}
+define void @pixel() #1 {
+entry:
+  ret void
+}
+attributes #0 = { "hlsl.shader"="vertex" }
+attributes #1 = { "hlsl.shader"="pixel" }
+
+!dx.semantic.signatures = !{!0, !3}
+!0 = !{ptr @vertex, null, !1}
+!1 = !{!2}
+!2 = !{i32 0, !"SV_RenderTargetArrayIndex", i32 5, i32 4, !5, i32 1, i32 1, i8 1, i32 0, i8 0, i8 0, i8 0, i32 0}
+!3 = !{ptr @pixel, !4, null}
+!4 = !{!2}
+!5 = !{i32 0}

diff  --git a/llvm/test/CodeGen/SPIRV/semantics/layer.ll b/llvm/test/CodeGen/SPIRV/semantics/layer.ll
new file mode 100644
index 00000000000000..b230bfdf89d6af
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/semantics/layer.ll
@@ -0,0 +1,94 @@
+; RUN: split-file %s %t
+; An unversioned spirv triple targets SPIR-V 1.4, where writing Layer from a
+; vertex shader needs SPV_EXT_shader_viewport_index_layer.
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan1.3-vertex -spirv-ext=+SPV_EXT_shader_viewport_index_layer %t/vertex.ll -o - | FileCheck %s --check-prefix=VS
+; RUN: not llc -O0 -mtriple=spirv-unknown-vulkan1.3-vertex %t/vertex.ll -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERROR
+; SPIR-V 1.5 promoted it to the core ShaderLayer capability, so the extension is
+; not used even when it is available.
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.5-unknown-vulkan1.2-vertex %t/vertex.ll -o - | FileCheck %s --check-prefix=VS-CORE --implicit-check-not=OpExtension --implicit-check-not=ShaderViewportIndexLayerEXT
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-unknown-vulkan1.3-vertex -spirv-ext=+SPV_EXT_shader_viewport_index_layer %t/vertex.ll -o - | FileCheck %s --check-prefix=VS-CORE --implicit-check-not=OpExtension --implicit-check-not=ShaderViewportIndexLayerEXT
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan1.3-pixel %t/pixel.ll -o - | FileCheck %s --check-prefix=PS --implicit-check-not=OpExtension
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan1.3-library %t/no-vertex.ll -o - | FileCheck %s --check-prefix=NOVS --implicit-check-not=OpExtension --implicit-check-not=ShaderViewportIndexLayerEXT
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan1.3-vertex -spirv-ext=+SPV_EXT_shader_viewport_index_layer %t/vertex.ll -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.5-unknown-vulkan1.2-vertex %t/vertex.ll -o - -filetype=obj | spirv-val --target-env vulkan1.2 %}
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-vertex %t/vertex.ll -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %t/pixel.ll -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
+
+; SV_RenderTargetArrayIndex is lowered to the Layer built-in. Writing it
+; from a vertex shader requires ShaderViewportIndexLayerEXT before SPIR-V 1.5
+; and ShaderLayer from SPIR-V 1.5, while reading it in a fragment shader
+; requires Geometry.
+
+; VS-DAG: OpCapability ShaderViewportIndexLayerEXT
+; VS-DAG: OpExtension "SPV_EXT_shader_viewport_index_layer"
+; VS-DAG: OpDecorate %[[#LAYER:]] BuiltIn Layer
+; VS-DAG: %[[#LAYER]] = OpVariable %[[#]] Output
+; ERROR: LLVM ERROR: Writing ViewportIndex or Layer requires the following SPIR-V extension: SPV_EXT_shader_viewport_index_layer
+
+; VS-CORE-DAG: OpCapability ShaderLayer
+; VS-CORE-DAG: OpDecorate %[[#LAYER:]] BuiltIn Layer
+; VS-CORE-DAG: %[[#LAYER]] = OpVariable %[[#]] Output
+
+; PS-DAG: OpCapability Geometry
+; PS-DAG: OpDecorate %[[#LAYER:]] BuiltIn Layer
+; PS-DAG: OpDecorate %[[#LAYER]] Flat
+; PS-DAG: %[[#LAYER]] = OpVariable %[[#]] Input
+
+; Only vertex and tessellation outputs need ShaderViewportIndexLayerEXT. Any
+; other writer, such as a geometry shader, uses Geometry. Geometry entry points
+; are not supported by the backend yet, so this writes it from a function in a
+; module without a vertex or tessellation entry point.
+; NOVS-DAG: OpCapability Geometry
+; NOVS-DAG: OpDecorate %[[#LAYER:]] BuiltIn Layer
+; NOVS-DAG: %[[#LAYER]] = OpVariable %[[#]] Output
+
+;--- vertex.ll
+ at SV_Position = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations !0
+ at SV_RenderTargetArrayIndex = external hidden thread_local addrspace(8) global i32, !spirv.Decorations !2
+
+define void @main() #0 {
+entry:
+  store <4 x float> zeroinitializer, ptr addrspace(8) @SV_Position, align 16
+  store i32 1, ptr addrspace(8) @SV_RenderTargetArrayIndex, align 4
+  ret void
+}
+
+attributes #0 = { "hlsl.shader"="vertex" }
+
+!0 = !{!1}
+!1 = !{i32 11, i32 0}
+!2 = !{!3, !4}
+!3 = !{i32 11, i32 9}
+!4 = !{i32 14}
+
+;--- pixel.ll
+ at SV_RenderTargetArrayIndex = external hidden thread_local addrspace(7) externally_initialized constant i32, !spirv.Decorations !0
+ at SV_Target0 = external hidden thread_local addrspace(8) global float, !spirv.Decorations !3
+
+define void @main() #0 {
+entry:
+  %0 = load i32, ptr addrspace(7) @SV_RenderTargetArrayIndex, align 4
+  %1 = uitofp i32 %0 to float
+  store float %1, ptr addrspace(8) @SV_Target0, align 4
+  ret void
+}
+
+attributes #0 = { "hlsl.shader"="pixel" }
+
+!0 = !{!1, !2}
+!1 = !{i32 11, i32 9}
+!2 = !{i32 14}
+!3 = !{!4}
+!4 = !{i32 30, i32 0}
+
+;--- no-vertex.ll
+ at SV_RenderTargetArrayIndex = external hidden thread_local addrspace(8) global i32, !spirv.Decorations !0
+
+define void @write_layer() {
+entry:
+  store i32 1, ptr addrspace(8) @SV_RenderTargetArrayIndex, align 4
+  ret void
+}
+
+!0 = !{!1}
+!1 = !{i32 11, i32 9}

diff  --git a/llvm/test/CodeGen/SPIRV/semantics/viewport-index.ll b/llvm/test/CodeGen/SPIRV/semantics/viewport-index.ll
index c0439fa1faa156..ae0e6a141b9173 100644
--- a/llvm/test/CodeGen/SPIRV/semantics/viewport-index.ll
+++ b/llvm/test/CodeGen/SPIRV/semantics/viewport-index.ll
@@ -14,7 +14,7 @@
 ; VS-DAG: OpExtension "SPV_EXT_shader_viewport_index_layer"
 ; VS-DAG: OpDecorate %[[#VP:]] BuiltIn ViewportIndex
 ; VS-DAG: %[[#VP]] = OpVariable %[[#]] Output
-; ERROR: LLVM ERROR: Writing ViewportIndex requires the following SPIR-V extension: SPV_EXT_shader_viewport_index_layer
+; ERROR: LLVM ERROR: Writing ViewportIndex or Layer requires the following SPIR-V extension: SPV_EXT_shader_viewport_index_layer
 
 ; PS-DAG: OpCapability MultiViewport
 ; PS-DAG: OpDecorate %[[#VP:]] BuiltIn ViewportIndex

diff  --git a/llvm/unittests/Frontend/HLSLSemanticStagesTest.cpp b/llvm/unittests/Frontend/HLSLSemanticStagesTest.cpp
index 7113f49f6a689a..5cb9e0b31dcec0 100644
--- a/llvm/unittests/Frontend/HLSLSemanticStagesTest.cpp
+++ b/llvm/unittests/Frontend/HLSLSemanticStagesTest.cpp
@@ -59,30 +59,32 @@ constexpr Triple::EnvironmentType AllStages[] = {
     Triple::Amplification, Triple::Mesh,  Triple::Library};
 
 // The semantic kinds getAvailableStages knows about.
-constexpr SemanticKind SupportedKinds[] = {SemanticKind::Arbitrary,
-                                           SemanticKind::Position,
-                                           SemanticKind::VertexID,
-                                           SemanticKind::Target,
-                                           SemanticKind::IsFrontFace,
-                                           SemanticKind::ClipDistance,
-                                           SemanticKind::CullDistance,
-                                           SemanticKind::TessFactor,
-                                           SemanticKind::InsideTessFactor,
-                                           SemanticKind::DispatchThreadID,
-                                           SemanticKind::GroupID,
-                                           SemanticKind::GroupIndex,
-                                           SemanticKind::GroupThreadID,
-                                           SemanticKind::InstanceID,
-                                           SemanticKind::ShadingRate,
-                                           SemanticKind::Barycentrics,
-                                           SemanticKind::StartVertexLocation,
-                                           SemanticKind::StartInstanceLocation,
-                                           SemanticKind::SampleIndex,
-                                           SemanticKind::ViewID,
-                                           SemanticKind::PrimitiveID,
-                                           SemanticKind::StencilRef,
-                                           SemanticKind::ViewPortArrayIndex,
-                                           SemanticKind::Coverage};
+constexpr SemanticKind SupportedKinds[] = {
+    SemanticKind::Arbitrary,
+    SemanticKind::Position,
+    SemanticKind::VertexID,
+    SemanticKind::Target,
+    SemanticKind::IsFrontFace,
+    SemanticKind::ClipDistance,
+    SemanticKind::CullDistance,
+    SemanticKind::TessFactor,
+    SemanticKind::InsideTessFactor,
+    SemanticKind::DispatchThreadID,
+    SemanticKind::GroupID,
+    SemanticKind::GroupIndex,
+    SemanticKind::GroupThreadID,
+    SemanticKind::InstanceID,
+    SemanticKind::ShadingRate,
+    SemanticKind::Barycentrics,
+    SemanticKind::StartVertexLocation,
+    SemanticKind::StartInstanceLocation,
+    SemanticKind::SampleIndex,
+    SemanticKind::ViewID,
+    SemanticKind::PrimitiveID,
+    SemanticKind::StencilRef,
+    SemanticKind::ViewPortArrayIndex,
+    SemanticKind::Coverage,
+    SemanticKind::RenderTargetArrayIndex};
 
 // Ensure all stages return a valid SemanticInterpretation
 TEST(HLSLSemanticStagesTest, StagesAreValid) {
@@ -278,4 +280,15 @@ TEST(HLSLSemanticStagesTest, CoverageSignaturePoints) {
   expectOnlySignaturePoints(SemanticKind::Coverage, Valid);
 }
 
+// SV_RenderTargetArrayIndex is written by the vertex shader and read by the
+// pixel shader. A vertex input with this name is an arbitrary semantic.
+TEST(HLSLSemanticStagesTest, RenderTargetArrayIndexSignaturePoints) {
+  const SignaturePoint Valid[] = {
+      {Triple::Vertex, IOType::In, SemanticInterpretation::Arbitrary},
+      {Triple::Vertex, IOType::Out, SemanticInterpretation::SV},
+      {Triple::Pixel, IOType::In, SemanticInterpretation::SV},
+  };
+  expectOnlySignaturePoints(SemanticKind::RenderTargetArrayIndex, Valid);
+}
+
 } // namespace


        


More information about the cfe-commits mailing list