Loading...
Searching...
No Matches
bufferArrayRegistry.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_ST_BUFFER_ARRAY_REGISTRY_H
8#define PXR_IMAGING_HD_ST_BUFFER_ARRAY_REGISTRY_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/strategyBase.h"
13
14#include "pxr/imaging/hd/bufferArrayRange.h"
15#include "pxr/imaging/hd/bufferSpec.h"
16#include "pxr/imaging/hd/perfLog.h"
17
18#include "pxr/imaging/hf/perfLog.h"
19
21#include "pxr/base/tf/token.h"
22
23#include <tbb/concurrent_unordered_map.h>
24
25#include <condition_variable>
26#include <memory>
27#include <mutex>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
31
32using HdBufferArraySharedPtr = std::shared_ptr<class HdBufferArray>;
33
39{
40public:
41 HF_MALLOC_TAG_NEW("new HdStBufferArrayRegistry");
42
43 HDST_API
45 ~HdStBufferArrayRegistry() = default;
46
49 HDST_API
50 HdBufferArrayRangeSharedPtr AllocateRange(
52 TfToken const &role,
53 HdBufferSpecVector const &bufferSpecs,
54 HdBufferArrayUsageHint usageHint);
55
57 HDST_API
59
61 HDST_API
63
67 HDST_API
69 VtDictionary &result) const;
70
72 HDST_API
73 friend std::ostream &operator <<(std::ostream &out,
74 const HdStBufferArrayRegistry& self);
75
76private:
77
79 HdStBufferArrayRegistry &operator=(const HdStBufferArrayRegistry &)=delete;
80
81 typedef std::list<HdBufferArraySharedPtr> _HdBufferArraySharedPtrList;
82
92 struct _Entry
93 {
94 _HdBufferArraySharedPtrList bufferArrays;
95 std::mutex lock;
96 std::condition_variable emptyCondition;
97
98 // Default / Copy constructors needed for std::make_pair.
99 // as the version of TBB doesn't have emplace() yet.
100 _Entry() {}
101 _Entry(const _Entry &other) { TF_VERIFY(bufferArrays.empty()); }
102 };
103
104
108 class _EntryIsNotEmpty
109 {
110 public:
111 _EntryIsNotEmpty(const _Entry &entry) : _entry(entry) {}
112
113 bool operator()() {
114 return (!(_entry.bufferArrays.empty()));
115 }
116
117 private:
118 const _Entry &_entry;
119 };
120
121 using _BufferArrayIndex = tbb::concurrent_unordered_map<
123 _BufferArrayIndex _entries;
124
132 void _InsertNewBufferArray(_Entry &entry,
133 const HdBufferArraySharedPtr &expectedTail,
134 HdStAggregationStrategy *strategy,
135 TfToken const &role,
136 HdBufferSpecVector const &bufferSpecs,
137 HdBufferArrayUsageHint usageHint);
138};
139
140
141PXR_NAMESPACE_CLOSE_SCOPE
142
143#endif // PXR_IMAGING_HD_ST_BUFFER_ARRAY_REGISTRY_H
Aggregation strategy base class.
Definition: strategyBase.h:31
size_t AggregationId
Aggregation ID.
Definition: strategyBase.h:34
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:71
A map with string keys and VtValue values.
Definition: dictionary.h:43
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:266
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...