Skip to content

Commit 56e3fc4

Browse files
authored
[NFC][HLSL][RootSignature] Split up HLSLRootSignatureUtils (#146124)
This pr breaks-up `HLSLRootSignatureUtils` into separate orthogonal and meaningful libraries. This prevents it ending up as a dumping grounds of many different parts. - Creates a library `RootSignatureMetadata` to contain helper functions for interacting the root signatures in their metadata representation - Create a library `RootSignatureValidations` to contain helper functions that will validate various values of root signatures - Move the serialization of root signature elements to `HLSLRootSignature` Resolves: #145946
1 parent a438c60 commit 56e3fc4

13 files changed

+607
-520
lines changed

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "clang/Basic/Specifiers.h"
2525
#include "clang/Basic/TypeTraits.h"
2626
#include "llvm/ADT/StringExtras.h"
27-
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
27+
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
2828

2929
#include <algorithm>
3030
#include <utility>

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "clang/AST/Type.h"
2424
#include "clang/Basic/TargetOptions.h"
2525
#include "llvm/ADT/SmallVector.h"
26-
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
26+
#include "llvm/Frontend/HLSL/RootSignatureMetadata.h"
2727
#include "llvm/IR/Constants.h"
2828
#include "llvm/IR/DerivedTypes.h"
2929
#include "llvm/IR/GlobalVariable.h"

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "llvm/ADT/StringExtras.h"
4040
#include "llvm/ADT/StringRef.h"
4141
#include "llvm/ADT/Twine.h"
42-
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
42+
#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
4343
#include "llvm/Support/Casting.h"
4444
#include "llvm/Support/DXILABI.h"
4545
#include "llvm/Support/ErrorHandling.h"

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/BinaryFormat/DXContainer.h"
1818
#include "llvm/Support/Compiler.h"
1919
#include "llvm/Support/DXILABI.h"
20+
#include "llvm/Support/raw_ostream.h"
2021
#include <limits>
2122
#include <variant>
2223

@@ -135,6 +136,21 @@ using RootElement =
135136
std::variant<dxbc::RootFlags, RootConstants, RootDescriptor,
136137
DescriptorTable, DescriptorTableClause, StaticSampler>;
137138

139+
/// The following contains the serialization interface for root elements
140+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags);
141+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
142+
const RootConstants &Constants);
143+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
144+
const DescriptorTableClause &Clause);
145+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
146+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
147+
const RootDescriptor &Descriptor);
148+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
149+
const StaticSampler &StaticSampler);
150+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element);
151+
152+
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
153+
138154
} // namespace rootsig
139155
} // namespace hlsl
140156
} // namespace llvm
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===- RootSignatureMetadata.h - HLSL Root Signature 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 contains a library for working with HLSL Root Signatures and
10+
/// their metadata representation.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
15+
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
16+
17+
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
18+
19+
namespace llvm {
20+
class LLVMContext;
21+
class MDNode;
22+
class Metadata;
23+
24+
namespace hlsl {
25+
namespace rootsig {
26+
27+
class MetadataBuilder {
28+
public:
29+
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
30+
: Ctx(Ctx), Elements(Elements) {}
31+
32+
/// Iterates through elements and dispatches onto the correct Build* method
33+
///
34+
/// Accumulates the root signature and returns the Metadata node that is just
35+
/// a list of all the elements
36+
LLVM_ABI MDNode *BuildRootSignature();
37+
38+
private:
39+
/// Define the various builders for the different metadata types
40+
MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
41+
MDNode *BuildRootConstants(const RootConstants &Constants);
42+
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
43+
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
44+
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
45+
MDNode *BuildStaticSampler(const StaticSampler &Sampler);
46+
47+
llvm::LLVMContext &Ctx;
48+
ArrayRef<RootElement> Elements;
49+
SmallVector<Metadata *> GeneratedMetadata;
50+
};
51+
52+
} // namespace rootsig
53+
} // namespace hlsl
54+
} // namespace llvm
55+
56+
#endif // LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H

llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h renamed to llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- HLSLRootSignatureUtils.h - HLSL Root Signature helpers -------------===//
1+
//===- RootSignatureValidations.h - HLSL Root Signature helpers -----------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,68 +11,16 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
15-
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
14+
#ifndef LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H
15+
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H
1616

17-
#include "llvm/ADT/ArrayRef.h"
1817
#include "llvm/ADT/IntervalMap.h"
1918
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
20-
#include "llvm/Support/Compiler.h"
21-
#include "llvm/Support/raw_ostream.h"
2219

2320
namespace llvm {
24-
class LLVMContext;
25-
class MDNode;
26-
class Metadata;
27-
2821
namespace hlsl {
2922
namespace rootsig {
3023

31-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags);
32-
33-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
34-
const RootConstants &Constants);
35-
36-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
37-
const DescriptorTableClause &Clause);
38-
39-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
40-
41-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
42-
const RootDescriptor &Descriptor);
43-
44-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
45-
const StaticSampler &StaticSampler);
46-
47-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element);
48-
49-
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
50-
51-
class MetadataBuilder {
52-
public:
53-
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
54-
: Ctx(Ctx), Elements(Elements) {}
55-
56-
/// Iterates through the elements and dispatches onto the correct Build method
57-
///
58-
/// Accumulates the root signature and returns the Metadata node that is just
59-
/// a list of all the elements
60-
LLVM_ABI MDNode *BuildRootSignature();
61-
62-
private:
63-
/// Define the various builders for the different metadata types
64-
MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
65-
MDNode *BuildRootConstants(const RootConstants &Constants);
66-
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
67-
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
68-
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
69-
MDNode *BuildStaticSampler(const StaticSampler &Sampler);
70-
71-
llvm::LLVMContext &Ctx;
72-
ArrayRef<RootElement> Elements;
73-
SmallVector<Metadata *> GeneratedMetadata;
74-
};
75-
7624
struct RangeInfo {
7725
const static uint32_t Unbounded = ~0u;
7826

@@ -83,7 +31,7 @@ struct RangeInfo {
8331
// Information retained for diagnostics
8432
llvm::dxil::ResourceClass Class;
8533
uint32_t Space;
86-
dxbc::ShaderVisibility Visibility;
34+
llvm::dxbc::ShaderVisibility Visibility;
8735
};
8836

8937
class ResourceRange {
@@ -141,4 +89,4 @@ class ResourceRange {
14189
} // namespace hlsl
14290
} // namespace llvm
14391

144-
#endif // LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
92+
#endif // LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H

llvm/lib/Frontend/HLSL/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
add_llvm_component_library(LLVMFrontendHLSL
22
CBuffer.cpp
33
HLSLResource.cpp
4-
HLSLRootSignatureUtils.cpp
4+
HLSLRootSignature.cpp
5+
RootSignatureMetadata.cpp
6+
RootSignatureValidations.cpp
57

68
ADDITIONAL_HEADER_DIRS
79
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend

0 commit comments

Comments
 (0)