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
28 changes: 28 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,32 @@ def DXSA_DclTgsmStructured : DXSA_Op<"dcl_tgsm_structured"> {
let hasVerifier = 1;
}

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

Example:

```mlir
dxsa.dcl_resource_raw <id = 3>
dxsa.dcl_resource_raw <id = 0, lbound = 0, ubound = 3, space = 1>
```
}];

let arguments = (ins
I32Attr:$id,
OptionalAttr<I32Attr>:$lbound,
OptionalAttr<I32Attr>:$ubound,
OptionalAttr<I32Attr>:$space);
let assemblyFormat = [{
` ` `<` `id` `=` $id
(`,` `lbound` `=` $lbound^ `,` `ubound` `=` $ubound
Copy link
Copy Markdown
Contributor

@asavonic asavonic Jun 1, 2026

Choose a reason for hiding this comment

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

What happens when lbound or ubound are not set?

`,` `space` `=` $space)? `>`
attr-dict
}];
let hasVerifier = 1;
}

#endif // DXSA_OPS
9 changes: 9 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,15 @@ LogicalResult DclTgsmStructured::verify() {
return success();
}

LogicalResult DclResourceRaw::verify() {
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
37 changes: 37 additions & 0 deletions mlir/lib/Target/DXSA/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,16 @@ class DXBuilder {
builder.getI32IntegerAttr(structCount));
}

Instruction buildDclResourceRaw(uint32_t id, 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::DclResourceRaw::create(builder, loc, id, toAttr(lbound),
toAttr(ubound), toAttr(space));
}

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

FailureOr<Instruction> parseDclResourceRaw(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, space;
if (indexDim == 3) {
lbound = indexArray[1];
ubound = indexArray[2];
auto spaceToken = parseToken();
FAILURE_IF_FAILED(spaceToken);
space = *spaceToken;
}

return builder.buildDclResourceRaw(id, lbound, ubound, space, loc);
}

OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
Instruction &out) {
FailureOr<Instruction> result;
Expand Down Expand Up @@ -1393,6 +1427,9 @@ class Parser {
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
result = parseDclTgsmStructured(loc);
break;
case D3D11_SB_OPCODE_DCL_RESOURCE_RAW:
result = parseDclResourceRaw(loc);
break;
default:
return std::nullopt;
}
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Target/DXSA/dcl_resource_raw.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_raw.bin | FileCheck %s

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

// expected-error@+1 {{'dxsa.dcl_resource_raw' op expected lbound <= ubound, got lbound=5, ubound=3}}
dxsa.dcl_resource_raw <id = 0, lbound = 5, ubound = 3, space = 1>
Binary file added mlir/test/Target/DXSA/inputs/dcl_resource_raw.bin
Binary file not shown.