Loading...
Searching...
No Matches
renderBufferPool.h
1//
2// Copyright 2025 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_RENDER_BUFFER_POOL_H
8#define PXR_IMAGING_HD_ST_RENDER_BUFFER_POOL_H
9
10#include "pxr/pxr.h"
11#include "pxr/base/gf/vec3i.h"
12#include "pxr/imaging/hdSt/api.h"
13#include "pxr/imaging/hdSt/renderBuffer.h"
14#include "pxr/imaging/hgi/hgi.h"
15#include "pxr/imaging/hgi/enums.h"
16#include "pxr/imaging/hgi/texture.h"
17
18#include <deque>
19#include <map>
20#include <unordered_map>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
25
34{
35public:
37 std::shared_ptr<HdStRenderBuffer> buffer,
39 const SdfPath& graphPath,
40 bool isDepth,
41 uint16_t idx);
43
44 HdStRenderBuffer* GetBuffer() const { return _buffer.get(); }
45private:
46 std::shared_ptr<HdStRenderBuffer> _buffer;
48 const SdfPath _graphPath;
49 bool _isDepth;
50 uint16_t _idx;
51
52 HdStPooledRenderBuffer & operator=(const HdStPooledRenderBuffer&) = delete;
54};
55
56using HdStPooledRenderBufferUniquePtr = std::unique_ptr<HdStPooledRenderBuffer>;
57
64{
65public:
66 // Allocate a RenderBuffer for usage during the current render graph
67 [[nodiscard]]
68 HDST_API
69 HdStPooledRenderBufferUniquePtr Allocate(
70 HdStResourceRegistry* registry,
71 const SdfPath& graphPath,
72 HdFormat fmt,
73 GfVec2i dims,
74 bool multiSampled,
75 bool depth);
76
77 HDST_API
78 void Free(
79 HdFormat fmt,
80 GfVec2i dims,
81 bool multiSampled,
82 bool depth,
83 const SdfPath& graphPath,
84 uint16_t idx);
85
86 // Frees allocations that are no longer in use by any render graphs
87 HDST_API
88 void Commit();
89private:
90 struct _PooledRenderBufferDesc
91 {
92 HdFormat fmt : 6;
93 bool multiSampled : 1;
94 bool depth : 1;
95 GfVec2i dims;
96 bool operator==(const _PooledRenderBufferDesc &other) const
97 {
98 return fmt == other.fmt &&
99 dims == other.dims &&
100 multiSampled == other.multiSampled &&
101 depth == other.depth;
102 }
103 struct HashFunctor
104 {
105 size_t operator()(_PooledRenderBufferDesc const& desc) const
106 {
107 return ((desc.multiSampled | (desc.depth << 2)
108 | (desc.fmt << 3))
109 ^ (desc.dims[0] & 0xFFFF))
110 | ((size_t)(desc.dims[1] & 0xFFFF) << 32);
111 }
112 };
113 };
114
115 using _HdStRenderBufferVec =
116 std::vector<std::shared_ptr<HdStRenderBuffer>>;
117
118 class _AllocationTracker
119 {
120 public:
121 uint16_t Allocate();
122 void Free(uint16_t index);
123 private:
124 uint16_t max = 0;
125 std::deque<uint16_t> freeList;
126 };
127
128 struct _HdStRenderBufferPoolEntry
129 {
130 std::map<const SdfPath, _AllocationTracker> allocs;
131 _HdStRenderBufferVec buffers;
132 };
133
134 std::unordered_map<_PooledRenderBufferDesc,
135 _HdStRenderBufferPoolEntry,
136 _PooledRenderBufferDesc::HashFunctor> _pooledRenderBuffers;
137};
138
139PXR_NAMESPACE_CLOSE_SCOPE
140
141#endif
Basic type for a vector of 2 int components.
Definition: vec2i.h:44
Represents a Render Buffer that may be re-used between render graphs Client code has exclusive access...
System for re-using HdStRenderBuffers between tasks in different graphs that regenerate data per-fram...
A central registry of all GPU resources.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274