All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bufferArrayRegistry.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
25 #define PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 
31 #include "pxr/imaging/hd/bufferArrayRange.h"
32 #include "pxr/imaging/hd/bufferSpec.h"
33 #include "pxr/imaging/hd/perfLog.h"
34 #include "pxr/imaging/hd/strategyBase.h"
35 
36 #include "pxr/imaging/hf/perfLog.h"
37 
38 #include "pxr/base/vt/dictionary.h"
39 #include "pxr/base/tf/token.h"
40 
41 #include <tbb/concurrent_unordered_map.h>
42 
43 #include <condition_variable>
44 #include <memory>
45 #include <mutex>
46 
47 PXR_NAMESPACE_OPEN_SCOPE
48 
49 
50 using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
51 
57 {
58 public:
59  HF_MALLOC_TAG_NEW("new HdBufferArrayRegistry");
60 
61  HD_API
63  ~HdBufferArrayRegistry() = default;
64 
67  HD_API
68  HdBufferArrayRangeSharedPtr AllocateRange(
69  HdAggregationStrategy *strategy,
70  TfToken const &role,
71  HdBufferSpecVector const &bufferSpecs,
72  HdBufferArrayUsageHint usageHint);
73 
75  HD_API
76  void ReallocateAll(HdAggregationStrategy *strategy);
77 
79  HD_API
80  void GarbageCollect();
81 
85  HD_API
87  VtDictionary &result) const;
88 
90  HD_API
91  friend std::ostream &operator <<(std::ostream &out,
92  const HdBufferArrayRegistry& self);
93 
94 private:
95 
96  HdBufferArrayRegistry(const HdBufferArrayRegistry &) = delete;
97  HdBufferArrayRegistry &operator=(const HdBufferArrayRegistry &) = delete;
98 
99  typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
100 
110  struct _Entry
111  {
112  _HdBufferArraySharedPtrList bufferArrays;
113  std::mutex lock;
114  std::condition_variable emptyCondition;
115 
116  // Default / Copy constructors needed for std::make_pair.
117  // as the version of TBB doesn't have emplace() yet.
118  _Entry() {}
119  _Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
120  };
121 
122 
126  class _EntryIsNotEmpty
127  {
128  public:
129  _EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
130 
131  bool operator()() {
132  return (!(_entry.bufferArrays.empty()));
133  }
134 
135  private:
136  const _Entry &_entry;
137  };
138 
139  typedef tbb::concurrent_unordered_map< HdAggregationStrategy::AggregationId, _Entry> _BufferArrayIndex;
140 
141  _BufferArrayIndex _entries;
142 
150  void _InsertNewBufferArray(_Entry &entry,
151  const HdBufferArraySharedPtr &expectedTail,
152  HdAggregationStrategy *strategy,
153  TfToken const &role,
154  HdBufferSpecVector const &bufferSpecs,
155  HdBufferArrayUsageHint usageHint);
156 };
157 
158 
159 PXR_NAMESPACE_CLOSE_SCOPE
160 
161 #endif // PXR_IMAGING_HD_BUFFER_ARRAY_REGISTRY_H
The union provides a set of flags that provide hints to the memory management system about the proper...
Definition: bufferArray.h:70
HD_API void ReallocateAll(HdAggregationStrategy *strategy)
Triggers reallocation on all buffers managed by the registry.
Aggregation strategy base class.
Definition: strategyBase.h:48
A map with string keys and VtValue values.
Definition: dictionary.h:63
Manages the pool of buffer arrays.
HD_API void GarbageCollect()
Frees up buffers that no longer contain any allocated ranges.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
HD_API HdBufferArrayRangeSharedPtr AllocateRange(HdAggregationStrategy *strategy, TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
Allocate new buffer array range using strategy Thread-Safe.
HD_API size_t GetResourceAllocation(HdAggregationStrategy *strategy, VtDictionary &result) const
Generate a report on resources consumed by the managed buffer array.
HD_API friend std::ostream & operator<<(std::ostream &out, const HdBufferArrayRegistry &self)
Debug dump.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...