Skip to content

Commit f5fad46

Browse files
committed
TrigBufCache: allow combo to be found by smallTrig()
1 parent 41758ef commit f5fad46

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/TrigBufCache.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ TrigBufCache::~TrigBufCache() = default;
180180
TrigPtr TrigBufCache::smallTrig(u32 W, u32 nW) {
181181
lock_guard lock{mut};
182182
auto& m = small;
183-
decay_t<decltype(m)>::key_type key{W, nW};
183+
decay_t<decltype(m)>::key_type key{W, nW, 0, 0};
184184

185185
TrigPtr p{};
186186
auto it = m.find(key);
@@ -198,15 +198,18 @@ TrigPtr TrigBufCache::smallTrigCombo(u32 width, u32 middle, u32 W, u32 nW) {
198198
#endif
199199

200200
lock_guard lock{mut};
201-
auto& m = combo;
202-
decay_t<decltype(m)>::key_type key{width, middle, W, nW};
201+
auto& m = small;
202+
decay_t<decltype(m)>::key_type key1{W, nW, width, middle};
203+
// We write the "combo" under two keys, so it can also be retrieved as non-combo by smallTrig()
204+
decay_t<decltype(m)>::key_type key2{W, nW, 0, 0};
203205

204206
TrigPtr p{};
205-
auto it = m.find(key);
207+
auto it = m.find(key1);
206208
if (it == m.end() || !(p = it->second.lock())) {
207209
p = make_shared<TrigBuf>(context, genSmallTrigCombo(width, middle, W, nW));
208-
m[key] = p;
209-
smallComboCache.add(p);
210+
m[key1] = p;
211+
m[key2] = p;
212+
smallCache.add(p);
210213
}
211214
return p;
212215
}

src/TrigBufCache.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ class TrigBufCache {
2727
const Context* context;
2828
std::mutex mut;
2929

30-
std::map<tuple<u32, u32>, TrigPtr::weak_type> small;
30+
std::map<tuple<u32, u32, u32, u32>, TrigPtr::weak_type> small;
3131
std::map<tuple<u32, u32, u32>, TrigPtr::weak_type> middle;
32-
std::map<tuple<u32, u32, u32, u32>, TrigPtr::weak_type> combo;
3332

3433
// The shared-pointers below keep the most recent set of buffers alive even without any Gpu instance
3534
// referencing them. This allows a single worker to delete & re-create the Gpu instance and still reuse the buffers.
3635
StrongCache smallCache{4};
3736
StrongCache middleCache{4};
38-
StrongCache smallComboCache{2};
3937

4038
public:
4139
TrigBufCache(const Context* context) :

0 commit comments

Comments
 (0)