Skip to content

Commit b97cec4

Browse files
committed
nfc: move root flags
1 parent cc71ffc commit b97cec4

File tree

7 files changed

+24
-55
lines changed

7 files changed

+24
-55
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class RootSignatureParser {
7171
// expected, or, there is a lexing error
7272

7373
/// Root Element parse methods:
74-
std::optional<llvm::hlsl::rootsig::RootFlags> parseRootFlags();
74+
std::optional<llvm::dxbc::RootFlags> parseRootFlags();
7575
std::optional<llvm::hlsl::rootsig::RootConstants> parseRootConstants();
7676
std::optional<llvm::hlsl::rootsig::RootDescriptor> parseRootDescriptor();
7777
std::optional<llvm::hlsl::rootsig::DescriptorTable> parseDescriptorTable();

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ static FlagType maybeOrFlag(std::optional<FlagType> Flags, FlagType Flag) {
7676
llvm::to_underlying(Flag));
7777
}
7878

79-
std::optional<RootFlags> RootSignatureParser::parseRootFlags() {
79+
std::optional<llvm::dxbc::RootFlags> RootSignatureParser::parseRootFlags() {
8080
assert(CurToken.TokKind == TokenKind::kw_RootFlags &&
8181
"Expects to only be invoked starting at given keyword");
8282

8383
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
8484
CurToken.TokKind))
8585
return std::nullopt;
8686

87-
std::optional<RootFlags> Flags = RootFlags::None;
87+
std::optional<llvm::dxbc::RootFlags> Flags = llvm::dxbc::RootFlags::None;
8888

8989
// Handle the edge-case of '0' to specify no flags set
9090
if (tryConsumeExpectedToken(TokenKind::int_literal)) {
@@ -104,7 +104,8 @@ std::optional<RootFlags> RootSignatureParser::parseRootFlags() {
104104
switch (CurToken.TokKind) {
105105
#define ROOT_FLAG_ENUM(NAME, LIT) \
106106
case TokenKind::en_##NAME: \
107-
Flags = maybeOrFlag<RootFlags>(Flags, RootFlags::NAME); \
107+
Flags = maybeOrFlag<llvm::dxbc::RootFlags>(Flags, \
108+
llvm::dxbc::RootFlags::NAME); \
108109
break;
109110
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
110111
default:

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,17 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
487487
ASSERT_EQ(Elements.size(), 3u);
488488

489489
RootElement Elem = Elements[0];
490-
ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));
491-
ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::None);
490+
ASSERT_TRUE(std::holds_alternative<llvm::dxbc::RootFlags>(Elem));
491+
ASSERT_EQ(std::get<llvm::dxbc::RootFlags>(Elem), llvm::dxbc::RootFlags::None);
492492

493493
Elem = Elements[1];
494-
ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));
495-
ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::None);
494+
ASSERT_TRUE(std::holds_alternative<llvm::dxbc::RootFlags>(Elem));
495+
ASSERT_EQ(std::get<llvm::dxbc::RootFlags>(Elem), llvm::dxbc::RootFlags::None);
496496

497497
Elem = Elements[2];
498-
ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));
499-
ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::ValidFlags);
498+
ASSERT_TRUE(std::holds_alternative<llvm::dxbc::RootFlags>(Elem));
499+
auto ValidRootFlags = llvm::dxbc::RootFlags(0xfff);
500+
ASSERT_EQ(std::get<llvm::dxbc::RootFlags>(Elem), ValidRootFlags);
500501

501502
ASSERT_TRUE(Consumer->isSatisfied());
502503
}

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1515
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1616

17+
#include "llvm/BinaryFormat/DXContainer.h"
1718
#include "llvm/Support/Compiler.h"
1819
#include "llvm/Support/DXILABI.h"
1920
#include <limits>
@@ -28,23 +29,6 @@ namespace rootsig {
2829
// carried over from their values in DXC. For reference:
2930
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/
3031

31-
enum class RootFlags : uint32_t {
32-
None = 0,
33-
AllowInputAssemblerInputLayout = 0x1,
34-
DenyVertexShaderRootAccess = 0x2,
35-
DenyHullShaderRootAccess = 0x4,
36-
DenyDomainShaderRootAccess = 0x8,
37-
DenyGeometryShaderRootAccess = 0x10,
38-
DenyPixelShaderRootAccess = 0x20,
39-
AllowStreamOutput = 0x40,
40-
LocalRootSignature = 0x80,
41-
DenyAmplificationShaderRootAccess = 0x100,
42-
DenyMeshShaderRootAccess = 0x200,
43-
CBVSRVUAVHeapDirectlyIndexed = 0x400,
44-
SamplerHeapDirectlyIndexed = 0x800,
45-
ValidFlags = 0x00000fff
46-
};
47-
4832
enum class RootDescriptorFlags : unsigned {
4933
None = 0,
5034
DataVolatile = 0x2,
@@ -251,8 +235,8 @@ struct StaticSampler {
251235
/// RootElements in the array, and it holds a data member for the Visibility
252236
/// parameter.
253237
using RootElement =
254-
std::variant<RootFlags, RootConstants, RootDescriptor, DescriptorTable,
255-
DescriptorTableClause, StaticSampler>;
238+
std::variant<dxbc::RootFlags, RootConstants, RootDescriptor,
239+
DescriptorTable, DescriptorTableClause, StaticSampler>;
256240

257241
} // namespace rootsig
258242
} // namespace hlsl

llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Metadata;
2828
namespace hlsl {
2929
namespace rootsig {
3030

31-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags);
31+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags);
3232

3333
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
3434
const RootConstants &Constants);
@@ -61,7 +61,7 @@ class MetadataBuilder {
6161

6262
private:
6363
/// Define the various builders for the different metadata types
64-
MDNode *BuildRootFlags(const RootFlags &Flags);
64+
MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
6565
MDNode *BuildRootConstants(const RootConstants &Constants);
6666
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
6767
MDNode *BuildDescriptorTable(const DescriptorTable &Table);

llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,9 @@ static raw_ostream &operator<<(raw_ostream &OS,
246246
return OS;
247247
}
248248

249-
static const EnumEntry<RootFlags> RootFlagNames[] = {
250-
{"AllowInputAssemblerInputLayout",
251-
RootFlags::AllowInputAssemblerInputLayout},
252-
{"DenyVertexShaderRootAccess", RootFlags::DenyVertexShaderRootAccess},
253-
{"DenyHullShaderRootAccess", RootFlags::DenyHullShaderRootAccess},
254-
{"DenyDomainShaderRootAccess", RootFlags::DenyDomainShaderRootAccess},
255-
{"DenyGeometryShaderRootAccess", RootFlags::DenyGeometryShaderRootAccess},
256-
{"DenyPixelShaderRootAccess", RootFlags::DenyPixelShaderRootAccess},
257-
{"AllowStreamOutput", RootFlags::AllowStreamOutput},
258-
{"LocalRootSignature", RootFlags::LocalRootSignature},
259-
{"DenyAmplificationShaderRootAccess",
260-
RootFlags::DenyAmplificationShaderRootAccess},
261-
{"DenyMeshShaderRootAccess", RootFlags::DenyMeshShaderRootAccess},
262-
{"CBVSRVUAVHeapDirectlyIndexed", RootFlags::CBVSRVUAVHeapDirectlyIndexed},
263-
{"SamplerHeapDirectlyIndexed", RootFlags::SamplerHeapDirectlyIndexed},
264-
};
265-
266-
raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) {
249+
raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags) {
267250
OS << "RootFlags(";
268-
printFlags(OS, Flags, ArrayRef(RootFlagNames));
251+
printFlags(OS, Flags, dxbc::getRootFlags());
269252
OS << ")";
270253

271254
return OS;
@@ -341,7 +324,7 @@ template <class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>;
341324

342325
raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element) {
343326
const auto Visitor = OverloadedVisit{
344-
[&OS](const RootFlags &Flags) { OS << Flags; },
327+
[&OS](const dxbc::RootFlags &Flags) { OS << Flags; },
345328
[&OS](const RootConstants &Constants) { OS << Constants; },
346329
[&OS](const RootDescriptor &Descriptor) { OS << Descriptor; },
347330
[&OS](const DescriptorTableClause &Clause) { OS << Clause; },
@@ -366,7 +349,7 @@ void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
366349

367350
MDNode *MetadataBuilder::BuildRootSignature() {
368351
const auto Visitor = OverloadedVisit{
369-
[this](const RootFlags &Flags) -> MDNode * {
352+
[this](const dxbc::RootFlags &Flags) -> MDNode * {
370353
return BuildRootFlags(Flags);
371354
},
372355
[this](const RootConstants &Constants) -> MDNode * {
@@ -396,7 +379,7 @@ MDNode *MetadataBuilder::BuildRootSignature() {
396379
return MDNode::get(Ctx, GeneratedMetadata);
397380
}
398381

399-
MDNode *MetadataBuilder::BuildRootFlags(const RootFlags &Flags) {
382+
MDNode *MetadataBuilder::BuildRootFlags(const dxbc::RootFlags &Flags) {
400383
IRBuilder<> Builder(Ctx);
401384
Metadata *Operands[] = {
402385
MDString::get(Ctx, "RootFlags"),

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ TEST(HLSLRootSignatureTest, SetRootConstantsDump) {
262262
}
263263

264264
TEST(HLSLRootSignatureTest, NoneRootFlagsDump) {
265-
RootFlags Flags = RootFlags::None;
265+
llvm::dxbc::RootFlags Flags = llvm::dxbc::RootFlags::None;
266266

267267
std::string Out;
268268
llvm::raw_string_ostream OS(Out);
@@ -274,7 +274,7 @@ TEST(HLSLRootSignatureTest, NoneRootFlagsDump) {
274274
}
275275

276276
TEST(HLSLRootSignatureTest, AllRootFlagsDump) {
277-
RootFlags Flags = RootFlags::ValidFlags;
277+
llvm::dxbc::RootFlags Flags = llvm::dxbc::RootFlags(0xfff);
278278

279279
std::string Out;
280280
llvm::raw_string_ostream OS(Out);

0 commit comments

Comments
 (0)