Skip to content

Commit bfa590e

Browse files
committed
[mlir][dxsa] Add dcl_max_output_vertex_count instruction
Example: dxsa.dcl_max_output_vertex_count 42 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 014c7b3 commit bfa590e

5 files changed

Lines changed: 63 additions & 2 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,25 @@ def DXSA_DclOutput : DXSA_Op<"dcl_output"> {
719719
let assemblyFormat = "$operand attr-dict";
720720
}
721721

722+
def DXSA_DclMaxOutputVertexCount :
723+
DXSA_Op<"dcl_max_output_vertex_count"> {
724+
let summary = "declares the geometry shader maximum output vertex count";
725+
let description = [{
726+
The `dxsa.dcl_max_output_vertex_count` operation declares the maximum
727+
number of vertices that a single invocation of the geometry shader will
728+
emit.
729+
730+
The count must be in [1, 1024].
731+
732+
Example:
733+
734+
```mlir
735+
dxsa.dcl_max_output_vertex_count 42
736+
```
737+
}];
738+
let arguments = (ins ConfinedAttr<I32Attr,
739+
[IntPositive, IntMaxValue<1024>]>:$count);
740+
let assemblyFormat = [{ $count attr-dict }];
741+
}
742+
722743
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ static void initInstructionInfo(MutableArrayRef<InstructionInfo> instructions) {
158158
D3D10_SB_DCL_OP);
159159
SET(D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY, "dcl_outputtopology", 0,
160160
0x00, D3D10_SB_DCL_OP);
161-
SET(D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT, "dcl_maxout", 0, 0x00,
162-
D3D10_SB_DCL_OP);
161+
SET(D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT,
162+
"dcl_max_output_vertex_count", 0, 0x00, D3D10_SB_DCL_OP);
163163
SET(D3D10_SB_OPCODE_DCL_INPUT_PS, "dcl_input_ps", 1, 0x00, D3D10_SB_DCL_OP);
164164
SET(D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER, "dcl_constantbuffer", 1, 0x00,
165165
D3D10_SB_DCL_OP);
@@ -585,6 +585,10 @@ class DXBuilder {
585585
return dxsa::DclInputPrimitive::create(builder, loc, inputPrimitiveAttr);
586586
}
587587

588+
Instruction buildDclMaxOutputVertexCount(uint32_t count, Location loc) {
589+
return dxsa::DclMaxOutputVertexCount::create(builder, loc, count);
590+
}
591+
588592
Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode,
589593
Operand operand, Location loc) {
590594
auto interpolationModeAttr = dxsa::InterpolationModeAttr::get(
@@ -1051,6 +1055,19 @@ class Parser {
10511055
return builder.buildDclInputPrimitive(*inputPrimitive, loc);
10521056
}
10531057

1058+
FailureOr<Instruction> parseDclMaxOutputVertexCount(Location loc) {
1059+
auto countToken = parseToken();
1060+
FAILURE_IF_FAILED(countToken);
1061+
auto count = *countToken;
1062+
if (count == 0)
1063+
return emitError(getLocation(), "max output vertex count cannot be zero");
1064+
if (count > 1024)
1065+
return emitError(getLocation(),
1066+
"max output vertex count must be <= 1024, got ")
1067+
<< count;
1068+
return builder.buildDclMaxOutputVertexCount(count, loc);
1069+
}
1070+
10541071
FailureOr<dxsa::InterpolationMode>
10551072
parseInterpolationMode(uint32_t opcodeToken, Location loc) {
10561073
auto rawInterpolationMode =
@@ -1205,6 +1222,9 @@ class Parser {
12051222
case D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE:
12061223
result = parseDclInputPrimitive(opcodeToken, loc);
12071224
break;
1225+
case D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT:
1226+
result = parseDclMaxOutputVertexCount(loc);
1227+
break;
12081228
case D3D10_SB_OPCODE_DCL_INPUT_PS:
12091229
result = parseDclInputPs(opcodeToken, loc);
12101230
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_max_output_vertex_count.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_max_output_vertex_count 1
5+
// CHECK-NEXT: dxsa.dcl_max_output_vertex_count 1024
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 1024}}
4+
dxsa.dcl_max_output_vertex_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 1024}}
9+
dxsa.dcl_max_output_vertex_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 1024}}
14+
dxsa.dcl_max_output_vertex_count 1025
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)