Skip to content

Commit a963016

Browse files
committed
[mlir][dxsa] Add dcl_input_control_point_count and dcl_output_control_point_count instructions
Example: dxsa.dcl_input_control_point_count 3 dxsa.dcl_output_control_point_count 4 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 856b5d3 commit a963016

8 files changed

Lines changed: 124 additions & 1 deletion

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,44 @@ def DXSA_DclTemps : DXSA_Op<"dcl_temps"> {
158158
let assemblyFormat = [{ $count attr-dict }];
159159
}
160160

161+
def DXSA_DclInputControlPointCount :
162+
DXSA_Op<"dcl_input_control_point_count"> {
163+
let summary = "declares the hull shader input control point count";
164+
let description = [{
165+
The `dxsa.dcl_input_control_point_count` operation declares the number of
166+
input control points for the hull shader.
167+
168+
The count must be in [1, 32].
169+
170+
Example:
171+
172+
```mlir
173+
dxsa.dcl_input_control_point_count 3
174+
```
175+
}];
176+
let arguments = (ins ConfinedAttr<I32Attr,
177+
[IntPositive, IntMaxValue<32>]>:$count);
178+
let assemblyFormat = [{ $count attr-dict }];
179+
}
180+
181+
def DXSA_DclOutputControlPointCount :
182+
DXSA_Op<"dcl_output_control_point_count"> {
183+
let summary = "declares the hull shader output control point count";
184+
let description = [{
185+
The `dxsa.dcl_output_control_point_count` operation declares the number
186+
of output control points for the hull shader.
187+
188+
The count must be in [0, 32].
189+
190+
Example:
191+
192+
```mlir
193+
dxsa.dcl_output_control_point_count 4
194+
```
195+
}];
196+
let arguments = (ins ConfinedAttr<I32Attr,
197+
[IntNonNegative, IntMaxValue<32>]>:$count);
198+
let assemblyFormat = [{ $count attr-dict }];
199+
}
200+
161201
#endif // DXSA_OPS

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
#include <optional>
2121

22-
#include "d3d12TokenizedProgramFormat.hpp"
22+
// d3d12TokenizedProgramFormat.hpp references the `UINT` type in some DECODE_*
23+
// macros. Mirror the Windows SDK alias (`typedef unsigned int UINT`) to use the
24+
// header without modification.
25+
using UINT = unsigned int;
26+
#include "d3d12TokenizedProgramFormat.hpp" // NOLINT
2327

2428
#define DEBUG_TYPE "import-dxsa-bin"
2529

@@ -516,6 +520,16 @@ class DXBuilder {
516520
builder.getI32IntegerAttr(count));
517521
}
518522

523+
Instruction buildDclInputControlPointCount(uint32_t count, Location loc) {
524+
return dxsa::DclInputControlPointCount::create(
525+
builder, loc, builder.getI32IntegerAttr(count));
526+
}
527+
528+
Instruction buildDclOutputControlPointCount(uint32_t count, Location loc) {
529+
return dxsa::DclOutputControlPointCount::create(
530+
builder, loc, builder.getI32IntegerAttr(count));
531+
}
532+
519533
private:
520534
MLIRContext *context;
521535
ModuleOp module;
@@ -831,6 +845,30 @@ class Parser {
831845
return builder.buildDclTemps(count, loc);
832846
}
833847

848+
FailureOr<Instruction> parseDclInputControlPointCount(uint32_t opcodeToken,
849+
Location loc) {
850+
auto count = DECODE_D3D11_SB_INPUT_CONTROL_POINT_COUNT(opcodeToken);
851+
if (count == 0) {
852+
emitError(loc, "input control point count cannot be zero");
853+
return failure();
854+
}
855+
if (count > 32) {
856+
emitError(loc, "input control point count must be <= 32, got ") << count;
857+
return failure();
858+
}
859+
return builder.buildDclInputControlPointCount(count, loc);
860+
}
861+
862+
FailureOr<Instruction> parseDclOutputControlPointCount(uint32_t opcodeToken,
863+
Location loc) {
864+
auto count = DECODE_D3D11_SB_OUTPUT_CONTROL_POINT_COUNT(opcodeToken);
865+
if (count > 32) {
866+
emitError(loc, "output control point count must be <= 32, got ") << count;
867+
return failure();
868+
}
869+
return builder.buildDclOutputControlPointCount(count, loc);
870+
}
871+
834872
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
835873
Instruction &out) {
836874
FailureOr<Instruction> result;
@@ -841,6 +879,12 @@ class Parser {
841879
case D3D10_SB_OPCODE_DCL_TEMPS:
842880
result = parseDclTemps(loc);
843881
break;
882+
case D3D11_SB_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT:
883+
result = parseDclInputControlPointCount(opcodeToken, loc);
884+
break;
885+
case D3D11_SB_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT:
886+
result = parseDclOutputControlPointCount(opcodeToken, loc);
887+
break;
844888
default:
845889
return std::nullopt;
846890
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_control_point_count.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_input_control_point_count 1
5+
// CHECK-NEXT: dxsa.dcl_input_control_point_count 3
6+
// CHECK-NEXT: dxsa.dcl_input_control_point_count 16
7+
// CHECK-NEXT: dxsa.dcl_input_control_point_count 32
8+
// 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_input_control_point_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_input_control_point_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_input_control_point_count 33
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_output_control_point_count.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_output_control_point_count 0
5+
// CHECK-NEXT: dxsa.dcl_output_control_point_count 1
6+
// CHECK-NEXT: dxsa.dcl_output_control_point_count 4
7+
// CHECK-NEXT: dxsa.dcl_output_control_point_count 32
8+
// CHECK-NEXT: }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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 non-negative whose maximum value is 32}}
4+
dxsa.dcl_output_control_point_count -1
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'count' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative whose maximum value is 32}}
9+
dxsa.dcl_output_control_point_count 33
16 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)