[ir] Move array_length intrinsic to a builtin
This CL moves the spirv intrinsic for `array_length` over to a bultin.
Bug: tint:1718
Change-Id: I444966ffae699db5e7fd577aa40f64de2fe67e32
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/150103
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/intrinsic/data/data.cc b/src/tint/lang/core/intrinsic/data/data.cc
index 9e6bd5a..d423120 100644
--- a/src/tint/lang/core/intrinsic/data/data.cc
+++ b/src/tint/lang/core/intrinsic/data/data.cc
@@ -69,7 +69,7 @@
if (!MatchBool(state, ty)) {
return nullptr;
}
- return BuildBool(state);
+ return BuildBool(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "bool";
@@ -83,7 +83,7 @@
if (!MatchIa(state, ty)) {
return nullptr;
}
- return BuildIa(state);
+ return BuildIa(state, ty);
},
/* string */ [](MatchState*) -> std::string {
StringStream ss;
@@ -99,7 +99,7 @@
if (!MatchFa(state, ty)) {
return nullptr;
}
- return BuildFa(state);
+ return BuildFa(state, ty);
},
/* string */ [](MatchState*) -> std::string {
StringStream ss;
@@ -115,7 +115,7 @@
if (!MatchI32(state, ty)) {
return nullptr;
}
- return BuildI32(state);
+ return BuildI32(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "i32";
@@ -129,7 +129,7 @@
if (!MatchU32(state, ty)) {
return nullptr;
}
- return BuildU32(state);
+ return BuildU32(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "u32";
@@ -143,7 +143,7 @@
if (!MatchF32(state, ty)) {
return nullptr;
}
- return BuildF32(state);
+ return BuildF32(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "f32";
@@ -157,7 +157,7 @@
if (!MatchF16(state, ty)) {
return nullptr;
}
- return BuildF16(state);
+ return BuildF16(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "f16";
@@ -176,7 +176,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec2(state, T);
+ return BuildVec2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -196,7 +196,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec3(state, T);
+ return BuildVec3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -216,7 +216,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec4(state, T);
+ return BuildVec4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -236,7 +236,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X2(state, T);
+ return BuildMat2X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -256,7 +256,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X3(state, T);
+ return BuildMat2X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -276,7 +276,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X4(state, T);
+ return BuildMat2X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -296,7 +296,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X2(state, T);
+ return BuildMat3X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -316,7 +316,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X3(state, T);
+ return BuildMat3X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -336,7 +336,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X4(state, T);
+ return BuildMat3X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -356,7 +356,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X2(state, T);
+ return BuildMat4X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -376,7 +376,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X3(state, T);
+ return BuildMat4X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -396,7 +396,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X4(state, T);
+ return BuildMat4X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -421,7 +421,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec(state, N, T);
+ return BuildVec(state, ty, N, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -454,7 +454,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat(state, N, M, T);
+ return BuildMat(state, ty, N, M, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -488,7 +488,7 @@
if (!A.IsValid()) {
return nullptr;
}
- return BuildPtr(state, S, T, A);
+ return BuildPtr(state, ty, S, T, A);
},
/* string */ [](MatchState* state) -> std::string {
const std::string S = state->NumName();
@@ -510,7 +510,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildAtomic(state, T);
+ return BuildAtomic(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -530,7 +530,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildArray(state, T);
+ return BuildArray(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -545,7 +545,7 @@
if (!MatchSampler(state, ty)) {
return nullptr;
}
- return BuildSampler(state);
+ return BuildSampler(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "sampler";
@@ -559,7 +559,7 @@
if (!MatchSamplerComparison(state, ty)) {
return nullptr;
}
- return BuildSamplerComparison(state);
+ return BuildSamplerComparison(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "sampler_comparison";
@@ -578,7 +578,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTexture1D(state, T);
+ return BuildTexture1D(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -598,7 +598,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTexture2D(state, T);
+ return BuildTexture2D(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -618,7 +618,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTexture2DArray(state, T);
+ return BuildTexture2DArray(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -638,7 +638,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTexture3D(state, T);
+ return BuildTexture3D(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -658,7 +658,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTextureCube(state, T);
+ return BuildTextureCube(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -678,7 +678,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTextureCubeArray(state, T);
+ return BuildTextureCubeArray(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -698,7 +698,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildTextureMultisampled2D(state, T);
+ return BuildTextureMultisampled2D(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -713,7 +713,7 @@
if (!MatchTextureDepth2D(state, ty)) {
return nullptr;
}
- return BuildTextureDepth2D(state);
+ return BuildTextureDepth2D(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_depth_2d";
@@ -727,7 +727,7 @@
if (!MatchTextureDepth2DArray(state, ty)) {
return nullptr;
}
- return BuildTextureDepth2DArray(state);
+ return BuildTextureDepth2DArray(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_depth_2d_array";
@@ -741,7 +741,7 @@
if (!MatchTextureDepthCube(state, ty)) {
return nullptr;
}
- return BuildTextureDepthCube(state);
+ return BuildTextureDepthCube(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_depth_cube";
@@ -755,7 +755,7 @@
if (!MatchTextureDepthCubeArray(state, ty)) {
return nullptr;
}
- return BuildTextureDepthCubeArray(state);
+ return BuildTextureDepthCubeArray(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_depth_cube_array";
@@ -769,7 +769,7 @@
if (!MatchTextureDepthMultisampled2D(state, ty)) {
return nullptr;
}
- return BuildTextureDepthMultisampled2D(state);
+ return BuildTextureDepthMultisampled2D(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_depth_multisampled_2d";
@@ -793,7 +793,7 @@
if (!A.IsValid()) {
return nullptr;
}
- return BuildTextureStorage1D(state, F, A);
+ return BuildTextureStorage1D(state, ty, F, A);
},
/* string */ [](MatchState* state) -> std::string {
const std::string F = state->NumName();
@@ -819,7 +819,7 @@
if (!A.IsValid()) {
return nullptr;
}
- return BuildTextureStorage2D(state, F, A);
+ return BuildTextureStorage2D(state, ty, F, A);
},
/* string */ [](MatchState* state) -> std::string {
const std::string F = state->NumName();
@@ -845,7 +845,7 @@
if (!A.IsValid()) {
return nullptr;
}
- return BuildTextureStorage2DArray(state, F, A);
+ return BuildTextureStorage2DArray(state, ty, F, A);
},
/* string */ [](MatchState* state) -> std::string {
const std::string F = state->NumName();
@@ -871,7 +871,7 @@
if (!A.IsValid()) {
return nullptr;
}
- return BuildTextureStorage3D(state, F, A);
+ return BuildTextureStorage3D(state, ty, F, A);
},
/* string */ [](MatchState* state) -> std::string {
const std::string F = state->NumName();
@@ -887,7 +887,7 @@
if (!MatchTextureExternal(state, ty)) {
return nullptr;
}
- return BuildTextureExternal(state);
+ return BuildTextureExternal(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "texture_external";
@@ -906,7 +906,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildPackedVec3(state, T);
+ return BuildPackedVec3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -926,7 +926,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildModfResult(state, T);
+ return BuildModfResult(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -953,7 +953,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildModfResultVec(state, N, T);
+ return BuildModfResultVec(state, ty, N, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -976,7 +976,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildFrexpResult(state, T);
+ return BuildFrexpResult(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -1003,7 +1003,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildFrexpResultVec(state, N, T);
+ return BuildFrexpResultVec(state, ty, N, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -1026,7 +1026,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildAtomicCompareExchangeResult(state, T);
+ return BuildAtomicCompareExchangeResult(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -1039,25 +1039,25 @@
constexpr TypeMatcher kScalarMatcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1074,19 +1074,19 @@
constexpr TypeMatcher kConcreteScalarMatcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1103,22 +1103,22 @@
constexpr TypeMatcher kScalarNoF32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1135,22 +1135,22 @@
constexpr TypeMatcher kScalarNoF16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1167,22 +1167,22 @@
constexpr TypeMatcher kScalarNoI32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1199,22 +1199,22 @@
constexpr TypeMatcher kScalarNoU32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
if (MatchBool(state, ty)) {
- return BuildBool(state);
+ return BuildBool(state, ty);
}
return nullptr;
},
@@ -1231,22 +1231,22 @@
constexpr TypeMatcher kScalarNoBoolMatcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1263,22 +1263,22 @@
constexpr TypeMatcher kFiaFiu32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1295,19 +1295,19 @@
constexpr TypeMatcher kFiaFi32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1324,19 +1324,19 @@
constexpr TypeMatcher kFiaFiu32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
return nullptr;
},
@@ -1353,10 +1353,10 @@
constexpr TypeMatcher kFaF32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
return nullptr;
},
@@ -1373,13 +1373,13 @@
constexpr TypeMatcher kFaF32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchFa(state, ty)) {
- return BuildFa(state);
+ return BuildFa(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1396,13 +1396,13 @@
constexpr TypeMatcher kIaIu32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
return nullptr;
},
@@ -1419,10 +1419,10 @@
constexpr TypeMatcher kIaI32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchIa(state, ty)) {
- return BuildIa(state);
+ return BuildIa(state, ty);
}
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
return nullptr;
},
@@ -1439,16 +1439,16 @@
constexpr TypeMatcher kFiu32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1465,13 +1465,13 @@
constexpr TypeMatcher kFiu32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
return nullptr;
},
@@ -1488,13 +1488,13 @@
constexpr TypeMatcher kFi32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1511,10 +1511,10 @@
constexpr TypeMatcher kFi32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
return nullptr;
},
@@ -1531,10 +1531,10 @@
constexpr TypeMatcher kF32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -1551,10 +1551,10 @@
constexpr TypeMatcher kIu32Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchI32(state, ty)) {
- return BuildI32(state);
+ return BuildI32(state, ty);
}
if (MatchU32(state, ty)) {
- return BuildU32(state);
+ return BuildU32(state, ty);
}
return nullptr;
},
@@ -1570,14 +1570,14 @@
/// EnumMatcher for 'match f32_texel_format'
constexpr NumberMatcher kF32TexelFormatMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<TexelFormat>(number.Value())) {
- case TexelFormat::kBgra8Unorm:
- case TexelFormat::kRgba8Unorm:
- case TexelFormat::kRgba8Snorm:
- case TexelFormat::kRgba16Float:
- case TexelFormat::kR32Float:
- case TexelFormat::kRg32Float:
- case TexelFormat::kRgba32Float:
+ switch (static_cast<core::TexelFormat>(number.Value())) {
+ case core::TexelFormat::kBgra8Unorm:
+ case core::TexelFormat::kRgba8Unorm:
+ case core::TexelFormat::kRgba8Snorm:
+ case core::TexelFormat::kRgba16Float:
+ case core::TexelFormat::kR32Float:
+ case core::TexelFormat::kRg32Float:
+ case core::TexelFormat::kRgba32Float:
return number;
default:
return Number::invalid;
@@ -1591,12 +1591,12 @@
/// EnumMatcher for 'match i32_texel_format'
constexpr NumberMatcher kI32TexelFormatMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<TexelFormat>(number.Value())) {
- case TexelFormat::kRgba8Sint:
- case TexelFormat::kRgba16Sint:
- case TexelFormat::kR32Sint:
- case TexelFormat::kRg32Sint:
- case TexelFormat::kRgba32Sint:
+ switch (static_cast<core::TexelFormat>(number.Value())) {
+ case core::TexelFormat::kRgba8Sint:
+ case core::TexelFormat::kRgba16Sint:
+ case core::TexelFormat::kR32Sint:
+ case core::TexelFormat::kRg32Sint:
+ case core::TexelFormat::kRgba32Sint:
return number;
default:
return Number::invalid;
@@ -1610,12 +1610,12 @@
/// EnumMatcher for 'match u32_texel_format'
constexpr NumberMatcher kU32TexelFormatMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<TexelFormat>(number.Value())) {
- case TexelFormat::kRgba8Uint:
- case TexelFormat::kRgba16Uint:
- case TexelFormat::kR32Uint:
- case TexelFormat::kRg32Uint:
- case TexelFormat::kRgba32Uint:
+ switch (static_cast<core::TexelFormat>(number.Value())) {
+ case core::TexelFormat::kRgba8Uint:
+ case core::TexelFormat::kRgba16Uint:
+ case core::TexelFormat::kR32Uint:
+ case core::TexelFormat::kRg32Uint:
+ case core::TexelFormat::kRgba32Uint:
return number;
default:
return Number::invalid;
@@ -1629,8 +1629,8 @@
/// EnumMatcher for 'match write'
constexpr NumberMatcher kWriteMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- if (number.IsAny() || number.Value() == static_cast<uint32_t>(Access::kWrite)) {
- return Number(static_cast<uint32_t>(Access::kWrite));
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::Access::kWrite)) {
+ return Number(static_cast<uint32_t>(core::Access::kWrite));
}
return Number::invalid;
},
@@ -1642,8 +1642,8 @@
/// EnumMatcher for 'match read_write'
constexpr NumberMatcher kReadWriteMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- if (number.IsAny() || number.Value() == static_cast<uint32_t>(Access::kReadWrite)) {
- return Number(static_cast<uint32_t>(Access::kReadWrite));
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::Access::kReadWrite)) {
+ return Number(static_cast<uint32_t>(core::Access::kReadWrite));
}
return Number::invalid;
},
@@ -1655,9 +1655,9 @@
/// EnumMatcher for 'match readable'
constexpr NumberMatcher kReadableMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<Access>(number.Value())) {
- case Access::kRead:
- case Access::kReadWrite:
+ switch (static_cast<core::Access>(number.Value())) {
+ case core::Access::kRead:
+ case core::Access::kReadWrite:
return number;
default:
return Number::invalid;
@@ -1671,9 +1671,9 @@
/// EnumMatcher for 'match writable'
constexpr NumberMatcher kWritableMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<Access>(number.Value())) {
- case Access::kWrite:
- case Access::kReadWrite:
+ switch (static_cast<core::Access>(number.Value())) {
+ case core::Access::kWrite:
+ case core::Access::kReadWrite:
return number;
default:
return Number::invalid;
@@ -1687,10 +1687,10 @@
/// EnumMatcher for 'match function_private_workgroup'
constexpr NumberMatcher kFunctionPrivateWorkgroupMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<AddressSpace>(number.Value())) {
- case AddressSpace::kFunction:
- case AddressSpace::kPrivate:
- case AddressSpace::kWorkgroup:
+ switch (static_cast<core::AddressSpace>(number.Value())) {
+ case core::AddressSpace::kFunction:
+ case core::AddressSpace::kPrivate:
+ case core::AddressSpace::kWorkgroup:
return number;
default:
return Number::invalid;
@@ -1704,9 +1704,9 @@
/// EnumMatcher for 'match workgroup_or_storage'
constexpr NumberMatcher kWorkgroupOrStorageMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<AddressSpace>(number.Value())) {
- case AddressSpace::kWorkgroup:
- case AddressSpace::kStorage:
+ switch (static_cast<core::AddressSpace>(number.Value())) {
+ case core::AddressSpace::kWorkgroup:
+ case core::AddressSpace::kStorage:
return number;
default:
return Number::invalid;
@@ -1720,8 +1720,8 @@
/// EnumMatcher for 'match storage'
constexpr NumberMatcher kStorageMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- if (number.IsAny() || number.Value() == static_cast<uint32_t>(AddressSpace::kStorage)) {
- return Number(static_cast<uint32_t>(AddressSpace::kStorage));
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::AddressSpace::kStorage)) {
+ return Number(static_cast<uint32_t>(core::AddressSpace::kStorage));
}
return Number::invalid;
},
@@ -1733,8 +1733,8 @@
/// EnumMatcher for 'match workgroup'
constexpr NumberMatcher kWorkgroupMatcher {
/* match */ [](MatchState&, Number number) -> Number {
- if (number.IsAny() || number.Value() == static_cast<uint32_t>(AddressSpace::kWorkgroup)) {
- return Number(static_cast<uint32_t>(AddressSpace::kWorkgroup));
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::AddressSpace::kWorkgroup)) {
+ return Number(static_cast<uint32_t>(core::AddressSpace::kWorkgroup));
}
return Number::invalid;
},
diff --git a/src/tint/lang/core/intrinsic/data/type_matchers.h b/src/tint/lang/core/intrinsic/data/type_matchers.h
index c2beb3c..1dbd965 100644
--- a/src/tint/lang/core/intrinsic/data/type_matchers.h
+++ b/src/tint/lang/core/intrinsic/data/type_matchers.h
@@ -46,29 +46,29 @@
return ty->IsAnyOf<intrinsic::Any, type::Bool>();
}
-inline const type::AbstractFloat* BuildFa(intrinsic::MatchState& state) {
+inline const type::AbstractFloat* BuildFa(intrinsic::MatchState& state, const type::Type*) {
return state.types.AFloat();
}
inline bool MatchFa(intrinsic::MatchState& state, const type::Type* ty) {
return (state.earliest_eval_stage <= EvaluationStage::kConstant) &&
- ty->IsAnyOf<intrinsic::Any, core::type::AbstractNumeric>();
+ ty->IsAnyOf<intrinsic::Any, type::AbstractNumeric>();
}
-inline const type::AbstractInt* BuildIa(intrinsic::MatchState& state) {
+inline const type::AbstractInt* BuildIa(intrinsic::MatchState& state, const type::Type*) {
return state.types.AInt();
}
inline bool MatchIa(intrinsic::MatchState& state, const type::Type* ty) {
return (state.earliest_eval_stage <= EvaluationStage::kConstant) &&
- ty->IsAnyOf<intrinsic::Any, core::type::AbstractInt>();
+ ty->IsAnyOf<intrinsic::Any, type::AbstractInt>();
}
-inline const type::Bool* BuildBool(intrinsic::MatchState& state) {
+inline const type::Bool* BuildBool(intrinsic::MatchState& state, const type::Type*) {
return state.types.bool_();
}
-inline const type::F16* BuildF16(intrinsic::MatchState& state) {
+inline const type::F16* BuildF16(intrinsic::MatchState& state, const type::Type*) {
return state.types.f16();
}
@@ -76,7 +76,7 @@
return ty->IsAnyOf<intrinsic::Any, type::F16, type::AbstractNumeric>();
}
-inline const type::F32* BuildF32(intrinsic::MatchState& state) {
+inline const type::F32* BuildF32(intrinsic::MatchState& state, const type::Type*) {
return state.types.f32();
}
@@ -84,7 +84,7 @@
return ty->IsAnyOf<intrinsic::Any, type::F32, type::AbstractNumeric>();
}
-inline const type::I32* BuildI32(intrinsic::MatchState& state) {
+inline const type::I32* BuildI32(intrinsic::MatchState& state, const type::Type*) {
return state.types.i32();
}
@@ -92,7 +92,7 @@
return ty->IsAnyOf<intrinsic::Any, type::I32, type::AbstractInt>();
}
-inline const type::U32* BuildU32(intrinsic::MatchState& state) {
+inline const type::U32* BuildU32(intrinsic::MatchState& state, const type::Type*) {
return state.types.u32();
}
@@ -110,7 +110,7 @@
return true;
}
- if (auto* v = ty->As<core::type::Vector>()) {
+ if (auto* v = ty->As<type::Vector>()) {
N = v->Width();
T = v->type();
return true;
@@ -125,7 +125,7 @@
return true;
}
- if (auto* v = ty->As<core::type::Vector>()) {
+ if (auto* v = ty->As<type::Vector>()) {
if (v->Width() == N) {
T = v->type();
return true;
@@ -135,13 +135,16 @@
}
inline const type::Vector* BuildVec(intrinsic::MatchState& state,
+ const type::Type*,
intrinsic::Number N,
const type::Type* el) {
return state.types.vec(el, N.Value());
}
template <uint32_t N>
-inline const type::Vector* BuildVec(intrinsic::MatchState& state, const type::Type* el) {
+inline const type::Vector* BuildVec(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* el) {
return state.types.vec(el, N);
}
@@ -159,7 +162,7 @@
return true;
}
- if (auto* v = ty->As<core::type::Vector>()) {
+ if (auto* v = ty->As<type::Vector>()) {
if (v->Packed()) {
T = v->type();
return true;
@@ -168,7 +171,9 @@
return false;
}
-inline const type::Vector* BuildPackedVec3(intrinsic::MatchState& state, const type::Type* el) {
+inline const type::Vector* BuildPackedVec3(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* el) {
return state.types.Get<type::Vector>(el, 3u, /* packed */ true);
}
@@ -183,7 +188,7 @@
T = ty;
return true;
}
- if (auto* m = ty->As<core::type::Matrix>()) {
+ if (auto* m = ty->As<type::Matrix>()) {
M = m->columns();
N = m->ColumnType()->Width();
T = m->type();
@@ -198,7 +203,7 @@
T = ty;
return true;
}
- if (auto* m = ty->As<core::type::Matrix>()) {
+ if (auto* m = ty->As<type::Matrix>()) {
if (m->columns() == C && m->rows() == R) {
T = m->type();
return true;
@@ -208,6 +213,7 @@
}
inline const type::Matrix* BuildMat(intrinsic::MatchState& state,
+ const type::Type*,
intrinsic::Number C,
intrinsic::Number R,
const type::Type* T) {
@@ -216,7 +222,9 @@
}
template <uint32_t C, uint32_t R>
-inline const type::Matrix* BuildMat(intrinsic::MatchState& state, const type::Type* T) {
+inline const type::Matrix* BuildMat(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* T) {
auto* column_type = state.types.vec(T, R);
return state.types.mat(column_type, C);
}
@@ -247,8 +255,8 @@
return true;
}
- if (auto* a = ty->As<core::type::Array>()) {
- if (a->Count()->Is<core::type::RuntimeArrayCount>()) {
+ if (auto* a = ty->As<type::Array>()) {
+ if (a->Count()->Is<type::RuntimeArrayCount>()) {
T = a->ElemType();
return true;
}
@@ -256,7 +264,9 @@
return false;
}
-inline const type::Array* BuildArray(intrinsic::MatchState& state, const type::Type* el) {
+inline const type::Array* BuildArray(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* el) {
return state.types.Get<type::Array>(el,
/* count */ state.types.Get<type::RuntimeArrayCount>(),
/* align */ 0u,
@@ -277,7 +287,7 @@
return true;
}
- if (auto* p = ty->As<core::type::Pointer>()) {
+ if (auto* p = ty->As<type::Pointer>()) {
S = intrinsic::Number(static_cast<uint32_t>(p->AddressSpace()));
T = p->StoreType();
A = intrinsic::Number(static_cast<uint32_t>(p->Access()));
@@ -287,6 +297,7 @@
}
inline const type::Pointer* BuildPtr(intrinsic::MatchState& state,
+ const type::Type*,
intrinsic::Number S,
const type::Type* T,
intrinsic::Number& A) {
@@ -300,14 +311,16 @@
return true;
}
- if (auto* a = ty->As<core::type::Atomic>()) {
+ if (auto* a = ty->As<type::Atomic>()) {
T = a->Type();
return true;
}
return false;
}
-inline const type::Atomic* BuildAtomic(intrinsic::MatchState& state, const type::Type* T) {
+inline const type::Atomic* BuildAtomic(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* T) {
return state.types.atomic(T);
}
@@ -315,12 +328,10 @@
if (ty->Is<intrinsic::Any>()) {
return true;
}
- return ty->Is([](const core::type::Sampler* s) {
- return s->kind() == core::type::SamplerKind::kSampler;
- });
+ return ty->Is([](const type::Sampler* s) { return s->kind() == type::SamplerKind::kSampler; });
}
-inline const type::Sampler* BuildSampler(intrinsic::MatchState& state) {
+inline const type::Sampler* BuildSampler(intrinsic::MatchState& state, const type::Type*) {
return state.types.sampler();
}
@@ -328,12 +339,12 @@
if (ty->Is<intrinsic::Any>()) {
return true;
}
- return ty->Is([](const core::type::Sampler* s) {
- return s->kind() == core::type::SamplerKind::kComparisonSampler;
- });
+ return ty->Is(
+ [](const type::Sampler* s) { return s->kind() == type::SamplerKind::kComparisonSampler; });
}
-inline const type::Sampler* BuildSamplerComparison(intrinsic::MatchState& state) {
+inline const type::Sampler* BuildSamplerComparison(intrinsic::MatchState& state,
+ const type::Type*) {
return state.types.comparison_sampler();
}
@@ -345,7 +356,7 @@
T = ty;
return true;
}
- if (auto* v = ty->As<core::type::SampledTexture>()) {
+ if (auto* v = ty->As<type::SampledTexture>()) {
if (v->dim() == dim) {
T = v->type();
return true;
@@ -356,14 +367,14 @@
#define JOIN(a, b) a##b
-#define DECLARE_SAMPLED_TEXTURE(suffix, dim) \
- inline bool JOIN(MatchTexture, suffix)(intrinsic::MatchState & state, const type::Type* ty, \
- const type::Type*& T) { \
- return MatchTexture(state, ty, dim, T); \
- } \
- inline const type::SampledTexture* JOIN(BuildTexture, suffix)(intrinsic::MatchState & state, \
- const type::Type* T) { \
- return state.types.Get<type::SampledTexture>(dim, T); \
+#define DECLARE_SAMPLED_TEXTURE(suffix, dim) \
+ inline bool JOIN(MatchTexture, suffix)(intrinsic::MatchState & state, const type::Type* ty, \
+ const type::Type*& T) { \
+ return MatchTexture(state, ty, dim, T); \
+ } \
+ inline const type::SampledTexture* JOIN(BuildTexture, suffix)( \
+ intrinsic::MatchState & state, const type::Type*, const type::Type* T) { \
+ return state.types.Get<type::SampledTexture>(dim, T); \
}
DECLARE_SAMPLED_TEXTURE(1D, type::TextureDimension::k1d)
@@ -382,7 +393,7 @@
T = ty;
return true;
}
- if (auto* v = ty->As<core::type::MultisampledTexture>()) {
+ if (auto* v = ty->As<type::MultisampledTexture>()) {
if (v->dim() == dim) {
T = v->type();
return true;
@@ -397,7 +408,7 @@
return MatchTextureMultisampled(state, ty, dim, T); \
} \
inline const type::MultisampledTexture* JOIN(BuildTextureMultisampled, suffix)( \
- intrinsic::MatchState & state, const type::Type* T) { \
+ intrinsic::MatchState & state, const type::Type*, const type::Type* T) { \
return state.types.Get<type::MultisampledTexture>(dim, T); \
}
@@ -410,17 +421,17 @@
if (ty->Is<intrinsic::Any>()) {
return true;
}
- return ty->Is([&](const core::type::DepthTexture* t) { return t->dim() == dim; });
+ return ty->Is([&](const type::DepthTexture* t) { return t->dim() == dim; });
}
-#define DECLARE_DEPTH_TEXTURE(suffix, dim) \
- inline bool JOIN(MatchTextureDepth, suffix)(intrinsic::MatchState & state, \
- const type::Type* ty) { \
- return MatchTextureDepth(state, ty, dim); \
- } \
- inline const type::DepthTexture* JOIN(BuildTextureDepth, \
- suffix)(intrinsic::MatchState & state) { \
- return state.types.Get<type::DepthTexture>(dim); \
+#define DECLARE_DEPTH_TEXTURE(suffix, dim) \
+ inline bool JOIN(MatchTextureDepth, suffix)(intrinsic::MatchState & state, \
+ const type::Type* ty) { \
+ return MatchTextureDepth(state, ty, dim); \
+ } \
+ inline const type::DepthTexture* JOIN(BuildTextureDepth, suffix)( \
+ intrinsic::MatchState & state, const type::Type*) { \
+ return state.types.Get<type::DepthTexture>(dim); \
}
DECLARE_DEPTH_TEXTURE(2D, type::TextureDimension::k2d)
@@ -433,14 +444,14 @@
if (ty->Is<intrinsic::Any>()) {
return true;
}
- return ty->Is([&](const core::type::DepthMultisampledTexture* t) {
- return t->dim() == core::type::TextureDimension::k2d;
+ return ty->Is([&](const type::DepthMultisampledTexture* t) {
+ return t->dim() == type::TextureDimension::k2d;
});
}
-inline type::DepthMultisampledTexture* BuildTextureDepthMultisampled2D(
- intrinsic::MatchState& state) {
- return state.types.Get<core::type::DepthMultisampledTexture>(core::type::TextureDimension::k2d);
+inline type::DepthMultisampledTexture* BuildTextureDepthMultisampled2D(intrinsic::MatchState& state,
+ const type::Type*) {
+ return state.types.Get<type::DepthMultisampledTexture>(type::TextureDimension::k2d);
}
inline bool MatchTextureStorage(intrinsic::MatchState&,
@@ -453,7 +464,7 @@
A = intrinsic::Number::any;
return true;
}
- if (auto* v = ty->As<core::type::StorageTexture>()) {
+ if (auto* v = ty->As<type::StorageTexture>()) {
if (v->dim() == dim) {
F = intrinsic::Number(static_cast<uint32_t>(v->texel_format()));
A = intrinsic::Number(static_cast<uint32_t>(v->access()));
@@ -470,7 +481,8 @@
return MatchTextureStorage(state, ty, dim, F, A); \
} \
inline const type::StorageTexture* JOIN(BuildTextureStorage, suffix)( \
- intrinsic::MatchState & state, intrinsic::Number F, intrinsic::Number A) { \
+ intrinsic::MatchState & state, const type::Type*, intrinsic::Number F, \
+ intrinsic::Number A) { \
auto format = static_cast<TexelFormat>(F.Value()); \
auto access = static_cast<Access>(A.Value()); \
auto* T = type::StorageTexture::SubtypeFor(format, state.types); \
@@ -487,7 +499,8 @@
return ty->IsAnyOf<intrinsic::Any, type::ExternalTexture>();
}
-inline const type::ExternalTexture* BuildTextureExternal(intrinsic::MatchState& state) {
+inline const type::ExternalTexture* BuildTextureExternal(intrinsic::MatchState& state,
+ const type::Type*) {
return state.types.Get<type::ExternalTexture>();
}
@@ -541,29 +554,36 @@
return false;
}
-inline const type::Struct* BuildModfResult(intrinsic::MatchState& state, const type::Type* el) {
+inline const type::Struct* BuildModfResult(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* el) {
return type::CreateModfResult(state.types, state.symbols, el);
}
inline const type::Struct* BuildModfResultVec(intrinsic::MatchState& state,
+ const type::Type*,
intrinsic::Number& n,
const type::Type* el) {
auto* vec = state.types.vec(el, n.Value());
- return core::type::CreateModfResult(state.types, state.symbols, vec);
+ return type::CreateModfResult(state.types, state.symbols, vec);
}
-inline const type::Struct* BuildFrexpResult(intrinsic::MatchState& state, const type::Type* el) {
+inline const type::Struct* BuildFrexpResult(intrinsic::MatchState& state,
+ const type::Type*,
+ const type::Type* el) {
return type::CreateFrexpResult(state.types, state.symbols, el);
}
inline const type::Struct* BuildFrexpResultVec(intrinsic::MatchState& state,
+ const type::Type*,
intrinsic::Number& n,
const type::Type* el) {
auto* vec = state.types.vec(el, n.Value());
- return core::type::CreateFrexpResult(state.types, state.symbols, vec);
+ return type::CreateFrexpResult(state.types, state.symbols, vec);
}
inline const type::Struct* BuildAtomicCompareExchangeResult(intrinsic::MatchState& state,
+ const type::Type*,
const type::Type* ty) {
return type::CreateAtomicCompareExchangeResult(state.types, state.symbols, ty);
}
diff --git a/src/tint/lang/spirv/intrinsic/data/BUILD.cmake b/src/tint/lang/spirv/intrinsic/data/BUILD.cmake
index 4c3e982..1f5e78f 100644
--- a/src/tint/lang/spirv/intrinsic/data/BUILD.cmake
+++ b/src/tint/lang/spirv/intrinsic/data/BUILD.cmake
@@ -28,6 +28,7 @@
tint_add_target(tint_lang_spirv_intrinsic_data lib
lang/spirv/intrinsic/data/data.cc
lang/spirv/intrinsic/data/data.h
+ lang/spirv/intrinsic/data/type_matchers.h
)
tint_target_add_dependencies(tint_lang_spirv_intrinsic_data lib
diff --git a/src/tint/lang/spirv/intrinsic/data/BUILD.gn b/src/tint/lang/spirv/intrinsic/data/BUILD.gn
index c64e4f7..4ae224e 100644
--- a/src/tint/lang/spirv/intrinsic/data/BUILD.gn
+++ b/src/tint/lang/spirv/intrinsic/data/BUILD.gn
@@ -29,6 +29,7 @@
sources = [
"data.cc",
"data.h",
+ "type_matchers.h",
]
deps = [
"${tint_src_dir}/lang/core",
diff --git a/src/tint/lang/spirv/intrinsic/data/data.cc b/src/tint/lang/spirv/intrinsic/data/data.cc
index 83531ed..74814e7 100644
--- a/src/tint/lang/spirv/intrinsic/data/data.cc
+++ b/src/tint/lang/spirv/intrinsic/data/data.cc
@@ -26,6 +26,7 @@
#include "src/tint/lang/core/intrinsic/data/type_matchers.h"
#include "src/tint/lang/spirv/intrinsic/data/data.h"
+#include "src/tint/lang/spirv/intrinsic/data/type_matchers.h"
#include "src/tint/utils/text/string_stream.h"
namespace tint::spirv::intrinsic::data {
@@ -71,7 +72,7 @@
if (!MatchF32(state, ty)) {
return nullptr;
}
- return BuildF32(state);
+ return BuildF32(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "f32";
@@ -85,7 +86,7 @@
if (!MatchF16(state, ty)) {
return nullptr;
}
- return BuildF16(state);
+ return BuildF16(state, ty);
},
/* string */ [](MatchState*) -> std::string {
return "f16";
@@ -93,6 +94,20 @@
};
+/// TypeMatcher for 'type u32'
+constexpr TypeMatcher kU32Matcher {
+/* match */ [](MatchState& state, const Type* ty) -> const Type* {
+ if (!MatchU32(state, ty)) {
+ return nullptr;
+ }
+ return BuildU32(state, ty);
+ },
+/* string */ [](MatchState*) -> std::string {
+ return "u32";
+ }
+};
+
+
/// TypeMatcher for 'type vec2'
constexpr TypeMatcher kVec2Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
@@ -104,7 +119,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec2(state, T);
+ return BuildVec2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -124,7 +139,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec3(state, T);
+ return BuildVec3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -144,7 +159,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec4(state, T);
+ return BuildVec4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -164,7 +179,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X2(state, T);
+ return BuildMat2X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -184,7 +199,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X3(state, T);
+ return BuildMat2X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -204,7 +219,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat2X4(state, T);
+ return BuildMat2X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -224,7 +239,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X2(state, T);
+ return BuildMat3X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -244,7 +259,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X3(state, T);
+ return BuildMat3X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -264,7 +279,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat3X4(state, T);
+ return BuildMat3X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -284,7 +299,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X2(state, T);
+ return BuildMat4X2(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -304,7 +319,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X3(state, T);
+ return BuildMat4X3(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -324,7 +339,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat4X4(state, T);
+ return BuildMat4X4(state, ty, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string T = state->TypeName();
@@ -349,7 +364,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildVec(state, N, T);
+ return BuildVec(state, ty, N, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -382,7 +397,7 @@
if (T == nullptr) {
return nullptr;
}
- return BuildMat(state, N, M, T);
+ return BuildMat(state, ty, N, M, T);
},
/* string */ [](MatchState* state) -> std::string {
const std::string N = state->NumName();
@@ -395,14 +410,60 @@
};
+/// TypeMatcher for 'type ptr'
+constexpr TypeMatcher kPtrMatcher {
+/* match */ [](MatchState& state, const Type* ty) -> const Type* {
+ Number S = Number::invalid;
+ const Type* T = nullptr;
+ Number A = Number::invalid;
+ if (!MatchPtr(state, ty, S, T, A)) {
+ return nullptr;
+ }
+ S = state.Num(S);
+ if (!S.IsValid()) {
+ return nullptr;
+ }
+ T = state.Type(T);
+ if (T == nullptr) {
+ return nullptr;
+ }
+ A = state.Num(A);
+ if (!A.IsValid()) {
+ return nullptr;
+ }
+ return BuildPtr(state, ty, S, T, A);
+ },
+/* string */ [](MatchState* state) -> std::string {
+ const std::string S = state->NumName();
+ const std::string T = state->TypeName();
+ const std::string A = state->NumName();
+ return "ptr<" + S + ", " + T + ", " + A + ">";
+ }
+};
+
+
+/// TypeMatcher for 'type struct_with_runtime_array'
+constexpr TypeMatcher kStructWithRuntimeArrayMatcher {
+/* match */ [](MatchState& state, const Type* ty) -> const Type* {
+ if (!MatchStructWithRuntimeArray(state, ty)) {
+ return nullptr;
+ }
+ return BuildStructWithRuntimeArray(state, ty);
+ },
+/* string */ [](MatchState*) -> std::string {
+ return "struct_with_runtime_array";
+ }
+};
+
+
/// TypeMatcher for 'match f32_f16'
constexpr TypeMatcher kF32F16Matcher {
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
if (MatchF32(state, ty)) {
- return BuildF32(state);
+ return BuildF32(state, ty);
}
if (MatchF16(state, ty)) {
- return BuildF16(state);
+ return BuildF16(state, ty);
}
return nullptr;
},
@@ -415,6 +476,19 @@
}
};
+/// EnumMatcher for 'match storage'
+constexpr NumberMatcher kStorageMatcher {
+/* match */ [](MatchState&, Number number) -> Number {
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::AddressSpace::kStorage)) {
+ return Number(static_cast<uint32_t>(core::AddressSpace::kStorage));
+ }
+ return Number::invalid;
+ },
+/* string */ [](MatchState*) -> std::string {
+ return "storage";
+ }
+};
+
/// Type and number matchers
/// The template types, types, and type matchers
@@ -422,21 +496,24 @@
/* [0] */ TemplateTypeMatcher<0>::matcher,
/* [1] */ kF32Matcher,
/* [2] */ kF16Matcher,
- /* [3] */ kVec2Matcher,
- /* [4] */ kVec3Matcher,
- /* [5] */ kVec4Matcher,
- /* [6] */ kMat2X2Matcher,
- /* [7] */ kMat2X3Matcher,
- /* [8] */ kMat2X4Matcher,
- /* [9] */ kMat3X2Matcher,
- /* [10] */ kMat3X3Matcher,
- /* [11] */ kMat3X4Matcher,
- /* [12] */ kMat4X2Matcher,
- /* [13] */ kMat4X3Matcher,
- /* [14] */ kMat4X4Matcher,
- /* [15] */ kVecMatcher,
- /* [16] */ kMatMatcher,
- /* [17] */ kF32F16Matcher,
+ /* [3] */ kU32Matcher,
+ /* [4] */ kVec2Matcher,
+ /* [5] */ kVec3Matcher,
+ /* [6] */ kVec4Matcher,
+ /* [7] */ kMat2X2Matcher,
+ /* [8] */ kMat2X3Matcher,
+ /* [9] */ kMat2X4Matcher,
+ /* [10] */ kMat3X2Matcher,
+ /* [11] */ kMat3X3Matcher,
+ /* [12] */ kMat3X4Matcher,
+ /* [13] */ kMat4X2Matcher,
+ /* [14] */ kMat4X3Matcher,
+ /* [15] */ kMat4X4Matcher,
+ /* [16] */ kVecMatcher,
+ /* [17] */ kMatMatcher,
+ /* [18] */ kPtrMatcher,
+ /* [19] */ kStructWithRuntimeArrayMatcher,
+ /* [20] */ kF32F16Matcher,
};
/// The template numbers, and number matchers
@@ -444,25 +521,31 @@
/* [0] */ TemplateNumberMatcher<0>::matcher,
/* [1] */ TemplateNumberMatcher<1>::matcher,
/* [2] */ TemplateNumberMatcher<2>::matcher,
+ /* [3] */ kStorageMatcher,
};
constexpr TypeMatcherIndex kTypeMatcherIndices[] = {
- /* [0] */ TypeMatcherIndex(16),
- /* [1] */ TypeMatcherIndex(0),
- /* [2] */ TypeMatcherIndex(15),
+ /* [0] */ TypeMatcherIndex(18),
+ /* [1] */ TypeMatcherIndex(19),
+ /* [2] */ TypeMatcherIndex(17),
/* [3] */ TypeMatcherIndex(0),
+ /* [4] */ TypeMatcherIndex(16),
+ /* [5] */ TypeMatcherIndex(0),
+ /* [6] */ TypeMatcherIndex(3),
};
static_assert(TypeMatcherIndex::CanIndex(kTypeMatcherIndices),
"TypeMatcherIndex is not large enough to index kTypeMatcherIndices");
constexpr NumberMatcherIndex kNumberMatcherIndices[] = {
- /* [0] */ NumberMatcherIndex(1),
+ /* [0] */ NumberMatcherIndex(3),
/* [1] */ NumberMatcherIndex(0),
- /* [2] */ NumberMatcherIndex(1),
- /* [3] */ NumberMatcherIndex(2),
- /* [4] */ NumberMatcherIndex(0),
- /* [5] */ NumberMatcherIndex(2),
+ /* [2] */ NumberMatcherIndex(2),
+ /* [3] */ NumberMatcherIndex(1),
+ /* [4] */ NumberMatcherIndex(2),
+ /* [5] */ NumberMatcherIndex(1),
+ /* [6] */ NumberMatcherIndex(0),
+ /* [7] */ NumberMatcherIndex(1),
};
static_assert(NumberMatcherIndex::CanIndex(kNumberMatcherIndices),
@@ -473,54 +556,66 @@
/* [0] */
/* usage */ core::ParameterUsage::kNone,
/* type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(4),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(0),
},
{
/* [1] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(0),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(3),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(/* invalid */),
},
{
/* [2] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(0),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
/* number_matcher_indices */ NumberMatcherIndicesIndex(1),
},
{
/* [3] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(1),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(/* invalid */),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(5),
},
{
/* [4] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(1),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(6),
},
{
/* [5] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(1),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(3),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(/* invalid */),
},
{
/* [6] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* number_matcher_indices */ NumberMatcherIndicesIndex(0),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(6),
},
{
/* [7] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(4),
/* number_matcher_indices */ NumberMatcherIndicesIndex(1),
},
{
/* [8] */
/* usage */ core::ParameterUsage::kNone,
- /* type_matcher_indices */ TypeMatcherIndicesIndex(1),
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(5),
+ },
+ {
+ /* [9] */
+ /* usage */ core::ParameterUsage::kNone,
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(4),
+ /* number_matcher_indices */ NumberMatcherIndicesIndex(1),
+ },
+ {
+ /* [10] */
+ /* usage */ core::ParameterUsage::kNone,
+ /* type_matcher_indices */ TypeMatcherIndicesIndex(3),
/* number_matcher_indices */ NumberMatcherIndicesIndex(/* invalid */),
},
};
@@ -531,8 +626,13 @@
constexpr TemplateTypeInfo kTemplateTypes[] = {
{
/* [0] */
+ /* name */ "I",
+ /* matcher_index */ TypeMatcherIndex(3),
+ },
+ {
+ /* [1] */
/* name */ "T",
- /* matcher_index */ TypeMatcherIndex(17),
+ /* matcher_index */ TypeMatcherIndex(20),
},
};
@@ -565,6 +665,11 @@
/* name */ "M",
/* matcher_index */ NumberMatcherIndex(/* invalid */),
},
+ {
+ /* [5] */
+ /* name */ "A",
+ /* matcher_index */ NumberMatcherIndex(/* invalid */),
+ },
};
static_assert(TemplateNumberIndex::CanIndex(kTemplateNumbers),
@@ -576,12 +681,12 @@
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* num_parameters */ 2,
/* num_template_types */ 1,
- /* num_template_numbers */ 3,
+ /* num_template_numbers */ 1,
/* template_types */ TemplateTypeIndex(0),
- /* template_numbers */ TemplateNumberIndex(0),
+ /* template_numbers */ TemplateNumberIndex(5),
/* parameters */ ParameterIndex(0),
- /* return_type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* return_number_matcher_indices */ NumberMatcherIndicesIndex(2),
+ /* return_type_matcher_indices */ TypeMatcherIndicesIndex(6),
+ /* return_number_matcher_indices */ NumberMatcherIndicesIndex(/* invalid */),
/* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
},
{
@@ -589,12 +694,12 @@
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* num_parameters */ 2,
/* num_template_types */ 1,
- /* num_template_numbers */ 2,
- /* template_types */ TemplateTypeIndex(0),
- /* template_numbers */ TemplateNumberIndex(3),
+ /* num_template_numbers */ 3,
+ /* template_types */ TemplateTypeIndex(1),
+ /* template_numbers */ TemplateNumberIndex(0),
/* parameters */ ParameterIndex(2),
- /* return_type_matcher_indices */ TypeMatcherIndicesIndex(0),
- /* return_number_matcher_indices */ NumberMatcherIndicesIndex(1),
+ /* return_type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* return_number_matcher_indices */ NumberMatcherIndicesIndex(3),
/* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
},
{
@@ -603,11 +708,11 @@
/* num_parameters */ 2,
/* num_template_types */ 1,
/* num_template_numbers */ 2,
- /* template_types */ TemplateTypeIndex(0),
+ /* template_types */ TemplateTypeIndex(1),
/* template_numbers */ TemplateNumberIndex(3),
/* parameters */ ParameterIndex(4),
/* return_type_matcher_indices */ TypeMatcherIndicesIndex(2),
- /* return_number_matcher_indices */ NumberMatcherIndicesIndex(0),
+ /* return_number_matcher_indices */ NumberMatcherIndicesIndex(6),
/* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
},
{
@@ -616,11 +721,11 @@
/* num_parameters */ 2,
/* num_template_types */ 1,
/* num_template_numbers */ 2,
- /* template_types */ TemplateTypeIndex(0),
+ /* template_types */ TemplateTypeIndex(1),
/* template_numbers */ TemplateNumberIndex(3),
- /* parameters */ ParameterIndex(5),
- /* return_type_matcher_indices */ TypeMatcherIndicesIndex(2),
- /* return_number_matcher_indices */ NumberMatcherIndicesIndex(0),
+ /* parameters */ ParameterIndex(6),
+ /* return_type_matcher_indices */ TypeMatcherIndicesIndex(4),
+ /* return_number_matcher_indices */ NumberMatcherIndicesIndex(3),
/* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
},
{
@@ -628,11 +733,24 @@
/* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
/* num_parameters */ 2,
/* num_template_types */ 1,
- /* num_template_numbers */ 1,
- /* template_types */ TemplateTypeIndex(0),
+ /* num_template_numbers */ 2,
+ /* template_types */ TemplateTypeIndex(1),
/* template_numbers */ TemplateNumberIndex(3),
/* parameters */ ParameterIndex(7),
- /* return_type_matcher_indices */ TypeMatcherIndicesIndex(2),
+ /* return_type_matcher_indices */ TypeMatcherIndicesIndex(4),
+ /* return_number_matcher_indices */ NumberMatcherIndicesIndex(3),
+ /* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
+ },
+ {
+ /* [5] */
+ /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
+ /* num_parameters */ 2,
+ /* num_template_types */ 1,
+ /* num_template_numbers */ 1,
+ /* template_types */ TemplateTypeIndex(1),
+ /* template_numbers */ TemplateNumberIndex(3),
+ /* parameters */ ParameterIndex(9),
+ /* return_type_matcher_indices */ TypeMatcherIndicesIndex(4),
/* return_number_matcher_indices */ NumberMatcherIndicesIndex(1),
/* const_eval_fn */ ConstEvalFunctionIndex(/* invalid */),
},
@@ -644,34 +762,40 @@
constexpr IntrinsicInfo kBuiltins[] = {
{
/* [0] */
- /* fn matrix_times_matrix<T : f32_f16, K : num, C : num, R : num>(mat<K, R, T>, mat<C, K, T>) -> mat<C, R, T> */
+ /* fn array_length<I : u32, A : access>(ptr<storage, struct_with_runtime_array, A>, I) -> u32 */
/* num overloads */ 1,
/* overloads */ OverloadIndex(0),
},
{
/* [1] */
- /* fn matrix_times_scalar<T : f32_f16, N : num, M : num>(mat<N, M, T>, T) -> mat<N, M, T> */
+ /* fn matrix_times_matrix<T : f32_f16, K : num, C : num, R : num>(mat<K, R, T>, mat<C, K, T>) -> mat<C, R, T> */
/* num overloads */ 1,
/* overloads */ OverloadIndex(1),
},
{
/* [2] */
- /* fn matrix_times_vector<T : f32_f16, N : num, M : num>(mat<N, M, T>, vec<N, T>) -> vec<M, T> */
+ /* fn matrix_times_scalar<T : f32_f16, N : num, M : num>(mat<N, M, T>, T) -> mat<N, M, T> */
/* num overloads */ 1,
/* overloads */ OverloadIndex(2),
},
{
/* [3] */
- /* fn vector_times_matrix<T : f32_f16, N : num, M : num>(vec<N, T>, mat<M, N, T>) -> vec<M, T> */
+ /* fn matrix_times_vector<T : f32_f16, N : num, M : num>(mat<N, M, T>, vec<N, T>) -> vec<M, T> */
/* num overloads */ 1,
/* overloads */ OverloadIndex(3),
},
{
/* [4] */
- /* fn vector_times_scalar<T : f32_f16, N : num>(vec<N, T>, T) -> vec<N, T> */
+ /* fn vector_times_matrix<T : f32_f16, N : num, M : num>(vec<N, T>, mat<M, N, T>) -> vec<M, T> */
/* num overloads */ 1,
/* overloads */ OverloadIndex(4),
},
+ {
+ /* [5] */
+ /* fn vector_times_scalar<T : f32_f16, N : num>(vec<N, T>, T) -> vec<N, T> */
+ /* num overloads */ 1,
+ /* overloads */ OverloadIndex(5),
+ },
};
// clang-format on
diff --git a/src/tint/lang/spirv/intrinsic/data/data.cc.tmpl b/src/tint/lang/spirv/intrinsic/data/data.cc.tmpl
index 76095e7..8130aea 100644
--- a/src/tint/lang/spirv/intrinsic/data/data.cc.tmpl
+++ b/src/tint/lang/spirv/intrinsic/data/data.cc.tmpl
@@ -20,6 +20,7 @@
#include <string>
#include "src/tint/lang/core/intrinsic/data/type_matchers.h"
+#include "src/tint/lang/spirv/intrinsic/data/type_matchers.h"
#include "src/tint/lang/spirv/intrinsic/data/data.h"
#include "src/tint/utils/text/string_stream.h"
diff --git a/src/tint/lang/spirv/intrinsic/data/type_matchers.h b/src/tint/lang/spirv/intrinsic/data/type_matchers.h
new file mode 100644
index 0000000..9708866
--- /dev/null
+++ b/src/tint/lang/spirv/intrinsic/data/type_matchers.h
@@ -0,0 +1,43 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_LANG_SPIRV_INTRINSIC_DATA_TYPE_MATCHERS_H_
+#define SRC_TINT_LANG_SPIRV_INTRINSIC_DATA_TYPE_MATCHERS_H_
+
+#include "src/tint/lang/core/intrinsic/table.h"
+
+namespace tint::spirv::intrinsic::data {
+
+inline bool MatchStructWithRuntimeArray(core::intrinsic::MatchState&, const core::type::Type* ty) {
+ if (auto* str = ty->As<core::type::Struct>()) {
+ if (str->Members().IsEmpty()) {
+ return false;
+ }
+ if (auto* ary = str->Members().Back()->Type()->As<core::type::Array>()) {
+ if (ary->Count()->Is<core::type::RuntimeArrayCount>()) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+inline const core::type::Type* BuildStructWithRuntimeArray(core::intrinsic::MatchState&,
+ const core::type::Type* ty) {
+ return ty;
+}
+
+} // namespace tint::spirv::intrinsic::data
+
+#endif // SRC_TINT_LANG_SPIRV_INTRINSIC_DATA_TYPE_MATCHERS_H_
diff --git a/src/tint/lang/spirv/ir/function.cc b/src/tint/lang/spirv/ir/function.cc
index e7885ea..ff7e55a 100644
--- a/src/tint/lang/spirv/ir/function.cc
+++ b/src/tint/lang/spirv/ir/function.cc
@@ -29,6 +29,8 @@
switch (i) {
case Function::kNone:
return "<none>";
+ case Function::kArrayLength:
+ return "spirv.array_length";
case Function::kMatrixTimesMatrix:
return "spirv.matrix_times_matrix";
case Function::kMatrixTimesScalar:
diff --git a/src/tint/lang/spirv/ir/function.h b/src/tint/lang/spirv/ir/function.h
index c6948e5..db6cb94 100644
--- a/src/tint/lang/spirv/ir/function.h
+++ b/src/tint/lang/spirv/ir/function.h
@@ -34,6 +34,7 @@
/// Enumerator of all builtin functions
enum class Function : uint8_t {
+ kArrayLength,
kMatrixTimesMatrix,
kMatrixTimesScalar,
kMatrixTimesVector,
diff --git a/src/tint/lang/spirv/ir/intrinsic.cc b/src/tint/lang/spirv/ir/intrinsic.cc
index 8933c06..7e2fbec 100644
--- a/src/tint/lang/spirv/ir/intrinsic.cc
+++ b/src/tint/lang/spirv/ir/intrinsic.cc
@@ -29,9 +29,6 @@
/// @param str the string to parse
/// @returns the parsed enum, or Intrinsic::kUndefined if the string could not be parsed.
Intrinsic ParseIntrinsic(std::string_view str) {
- if (str == "array_length") {
- return Intrinsic::kArrayLength;
- }
if (str == "atomic_and") {
return Intrinsic::kAtomicAnd;
}
@@ -120,8 +117,6 @@
switch (value) {
case Intrinsic::kUndefined:
return "undefined";
- case Intrinsic::kArrayLength:
- return "array_length";
case Intrinsic::kAtomicAnd:
return "atomic_and";
case Intrinsic::kAtomicCompareExchange:
diff --git a/src/tint/lang/spirv/ir/intrinsic.h b/src/tint/lang/spirv/ir/intrinsic.h
index 2b5f906..a679026 100644
--- a/src/tint/lang/spirv/ir/intrinsic.h
+++ b/src/tint/lang/spirv/ir/intrinsic.h
@@ -34,7 +34,6 @@
/// Intrinsic
enum class Intrinsic : uint8_t {
kUndefined,
- kArrayLength,
kAtomicAnd,
kAtomicCompareExchange,
kAtomicExchange,
@@ -82,7 +81,6 @@
Intrinsic ParseIntrinsic(std::string_view str);
constexpr const char* kIntrinsicStrings[] = {
- "array_length",
"atomic_and",
"atomic_compare_exchange",
"atomic_exchange",
diff --git a/src/tint/lang/spirv/spirv.def b/src/tint/lang/spirv/spirv.def
index 11ee7ec..4fc2d20 100644
--- a/src/tint/lang/spirv/spirv.def
+++ b/src/tint/lang/spirv/spirv.def
@@ -22,6 +22,7 @@
type f32
type f16
+type u32
type vec2<T>
type vec3<T>
type vec4<T>
@@ -36,13 +37,34 @@
type mat4x4<T>
@display("vec{N}<{T}>") type vec<N: num, T>
@display("mat{N}x{M}<{T}>") type mat<N: num, M: num, T>
+type ptr<S: address_space, T, A: access>
+
+type struct_with_runtime_array
+
+enum address_space {
+ function
+ private
+ workgroup
+ uniform
+ storage
+ push_constant
+ pixel_local
+}
+
+enum access {
+ read
+ write
+ read_write
+}
+
+match storage
+ : address_space.storage
////////////////////////////////////////////////////////////////////////////////
// Enumerators //
////////////////////////////////////////////////////////////////////////////////
enum intrinsic {
- array_length
atomic_and
atomic_compare_exchange
atomic_exchange
@@ -75,6 +97,7 @@
////////////////////////////////////////////////////////////////////////////////
// Builtin Functions //
////////////////////////////////////////////////////////////////////////////////
+fn array_length<I: u32, A: access>(ptr<storage, struct_with_runtime_array, A>, I) -> u32
fn matrix_times_matrix<T: f32_f16, K: num, C: num, R: num>(mat<K, R, T>, mat<C, K, T>) -> mat<C, R, T>
fn matrix_times_scalar<T: f32_f16, N: num, M: num>(mat<N, M, T>, T) -> mat<N, M, T>
fn matrix_times_vector<T: f32_f16, N: num, M: num>(mat<N, M, T>, vec<N, T>) -> vec<M, T>
diff --git a/src/tint/lang/spirv/writer/printer/printer.cc b/src/tint/lang/spirv/writer/printer/printer.cc
index e2c94fe..619abac 100644
--- a/src/tint/lang/spirv/writer/printer/printer.cc
+++ b/src/tint/lang/spirv/writer/printer/printer.cc
@@ -1092,6 +1092,9 @@
spv::Op op = spv::Op::Max;
switch (builtin->Func()) {
+ case spirv::ir::Function::kArrayLength:
+ op = spv::Op::OpArrayLength;
+ break;
case spirv::ir::Function::kMatrixTimesMatrix:
op = spv::Op::OpMatrixTimesMatrix;
break;
@@ -1571,9 +1574,6 @@
spv::Op op = spv::Op::Max;
switch (call->Kind()) {
- case spirv::ir::Intrinsic::kArrayLength:
- op = spv::Op::OpArrayLength;
- break;
case spirv::ir::Intrinsic::kAtomicIadd:
op = spv::Op::OpAtomicIAdd;
break;
diff --git a/src/tint/lang/spirv/writer/raise/builtin_polyfill.cc b/src/tint/lang/spirv/writer/raise/builtin_polyfill.cc
index 20290d5..4a57b53 100644
--- a/src/tint/lang/spirv/writer/raise/builtin_polyfill.cc
+++ b/src/tint/lang/spirv/writer/raise/builtin_polyfill.cc
@@ -28,6 +28,7 @@
#include "src/tint/lang/core/type/sampled_texture.h"
#include "src/tint/lang/core/type/storage_texture.h"
#include "src/tint/lang/core/type/texture.h"
+#include "src/tint/lang/spirv/ir/builtin_call.h"
#include "src/tint/lang/spirv/ir/intrinsic_call.h"
#include "src/tint/utils/ice/ice.h"
@@ -186,8 +187,8 @@
auto* const_idx = access->Indices()[0]->As<core::ir::Constant>();
// Replace the builtin call with a call to the spirv.array_length intrinsic.
- auto* call = b.Call<spirv::ir::IntrinsicCall>(
- builtin->Result()->Type(), spirv::ir::Intrinsic::kArrayLength,
+ auto* call = b.Call<spirv::ir::BuiltinCall>(
+ builtin->Result()->Type(), spirv::ir::Function::kArrayLength,
Vector{access->Object(), Literal(u32(const_idx->Value()->ValueAs<uint32_t>()))});
call->InsertBefore(builtin);
return call->Result();
diff --git a/src/tint/utils/templates/intrinsic_table_data.tmpl.inc b/src/tint/utils/templates/intrinsic_table_data.tmpl.inc
index bb0c169..9da4e6c 100644
--- a/src/tint/utils/templates/intrinsic_table_data.tmpl.inc
+++ b/src/tint/utils/templates/intrinsic_table_data.tmpl.inc
@@ -315,7 +315,7 @@
return nullptr;
}
{{- end }}
- return Build{{$name}}(state{{range .TemplateParams}}, {{.GetName}}{{end}});
+ return Build{{$name}}(state, ty{{range .TemplateParams}}, {{.GetName}}{{end}});
},
/* string */ [](MatchState*{{if .TemplateParams}} state{{end}}) -> std::string {
{{- range .TemplateParams }}
@@ -346,7 +346,7 @@
/* match */ [](MatchState& state, const Type* ty) -> const Type* {
{{- range .PrecedenceSortedTypes }}
if (Match{{PascalCase .Name}}(state, ty)) {
- return Build{{PascalCase .Name}}(state);
+ return Build{{PascalCase .Name}}(state, ty);
}
{{- end }}
return nullptr;
@@ -379,16 +379,16 @@
{{- $option := index .Options 0 }}
{{- $entry := printf "k%v" (PascalCase $option.Name) -}}
/* match */ [](MatchState&, Number number) -> Number {
- if (number.IsAny() || number.Value() == static_cast<uint32_t>({{$enum}}::{{$entry}})) {
- return Number(static_cast<uint32_t>({{$enum}}::{{$entry}}));
+ if (number.IsAny() || number.Value() == static_cast<uint32_t>(core::{{$enum}}::{{$entry}})) {
+ return Number(static_cast<uint32_t>(core::{{$enum}}::{{$entry}}));
}
return Number::invalid;
},
{{- else -}}
/* match */ [](MatchState&, Number number) -> Number {
- switch (static_cast<{{$enum}}>(number.Value())) {
+ switch (static_cast<core::{{$enum}}>(number.Value())) {
{{- range .Options }}
- case {{$enum}}::k{{PascalCase .Name}}:
+ case core::{{$enum}}::k{{PascalCase .Name}}:
{{- end }}
return number;
default: