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
30 changes: 30 additions & 0 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,34 @@ def DXSA_DclTgsmStructured : DXSA_Op<"dcl_tgsm_structured"> {
let hasVerifier = 1;
}

def DXSA_DclResourceStructured : DXSA_Op<"dcl_resource_structured"> {
let summary = "declares a structured buffer shader input resource bound to a register";
let description = [{
The `dxsa.dcl_resource_structured` operation declares a structured
buffer shader input resource bound to a register.

Example:

```mlir
dxsa.dcl_resource_structured <id = 3, struct_byte_stride = 16>
dxsa.dcl_resource_structured
<id = 0, struct_byte_stride = 32, lbound = 0, ubound = 3, space = 1>
```
}];

let arguments = (ins
I32Attr:$id,
ConfinedAttr<I32Attr, [IntPositive]>:$struct_byte_stride,
OptionalAttr<I32Attr>:$lbound,
OptionalAttr<I32Attr>:$ubound,
OptionalAttr<I32Attr>:$space);
let assemblyFormat = [{
` ` `<` `id` `=` $id `,` `struct_byte_stride` `=` $struct_byte_stride
(`,` `lbound` `=` $lbound^ `,` `ubound` `=` $ubound
`,` `space` `=` $space)? `>`
attr-dict
}];
let hasVerifier = 1;
}

#endif // DXSA_OPS
13 changes: 13 additions & 0 deletions mlir/lib/Dialect/DXSA/IR/DXSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ LogicalResult DclTgsmStructured::verify() {
return success();
}

LogicalResult DclResourceStructured::verify() {
auto stride = getStructByteStride();
if (stride % 4 != 0)
return emitOpError("struct byte stride must be a multiple of 4, got ")
<< stride;
auto lbound = getLbound();
auto ubound = getUbound();
if (lbound && ubound && *lbound > *ubound)
return emitOpError("expected lbound <= ubound, got lbound=")
<< *lbound << ", ubound=" << *ubound;
return success();
}

//===----------------------------------------------------------------------===//
// TableGen'd attribute method definitions
//===----------------------------------------------------------------------===//
Expand Down
48 changes: 48 additions & 0 deletions mlir/lib/Target/DXSA/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,19 @@ class DXBuilder {
builder.getI32IntegerAttr(structCount));
}

Instruction buildDclResourceStructured(uint32_t id, uint32_t structByteStride,
std::optional<uint32_t> lbound,
std::optional<uint32_t> ubound,
std::optional<uint32_t> space,
Location loc) {
auto toAttr = [&](std::optional<uint32_t> v) -> IntegerAttr {
return v ? builder.getI32IntegerAttr(*v) : IntegerAttr();
};
return dxsa::DclResourceStructured::create(builder, loc, id,
structByteStride, toAttr(lbound),
toAttr(ubound), toAttr(space));
}

private:
MLIRContext *context;
ModuleOp module;
Expand Down Expand Up @@ -1317,6 +1330,38 @@ class Parser {
*structCount, loc);
}

FailureOr<Instruction> parseDclResourceStructured(Location loc) {
auto operand = parseInlineOperand();
FAILURE_IF_FAILED(operand);
if (operand->getType() != dxsa::InlineOperandType::resource)
return emitError(loc, "operand must be a resource register, got ")
<< dxsa::stringifyInlineOperandType(operand->getType());
auto indexArray = operand->getIndex();
auto indexDim = indexArray ? indexArray.size() : 0;
if (indexDim != 1 && indexDim != 3)
return emitError(loc, "operand must have a 1D or 3D index, got ")
<< indexDim;
auto id = indexArray[0];
std::optional<uint32_t> lbound, ubound;
if (indexDim == 3) {
lbound = indexArray[1];
ubound = indexArray[2];
}

auto strideToken = parseToken();
FAILURE_IF_FAILED(strideToken);

std::optional<uint32_t> space;
if (indexDim == 3) {
auto spaceToken = parseToken();
FAILURE_IF_FAILED(spaceToken);
space = *spaceToken;
}

return builder.buildDclResourceStructured(id, *strideToken, lbound, ubound,
space, loc);
}

OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
Instruction &out) {
FailureOr<Instruction> result;
Expand Down Expand Up @@ -1393,6 +1438,9 @@ class Parser {
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
result = parseDclTgsmStructured(loc);
break;
case D3D11_SB_OPCODE_DCL_RESOURCE_STRUCTURED:
result = parseDclResourceStructured(loc);
break;
default:
return std::nullopt;
}
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Target/DXSA/dcl_resource_structured.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_resource_structured.bin | FileCheck %s

// CHECK: module {
// CHECK-NEXT: dxsa.dcl_resource_structured <id = 3, struct_byte_stride = 16>
// CHECK-NEXT: dxsa.dcl_resource_structured <id = 0, struct_byte_stride = 32, lbound = 0, ubound = 3, space = 1>
// CHECK-NEXT: }
14 changes: 14 additions & 0 deletions mlir/test/Target/DXSA/dcl_resource_structured_invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics

// expected-error@+1 {{'dxsa.dcl_resource_structured' op struct byte stride must be a multiple of 4, got 6}}
dxsa.dcl_resource_structured <id = 0, struct_byte_stride = 6>

// -----

// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
dxsa.dcl_resource_structured <id = 0, struct_byte_stride = 0>

// -----

// expected-error@+1 {{'dxsa.dcl_resource_structured' op expected lbound <= ubound, got lbound=5, ubound=3}}
dxsa.dcl_resource_structured <id = 0, struct_byte_stride = 16, lbound = 5, ubound = 3, space = 1>
Binary file not shown.