Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 61 additions & 23 deletions tools/clang/lib/Headers/hlsl/dx/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,75 @@ namespace hlsl {

} // namespace hlsl

namespace dxil {

// This enum must _exactly_ match the DXIL constants.
enum class ComponentType : uint32_t {
Invalid = 0,
I1 = 1,
I16 = 2,
U16 = 3,
I32 = 4,
U32 = 5,
I64 = 6,
U64 = 7,
F16 = 8,
F32 = 9,
F64 = 10,
SNormF16 = 11,
UNormF16 = 12,
SNormF32 = 13,
UNormF32 = 14,
SNormF64 = 15,
UNormF64 = 16,
PackedS8x32 = 17,
PackedU8x32 = 18,

// BEGIN NEW FOR SM 6.10
I8 = 19,
U8 = 20,
F8_E4M3 = 21,
F8_E5M2 = 22,
// END

LastEntry
};

} // namespace dxil

namespace dx {

namespace linalg {

#define __COMPONENT_TYPE(type) type = (uint)dxil::ComponentType::type

// This enum only defines values that are valid for Matrix component types.
// Each enumeration's value matches the cooresponding DXIL constant.
struct ComponentType {
enum ComponentEnum {
Invalid = 0,
I1 = 1,
I16 = 2,
U16 = 3,
I32 = 4,
U32 = 5,
I64 = 6,
U64 = 7,
F16 = 8,
F32 = 9,
F64 = 10,
SNormF16 = 11,
UNormF16 = 12,
SNormF32 = 13,
UNormF32 = 14,
SNormF64 = 15,
UNormF64 = 16,
PackedS8x32 = 17,
PackedU8x32 = 18,
U8 = 19,
I8 = 20,
F8_E4M3 = 21,
F8_E5M2 = 22,
// Signed integers.
__COMPONENT_TYPE(I8),
__COMPONENT_TYPE(I16),
__COMPONENT_TYPE(I32),
__COMPONENT_TYPE(I64),

// Unsigned integers.
__COMPONENT_TYPE(U8),
__COMPONENT_TYPE(U16),
__COMPONENT_TYPE(U32),
__COMPONENT_TYPE(U64),

// Floating point types.
__COMPONENT_TYPE(F8_E4M3),
__COMPONENT_TYPE(F8_E5M2),
__COMPONENT_TYPE(F16),
__COMPONENT_TYPE(F32),
__COMPONENT_TYPE(F64),
};
Comment thread
hekota marked this conversation as resolved.
};

#undef __COMPONENT_TYPE

using ComponentEnum = ComponentType::ComponentEnum;

struct MatrixUse {
Expand Down
10 changes: 5 additions & 5 deletions tools/clang/test/CodeGenDXIL/hlsl/linalg/attr-matrix-type.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace dx::linalg;

// CHECK: %dx.types.LinAlgMatrixC4M4N5U1S2 = type { i8* }
// CHECK: %dx.types.LinAlgMatrixC17M3N3U0S1 = type { i8* }
// CHECK: %dx.types.LinAlgMatrixC21M3N3U0S1 = type { i8* }
// CHECK: %dx.types.LinAlgMatrixC9M10N20U0S0 = type { i8* }
// CHECK: %dx.types.LinAlgMatrixC2M3N4U2S2 = type { i8* }

Expand All @@ -16,9 +16,9 @@ void f1() {
__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup)]] mat1;
}

// CHECK: define internal void @"\01?f2@@YAX$linalg_matrixC17M3N3U0S1@@Z"(%dx.types.LinAlgMatrixC17M3N3U0S1 %mat2.coerce)
// CHECK: %{{.*}} = alloca %dx.types.LinAlgMatrixC17M3N3U0S1, align 4
void f2(__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(ComponentType::PackedS8x32, 3, 3, MatrixUse::A, MatrixScope::Wave)]] mat2) {
// CHECK: define internal void @"\01?f2@@YAX$linalg_matrixC21M3N3U0S1@@Z"(%dx.types.LinAlgMatrixC21M3N3U0S1 %mat2.coerce)
// CHECK: %{{.*}} = alloca %dx.types.LinAlgMatrixC21M3N3U0S1, align 4
void f2(__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(ComponentType::F8_E4M3, 3, 3, MatrixUse::A, MatrixScope::Wave)]] mat2) {
}

// CHECK: define internal %dx.types.LinAlgMatrixC9M10N20U0S0 @"\01?f3@@YA$linalg_matrixC9M10N20U0S0@XZ"()
Expand Down Expand Up @@ -47,7 +47,7 @@ void f4() {

// CHECK: !dx.targetTypes = !{![[T0:.*]], ![[T1:.*]], ![[T2:.*]], ![[T3:.*]]}
// CHECK: ![[T0:.*]] = !{%dx.types.LinAlgMatrixC4M4N5U1S2 undef, i32 4, i32 4, i32 5, i32 1, i32 2}
// CHECK: ![[T1:.*]] = !{%dx.types.LinAlgMatrixC17M3N3U0S1 undef, i32 17, i32 3, i32 3, i32 0, i32 1}
// CHECK: ![[T1:.*]] = !{%dx.types.LinAlgMatrixC21M3N3U0S1 undef, i32 21, i32 3, i32 3, i32 0, i32 1}
// CHECK: ![[T2:.*]] = !{%dx.types.LinAlgMatrixC9M10N20U0S0 undef, i32 9, i32 10, i32 20, i32 0, i32 0}
// CHECK: ![[T3:.*]] = !{%dx.types.LinAlgMatrixC2M3N4U2S2 undef, i32 2, i32 3, i32 4, i32 2, i32 2}

Expand Down
13 changes: 6 additions & 7 deletions tools/clang/test/CodeGenDXIL/hlsl/linalg/linalg-matrix-type.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ using namespace dx::linalg;
// CHECK-SAME: dx::linalg::MatrixScope::MatrixScopeEnum::ThreadGroup>" = type { %dx.types.LinAlgMatrixC4M4N5U1S2 }
// CHECK: %dx.types.LinAlgMatrixC4M4N5U1S2 = type { i8* }


// CHECK: %"class.dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::PackedS8x32, 100, 100, dx::linalg::MatrixUse::MatrixUseEnum::A,
// CHECK-SAME: dx::linalg::MatrixScope::MatrixScopeEnum::Wave>" = type { %dx.types.LinAlgMatrixC17M100N100U0S1 }
// CHECK: %dx.types.LinAlgMatrixC17M100N100U0S1 = type { i8* }
// CHECK: %"class.dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::F32, 100, 100, dx::linalg::MatrixUse::MatrixUseEnum::A,
// CHECK-SAME: dx::linalg::MatrixScope::MatrixScopeEnum::Wave>" = type { %dx.types.LinAlgMatrixC9M100N100U0S1 }
// CHECK: %dx.types.LinAlgMatrixC9M100N100U0S1 = type { i8* }

// CHECK: define internal void @"\01?f@@YAXXZ"()
void f() {
// CHECK: %mat1 = alloca %"class.dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::I32, 4, 5,
// CHECK-SAME: dx::linalg::MatrixUse::MatrixUseEnum::B, dx::linalg::MatrixScope::MatrixScopeEnum::ThreadGroup>", align 4
Matrix<ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup> mat1;
// CHECK: %mat2 = alloca %"class.dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::PackedS8x32, 100, 100,
// CHECK: %mat2 = alloca %"class.dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::F32, 100, 100,
// CHECK-SAME: dx::linalg::MatrixUse::MatrixUseEnum::A, dx::linalg::MatrixScope::MatrixScopeEnum::Wave>", align 4
Matrix<ComponentType::PackedS8x32, 100, 100, MatrixUse::A, MatrixScope::Wave> mat2;
Matrix<ComponentType::F32, 100, 100, MatrixUse::A, MatrixScope::Wave> mat2;
}

// CHECK: !dx.targetTypes = !{![[T0:.*]], ![[T0:.*]]}
// CHECK: ![[T0:.*]] = !{%dx.types.LinAlgMatrixC4M4N5U1S2 undef, i32 4, i32 4, i32 5, i32 1, i32 2}
// CHECK: ![[T1:.*]] = !{%dx.types.LinAlgMatrixC17M100N100U0S1 undef, i32 17, i32 100, i32 100, i32 0, i32 1}
// CHECK: ![[T1:.*]] = !{%dx.types.LinAlgMatrixC9M100N100U0S1 undef, i32 9, i32 100, i32 100, i32 0, i32 1}

// CHECKVAL-NOT: error: validation errors
// CHECKVAL-NOT: error: Named metadata 'dx.targetTypes' is unknown.
10 changes: 5 additions & 5 deletions tools/clang/test/SemaHLSL/hlsl/linalg/linalg-matrix-ast.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace dx::linalg;

void f() {
Matrix<ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup> mat1;
Matrix<ComponentType::PackedS8x32, 100, 100, MatrixUse::A, MatrixScope::Wave> mat2;
Matrix<ComponentType::F32, 100, 100, MatrixUse::A, MatrixScope::Wave> mat2;
}

// CHECK: ClassTemplateDecl {{.*}} Matrix{{$}}
Expand Down Expand Up @@ -42,16 +42,16 @@ void f() {
// CHECK-NEXT: TemplateArgument integral 1
// CHECK-NEXT: CXXRecordDecl {{.*}} implicit class Matrix
// CHECK-NEXT: TypeAliasDecl {{.*}} HandleT '__builtin_LinAlgMatrix
// CHECK-SAME{LITERAL}: [[__LinAlgMatrix_Attributes(ComponentType::PackedS8x32,100, 100, MatrixUse::A, MatrixScope::Wave)]]'
// CHECK-SAME{LITERAL}: [[__LinAlgMatrix_Attributes(ComponentType::F32,100, 100, MatrixUse::A, MatrixScope::Wave)]]'
// CHECK-NEXT: FieldDecl {{.*}} __handle 'HandleT':'__builtin_LinAlgMatrix
// CHECK-SAME{LITERAL}: [[__LinAlgMatrix_Attributes(ComponentType::PackedS8x32, 100, 100, MatrixUse::A, MatrixScope::Wave)]]'
// CHECK-SAME{LITERAL}: [[__LinAlgMatrix_Attributes(ComponentType::F32, 100, 100, MatrixUse::A, MatrixScope::Wave)]]'

// CHECK: FunctionDecl {{.*}} f 'void ()'

// CHECK: VarDecl {{.*}} mat1 'Matrix<ComponentType::I32, 4, 5, MatrixUse::B, MatrixScope::ThreadGroup>':
// CHECK-SAME: 'dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::I32, 4, 5, dx::linalg::MatrixUse::MatrixUseEnum::B,
// CHECK-SAME: dx::linalg::MatrixScope::MatrixScopeEnum::ThreadGroup>'

// CHECK: VarDecl {{.*}} mat2 'Matrix<ComponentType::PackedS8x32, 100, 100, MatrixUse::A, MatrixScope::Wave>':
// CHECK-SAME: 'dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::PackedS8x32, 100, 100,
// CHECK: VarDecl {{.*}} mat2 'Matrix<ComponentType::F32, 100, 100, MatrixUse::A, MatrixScope::Wave>':
// CHECK-SAME: 'dx::linalg::Matrix<dx::linalg::ComponentType::ComponentEnum::F32, 100, 100,
// CHECK-SAME: dx::linalg::MatrixUse::MatrixUseEnum::A, dx::linalg::MatrixScope::MatrixScopeEnum::Wave>'
Loading