Loading...
Searching...
No Matches
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_ST_BUFFER_ARRAY_REGISTRY_H
25#define PXR_IMAGING_HD_ST_BUFFER_ARRAY_REGISTRY_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hdSt/strategyBase.h"
30
31#include "pxr/imaging/hd/bufferArrayRange.h"
32#include "pxr/imaging/hd/bufferSpec.h"
33#include "pxr/imaging/hd/perfLog.h"
34
35#include "pxr/imaging/hf/perfLog.h"
36
38#include "pxr/base/tf/token.h"
39
40#include <tbb/concurrent_unordered_map.h>
41
42#include <condition_variable>
43#include <memory>
44#include <mutex>
45
46PXR_NAMESPACE_OPEN_SCOPE
47
48
49using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
50
56{
57public:
58 HF_MALLOC_TAG_NEW("new HdStBufferArrayRegistry");
59
60 HDST_API
62 ~HdStBufferArrayRegistry() = default;
63
66 HDST_API
67 HdBufferArrayRangeSharedPtr AllocateRange(
69 TfToken const &role,
70 HdBufferSpecVector const &bufferSpecs,
71 HdBufferArrayUsageHint usageHint);
72
74 HDST_API
76
78 HDST_API
80
84 HDST_API
86 VtDictionary &result) const;
87
89 HDST_API
90 friend std::ostream &operator <<(std::ostream &out,
91 const HdStBufferArrayRegistry& self);
92
93private:
94
96 HdStBufferArrayRegistry &operator=(const HdStBufferArrayRegistry &)=delete;
97
98 typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
99
109 struct _Entry
110 {
111 _HdBufferArraySharedPtrList bufferArrays;
112 std::mutex lock;
113 std::condition_variable emptyCondition;
114
115 // Default / Copy constructors needed for std::make_pair.
116 // as the version of TBB doesn't have emplace() yet.
117 _Entry() {}
118 _Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
119 };
120
121
125 class _EntryIsNotEmpty
126 {
127 public:
128 _EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
129
130 bool operator()() {
131 return (!(_entry.bufferArrays.empty()));
132 }
133
134 private:
135 const _Entry &_entry;
136 };
137
138 using _BufferArrayIndex = tbb::concurrent_unordered_map<
140 _BufferArrayIndex _entries;
141
149 void _InsertNewBufferArray(_Entry &entry,
150 const HdBufferArraySharedPtr &expectedTail,
151 HdStAggregationStrategy *strategy,
152 TfToken const &role,
153 HdBufferSpecVector const &bufferSpecs,
154 HdBufferArrayUsageHint usageHint);
155};
156
157
158PXR_NAMESPACE_CLOSE_SCOPE
159
160#endif // PXR_IMAGING_HD_ST_BUFFER_ARRAY_REGISTRY_H
Aggregation strategy base class.
Definition: strategyBase.h:48
size_t AggregationId
Aggregation ID.
Definition: strategyBase.h:51
Manages the pool of buffer arrays.
HDST_API void GarbageCollect()
Frees up buffers that no longer contain any allocated ranges.
HDST_API friend std::ostream & operator<<(std::ostream &out, const HdStBufferArrayRegistry &self)
Debug dump.
HDST_API HdBufferArrayRangeSharedPtr AllocateRange(HdStAggregationStrategy *strategy, TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
Allocate new buffer array range using strategy Thread-Safe.
HDST_API size_t GetResourceAllocation(HdStAggregationStrategy *strategy, VtDictionary &result) const
Generate a report on resources consumed by the managed buffer array.
HDST_API void ReallocateAll(HdStAggregationStrategy *strategy)
Triggers reallocation on all buffers managed by the registry.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
A map with string keys and VtValue values.
Definition: dictionary.h:60
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...