Skip to content

Commit 00b41ee

Browse files
committed
[mlir][dxsa] Add dcl_hs_max_tessfactor instruction
Example: dxsa.dcl_hs_max_tessfactor 6.400000e+01 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent d7b8e52 commit 00b41ee

6 files changed

Lines changed: 78 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
@@ -771,4 +771,23 @@ def DXSA_DclOutputSiv : DXSA_Op<"dcl_output_siv"> {
771771
let assemblyFormat = "$operand `,` $name attr-dict";
772772
}
773773

774+
def DXSA_DclHsMaxTessFactor : DXSA_Op<"dcl_hs_max_tessfactor"> {
775+
let summary = "declares the MaxTessFactor for the patch";
776+
let description = [{
777+
The `dxsa.dcl_hs_max_tessfactor` operation declares the MaxTessFactor
778+
for the patch.
779+
780+
The `$max_tessfactor` is a float32 value in the range [1.0, 64.0].
781+
782+
Example:
783+
784+
```mlir
785+
dxsa.dcl_hs_max_tessfactor 4.200000e+01
786+
```
787+
}];
788+
let arguments = (ins F32Attr:$max_tessfactor);
789+
let assemblyFormat = "$max_tessfactor attr-dict";
790+
let hasVerifier = 1;
791+
}
792+
774793
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ LogicalResult DclIndexRange::verify() {
5454
return success();
5555
}
5656

57+
LogicalResult DclHsMaxTessFactor::verify() {
58+
auto value = getMaxTessfactorAttr().getValue();
59+
if (!value.isFinite() || value < llvm::APFloat(1.0f) ||
60+
value > llvm::APFloat(64.0f))
61+
return emitOpError("MaxTessFactor must be in [1.0, 64.0], got ")
62+
<< value.convertToFloat();
63+
return success();
64+
}
65+
5766
//===----------------------------------------------------------------------===//
5867
// TableGen'd attribute method definitions
5968
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mlir/IR/Location.h"
1313
#include "llvm/ADT/ArrayRef.h"
1414
#include "llvm/ADT/SmallVector.h"
15+
#include "llvm/ADT/bit.h"
1516
#include "llvm/Support/Debug.h"
1617
#include "llvm/Support/DebugLog.h"
1718
#include "llvm/Support/Endian.h"
@@ -653,6 +654,11 @@ class DXBuilder {
653654
return dxsa::DclOutputSiv::create(builder, loc, operand, nameAttr);
654655
}
655656

657+
Instruction buildDclHsMaxTessFactor(float maxTessFactor, Location loc) {
658+
return dxsa::DclHsMaxTessFactor::create(
659+
builder, loc, builder.getF32FloatAttr(maxTessFactor));
660+
}
661+
656662
private:
657663
MLIRContext *context;
658664
ModuleOp module;
@@ -1216,6 +1222,13 @@ class Parser {
12161222
return builder.buildDclOutputSiv(*operand, *name, loc);
12171223
}
12181224

1225+
FailureOr<Instruction> parseDclHsMaxTessFactor(Location loc) {
1226+
auto token = parseToken();
1227+
FAILURE_IF_FAILED(token);
1228+
auto maxTessFactor = llvm::bit_cast<float>(*token);
1229+
return builder.buildDclHsMaxTessFactor(maxTessFactor, loc);
1230+
}
1231+
12191232
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
12201233
Instruction &out) {
12211234
FailureOr<Instruction> result;
@@ -1271,6 +1284,9 @@ class Parser {
12711284
case D3D10_SB_OPCODE_DCL_OUTPUT_SIV:
12721285
result = parseDclOutputSiv(loc);
12731286
break;
1287+
case D3D11_SB_OPCODE_DCL_HS_MAX_TESSFACTOR:
1288+
result = parseDclHsMaxTessFactor(loc);
1289+
break;
12741290
default:
12751291
return std::nullopt;
12761292
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_hs_max_tessfactor.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_hs_max_tessfactor 4.200000e+01
5+
// CHECK-NEXT: }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got 5.000000e-01}}
4+
dxsa.dcl_hs_max_tessfactor 0.5
5+
6+
// -----
7+
8+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got -1.000000e+00}}
9+
dxsa.dcl_hs_max_tessfactor -1.000000e+00
10+
11+
// -----
12+
13+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got 6.500000e+01}}
14+
dxsa.dcl_hs_max_tessfactor 6.500000e+01
15+
16+
// -----
17+
18+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got nan}}
19+
dxsa.dcl_hs_max_tessfactor 0x7FC00000
20+
21+
// -----
22+
23+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got INF}}
24+
dxsa.dcl_hs_max_tessfactor 0x7F800000
25+
26+
// -----
27+
28+
// expected-error@+1 {{'dxsa.dcl_hs_max_tessfactor' op MaxTessFactor must be in [1.0, 64.0], got -INF}}
29+
dxsa.dcl_hs_max_tessfactor 0xFF800000
8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)