Skip to content

Commit ac0672b

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 014c7b3 commit ac0672b

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
@@ -719,4 +719,23 @@ def DXSA_DclOutput : DXSA_Op<"dcl_output"> {
719719
let assemblyFormat = "$operand attr-dict";
720720
}
721721

722+
def DXSA_DclGsInstanceCount : DXSA_Op<"dcl_gs_instance_count"> {
723+
let summary = "declares instance count for the geometry shader";
724+
let description = [{
725+
The `dxsa.dcl_gs_instance_count` operation declares declares instance count
726+
for the geometry shader.
727+
728+
The `$count` must be in [1, 32].
729+
730+
Example:
731+
732+
```mlir
733+
dxsa.dcl_gs_instance_count 4
734+
```
735+
}];
736+
let arguments = (ins ConfinedAttr<I32Attr,
737+
[IntPositive, IntMaxValue<32>]>:$count);
738+
let assemblyFormat = [{ $count attr-dict }];
739+
}
740+
722741
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

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

588+
Instruction buildDclGsInstanceCount(uint32_t count, Location loc) {
589+
return dxsa::DclGsInstanceCount::create(builder, loc,
590+
builder.getI32IntegerAttr(count));
591+
}
592+
588593
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
589594
Operand operand, Location loc) {
590595
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
@@ -1051,6 +1056,17 @@ class Parser {
10511056
return builder.buildDclInputPrimitive(*inputPrimitive, loc);
10521057
}
10531058

1059+
FailureOr<Instruction> parseDclGsInstanceCount(Location loc) {
1060+
auto countToken = parseToken();
1061+
FAILURE_IF_FAILED(countToken);
1062+
auto count = *countToken;
1063+
if (count == 0)
1064+
return emitError(loc, "instance count cannot be zero");
1065+
if (count > 32)
1066+
return emitError(loc, "instance count must be <= 32, got ") << count;
1067+
return builder.buildDclGsInstanceCount(count, loc);
1068+
}
1069+
10541070
FailureOr<dxsa::InterpolationMode>
10551071
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
10561072
auto rawInterpolationMode =
@@ -1205,6 +1221,9 @@ class Parser {
12051221
case D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE:
12061222
result = parseDclInputPrimitive(opcodeToken, loc);
12071223
break;
1224+
case D3D11_SB_OPCODE_DCL_GS_INSTANCE_COUNT:
1225+
result = parseDclGsInstanceCount(loc);
1226+
break;
12081227
case D3D10_SB_OPCODE_DCL_INPUT_PS:
12091228
result = parseDclInputPs(opcodeToken, loc);
12101229
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)