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 HD_BUFFER_ARRAY_REGISTRY_H
25 #define 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 <boost/noncopyable.hpp>
42 #include <boost/shared_ptr.hpp>
43 #include <tbb/concurrent_unordered_map.h>
44 
45 #include <condition_variable>
46 #include <mutex>
47 
48 PXR_NAMESPACE_OPEN_SCOPE
49 
50 
51 typedef boost::shared_ptr<class HdBufferArray> HdBufferArraySharedPtr;
52 
57 class HdBufferArrayRegistry : public boost::noncopyable {
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  typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
96 
106  struct _Entry
107  {
108  _HdBufferArraySharedPtrList bufferArrays;
109  std::mutex lock;
110  std::condition_variable emptyCondition;
111 
112  // Default / Copy constructors needed for std::make_pair.
113  // as the version of TBB doesn't have emplace() yet.
114  _Entry() {}
115  _Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
116  };
117 
118 
122  class _EntryIsNotEmpty
123  {
124  public:
125  _EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
126 
127  bool operator()() {
128  return (!(_entry.bufferArrays.empty()));
129  }
130 
131  private:
132  const _Entry &_entry;
133  };
134 
135  typedef tbb::concurrent_unordered_map< HdAggregationStrategy::AggregationId, _Entry> _BufferArrayIndex;
136 
137  _BufferArrayIndex _entries;
138 
146  void _InsertNewBufferArray(_Entry &entry,
147  const HdBufferArraySharedPtr &expectedTail,
148  HdAggregationStrategy *strategy,
149  TfToken const &role,
150  HdBufferSpecVector const &bufferSpecs,
151  HdBufferArrayUsageHint usageHint);
152 };
153 
154 
155 PXR_NAMESPACE_CLOSE_SCOPE
156 
157 #endif // 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:74
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:61
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:89
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:289
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.