Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
81 changes: 81 additions & 0 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td
Original file line number Diff line number Diff line change
@@ -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, <x, x, x, x>>
```
}];
}

//===----------------------------------------------------------------------===//
// 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
7 changes: 7 additions & 0 deletions mlir/lib/Target/DXSA/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions mlir/test/Target/DXSA/resource_ops.test
Original file line number Diff line number Diff line change
@@ -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 <x, y> r<0, <x>>, r<1, <y, z, w, y>>
// 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 <x, y> r<0, <x>>, r<1, <y, z, w, y>>, 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 <x, y> r<0, <x>>, r<1, <y, z, w, y>>, l(0x1, 0x1, 0x0, 0x0)
// CHECK-NEXT: }
0x0a1800cb, 0x00100012, 0x00000000, 0x00100796, 0x00000001, 0x00004002, 0x00000001, 0x00000001, 0x00000000, 0x00000000