Skip to content

Commit cc71ffc

Browse files
committed
nfc: prepare dxbc::RootFlags
1 parent 5a194c1 commit cc71ffc

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ enum class FeatureFlags : uint64_t {
157157
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
158158
"Shader flag bits exceed enum size.");
159159

160-
#define ROOT_ELEMENT_FLAG(Num, Val) Val = Num,
161-
enum class RootElementFlag : uint32_t {
160+
#define ROOT_SIGNATURE_FLAG(Num, Val) Val = Num,
161+
enum class RootFlags : uint32_t {
162162
#include "DXContainerConstants.def"
163163
};
164164

165+
LLVM_ABI ArrayRef<EnumEntry<RootFlags>> getRootFlags();
166+
165167
#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = Num,
166168
enum class RootDescriptorFlag : uint32_t {
167169
#include "DXContainerConstants.def"

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,30 @@ SHADER_FEATURE_FLAG(33, 39, NextUnusedBit, "Next reserved shader flag bit (not a
5555
#undef SHADER_FEATURE_FLAG
5656
#endif // SHADER_FEATURE_FLAG
5757

58-
59-
// ROOT_ELEMENT_FLAG(bit offset for the flag, name).
60-
#ifdef ROOT_ELEMENT_FLAG
61-
62-
ROOT_ELEMENT_FLAG(0, NONE)
63-
ROOT_ELEMENT_FLAG(0x1, AllowInputAssemblerInputLayout)
64-
ROOT_ELEMENT_FLAG(0x2, DenyVertexShaderRootAccess)
65-
ROOT_ELEMENT_FLAG(0x4, DenyHullShaderRootAccess)
66-
ROOT_ELEMENT_FLAG(0x8, DenyDomainShaderRootAccess)
67-
ROOT_ELEMENT_FLAG(0x10, DenyGeometryShaderRootAccess)
68-
ROOT_ELEMENT_FLAG(0x20, DenyPixelShaderRootAccess)
69-
ROOT_ELEMENT_FLAG(0x40, AllowStreamOutput)
70-
ROOT_ELEMENT_FLAG(0x80, LocalRootSignature)
71-
ROOT_ELEMENT_FLAG(0x100, DenyAmplificationShaderRootAccess)
72-
ROOT_ELEMENT_FLAG(0x200, DenyMeshShaderRootAccess)
73-
ROOT_ELEMENT_FLAG(0x400, CBVSRVUAVHeapDirectlyIndexed)
74-
ROOT_ELEMENT_FLAG(0x800, SamplerHeapDirectlyIndexed)
75-
#undef ROOT_ELEMENT_FLAG
76-
#endif // ROOT_ELEMENT_FLAG
77-
58+
// Below is the definition of root signature enumerations and flags. The
59+
// definitions of all values here correspond to their description in the
60+
// d3d12.h header and are carried over from their values in DXC. For reference:
61+
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/
62+
63+
// ROOT_SIGNATURE_FLAG(flag value, name).
64+
#ifdef ROOT_SIGNATURE_FLAG
65+
66+
ROOT_SIGNATURE_FLAG(0, None)
67+
ROOT_SIGNATURE_FLAG(0x1, AllowInputAssemblerInputLayout)
68+
ROOT_SIGNATURE_FLAG(0x2, DenyVertexShaderRootAccess)
69+
ROOT_SIGNATURE_FLAG(0x4, DenyHullShaderRootAccess)
70+
ROOT_SIGNATURE_FLAG(0x8, DenyDomainShaderRootAccess)
71+
ROOT_SIGNATURE_FLAG(0x10, DenyGeometryShaderRootAccess)
72+
ROOT_SIGNATURE_FLAG(0x20, DenyPixelShaderRootAccess)
73+
ROOT_SIGNATURE_FLAG(0x40, AllowStreamOutput)
74+
ROOT_SIGNATURE_FLAG(0x80, LocalRootSignature)
75+
ROOT_SIGNATURE_FLAG(0x100, DenyAmplificationShaderRootAccess)
76+
ROOT_SIGNATURE_FLAG(0x200, DenyMeshShaderRootAccess)
77+
ROOT_SIGNATURE_FLAG(0x400, CBVSRVUAVHeapDirectlyIndexed)
78+
ROOT_SIGNATURE_FLAG(0x800, SamplerHeapDirectlyIndexed)
79+
80+
#undef ROOT_SIGNATURE_FLAG
81+
#endif // ROOT_SIGNATURE_FLAG
7882

7983
// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name).
8084
#ifdef ROOT_DESCRIPTOR_FLAG

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct RootSignatureYamlDesc {
203203
LLVM_ABI static llvm::Expected<DXContainerYAML::RootSignatureYamlDesc>
204204
create(const object::DirectX::RootSignature &Data);
205205

206-
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
206+
#define ROOT_SIGNATURE_FLAG(Num, Val) bool Val = false;
207207
#include "llvm/BinaryFormat/DXContainerConstants.def"
208208
};
209209

llvm/lib/BinaryFormat/DXContainer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ ArrayRef<EnumEntry<SigComponentType>> dxbc::getSigComponentTypes() {
6060
return ArrayRef(SigComponentTypes);
6161
}
6262

63+
static const EnumEntry<RootFlags> RootFlagNames[] = {
64+
#define ROOT_SIGNATURE_FLAG(Val, Enum) {#Enum, RootFlags::Enum},
65+
#include "llvm/BinaryFormat/DXContainerConstants.def"
66+
};
67+
68+
ArrayRef<EnumEntry<RootFlags>> dxbc::getRootFlags() {
69+
return ArrayRef(RootFlagNames);
70+
}
71+
6372
#define SHADER_VISIBILITY(Val, Enum) {#Enum, ShaderVisibility::Enum},
6473

6574
static const EnumEntry<ShaderVisibility> ShaderVisibilityValues[] = {

llvm/lib/Frontend/HLSL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_llvm_component_library(LLVMFrontendHLSL
1111
intrinsics_gen
1212

1313
LINK_COMPONENTS
14+
BinaryFormat
1415
Core
1516
Support
1617
)

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ DXContainerYAML::RootSignatureYamlDesc::create(
180180
RootSigDesc.StaticSamplers.push_back(NewS);
181181
}
182182

183-
#define ROOT_ELEMENT_FLAG(Num, Val) \
184-
RootSigDesc.Val = \
185-
(Flags & llvm::to_underlying(dxbc::RootElementFlag::Val)) > 0;
183+
#define ROOT_SIGNATURE_FLAG(Num, Val) \
184+
RootSigDesc.Val = (Flags & llvm::to_underlying(dxbc::RootFlags::Val)) > 0;
186185
#include "llvm/BinaryFormat/DXContainerConstants.def"
187186
return RootSigDesc;
188187
}
@@ -198,9 +197,9 @@ uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() const {
198197

199198
uint32_t DXContainerYAML::RootSignatureYamlDesc::getEncodedFlags() {
200199
uint64_t Flag = 0;
201-
#define ROOT_ELEMENT_FLAG(Num, Val) \
200+
#define ROOT_SIGNATURE_FLAG(Num, Val) \
202201
if (Val) \
203-
Flag |= (uint32_t)dxbc::RootElementFlag::Val;
202+
Flag |= (uint32_t)dxbc::RootFlags::Val;
204203
#include "llvm/BinaryFormat/DXContainerConstants.def"
205204
return Flag;
206205
}
@@ -382,7 +381,7 @@ void MappingTraits<DXContainerYAML::RootSignatureYamlDesc>::mapping(
382381
IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset);
383382
IO.mapRequired("Parameters", S.Parameters.Locations, S);
384383
IO.mapOptional("Samplers", S.StaticSamplers);
385-
#define ROOT_ELEMENT_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);
384+
#define ROOT_SIGNATURE_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);
386385
#include "llvm/BinaryFormat/DXContainerConstants.def"
387386
}
388387

0 commit comments

Comments
 (0)