-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDXSA.cpp
More file actions
177 lines (151 loc) · 6.12 KB
/
Copy pathDXSA.cpp
File metadata and controls
177 lines (151 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//===--------------- DXSA.cpp - MLIR DXSA Operations ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/DXSA/IR/DXSA.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;
using namespace mlir::dxsa;
#include "mlir/Dialect/DXSA/IR/DXSAOpsDialect.cpp.inc"
#include "mlir/Dialect/DXSA/IR/DXSAOpsEnums.cpp.inc"
void DXSADialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
>();
addTypes<
#define GET_TYPEDEF_LIST
#include "mlir/Dialect/DXSA/IR/DXSAOpsTypes.cpp.inc"
>();
addAttributes<
#define GET_ATTRDEF_LIST
#include "mlir/Dialect/DXSA/IR/DXSAOpsAttributes.cpp.inc"
>();
}
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//
#define GET_OP_CLASSES
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
//===----------------------------------------------------------------------===//
// ModuleOp
//===----------------------------------------------------------------------===//
void ModuleOp::build(OpBuilder &builder, OperationState &state,
ProgramTypeAttr programType,
ShaderVersionAttr shaderVersion) {
if (programType)
state.addAttribute("program_type", programType);
if (shaderVersion)
state.addAttribute("shader_version", shaderVersion);
OpBuilder::InsertionGuard guard(builder);
builder.createBlock(state.addRegion());
}
ParseResult ModuleOp::parse(OpAsmParser &parser, OperationState &result) {
// Parse optional shader information like `pixel_shader 5 0`.
StringRef typeKeyword;
auto typeLoc = parser.getCurrentLocation();
if (succeeded(parser.parseOptionalKeyword(&typeKeyword))) {
auto programType = symbolizeProgramType(typeKeyword);
if (!programType)
return parser.emitError(typeLoc)
<< "unknown program type: " << typeKeyword;
result.addAttribute("program_type", ProgramTypeAttr::get(
parser.getContext(), *programType));
uint8_t major = 0, minor = 0;
if (parser.parseInteger(major) || parser.parseInteger(minor))
return failure();
result.addAttribute(
"shader_version",
ShaderVersionAttr::get(parser.getContext(), major, minor));
}
Region *body = result.addRegion();
if (parser.parseOptionalAttrDictWithKeyword(result.attributes) ||
parser.parseRegion(*body, /*arguments=*/{}))
return failure();
if (body->empty())
body->push_back(new Block());
return success();
}
void ModuleOp::print(OpAsmPrinter &printer) {
if (auto programType = getProgramType()) {
printer << ' ' << stringifyProgramType(*programType);
auto version = getShaderVersionAttr();
printer << ' ' << static_cast<unsigned>(version.getMajor()) << ' '
<< static_cast<unsigned>(version.getMinor());
}
printer.printOptionalAttrDictWithKeyword((*this)->getAttrs(),
{"program_type", "shader_version"});
printer << ' ';
printer.printRegion(getBody());
}
LogicalResult ModuleOp::verify() {
bool hasType = static_cast<bool>(getProgramTypeAttr());
bool hasVersion = static_cast<bool>(getShaderVersionAttr());
if (hasType != hasVersion)
return emitOpError(
"program_type and shader_version must both be present or both absent");
return success();
}
//===----------------------------------------------------------------------===//
// Op verifiers
//===----------------------------------------------------------------------===//
LogicalResult DclIndexRange::verify() {
auto operandType = getOperand().getType();
if (operandType != InlineOperandType::input &&
operandType != InlineOperandType::output)
return emitOpError("operand must be an input or output register, got ")
<< stringifyInlineOperandType(operandType);
return success();
}
LogicalResult DclHsMaxTessFactor::verify() {
auto value = getMaxTessfactorAttr().getValue();
if (!value.isFinite() || value < llvm::APFloat(1.0f) ||
value > llvm::APFloat(64.0f))
return emitOpError("MaxTessFactor must be in [1.0, 64.0], got ")
<< value.convertToFloat();
return success();
}
LogicalResult DclTgsmRaw::verify() {
auto byteCount = getByteCount();
if (byteCount % 4 != 0)
return emitOpError("byte count must be a multiple of 4, got ") << byteCount;
return success();
}
LogicalResult DclTgsmStructured::verify() {
auto stride = getStructByteStride();
auto count = getStructCount();
if (stride % 4 != 0)
return emitOpError("struct byte stride must be a multiple of 4, got ")
<< stride;
auto totalSize = static_cast<uint64_t>(stride) * count;
if (totalSize > 32768)
return emitOpError("total size struct_byte_stride * struct_count must "
"be <= 32768, got ")
<< totalSize;
return success();
}
LogicalResult DclConstantBuffer::verify() {
auto lbound = getLbound();
auto ubound = getUbound();
if (lbound && ubound && *lbound > *ubound)
return emitOpError("expected lbound <= ubound, got lbound=")
<< *lbound << ", ubound=" << *ubound;
return success();
}
//===----------------------------------------------------------------------===//
// TableGen'd attribute method definitions
//===----------------------------------------------------------------------===//
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/DXSA/IR/DXSAOpsAttributes.cpp.inc"
//===----------------------------------------------------------------------===//
// TableGen'd type method definitions
//===----------------------------------------------------------------------===//
#define GET_TYPEDEF_CLASSES
#include "mlir/Dialect/DXSA/IR/DXSAOpsTypes.cpp.inc"