Skip to content

Commit fdd3b7d

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 fe4345d commit fdd3b7d

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
@@ -163,6 +163,96 @@ def DXSA_InputPrimitiveAttr :
163163
let assemblyFormat = "$value";
164164
}
165165

166+
def DXSA_InterpolationMode_Constant : I32EnumAttrCase<"constant", 1>;
167+
def DXSA_InterpolationMode_Linear : I32EnumAttrCase<"linear", 2>;
168+
def DXSA_InterpolationMode_LinearCentroid : I32EnumAttrCase<"linearCentroid", 3>;
169+
def DXSA_InterpolationMode_LinearNoPerspective : I32EnumAttrCase<"linearNoPerspective", 4>;
170+
def DXSA_InterpolationMode_LinearNoPerspectiveCentroid : I32EnumAttrCase<"linearNoPerspectiveCentroid", 5>;
171+
def DXSA_InterpolationMode_LinearSample : I32EnumAttrCase<"linearSample", 6>;
172+
def DXSA_InterpolationMode_LinearNoPerspectiveSample : I32EnumAttrCase<"linearNoPerspectiveSample", 7>;
173+
174+
def DXSA_InterpolationMode : I32EnumAttr<
175+
"InterpolationMode", "pixel shader interpolation mode", [
176+
DXSA_InterpolationMode_Constant,
177+
DXSA_InterpolationMode_Linear,
178+
DXSA_InterpolationMode_LinearCentroid,
179+
DXSA_InterpolationMode_LinearNoPerspective,
180+
DXSA_InterpolationMode_LinearNoPerspectiveCentroid,
181+
DXSA_InterpolationMode_LinearSample,
182+
DXSA_InterpolationMode_LinearNoPerspectiveSample
183+
]> {
184+
let cppNamespace = "::mlir::dxsa";
185+
let genSpecializedAttr = 0;
186+
}
187+
188+
def DXSA_InterpolationModeAttr :
189+
EnumAttr<DXSADialect, DXSA_InterpolationMode, "interpolation_mode"> {
190+
let assemblyFormat = "$value";
191+
}
192+
193+
def DXSA_SystemValueName_Position : I32EnumAttrCase<"position", 1>;
194+
def DXSA_SystemValueName_ClipDistance : I32EnumAttrCase<"clipDistance", 2>;
195+
def DXSA_SystemValueName_CullDistance : I32EnumAttrCase<"cullDistance", 3>;
196+
def DXSA_SystemValueName_RenderTargetArrayIndex : I32EnumAttrCase<"renderTargetArrayIndex", 4>;
197+
def DXSA_SystemValueName_ViewportArrayIndex : I32EnumAttrCase<"viewportArrayIndex", 5>;
198+
def DXSA_SystemValueName_VertexId : I32EnumAttrCase<"vertexID", 6>;
199+
def DXSA_SystemValueName_PrimitiveId : I32EnumAttrCase<"primitiveID", 7>;
200+
def DXSA_SystemValueName_InstanceId : I32EnumAttrCase<"instanceID", 8>;
201+
def DXSA_SystemValueName_IsFrontFace : I32EnumAttrCase<"isFrontFace", 9>;
202+
def DXSA_SystemValueName_SampleIndex : I32EnumAttrCase<"sampleIndex", 10>;
203+
def DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq0EdgeTessFactor", 11>;
204+
def DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq0EdgeTessFactor", 12>;
205+
def DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq1EdgeTessFactor", 13>;
206+
def DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq1EdgeTessFactor", 14>;
207+
def DXSA_SystemValueName_FinalQuadUInsideTessFactor : I32EnumAttrCase<"finalQuadUInsideTessFactor", 15>;
208+
def DXSA_SystemValueName_FinalQuadVInsideTessFactor : I32EnumAttrCase<"finalQuadVInsideTessFactor", 16>;
209+
def DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor : I32EnumAttrCase<"finalTriUeq0EdgeTessFactor", 17>;
210+
def DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor : I32EnumAttrCase<"finalTriVeq0EdgeTessFactor", 18>;
211+
def DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor : I32EnumAttrCase<"finalTriWeq0EdgeTessFactor", 19>;
212+
def DXSA_SystemValueName_FinalTriInsideTessFactor : I32EnumAttrCase<"finalTriInsideTessFactor", 20>;
213+
def DXSA_SystemValueName_FinalLineDetailTessFactor : I32EnumAttrCase<"finalLineDetailTessFactor", 21>;
214+
def DXSA_SystemValueName_FinalLineDensityTessFactor : I32EnumAttrCase<"finalLineDensityTessFactor", 22>;
215+
def DXSA_SystemValueName_Barycentrics : I32EnumAttrCase<"barycentrics", 23>;
216+
def DXSA_SystemValueName_ShadingRate : I32EnumAttrCase<"shadingRate", 24>;
217+
def DXSA_SystemValueName_CullPrimitive : I32EnumAttrCase<"cullPrimitive", 25>;
218+
219+
def DXSA_SystemValueName : I32EnumAttr<
220+
"SystemValueName", "DXBC system interpreted/generated value name", [
221+
DXSA_SystemValueName_Position,
222+
DXSA_SystemValueName_ClipDistance,
223+
DXSA_SystemValueName_CullDistance,
224+
DXSA_SystemValueName_RenderTargetArrayIndex,
225+
DXSA_SystemValueName_ViewportArrayIndex,
226+
DXSA_SystemValueName_VertexId,
227+
DXSA_SystemValueName_PrimitiveId,
228+
DXSA_SystemValueName_InstanceId,
229+
DXSA_SystemValueName_IsFrontFace,
230+
DXSA_SystemValueName_SampleIndex,
231+
DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor,
232+
DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor,
233+
DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor,
234+
DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor,
235+
DXSA_SystemValueName_FinalQuadUInsideTessFactor,
236+
DXSA_SystemValueName_FinalQuadVInsideTessFactor,
237+
DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor,
238+
DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor,
239+
DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor,
240+
DXSA_SystemValueName_FinalTriInsideTessFactor,
241+
DXSA_SystemValueName_FinalLineDetailTessFactor,
242+
DXSA_SystemValueName_FinalLineDensityTessFactor,
243+
DXSA_SystemValueName_Barycentrics,
244+
DXSA_SystemValueName_ShadingRate,
245+
DXSA_SystemValueName_CullPrimitive
246+
]> {
247+
let cppNamespace = "::mlir::dxsa";
248+
let genSpecializedAttr = 0;
249+
}
250+
251+
def DXSA_SystemValueNameAttr :
252+
EnumAttr<DXSADialect, DXSA_SystemValueName, "system_value_name"> {
253+
let assemblyFormat = "$value";
254+
}
255+
166256
//===----------------------------------------------------------------------===//
167257
// DXSA op definitions
168258
//===----------------------------------------------------------------------===//
@@ -391,4 +481,57 @@ def DXSA_DclInputPrimitive : DXSA_Op<"dcl_input_primitive"> {
391481
let assemblyFormat = "$type attr-dict";
392482
}
393483

484+
def DXSA_DclInputPs : DXSA_Op<"dcl_input_ps"> {
485+
let summary = "declares a pixel shader input";
486+
let description = [{
487+
The `dxsa.dcl_input_ps` operation declares a pixel shader input
488+
with the given attribute interpolation mode.
489+
490+
Example:
491+
492+
```mlir
493+
dxsa.dcl_input_ps linear %v0
494+
```
495+
}];
496+
let arguments = (ins DXSA_InterpolationModeAttr:$mode,
497+
DXSA_OperandType:$operand);
498+
let assemblyFormat = "$mode $operand attr-dict";
499+
}
500+
501+
def DXSA_DclInputPsSiv : DXSA_Op<"dcl_input_ps_siv"> {
502+
let summary = "declares a pixel shader system-interpreted input";
503+
let description = [{
504+
The `dxsa.dcl_input_ps_siv` operation declares a pixel shader input
505+
that receives a System Interpreted Value, with the given attribute
506+
interpolation mode.
507+
508+
Example:
509+
510+
```mlir
511+
dxsa.dcl_input_ps_siv linear %v0, position
512+
```
513+
}];
514+
let arguments = (ins DXSA_InterpolationModeAttr:$mode,
515+
DXSA_OperandType:$operand,
516+
DXSA_SystemValueNameAttr:$name);
517+
let assemblyFormat = "$mode $operand `,` $name attr-dict";
518+
}
519+
520+
def DXSA_DclInputPsSgv : DXSA_Op<"dcl_input_ps_sgv"> {
521+
let summary = "declares a pixel shader system-generated input";
522+
let description = [{
523+
The `dxsa.dcl_input_ps_sgv` operation declares a pixel shader input
524+
that receives a System Generated Value.
525+
526+
Example:
527+
528+
```mlir
529+
dxsa.dcl_input_ps_sgv %v0, sampleIndex
530+
```
531+
}];
532+
let arguments = (ins DXSA_OperandType:$operand,
533+
DXSA_SystemValueNameAttr:$name);
534+
let assemblyFormat = "$operand `,` $name attr-dict";
535+
}
536+
394537
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,35 @@ class DXBuilder {
568568
return dxsa::DclInputPrimitive::create(builder, loc, inputPrimitiveAttr);
569569
}
570570

571+
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
572+
Operand operand, Location loc) {
573+
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
574+
builder.getContext(), interpolationMode);
575+
return dxsa::DclInputPs::create(builder, loc, interpolationModeAttr,
576+
operand);
577+
}
578+
579+
Instruction buildDclInputPsSiv(dxsa::InterpolationMode interpolationMode,
580+
Operand operand,
581+
dxsa::SystemValueName systemValueName,
582+
Location loc) {
583+
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
584+
builder.getContext(), interpolationMode);
585+
auto systemValueNameAttr =
586+
dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName);
587+
return dxsa::DclInputPsSiv::create(builder, loc, interpolationModeAttr,
588+
operand, systemValueNameAttr);
589+
}
590+
591+
Instruction buildDclInputPsSgv(Operand operand,
592+
dxsa::SystemValueName systemValueName,
593+
Location loc) {
594+
auto systemValueNameAttr =
595+
dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName);
596+
return dxsa::DclInputPsSgv::create(builder, loc, operand,
597+
systemValueNameAttr);
598+
}
599+
571600
private:
572601
MLIRContext *context;
573602
ModuleOp module;
@@ -619,7 +648,7 @@ class Parser {
619648
}
620649

621650
FailureOr<OperandComponents> parseOperandComponents(uint32_t token) {
622-
OperandComponents components;
651+
OperandComponents components{};
623652
switch (DECODE_D3D10_SB_OPERAND_NUM_COMPONENTS(token)) {
624653
case D3D10_SB_OPERAND_0_COMPONENT: {
625654
components.num = 0;
@@ -984,6 +1013,69 @@ class Parser {
9841013
return builder.buildDclInputPrimitive(*inputPrimitive, loc);
9851014
}
9861015

1016+
FailureOr<dxsa::InterpolationMode>
1017+
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
1018+
auto rawInterpolationMode =
1019+
DECODE_D3D10_SB_INPUT_INTERPOLATION_MODE(opcodeToken);
1020+
auto interpolationMode =
1021+
dxsa::symbolizeInterpolationMode(rawInterpolationMode);
1022+
if (!interpolationMode)
1023+
return emitError(loc, "unknown interpolation mode: ")
1024+
<< rawInterpolationMode;
1025+
return *interpolationMode;
1026+
}
1027+
1028+
FailureOr<dxsa::SystemValueName> parseSystemValueName(Location loc) {
1029+
Token nameToken = parseToken();
1030+
if (failed(nameToken))
1031+
return failure();
1032+
auto rawSystemValueName = DECODE_D3D10_SB_NAME(*nameToken);
1033+
auto systemValueName = dxsa::symbolizeSystemValueName(rawSystemValueName);
1034+
if (!systemValueName)
1035+
return emitError(loc, "unknown system value name: ")
1036+
<< rawSystemValueName;
1037+
return *systemValueName;
1038+
}
1039+
1040+
FailureOr<Instruction> parseDclInputPs(uint32_t opcodeToken, Location loc) {
1041+
FailureOr<dxsa::InterpolationMode> interpolationMode =
1042+
parseInterpolationMode(opcodeToken, loc);
1043+
if (failed(interpolationMode))
1044+
return failure();
1045+
FailureOr<Operand> operand = parseOperand();
1046+
if (failed(operand))
1047+
return failure();
1048+
return builder.buildDclInputPs(*interpolationMode, *operand, loc);
1049+
}
1050+
1051+
FailureOr<Instruction> parseDclInputPsSiv(uint32_t opcodeToken,
1052+
Location loc) {
1053+
FailureOr<dxsa::InterpolationMode> interpolationMode =
1054+
parseInterpolationMode(opcodeToken, loc);
1055+
if (failed(interpolationMode))
1056+
return failure();
1057+
FailureOr<Operand> operand = parseOperand();
1058+
if (failed(operand))
1059+
return failure();
1060+
FailureOr<dxsa::SystemValueName> systemValueName =
1061+
parseSystemValueName(getLocation());
1062+
if (failed(systemValueName))
1063+
return failure();
1064+
return builder.buildDclInputPsSiv(*interpolationMode, *operand,
1065+
*systemValueName, loc);
1066+
}
1067+
1068+
FailureOr<Instruction> parseDclInputPsSgv(Location loc) {
1069+
FailureOr<Operand> operand = parseOperand();
1070+
if (failed(operand))
1071+
return failure();
1072+
FailureOr<dxsa::SystemValueName> systemValueName =
1073+
parseSystemValueName(getLocation());
1074+
if (failed(systemValueName))
1075+
return failure();
1076+
return builder.buildDclInputPsSgv(*operand, *systemValueName, loc);
1077+
}
1078+
9871079
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
9881080
Instruction &out) {
9891081
FailureOr<Instruction> result;
@@ -1015,6 +1107,15 @@ class Parser {
10151107
case D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE:
10161108
result = parseDclInputPrimitive(opcodeToken, loc);
10171109
break;
1110+
case D3D10_SB_OPCODE_DCL_INPUT_PS:
1111+
result = parseDclInputPs(opcodeToken, loc);
1112+
break;
1113+
case D3D10_SB_OPCODE_DCL_INPUT_PS_SIV:
1114+
result = parseDclInputPsSiv(opcodeToken, loc);
1115+
break;
1116+
case D3D10_SB_OPCODE_DCL_INPUT_PS_SGV:
1117+
result = parseDclInputPsSgv(loc);
1118+
break;
10181119
default:
10191120
return std::nullopt;
10201121
}
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)