From 54bcbdbbf34be86f006c7e4cadc60798942a99b5 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 31 Aug 2022 01:06:28 +0000 Subject: [PATCH] tint/resolver: Fix intrinsic table matching of AInt as AFloat An AInt argument can be passed to a parameter of type AFloat. Fix the matcher for AFloat so that it includes AInts. Change-Id: I6aeebb567b6176b146920a2035f09cd07c11c014 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100780 Reviewed-by: Antonio Maiorano Commit-Queue: Antonio Maiorano Kokoro: Kokoro --- src/tint/intrinsics.def | 40 +++++------ src/tint/resolver/intrinsic_table.cc | 2 +- src/tint/resolver/intrinsic_table.inl | 86 +++++++++++------------ src/tint/resolver/intrinsic_table_test.cc | 16 +++++ 4 files changed, 80 insertions(+), 64 deletions(-) diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index 2b84d45fb3..ae89f5c37d 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -105,8 +105,8 @@ enum texel_format { // https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section type bool -@precedence(5) @display("abstract-float") type fa -@precedence(4) @display("abstract-int") type ia +@precedence(5) @display("abstract-int") type ia +@precedence(4) @display("abstract-float") type fa @precedence(3) type i32 @precedence(2) type u32 @precedence(1) type f32 @@ -757,40 +757,40 @@ fn textureLoad(texture: texture_external, coords: vec2) -> vec4 // Matrix constructors (scalar) @const("MatCtorS") ctor mat2x2(T, T, - T, T) -> mat2x2 + T, T) -> mat2x2 @const("MatCtorS") ctor mat2x3(T, T, T, - T, T, T) -> mat2x3 + T, T, T) -> mat2x3 @const("MatCtorS") ctor mat2x4(T, T, T, T, - T, T, T, T) -> mat2x4 + T, T, T, T) -> mat2x4 @const("MatCtorS") ctor mat3x2(T, T, - T, T, - T, T) -> mat3x2 + T, T, + T, T) -> mat3x2 @const("MatCtorS") ctor mat3x3(T, T, T, - T, T, T, - T, T, T) -> mat3x3 + T, T, T, + T, T, T) -> mat3x3 @const("MatCtorS") ctor mat3x4(T, T, T, T, - T, T, T, T, - T, T, T, T) -> mat3x4 + T, T, T, T, + T, T, T, T) -> mat3x4 @const("MatCtorS") ctor mat4x2(T, T, - T, T, - T, T, - T, T) -> mat4x2 + T, T, + T, T, + T, T) -> mat4x2 @const("MatCtorS") ctor mat4x3(T, T, T, - T, T, T, - T, T, T, - T, T, T) -> mat4x3 + T, T, T, + T, T, T, + T, T, T) -> mat4x3 @const("MatCtorS") ctor mat4x4(T, T, T, T, - T, T, T, T, - T, T, T, T, - T, T, T, T) -> mat4x4 + T, T, T, T, + T, T, T, T, + T, T, T, T) -> mat4x4 // Matrix constructors (column vectors) @const("MatCtorV") diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc index 0cd0abec37..86b44a43a7 100644 --- a/src/tint/resolver/intrinsic_table.cc +++ b/src/tint/resolver/intrinsic_table.cc @@ -349,7 +349,7 @@ const sem::AbstractFloat* build_fa(MatchState& state) { } bool match_fa(const sem::Type* ty) { - return ty->IsAnyOf(); + return ty->IsAnyOf(); } const sem::AbstractInt* build_ia(MatchState& state) { diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl index c589b2f66e..ff5878a2d7 100644 --- a/src/tint/resolver/intrinsic_table.inl +++ b/src/tint/resolver/intrinsic_table.inl @@ -48,34 +48,6 @@ std::string Bool::String(MatchState*) const { return "bool"; } -/// TypeMatcher for 'type fa' -class Fa : public TypeMatcher { - public: - /// Checks whether the given type matches the matcher rules. - /// Match may define and refine the template types and numbers in state. - /// @param state the MatchState - /// @param type the type to match - /// @returns the canonicalized type on match, otherwise nullptr - const sem::Type* Match(MatchState& state, - const sem::Type* type) const override; - /// @param state the MatchState - /// @return a string representation of the matcher. - std::string String(MatchState* state) const override; -}; - -const sem::Type* Fa::Match(MatchState& state, const sem::Type* ty) const { - if (!match_fa(ty)) { - return nullptr; - } - return build_fa(state); -} - -std::string Fa::String(MatchState*) const { - std::stringstream ss; - ss << "abstract-float"; - return ss.str(); -} - /// TypeMatcher for 'type ia' class Ia : public TypeMatcher { public: @@ -104,6 +76,34 @@ std::string Ia::String(MatchState*) const { return ss.str(); } +/// TypeMatcher for 'type fa' +class Fa : public TypeMatcher { + public: + /// Checks whether the given type matches the matcher rules. + /// Match may define and refine the template types and numbers in state. + /// @param state the MatchState + /// @param type the type to match + /// @returns the canonicalized type on match, otherwise nullptr + const sem::Type* Match(MatchState& state, + const sem::Type* type) const override; + /// @param state the MatchState + /// @return a string representation of the matcher. + std::string String(MatchState* state) const override; +}; + +const sem::Type* Fa::Match(MatchState& state, const sem::Type* ty) const { + if (!match_fa(ty)) { + return nullptr; + } + return build_fa(state); +} + +std::string Fa::String(MatchState*) const { + std::stringstream ss; + ss << "abstract-float"; + return ss.str(); +} + /// TypeMatcher for 'type i32' class I32 : public TypeMatcher { public: @@ -1567,12 +1567,12 @@ class AbstractOrScalar : public TypeMatcher { }; const sem::Type* AbstractOrScalar::Match(MatchState& state, const sem::Type* ty) const { - if (match_fa(ty)) { - return build_fa(state); - } if (match_ia(ty)) { return build_ia(state); } + if (match_fa(ty)) { + return build_fa(state); + } if (match_i32(ty)) { return build_i32(state); } @@ -1859,12 +1859,12 @@ class FiaFiu32F16 : public TypeMatcher { }; const sem::Type* FiaFiu32F16::Match(MatchState& state, const sem::Type* ty) const { - if (match_fa(ty)) { - return build_fa(state); - } if (match_ia(ty)) { return build_ia(state); } + if (match_fa(ty)) { + return build_fa(state); + } if (match_i32(ty)) { return build_i32(state); } @@ -1905,12 +1905,12 @@ class FiaFi32F16 : public TypeMatcher { }; const sem::Type* FiaFi32F16::Match(MatchState& state, const sem::Type* ty) const { - if (match_fa(ty)) { - return build_fa(state); - } if (match_ia(ty)) { return build_ia(state); } + if (match_fa(ty)) { + return build_fa(state); + } if (match_i32(ty)) { return build_i32(state); } @@ -1948,12 +1948,12 @@ class FiaFiu32 : public TypeMatcher { }; const sem::Type* FiaFiu32::Match(MatchState& state, const sem::Type* ty) const { - if (match_fa(ty)) { - return build_fa(state); - } if (match_ia(ty)) { return build_ia(state); } + if (match_fa(ty)) { + return build_fa(state); + } if (match_i32(ty)) { return build_i32(state); } @@ -2533,8 +2533,8 @@ class Matchers { TemplateNumberMatcher template_number_1_{1}; TemplateNumberMatcher template_number_2_{2}; Bool Bool_; - Fa Fa_; Ia Ia_; + Fa Fa_; I32 I32_; U32 U32_; F32 F32_; @@ -2619,8 +2619,8 @@ class Matchers { /* [0] */ &template_type_0_, /* [1] */ &template_type_1_, /* [2] */ &Bool_, - /* [3] */ &Fa_, - /* [4] */ &Ia_, + /* [3] */ &Ia_, + /* [4] */ &Fa_, /* [5] */ &I32_, /* [6] */ &U32_, /* [7] */ &F32_, diff --git a/src/tint/resolver/intrinsic_table_test.cc b/src/tint/resolver/intrinsic_table_test.cc index 02c97f7aac..b9f9d53c5f 100644 --- a/src/tint/resolver/intrinsic_table_test.cc +++ b/src/tint/resolver/intrinsic_table_test.cc @@ -767,6 +767,22 @@ TEST_F(IntrinsicTableTest, MismatchTypeConstructorExplicit) { )"); } +TEST_F(IntrinsicTableTest, MatchTypeConstructorImplicitMatFromVec) { + auto* af = create(); + auto* vec2_ai = create(create(), 2u); + auto* vec2_af = create(af, 2u); + auto* mat2x2_af = create(vec2_af, 2u); + auto result = table->Lookup(CtorConvIntrinsic::kMat2x2, nullptr, + utils::Vector{vec2_ai, vec2_ai}, Source{{12, 34}}); + ASSERT_NE(result.target, nullptr); + EXPECT_TYPE(result.target->ReturnType(), mat2x2_af); + EXPECT_TRUE(result.target->Is()); + ASSERT_EQ(result.target->Parameters().Length(), 2u); + EXPECT_TYPE(result.target->Parameters()[0]->Type(), vec2_af); + EXPECT_TYPE(result.target->Parameters()[1]->Type(), vec2_af); + EXPECT_NE(result.const_eval_fn, nullptr); +} + TEST_F(IntrinsicTableTest, MatchTypeConversion) { auto* i32 = create(); auto* vec3_i32 = create(i32, 3u);