Skip to content

Commit 2d70958

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

6 files changed

Lines changed: 94 additions & 0 deletions

File tree

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

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

925+
def DXSA_DclResourceStructured : DXSA_Op<"dcl_resource_structured"> {
926+
let summary = "declares a structured buffer shader input resource bound to a register";
927+
let description = [{
928+
The `dxsa.dcl_resource_structured` operation declares a structured buffer
929+
shader input resource bound to a register.
930+
931+
`$struct_byte_stride` is the structure size in bytes; it must be a multiple of 4.
932+
933+
Example:
934+
935+
```mlir
936+
dxsa.dcl_resource_structured <type = resource, components = 0, index = [3]>,
937+
<struct_byte_stride = 16>
938+
dxsa.dcl_resource_structured <type = resource, components = 0, index = [0, 0, 3]>,
939+
<struct_byte_stride = 32, space = 1>
940+
```
941+
}];
942+
943+
let arguments = (ins
944+
DXSA_InlineOperandAttr:$operand,
945+
ConfinedAttr<I32Attr, [IntPositive]>:$struct_byte_stride,
946+
OptionalAttr<I32Attr>:$space);
947+
let assemblyFormat = [{
948+
$operand `,`
949+
`<` `struct_byte_stride` `=` $struct_byte_stride
950+
(`,` `space` `=` $space^)? `>`
951+
attr-dict
952+
}];
953+
let hasVerifier = 1;
954+
}
955+
925956
#endif // DXSA_OPS

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

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

87+
LogicalResult DclResourceStructured::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+
auto stride = getStructByteStride();
93+
if (stride % 4 != 0)
94+
return emitOpError("struct byte stride must be a multiple of 4, got ")
95+
<< stride;
96+
return success();
97+
}
98+
8799
//===----------------------------------------------------------------------===//
88100
// TableGen'd attribute method definitions
89101
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

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

695+
Instruction buildDclResourceStructured(dxsa::InlineOperandAttr operand,
696+
uint32_t structByteStride,
697+
std::optional<uint32_t> space,
698+
Location loc) {
699+
auto spaceAttr = space ? builder.getI32IntegerAttr(*space) : IntegerAttr();
700+
return dxsa::DclResourceStructured::create(builder, loc, operand,
701+
structByteStride, spaceAttr);
702+
}
703+
695704
private:
696705
MLIRContext *context;
697706
ModuleOp module;
@@ -1317,6 +1326,25 @@ class Parser {
13171326
*structCount, loc);
13181327
}
13191328

1329+
FailureOr<Instruction> parseDclResourceStructured(Location loc) {
1330+
auto operand = parseInlineOperand();
1331+
FAILURE_IF_FAILED(operand);
1332+
1333+
auto strideToken = parseToken();
1334+
FAILURE_IF_FAILED(strideToken);
1335+
1336+
std::optional<uint32_t> space;
1337+
auto indexArray = operand->getIndex();
1338+
if (indexArray && indexArray.size() == 3) {
1339+
auto spaceToken = parseToken();
1340+
FAILURE_IF_FAILED(spaceToken);
1341+
space = *spaceToken;
1342+
}
1343+
1344+
return builder.buildDclResourceStructured(*operand, *strideToken, space,
1345+
loc);
1346+
}
1347+
13201348
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
13211349
Instruction &out) {
13221350
FailureOr<Instruction> result;
@@ -1393,6 +1421,9 @@ class Parser {
13931421
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
13941422
result = parseDclTgsmStructured(loc);
13951423
break;
1424+
case D3D11_SB_OPCODE_DCL_RESOURCE_STRUCTURED:
1425+
result = parseDclResourceStructured(loc);
1426+
break;
13961427
default:
13971428
return std::nullopt;
13981429
}
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_structured.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_resource_structured <type = resource, components = 0, index = [3]>, <struct_byte_stride = 16>
5+
// CHECK-NEXT: dxsa.dcl_resource_structured <type = resource, components = 0, index = [0, 0, 3]>, <struct_byte_stride = 32, space = 1>
6+
// CHECK-NEXT: }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_resource_structured' op operand must be a resource register, got temp}}
4+
dxsa.dcl_resource_structured <type = temp, components = 0, index = [0]>, <struct_byte_stride = 16>
5+
6+
// -----
7+
8+
// expected-error@+1 {{'dxsa.dcl_resource_structured' op struct byte stride must be a multiple of 4, got 6}}
9+
dxsa.dcl_resource_structured <type = resource, components = 0, index = [0]>, <struct_byte_stride = 6>
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}}
14+
dxsa.dcl_resource_structured <type = resource, components = 0, index = [0]>, <struct_byte_stride = 0>
44 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)