Skip to content

Commit 78ee3be

Browse files
committed
[mlir][dxsa] Add dcl_stream instruction
Example: dxsa.dcl_stream 0 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent cdfb680 commit 78ee3be

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,4 +969,22 @@ def DXSA_DclConstantBuffer : DXSA_Op<"dcl_constant_buffer"> {
969969
let hasVerifier = 1;
970970
}
971971

972+
def DXSA_DclStream : DXSA_Op<"dcl_stream"> {
973+
let summary = "declares a geometry shader (GS) output stream";
974+
let description = [{
975+
The `dxsa.dcl_stream` operation declares a geometry shader (GS) output stream.
976+
977+
The `$index` must be in the range [0, 3].
978+
979+
Example:
980+
981+
```mlir
982+
dxsa.dcl_stream 0
983+
```
984+
}];
985+
let arguments = (ins ConfinedAttr<I32Attr,
986+
[IntNonNegative, IntMaxValue<3>]>:$index);
987+
let assemblyFormat = [{ $index attr-dict }];
988+
}
989+
972990
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,11 @@ class DXBuilder {
595595
return dxsa::DclMaxOutputVertexCount::create(builder, loc, count);
596596
}
597597

598+
Instruction buildDclStream(uint32_t index, Location loc) {
599+
return dxsa::DclStream::create(builder, loc,
600+
builder.getI32IntegerAttr(index));
601+
}
602+
598603
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
599604
Operand operand, Location loc) {
600605
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
@@ -1144,6 +1149,38 @@ class Parser {
11441149
return builder.buildDclMaxOutputVertexCount(count, loc);
11451150
}
11461151

1152+
FailureOr<Instruction> parseDclStream(Location loc) {
1153+
auto operandToken = parseToken();
1154+
FAILURE_IF_FAILED(operandToken);
1155+
1156+
auto operandType = DECODE_D3D10_SB_OPERAND_TYPE(*operandToken);
1157+
if (operandType != D3D11_SB_OPERAND_TYPE_STREAM)
1158+
return emitError(loc, "unexpected operand type: ") << operandType;
1159+
1160+
if (DECODE_IS_D3D10_SB_OPERAND_EXTENDED(*operandToken))
1161+
return emitError(loc, "extended operand tokens are not supported");
1162+
1163+
auto numComponents = DECODE_D3D10_SB_OPERAND_NUM_COMPONENTS(*operandToken);
1164+
if (numComponents != D3D10_SB_OPERAND_0_COMPONENT)
1165+
return emitError(loc, "unexpected number of components: ")
1166+
<< numComponents;
1167+
1168+
auto indexDim = DECODE_D3D10_SB_OPERAND_INDEX_DIMENSION(*operandToken);
1169+
if (indexDim != D3D10_SB_OPERAND_INDEX_1D)
1170+
return emitError(loc, "unsupported index dimension: ") << indexDim;
1171+
1172+
auto indexRepresentation =
1173+
DECODE_D3D10_SB_OPERAND_INDEX_REPRESENTATION(0, *operandToken);
1174+
if (indexRepresentation != D3D10_SB_OPERAND_INDEX_IMMEDIATE32)
1175+
return emitError(loc, "unsupported index representation: ")
1176+
<< indexRepresentation;
1177+
1178+
auto indexToken = parseToken();
1179+
FAILURE_IF_FAILED(indexToken);
1180+
1181+
return builder.buildDclStream(*indexToken, loc);
1182+
}
1183+
11471184
FailureOr<dxsa::InterpolationMode>
11481185
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
11491186
auto rawInterpolationMode =
@@ -1423,6 +1460,9 @@ class Parser {
14231460
case D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT:
14241461
result = parseDclMaxOutputVertexCount(loc);
14251462
break;
1463+
case D3D11_SB_OPCODE_DCL_STREAM:
1464+
result = parseDclStream(loc);
1465+
break;
14261466
case D3D10_SB_OPCODE_DCL_INPUT_PS:
14271467
result = parseDclInputPs(opcodeToken, loc);
14281468
break;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_stream.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_stream 0
5+
// CHECK-NEXT: dxsa.dcl_stream 3
6+
// CHECK-NEXT: }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative whose maximum value is 3}}
4+
dxsa.dcl_stream -1
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative whose maximum value is 3}}
9+
dxsa.dcl_stream 4
24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)