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 <zhaoming.jiang@intel.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-07-16 00:00:29 +00:00 committed by Dawn LUCI CQ
parent ac660c2794
commit 605b7fbadc
2 changed files with 41 additions and 68 deletions

View File

@ -502,42 +502,43 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi
auto* ret_ty = TypeOf(expr)->UnwrapRef(); auto* ret_ty = TypeOf(expr)->UnwrapRef();
auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef(); auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef();
auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef(); auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef();
fn = utils::GetOrCreate(float_modulo_funcs_, {lhs_ty, rhs_ty}, [&]() -> std::string { fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}},
TextBuffer b; [&]() -> std::string {
TINT_DEFER(helpers_.Append(b)); TextBuffer b;
TINT_DEFER(helpers_.Append(b));
auto fn_name = UniqueIdentifier("tint_float_modulo"); auto fn_name = UniqueIdentifier("tint_float_modulo");
std::vector<std::string> parameter_names; std::vector<std::string> parameter_names;
{ {
auto decl = line(&b); auto decl = line(&b);
if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone, ast::Access::kUndefined, if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone,
fn_name)) { ast::Access::kUndefined, fn_name)) {
return ""; return "";
} }
{ {
ScopedParen sp(decl); ScopedParen sp(decl);
const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); const auto* ty = TypeOf(expr->lhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined, if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone,
"lhs")) { ast::Access::kUndefined, "lhs")) {
return ""; return "";
} }
decl << ", "; decl << ", ";
ty = TypeOf(expr->rhs)->UnwrapRef(); ty = TypeOf(expr->rhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined, if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone,
"rhs")) { ast::Access::kUndefined, "rhs")) {
return ""; return "";
} }
} }
decl << " {"; decl << " {";
} }
{ {
ScopedIndent si(&b); ScopedIndent si(&b);
line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; line(&b) << "return (lhs - rhs * trunc(lhs / rhs));";
} }
line(&b) << "}"; line(&b) << "}";
line(&b); line(&b);
return fn_name; return fn_name;
}); });
if (fn.empty()) { if (fn.empty()) {
return false; return false;

View File

@ -16,6 +16,7 @@
#define SRC_TINT_WRITER_GLSL_GENERATOR_IMPL_H_ #define SRC_TINT_WRITER_GLSL_GENERATOR_IMPL_H_
#include <string> #include <string>
#include <tuple>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <utility> #include <utility>
@ -478,36 +479,9 @@ class GeneratorImpl : public TextGenerator {
std::string var_name; std::string var_name;
}; };
struct DMAIntrinsic { /// The map key for two semantic types.
transform::DecomposeMemoryAccess::Intrinsic::Op op; using BinaryOperandType =
transform::DecomposeMemoryAccess::Intrinsic::DataType type; utils::UnorderedKeyWrapper<std::tuple<const sem::Type*, const sem::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);
}
};
};
/// CallBuiltinHelper will call the builtin helper function, creating it /// CallBuiltinHelper will call the builtin helper function, creating it
/// if it hasn't been built already. If the builtin needs to be built then /// 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 TextBuffer helpers_; // Helper functions emitted at the top of the output
std::function<bool()> emit_continuing_; std::function<bool()> emit_continuing_;
std::unordered_map<DMAIntrinsic, std::string, DMAIntrinsic::Hasher> dma_intrinsics_;
std::unordered_map<const sem::Builtin*, std::string> builtins_; std::unordered_map<const sem::Builtin*, std::string> builtins_;
std::unordered_map<const sem::Vector*, std::string> dynamic_vector_write_; std::unordered_map<const sem::Vector*, std::string> dynamic_vector_write_;
std::unordered_map<const sem::Vector*, std::string> int_dot_funcs_; std::unordered_map<const sem::Vector*, std::string> int_dot_funcs_;
std::unordered_map<BinaryOperandType, std::string, BinaryOperandType::Hasher> std::unordered_map<BinaryOperandType, std::string> float_modulo_funcs_;
float_modulo_funcs_;
std::unordered_set<const sem::Struct*> emitted_structs_; std::unordered_set<const sem::Struct*> emitted_structs_;
bool requires_oes_sample_variables_ = false; bool requires_oes_sample_variables_ = false;
bool requires_default_precision_qualifier_ = false; bool requires_default_precision_qualifier_ = false;