Fix declarations hashing

This commit is contained in:
ReinUsesLisp 2019-09-09 16:46:46 -03:00
parent ae7c664016
commit bb6a3421d2
2 changed files with 19 additions and 1 deletions

View file

@ -920,6 +920,15 @@ public:
Id OpImageQuerySamples(Id result_type, Id image);
private:
struct HashOp {
std::size_t operator()(const std::unique_ptr<Op>& op) const noexcept;
};
struct EqualOp {
bool operator()(const std::unique_ptr<Op>& lhs, const std::unique_ptr<Op>& rhs) const
noexcept;
};
Id AddCode(std::unique_ptr<Op> op);
Id AddCode(spv::Op opcode, std::optional<std::uint32_t> id = {});
@ -945,7 +954,7 @@ private:
std::vector<std::unique_ptr<Op>> execution_modes;
std::vector<std::unique_ptr<Op>> debug;
std::vector<std::unique_ptr<Op>> annotations;
std::unordered_set<std::unique_ptr<Op>> declarations;
std::unordered_set<std::unique_ptr<Op>, HashOp, EqualOp> declarations;
std::vector<Id> sorted_declarations;
std::vector<Id> global_variables;

View file

@ -20,6 +20,15 @@ static void WriteSet(Stream& stream, const T& set) {
}
}
std::size_t Module::HashOp::operator()(const std::unique_ptr<Op>& op) const noexcept {
return op->Hash();
}
bool Module::EqualOp::operator()(const std::unique_ptr<Op>& lhs,
const std::unique_ptr<Op>& rhs) const noexcept {
return *lhs == *rhs;
}
Module::Module(u32 version) : version(version) {}
Module::~Module() = default;