Skip to content

Commit b33f6d4

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

6 files changed

Lines changed: 82 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_DclHsMaxTessFactor : DXSA_Op<"dcl_hs_max_tessfactor"> {
723+
let summary = "declares the MaxTessFactor for the patch";
724+
let description = [{
725+
The `dxsa.dcl_hs_max_tessfactor` operation declares the MaxTessFactor
726+
for the patch.
727+
728+
The `$max_tessfactor` is a float32 value in the range [1.0, 64.0].
729+
730+
Example:
731+
732+
```mlir
733+
dxsa.dcl_hs_max_tessfactor 4.200000e+01
734+
```
735+
}];
736+
let arguments = (ins F32Attr:$max_tessfactor);
737+
let assemblyFormat = "$max_tessfactor attr-dict";
738+
let hasVerifier = 1;
739+
}
740+
722741
#endif // DXSA_OPS

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ void DXSADialect::initialize() {
4141
#define GET_OP_CLASSES
4242
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
4343

44+
//===----------------------------------------------------------------------===//
45+
// Op verifiers
46+
//===----------------------------------------------------------------------===//
47+
48+
LogicalResult DclHsMaxTessFactor::verify() {
49+
auto value = getMaxTessfactorAttr().getValue();
50+
if (!value.isFinite() || value < llvm::APFloat(1.0f) ||
51+
value > llvm::APFloat(64.0f))
52+
return emitOpError("MaxTessFactor must be in [1.0, 64.0], got ")
53+
<< value.convertToFloat();
54+
return success();
55+
}
56+
4457
//===----------------------------------------------------------------------===//
4558
// TableGen'd attribute method definitions
4659
//===----------------------------------------------------------------------===//

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"
@@ -635,6 +636,11 @@ class DXBuilder {
635636
return dxsa::DclOutput::create(builder, loc, operand);
636637
}
637638

639+
Instruction buildDclHsMaxTessFactor(float maxTessFactor, Location loc) {
640+
return dxsa::DclHsMaxTessFactor::create(
641+
builder, loc, builder.getF32FloatAttr(maxTessFactor));
642+
}
643+
638644
private:
639645
MLIRContext *context;
640646
ModuleOp module;
@@ -1174,6 +1180,13 @@ class Parser {
11741180
return builder.buildDclOutput(*operand, loc);
11751181
}
11761182

1183+
FailureOr<Instruction> parseDclHsMaxTessFactor(Location loc) {
1184+
auto token = parseToken();
1185+
FAILURE_IF_FAILED(token);
1186+
auto maxTessFactor = llvm::bit_cast<float>(*token);
1187+
return builder.buildDclHsMaxTessFactor(maxTessFactor, loc);
1188+
}
1189+
11771190
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
11781191
Instruction &out) {
11791192
FailureOr<Instruction> result;
@@ -1220,6 +1233,9 @@ class Parser {
12201233
case D3D10_SB_OPCODE_DCL_OUTPUT:
12211234
result = parseDclOutput(loc);
12221235
break;
1236+
case D3D11_SB_OPCODE_DCL_HS_MAX_TESSFACTOR:
1237+
result = parseDclHsMaxTessFactor(loc);
1238+
break;
12231239
default:
12241240
return std::nullopt;
12251241
}
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)