Skip to content

Commit ccd58cf

Browse files
committed
[mlir][dxsa] Add dcl_tgsm_raw instruction
Example: dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 40 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 2f93f2b commit ccd58cf

6 files changed

Lines changed: 66 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,7 @@ def DXSA_InlineOperandAttr : AttrDef<DXSADialect, "InlineOperand"> {
485485
"uint32_t":$components,
486486
OptionalParameter<"::mlir::dxsa::ComponentMaskAttr">:$mask,
487487
OptionalParameter<"::mlir::DenseI64ArrayAttr">:$index);
488-
let assemblyFormat = [{
489-
`<` `type` `=` $type
490-
`,` `components` `=` $components
491-
(`,` `mask` `=` $mask^)?
492-
(`,` `index` `=` $index^)?
493-
`>`
494-
}];
488+
let assemblyFormat = "`<` struct(params) `>`";
495489
}
496490

497491
def DXSA_DclGlobalFlags : DXSA_Op<"dcl_global_flags"> {
@@ -878,4 +872,26 @@ def DXSA_DclMaxOutputVertexCount :
878872
let assemblyFormat = [{ $count attr-dict }];
879873
}
880874

875+
def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
876+
let summary = "declares a reference to a Thread Group Shared Memory region";
877+
let description = [{
878+
The `dxsa.dcl_tgsm_raw` operation declares a reference to a Thread Group Shared Memory region.
879+
880+
The `$operand` is the `g#` register being declared.
881+
The `$byte_count$ is the size of the block of untyped shared memory;
882+
must be a multiple of 4.
883+
884+
Example:
885+
886+
```mlir
887+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 1024
888+
```
889+
}];
890+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
891+
ConfinedAttr<I32Attr,
892+
[IntPositive, IntMaxValue<32768>]>:$byte_count);
893+
let assemblyFormat = "$operand `,` $byte_count attr-dict";
894+
let hasVerifier = 1;
895+
}
896+
881897
#endif // DXSA_OPS

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ LogicalResult DclHsMaxTessFactor::verify() {
6363
return success();
6464
}
6565

66+
LogicalResult DclTgsmRaw::verify() {
67+
auto byteCount = getByteCount();
68+
if (byteCount % 4 != 0)
69+
return emitOpError("byte count must be a multiple of 4, got ") << byteCount;
70+
return success();
71+
}
72+
6673
//===----------------------------------------------------------------------===//
6774
// TableGen'd attribute method definitions
6875
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,12 @@ class DXBuilder {
678678
builder, loc, builder.getUI32IntegerAttr(count));
679679
}
680680

681+
Instruction buildDclTgsmRaw(dxsa::InlineOperandAttr operand,
682+
uint32_t byteCount, Location loc) {
683+
return dxsa::DclTgsmRaw::create(builder, loc, operand,
684+
builder.getI32IntegerAttr(byteCount));
685+
}
686+
681687
private:
682688
MLIRContext *context;
683689
ModuleOp module;
@@ -1284,6 +1290,14 @@ class Parser {
12841290
return builder.buildDclHsForkPhaseInstanceCount(*count, loc);
12851291
}
12861292

1293+
FailureOr<Instruction> parseDclTgsmRaw(Location loc) {
1294+
auto operand = parseInlineOperand();
1295+
FAILURE_IF_FAILED(operand);
1296+
auto byteCount = parseToken();
1297+
FAILURE_IF_FAILED(byteCount);
1298+
return builder.buildDclTgsmRaw(*operand, *byteCount, loc);
1299+
}
1300+
12871301
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
12881302
Instruction &out) {
12891303
FailureOr<Instruction> result;
@@ -1354,6 +1368,9 @@ class Parser {
13541368
case D3D11_SB_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT:
13551369
result = parseDclHsForkPhaseInstanceCount(loc);
13561370
break;
1371+
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
1372+
result = parseDclTgsmRaw(loc);
1373+
break;
13571374
default:
13581375
return std::nullopt;
13591376
}
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_raw.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 40
5+
// 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_tgsm_raw' op byte count must be a multiple of 4, got 42}}
4+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 42
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
9+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 0
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
14+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 32769
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)