From 605b7fbadcc85f67ea2253bcd903784d9f602534 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 16 Jul 2022 00:00:29 +0000 Subject: [PATCH] tint/writer/glsl: Simplify map keys with UnorderedKeyWrapper And remove the unused DMAIntrinsic struct / field. Change-Id: I641c066a7bc22dc903592b3928705be56d83392c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96145 Reviewed-by: Zhaoming Jiang Commit-Queue: Ben Clayton Reviewed-by: Antonio Maiorano --- src/tint/writer/glsl/generator_impl.cc | 71 +++++++++++++------------- src/tint/writer/glsl/generator_impl.h | 38 ++------------ 2 files changed, 41 insertions(+), 68 deletions(-) diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index d28f3f491a..88eec26319 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -502,42 +502,43 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi auto* ret_ty = TypeOf(expr)->UnwrapRef(); auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef(); auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef(); - fn = utils::GetOrCreate(float_modulo_funcs_, {lhs_ty, rhs_ty}, [&]() -> std::string { - TextBuffer b; - TINT_DEFER(helpers_.Append(b)); + fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, + [&]() -> std::string { + TextBuffer b; + TINT_DEFER(helpers_.Append(b)); - auto fn_name = UniqueIdentifier("tint_float_modulo"); - std::vector parameter_names; - { - auto decl = line(&b); - if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone, ast::Access::kUndefined, - fn_name)) { - return ""; - } - { - ScopedParen sp(decl); - const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined, - "lhs")) { - return ""; - } - decl << ", "; - ty = TypeOf(expr->rhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined, - "rhs")) { - return ""; - } - } - decl << " {"; - } - { - ScopedIndent si(&b); - line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; - } - line(&b) << "}"; - line(&b); - return fn_name; - }); + auto fn_name = UniqueIdentifier("tint_float_modulo"); + std::vector parameter_names; + { + auto decl = line(&b); + if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone, + ast::Access::kUndefined, fn_name)) { + return ""; + } + { + ScopedParen sp(decl); + const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); + if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, + ast::Access::kUndefined, "lhs")) { + return ""; + } + decl << ", "; + ty = TypeOf(expr->rhs)->UnwrapRef(); + if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, + ast::Access::kUndefined, "rhs")) { + return ""; + } + } + decl << " {"; + } + { + ScopedIndent si(&b); + line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; + } + line(&b) << "}"; + line(&b); + return fn_name; + }); if (fn.empty()) { return false; diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index 37352c55a7..811dd9124b 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -16,6 +16,7 @@ #define SRC_TINT_WRITER_GLSL_GENERATOR_IMPL_H_ #include +#include #include #include #include @@ -478,36 +479,9 @@ class GeneratorImpl : public TextGenerator { std::string var_name; }; - struct DMAIntrinsic { - transform::DecomposeMemoryAccess::Intrinsic::Op op; - transform::DecomposeMemoryAccess::Intrinsic::DataType type; - bool operator==(const DMAIntrinsic& rhs) const { return op == rhs.op && type == rhs.type; } - /// Hasher is a std::hash function for DMAIntrinsic - struct Hasher { - /// @param i the DMAIntrinsic to hash - /// @returns the hash of `i` - inline std::size_t operator()(const DMAIntrinsic& i) const { - return utils::Hash(i.op, i.type); - } - }; - }; - - /// The structure holding both type of two operands for a binary operator. - struct BinaryOperandType { - const sem::Type* lhs_type; - const sem::Type* rhs_type; - bool operator==(const BinaryOperandType& rhs) const { - return lhs_type == rhs.lhs_type && rhs_type == rhs.rhs_type; - } - /// Hasher is a std::hash function for BinaryOperandType - struct Hasher { - /// @param i the BinaryOperandType to hash - /// @returns the hash of `i` - inline std::size_t operator()(const BinaryOperandType& i) const { - return utils::Hash(i.lhs_type, i.rhs_type); - } - }; - }; + /// The map key for two semantic types. + using BinaryOperandType = + utils::UnorderedKeyWrapper>; /// CallBuiltinHelper will call the builtin helper function, creating it /// if it hasn't been built already. If the builtin needs to be built then @@ -535,12 +509,10 @@ class GeneratorImpl : public TextGenerator { TextBuffer helpers_; // Helper functions emitted at the top of the output std::function emit_continuing_; - std::unordered_map dma_intrinsics_; std::unordered_map builtins_; std::unordered_map dynamic_vector_write_; std::unordered_map int_dot_funcs_; - std::unordered_map - float_modulo_funcs_; + std::unordered_map float_modulo_funcs_; std::unordered_set emitted_structs_; bool requires_oes_sample_variables_ = false; bool requires_default_precision_qualifier_ = false;