Skip to content

[mlir][dxsa] Add sample instruction#182

Open
asavonic wants to merge 9 commits into
dxsa-mlirfrom
dxsa-mlir-sampler
Open

[mlir][dxsa] Add sample instruction#182
asavonic wants to merge 9 commits 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
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 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
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 added 7 commits June 19, 2026 17:25
Added:

  - sample_b
  - sample_c
  - sample_c_lz
  - sample_d
  - sample_l

These have different semantic and operands, so they are modeled as
separate instructions. Each also has a clamp_feedback variant with
optional clamp and feeback operands.
@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
Co-authored-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
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