Skip to content

Commit 4aaa643

Browse files
committed
[mlir][dxsa] Add dcl_output_topology instruction
Example: dxsa.dcl_output_topology trianglestrip Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 856b5d3 commit 4aaa643

8 files changed

Lines changed: 73 additions & 0 deletions

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ def DXSA_GlobalFlagsAttr :
6262
let assemblyFormat = "`<` $value `>`";
6363
}
6464

65+
def DXSA_OutputPrimitiveTopology_PointList : I32EnumAttrCase<"pointlist", 0>;
66+
def DXSA_OutputPrimitiveTopology_LineStrip : I32EnumAttrCase<"linestrip", 1>;
67+
def DXSA_OutputPrimitiveTopology_TriangleStrip : I32EnumAttrCase<"trianglestrip", 2>;
68+
69+
def DXSA_OutputPrimitiveTopology : I32EnumAttr<
70+
"OutputPrimitiveTopology", "shader output primitive topology", [
71+
DXSA_OutputPrimitiveTopology_PointList,
72+
DXSA_OutputPrimitiveTopology_LineStrip,
73+
DXSA_OutputPrimitiveTopology_TriangleStrip
74+
]> {
75+
let cppNamespace = "::mlir::dxsa";
76+
let genSpecializedAttr = 0;
77+
}
78+
79+
def DXSA_OutputPrimitiveTopologyAttr :
80+
EnumAttr<DXSADialect, DXSA_OutputPrimitiveTopology,
81+
"output_primitive_topology"> {
82+
let assemblyFormat = "$value";
83+
}
84+
6585
//===----------------------------------------------------------------------===//
6686
// DXSA op definitions
6787
//===----------------------------------------------------------------------===//
@@ -158,4 +178,20 @@ def DXSA_DclTemps : DXSA_Op<"dcl_temps"> {
158178
let assemblyFormat = [{ $count attr-dict }];
159179
}
160180

181+
def DXSA_DclOutputTopology : DXSA_Op<"dcl_output_topology"> {
182+
let summary = "declare what primitive topology the shader generates as output";
183+
let description = [{
184+
The `dxsa.dcl_output_topology` operation declares the primitive topology
185+
that the shader generates as output.
186+
187+
Example:
188+
189+
```mlir
190+
dxsa.dcl_output_topology trianglestrip
191+
```
192+
}];
193+
let arguments = (ins DXSA_OutputPrimitiveTopologyAttr:$topology);
194+
let assemblyFormat = "$topology attr-dict";
195+
}
196+
161197
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ class DXBuilder {
516516
builder.getI32IntegerAttr(count));
517517
}
518518

519+
Instruction buildDclOutputTopology(dxsa::OutputPrimitiveTopology topology,
520+
Location loc) {
521+
auto topologyAttr =
522+
dxsa::OutputPrimitiveTopologyAttr::get(builder.getContext(), topology);
523+
return dxsa::DclOutputTopology::create(builder, loc, topologyAttr);
524+
}
525+
519526
private:
520527
MLIRContext *context;
521528
ModuleOp module;
@@ -831,6 +838,24 @@ class Parser {
831838
return builder.buildDclTemps(count, loc);
832839
}
833840

841+
FailureOr<Instruction> parseDclOutputTopology(uint32_t opcodeToken,
842+
Location loc) {
843+
auto topology = DECODE_D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY(opcodeToken);
844+
switch (topology) {
845+
case D3D10_SB_PRIMITIVE_TOPOLOGY_POINTLIST:
846+
return builder.buildDclOutputTopology(
847+
dxsa::OutputPrimitiveTopology::pointlist, loc);
848+
case D3D10_SB_PRIMITIVE_TOPOLOGY_LINESTRIP:
849+
return builder.buildDclOutputTopology(
850+
dxsa::OutputPrimitiveTopology::linestrip, loc);
851+
case D3D10_SB_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP:
852+
return builder.buildDclOutputTopology(
853+
dxsa::OutputPrimitiveTopology::trianglestrip, loc);
854+
default:
855+
return emitError(loc, "invalid output primitive topology");
856+
}
857+
}
858+
834859
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
835860
Instruction &out) {
836861
FailureOr<Instruction> result;
@@ -841,6 +866,9 @@ class Parser {
841866
case D3D10_SB_OPCODE_DCL_TEMPS:
842867
result = parseDclTemps(loc);
843868
break;
869+
case D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
870+
result = parseDclOutputTopology(opcodeToken, loc);
871+
break;
844872
default:
845873
return std::nullopt;
846874
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_output_topology_linestrip.bin | FileCheck %s
2+
3+
// CHECK: dxsa.dcl_output_topology linestrip
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_output_topology_pointlist.bin | FileCheck %s
2+
3+
// CHECK: dxsa.dcl_output_topology pointlist
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_output_topology_trianglestrip.bin | FileCheck %s
2+
3+
// CHECK: dxsa.dcl_output_topology trianglestrip
4 Bytes
Binary file not shown.
4 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)