renderBuffer.h
1 //
2 // Copyright 2018 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_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/renderBuffer.h"
29 
30 PXR_NAMESPACE_OPEN_SCOPE
31 
32 class HdEmbreeRenderBuffer : public HdRenderBuffer
33 {
34 public:
35  HdEmbreeRenderBuffer(SdfPath const& id);
36  ~HdEmbreeRenderBuffer() override;
37 
44  void Sync(HdSceneDelegate *sceneDelegate,
45  HdRenderParam *renderParam,
46  HdDirtyBits *dirtyBits) override;
47 
52  void Finalize(HdRenderParam *renderParam) override;
53 
62  bool Allocate(GfVec3i const& dimensions,
63  HdFormat format,
64  bool multiSampled) override;
65 
68  unsigned int GetWidth() const override { return _width; }
69 
72  unsigned int GetHeight() const override { return _height; }
73 
76  unsigned int GetDepth() const override { return 1; }
77 
80  HdFormat GetFormat() const override { return _format; }
81 
84  bool IsMultiSampled() const override { return _multiSampled; }
85 
90  void* Map() override {
91  _mappers++;
92  return _buffer.data();
93  }
94 
96  void Unmap() override {
97  _mappers--;
98  }
99 
102  bool IsMapped() const override {
103  return _mappers.load() != 0;
104  }
105 
109  bool IsConverged() const override {
110  return _converged.load();
111  }
112 
115  void SetConverged(bool cv) {
116  _converged.store(cv);
117  }
118 
120  void Resolve() override;
121 
122  // ---------------------------------------------------------------------- //
124  // ---------------------------------------------------------------------- //
125 
133  void Write(GfVec3i const& pixel, size_t numComponents, float const* value);
134 
142  void Write(GfVec3i const& pixel, size_t numComponents, int const* value);
143 
150  void Clear(size_t numComponents, float const* value);
151 
158  void Clear(size_t numComponents, int const* value);
159 
160 private:
161  // Calculate the needed buffer size, given the allocation parameters.
162  static size_t _GetBufferSize(GfVec2i const& dims, HdFormat format);
163 
164  // Return the sample format for the given buffer format. Sample buffers
165  // are always float32 or int32, but with the same number of components
166  // as the base format.
167  static HdFormat _GetSampleFormat(HdFormat format);
168 
169  // Release any allocated resources.
170  void _Deallocate() override;
171 
172  // Buffer width.
173  unsigned int _width;
174  // Buffer height.
175  unsigned int _height;
176  // Buffer format.
177  HdFormat _format;
178  // Whether the buffer is operating in multisample mode.
179  bool _multiSampled;
180 
181  // The resolved output buffer.
182  std::vector<uint8_t> _buffer;
183  // For multisampled buffers: the input write buffer.
184  std::vector<uint8_t> _sampleBuffer;
185  // For multisampled buffers: the sample count buffer.
186  std::vector<uint8_t> _sampleCount;
187 
188  // The number of callers mapping this buffer.
189  std::atomic<int> _mappers;
190  // Whether the buffer has been marked as converged.
191  std::atomic<bool> _converged;
192 };
193 
194 PXR_NAMESPACE_CLOSE_SCOPE
195 
196 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
virtual void Unmap()=0
Unmap the buffer. It is no longer safe to read from the buffer.
virtual bool IsMapped() const =0
Return whether the buffer is currently mapped by anybody.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
virtual unsigned int GetWidth() const =0
Get the buffer's width.
HD_API void Finalize(HdRenderParam *renderParam) override
Deallocate before deletion.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
Adapter class providing data exchange with the client scene graph.
virtual HdFormat GetFormat() const =0
Get the buffer's per-pixel format.
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
virtual bool IsConverged() const =0
Return whether the buffer is converged (whether the renderer is still adding samples or not).
virtual unsigned int GetHeight() const =0
Get the buffer's height.
virtual unsigned int GetDepth() const =0
Get the buffer's depth.
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:49
virtual void * Map()=0
Map the buffer for reading.
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
Allocate a buffer.
virtual bool IsMultiSampled() const =0
Get whether the buffer is multisampled.
virtual void Resolve()=0
Resolve the buffer so that reads reflect the latest writes.