Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,7 @@ def DXSA_InlineOperandAttr : AttrDef<DXSADialect, "InlineOperand"> {
"uint32_t":$components,
OptionalParameter<"::mlir::dxsa::ComponentMaskAttr">:$mask,
OptionalParameter<"::mlir::DenseI64ArrayAttr">:$index);
let assemblyFormat = [{
`<` `type` `=` $type
`,` `components` `=` $components
(`,` `mask` `=` $mask^)?
(`,` `index` `=` $index^)?
`>`
}];
let assemblyFormat = "`<` struct(params) `>`";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice, we need to use this shortcut for other instructions as well.

}

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

def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
let summary = "declares a reference to a Thread Group Shared Memory region";
let description = [{
The `dxsa.dcl_tgsm_raw` operation declares a reference to a Thread Group Shared Memory region.

The `$operand` is the `g#` register being declared.
The `$byte_count$ is the size of the block of untyped shared memory;
must be a multiple of 4.

Example:

```mlir
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 1024
```
}];
let arguments = (ins DXSA_InlineOperandAttr:$operand,
ConfinedAttr<I32Attr,
[IntPositive, IntMaxValue<32768>]>:$byte_count);
let assemblyFormat = "$operand `,` $byte_count attr-dict";
let hasVerifier = 1;
}

#endif // DXSA_OPS
7 changes: 7 additions & 0 deletions mlir/lib/Dialect/DXSA/IR/DXSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ LogicalResult DclHsMaxTessFactor::verify() {
return success();
}

LogicalResult DclTgsmRaw::verify() {
auto byteCount = getByteCount();
if (byteCount % 4 != 0)
return emitOpError("byte count must be a multiple of 4, got ") << byteCount;
return success();
}

//===----------------------------------------------------------------------===//
// TableGen'd attribute method definitions
//===----------------------------------------------------------------------===//
Expand Down
17 changes: 17 additions & 0 deletions mlir/lib/Target/DXSA/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ class DXBuilder {
builder, loc, builder.getUI32IntegerAttr(count));
}

Instruction buildDclTgsmRaw(dxsa::InlineOperandAttr operand,
uint32_t byteCount, Location loc) {
return dxsa::DclTgsmRaw::create(builder, loc, operand,
builder.getI32IntegerAttr(byteCount));
}

private:
MLIRContext *context;
ModuleOp module;
Expand Down Expand Up @@ -1284,6 +1290,14 @@ class Parser {
return builder.buildDclHsForkPhaseInstanceCount(*count, loc);
}

FailureOr<Instruction> parseDclTgsmRaw(Location loc) {
auto operand = parseInlineOperand();
FAILURE_IF_FAILED(operand);
auto byteCount = parseToken();
FAILURE_IF_FAILED(byteCount);
return builder.buildDclTgsmRaw(*operand, *byteCount, loc);
}

OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
Instruction &out) {
FailureOr<Instruction> result;
Expand Down Expand Up @@ -1354,6 +1368,9 @@ class Parser {
case D3D11_SB_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT:
result = parseDclHsForkPhaseInstanceCount(loc);
break;
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
result = parseDclTgsmRaw(loc);
break;
default:
return std::nullopt;
}
Expand Down
5 changes: 5 additions & 0 deletions mlir/test/Target/DXSA/dcl_tgsm_raw.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_tgsm_raw.bin | FileCheck %s

// CHECK: module {
// CHECK-NEXT: dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 40
// CHECK-NEXT: }
14 changes: 14 additions & 0 deletions mlir/test/Target/DXSA/dcl_tgsm_raw_invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics

// expected-error@+1 {{'dxsa.dcl_tgsm_raw' op byte count must be a multiple of 4, got 42}}
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 42

// -----

// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 0

// -----

// expected-error@+1 {{attribute 'byte_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 32769
Binary file added mlir/test/Target/DXSA/inputs/dcl_tgsm_raw.bin
Binary file not shown.