Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/gpu/vk/GrVkResource.h

Issue 2194823003: Use HashSet instead of Dynamic hash for tracking vulkan resources (Closed) Base URL: https://skia.googlesource.com/skia.git@mergeProgDesc
Patch Set: review cleanup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrVkResource_DEFINED 8 #ifndef GrVkResource_DEFINED
9 #define GrVkResource_DEFINED 9 #define GrVkResource_DEFINED
10 10
11 #include "SkAtomics.h" 11 #include "SkAtomics.h"
12 #include "SkTDynamicHash.h"
13 #include "SkRandom.h" 12 #include "SkRandom.h"
13 #include "SkTHash.h"
14 14
15 class GrVkGpu; 15 class GrVkGpu;
16 16
17 // uncomment to enable tracing of resource refs 17 // uncomment to enable tracing of resource refs
18 #ifdef SK_DEBUG 18 #ifdef SK_DEBUG
19 #define SK_TRACE_VK_RESOURCES 19 #define SK_TRACE_VK_RESOURCES
20 #endif 20 #endif
21 21
22 /** \class GrVkResource 22 /** \class GrVkResource
23 23
24 GrVkResource is the base class for Vulkan resources that may be shared by mult iple 24 GrVkResource is the base class for Vulkan resources that may be shared by mult iple
25 objects. When an existing owner wants to share a reference, it calls ref(). 25 objects. When an existing owner wants to share a reference, it calls ref().
26 When an owner wants to release its reference, it calls unref(). When the 26 When an owner wants to release its reference, it calls unref(). When the
27 shared object's reference count goes to zero as the result of an unref() 27 shared object's reference count goes to zero as the result of an unref()
28 call, its (virtual) destructor is called. It is an error for the 28 call, its (virtual) destructor is called. It is an error for the
29 destructor to be called explicitly (or via the object going out of scope on 29 destructor to be called explicitly (or via the object going out of scope on
30 the stack or calling delete) if getRefCnt() > 1. 30 the stack or calling delete) if getRefCnt() > 1.
31 31
32 This is nearly identical to SkRefCntBase. The exceptions are that unref() 32 This is nearly identical to SkRefCntBase. The exceptions are that unref()
33 takes a GrVkGpu, and any derived classes must implement freeGPUData() and 33 takes a GrVkGpu, and any derived classes must implement freeGPUData() and
34 possibly abandonSubResources(). 34 possibly abandonSubResources().
35 */ 35 */
36 36
37 class GrVkResource : SkNoncopyable { 37 class GrVkResource : SkNoncopyable {
38 public: 38 public:
39 // Simple refCount tracing, to ensure that everything ref'ed is unref'ed. 39 // Simple refCount tracing, to ensure that everything ref'ed is unref'ed.
40 #ifdef SK_TRACE_VK_RESOURCES 40 #ifdef SK_TRACE_VK_RESOURCES
41 static const uint32_t& GetKey(const GrVkResource& r) { return r.fKey; } 41 struct Hash {
42 static uint32_t Hash(const uint32_t& k) { return k; } 42 uint32_t operator()(const GrVkResource* const& r) const {
43 SkASSERT(r);
44 return r->fKey;
45 }
46 };
43 47
44 class Trace { 48 class Trace {
45 public: 49 public:
46 ~Trace() { 50 ~Trace() {
47 if (fHash.count()) { 51 fHashSet.foreach([](const GrVkResource* r) {
48 SkTDynamicHash<GrVkResource, uint32_t>::Iter iter(&fHash); 52 r->dumpInfo();
49 for (; !iter.done(); ++iter) { 53 });
50 (*iter).dumpInfo(); 54 SkASSERT(0 == fHashSet.count());
51 }
52 }
53 SkASSERT(0 == fHash.count());
54 } 55 }
55 void add(GrVkResource* r) { fHash.add(r); } 56 void add(const GrVkResource* r) { fHashSet.add(r); }
56 void remove(const GrVkResource* r) { fHash.remove(GetKey(*r)); } 57 void remove(const GrVkResource* r) { fHashSet.remove(r); }
57 58
58 private: 59 private:
59 SkTDynamicHash<GrVkResource, uint32_t> fHash; 60 SkTHashSet<const GrVkResource*, GrVkResource::Hash> fHashSet;
60 }; 61 };
61 static Trace fTrace; 62 static Trace fTrace;
62 63
63 static uint32_t fKeyCounter; 64 static uint32_t fKeyCounter;
64 #endif 65 #endif
65 66
66 /** Default construct, initializing the reference count to 1. 67 /** Default construct, initializing the reference count to 1.
67 */ 68 */
68 GrVkResource() : fRefCnt(1) { 69 GrVkResource() : fRefCnt(1) {
69 #ifdef SK_TRACE_VK_RESOURCES 70 #ifdef SK_TRACE_VK_RESOURCES
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } else { 204 } else {
204 this->unref(gpu); 205 this->unref(gpu);
205 } 206 }
206 } 207 }
207 208
208 private: 209 private:
209 virtual void onRecycle(GrVkGpu* gpu) const = 0; 210 virtual void onRecycle(GrVkGpu* gpu) const = 0;
210 }; 211 };
211 212
212 #endif 213 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698