From 35d1f0ba0b94877bfb79f0eb6e9ba403859a4ecd Mon Sep 17 00:00:00 2001 From: Vladimir Shiryaev Date: Sun, 28 Jun 2026 12:18:21 -0700 Subject: [PATCH] [mlir][dxsa] Add eval_centroid, eval_sample_index and eval_snapped instructions Example: dxsa.eval_centroid r<0>, r<1> dxsa.eval_sample_index r<0>, r<1>, l(0x2) dxsa.eval_snapped r<0>, r<1>, l(0x2, 0x3, 0x0, 0x0) Signed-off-by: Vladimir Shiryaev --- mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td | 1 + .../mlir/Dialect/DXSA/IR/DXSAResourceOps.td | 81 +++++++++++++++++++ mlir/lib/Target/DXSA/BinaryParser.cpp | 7 ++ mlir/test/Target/DXSA/resource_ops.test | 42 ++++++++++ 4 files changed, 131 insertions(+) create mode 100644 mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td create mode 100644 mlir/test/Target/DXSA/resource_ops.test diff --git a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td index dc72b4f6fc4a..4abcf2b5b317 100644 --- a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td +++ b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td @@ -17,6 +17,7 @@ include "mlir/Dialect/DXSA/IR/DXSAConditionOps.td" include "mlir/Dialect/DXSA/IR/DXSABitwiseOps.td" include "mlir/Dialect/DXSA/IR/DXSATypeConversionOps.td" include "mlir/Dialect/DXSA/IR/DXSAAtomicOps.td" +include "mlir/Dialect/DXSA/IR/DXSAResourceOps.td" include "mlir/IR/AttrTypeBase.td" include "mlir/IR/BuiltinAttributeInterfaces.td" include "mlir/IR/EnumAttr.td" diff --git a/mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td b/mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td new file mode 100644 index 000000000000..e542e9fa027e --- /dev/null +++ b/mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td @@ -0,0 +1,81 @@ +//===- DXSAResourceOps.td - DXSA resource ops -----------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Resource instructions of the DXSA dialect. Each op samples a pixel shader +// input attribute at a location other than the one implied by its declared +// interpolation mode. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS +#define MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS + +include "mlir/Dialect/DXSA/IR/DXSAOpBase.td" + +//===----------------------------------------------------------------------===// +// dxsa.eval_centroid +//===----------------------------------------------------------------------===// + +def DXSA_EvalCentroid : DXSA_UnaryOp<"eval_centroid"> { + let summary = "evaluate a pixel shader input at the centroid location"; + let description = [{ + The `dxsa.eval_centroid` operation samples the pixel shader input + attribute `$src` at the centroid location within the pixel and writes + the result to `$dst`. + + Example: + + ```mlir + dxsa.eval_centroid r<0>, r<1> + ``` + }]; +} + +//===----------------------------------------------------------------------===// +// dxsa.eval_sample_index +//===----------------------------------------------------------------------===// + +def DXSA_EvalSampleIndex : DXSA_BinaryOp<"eval_sample_index"> { + let summary = "evaluate a pixel shader input at a given sample index"; + let description = [{ + The `dxsa.eval_sample_index` operation samples the pixel shader input + attribute `$lhs` at the sample whose index is the scalar operand + `$rhs` and writes the result to `$dst`. `$rhs` is either an integer + immediate or a single-component register reference. + + Example: + + ```mlir + dxsa.eval_sample_index r<0>, r<1>, l(0x2) + dxsa.eval_sample_index r<0>, r<1>, r<2, > + ``` + }]; +} + +//===----------------------------------------------------------------------===// +// dxsa.eval_snapped +//===----------------------------------------------------------------------===// + +def DXSA_EvalSnapped : DXSA_BinaryOp<"eval_snapped"> { + let summary = "evaluate a pixel shader input at a snapped pixel offset"; + let description = [{ + The `dxsa.eval_snapped` operation samples the pixel shader input + attribute `$lhs` at a fractional pixel offset from the pixel center + given by the int4 immediate operand `$rhs` (interpreted on a 16x16 + grid using the lowest 4 bits of its first two components) and writes + the result to `$dst`. + + Example: + + ```mlir + dxsa.eval_snapped r<0>, r<1>, l(0x2, 0x3, 0x0, 0x0) + ``` + }]; +} + +#endif // MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS diff --git a/mlir/lib/Target/DXSA/BinaryParser.cpp b/mlir/lib/Target/DXSA/BinaryParser.cpp index 976322f05f8c..df24a023500b 100644 --- a/mlir/lib/Target/DXSA/BinaryParser.cpp +++ b/mlir/lib/Target/DXSA/BinaryParser.cpp @@ -2477,6 +2477,13 @@ class Parser { return PLAIN_OP(ImmAtomicAlloc, 1, 1, HasPreciseAttr::No); case D3D11_SB_OPCODE_IMM_ATOMIC_CONSUME: return PLAIN_OP(ImmAtomicConsume, 1, 1, HasPreciseAttr::No); + // Resource instructions + case D3D11_SB_OPCODE_EVAL_CENTROID: + return PLAIN_OP(EvalCentroid, 1, 1, HasPreciseAttr::Yes); + case D3D11_SB_OPCODE_EVAL_SAMPLE_INDEX: + return PLAIN_OP(EvalSampleIndex, 1, 2, HasPreciseAttr::Yes); + case D3D11_SB_OPCODE_EVAL_SNAPPED: + return PLAIN_OP(EvalSnapped, 1, 2, HasPreciseAttr::Yes); } #undef SATURABLE_OP #undef PLAIN_OP diff --git a/mlir/test/Target/DXSA/resource_ops.test b/mlir/test/Target/DXSA/resource_ops.test new file mode 100644 index 000000000000..3a683c926d05 --- /dev/null +++ b/mlir/test/Target/DXSA/resource_ops.test @@ -0,0 +1,42 @@ +// RUN: mlir-translate --split-input-file --import-dxsa-hex %s | FileCheck %s +// RUN: mlir-translate --split-input-file --import-dxsa-hex %s | mlir-opt --split-input-file --verify-roundtrip + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_centroid r<0>, r<1> +// CHECK-NEXT: } +0x050000cd, 0x001000f2, 0x00000000, 0x00100e46, 0x00000001 + +// ----- + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_centroid precise r<0, >, r<1, > +// CHECK-NEXT: } +0x051800cd, 0x00100012, 0x00000000, 0x00100796, 0x00000001 + +// ----- + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_sample_index r<0>, r<1>, l(0x2) +// CHECK-NEXT: } +0x070000cc, 0x001000f2, 0x00000000, 0x00100e46, 0x00000001, 0x00004001, 0x00000002 + +// ----- + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_sample_index precise r<0, >, r<1, >, l(0x3) +// CHECK-NEXT: } +0x071800cc, 0x00100012, 0x00000000, 0x00100796, 0x00000001, 0x00004001, 0x00000003 + +// ----- + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_snapped r<0>, r<1>, l(0x2, 0xFFFFFFFE, 0x0, 0x0) +// CHECK-NEXT: } +0x0a0000cb, 0x001000f2, 0x00000000, 0x00100e46, 0x00000001, 0x00004002, 0x00000002, 0xfffffffe, 0x00000000, 0x00000000 + +// ----- + +// CHECK-LABEL: dxsa.module { +// CHECK-NEXT: dxsa.eval_snapped precise r<0, >, r<1, >, l(0x1, 0x1, 0x0, 0x0) +// CHECK-NEXT: } +0x0a1800cb, 0x00100012, 0x00000000, 0x00100796, 0x00000001, 0x00004002, 0x00000001, 0x00000001, 0x00000000, 0x00000000