Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Shader goodies: async. compilation + caching (ubershader approach) #53411

Merged
merged 5 commits into from
Nov 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid the need for copy assignment in HashMap key/data types
  • Loading branch information
RandomShaper committed Nov 8, 2021
commit 5eb80bb1a304ef17ed84f8a3cfa59dd0fe32a0ed
18 changes: 11 additions & 7 deletions core/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class HashMap {
TKey key;
TData data;

Pair() {}
Pair(const TKey &p_key) :
key(p_key),
data() {}
Pair(const TKey &p_key, const TData &p_data) :
key(p_key),
data(p_data) {
Expand Down Expand Up @@ -90,6 +92,12 @@ class HashMap {
const TData &value() const {
return pair.value();
}

Element(const TKey &p_key) :
pair(p_key) {}
Element(const Element &p_other) :
hash(p_other.hash),
pair(p_other.pair.key, p_other.pair.data) {}
};

private:
Expand Down Expand Up @@ -192,14 +200,12 @@ class HashMap {

Element *create_element(const TKey &p_key) {
/* if element doesn't exist, create it */
Element *e = memnew(Element);
Element *e = memnew(Element(p_key));
ERR_FAIL_COND_V_MSG(!e, nullptr, "Out of memory.");
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
e->next = hash_table[index];
e->hash = hash;
e->pair.key = p_key;
e->pair.data = TData();

hash_table[index] = e;
elements++;
Expand Down Expand Up @@ -228,9 +234,7 @@ class HashMap {
const Element *e = p_t.hash_table[i];

while (e) {
Element *le = memnew(Element); /* local element */

*le = *e; /* copy data */
Element *le = memnew(Element(*e)); /* local element */

/* add to list and reassign pointers */
le->next = hash_table[i];
Expand Down