LLVM 24.0.0git
SemanticSignaturePacking.cpp
Go to the documentation of this file.
1//===- SemanticSignaturePacking.cpp - HLSL signature packing helpers -----===//
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 implements helpers for packing HLSL semantic signatures.
10///
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/STLExtras.h"
15#include <cassert>
16
17using namespace llvm;
18using namespace llvm::hlsl;
19
21
23 switch (Kind) {
25 OS << "signature elements do not fit in " << MaxSignatureRows << " rows";
26 break;
27 }
28 OS << " (element " << ElementIndex << ")";
29}
30
33 Triple::EnvironmentType ShaderStage, IOType IOTy) {
34 assert(ShaderStage == Triple::Vertex && IOTy == IOType::In &&
35 "stacked packing is only valid for a vertex shader input signature");
36
37 unsigned NextRow = 0;
38 for (auto &&[Index, Element] : enumerate(Elements)) {
39 assert(Element.StartRow == UnallocatedRow &&
40 Element.StartCol == UnallocatedCol && "already allocated?");
41 assert(Element.Rows > 0 && "signature element must have at least one row");
42 assert(Element.Cols > 0 && Element.Cols <= MaxSignatureCols &&
43 "signature element must have between 1 and 4 columns");
44
45 SemanticInterpretation Interpretation =
46 getInterpretationKind(Element.SemanticKind, ShaderStage, IOTy);
47 if (Interpretation == SemanticInterpretation::NotAllocated)
48 continue;
49
50 assert((Interpretation == SemanticInterpretation::Arbitrary ||
51 Interpretation == SemanticInterpretation::SV ||
52 Interpretation == SemanticInterpretation::SGV) &&
53 "unexpected semantic interpretation for stacked packing, should "
54 "have been diagnosed by Sema");
55
56 if (Element.Rows > MaxSignatureRows - NextRow)
59 static_cast<unsigned>(Index));
60
61 Element.StartRow = NextRow;
62 Element.StartCol = 0;
63 NextRow += Element.Rows;
64 }
65
66 return NextRow;
67}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains some templates that are useful if you are working with the STL at all.
Tagged union holding either a T or a Error.
Definition Error.h:485
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
void log(raw_ostream &OS) const override
Print an error message to an output stream.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
static constexpr uint32_t UnallocatedRow
LLVM_ABI Expected< unsigned > packSignatureStacked(MutableArrayRef< SemanticSignatureElement > Elements, Triple::EnvironmentType ShaderStage, IOType IOTy)
Packs eligible signature elements into consecutive rows.
LLVM_ABI SemanticInterpretation getInterpretationKind(dxbc::PSV::SemanticKind SemanticKind, Triple::EnvironmentType ShaderStage, IOType IOTy)
static constexpr unsigned MaxSignatureRows
static constexpr uint8_t UnallocatedCol
static constexpr unsigned MaxSignatureCols
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340