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 @@ -12,6 +12,7 @@
include "mlir/Dialect/DXSA/IR/DXSAOpBase.td"
include "mlir/Dialect/DXSA/IR/DXSATypes.td"
include "mlir/Dialect/DXSA/IR/DXSAFPArithOps.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
273 changes: 273 additions & 0 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAResourceOps.td
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^)?

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.

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
14 changes: 14 additions & 0 deletions mlir/lib/Dialect/DXSA/IR/DXSAOperand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,3 +991,17 @@ void SrcOperandAttr::print(AsmPrinter &printer) const {
printNegAndAbsModifier(printer, getModifier(),
[&] { printSrcOperandBody(printer, *this); });
}

LogicalResult
SampleOffsetAttr::verify(function_ref<InFlightDiagnostic()> emitError,
int32_t u, int32_t v, int32_t w) {
int32_t values[] = {u, v, w};
for (int32_t value : values) {
if (value < -8 || value > 7) {
return emitError()
<< "sample offsets must be 4 bit 2's complement numbers, "
"having integer range [-8,7], got " << value;
}
}
return success();
}
Loading