Skip to content

Commit 0efd8cc

Browse files
author
joaosaffran
committed
adding root constants
1 parent b1b28f8 commit 0efd8cc

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ enum class RootElementFlag : uint32_t {
159159
#include "DXContainerConstants.def"
160160
};
161161

162+
#define ROOT_PARAMETER(Val, Enum) Enum = Val,
163+
enum class RootParameterType : uint8_t {
164+
#include "DXContainerConstants.def"
165+
};
166+
167+
ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();
168+
169+
#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
170+
enum class ShaderVisibilityFlag : uint8_t {
171+
#include "DXContainerConstants.def"
172+
};
173+
174+
ArrayRef<EnumEntry<ShaderVisibilityFlag>> getShaderVisibilityFlags();
175+
162176
PartType parsePartType(StringRef S);
163177

164178
struct VertexPSVInfo {

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
7272
#undef ROOT_ELEMENT_FLAG
7373
#endif // ROOT_ELEMENT_FLAG
7474

75+
#ifdef ROOT_PARAMETER
76+
77+
ROOT_PARAMETER(1, Constants32Bit)
78+
#undef ROOT_PARAMETER
79+
#endif // ROOT_PARAMETER
80+
81+
#ifdef SHADER_VISIBILITY
82+
SHADER_VISIBILITY(0, All)
83+
SHADER_VISIBILITY(1, Vertex)
84+
SHADER_VISIBILITY(2, Hull)
85+
SHADER_VISIBILITY(3, Domain)
86+
SHADER_VISIBILITY(4, Geometry)
87+
SHADER_VISIBILITY(5, Pixel)
88+
SHADER_VISIBILITY(6, Amplification)
89+
SHADER_VISIBILITY(7, Mesh)
90+
#undef SHADER_VISIBILITY
91+
#endif // SHADER_VISIBILITY
7592

7693
#ifdef DXIL_MODULE_FLAG
7794

llvm/include/llvm/MC/DXContainerRootSignature.h

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

9+
#include "llvm/BinaryFormat/DXContainer.h"
910
#include <cstdint>
1011
#include <limits>
1112

@@ -14,6 +15,9 @@ namespace llvm {
1415
class raw_ostream;
1516

1617
namespace mcdxbc {
18+
19+
20+
1721
struct RootSignatureHeader {
1822
uint32_t Version = 2;
1923
uint32_t NumParameters = 0;
@@ -24,5 +28,23 @@ struct RootSignatureHeader {
2428

2529
void write(raw_ostream &OS);
2630
};
31+
32+
struct RootConstants {
33+
uint32_t ShaderRegister;
34+
uint32_t RegisterSpace;
35+
uint32_t Num32BitValues;
36+
37+
void write(raw_ostream &OS);
38+
};
39+
40+
struct RootParameter {
41+
dxbc::RootParameterType ParameterType;
42+
union {
43+
RootConstants Constants;
44+
};
45+
dxbc::ShaderVisibilityFlag ShaderVisibility;
46+
47+
void write(raw_ostream &OS);
48+
};
2749
} // namespace mcdxbc
2850
} // namespace llvm

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,34 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/MC/DXContainerRootSignature.h"
10+
#include "llvm/ADT/bit.h"
1011
#include "llvm/Support/EndianStream.h"
1112

1213
using namespace llvm;
1314
using namespace llvm::mcdxbc;
1415

1516
void RootSignatureHeader::write(raw_ostream &OS) {
16-
1717
support::endian::write(OS, Version, llvm::endianness::little);
1818
support::endian::write(OS, NumParameters, llvm::endianness::little);
1919
support::endian::write(OS, RootParametersOffset, llvm::endianness::little);
2020
support::endian::write(OS, NumStaticSamplers, llvm::endianness::little);
2121
support::endian::write(OS, StaticSamplersOffset, llvm::endianness::little);
2222
support::endian::write(OS, Flags, llvm::endianness::little);
2323
}
24+
25+
void RootParameter::write(raw_ostream &OS) {
26+
support::endian::write(OS, ParameterType, llvm::endianness::little);
27+
support::endian::write(OS, ShaderVisibility, llvm::endianness::little);
28+
29+
switch(ParameterType){
30+
case dxbc::RootParameterType::Constants32Bit:
31+
Constants.write(OS);
32+
break;
33+
}
34+
}
35+
36+
void RootConstants::write(raw_ostream &OS) {
37+
support::endian::write(OS, Num32BitValues, llvm::endianness::little);
38+
support::endian::write(OS, RegisterSpace, llvm::endianness::little);
39+
support::endian::write(OS, ShaderRegister, llvm::endianness::little);
40+
}

0 commit comments

Comments
 (0)