Skip to content

Commit b95d157

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 b95d157

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

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", 1>;
66+
def DXSA_OutputPrimitiveTopology_LineStrip : I32EnumAttrCase<"linestrip", 3>;
67+
def DXSA_OutputPrimitiveTopology_TriangleStrip : I32EnumAttrCase<"trianglestrip", 5>;
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,14 @@ class DXBuilder {
516516
builder.getI32IntegerAttr(count));
517517
}
518518

519+
Instruction
520+
buildDclOutputTopology(dxsa::OutputPrimitiveTopology outputTopology,
521+
Location loc) {
522+
auto outputTopologyAttr = dxsa::OutputPrimitiveTopologyAttr::get(
523+
builder.getContext(), outputTopology);
524+
return dxsa::DclOutputTopology::create(builder, loc, outputTopologyAttr);
525+
}
526+
519527
private:
520528
MLIRContext *context;
521529
ModuleOp module;
@@ -831,6 +839,18 @@ class Parser {
831839
return builder.buildDclTemps(count, loc);
832840
}
833841

842+
FailureOr<Instruction> parseDclOutputTopology(uint32_t opcodeToken,
843+
Location loc) {
844+
auto rawOutputTopology =
845+
DECODE_D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY(opcodeToken);
846+
auto outputTopology =
847+
dxsa::symbolizeOutputPrimitiveTopology(rawOutputTopology);
848+
if (!outputTopology)
849+
return emitError(loc, "unknown output primitive topology: ")
850+
<< rawOutputTopology;
851+
return builder.buildDclOutputTopology(*outputTopology, loc);
852+
}
853+
834854
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
835855
Instruction &out) {
836856
FailureOr<Instruction> result;
@@ -841,6 +861,9 @@ class Parser {
841861
case D3D10_SB_OPCODE_DCL_TEMPS:
842862
result = parseDclTemps(loc);
843863
break;
864+
case D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
865+
result = parseDclOutputTopology(opcodeToken, loc);
866+
break;
844867
default:
845868
return std::nullopt;
846869
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_output_topology.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_output_topology pointlist
5+
// CHECK-NEXT: dxsa.dcl_output_topology linestrip
6+
// CHECK-NEXT: dxsa.dcl_output_topology trianglestrip
7+
// CHECK-NEXT: }
12 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)