LLVM 24.0.0git
SemanticSignatures.h
Go to the documentation of this file.
1//===- SemanticSignatures.h - HLSL Semantic Signature helper objects ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file This file contains structure definitions of HLSL Semantic Signature
10/// objects.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_FRONTEND_HLSL_SEMANTICSIGNATURES_H
15#define LLVM_FRONTEND_HLSL_SEMANTICSIGNATURES_H
16
17#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
24#include "llvm/Support/Error.h"
26#include <cassert>
27#include <cstdint>
28
29namespace llvm {
30
31class LLVMContext;
32class MDNode;
33
34namespace hlsl {
35
37
38// For now just use the DXIL ABI enums directly. This may change in the future.
40
41// Definitions of the in-memory data layout structures
42
43// Bitmask denoting whether a semantic is an input, output, inout or a value
44// that is constant across a patch (hull/domain shaders) or primitive
45// (mesh shaders).
46enum class IOType {
47 In = 0b001,
48 Out = 0b010,
49 InOut = 0b011,
51 All = 0b111,
52
54};
55
56// Keywords written on a declaration, before sampling-location precedence and
57// stage/type defaults are applied.
59 None = 0,
61 Linear = 1 << 1,
62 NoPerspective = 1 << 2,
63 // Sampling-location bits are ordered by increasing precedence for min/max.
64 Center = 1 << 3,
65 Centroid = 1 << 4,
66 Sample = 1 << 5,
68};
69
75 "sampling-location bits must increase in precedence");
76
77// SPIR-V Decoration enumerants that bind an interface variable to a builtin or
78// a user location. The values match the SPIR-V specification.
83
84// SPIR-V BuiltIn enumerants used as the operand of a BuiltIn decoration. The
85// values match the SPIR-V specification.
86enum class SPIRVBuiltIn : uint32_t {
87 Layer = 9,
90};
91
92// SPIR-V Decoration enumerants that control how a fragment shader input is
93// interpolated. The values match the SPIR-V specification.
100
101// Select the highest-precedence sampling-location bit (sample > centroid >
102// center), ignoring other modifiers. Returns None if no location is explicit,
103// keeping it distinct from Center so diagnostics can detect location overrides.
106
107// Returns Invalid for nointerpolation combined with any other modifier.
110
111// Apply component-type defaults and SV_Position's noperspective requirement.
112// Vertex outputs carry interpolation modes so they pack compatibly with pixel
113// inputs; other signature points do not use interpolation modes.
116 dxbc::PSV::SemanticKind Kind, Triple::EnvironmentType Stage, IOType IO);
117
129
135
136// Sentinel values denoting that an element is unallocated
137static constexpr uint32_t UnallocatedRow = ~0U;
138static constexpr uint8_t UnallocatedCol = 0xFF;
139
140// Models a single packed range of signature rows with its semantic name and
141// indices, register placement, component masks, and stage-specific attributes.
149 dxbc::PSV::InterpolationMode::Undefined;
154 // Register-relative components accessed by the shader, including conditional
155 // accesses. Input program signatures call this field AlwaysReads.
157 // Element-relative dynamically indexed components, as in DXIL and PSV.
160
169
170 bool isAllocated() const {
172 }
173
174 // Register column of the element's first component. Unallocated elements
175 // have no register, so their masks are relative to component 0.
176 uint8_t getStartColOrZero() const { return isAllocated() ? StartCol : 0; }
177
179 unsigned Column = getStartColOrZero();
180 assert(Cols >= 1 && Column + Cols <= 4 &&
181 "declared components must fit within one register row");
182 return static_cast<uint8_t>(((1U << Cols) - 1U) << Column);
183 }
184
186
188 return static_cast<uint8_t>(~UsageMask & 0xF);
189 }
190
191 dxbc::SigMinPrecision getMinPrecision(bool UseMinPrecision) const {
192 if (!UseMinPrecision)
193 return dxbc::SigMinPrecision::Default;
194 switch (CompType) {
196 return dxbc::SigMinPrecision::Float16;
198 return dxbc::SigMinPrecision::SInt16;
200 return dxbc::SigMinPrecision::UInt16;
201 default:
202 return dxbc::SigMinPrecision::Default;
203 }
204 }
205
206 // Parse a signature element from its metadata representation
208 fromMetadata(const MDNode *Node);
209
210 // Build the metadata representation of this signature element
212};
213
215
218
219LLVM_ABI SemanticInterpretation
221 Triple::EnvironmentType ShaderStage, IOType IOTy);
222
223} // namespace hlsl
224} // namespace llvm
225
226#endif // LLVM_FRONTEND_HLSL_SEMANTICSIGNATURES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:211
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Tagged union holding either a T or a Error.
Definition Error.h:485
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Metadata node.
Definition Metadata.h:1087
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
ElementType
The element type of an SRV or UAV resource.
Definition DXILABI.h:68
static constexpr uint32_t UnallocatedRow
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
LLVM_ABI SemanticInterpretation getInterpretationKind(dxbc::PSV::SemanticKind SemanticKind, Triple::EnvironmentType ShaderStage, IOType IOTy)
LLVM_ABI ArrayRef< SemanticStageInfo > getAvailableStages(dxbc::PSV::SemanticKind SemanticKind)
LLVM_ABI dxbc::PSV::InterpolationMode getInterpolationMode(InterpolationModifier Modifiers)
LLVM_ABI dxbc::PSV::InterpolationMode normalizeInterpolationMode(dxbc::PSV::InterpolationMode Mode, dxil::ElementType CompType, dxbc::PSV::SemanticKind Kind, Triple::EnvironmentType Stage, IOType IO)
LLVM_ABI InterpolationModifier getInterpolationSamplingLocation(InterpolationModifier Modifiers)
LLVM_ABI dxbc::PSV::SemanticKind getSemanticKind(StringRef SemanticName)
static constexpr uint8_t UnallocatedCol
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
dxbc::SigMinPrecision getMinPrecision(bool UseMinPrecision) const
static LLVM_ABI Expected< SemanticSignatureElement > fromMetadata(const MDNode *Node)
SemanticSignatureElement(uint32_t SigId, StringRef SemanticName, dxil::ElementType CompType, dxbc::PSV::SemanticKind SemanticKind, ArrayRef< uint32_t > SemanticIndices, uint8_t Cols)
dxbc::PSV::InterpolationMode InterpMode
LLVM_ABI MDNode * toMetadata(LLVMContext &Ctx) const
SemanticInterpretation Interpretation
Triple::EnvironmentType Stage