From a40efc5d76542de7bfb75097ad2520e86c02eda1 Mon Sep 17 00:00:00 2001 From: Vladimir Shiryaev Date: Sat, 30 May 2026 00:09:15 -0700 Subject: [PATCH] [mlir][dxsa] Add dcl_stream instruction Example: dxsa.dcl_stream 0 Signed-off-by: Vladimir Shiryaev --- mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td | 18 +++++++++++++ mlir/lib/Target/DXSA/BinaryParser.cpp | 24 ++++++++++++++++++ mlir/test/Target/DXSA/dcl_stream.mlir | 6 +++++ mlir/test/Target/DXSA/dcl_stream_invalid.mlir | 9 +++++++ mlir/test/Target/DXSA/inputs/dcl_stream.bin | Bin 0 -> 24 bytes 5 files changed, 57 insertions(+) create mode 100644 mlir/test/Target/DXSA/dcl_stream.mlir create mode 100644 mlir/test/Target/DXSA/dcl_stream_invalid.mlir create mode 100644 mlir/test/Target/DXSA/inputs/dcl_stream.bin diff --git a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td index c3546ee6d149..33055b8991dc 100644 --- a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td +++ b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td @@ -1054,4 +1054,22 @@ def DXSA_DclSampler : DXSA_Op<"dcl_sampler"> { let hasVerifier = 1; } +def DXSA_DclStream : DXSA_Op<"dcl_stream"> { + let summary = "declares a geometry shader (GS) output stream"; + let description = [{ + The `dxsa.dcl_stream` operation declares a geometry shader (GS) output stream. + + The `$index` must be in the range [0, 3]. + + Example: + + ```mlir + dxsa.dcl_stream 0 + ``` + }]; + let arguments = (ins ConfinedAttr]>:$index); + let assemblyFormat = [{ $index attr-dict }]; +} + #endif // DXSA_OPS diff --git a/mlir/lib/Target/DXSA/BinaryParser.cpp b/mlir/lib/Target/DXSA/BinaryParser.cpp index 44a5b0e97bac..0e0e38c70fa1 100644 --- a/mlir/lib/Target/DXSA/BinaryParser.cpp +++ b/mlir/lib/Target/DXSA/BinaryParser.cpp @@ -595,6 +595,11 @@ class DXBuilder { return dxsa::DclMaxOutputVertexCount::create(builder, loc, count); } + Instruction buildDclStream(uint32_t index, Location loc) { + return dxsa::DclStream::create(builder, loc, + builder.getI32IntegerAttr(index)); + } + Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode, Operand operand, Location loc) { auto interpolationModeAttr = dxsa::InterpolationModeAttr::get( @@ -1168,6 +1173,22 @@ class Parser { return builder.buildDclMaxOutputVertexCount(count, loc); } + FailureOr parseDclStream(Location loc) { + auto operand = parseInlineOperand(); + FAILURE_IF_FAILED(operand); + if (operand->getType() != dxsa::InlineOperandType::stream) + return emitError(loc, "unexpected operand type: ") + << dxsa::stringifyInlineOperandType(operand->getType()); + if (operand->getComponents() != 0) + return emitError(loc, "unexpected number of components: ") + << operand->getComponents(); + auto indexArray = operand->getIndex(); + if (!indexArray || indexArray.size() != 1) + return emitError(loc, "unsupported index dimension: ") + << (indexArray ? indexArray.size() : 0); + return builder.buildDclStream(static_cast(indexArray[0]), loc); + } + FailureOr parseInterpolationMode(uint32_t opcodeToken, Location loc) { auto rawInterpolationMode = @@ -1492,6 +1513,9 @@ class Parser { case D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT: result = parseDclMaxOutputVertexCount(loc); break; + case D3D11_SB_OPCODE_DCL_STREAM: + result = parseDclStream(loc); + break; case D3D10_SB_OPCODE_DCL_INPUT_PS: result = parseDclInputPs(opcodeToken, loc); break; diff --git a/mlir/test/Target/DXSA/dcl_stream.mlir b/mlir/test/Target/DXSA/dcl_stream.mlir new file mode 100644 index 000000000000..573df5eaaffe --- /dev/null +++ b/mlir/test/Target/DXSA/dcl_stream.mlir @@ -0,0 +1,6 @@ +// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_stream.bin | FileCheck %s + +// CHECK: module { +// CHECK-NEXT: dxsa.dcl_stream 0 +// CHECK-NEXT: dxsa.dcl_stream 3 +// CHECK-NEXT: } diff --git a/mlir/test/Target/DXSA/dcl_stream_invalid.mlir b/mlir/test/Target/DXSA/dcl_stream_invalid.mlir new file mode 100644 index 000000000000..b86dec83b88d --- /dev/null +++ b/mlir/test/Target/DXSA/dcl_stream_invalid.mlir @@ -0,0 +1,9 @@ +// RUN: mlir-opt %s -split-input-file -verify-diagnostics + +// expected-error@+1 {{attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative whose maximum value is 3}} +dxsa.dcl_stream -1 + +// ----- + +// expected-error@+1 {{attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative whose maximum value is 3}} +dxsa.dcl_stream 4 diff --git a/mlir/test/Target/DXSA/inputs/dcl_stream.bin b/mlir/test/Target/DXSA/inputs/dcl_stream.bin new file mode 100644 index 0000000000000000000000000000000000000000..c291a731dda234794f4b7d69f74c727051aa01b5 GIT binary patch literal 24 WcmeBYU|?oo5M%&>ekdC#zyJUiG66~e literal 0 HcmV?d00001