Skip to content

[mlir][dxsa] Add sample instruction#182

Merged
asavonic merged 1 commit into
dxsa-mlirfrom
dxsa-mlir-sampler
Jul 2, 2026
Merged

[mlir][dxsa] Add sample instruction#182
asavonic merged 1 commit into
dxsa-mlirfrom
dxsa-mlir-sampler

Conversation

@asavonic

Copy link
Copy Markdown
Contributor

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 18, 2026 15:22
@asavonic asavonic force-pushed the dxsa-mlir-sampler branch from 562d731 to 22f12b4 Compare June 18, 2026 15:44
Comment thread mlir/test/Target/DXSA/sample_offset.mlir Outdated
Comment thread mlir/test/Target/DXSA/sample_clamp_feedback.mlir Outdated
Comment thread mlir/test/Target/DXSA/sample_clamp_feedback.mlir Outdated
Comment thread mlir/test/Target/DXSA/sample.mlir Outdated
Comment thread mlir/test/Target/DXSA/sample.mlir Outdated

let assemblyFormat = [{
$dst `,` $src_address `,` $src_resource `,` $src_sampler
(`,` $offset^)? (`,` $clamp_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.

It seems to me that two optional attrs could broke roundtrip. I vote to enable roundtrip in the test files and retest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Offset and Clamp/Feedback syntax is not ambiguous. Offset is <u = 1, v = 2, w = 3>, and clamp/feedback are two operands. Added --verify-roundtrip.

} while (DECODE_IS_D3D10_SB_OPCODE_EXTENDED(*opcodeToken1));
}

// TODO: extended instructions:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Isn't this comment obsole?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Partially. There is still #160 conditional instructions that I need to rebase and merge.

Comment thread mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td Outdated
Comment thread mlir/lib/Target/DXSA/BinaryParser.cpp Outdated
Comment thread mlir/lib/Target/DXSA/BinaryParser.cpp Outdated
ExtendedInstruction &ext, Location loc) {
dxsa::SampleOffsetAttr offset;
if (auto sampleOffset = ext.sampleOffset) {
offset = dxsa::SampleOffsetAttr::get(context, sampleOffset->u,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe we can build attribute outside of this function, to make it interface more consistent?
Rather then passing the structure from parser level?
There is a minor inconsistency here - the clampFeedback is build on the parser layer, but offset is inside the builder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is a good point. I think it makes sense to keep all MLIR construction in the builder, and parsing stuff in the parser. Refactored the code to avoid constructing SampleClampFeedbackAttr in the parser.

@asavonic

Copy link
Copy Markdown
Contributor Author

Addressed comments and added other variants of the sample instruction.

Comment thread mlir/lib/Dialect/DXSA/IR/DXSAOperand.cpp Outdated
@asavonic asavonic force-pushed the dxsa-mlir-sampler branch from e6be522 to cc0bf04 Compare July 2, 2026 08:06
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.

Feedback (ClampFeedback) and Offset are both supposed to be optional
attributes. MLIR parser is not able to handle cases where feedback is
present, but offset is absent, so and fails roundtrip verifier tests.

Therefore such instructions are separate, and feedback operand is not
optional.
@asavonic asavonic force-pushed the dxsa-mlir-sampler branch from cc0bf04 to 161d8b2 Compare July 2, 2026 08:06
@asavonic asavonic merged commit 8e2bba9 into dxsa-mlir Jul 2, 2026
5 checks passed
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