Skip to content

Commit 4304b0f

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 4304b0f

6 files changed

Lines changed: 66 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,28 @@ 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 <type = resource, components = 0, index = [3]>
935+
dxsa.dcl_resource_raw <type = resource, components = 0, index = [0, 0, 3]>, <space = 1>
936+
```
937+
}];
938+
939+
let arguments = (ins
940+
DXSA_InlineOperandAttr:$operand,
941+
OptionalAttr<I32Attr>:$space);
942+
let assemblyFormat = [{
943+
$operand (`,` `<` `space` `=` $space^ `>`)?
944+
attr-dict
945+
}];
946+
let hasVerifier = 1;
947+
}
948+
925949
#endif // DXSA_OPS

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

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

87+
LogicalResult DclResourceRaw::verify() {
88+
auto operandType = getOperand().getType();
89+
if (operandType != InlineOperandType::resource)
90+
return emitOpError("operand must be a resource register, got ")
91+
<< stringifyInlineOperandType(operandType);
92+
return success();
93+
}
94+
8795
//===----------------------------------------------------------------------===//
8896
// TableGen'd attribute method definitions
8997
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

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

695+
Instruction buildDclResourceRaw(dxsa::InlineOperandAttr operand,
696+
std::optional<uint32_t> space, Location loc) {
697+
auto spaceAttr = space ? builder.getI32IntegerAttr(*space) : IntegerAttr();
698+
return dxsa::DclResourceRaw::create(builder, loc, operand, spaceAttr);
699+
}
700+
695701
private:
696702
MLIRContext *context;
697703
ModuleOp module;
@@ -1317,6 +1323,21 @@ class Parser {
13171323
*structCount, loc);
13181324
}
13191325

1326+
FailureOr<Instruction> parseDclResourceRaw(Location loc) {
1327+
auto operand = parseInlineOperand();
1328+
FAILURE_IF_FAILED(operand);
1329+
1330+
std::optional<uint32_t> space;
1331+
auto indexArray = operand->getIndex();
1332+
if (indexArray && indexArray.size() == 3) {
1333+
auto spaceToken = parseToken();
1334+
FAILURE_IF_FAILED(spaceToken);
1335+
space = *spaceToken;
1336+
}
1337+
1338+
return builder.buildDclResourceRaw(*operand, space, loc);
1339+
}
1340+
13201341
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
13211342
Instruction &out) {
13221343
FailureOr<Instruction> result;
@@ -1393,6 +1414,9 @@ class Parser {
13931414
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
13941415
result = parseDclTgsmStructured(loc);
13951416
break;
1417+
case D3D11_SB_OPCODE_DCL_RESOURCE_RAW:
1418+
result = parseDclResourceRaw(loc);
1419+
break;
13961420
default:
13971421
return std::nullopt;
13981422
}
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 <type = resource, components = 0, index = [3]>
5+
// CHECK-NEXT: dxsa.dcl_resource_raw <type = resource, components = 0, index = [0, 0, 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 operand must be a resource register, got temp}}
4+
dxsa.dcl_resource_raw <type = temp, components = 0, index = [0]>
36 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)