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 Decoration enumerants that control how a fragment shader input is
85// interpolated. The values match the SPIR-V specification.
92
93// Select the highest-precedence sampling-location bit (sample > centroid >
94// center), ignoring other modifiers. Returns None if no location is explicit,
95// keeping it distinct from Center so diagnostics can detect location overrides.
98
99// Returns Invalid for nointerpolation combined with any other modifier.
102
103// Apply component-type defaults and SV_Position's noperspective requirement.
104// Vertex outputs carry interpolation modes so they pack compatibly with pixel
105// inputs; other signature points do not use interpolation modes.
108 dxbc::PSV::SemanticKind Kind, Triple::EnvironmentType Stage, IOType IO);
109
121
127
128// Sentinel values denoting that an element is unallocated
129static constexpr uint32_t UnallocatedRow = ~0U;
130static constexpr uint8_t UnallocatedCol = 0xFF;
131
132// Models a single packed range of signature rows with its semantic name and
133// indices, register placement, component masks, and stage-specific attributes.
141 dxbc::PSV::InterpolationMode::Undefined;
146 // Register-relative components accessed by the shader, including conditional
147 // accesses. Input program signatures call this field AlwaysReads.
149 // Element-relative dynamically indexed components, as in DXIL and PSV.
152
161
162 bool isAllocated() const {
164 }
165
166 // Register column of the element's first component. Unallocated elements
167 // have no register, so their masks are relative to component 0.
168 uint8_t getStartColOrZero() const { return isAllocated() ? StartCol : 0; }
169
171 unsigned Column = getStartColOrZero();
172 assert(Cols >= 1 && Column + Cols <= 4 &&
173 "declared components must fit within one register row");
174 return static_cast<uint8_t>(((1U << Cols) - 1U) << Column);
175 }
176
178
180 return static_cast<uint8_t>(~UsageMask & 0xF);
181 }
182
183 dxbc::SigMinPrecision getMinPrecision(bool UseMinPrecision) const {
184 if (!UseMinPrecision)
185 return dxbc::SigMinPrecision::Default;
186 switch (CompType) {
188 return dxbc::SigMinPrecision::Float16;
190 return dxbc::SigMinPrecision::SInt16;
192 return dxbc::SigMinPrecision::UInt16;
193 default:
194 return dxbc::SigMinPrecision::Default;
195 }
196 }
197
198 // Parse a signature element from its metadata representation
200 fromMetadata(const MDNode *Node);
201
202 // Build the metadata representation of this signature element
204};
205
207
210
211LLVM_ABI SemanticInterpretation
213 Triple::EnvironmentType ShaderStage, IOType IOTy);
214
215} // namespace hlsl
216} // namespace llvm
217
218#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:1081
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