Skip to content

Commit 9f87522

Browse files
authored
[DX] Add support for program signatures (#67346)
For DirectX, program signatures are encoded into three different binary sections depending on if the signature is for inputs, outputs, or patches. All three signature types use the same data structure encoding so they can share a lot of logic. This patch adds support for reading and writing program signature data as both yaml and binary data. Fixes #57743 and #57744
1 parent 7e28234 commit 9f87522

File tree

13 files changed

+859
-65
lines changed

13 files changed

+859
-65
lines changed

llvm/include/llvm/BinaryFormat/DXContainer.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,74 @@ struct ResourceBindInfo : public v0::ResourceBindInfo {
426426
} // namespace v2
427427
} // namespace PSV
428428

429+
#define COMPONENT_PRECISION(Val, Enum) Enum = Val,
430+
enum class SigMinPrecision : uint32_t {
431+
#include "DXContainerConstants.def"
432+
};
433+
434+
ArrayRef<EnumEntry<SigMinPrecision>> getSigMinPrecisions();
435+
436+
#define D3D_SYSTEM_VALUE(Val, Enum) Enum = Val,
437+
enum class D3DSystemValue : uint32_t {
438+
#include "DXContainerConstants.def"
439+
};
440+
441+
ArrayRef<EnumEntry<D3DSystemValue>> getD3DSystemValues();
442+
443+
#define COMPONENT_TYPE(Val, Enum) Enum = Val,
444+
enum class SigComponentType : uint32_t {
445+
#include "DXContainerConstants.def"
446+
};
447+
448+
ArrayRef<EnumEntry<SigComponentType>> getSigComponentTypes();
449+
450+
struct ProgramSignatureHeader {
451+
uint32_t ParamCount;
452+
uint32_t FirstParamOffset;
453+
454+
void swapBytes() {
455+
sys::swapByteOrder(ParamCount);
456+
sys::swapByteOrder(ParamCount);
457+
}
458+
};
459+
460+
struct ProgramSignatureElement {
461+
uint32_t Stream; // Stream index (parameters must appear in non-decreasing
462+
// stream order)
463+
uint32_t NameOffset; // Offset from the start of the ProgramSignatureHeader to
464+
// the start of the null terminated string for the name.
465+
uint32_t Index; // Semantic Index
466+
D3DSystemValue SystemValue; // Semantic type. Similar to PSV::SemanticKind.
467+
SigComponentType CompType; // Type of bits.
468+
uint32_t Register; // Register Index (row index)
469+
uint8_t Mask; // Mask (column allocation)
470+
471+
// The ExclusiveMask has a different meaning for input and output signatures.
472+
// For an output signature, masked components of the output register are never
473+
// written to.
474+
// For an input signature, masked components of the input register are always
475+
// read.
476+
uint8_t ExclusiveMask;
477+
478+
uint16_t Unused;
479+
SigMinPrecision MinPrecision; // Minimum precision of input/output data
480+
481+
void swapBytes() {
482+
sys::swapByteOrder(Stream);
483+
sys::swapByteOrder(NameOffset);
484+
sys::swapByteOrder(Index);
485+
sys::swapByteOrder(SystemValue);
486+
sys::swapByteOrder(CompType);
487+
sys::swapByteOrder(Register);
488+
sys::swapByteOrder(Mask);
489+
sys::swapByteOrder(ExclusiveMask);
490+
sys::swapByteOrder(MinPrecision);
491+
}
492+
};
493+
494+
static_assert(sizeof(ProgramSignatureElement) == 32,
495+
"ProgramSignatureElement is misaligned");
496+
429497
} // namespace dxbc
430498
} // namespace llvm
431499

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CONTAINER_PART(DXIL)
44
CONTAINER_PART(SFI0)
55
CONTAINER_PART(HASH)
66
CONTAINER_PART(PSV0)
7+
CONTAINER_PART(ISG1)
8+
CONTAINER_PART(OSG1)
9+
CONTAINER_PART(PSG1)
710

811
#undef CONTAINER_PART
912
#endif
@@ -101,6 +104,20 @@ COMPONENT_TYPE(9, Float64)
101104
#undef COMPONENT_TYPE
102105
#endif
103106

107+
#ifdef COMPONENT_PRECISION
108+
109+
COMPONENT_PRECISION(0, Default)
110+
COMPONENT_PRECISION(1, Float16)
111+
COMPONENT_PRECISION(2, Float2_8)
112+
COMPONENT_PRECISION(3, Reserved)
113+
COMPONENT_PRECISION(4, SInt16)
114+
COMPONENT_PRECISION(5, UInt16)
115+
COMPONENT_PRECISION(0xf0, Any16)
116+
COMPONENT_PRECISION(0xf1, Any10)
117+
118+
#undef COMPONENT_PRECISION
119+
#endif
120+
104121
#ifdef INTERPOLATION_MODE
105122

106123
INTERPOLATION_MODE(0, Undefined)
@@ -115,3 +132,37 @@ INTERPOLATION_MODE(8, Invalid)
115132

116133
#undef INTERPOLATION_MODE
117134
#endif
135+
136+
#ifdef D3D_SYSTEM_VALUE
137+
138+
D3D_SYSTEM_VALUE(0, Undefined)
139+
D3D_SYSTEM_VALUE(1, Position)
140+
D3D_SYSTEM_VALUE(2, ClipDistance)
141+
D3D_SYSTEM_VALUE(3, CullDistance)
142+
D3D_SYSTEM_VALUE(4, RenderTargetArrayIndex)
143+
D3D_SYSTEM_VALUE(5, ViewPortArrayIndex)
144+
D3D_SYSTEM_VALUE(6, VertexID)
145+
D3D_SYSTEM_VALUE(7, PrimitiveID)
146+
D3D_SYSTEM_VALUE(8, InstanceID)
147+
D3D_SYSTEM_VALUE(9, IsFrontFace)
148+
D3D_SYSTEM_VALUE(10, SampleIndex)
149+
D3D_SYSTEM_VALUE(11, FinalQuadEdgeTessfactor)
150+
D3D_SYSTEM_VALUE(12, FinalQuadInsideTessfactor)
151+
D3D_SYSTEM_VALUE(13, FinalTriEdgeTessfactor)
152+
D3D_SYSTEM_VALUE(14, FinalTriInsideTessfactor)
153+
D3D_SYSTEM_VALUE(15, FinalLineDetailTessfactor)
154+
D3D_SYSTEM_VALUE(16, FinalLineDensityTessfactor)
155+
D3D_SYSTEM_VALUE(23, Barycentrics)
156+
D3D_SYSTEM_VALUE(24, ShadingRate)
157+
D3D_SYSTEM_VALUE(25, CullPrimitive)
158+
D3D_SYSTEM_VALUE(64, Target)
159+
D3D_SYSTEM_VALUE(65, Depth)
160+
D3D_SYSTEM_VALUE(66, Coverage)
161+
D3D_SYSTEM_VALUE(67, DepthGE)
162+
D3D_SYSTEM_VALUE(68, DepthLE)
163+
D3D_SYSTEM_VALUE(69, StencilRef)
164+
D3D_SYSTEM_VALUE(70, InnerCoverage)
165+
166+
#undef D3D_SYSTEM_VALUE
167+
168+
#endif

llvm/include/llvm/MC/DXContainerPSVInfo.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ struct PSVRuntimeInfo {
8686
}
8787
};
8888

89+
class Signature {
90+
struct Parameter {
91+
uint32_t Stream;
92+
StringRef Name;
93+
uint32_t Index;
94+
dxbc::D3DSystemValue SystemValue;
95+
dxbc::SigComponentType CompType;
96+
uint32_t Register;
97+
uint8_t Mask;
98+
uint8_t ExclusiveMask;
99+
dxbc::SigMinPrecision MinPrecision;
100+
};
101+
102+
SmallVector<Parameter> Params;
103+
104+
public:
105+
void addParam(uint32_t Stream, StringRef Name, uint32_t Index,
106+
dxbc::D3DSystemValue SystemValue,
107+
dxbc::SigComponentType CompType, uint32_t Register,
108+
uint8_t Mask, uint8_t ExclusiveMask,
109+
dxbc::SigMinPrecision MinPrecision) {
110+
Params.push_back(Parameter{Stream, Name, Index, SystemValue, CompType,
111+
Register, Mask, ExclusiveMask, MinPrecision});
112+
}
113+
114+
void write(raw_ostream &OS);
115+
};
116+
89117
} // namespace mcdxbc
90118
} // namespace llvm
91119

0 commit comments

Comments
 (0)