Skip to content

Commit 17b810e

Browse files
Use ComponentType and MatrixLayout from DxilConstants.h
1 parent 4295c84 commit 17b810e

1 file changed

Lines changed: 32 additions & 56 deletions

File tree

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "clang/Sema/SemaHLSL.h"
1717
#include "VkConstantsTables.h"
18+
#include "dxc/DXIL/DxilConstants.h"
1819
#include "dxc/DXIL/DxilFunctionProps.h"
1920
#include "dxc/DXIL/DxilShaderModel.h"
2021
#include "dxc/DXIL/DxilUtil.h"
@@ -11681,74 +11682,50 @@ static const unsigned kMatVecMulMatrixStrideIdx = 12;
1168111682
// MatVecAdd
1168211683
const unsigned kMatVecMulAddBiasInterpretation = 15;
1168311684

11684-
enum MatrixLayout {
11685-
MATRIX_LAYOUT_ROW_MAJOR = 0,
11686-
MATRIX_LAYOUT_COLUMN_MAJOR = 1,
11687-
MATRIX_LAYOUT_MUL_OPTIMAL = 2,
11688-
MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL = 3
11689-
};
11690-
11691-
bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) {
11692-
return Layout <= static_cast<unsigned>(
11693-
MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL);
11685+
static bool IsValidMatrixLayoutForMulandMulAddOps(unsigned Layout) {
11686+
return Layout <=
11687+
static_cast<unsigned>(DXIL::LinalgMatrixLayout::OuterProductOptimal);
1169411688
}
1169511689

11696-
bool IsOptimalTypeMatrixLayout(unsigned Layout) {
11697-
return (Layout == (static_cast<unsigned>(
11698-
MatrixLayout::MATRIX_LAYOUT_MUL_OPTIMAL)) ||
11699-
(Layout == (static_cast<unsigned>(
11700-
MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL))));
11690+
static bool IsOptimalTypeMatrixLayout(unsigned Layout) {
11691+
return (
11692+
Layout == (static_cast<unsigned>(DXIL::LinalgMatrixLayout::MulOptimal)) ||
11693+
(Layout ==
11694+
(static_cast<unsigned>(DXIL::LinalgMatrixLayout::OuterProductOptimal))));
1170111695
}
1170211696

11703-
bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) {
11704-
switch (static_cast<MatrixLayout>(Layout)) {
11705-
case MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR:
11706-
case MatrixLayout::MATRIX_LAYOUT_COLUMN_MAJOR:
11697+
static bool IsValidTransposeForMatrixLayout(unsigned Layout, bool Transposed) {
11698+
switch (static_cast<DXIL::LinalgMatrixLayout>(Layout)) {
11699+
case DXIL::LinalgMatrixLayout::RowMajor:
11700+
case DXIL::LinalgMatrixLayout::ColumnMajor:
1170711701
return !Transposed;
1170811702

1170911703
default:
1171011704
return true;
1171111705
}
1171211706
}
1171311707

11714-
enum DataType {
11715-
DATA_TYPE_SINT16 = 2, // ComponentType::I16
11716-
DATA_TYPE_UINT16 = 3, // ComponentType::U16
11717-
DATA_TYPE_SINT32 = 4, // ComponentType::I32
11718-
DATA_TYPE_UINT32 = 5, // ComponentType::U32
11719-
DATA_TYPE_FLOAT16 = 8, // ComponentType::F16
11720-
DATA_TYPE_FLOAT32 = 9, // ComponentType::F32
11721-
DATA_TYPE_SINT8_T4_PACKED = 17, // ComponentType::PackedS8x32
11722-
DATA_TYPE_UINT8_T4_PACKED = 18, // ComponentType::PackedU8x32
11723-
DATA_TYPE_UINT8 = 19, // ComponentType::U8
11724-
DATA_TYPE_SINT8 = 20, // ComponentType::I8
11725-
DATA_TYPE_FLOAT8_E4M3 = 21, // ComponentType::F8_E4M3
11726-
// (1 sign, 4 exp, 3 mantissa bits)
11727-
DATA_TYPE_FLOAT8_E5M2 = 22, // ComponentType::F8_E5M2
11728-
// (1 sign, 5 exp, 2 mantissa bits)
11729-
};
11730-
11731-
bool IsPackedType(unsigned type) {
11732-
return (type == static_cast<unsigned>(DATA_TYPE_SINT8_T4_PACKED) ||
11733-
type == static_cast<unsigned>(DATA_TYPE_UINT8_T4_PACKED));
11708+
static bool IsPackedType(unsigned type) {
11709+
return (type == static_cast<unsigned>(DXIL::ComponentType::PackedS8x32) ||
11710+
type == static_cast<unsigned>(DXIL::ComponentType::PackedU8x32));
1173411711
}
1173511712

1173611713
static bool IsValidLinalgTypeInterpretation(uint32_t Input, bool InRegister) {
1173711714

1173811715
switch (Input) {
11739-
case DATA_TYPE_SINT16:
11740-
case DATA_TYPE_UINT16:
11741-
case DATA_TYPE_SINT32:
11742-
case DATA_TYPE_UINT32:
11743-
case DATA_TYPE_FLOAT16:
11744-
case DATA_TYPE_FLOAT32:
11745-
case DATA_TYPE_UINT8:
11746-
case DATA_TYPE_SINT8:
11747-
case DATA_TYPE_FLOAT8_E4M3:
11748-
case DATA_TYPE_FLOAT8_E5M2:
11716+
case DXIL::ComponentType::I16:
11717+
case DXIL::ComponentType::U16:
11718+
case DXIL::ComponentType::I32:
11719+
case DXIL::ComponentType::U32:
11720+
case DXIL::ComponentType::F16:
11721+
case DXIL::ComponentType::F32:
11722+
case DXIL::ComponentType::U8:
11723+
case DXIL::ComponentType::I8:
11724+
case DXIL::ComponentType::F8_E4M3:
11725+
case DXIL::ComponentType::F8_E5M2:
1174911726
return true;
11750-
case DATA_TYPE_SINT8_T4_PACKED:
11751-
case DATA_TYPE_UINT8_T4_PACKED:
11727+
case DXIL::ComponentType::PackedS8x32:
11728+
case DXIL::ComponentType::PackedU8x32:
1175211729
return InRegister;
1175311730
default:
1175411731
return false;
@@ -12038,9 +12015,9 @@ static void CheckCommonMulandMulAddParameters(Sema &S, CallExpr *CE,
1203812015
diag::err_hlsl_linalg_matrix_layout_invalid)
1203912016
<< std::to_string(MatrixLayoutValue)
1204012017
<< std::to_string(
12041-
static_cast<unsigned>(MatrixLayout::MATRIX_LAYOUT_ROW_MAJOR))
12018+
static_cast<unsigned>(DXIL::LinalgMatrixLayout::RowMajor))
1204212019
<< std::to_string(static_cast<unsigned>(
12043-
MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL));
12020+
DXIL::LinalgMatrixLayout::OuterProductOptimal));
1204412021
return;
1204512022
}
1204612023
} else {
@@ -12184,14 +12161,13 @@ static void CheckOuterProductAccumulateCall(Sema &S, FunctionDecl *FD,
1218412161
if (MatrixLayoutExpr->isIntegerConstantExpr(MatrixLayoutExprVal, S.Context)) {
1218512162
MatrixLayoutValue = MatrixLayoutExprVal.getLimitedValue();
1218612163
if (MatrixLayoutValue !=
12187-
static_cast<unsigned>(
12188-
MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL)) {
12164+
static_cast<unsigned>(DXIL::LinalgMatrixLayout::OuterProductOptimal)) {
1218912165
S.Diags.Report(
1219012166
MatrixLayoutExpr->getExprLoc(),
1219112167
diag::
1219212168
err_hlsl_linalg_outer_prod_acc_matrix_layout_must_be_outer_prod_acc_optimal)
1219312169
<< std::to_string(static_cast<unsigned>(
12194-
MatrixLayout::MATRIX_LAYOUT_OUTER_PRODUCT_OPTIMAL));
12170+
DXIL::LinalgMatrixLayout::OuterProductOptimal));
1219512171
return;
1219612172
}
1219712173
} else {

0 commit comments

Comments
 (0)