Skip to content

Commit 2a869b0

Browse files
committed
[mlir][dxsa] Add dcl_resource_raw instruction
Example: dxsa.dcl_resource_raw <type = resource, components = 0, index = [0, 0, 3]>, <space = 1> Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent ebce8ee commit 2a869b0

6 files changed

Lines changed: 84 additions & 0 deletions

File tree

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,32 @@ def DXSA_DclTgsmStructured : DXSA_Op<"dcl_tgsm_structured"> {
922922
let hasVerifier = 1;
923923
}
924924

925+
def DXSA_DclResourceRaw : DXSA_Op<"dcl_resource_raw"> {
926+
let summary = "declares a raw buffer shader input resource bound to a register";
927+
let description = [{
928+
The `dxsa.dcl_resource_raw` operation declares a raw buffer shader
929+
input resource bound to a register.
930+
931+
Example:
932+
933+
```mlir
934+
dxsa.dcl_resource_raw <id = 3>
935+
dxsa.dcl_resource_raw <id = 0, lbound = 0, ubound = 3, space = 1>
936+
```
937+
}];
938+
939+
let arguments = (ins
940+
I32Attr:$id,
941+
OptionalAttr<I32Attr>:$lbound,
942+
OptionalAttr<I32Attr>:$ubound,
943+
OptionalAttr<I32Attr>:$space);
944+
let assemblyFormat = [{
945+
` ` `<` `id` `=` $id
946+
(`,` `lbound` `=` $lbound^ `,` `ubound` `=` $ubound
947+
`,` `space` `=` $space)? `>`
948+
attr-dict
949+
}];
950+
let hasVerifier = 1;
951+
}
952+
925953
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ LogicalResult DclTgsmStructured::verify() {
8484
return success();
8585
}
8686

87+
LogicalResult DclResourceRaw::verify() {
88+
auto lbound = getLbound();
89+
auto ubound = getUbound();
90+
if (lbound && ubound && *lbound > *ubound)
91+
return emitOpError("expected lbound <= ubound, got lbound=")
92+
<< *lbound << ", ubound=" << *ubound;
93+
return success();
94+
}
95+
8796
//===----------------------------------------------------------------------===//
8897
// TableGen'd attribute method definitions
8998
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,16 @@ class DXBuilder {
692692
builder.getI32IntegerAttr(structCount));
693693
}
694694

695+
Instruction buildDclResourceRaw(uint32_t id, std::optional<uint32_t> lbound,
696+
std::optional<uint32_t> ubound,
697+
std::optional<uint32_t> space, Location loc) {
698+
auto toAttr = [&](std::optional<uint32_t> v) -> IntegerAttr {
699+
return v ? builder.getI32IntegerAttr(*v) : IntegerAttr();
700+
};
701+
return dxsa::DclResourceRaw::create(builder, loc, id, toAttr(lbound),
702+
toAttr(ubound), toAttr(space));
703+
}
704+
695705
private:
696706
MLIRContext *context;
697707
ModuleOp module;
@@ -1317,6 +1327,30 @@ class Parser {
13171327
*structCount, loc);
13181328
}
13191329

1330+
FailureOr<Instruction> parseDclResourceRaw(Location loc) {
1331+
auto operand = parseInlineOperand();
1332+
FAILURE_IF_FAILED(operand);
1333+
if (operand->getType() != dxsa::InlineOperandType::resource)
1334+
return emitError(loc, "operand must be a resource register, got ")
1335+
<< dxsa::stringifyInlineOperandType(operand->getType());
1336+
auto indexArray = operand->getIndex();
1337+
auto indexDim = indexArray ? indexArray.size() : 0;
1338+
if (indexDim != 1 && indexDim != 3)
1339+
return emitError(loc, "operand must have a 1D or 3D index, got ")
1340+
<< indexDim;
1341+
auto id = indexArray[0];
1342+
std::optional<uint32_t> lbound, ubound, space;
1343+
if (indexDim == 3) {
1344+
lbound = indexArray[1];
1345+
ubound = indexArray[2];
1346+
auto spaceToken = parseToken();
1347+
FAILURE_IF_FAILED(spaceToken);
1348+
space = *spaceToken;
1349+
}
1350+
1351+
return builder.buildDclResourceRaw(id, lbound, ubound, space, loc);
1352+
}
1353+
13201354
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
13211355
Instruction &out) {
13221356
FailureOr<Instruction> result;
@@ -1393,6 +1427,9 @@ class Parser {
13931427
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
13941428
result = parseDclTgsmStructured(loc);
13951429
break;
1430+
case D3D11_SB_OPCODE_DCL_RESOURCE_RAW:
1431+
result = parseDclResourceRaw(loc);
1432+
break;
13961433
default:
13971434
return std::nullopt;
13981435
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_resource_raw.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_resource_raw <id = 3>
5+
// CHECK-NEXT: dxsa.dcl_resource_raw <id = 0, lbound = 0, ubound = 3, space = 1>
6+
// CHECK-NEXT: }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_resource_raw' op expected lbound <= ubound, got lbound=5, ubound=3}}
4+
dxsa.dcl_resource_raw <id = 0, lbound = 5, ubound = 3, space = 1>
36 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)