Skip to content

[mlir][dxsa] Add gather4 variants#203

Open
asavonic wants to merge 2 commits into
dxsa-mlirfrom
dxsa-mlir-gather4
Open

[mlir][dxsa] Add gather4 variants#203
asavonic wants to merge 2 commits into
dxsa-mlirfrom
dxsa-mlir-gather4

Conversation

@asavonic

Copy link
Copy Markdown
Contributor

Please ignore the first commit in the stack. It is reviewed separately in #182.

asavonic added 2 commits June 26, 2026 19:51
Sample instruction takes an address, a resource (texture), a sampler,
and writes texture data to the destination register.

There are several optional that can be present:

- Offset is encoded as an extended opcode.
- LOD clamp and feeback for sample_cl_s.

The spec mentions clamp and feedback as optional, but DXC decodes them
both. It is possible that they are always present as operands, but can
be null.

Other extended instruction are added for other resource instructions,
and not enabled for sample instruction.
@asavonic asavonic requested a review from tagolog June 26, 2026 10:54

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest PRs, I've introduced a new approach to test files that was approved by Anton.

Can we combine all gather-related tests to a single test file gather_ops.test and run mlir-translate with --split-input-file option?
atomic_ops.test

// 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.atomic_and u<0>, r<0>, r<1, <x>>
// CHECK-NEXT: }
0x070000a9, 0x0011e000, 0x00000000, 0x00100e46, 0x00000000, 0x0010000a, 0x00000001

// -----

// CHECK-LABEL: dxsa.module {
// CHECK-NEXT:   dxsa.atomic_and g<0>, r<2>, r<3, <x>>
// CHECK-NEXT: }
0x070000a9, 0x0011f000, 0x00000000, 0x00100e46, 0x00000002, 0x0010000a, 0x00000003

case D3DWDDM1_3_SB_OPCODE_SAMPLE_C_LZ_FEEDBACK: {
// 1 extra operand
auto extraOp = parseSrcOperand();
FAILURE_IF_FAILED(srcAddress);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FAILURE_IF_FAILED(srcAddress);
FAILURE_IF_FAILED(extraOp);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same issue is in parseSampleOp (not involved this PR, but worth fixing)

      // 2 extra operands
      auto extraOp = parseSrcOperand();
      FAILURE_IF_FAILED(srcAddress);
      extraOperands.push_back(*extraOp);
      [[fallthrough]];

let results = (outs);

let assemblyFormat = [{
$dst `,` $src_address `,` $src_resource `,` $src_sampler `,` $src_reference_value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$dst `,` $src_address `,` $src_resource `,` $src_sampler `,` $src_reference_value
$dst `,` $src_address `,` $src_resource `,` $src_sampler `,` $src_reference_value

let results = (outs);

let assemblyFormat = [{
$dst `,` $src_address `,` $src_offset `,` $src_resource `,` $src_sampler `,` $src_reference_value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$dst `,` $src_address `,` $src_offset `,` $src_resource `,` $src_sampler `,` $src_reference_value
$dst `,` $src_address `,` $src_offset `,` $src_resource `,` $src_sampler `,` $src_reference_value

//===----------------------------------------------------------------------===//

def DXSA_Gather4POC : DXSA_Op<"gather4_po_c"> {
let summary = "Same as `dxsa.gather4_po`, except performs comparison on texels, similar to `dxsa.sample_c`";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let summary = "Same as `dxsa.gather4_po`, except performs comparison on texels, similar to `dxsa.sample_c`";
let summary = "same as `dxsa.gather4_po`, except performs comparison on texels, similar to `dxsa.sample_c`";

case D3D11_SB_OPCODE_GATHER4_PO_C:
case D3DWDDM1_3_SB_OPCODE_GATHER4_PO_C_FEEDBACK:
return builder.buildGather4POC(*dst, *srcAddress, srcOffset, *srcResource,
*srcSampler, extraOperand, feedback,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format changes this line a little bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants