Skip to content

Commit c349e73

Browse files
committed
[mlir][dxsa] Add dcl_input_ps, dcl_input_ps_siv and dcl_input_ps_sgv instructions
Example: dxsa.dcl_input_ps linear %v0 dxsa.dcl_input_ps_siv linear %v1, position dxsa.dcl_input_ps_sgv %v2, sampleIndex Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent cd6fa32 commit c349e73

8 files changed

Lines changed: 332 additions & 1 deletion

File tree

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,96 @@ def DXSA_OutputPrimitiveTopologyAttr :
9393
let assemblyFormat = "$value";
9494
}
9595

96+
def DXSA_InterpolationMode_Constant : I32EnumAttrCase<"constant", 1>;
97+
def DXSA_InterpolationMode_Linear : I32EnumAttrCase<"linear", 2>;
98+
def DXSA_InterpolationMode_LinearCentroid : I32EnumAttrCase<"linearCentroid", 3>;
99+
def DXSA_InterpolationMode_LinearNoPerspective : I32EnumAttrCase<"linearNoPerspective", 4>;
100+
def DXSA_InterpolationMode_LinearNoPerspectiveCentroid : I32EnumAttrCase<"linearNoPerspectiveCentroid", 5>;
101+
def DXSA_InterpolationMode_LinearSample : I32EnumAttrCase<"linearSample", 6>;
102+
def DXSA_InterpolationMode_LinearNoPerspectiveSample : I32EnumAttrCase<"linearNoPerspectiveSample", 7>;
103+
104+
def DXSA_InterpolationMode : I32EnumAttr<
105+
"InterpolationMode", "pixel shader interpolation mode", [
106+
DXSA_InterpolationMode_Constant,
107+
DXSA_InterpolationMode_Linear,
108+
DXSA_InterpolationMode_LinearCentroid,
109+
DXSA_InterpolationMode_LinearNoPerspective,
110+
DXSA_InterpolationMode_LinearNoPerspectiveCentroid,
111+
DXSA_InterpolationMode_LinearSample,
112+
DXSA_InterpolationMode_LinearNoPerspectiveSample
113+
]> {
114+
let cppNamespace = "::mlir::dxsa";
115+
let genSpecializedAttr = 0;
116+
}
117+
118+
def DXSA_InterpolationModeAttr :
119+
EnumAttr<DXSADialect, DXSA_InterpolationMode, "interpolation_mode"> {
120+
let assemblyFormat = "$value";
121+
}
122+
123+
def DXSA_SystemValueName_Position : I32EnumAttrCase<"position", 1>;
124+
def DXSA_SystemValueName_ClipDistance : I32EnumAttrCase<"clipDistance", 2>;
125+
def DXSA_SystemValueName_CullDistance : I32EnumAttrCase<"cullDistance", 3>;
126+
def DXSA_SystemValueName_RenderTargetArrayIndex : I32EnumAttrCase<"renderTargetArrayIndex", 4>;
127+
def DXSA_SystemValueName_ViewportArrayIndex : I32EnumAttrCase<"viewportArrayIndex", 5>;
128+
def DXSA_SystemValueName_VertexId : I32EnumAttrCase<"vertexID", 6>;
129+
def DXSA_SystemValueName_PrimitiveId : I32EnumAttrCase<"primitiveID", 7>;
130+
def DXSA_SystemValueName_InstanceId : I32EnumAttrCase<"instanceID", 8>;
131+
def DXSA_SystemValueName_IsFrontFace : I32EnumAttrCase<"isFrontFace", 9>;
132+
def DXSA_SystemValueName_SampleIndex : I32EnumAttrCase<"sampleIndex", 10>;
133+
def DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq0EdgeTessFactor", 11>;
134+
def DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq0EdgeTessFactor", 12>;
135+
def DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq1EdgeTessFactor", 13>;
136+
def DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq1EdgeTessFactor", 14>;
137+
def DXSA_SystemValueName_FinalQuadUInsideTessFactor : I32EnumAttrCase<"finalQuadUInsideTessFactor", 15>;
138+
def DXSA_SystemValueName_FinalQuadVInsideTessFactor : I32EnumAttrCase<"finalQuadVInsideTessFactor", 16>;
139+
def DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor : I32EnumAttrCase<"finalTriUeq0EdgeTessFactor", 17>;
140+
def DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor : I32EnumAttrCase<"finalTriVeq0EdgeTessFactor", 18>;
141+
def DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor : I32EnumAttrCase<"finalTriWeq0EdgeTessFactor", 19>;
142+
def DXSA_SystemValueName_FinalTriInsideTessFactor : I32EnumAttrCase<"finalTriInsideTessFactor", 20>;
143+
def DXSA_SystemValueName_FinalLineDetailTessFactor : I32EnumAttrCase<"finalLineDetailTessFactor", 21>;
144+
def DXSA_SystemValueName_FinalLineDensityTessFactor : I32EnumAttrCase<"finalLineDensityTessFactor", 22>;
145+
def DXSA_SystemValueName_Barycentrics : I32EnumAttrCase<"barycentrics", 23>;
146+
def DXSA_SystemValueName_ShadingRate : I32EnumAttrCase<"shadingRate", 24>;
147+
def DXSA_SystemValueName_CullPrimitive : I32EnumAttrCase<"cullPrimitive", 25>;
148+
149+
def DXSA_SystemValueName : I32EnumAttr<
150+
"SystemValueName", "DXBC system interpreted/generated value name", [
151+
DXSA_SystemValueName_Position,
152+
DXSA_SystemValueName_ClipDistance,
153+
DXSA_SystemValueName_CullDistance,
154+
DXSA_SystemValueName_RenderTargetArrayIndex,
155+
DXSA_SystemValueName_ViewportArrayIndex,
156+
DXSA_SystemValueName_VertexId,
157+
DXSA_SystemValueName_PrimitiveId,
158+
DXSA_SystemValueName_InstanceId,
159+
DXSA_SystemValueName_IsFrontFace,
160+
DXSA_SystemValueName_SampleIndex,
161+
DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor,
162+
DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor,
163+
DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor,
164+
DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor,
165+
DXSA_SystemValueName_FinalQuadUInsideTessFactor,
166+
DXSA_SystemValueName_FinalQuadVInsideTessFactor,
167+
DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor,
168+
DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor,
169+
DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor,
170+
DXSA_SystemValueName_FinalTriInsideTessFactor,
171+
DXSA_SystemValueName_FinalLineDetailTessFactor,
172+
DXSA_SystemValueName_FinalLineDensityTessFactor,
173+
DXSA_SystemValueName_Barycentrics,
174+
DXSA_SystemValueName_ShadingRate,
175+
DXSA_SystemValueName_CullPrimitive
176+
]> {
177+
let cppNamespace = "::mlir::dxsa";
178+
let genSpecializedAttr = 0;
179+
}
180+
181+
def DXSA_SystemValueNameAttr :
182+
EnumAttr<DXSADialect, DXSA_SystemValueName, "system_value_name"> {
183+
let assemblyFormat = "$value";
184+
}
185+
96186
//===----------------------------------------------------------------------===//
97187
// DXSA op definitions
98188
//===----------------------------------------------------------------------===//
@@ -271,4 +361,57 @@ def DXSA_DclOutputTopology : DXSA_Op<"dcl_output_topology"> {
271361
let assemblyFormat = "$topology attr-dict";
272362
}
273363

364+
def DXSA_DclInputPs : DXSA_Op<"dcl_input_ps"> {
365+
let summary = "declares a pixel shader input";
366+
let description = [{
367+
The `dxsa.dcl_input_ps` operation declares a pixel shader input
368+
with the given attribute interpolation mode.
369+
370+
Example:
371+
372+
```mlir
373+
dxsa.dcl_input_ps linear %v0
374+
```
375+
}];
376+
let arguments = (ins DXSA_InterpolationModeAttr:$mode,
377+
DXSA_OperandType:$operand);
378+
let assemblyFormat = "$mode $operand attr-dict";
379+
}
380+
381+
def DXSA_DclInputPsSiv : DXSA_Op<"dcl_input_ps_siv"> {
382+
let summary = "declares a pixel shader system-interpreted input";
383+
let description = [{
384+
The `dxsa.dcl_input_ps_siv` operation declares a pixel shader input
385+
that receives a System Interpreted Value, with the given attribute
386+
interpolation mode.
387+
388+
Example:
389+
390+
```mlir
391+
dxsa.dcl_input_ps_siv linear %v0, position
392+
```
393+
}];
394+
let arguments = (ins DXSA_InterpolationModeAttr:$mode,
395+
DXSA_OperandType:$operand,
396+
DXSA_SystemValueNameAttr:$name);
397+
let assemblyFormat = "$mode $operand `,` $name attr-dict";
398+
}
399+
400+
def DXSA_DclInputPsSgv : DXSA_Op<"dcl_input_ps_sgv"> {
401+
let summary = "declares a pixel shader system-generated input";
402+
let description = [{
403+
The `dxsa.dcl_input_ps_sgv` operation declares a pixel shader input
404+
that receives a System Generated Value.
405+
406+
Example:
407+
408+
```mlir
409+
dxsa.dcl_input_ps_sgv %v0, sampleIndex
410+
```
411+
}];
412+
let arguments = (ins DXSA_OperandType:$operand,
413+
DXSA_SystemValueNameAttr:$name);
414+
let assemblyFormat = "$operand `,` $name attr-dict";
415+
}
416+
274417
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,35 @@ class DXBuilder {
546546
return dxsa::DclOutputTopology::create(builder, loc, outputTopologyAttr);
547547
}
548548

549+
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
550+
Operand operand, Location loc) {
551+
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
552+
builder.getContext(), interpolationMode);
553+
return dxsa::DclInputPs::create(builder, loc, interpolationModeAttr,
554+
operand);
555+
}
556+
557+
Instruction buildDclInputPsSiv(dxsa::InterpolationMode interpolationMode,
558+
Operand operand,
559+
dxsa::SystemValueName systemValueName,
560+
Location loc) {
561+
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
562+
builder.getContext(), interpolationMode);
563+
auto systemValueNameAttr =
564+
dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName);
565+
return dxsa::DclInputPsSiv::create(builder, loc, interpolationModeAttr,
566+
operand, systemValueNameAttr);
567+
}
568+
569+
Instruction buildDclInputPsSgv(Operand operand,
570+
dxsa::SystemValueName systemValueName,
571+
Location loc) {
572+
auto systemValueNameAttr =
573+
dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName);
574+
return dxsa::DclInputPsSgv::create(builder, loc, operand,
575+
systemValueNameAttr);
576+
}
577+
549578
private:
550579
MLIRContext *context;
551580
ModuleOp module;
@@ -597,7 +626,7 @@ class Parser {
597626
}
598627

599628
FailureOr<OperandComponents> parseOperandComponents(uint32_t token) {
600-
OperandComponents components;
629+
OperandComponents components{};
601630
switch (DECODE_D3D10_SB_OPERAND_NUM_COMPONENTS(token)) {
602631
case D3D10_SB_OPERAND_0_COMPONENT: {
603632
components.num = 0;
@@ -933,6 +962,69 @@ class Parser {
933962
return builder.buildDclOutputTopology(*outputTopology, loc);
934963
}
935964

965+
FailureOr<dxsa::InterpolationMode>
966+
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
967+
auto rawInterpolationMode =
968+
DECODE_D3D10_SB_INPUT_INTERPOLATION_MODE(opcodeToken);
969+
auto interpolationMode =
970+
dxsa::symbolizeInterpolationMode(rawInterpolationMode);
971+
if (!interpolationMode)
972+
return emitError(loc, "unknown interpolation mode: ")
973+
<< rawInterpolationMode;
974+
return *interpolationMode;
975+
}
976+
977+
FailureOr<dxsa::SystemValueName> parseSystemValueName(Location loc) {
978+
Token nameToken = parseToken();
979+
if (failed(nameToken))
980+
return failure();
981+
auto rawSystemValueName = DECODE_D3D10_SB_NAME(*nameToken);
982+
auto systemValueName = dxsa::symbolizeSystemValueName(rawSystemValueName);
983+
if (!systemValueName)
984+
return emitError(loc, "unknown system value name: ")
985+
<< rawSystemValueName;
986+
return *systemValueName;
987+
}
988+
989+
FailureOr<Instruction> parseDclInputPs(uint32_t opcodeToken, Location loc) {
990+
FailureOr<dxsa::InterpolationMode> interpolationMode =
991+
parseInterpolationMode(opcodeToken, loc);
992+
if (failed(interpolationMode))
993+
return failure();
994+
FailureOr<Operand> operand = parseOperand();
995+
if (failed(operand))
996+
return failure();
997+
return builder.buildDclInputPs(*interpolationMode, *operand, loc);
998+
}
999+
1000+
FailureOr<Instruction> parseDclInputPsSiv(uint32_t opcodeToken,
1001+
Location loc) {
1002+
FailureOr<dxsa::InterpolationMode> interpolationMode =
1003+
parseInterpolationMode(opcodeToken, loc);
1004+
if (failed(interpolationMode))
1005+
return failure();
1006+
FailureOr<Operand> operand = parseOperand();
1007+
if (failed(operand))
1008+
return failure();
1009+
FailureOr<dxsa::SystemValueName> systemValueName =
1010+
parseSystemValueName(getLocation());
1011+
if (failed(systemValueName))
1012+
return failure();
1013+
return builder.buildDclInputPsSiv(*interpolationMode, *operand,
1014+
*systemValueName, loc);
1015+
}
1016+
1017+
FailureOr<Instruction> parseDclInputPsSgv(Location loc) {
1018+
FailureOr<Operand> operand = parseOperand();
1019+
if (failed(operand))
1020+
return failure();
1021+
FailureOr<dxsa::SystemValueName> systemValueName =
1022+
parseSystemValueName(getLocation());
1023+
if (failed(systemValueName))
1024+
return failure();
1025+
return builder.buildDclInputPsSgv(*operand, *systemValueName, loc);
1026+
}
1027+
9361028
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
9371029
Instruction &out) {
9381030
FailureOr<Instruction> result;
@@ -955,6 +1047,15 @@ class Parser {
9551047
case D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
9561048
result = parseDclOutputTopology(opcodeToken, loc);
9571049
break;
1050+
case D3D10_SB_OPCODE_DCL_INPUT_PS:
1051+
result = parseDclInputPs(opcodeToken, loc);
1052+
break;
1053+
case D3D10_SB_OPCODE_DCL_INPUT_PS_SIV:
1054+
result = parseDclInputPsSiv(opcodeToken, loc);
1055+
break;
1056+
case D3D10_SB_OPCODE_DCL_INPUT_PS_SGV:
1057+
result = parseDclInputPsSgv(loc);
1058+
break;
9581059
default:
9591060
return std::nullopt;
9601061
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps.bin | FileCheck %s
2+
3+
// CHECK-LABEL: module
4+
module {
5+
// dcl_input_ps constant v0.x
6+
// CHECK: %0 = dxsa.index.imm {imm = 0 : i32}
7+
// CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
8+
// CHECK-NEXT: dxsa.dcl_input_ps constant %1
9+
10+
// dcl_input_ps linear v1.x
11+
// CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32}
12+
// CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
13+
// CHECK-NEXT: dxsa.dcl_input_ps linear %3
14+
15+
// dcl_input_ps linearCentroid v2.x
16+
// CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32}
17+
// CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
18+
// CHECK-NEXT: dxsa.dcl_input_ps linearCentroid %5
19+
20+
// dcl_input_ps linearNoPerspective v3.x
21+
// CHECK-NEXT: %6 = dxsa.index.imm {imm = 3 : i32}
22+
// CHECK-NEXT: %7 = dxsa.operand %6 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
23+
// CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspective %7
24+
25+
// dcl_input_ps linearNoPerspectiveCentroid v4.x
26+
// CHECK-NEXT: %8 = dxsa.index.imm {imm = 4 : i32}
27+
// CHECK-NEXT: %9 = dxsa.operand %8 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
28+
// CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspectiveCentroid %9
29+
30+
// dcl_input_ps linearSample v5.x
31+
// CHECK-NEXT: %10 = dxsa.index.imm {imm = 5 : i32}
32+
// CHECK-NEXT: %11 = dxsa.operand %10 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
33+
// CHECK-NEXT: dxsa.dcl_input_ps linearSample %11
34+
35+
// dcl_input_ps linearNoPerspectiveSample v6.x
36+
// CHECK-NEXT: %12 = dxsa.index.imm {imm = 6 : i32}
37+
// CHECK-NEXT: %13 = dxsa.operand %12 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
38+
// CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspectiveSample %13
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps_sgv.bin | FileCheck %s
2+
3+
// CHECK-LABEL: module
4+
module {
5+
// dcl_input_ps_sgv v0.x, primitiveID
6+
// CHECK: %0 = dxsa.index.imm {imm = 0 : i32}
7+
// CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
8+
// CHECK-NEXT: dxsa.dcl_input_ps_sgv %1, primitiveID
9+
10+
// dcl_input_ps_sgv v1.x, isFrontFace
11+
// CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32}
12+
// CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
13+
// CHECK-NEXT: dxsa.dcl_input_ps_sgv %3, isFrontFace
14+
15+
// dcl_input_ps_sgv v2.x, sampleIndex
16+
// CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32}
17+
// CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
18+
// CHECK-NEXT: dxsa.dcl_input_ps_sgv %5, sampleIndex
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps_siv.bin | FileCheck %s
2+
3+
// CHECK-LABEL: module
4+
module {
5+
// dcl_input_ps_siv linear v0.x, position
6+
// CHECK: %0 = dxsa.index.imm {imm = 0 : i32}
7+
// CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
8+
// CHECK-NEXT: dxsa.dcl_input_ps_siv linear %1, position
9+
10+
// dcl_input_ps_siv linear v1.x, clipDistance
11+
// CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32}
12+
// CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
13+
// CHECK-NEXT: dxsa.dcl_input_ps_siv linear %3, clipDistance
14+
15+
// dcl_input_ps_siv linear v2.x, cullDistance
16+
// CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32}
17+
// CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
18+
// CHECK-NEXT: dxsa.dcl_input_ps_siv linear %5, cullDistance
19+
20+
// dcl_input_ps_siv linear v3.x, renderTargetArrayIndex
21+
// CHECK-NEXT: %6 = dxsa.index.imm {imm = 3 : i32}
22+
// CHECK-NEXT: %7 = dxsa.operand %6 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
23+
// CHECK-NEXT: dxsa.dcl_input_ps_siv linear %7, renderTargetArrayIndex
24+
25+
// dcl_input_ps_siv linear v4.x, viewportArrayIndex
26+
// CHECK-NEXT: %8 = dxsa.index.imm {imm = 4 : i32}
27+
// CHECK-NEXT: %9 = dxsa.operand %8 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32}
28+
// CHECK-NEXT: dxsa.dcl_input_ps_siv linear %9, viewportArrayIndex
29+
}
84 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
80 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)