Fix issues of the interaction between cooperative_matrix and spirv_intrinsics

coopmat<> type definition allows type parameters. To make it accept
types defined by spirv_type directive, we add spirvType info to the type
parameters. This change is to support this case. And a test is added to
show the missing usage.
This commit is contained in:
Rex Xu 2024-03-21 23:09:00 +08:00 committed by GitHub
parent 10ee92feb0
commit 022aea431c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1136 additions and 1022 deletions

View File

@ -0,0 +1,71 @@
spv.intrinsicsInteractWithCoopMat.comp
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 36
Capability Shader
Capability Float16
Capability VulkanMemoryModelKHR
Capability CooperativeMatrixKHR
Extension "SPV_KHR_cooperative_matrix"
Extension "SPV_KHR_storage_buffer_storage_class"
Extension "SPV_KHR_vulkan_memory_model"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical VulkanKHR
EntryPoint GLCompute 4 "main"
ExecutionMode 4 LocalSize 32 1 1
Source GLSL 450
SourceExtension "GL_EXT_spirv_intrinsics"
SourceExtension "GL_KHR_cooperative_matrix"
SourceExtension "GL_KHR_memory_scope_semantics"
Name 4 "main"
Name 13 "tempArg"
Name 16 "Buf"
MemberName 16(Buf) 0 "x"
Name 18 "buf"
Name 26 "A"
Decorate 15 ArrayStride 16
MemberDecorate 16(Buf) 0 Offset 0
Decorate 16(Buf) Block
Decorate 18(buf) DescriptorSet 0
Decorate 18(buf) Binding 0
Decorate 35 BuiltIn WorkgroupSize
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 16
7: TypeInt 32 0
8: 7(int) Constant 3
9: 7(int) Constant 16
10: 7(int) Constant 0
11: TypeCooperativeMatrixKHR 6(float16_t) 8 9 9 10
12: TypePointer Function 11
14: TypeVector 7(int) 4
15: TypeRuntimeArray 14(ivec4)
16(Buf): TypeStruct 15
17: TypePointer StorageBuffer 16(Buf)
18(buf): 17(ptr) Variable StorageBuffer
19: TypeInt 32 1
20: 19(int) Constant 0
21: TypePointer StorageBuffer 14(ivec4)
23: 7(int) Constant 2
25: TypePointer Private 11
26(A): 25(ptr) Variable Private
29: 7(int) Constant 64
31: 7(int) Constant 4
32: TypeVector 7(int) 3
33: 7(int) Constant 32
34: 7(int) Constant 1
35: 32(ivec3) ConstantComposite 33 34 34
4(main): 2 Function None 3
5: Label
13(tempArg): 12(ptr) Variable Function
22: 21(ptr) AccessChain 18(buf) 20 10
24: 11 CooperativeMatrixLoadKHR 22 20 23 None
Store 13(tempArg) 24
27: 11 Load 13(tempArg)
Store 26(A) 27
28: 11 Load 26(A)
30: 21(ptr) AccessChain 18(buf) 20 29
CooperativeMatrixStoreKHR 30 28 20 31 None
Return
FunctionEnd

View File

@ -0,0 +1,20 @@
#version 450 core
#pragma use_vulkan_memory_model
#extension GL_KHR_memory_scope_semantics : enable
#extension GL_KHR_cooperative_matrix : enable
#extension GL_EXT_spirv_intrinsics : enable
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
layout(set=0, binding=0, std430) buffer Buf { uvec4 x[]; } buf;
#define ELT_SIZE 16
#define half spirv_type(capabilities=[9], id = 22, 16)
coopmat<half, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> A;
void main() {
coopMatLoad(A, buf.x, 0, ELT_SIZE / 8, 0);
coopMatStore(A, buf.x, 64, 4, 0);
}

View File

@ -1435,13 +1435,25 @@ class TTypeParameters {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TTypeParameters() : basicType(EbtVoid), arraySizes(nullptr) {}
TTypeParameters() : basicType(EbtVoid), arraySizes(nullptr), spirvType(nullptr) {}
TBasicType basicType;
TArraySizes *arraySizes;
TSpirvType *spirvType;
bool operator==(const TTypeParameters& rhs) const { return basicType == rhs.basicType && *arraySizes == *rhs.arraySizes; }
bool operator!=(const TTypeParameters& rhs) const { return basicType != rhs.basicType || *arraySizes != *rhs.arraySizes; }
bool operator==(const TTypeParameters& rhs) const
{
bool same = basicType == rhs.basicType && *arraySizes == *rhs.arraySizes;
if (same && basicType == EbtSpirvType) {
assert(spirvType && rhs.spirvType);
return *spirvType == *rhs.spirvType;
}
return same;
}
bool operator!=(const TTypeParameters& rhs) const
{
return !(*this == rhs);
}
};
//
@ -1618,6 +1630,10 @@ public:
}
if (p.isCoopmatKHR() && p.typeParameters && p.typeParameters->arraySizes->getNumDims() > 0) {
basicType = p.typeParameters->basicType;
if (isSpirvType()) {
assert(p.typeParameters->spirvType);
spirvType = p.typeParameters->spirvType;
}
if (p.typeParameters->arraySizes->getNumDims() == 4) {
const int dimSize = p.typeParameters->arraySizes->getDimSize(3);
@ -2719,7 +2735,8 @@ public:
if (isCoopMatKHR() && right.isCoopMatKHR()) {
return ((getBasicType() == right.getBasicType()) || (getBasicType() == EbtCoopmat) ||
(right.getBasicType() == EbtCoopmat)) &&
typeParameters == nullptr && right.typeParameters != nullptr;
((typeParameters == nullptr && right.typeParameters != nullptr) ||
(typeParameters != nullptr && right.typeParameters == nullptr));
}
return false;
}
@ -2825,6 +2842,7 @@ protected:
typeParameters = new TTypeParameters;
typeParameters->arraySizes = new TArraySizes;
*typeParameters->arraySizes = *copyOf.typeParameters->arraySizes;
*typeParameters->spirvType = *copyOf.typeParameters->spirvType;
typeParameters->basicType = copyOf.basicType;
}

View File

@ -7413,6 +7413,7 @@ void TParseContext::coopMatTypeParametersCheck(const TSourceLoc& loc, const TPub
case EbtUint:
case EbtUint8:
case EbtUint16:
case EbtSpirvType:
break;
default:
error(loc, "coopmat invalid basic type", TType::getBasicString(publicType.typeParameters->basicType), "");
@ -7795,7 +7796,8 @@ TIntermNode* TParseContext::declareVariable(const TSourceLoc& loc, TString& iden
error(loc, "unexpected number type parameters", identifier.c_str(), "");
}
if (publicType.typeParameters) {
if (!isTypeFloat(publicType.typeParameters->basicType) && !isTypeInt(publicType.typeParameters->basicType)) {
if (!isTypeFloat(publicType.typeParameters->basicType) &&
!isTypeInt(publicType.typeParameters->basicType) && publicType.typeParameters->basicType != EbtSpirvType) {
error(loc, "expected 8, 16, 32, or 64 bit signed or unsigned integer or 16, 32, or 64 bit float type", identifier.c_str(), "");
}
}

View File

@ -1756,6 +1756,7 @@ type_parameter_specifier_list
: type_specifier {
$$ = new TTypeParameters;
$$->arraySizes = new TArraySizes;
$$->spirvType = $1.spirvType;
$$->basicType = $1.basicType;
}
| unary_expression {

File diff suppressed because it is too large Load Diff

View File

@ -423,6 +423,7 @@ INSTANTIATE_TEST_SUITE_P(
"spv.intrinsicsSpirvDecorateId.comp",
"spv.intrinsicsSpirvDecorateString.comp",
"spv.intrinsicsSpirvExecutionMode.frag",
"spv.intrinsicsInteractWithCoopMat.comp",
"spv.intrinsicsSpirvInstruction.vert",
"spv.intrinsicsSpirvLiteral.vert",
"spv.intrinsicsSpirvStorageClass.rchit",