From 72551392e8871cb169e6ea74674bb840abb4bfca Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Mon, 21 Nov 2022 15:29:54 +0000 Subject: [PATCH] tint: remove ConstEval::current_source member and pass down source through function calls Bug: tint:1581 Bug: tint:1751 Change-Id: I4dea92d4b67d39559ce65f45144215e56b6a3e9a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110724 Reviewed-by: Ben Clayton Kokoro: Kokoro --- src/tint/resolver/const_eval.cc | 269 ++++++++++++++++---------------- src/tint/resolver/const_eval.h | 223 ++++++++++++++------------ 2 files changed, 259 insertions(+), 233 deletions(-) diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index 713ad36d3e..306e9c9a85 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -39,7 +39,6 @@ #include "src/tint/utils/bitcast.h" #include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/map.h" -#include "src/tint/utils/scoped_assignment.h" #include "src/tint/utils/transform.h" using namespace tint::number_suffixes; // NOLINT @@ -651,13 +650,13 @@ ImplResult TransformBinaryElements(ProgramBuilder& builder, ConstEval::ConstEval(ProgramBuilder& b) : builder(b) {} template -utils::Result ConstEval::Add(NumberT a, NumberT b) { +utils::Result ConstEval::Add(const Source& source, NumberT a, NumberT b) { NumberT result; if constexpr (IsAbstract || IsFloatingPoint) { if (auto r = CheckedAdd(a, b)) { result = r->value; } else { - AddError(OverflowErrorMessage(a, "+", b), *current_source); + AddError(OverflowErrorMessage(a, "+", b), source); return utils::Failure; } } else { @@ -677,13 +676,13 @@ utils::Result ConstEval::Add(NumberT a, NumberT b) { } template -utils::Result ConstEval::Sub(NumberT a, NumberT b) { +utils::Result ConstEval::Sub(const Source& source, NumberT a, NumberT b) { NumberT result; if constexpr (IsAbstract || IsFloatingPoint) { if (auto r = CheckedSub(a, b)) { result = r->value; } else { - AddError(OverflowErrorMessage(a, "-", b), *current_source); + AddError(OverflowErrorMessage(a, "-", b), source); return utils::Failure; } } else { @@ -703,7 +702,7 @@ utils::Result ConstEval::Sub(NumberT a, NumberT b) { } template -utils::Result ConstEval::Mul(NumberT a, NumberT b) { +utils::Result ConstEval::Mul(const Source& source, NumberT a, NumberT b) { using T = UnwrapNumber; NumberT result; if constexpr (IsAbstract || IsFloatingPoint) { @@ -711,7 +710,7 @@ utils::Result ConstEval::Mul(NumberT a, NumberT b) { if (auto r = CheckedMul(a, b)) { result = r->value; } else { - AddError(OverflowErrorMessage(a, "*", b), *current_source); + AddError(OverflowErrorMessage(a, "*", b), source); return utils::Failure; } } else { @@ -730,14 +729,14 @@ utils::Result ConstEval::Mul(NumberT a, NumberT b) { } template -utils::Result ConstEval::Div(NumberT a, NumberT b) { +utils::Result ConstEval::Div(const Source& source, NumberT a, NumberT b) { NumberT result; if constexpr (IsAbstract || IsFloatingPoint) { // Check for over/underflow for abstract values if (auto r = CheckedDiv(a, b)) { result = r->value; } else { - AddError(OverflowErrorMessage(a, "/", b), *current_source); + AddError(OverflowErrorMessage(a, "/", b), source); return utils::Failure; } } else { @@ -765,16 +764,20 @@ utils::Result ConstEval::Div(NumberT a, NumberT b) { } template -utils::Result ConstEval::Dot2(NumberT a1, NumberT a2, NumberT b1, NumberT b2) { - auto r1 = Mul(a1, b1); +utils::Result ConstEval::Dot2(const Source& source, + NumberT a1, + NumberT a2, + NumberT b1, + NumberT b2) { + auto r1 = Mul(source, a1, b1); if (!r1) { return utils::Failure; } - auto r2 = Mul(a2, b2); + auto r2 = Mul(source, a2, b2); if (!r2) { return utils::Failure; } - auto r = Add(r1.Get(), r2.Get()); + auto r = Add(source, r1.Get(), r2.Get()); if (!r) { return utils::Failure; } @@ -782,29 +785,30 @@ utils::Result ConstEval::Dot2(NumberT a1, NumberT a2, NumberT b1, Numbe } template -utils::Result ConstEval::Dot3(NumberT a1, +utils::Result ConstEval::Dot3(const Source& source, + NumberT a1, NumberT a2, NumberT a3, NumberT b1, NumberT b2, NumberT b3) { - auto r1 = Mul(a1, b1); + auto r1 = Mul(source, a1, b1); if (!r1) { return utils::Failure; } - auto r2 = Mul(a2, b2); + auto r2 = Mul(source, a2, b2); if (!r2) { return utils::Failure; } - auto r3 = Mul(a3, b3); + auto r3 = Mul(source, a3, b3); if (!r3) { return utils::Failure; } - auto r = Add(r1.Get(), r2.Get()); + auto r = Add(source, r1.Get(), r2.Get()); if (!r) { return utils::Failure; } - r = Add(r.Get(), r3.Get()); + r = Add(source, r.Get(), r3.Get()); if (!r) { return utils::Failure; } @@ -812,7 +816,8 @@ utils::Result ConstEval::Dot3(NumberT a1, } template -utils::Result ConstEval::Dot4(NumberT a1, +utils::Result ConstEval::Dot4(const Source& source, + NumberT a1, NumberT a2, NumberT a3, NumberT a4, @@ -820,31 +825,31 @@ utils::Result ConstEval::Dot4(NumberT a1, NumberT b2, NumberT b3, NumberT b4) { - auto r1 = Mul(a1, b1); + auto r1 = Mul(source, a1, b1); if (!r1) { return utils::Failure; } - auto r2 = Mul(a2, b2); + auto r2 = Mul(source, a2, b2); if (!r2) { return utils::Failure; } - auto r3 = Mul(a3, b3); + auto r3 = Mul(source, a3, b3); if (!r3) { return utils::Failure; } - auto r4 = Mul(a4, b4); + auto r4 = Mul(source, a4, b4); if (!r4) { return utils::Failure; } - auto r = Add(r1.Get(), r2.Get()); + auto r = Add(source, r1.Get(), r2.Get()); if (!r) { return utils::Failure; } - r = Add(r.Get(), r3.Get()); + r = Add(source, r.Get(), r3.Get()); if (!r) { return utils::Failure; } - r = Add(r.Get(), r4.Get()); + r = Add(source, r.Get(), r4.Get()); if (!r) { return utils::Failure; } @@ -852,16 +857,20 @@ utils::Result ConstEval::Dot4(NumberT a1, } template -utils::Result ConstEval::Det2(NumberT a1, NumberT a2, NumberT b1, NumberT b2) { - auto r1 = Mul(a1, b2); +utils::Result ConstEval::Det2(const Source& source, + NumberT a1, + NumberT a2, + NumberT b1, + NumberT b2) { + auto r1 = Mul(source, a1, b2); if (!r1) { return utils::Failure; } - auto r2 = Mul(b1, a2); + auto r2 = Mul(source, b1, a2); if (!r2) { return utils::Failure; } - auto r = Sub(r1.Get(), r2.Get()); + auto r = Sub(source, r1.Get(), r2.Get()); if (!r) { return utils::Failure; } @@ -869,86 +878,86 @@ utils::Result ConstEval::Det2(NumberT a1, NumberT a2, NumberT b1, Numbe } template -utils::Result ConstEval::Clamp(NumberT e, NumberT low, NumberT high) { +utils::Result ConstEval::Clamp(const Source&, NumberT e, NumberT low, NumberT high) { return NumberT{std::min(std::max(e, low), high)}; } -auto ConstEval::ClampFunc(const sem::Type* elem_ty) { +auto ConstEval::ClampFunc(const Source& source, const sem::Type* elem_ty) { return [=](auto e, auto low, auto high) -> ImplResult { - if (auto r = Clamp(e, low, high)) { + if (auto r = Clamp(source, e, low, high)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::AddFunc(const sem::Type* elem_ty) { +auto ConstEval::AddFunc(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2) -> ImplResult { - if (auto r = Add(a1, a2)) { + if (auto r = Add(source, a1, a2)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::SubFunc(const sem::Type* elem_ty) { +auto ConstEval::SubFunc(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2) -> ImplResult { - if (auto r = Sub(a1, a2)) { + if (auto r = Sub(source, a1, a2)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::MulFunc(const sem::Type* elem_ty) { +auto ConstEval::MulFunc(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2) -> ImplResult { - if (auto r = Mul(a1, a2)) { + if (auto r = Mul(source, a1, a2)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::DivFunc(const sem::Type* elem_ty) { +auto ConstEval::DivFunc(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2) -> ImplResult { - if (auto r = Div(a1, a2)) { + if (auto r = Div(source, a1, a2)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::Dot2Func(const sem::Type* elem_ty) { +auto ConstEval::Dot2Func(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2, auto b1, auto b2) -> ImplResult { - if (auto r = Dot2(a1, a2, b1, b2)) { + if (auto r = Dot2(source, a1, a2, b1, b2)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::Dot3Func(const sem::Type* elem_ty) { +auto ConstEval::Dot3Func(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2, auto a3, auto b1, auto b2, auto b3) -> ImplResult { - if (auto r = Dot3(a1, a2, a3, b1, b2, b3)) { + if (auto r = Dot3(source, a1, a2, a3, b1, b2, b3)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::Dot4Func(const sem::Type* elem_ty) { +auto ConstEval::Dot4Func(const Source& source, const sem::Type* elem_ty) { return [=](auto a1, auto a2, auto a3, auto a4, auto b1, auto b2, auto b3, auto b4) -> ImplResult { - if (auto r = Dot4(a1, a2, a3, a4, b1, b2, b3, b4)) { + if (auto r = Dot4(source, a1, a2, a3, a4, b1, b2, b3, b4)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; }; } -auto ConstEval::Det2Func(const sem::Type* elem_ty) { +auto ConstEval::Det2Func(const Source& source, const sem::Type* elem_ty) { return [=](auto a, auto b, auto c, auto d) -> ImplResult { - if (auto r = Det2(a, b, c, d)) { + if (auto r = Det2(source, a, b, c, d)) { return CreateElement(builder, elem_ty, r.Get()); } return utils::Failure; @@ -1205,9 +1214,8 @@ ConstEval::Result ConstEval::OpNot(const sem::Type* ty, ConstEval::Result ConstEval::OpPlus(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) { - return Dispatch_fia_fiu32_f16(AddFunc(c0->Type()), c0, c1); + return Dispatch_fia_fiu32_f16(AddFunc(source, c0->Type()), c0, c1); }; return TransformBinaryElements(builder, ty, transform, args[0], args[1]); @@ -1216,9 +1224,8 @@ ConstEval::Result ConstEval::OpPlus(const sem::Type* ty, ConstEval::Result ConstEval::OpMinus(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) { - return Dispatch_fia_fiu32_f16(SubFunc(c0->Type()), c0, c1); + return Dispatch_fia_fiu32_f16(SubFunc(source, c0->Type()), c0, c1); }; return TransformBinaryElements(builder, ty, transform, args[0], args[1]); @@ -1227,9 +1234,8 @@ ConstEval::Result ConstEval::OpMinus(const sem::Type* ty, ConstEval::Result ConstEval::OpMultiply(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) { - return Dispatch_fia_fiu32_f16(MulFunc(c0->Type()), c0, c1); + return Dispatch_fia_fiu32_f16(MulFunc(source, c0->Type()), c0, c1); }; return TransformBinaryElements(builder, ty, transform, args[0], args[1]); @@ -1238,7 +1244,6 @@ ConstEval::Result ConstEval::OpMultiply(const sem::Type* ty, ConstEval::Result ConstEval::OpMultiplyMatVec(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto* mat_ty = args[0]->Type()->As(); auto* vec_ty = args[1]->Type()->As(); auto* elem_ty = vec_ty->type(); @@ -1247,29 +1252,29 @@ ConstEval::Result ConstEval::OpMultiplyMatVec(const sem::Type* ty, ImplResult result; switch (mat_ty->columns()) { case 2: - result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), // - m->Index(0)->Index(row), // - m->Index(1)->Index(row), // - v->Index(0), // + result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), // + m->Index(0)->Index(row), // + m->Index(1)->Index(row), // + v->Index(0), // v->Index(1)); break; case 3: - result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), // - m->Index(0)->Index(row), // - m->Index(1)->Index(row), // - m->Index(2)->Index(row), // - v->Index(0), // + result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), // + m->Index(0)->Index(row), // + m->Index(1)->Index(row), // + m->Index(2)->Index(row), // + v->Index(0), // v->Index(1), v->Index(2)); break; case 4: - result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), // - m->Index(0)->Index(row), // - m->Index(1)->Index(row), // - m->Index(2)->Index(row), // - m->Index(3)->Index(row), // - v->Index(0), // - v->Index(1), // - v->Index(2), // + result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), // + m->Index(0)->Index(row), // + m->Index(1)->Index(row), // + m->Index(2)->Index(row), // + m->Index(3)->Index(row), // + v->Index(0), // + v->Index(1), // + v->Index(2), // v->Index(3)); break; } @@ -1289,7 +1294,6 @@ ConstEval::Result ConstEval::OpMultiplyMatVec(const sem::Type* ty, ConstEval::Result ConstEval::OpMultiplyVecMat(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto* vec_ty = args[0]->Type()->As(); auto* mat_ty = args[1]->Type()->As(); auto* elem_ty = vec_ty->type(); @@ -1298,30 +1302,30 @@ ConstEval::Result ConstEval::OpMultiplyVecMat(const sem::Type* ty, ImplResult result; switch (mat_ty->rows()) { case 2: - result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), // - m->Index(col)->Index(0), // - m->Index(col)->Index(1), // - v->Index(0), // + result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), // + m->Index(col)->Index(0), // + m->Index(col)->Index(1), // + v->Index(0), // v->Index(1)); break; case 3: - result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), // - m->Index(col)->Index(0), // - m->Index(col)->Index(1), // + result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), // + m->Index(col)->Index(0), // + m->Index(col)->Index(1), // m->Index(col)->Index(2), v->Index(0), // v->Index(1), // v->Index(2)); break; case 4: - result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), // - m->Index(col)->Index(0), // - m->Index(col)->Index(1), // - m->Index(col)->Index(2), // - m->Index(col)->Index(3), // - v->Index(0), // - v->Index(1), // - v->Index(2), // + result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), // + m->Index(col)->Index(0), // + m->Index(col)->Index(1), // + m->Index(col)->Index(2), // + m->Index(col)->Index(3), // + v->Index(0), // + v->Index(1), // + v->Index(2), // v->Index(3)); } return result; @@ -1341,7 +1345,6 @@ ConstEval::Result ConstEval::OpMultiplyVecMat(const sem::Type* ty, ConstEval::Result ConstEval::OpMultiplyMatMat(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto* mat1 = args[0]; auto* mat2 = args[1]; auto* mat1_ty = mat1->Type()->As(); @@ -1355,30 +1358,30 @@ ConstEval::Result ConstEval::OpMultiplyMatMat(const sem::Type* ty, ImplResult result; switch (mat1_ty->columns()) { case 2: - result = Dispatch_fa_f32_f16(Dot2Func(elem_ty), // - m1e(row, 0), // - m1e(row, 1), // - m2e(0, col), // + result = Dispatch_fa_f32_f16(Dot2Func(source, elem_ty), // + m1e(row, 0), // + m1e(row, 1), // + m2e(0, col), // m2e(1, col)); break; case 3: - result = Dispatch_fa_f32_f16(Dot3Func(elem_ty), // - m1e(row, 0), // - m1e(row, 1), // - m1e(row, 2), // - m2e(0, col), // - m2e(1, col), // + result = Dispatch_fa_f32_f16(Dot3Func(source, elem_ty), // + m1e(row, 0), // + m1e(row, 1), // + m1e(row, 2), // + m2e(0, col), // + m2e(1, col), // m2e(2, col)); break; case 4: - result = Dispatch_fa_f32_f16(Dot4Func(elem_ty), // - m1e(row, 0), // - m1e(row, 1), // - m1e(row, 2), // - m1e(row, 3), // - m2e(0, col), // - m2e(1, col), // - m2e(2, col), // + result = Dispatch_fa_f32_f16(Dot4Func(source, elem_ty), // + m1e(row, 0), // + m1e(row, 1), // + m1e(row, 2), // + m1e(row, 3), // + m2e(0, col), // + m2e(1, col), // + m2e(2, col), // m2e(3, col)); break; } @@ -1406,9 +1409,8 @@ ConstEval::Result ConstEval::OpMultiplyMatMat(const sem::Type* ty, ConstEval::Result ConstEval::OpDivide(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto transform = [&](const sem::Constant* c0, const sem::Constant* c1) { - return Dispatch_fia_fiu32_f16(DivFunc(c0->Type()), c0, c1); + return Dispatch_fia_fiu32_f16(DivFunc(source, c0->Type()), c0, c1); }; return TransformBinaryElements(builder, ty, transform, args[0], args[1]); @@ -1803,10 +1805,10 @@ ConstEval::Result ConstEval::ceil(const sem::Type* ty, ConstEval::Result ConstEval::clamp(const sem::Type* ty, utils::VectorRef args, - const Source&) { + const Source& source) { auto transform = [&](const sem::Constant* c0, const sem::Constant* c1, const sem::Constant* c2) { - return Dispatch_fia_fiu32_f16(ClampFunc(c0->Type()), c0, c1, c2); + return Dispatch_fia_fiu32_f16(ClampFunc(source, c0->Type()), c0, c1, c2); }; return TransformElements(builder, ty, transform, args[0], args[1], args[2]); } @@ -1894,7 +1896,6 @@ ConstEval::Result ConstEval::countTrailingZeros(const sem::Type* ty, ConstEval::Result ConstEval::cross(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); auto* u = args[0]; auto* v = args[1]; auto* elem_ty = u->Type()->As()->type(); @@ -1918,15 +1919,15 @@ ConstEval::Result ConstEval::cross(const sem::Type* ty, auto* v1 = v->Index(1); auto* v2 = v->Index(2); - auto x = Dispatch_fa_f32_f16(Det2Func(elem_ty), u1, u2, v1, v2); + auto x = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), u1, u2, v1, v2); if (!x) { return utils::Failure; } - auto y = Dispatch_fa_f32_f16(Det2Func(elem_ty), v0, v2, u0, u2); + auto y = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), v0, v2, u0, u2); if (!y) { return utils::Failure; } - auto z = Dispatch_fa_f32_f16(Det2Func(elem_ty), u0, u1, v0, v1); + auto z = Dispatch_fa_f32_f16(Det2Func(source, elem_ty), u0, u1, v0, v1); if (!z) { return utils::Failure; } @@ -2178,9 +2179,9 @@ ConstEval::Result ConstEval::pack2x16float(const sem::Type* ty, ConstEval::Result ConstEval::pack2x16snorm(const sem::Type* ty, utils::VectorRef args, - const Source&) { + const Source& source) { auto calc = [&](f32 val) -> u32 { - auto clamped = Clamp(val, f32(-1.0f), f32(1.0f)).Get(); + auto clamped = Clamp(source, val, f32(-1.0f), f32(1.0f)).Get(); return u32(utils::Bitcast( static_cast(std::floor(0.5f + (32767.0f * clamped))))); }; @@ -2195,9 +2196,9 @@ ConstEval::Result ConstEval::pack2x16snorm(const sem::Type* ty, ConstEval::Result ConstEval::pack2x16unorm(const sem::Type* ty, utils::VectorRef args, - const Source&) { + const Source& source) { auto calc = [&](f32 val) -> u32 { - auto clamped = Clamp(val, f32(0.0f), f32(1.0f)).Get(); + auto clamped = Clamp(source, val, f32(0.0f), f32(1.0f)).Get(); return u32{std::floor(0.5f + (65535.0f * clamped))}; }; @@ -2211,9 +2212,9 @@ ConstEval::Result ConstEval::pack2x16unorm(const sem::Type* ty, ConstEval::Result ConstEval::pack4x8snorm(const sem::Type* ty, utils::VectorRef args, - const Source&) { + const Source& source) { auto calc = [&](f32 val) -> u32 { - auto clamped = Clamp(val, f32(-1.0f), f32(1.0f)).Get(); + auto clamped = Clamp(source, val, f32(-1.0f), f32(1.0f)).Get(); return u32( utils::Bitcast(static_cast(std::floor(0.5f + (127.0f * clamped))))); }; @@ -2231,9 +2232,9 @@ ConstEval::Result ConstEval::pack4x8snorm(const sem::Type* ty, ConstEval::Result ConstEval::pack4x8unorm(const sem::Type* ty, utils::VectorRef args, - const Source&) { + const Source& source) { auto calc = [&](f32 val) -> u32 { - auto clamped = Clamp(val, f32(0.0f), f32(1.0f)).Get(); + auto clamped = Clamp(source, val, f32(0.0f), f32(1.0f)).Get(); return u32{std::floor(0.5f + (255.0f * clamped))}; }; @@ -2405,8 +2406,6 @@ ConstEval::Result ConstEval::sinh(const sem::Type* ty, ConstEval::Result ConstEval::smoothstep(const sem::Type* ty, utils::VectorRef args, const Source& source) { - TINT_SCOPED_ASSIGNMENT(current_source, &source); - auto transform = [&](const sem::Constant* c0, const sem::Constant* c1, const sem::Constant* c2) { auto create = [&](auto low, auto high, auto x) -> ImplResult { @@ -2418,33 +2417,33 @@ ConstEval::Result ConstEval::smoothstep(const sem::Type* ty, }; // t = clamp((x - low) / (high - low), 0.0, 1.0) - auto x_minus_low = Sub(x, low); - auto high_minus_low = Sub(high, low); + auto x_minus_low = Sub(source, x, low); + auto high_minus_low = Sub(source, high, low); if (!x_minus_low || !high_minus_low) { return err(); } - auto div = Div(x_minus_low.Get(), high_minus_low.Get()); + auto div = Div(source, x_minus_low.Get(), high_minus_low.Get()); if (!div) { return err(); } - auto clamp = Clamp(div.Get(), NumberT(0), NumberT(1)); + auto clamp = Clamp(source, div.Get(), NumberT(0), NumberT(1)); auto t = clamp.Get(); // result = t * t * (3.0 - 2.0 * t) - auto t_times_t = Mul(t, t); - auto t_times_2 = Mul(NumberT(2), t); + auto t_times_t = Mul(source, t, t); + auto t_times_2 = Mul(source, NumberT(2), t); if (!t_times_t || !t_times_2) { return err(); } - auto three_minus_t_times_2 = Sub(NumberT(3), t_times_2.Get()); + auto three_minus_t_times_2 = Sub(source, NumberT(3), t_times_2.Get()); if (!three_minus_t_times_2) { return err(); } - auto result = Mul(t_times_t.Get(), three_minus_t_times_2.Get()); + auto result = Mul(source, t_times_t.Get(), three_minus_t_times_2.Get()); if (!result) { return err(); } diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h index e2c5ed0893..73274a1596 100644 --- a/src/tint/resolver/const_eval.h +++ b/src/tint/resolver/const_eval.h @@ -105,7 +105,7 @@ class ConstEval { /// Convert the `value` to `target_type` /// @param ty the result type /// @param value the value being converted - /// @param source the source location of the conversion + /// @param source the source location /// @return the converted value, or null if the value cannot be calculated Result Convert(const sem::Type* ty, const sem::Constant* value, const Source& source); @@ -116,7 +116,7 @@ class ConstEval { /// Type conversion /// @param ty the result type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the converted value, or null if the value cannot be calculated Result Conv(const sem::Type* ty, utils::VectorRef args, @@ -125,7 +125,7 @@ class ConstEval { /// Zero value type initializer /// @param ty the result type /// @param args the input arguments (no arguments provided) - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result Zero(const sem::Type* ty, utils::VectorRef args, @@ -134,7 +134,7 @@ class ConstEval { /// Identity value type initializer /// @param ty the result type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result Identity(const sem::Type* ty, utils::VectorRef args, @@ -143,7 +143,7 @@ class ConstEval { /// Vector splat initializer /// @param ty the vector type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result VecSplat(const sem::Type* ty, utils::VectorRef args, @@ -152,7 +152,7 @@ class ConstEval { /// Vector initializer using scalars /// @param ty the vector type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result VecInitS(const sem::Type* ty, utils::VectorRef args, @@ -161,7 +161,7 @@ class ConstEval { /// Vector initializer using a mix of scalars and smaller vectors /// @param ty the vector type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result VecInitM(const sem::Type* ty, utils::VectorRef args, @@ -170,7 +170,7 @@ class ConstEval { /// Matrix initializer using scalar values /// @param ty the matrix type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result MatInitS(const sem::Type* ty, utils::VectorRef args, @@ -179,7 +179,7 @@ class ConstEval { /// Matrix initializer using column vectors /// @param ty the matrix type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the constructed value, or null if the value cannot be calculated Result MatInitV(const sem::Type* ty, utils::VectorRef args, @@ -192,7 +192,7 @@ class ConstEval { /// Complement operator '~' /// @param ty the integer type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpComplement(const sem::Type* ty, utils::VectorRef args, @@ -201,7 +201,7 @@ class ConstEval { /// Unary minus operator '-' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpUnaryMinus(const sem::Type* ty, utils::VectorRef args, @@ -210,7 +210,7 @@ class ConstEval { /// Unary not operator '!' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpNot(const sem::Type* ty, utils::VectorRef args, @@ -223,7 +223,7 @@ class ConstEval { /// Plus operator '+' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpPlus(const sem::Type* ty, utils::VectorRef args, @@ -232,7 +232,7 @@ class ConstEval { /// Minus operator '-' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpMinus(const sem::Type* ty, utils::VectorRef args, @@ -241,7 +241,7 @@ class ConstEval { /// Multiply operator '*' for the same type on the LHS and RHS /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpMultiply(const sem::Type* ty, utils::VectorRef args, @@ -250,7 +250,7 @@ class ConstEval { /// Multiply operator '*' for matCxR * vecC /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpMultiplyMatVec(const sem::Type* ty, utils::VectorRef args, @@ -259,7 +259,7 @@ class ConstEval { /// Multiply operator '*' for vecR * matCxR /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpMultiplyVecMat(const sem::Type* ty, utils::VectorRef args, @@ -268,7 +268,7 @@ class ConstEval { /// Multiply operator '*' for matKxR * matCxK /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpMultiplyMatMat(const sem::Type* ty, utils::VectorRef args, @@ -277,7 +277,7 @@ class ConstEval { /// Divide operator '/' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpDivide(const sem::Type* ty, utils::VectorRef args, @@ -286,7 +286,7 @@ class ConstEval { /// Equality operator '==' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpEqual(const sem::Type* ty, utils::VectorRef args, @@ -295,7 +295,7 @@ class ConstEval { /// Inequality operator '!=' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpNotEqual(const sem::Type* ty, utils::VectorRef args, @@ -304,7 +304,7 @@ class ConstEval { /// Less than operator '<' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpLessThan(const sem::Type* ty, utils::VectorRef args, @@ -313,7 +313,7 @@ class ConstEval { /// Greater than operator '>' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpGreaterThan(const sem::Type* ty, utils::VectorRef args, @@ -322,7 +322,7 @@ class ConstEval { /// Less than or equal operator '<=' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpLessThanEqual(const sem::Type* ty, utils::VectorRef args, @@ -331,7 +331,7 @@ class ConstEval { /// Greater than or equal operator '>=' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpGreaterThanEqual(const sem::Type* ty, utils::VectorRef args, @@ -340,7 +340,7 @@ class ConstEval { /// Bitwise and operator '&' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpAnd(const sem::Type* ty, utils::VectorRef args, @@ -349,7 +349,7 @@ class ConstEval { /// Bitwise or operator '|' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpOr(const sem::Type* ty, utils::VectorRef args, @@ -358,7 +358,7 @@ class ConstEval { /// Bitwise xor operator '^' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpXor(const sem::Type* ty, utils::VectorRef args, @@ -367,7 +367,7 @@ class ConstEval { /// Bitwise shift left operator '<<' /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result OpShiftLeft(const sem::Type* ty, utils::VectorRef args, @@ -380,7 +380,7 @@ class ConstEval { /// abs builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result abs(const sem::Type* ty, utils::VectorRef args, @@ -389,7 +389,7 @@ class ConstEval { /// acos builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result acos(const sem::Type* ty, utils::VectorRef args, @@ -398,7 +398,7 @@ class ConstEval { /// acosh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result acosh(const sem::Type* ty, utils::VectorRef args, @@ -407,7 +407,7 @@ class ConstEval { /// all builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result all(const sem::Type* ty, utils::VectorRef args, @@ -416,7 +416,7 @@ class ConstEval { /// any builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result any(const sem::Type* ty, utils::VectorRef args, @@ -425,7 +425,7 @@ class ConstEval { /// asin builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result asin(const sem::Type* ty, utils::VectorRef args, @@ -434,7 +434,7 @@ class ConstEval { /// asinh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result asinh(const sem::Type* ty, utils::VectorRef args, @@ -443,7 +443,7 @@ class ConstEval { /// atan builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result atan(const sem::Type* ty, utils::VectorRef args, @@ -452,7 +452,7 @@ class ConstEval { /// atanh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result atanh(const sem::Type* ty, utils::VectorRef args, @@ -461,7 +461,7 @@ class ConstEval { /// atan2 builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result atan2(const sem::Type* ty, utils::VectorRef args, @@ -470,7 +470,7 @@ class ConstEval { /// ceil builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result ceil(const sem::Type* ty, utils::VectorRef args, @@ -479,7 +479,7 @@ class ConstEval { /// clamp builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result clamp(const sem::Type* ty, utils::VectorRef args, @@ -488,7 +488,7 @@ class ConstEval { /// cos builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result cos(const sem::Type* ty, utils::VectorRef args, @@ -497,7 +497,7 @@ class ConstEval { /// cosh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result cosh(const sem::Type* ty, utils::VectorRef args, @@ -506,7 +506,7 @@ class ConstEval { /// countLeadingZeros builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result countLeadingZeros(const sem::Type* ty, utils::VectorRef args, @@ -515,7 +515,7 @@ class ConstEval { /// countOneBits builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result countOneBits(const sem::Type* ty, utils::VectorRef args, @@ -524,7 +524,7 @@ class ConstEval { /// countTrailingZeros builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result countTrailingZeros(const sem::Type* ty, utils::VectorRef args, @@ -533,7 +533,7 @@ class ConstEval { /// cross builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result cross(const sem::Type* ty, utils::VectorRef args, @@ -542,7 +542,7 @@ class ConstEval { /// extractBits builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result extractBits(const sem::Type* ty, utils::VectorRef args, @@ -551,7 +551,7 @@ class ConstEval { /// firstLeadingBit builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result firstLeadingBit(const sem::Type* ty, utils::VectorRef args, @@ -560,7 +560,7 @@ class ConstEval { /// firstTrailingBit builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result firstTrailingBit(const sem::Type* ty, utils::VectorRef args, @@ -569,7 +569,7 @@ class ConstEval { /// floor builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result floor(const sem::Type* ty, utils::VectorRef args, @@ -578,7 +578,7 @@ class ConstEval { /// insertBits builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result insertBits(const sem::Type* ty, utils::VectorRef args, @@ -587,7 +587,7 @@ class ConstEval { /// max builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result max(const sem::Type* ty, utils::VectorRef args, @@ -596,7 +596,7 @@ class ConstEval { /// min builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result min(const sem::Type* ty, // NOLINT(build/include_what_you_use) -- confused by min utils::VectorRef args, @@ -605,7 +605,7 @@ class ConstEval { /// pack2x16float builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result pack2x16float(const sem::Type* ty, utils::VectorRef args, @@ -614,7 +614,7 @@ class ConstEval { /// pack2x16snorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result pack2x16snorm(const sem::Type* ty, utils::VectorRef args, @@ -623,7 +623,7 @@ class ConstEval { /// pack2x16unorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result pack2x16unorm(const sem::Type* ty, utils::VectorRef args, @@ -632,7 +632,7 @@ class ConstEval { /// pack4x8snorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result pack4x8snorm(const sem::Type* ty, utils::VectorRef args, @@ -641,7 +641,7 @@ class ConstEval { /// pack4x8unorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result pack4x8unorm(const sem::Type* ty, utils::VectorRef args, @@ -650,7 +650,7 @@ class ConstEval { /// reverseBits builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result reverseBits(const sem::Type* ty, utils::VectorRef args, @@ -659,7 +659,7 @@ class ConstEval { /// round builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result round(const sem::Type* ty, utils::VectorRef args, @@ -668,7 +668,7 @@ class ConstEval { /// saturate builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result saturate(const sem::Type* ty, utils::VectorRef args, @@ -677,7 +677,7 @@ class ConstEval { /// select builtin with single bool third arg /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result select_bool(const sem::Type* ty, utils::VectorRef args, @@ -686,7 +686,7 @@ class ConstEval { /// select builtin with vector of bool third arg /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result select_boolvec(const sem::Type* ty, utils::VectorRef args, @@ -695,7 +695,7 @@ class ConstEval { /// sign builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result sign(const sem::Type* ty, utils::VectorRef args, @@ -704,7 +704,7 @@ class ConstEval { /// sin builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result sin(const sem::Type* ty, utils::VectorRef args, @@ -713,7 +713,7 @@ class ConstEval { /// sinh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result sinh(const sem::Type* ty, utils::VectorRef args, @@ -722,7 +722,7 @@ class ConstEval { /// smoothstep builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result smoothstep(const sem::Type* ty, utils::VectorRef args, @@ -731,7 +731,7 @@ class ConstEval { /// step builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result step(const sem::Type* ty, utils::VectorRef args, @@ -740,7 +740,7 @@ class ConstEval { /// sqrt builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result sqrt(const sem::Type* ty, utils::VectorRef args, @@ -749,7 +749,7 @@ class ConstEval { /// tan builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result tan(const sem::Type* ty, utils::VectorRef args, @@ -758,7 +758,7 @@ class ConstEval { /// tanh builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result tanh(const sem::Type* ty, utils::VectorRef args, @@ -767,7 +767,7 @@ class ConstEval { /// trunc builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result trunc(const sem::Type* ty, utils::VectorRef args, @@ -776,7 +776,7 @@ class ConstEval { /// unpack2x16float builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result unpack2x16float(const sem::Type* ty, utils::VectorRef args, @@ -785,7 +785,7 @@ class ConstEval { /// unpack2x16snorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result unpack2x16snorm(const sem::Type* ty, utils::VectorRef args, @@ -794,7 +794,7 @@ class ConstEval { /// unpack2x16unorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result unpack2x16unorm(const sem::Type* ty, utils::VectorRef args, @@ -803,7 +803,7 @@ class ConstEval { /// unpack4x8snorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result unpack4x8snorm(const sem::Type* ty, utils::VectorRef args, @@ -812,7 +812,7 @@ class ConstEval { /// unpack4x8unorm builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result unpack4x8unorm(const sem::Type* ty, utils::VectorRef args, @@ -821,7 +821,7 @@ class ConstEval { /// quantizeToF16 builtin /// @param ty the expression type /// @param args the input arguments - /// @param source the source location of the conversion + /// @param source the source location /// @return the result value, or null if the value cannot be calculated Result quantizeToF16(const sem::Type* ty, utils::VectorRef args, @@ -838,43 +838,53 @@ class ConstEval { void AddNote(const std::string& msg, const Source& source) const; /// Adds two Numbers + /// @param source the source location /// @param a the lhs number /// @param b the rhs number /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Add(NumberT a, NumberT b); + utils::Result Add(const Source& source, NumberT a, NumberT b); /// Subtracts two Numbers + /// @param source the source location /// @param a the lhs number /// @param b the rhs number /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Sub(NumberT a, NumberT b); + utils::Result Sub(const Source& source, NumberT a, NumberT b); /// Multiplies two Numbers + /// @param source the source location /// @param a the lhs number /// @param b the rhs number /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Mul(NumberT a, NumberT b); + utils::Result Mul(const Source& source, NumberT a, NumberT b); /// Divides two Numbers + /// @param source the source location /// @param a the lhs number /// @param b the rhs number /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Div(NumberT a, NumberT b); + utils::Result Div(const Source& source, NumberT a, NumberT b); /// Returns the dot product of (a1,a2) with (b1,b2) + /// @param source the source location /// @param a1 component 1 of lhs vector /// @param a2 component 2 of lhs vector /// @param b1 component 1 of rhs vector /// @param b2 component 2 of rhs vector /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Dot2(NumberT a1, NumberT a2, NumberT b1, NumberT b2); + utils::Result Dot2(const Source& source, + NumberT a1, + NumberT a2, + NumberT b1, + NumberT b2); /// Returns the dot product of (a1,a2,a3) with (b1,b2,b3) + /// @param source the source location /// @param a1 component 1 of lhs vector /// @param a2 component 2 of lhs vector /// @param a3 component 3 of lhs vector @@ -883,7 +893,8 @@ class ConstEval { /// @param b3 component 3 of rhs vector /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Dot3(NumberT a1, + utils::Result Dot3(const Source& source, + NumberT a1, NumberT a2, NumberT a3, NumberT b1, @@ -891,6 +902,7 @@ class ConstEval { NumberT b3); /// Returns the dot product of (a1,b1,c1,d1) with (a2,b2,c2,d2) + /// @param source the source location /// @param a1 component 1 of lhs vector /// @param a2 component 2 of lhs vector /// @param a3 component 3 of lhs vector @@ -901,7 +913,8 @@ class ConstEval { /// @param b4 component 4 of rhs vector /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Dot4(NumberT a1, + utils::Result Dot4(const Source& source, + NumberT a1, NumberT a2, NumberT a3, NumberT a4, @@ -911,77 +924,91 @@ class ConstEval { NumberT b4); /// Returns the determinant of the 2x2 matrix [(a1, a2), (b1, b2)] + /// @param source the source location /// @param a1 component 1 of the first column vector /// @param a2 component 2 of the first column vector /// @param b1 component 1 of the second column vector /// @param b2 component 2 of the second column vector template - utils::Result Det2(NumberT a1, NumberT a2, NumberT b1, NumberT b2); + utils::Result Det2(const Source& source, + NumberT a1, + NumberT a2, + NumberT b1, + NumberT b2); /// Clamps e between low and high + /// @param source the source location /// @param e the number to clamp /// @param low the lower bound /// @param high the upper bound /// @returns the result number on success, or logs an error and returns Failure template - utils::Result Clamp(NumberT e, NumberT low, NumberT high); + utils::Result Clamp(const Source& source, NumberT e, NumberT low, NumberT high); /// Returns a callable that calls Add, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto AddFunc(const sem::Type* elem_ty); + auto AddFunc(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Sub, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto SubFunc(const sem::Type* elem_ty); + auto SubFunc(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Mul, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto MulFunc(const sem::Type* elem_ty); + auto MulFunc(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Div, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto DivFunc(const sem::Type* elem_ty); + auto DivFunc(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Dot2, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto Dot2Func(const sem::Type* elem_ty); + auto Dot2Func(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Dot3, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto Dot3Func(const sem::Type* elem_ty); + auto Dot3Func(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Dot4, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto Dot4Func(const sem::Type* elem_ty); + auto Dot4Func(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Det2, and creates a Constant with its result of type `elem_ty` /// if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto Det2Func(const sem::Type* elem_ty); + auto Det2Func(const Source& source, const sem::Type* elem_ty); /// Returns a callable that calls Clamp, and creates a Constant with its result of type /// `elem_ty` if successful, or returns Failure otherwise. + /// @param source the source location /// @param elem_ty the element type of the Constant to create on success /// @returns the callable function - auto ClampFunc(const sem::Type* elem_ty); + auto ClampFunc(const Source& source, const sem::Type* elem_ty); ProgramBuilder& builder; - const Source* current_source = nullptr; }; } // namespace tint::resolver