Skip to content

Commit b5513e1

Browse files
committed
[mlir][dxsa] Add dcl_tgsm_structured instruction
Example: dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 64a63c0 commit b5513e1

6 files changed

Lines changed: 97 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
@@ -736,4 +736,32 @@ def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
736736
let hasVerifier = 1;
737737
}
738738

739+
def DXSA_DclTgsmStructured : DXSA_Op<"dcl_tgsm_structured"> {
740+
let summary = "declares a reference to a region of shared memory space available to the shader's thread group";
741+
let description = [{
742+
The `dxsa.dcl_tgsm_structured` operation declares a reference
743+
to a region of shared memory space available to the shader's thread group.
744+
745+
The `$operand` is the `g#` register being declared.
746+
The `$struct_byte_stride` is a uint in bytes and must be a multiple of 4.
747+
The `$struct_count` is the number of structures.
748+
The total size `$struct_byte_stride * $struct_count` must not exceed
749+
32 KB.
750+
751+
Example:
752+
753+
```mlir
754+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64
755+
```
756+
}];
757+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
758+
ConfinedAttr<I32Attr,
759+
[IntPositive, IntMaxValue<32768>]>:$struct_byte_stride,
760+
ConfinedAttr<I32Attr,
761+
[IntPositive, IntMaxValue<8192>]>:$struct_count);
762+
let assemblyFormat =
763+
"$operand `,` $struct_byte_stride `,` $struct_count attr-dict";
764+
let hasVerifier = 1;
765+
}
766+
739767
#endif // DXSA_OPS

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ LogicalResult DclTgsmRaw::verify() {
5252
return success();
5353
}
5454

55+
LogicalResult DclTgsmStructured::verify() {
56+
auto stride = getStructByteStride();
57+
auto count = getStructCount();
58+
if (stride % 4 != 0)
59+
return emitOpError("struct byte stride must be a multiple of 4, got ")
60+
<< stride;
61+
auto totalSize = static_cast<uint64_t>(stride) * count;
62+
if (totalSize > 32768)
63+
return emitOpError("total size struct_byte_stride * struct_count must "
64+
"be <= 32768, got ") << totalSize;
65+
return success();
66+
}
67+
5568
//===----------------------------------------------------------------------===//
5669
// TableGen'd attribute method definitions
5770
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ class DXBuilder {
641641
builder.getI32IntegerAttr(byteCount));
642642
}
643643

644+
Instruction buildDclTgsmStructured(dxsa::InlineOperandAttr operand,
645+
uint32_t structByteStride,
646+
uint32_t structCount, Location loc) {
647+
return dxsa::DclTgsmStructured::create(
648+
builder, loc, operand, builder.getI32IntegerAttr(structByteStride),
649+
builder.getI32IntegerAttr(structCount));
650+
}
651+
644652
private:
645653
MLIRContext *context;
646654
ModuleOp module;
@@ -1188,6 +1196,17 @@ class Parser {
11881196
return builder.buildDclTgsmRaw(*operand, *byteCount, loc);
11891197
}
11901198

1199+
FailureOr<Instruction> parseDclTgsmStructured(Location loc) {
1200+
auto operand = parseInlineOperand();
1201+
FAILURE_IF_FAILED(operand);
1202+
auto structByteStride = parseToken();
1203+
FAILURE_IF_FAILED(structByteStride);
1204+
auto structCount = parseToken();
1205+
FAILURE_IF_FAILED(structCount);
1206+
return builder.buildDclTgsmStructured(*operand, *structByteStride,
1207+
*structCount, loc);
1208+
}
1209+
11911210
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
11921211
Instruction &out) {
11931212
FailureOr<Instruction> result;
@@ -1237,6 +1256,9 @@ class Parser {
12371256
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
12381257
result = parseDclTgsmRaw(loc);
12391258
break;
1259+
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
1260+
result = parseDclTgsmStructured(loc);
1261+
break;
12401262
default:
12411263
return std::nullopt;
12421264
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_tgsm_structured.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64
5+
// CHECK-NEXT: }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_tgsm_structured' op struct byte stride must be a multiple of 4, got 6}}
4+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 6, 64
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
9+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 0, 64
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
14+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 32772, 1
15+
16+
// -----
17+
18+
// expected-error@+1 {{attribute 'struct_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 8192}}
19+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 0
20+
21+
// -----
22+
23+
// expected-error@+1 {{attribute 'struct_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 8192}}
24+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 4, 8193
25+
26+
// -----
27+
28+
// expected-error@+1 {{'dxsa.dcl_tgsm_structured' op total size struct_byte_stride * struct_count must be <= 32768, got 32768 * 2}}
29+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 32768, 2
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)