Skip to content

Commit c0fee1a

Browse files
committed
[mlir][dxsa] Add dcl_gs_instance_count instruction
Example: dxsa.dcl_gs_instance_count 4 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent f7e0032 commit c0fee1a

5 files changed

Lines changed: 58 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,23 @@ def DXSA_DclHsForkPhaseInstanceCount :
838838
let assemblyFormat = "$count attr-dict";
839839
}
840840

841+
def DXSA_DclGsInstanceCount : DXSA_Op<"dcl_gs_instance_count"> {
842+
let summary = "declares instance count for the geometry shader";
843+
let description = [{
844+
The `dxsa.dcl_gs_instance_count` operation declares declares instance count
845+
for the geometry shader.
846+
847+
The `$count` must be in [1, 32].
848+
849+
Example:
850+
851+
```mlir
852+
dxsa.dcl_gs_instance_count 4
853+
```
854+
}];
855+
let arguments = (ins ConfinedAttr<I32Attr,
856+
[IntPositive, IntMaxValue<32>]>:$count);
857+
let assemblyFormat = [{ $count attr-dict }];
858+
}
859+
841860
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ class DXBuilder {
586586
return dxsa::DclInputPrimitive::create(builder, loc, inputPrimitiveAttr);
587587
}
588588

589+
Instruction buildDclGsInstanceCount(uint32_t count, Location loc) {
590+
return dxsa::DclGsInstanceCount::create(builder, loc,
591+
builder.getI32IntegerAttr(count));
592+
}
593+
589594
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
590595
Operand operand, Location loc) {
591596
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
@@ -1085,6 +1090,17 @@ class Parser {
10851090
return builder.buildDclInputPrimitive(*inputPrimitive, loc);
10861091
}
10871092

1093+
FailureOr<Instruction> parseDclGsInstanceCount(Location loc) {
1094+
auto countToken = parseToken();
1095+
FAILURE_IF_FAILED(countToken);
1096+
auto count = *countToken;
1097+
if (count == 0)
1098+
return emitError(loc, "instance count cannot be zero");
1099+
if (count > 32)
1100+
return emitError(loc, "instance count must be <= 32, got ") << count;
1101+
return builder.buildDclGsInstanceCount(count, loc);
1102+
}
1103+
10881104
FailureOr<dxsa::InterpolationMode>
10891105
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
10901106
auto rawInterpolationMode =
@@ -1282,6 +1298,9 @@ class Parser {
12821298
case D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE:
12831299
result = parseDclInputPrimitive(opcodeToken, loc);
12841300
break;
1301+
case D3D11_SB_OPCODE_DCL_GS_INSTANCE_COUNT:
1302+
result = parseDclGsInstanceCount(loc);
1303+
break;
12851304
case D3D10_SB_OPCODE_DCL_INPUT_PS:
12861305
result = parseDclInputPs(opcodeToken, loc);
12871306
break;
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_gs_instance_count.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_gs_instance_count 1
5+
// CHECK-NEXT: dxsa.dcl_gs_instance_count 32
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 {{attribute 'count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32}}
4+
dxsa.dcl_gs_instance_count -1
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32}}
9+
dxsa.dcl_gs_instance_count 0
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32}}
14+
dxsa.dcl_gs_instance_count 33
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)