-
Notifications
You must be signed in to change notification settings - Fork 2
[mlir][dxsa] Add sample instruction #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
asavonic
wants to merge
9
commits into
dxsa-mlir
Choose a base branch
from
dxsa-mlir-sampler
base: dxsa-mlir
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
22f12b4
[mlir][dxsa] Add sample instruction
asavonic 1f26f0e
Add --verify-roundtrip
asavonic d4fb043
Use hex input for tests
asavonic 080d383
Use FAILURE_IF_FAILED
asavonic 6e75030
Avoid building SampleClampFeedbackAttr in the parser
asavonic b7a3119
Reword descriptions
asavonic 4ec4545
Refactor to only use one buildSampleOp function
asavonic 9f9ff8b
Add all variants of the sample instruction
asavonic 99ca996
Print value for range diagnostic
asavonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,273 @@ | ||
| //===---- DXSAResourceOps.td - sampler and 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Sampler and Resource instructions of the DXSA dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS | ||
| #define MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS | ||
|
|
||
| include "mlir/Dialect/DXSA/IR/DXSAOpBase.td" | ||
|
|
||
| def DXSA_SampleOffsetAttr : AttrDef<DXSADialect, "SampleOffset"> { | ||
| let mnemonic = "sample_offset"; | ||
| let summary = "immediate offset for the texture coordinates for the sample"; | ||
| let description = [{ | ||
| The dxsa.sample_offset attribute indicates that the texture coordinates for | ||
| the sample are to be offset by a set of provided immediate texel space | ||
| integer constant values. The literal values are a set of 4 bit 2's | ||
| complement numbers, having integer range [-8,7]. | ||
| }]; | ||
| let parameters = (ins "int32_t":$u, "int32_t":$v, "int32_t":$w); | ||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| let genVerifyDecl = 1; | ||
| } | ||
|
|
||
| def DXSA_SampleClampFeedbackAttr : AttrDef<DXSADialect, "SampleClampFeedback"> { | ||
| let mnemonic = "sample_clamp_feedback"; | ||
| let summary = "optional LOD clamp and Tiled Resources shader feedback status output value"; | ||
| let description = [{ | ||
| The dxsa.sample_clamp_feed attribute is an optional pair of operands for | ||
| dxsa.sample instruction. | ||
|
|
||
| `lod_clamp` is an additional 32 bit scalar LOD clamp operand. | ||
|
|
||
| `feedback` is a shader feedback status output value. The contents | ||
| of the return value are opaque - direct reading by the shader | ||
| program is disallowed. | ||
| }]; | ||
|
|
||
| let parameters = (ins | ||
| AttrParameter<"SrcOperandAttr", "lod_clamp">:$lod_clamp, | ||
| AttrParameter<"DstOperandAttr", "feedback">:$feedback); | ||
|
|
||
| let assemblyFormat = "`<` $lod_clamp `,` $feedback `>`"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_Sample : DXSA_Op<"sample"> { | ||
| let summary = "sample data from the specified texture using the filtering mode identified by the given sampler"; | ||
| let description = [{ | ||
| The dxsa.sample operation uses provided address, sample data from the | ||
| specified Element/texture using the filtering mode identified by the given | ||
| sampler. The source data may come from any Resource Type (5), other than | ||
| Buffers. | ||
|
|
||
| `src_address` provides the set of texture coordinates needed to perform the | ||
| sample, as floating point values referencing normalized space in the texture. | ||
|
|
||
| `src_resource` is a texture register (t). This is simply a | ||
| placeholder for a texture, including the return data type of the | ||
| resource being sampled. | ||
|
|
||
| `src_sampler` is a sampler register (s). This is simply a | ||
| placeholder for a collection of filtering controls (such as point | ||
| vs. linear, mipmapping and address wrapping controls). | ||
|
|
||
| The optional `offset` operand suffix (address offset by immediate | ||
| integer) indicates that the texture coordinates for the sample are | ||
| to be offset by a set of provided immediate texel space integer | ||
| constant values. The literal values are a set of 4 bit 2's | ||
| complement numbers, having integer range [-8,7]. | ||
|
|
||
| The optional `clamp_feedback` operand appends an additional 32 bit | ||
| scalar LOD clamp operand and an additional 32 bit scalar Tiled | ||
| Resources shader feedback status output value. | ||
| }]; | ||
|
|
||
| let arguments = (ins | ||
| DXSA_DstOperandAttr:$dst, | ||
| DXSA_SrcOperandAttr:$src_address, | ||
| DXSA_SrcOperandAttr:$src_resource, | ||
| DXSA_SrcOperandAttr:$src_sampler, | ||
| OptionalAttr<DXSA_SampleOffsetAttr>:$offset, | ||
| OptionalAttr<DXSA_SampleClampFeedbackAttr>:$clamp_feedback); | ||
| let results = (outs); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $dst `,` $src_address `,` $src_resource `,` $src_sampler | ||
| (`,` $offset^)? (`,` $clamp_feedback^)? | ||
| attr-dict | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample_b | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_SampleB : DXSA_Op<"sample_b"> { | ||
| let summary = "sample data from the specified texture with an additional bias applied to the LOD"; | ||
| let description = [{ | ||
| The `dxsa.sample_b` operation uses provided address, sample data from the | ||
| specified Element/texture using the filtering mode identified by the given | ||
| sampler. The source data may come from any Resource Type(5), other than | ||
| Buffers. An additional bias is applied to the level of detail computed as | ||
| part of the instruction execution. | ||
|
|
||
| `src_address`, `src_resource`, `src_sampler`, `offset`, and `clamp_feedback` | ||
| operands are the same as in `dxsa.sample` instruction. | ||
|
|
||
| The `src_lod_bias` value is added to the computed LOD on a per-pixel basis, | ||
| along with the sampler MipLODBias value, prior to the clamp to MinLOD and | ||
| MaxLOD. | ||
|
|
||
| }]; | ||
|
|
||
| let arguments = (ins | ||
| DXSA_DstOperandAttr:$dst, | ||
| DXSA_SrcOperandAttr:$src_address, | ||
| DXSA_SrcOperandAttr:$src_resource, | ||
| DXSA_SrcOperandAttr:$src_sampler, | ||
| DXSA_SrcOperandAttr:$src_lod_bias, | ||
| OptionalAttr<DXSA_SampleOffsetAttr>:$offset, | ||
| OptionalAttr<DXSA_SampleClampFeedbackAttr>:$clamp_feedback); | ||
| let results = (outs); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $dst `,` $src_address `,` $src_resource `,` $src_sampler `,` $src_lod_bias | ||
| (`,` $offset^)? (`,` $clamp_feedback^)? | ||
| attr-dict | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample_d | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_SampleD : DXSA_Op<"sample_d"> { | ||
| let summary = "sample data from the specified texture with derivatives for X and Y"; | ||
| let description = [{ | ||
| The `dxsa.sample_d` operation uses provided address, sample data from the | ||
| specified Element/texture using the filtering mode identified by the given | ||
| sampler. The source data may come from any Resource Type(5), other than | ||
| Buffers. | ||
|
|
||
| `src_address`, `src_resource`, `src_sampler`, `offset`, and `clamp_feedback` | ||
| operands are the same as in `dxsa.sample` instruction. | ||
|
|
||
| Derivatives for the source address in the x direction and the y direction are | ||
| provided by extra parameters, `src_x_derivatives` and `src_y_derivatives`, | ||
| respectively. These derivatives are in normalized texture coordinate space. | ||
| }]; | ||
|
|
||
| let arguments = (ins | ||
| DXSA_DstOperandAttr:$dst, | ||
| DXSA_SrcOperandAttr:$src_address, | ||
| DXSA_SrcOperandAttr:$src_resource, | ||
| DXSA_SrcOperandAttr:$src_sampler, | ||
| DXSA_SrcOperandAttr:$src_x_derivatives, | ||
| DXSA_SrcOperandAttr:$src_y_derivatives, | ||
| OptionalAttr<DXSA_SampleOffsetAttr>:$offset, | ||
| OptionalAttr<DXSA_SampleClampFeedbackAttr>:$clamp_feedback); | ||
| let results = (outs); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $dst `,` $src_address `,` $src_resource `,` $src_sampler | ||
| `,` $src_x_derivatives `,` $src_y_derivatives | ||
| (`,` $offset^)? (`,` $clamp_feedback^)? | ||
| attr-dict | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample_l | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_SampleL : DXSA_Op<"sample_l"> { | ||
| let summary = "sample data from the specified texture with specific LOD"; | ||
| let description = [{ | ||
| `dxsa.sample_l` is identical to `dxsa.sample`, except that LOD is provided | ||
| directly by the application as a scalar value, representing no anisotropy. | ||
|
|
||
| `src_address`, `src_resource`, `src_sampler`, `offset`, and `clamp_feedback` | ||
| operands are the same as in `dxsa.sample` instruction. | ||
|
|
||
| `src_lod` is the LOD value. If the LOD value is <= 0, the zero'th (biggest | ||
| map) is chosen, with the magnify filter applied (if applicable based on the | ||
| filter mode). Since `src_lod` is a floating point value, the fractional | ||
| value is used to interpolate (if the minify filter is LINEAR or with | ||
| anisotropic filtering) between two mip levels. | ||
| }]; | ||
|
|
||
| let arguments = (ins | ||
| DXSA_DstOperandAttr:$dst, | ||
| DXSA_SrcOperandAttr:$src_address, | ||
| DXSA_SrcOperandAttr:$src_resource, | ||
| DXSA_SrcOperandAttr:$src_sampler, | ||
| DXSA_SrcOperandAttr:$src_lod, | ||
| OptionalAttr<DXSA_SampleOffsetAttr>:$offset, | ||
| OptionalAttr<DXSA_SampleClampFeedbackAttr>:$clamp_feedback); | ||
| let results = (outs); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $dst `,` $src_address `,` $src_resource `,` $src_sampler | ||
| `,` $src_lod | ||
| (`,` $offset^)? (`,` $clamp_feedback^)? | ||
| attr-dict | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample_c | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class DXSA_SampleC_Base<string mnemonic> : DXSA_Op<mnemonic> { | ||
| let arguments = (ins | ||
| DXSA_DstOperandAttr:$dst, | ||
| DXSA_SrcOperandAttr:$src_address, | ||
| DXSA_SrcOperandAttr:$src_resource, | ||
| DXSA_SrcOperandAttr:$src_sampler, | ||
| DXSA_SrcOperandAttr:$src_reference_value, | ||
| OptionalAttr<DXSA_SampleOffsetAttr>:$offset, | ||
| OptionalAttr<DXSA_SampleClampFeedbackAttr>:$clamp_feedback); | ||
| let results = (outs); | ||
|
|
||
| let assemblyFormat = [{ | ||
| $dst `,` $src_address `,` $src_resource `,` $src_sampler | ||
| `,` $src_reference_value | ||
| (`,` $offset^)? (`,` $clamp_feedback^)? | ||
| attr-dict | ||
| }]; | ||
| } | ||
|
|
||
| def DXSA_SampleC : DXSA_SampleC_Base<"sample_c"> { | ||
| let summary = "perform a comparison filter"; | ||
| let description = [{ | ||
| `dxsa.sample_c` is to provide a building-block for Percentage-Closer Depth | ||
| filtering. The 'c' in sample_c stands for Comparison. | ||
|
|
||
| The operands to `dxsa.sample_c` are identical to `dxsa.sample`, except that | ||
| there is an additional float32 source operand, `src_reference_value`, which | ||
| must be a register with single-component selected, or a scalar literal. | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // dxsa.sample_c_lz | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def DXSA_SampleCLZ : DXSA_SampleC_Base<"sample_c_lz"> { | ||
| let summary = "perform a comparison filter with zero LOD"; | ||
| let description = [{ | ||
| Same as `dxsa.sample_c`, except LOD is 0, and derivatives are ignored (as if | ||
| they are 0). The 'lz' stands for level-zero. Because derivatives are | ||
| ignored, this instruction is available in shaders other than the Pixel | ||
| Shader. | ||
|
|
||
| `dxsa.sample_c` is to provide a building-block for Percentage-Closer Depth | ||
| filtering. The 'c' in sample_c stands for Comparison. | ||
|
|
||
| The operands to `dxsa.sample_c_lz` are identical to `dxsa.sample_c`. | ||
| }]; | ||
| } | ||
|
|
||
| #endif // MLIR_DIALECT_DXSA_IR_DXSARESOURCEOPS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.