Skip to content

Commit cb372ef

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 d7483e9 commit cb372ef

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
@@ -73,6 +73,26 @@ def DXSA_TessellatorOutputPrimitiveTypeAttr :
7373
let assemblyFormat = "$value";
7474
}
7575

76+
def DXSA_OutputPrimitiveTopology_PointList : I32EnumAttrCase<"pointlist", 1>;
77+
def DXSA_OutputPrimitiveTopology_LineStrip : I32EnumAttrCase<"linestrip", 3>;
78+
def DXSA_OutputPrimitiveTopology_TriangleStrip : I32EnumAttrCase<"trianglestrip", 5>;
79+
80+
def DXSA_OutputPrimitiveTopology : I32EnumAttr<
81+
"OutputPrimitiveTopology", "shader output primitive topology", [
82+
DXSA_OutputPrimitiveTopology_PointList,
83+
DXSA_OutputPrimitiveTopology_LineStrip,
84+
DXSA_OutputPrimitiveTopology_TriangleStrip
85+
]> {
86+
let cppNamespace = "::mlir::dxsa";
87+
let genSpecializedAttr = 0;
88+
}
89+
90+
def DXSA_OutputPrimitiveTopologyAttr :
91+
EnumAttr<DXSADialect, DXSA_OutputPrimitiveTopology,
92+
"output_primitive_topology"> {
93+
let assemblyFormat = "$value";
94+
}
95+
7696
//===----------------------------------------------------------------------===//
7797
// DXSA op definitions
7898
//===----------------------------------------------------------------------===//
@@ -235,4 +255,20 @@ def DXSA_DclTessellatorOutputPrimitive
235255
let assemblyFormat = "$type attr-dict";
236256
}
237257

258+
def DXSA_DclOutputTopology : DXSA_Op<"dcl_output_topology"> {
259+
let summary = "declare what primitive topology the shader generates as output";
260+
let description = [{
261+
The `dxsa.dcl_output_topology` operation declares the primitive topology
262+
that the shader generates as output.
263+
264+
Example:
265+
266+
```mlir
267+
dxsa.dcl_output_topology trianglestrip
268+
```
269+
}];
270+
let arguments = (ins DXSA_OutputPrimitiveTopologyAttr:$topology);
271+
let assemblyFormat = "$topology attr-dict";
272+
}
273+
238274
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ class DXBuilder {
538538
outputPrimitiveTypeAttr);
539539
}
540540

541+
Instruction
542+
buildDclOutputTopology(dxsa::OutputPrimitiveTopology outputTopology,
543+
Location loc) {
544+
auto outputTopologyAttr = dxsa::OutputPrimitiveTopologyAttr::get(
545+
builder.getContext(), outputTopology);
546+
return dxsa::DclOutputTopology::create(builder, loc, outputTopologyAttr);
547+
}
548+
541549
private:
542550
MLIRContext *context;
543551
ModuleOp module;
@@ -913,6 +921,18 @@ class Parser {
913921
loc);
914922
}
915923

924+
FailureOr<Instruction> parseDclOutputTopology(uint32_t opcodeToken,
925+
Location loc) {
926+
auto rawOutputTopology =
927+
DECODE_D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY(opcodeToken);
928+
auto outputTopology =
929+
dxsa::symbolizeOutputPrimitiveTopology(rawOutputTopology);
930+
if (!outputTopology)
931+
return emitError(loc, "unknown output primitive topology: ")
932+
<< rawOutputTopology;
933+
return builder.buildDclOutputTopology(*outputTopology, loc);
934+
}
935+
916936
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
917937
Instruction &out) {
918938
FailureOr<Instruction> result;
@@ -932,6 +952,9 @@ class Parser {
932952
case D3D11_SB_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE:
933953
result = parseDclTessellatorOutputPrimitive(opcodeToken, loc);
934954
break;
955+
case D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
956+
result = parseDclOutputTopology(opcodeToken, loc);
957+
break;
935958
default:
936959
return std::nullopt;
937960
}
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)