@@ -635,6 +635,18 @@ class DXBuilder {
635635 return dxsa::DclOutput::create (builder, loc, operand);
636636 }
637637
638+ Instruction buildDclConstantBuffer (
639+ uint32_t id, uint32_t size, std::optional<uint32_t > lbound,
640+ std::optional<uint32_t > ubound, std::optional<uint32_t > space,
641+ dxsa::ConstantBufferAccessPattern accessPattern, Location loc) {
642+ auto optionalToAttr = [&](std::optional<uint32_t > v) -> IntegerAttr {
643+ return v ? builder.getI32IntegerAttr (*v) : IntegerAttr ();
644+ };
645+ return dxsa::DclConstantBuffer::create (
646+ builder, loc, id, size, optionalToAttr (lbound), optionalToAttr (ubound),
647+ optionalToAttr (space), accessPattern);
648+ }
649+
638650private:
639651 MLIRContext *context;
640652 ModuleOp module ;
@@ -1174,6 +1186,63 @@ class Parser {
11741186 return builder.buildDclOutput (*operand, loc);
11751187 }
11761188
1189+ FailureOr<Instruction> parseDclConstantBuffer (uint32_t opcodeToken,
1190+ Location loc) {
1191+ auto rawAccessPattern =
1192+ DECODE_D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN (opcodeToken);
1193+ auto accessPattern =
1194+ dxsa::symbolizeConstantBufferAccessPattern (rawAccessPattern);
1195+ if (!accessPattern)
1196+ return emitError (loc, " unknown constant buffer access pattern: " )
1197+ << rawAccessPattern;
1198+
1199+ auto operandToken = parseToken ();
1200+ FAILURE_IF_FAILED (operandToken);
1201+
1202+ auto operandType = DECODE_D3D10_SB_OPERAND_TYPE (*operandToken);
1203+ if (operandType != D3D10_SB_OPERAND_TYPE_CONSTANT_BUFFER)
1204+ return emitError (loc, " unexpected operand type: " ) << operandType;
1205+
1206+ if (DECODE_IS_D3D10_SB_OPERAND_EXTENDED (*operandToken))
1207+ return emitError (loc, " extended operand tokens are not supported" );
1208+
1209+ auto indexDim = DECODE_D3D10_SB_OPERAND_INDEX_DIMENSION (*operandToken);
1210+ if (indexDim != D3D10_SB_OPERAND_INDEX_2D &&
1211+ indexDim != D3D10_SB_OPERAND_INDEX_3D)
1212+ return emitError (loc, " unsupported index dimension: " ) << indexDim;
1213+
1214+ SmallVector<uint32_t , 3 > indices;
1215+ indices.reserve (indexDim);
1216+ for (uint32_t i = 0 ; i < indexDim; ++i) {
1217+ auto indexRepesentation =
1218+ DECODE_D3D10_SB_OPERAND_INDEX_REPRESENTATION (i, *operandToken);
1219+ if (indexRepesentation != D3D10_SB_OPERAND_INDEX_IMMEDIATE32)
1220+ return emitError (loc, " unsupported index representation: " )
1221+ << indexRepesentation;
1222+ auto value = parseToken ();
1223+ FAILURE_IF_FAILED (value);
1224+ indices.push_back (*value);
1225+ }
1226+
1227+ switch (indexDim) {
1228+ case D3D10_SB_OPERAND_INDEX_2D:
1229+ return builder.buildDclConstantBuffer (
1230+ /* id=*/ indices[0 ], /* size=*/ indices[1 ], /* lbound=*/ std::nullopt ,
1231+ /* ubound=*/ std::nullopt , /* space=*/ std::nullopt , *accessPattern, loc);
1232+ case D3D10_SB_OPERAND_INDEX_3D: {
1233+ auto sizeToken = parseToken ();
1234+ FAILURE_IF_FAILED (sizeToken);
1235+ auto spaceToken = parseToken ();
1236+ FAILURE_IF_FAILED (spaceToken);
1237+ return builder.buildDclConstantBuffer (
1238+ /* id=*/ indices[0 ], /* size=*/ *sizeToken, /* lbound=*/ indices[1 ],
1239+ /* ubound=*/ indices[2 ], /* space=*/ *spaceToken, *accessPattern, loc);
1240+ }
1241+ default :
1242+ llvm_unreachable (" indexDim was validated above" );
1243+ }
1244+ }
1245+
11771246 OptionalParseResult parseDclInstruction (uint32_t opcodeToken, Location loc,
11781247 Instruction &out) {
11791248 FailureOr<Instruction> result;
@@ -1220,6 +1289,9 @@ class Parser {
12201289 case D3D10_SB_OPCODE_DCL_OUTPUT:
12211290 result = parseDclOutput (loc);
12221291 break ;
1292+ case D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER:
1293+ result = parseDclConstantBuffer (opcodeToken, loc);
1294+ break ;
12231295 default :
12241296 return std::nullopt ;
12251297 }
0 commit comments