|
12 | 12 | #include "mlir/IR/Location.h" |
13 | 13 | #include "llvm/ADT/ArrayRef.h" |
14 | 14 | #include "llvm/ADT/SmallVector.h" |
| 15 | +#include "llvm/ADT/bit.h" |
15 | 16 | #include "llvm/Support/Debug.h" |
16 | 17 | #include "llvm/Support/DebugLog.h" |
17 | 18 | #include "llvm/Support/Endian.h" |
@@ -635,6 +636,18 @@ class DXBuilder { |
635 | 636 | return dxsa::DclOutput::create(builder, loc, operand); |
636 | 637 | } |
637 | 638 |
|
| 639 | + Instruction buildDclConstantBuffer( |
| 640 | + uint32_t id, uint32_t size, std::optional<uint32_t> lbound, |
| 641 | + std::optional<uint32_t> ubound, std::optional<uint32_t> space, |
| 642 | + dxsa::ConstantBufferAccessPattern accessPattern, Location loc) { |
| 643 | + auto optionalToAttr = [&](std::optional<uint32_t> v) -> IntegerAttr { |
| 644 | + return v ? builder.getI32IntegerAttr(*v) : IntegerAttr(); |
| 645 | + }; |
| 646 | + return dxsa::DclConstantBuffer::create( |
| 647 | + builder, loc, id, size, optionalToAttr(lbound), optionalToAttr(ubound), |
| 648 | + optionalToAttr(space), accessPattern); |
| 649 | + } |
| 650 | + |
638 | 651 | private: |
639 | 652 | MLIRContext *context; |
640 | 653 | ModuleOp module; |
@@ -1174,6 +1187,63 @@ class Parser { |
1174 | 1187 | return builder.buildDclOutput(*operand, loc); |
1175 | 1188 | } |
1176 | 1189 |
|
| 1190 | + FailureOr<Instruction> parseDclConstantBuffer(uint32_t opcodeToken, |
| 1191 | + Location loc) { |
| 1192 | + auto rawAccessPattern = |
| 1193 | + DECODE_D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN(opcodeToken); |
| 1194 | + auto accessPattern = |
| 1195 | + dxsa::symbolizeConstantBufferAccessPattern(rawAccessPattern); |
| 1196 | + if (!accessPattern) |
| 1197 | + return emitError(loc, "unknown constant buffer access pattern: ") |
| 1198 | + << rawAccessPattern; |
| 1199 | + |
| 1200 | + auto operandToken = parseToken(); |
| 1201 | + FAILURE_IF_FAILED(operandToken); |
| 1202 | + |
| 1203 | + auto operandType = DECODE_D3D10_SB_OPERAND_TYPE(*operandToken); |
| 1204 | + if (operandType != D3D10_SB_OPERAND_TYPE_CONSTANT_BUFFER) |
| 1205 | + return emitError(loc, "unexpected operand type: ") << operandType; |
| 1206 | + |
| 1207 | + if (DECODE_IS_D3D10_SB_OPERAND_EXTENDED(*operandToken)) |
| 1208 | + return emitError(loc, "extended operand tokens are not supported"); |
| 1209 | + |
| 1210 | + auto indexDim = DECODE_D3D10_SB_OPERAND_INDEX_DIMENSION(*operandToken); |
| 1211 | + if (indexDim != D3D10_SB_OPERAND_INDEX_2D && |
| 1212 | + indexDim != D3D10_SB_OPERAND_INDEX_3D) |
| 1213 | + return emitError(loc, "unsupported index dimension: ") << indexDim; |
| 1214 | + |
| 1215 | + SmallVector<uint32_t, 3> indices; |
| 1216 | + indices.reserve(indexDim); |
| 1217 | + for (uint32_t i = 0; i < indexDim; ++i) { |
| 1218 | + auto indexRepesentation = |
| 1219 | + DECODE_D3D10_SB_OPERAND_INDEX_REPRESENTATION(i, *operandToken); |
| 1220 | + if (indexRepesentation != D3D10_SB_OPERAND_INDEX_IMMEDIATE32) |
| 1221 | + return emitError(loc, "unsupported index representation: ") |
| 1222 | + << indexRepesentation; |
| 1223 | + auto value = parseToken(); |
| 1224 | + FAILURE_IF_FAILED(value); |
| 1225 | + indices.push_back(*value); |
| 1226 | + } |
| 1227 | + |
| 1228 | + switch (indexDim) { |
| 1229 | + case D3D10_SB_OPERAND_INDEX_2D: |
| 1230 | + return builder.buildDclConstantBuffer( |
| 1231 | + /*id=*/indices[0], /*size=*/indices[1], /*lbound=*/std::nullopt, |
| 1232 | + /*ubound=*/std::nullopt, /*space=*/std::nullopt, *accessPattern, loc); |
| 1233 | + case D3D10_SB_OPERAND_INDEX_3D: { |
| 1234 | + auto sizeToken = parseToken(); |
| 1235 | + FAILURE_IF_FAILED(sizeToken); |
| 1236 | + auto spaceToken = parseToken(); |
| 1237 | + FAILURE_IF_FAILED(spaceToken); |
| 1238 | + return builder.buildDclConstantBuffer( |
| 1239 | + /*id=*/indices[0], /*size=*/*sizeToken, /*lbound=*/indices[1], |
| 1240 | + /*ubound=*/indices[2], /*space=*/*spaceToken, *accessPattern, loc); |
| 1241 | + } |
| 1242 | + default: |
| 1243 | + return emitError(loc, "unsupported index dimension: ") << indexDim; |
| 1244 | + } |
| 1245 | + } |
| 1246 | + |
1177 | 1247 | OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc, |
1178 | 1248 | Instruction &out) { |
1179 | 1249 | FailureOr<Instruction> result; |
@@ -1220,6 +1290,9 @@ class Parser { |
1220 | 1290 | case D3D10_SB_OPCODE_DCL_OUTPUT: |
1221 | 1291 | result = parseDclOutput(loc); |
1222 | 1292 | break; |
| 1293 | + case D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER: |
| 1294 | + result = parseDclConstantBuffer(opcodeToken, loc); |
| 1295 | + break; |
1223 | 1296 | default: |
1224 | 1297 | return std::nullopt; |
1225 | 1298 | } |
|
0 commit comments