Skip to content

Commit c21e2a5

Browse files
joaosaffranjoaosaffran
andauthored
[DirectX] Moving Root Signature Metadata Parsing in to Shared Root Signature Metadata lib (#149221)
This PR, moves the existing Root Signature Metadata Parsing logic used in `DXILRootSignature` to the common library used by both frontend and backend. Closes: [#145942](#145942) --------- Co-authored-by: joaosaffran <[email protected]>
1 parent 7ae3715 commit c21e2a5

File tree

5 files changed

+531
-474
lines changed

5 files changed

+531
-474
lines changed

llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
1616

1717
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
18+
#include "llvm/IR/Constants.h"
19+
#include "llvm/MC/DXContainerRootSignature.h"
1820

1921
namespace llvm {
2022
class LLVMContext;
@@ -49,6 +51,48 @@ class MetadataBuilder {
4951
SmallVector<Metadata *> GeneratedMetadata;
5052
};
5153

54+
enum class RootSignatureElementKind {
55+
Error = 0,
56+
RootFlags = 1,
57+
RootConstants = 2,
58+
SRV = 3,
59+
UAV = 4,
60+
CBV = 5,
61+
DescriptorTable = 6,
62+
StaticSamplers = 7
63+
};
64+
65+
class MetadataParser {
66+
public:
67+
MetadataParser(MDNode *Root) : Root(Root) {}
68+
69+
LLVM_ABI bool ParseRootSignature(LLVMContext *Ctx,
70+
mcdxbc::RootSignatureDesc &RSD);
71+
72+
private:
73+
bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
74+
MDNode *RootFlagNode);
75+
bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
76+
MDNode *RootConstantNode);
77+
bool parseRootDescriptors(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
78+
MDNode *RootDescriptorNode,
79+
RootSignatureElementKind ElementKind);
80+
bool parseDescriptorRange(LLVMContext *Ctx, mcdxbc::DescriptorTable &Table,
81+
MDNode *RangeDescriptorNode);
82+
bool parseDescriptorTable(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
83+
MDNode *DescriptorTableNode);
84+
bool parseRootSignatureElement(LLVMContext *Ctx,
85+
mcdxbc::RootSignatureDesc &RSD,
86+
MDNode *Element);
87+
bool parseStaticSampler(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
88+
MDNode *StaticSamplerNode);
89+
90+
bool validateRootSignature(LLVMContext *Ctx,
91+
const llvm::mcdxbc::RootSignatureDesc &RSD);
92+
93+
MDNode *Root;
94+
};
95+
5296
} // namespace rootsig
5397
} // namespace hlsl
5498
} // namespace llvm

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifndef LLVM_MC_DXCONTAINERROOTSIGNATURE_H
10+
#define LLVM_MC_DXCONTAINERROOTSIGNATURE_H
11+
912
#include "llvm/BinaryFormat/DXContainer.h"
1013
#include <cstdint>
1114
#include <limits>
@@ -116,3 +119,5 @@ struct RootSignatureDesc {
116119
};
117120
} // namespace mcdxbc
118121
} // namespace llvm
122+
123+
#endif // LLVM_MC_DXCONTAINERROOTSIGNATURE_H

0 commit comments

Comments
 (0)