9 #include <pxr/base/gf/vec3i.h>
10 #include <pxr/base/gf/vec4f.h>
28 HdRenderBuffer::Finalize(renderParam);
33 if (dimensions[2] != 1) {
34 TF_RUNTIME_ERROR(
"HdCyclesRenderBuffer::Allocate called with dimensions that are not 2D.");
38 const size_t oldSize = _dataSize;
39 const size_t newSize = dimensions[0] * dimensions[1] * HdDataSizeOfFormat(
format);
40 if (oldSize == newSize) {
45 TF_RUNTIME_ERROR(
"HdCyclesRenderBuffer::Allocate called while buffer is mapped.");
49 _width = dimensions[0];
50 _height = dimensions[1];
53 _resourceUsed =
false;
58 void HdCyclesRenderBuffer::_Deallocate()
62 _format = HdFormatInvalid;
65 _data.shrink_to_fit();
68 _resource = VtValue();
74 if (!_resource.IsEmpty()) {
78 if (_data.size() != _dataSize) {
79 _data.resize(_dataSize);
113 return _resourceUsed;
118 TF_UNUSED(multiSampled);
120 _resourceUsed =
true;
127 _resource = resource;
132 struct SimpleConversion {
133 static float convert(
float value)
138 struct IdConversion {
141 return static_cast<int32_t>(value) - 1;
144 struct UInt8Conversion {
147 return static_cast<uint8_t>(value * 255.f);
150 struct SInt8Conversion {
153 return static_cast<int8_t>(value * 127.f);
156 struct HalfConversion {
163 template<
typename SrcT,
typename DstT,
typename Convertor = SimpleConversion>
164 void writePixels(
const SrcT *srcPtr,
165 const GfVec2i &srcSize,
168 const GfVec2i &dstSize,
170 const Convertor &convertor = {})
172 const auto writeSize = GfVec2i(GfMin(srcSize[0], dstSize[0]), GfMin(srcSize[1], dstSize[1]));
173 const auto writeChannelCount = GfMin(srcChannelCount, dstChannelCount);
175 for (
int y = 0;
y < writeSize[1]; ++
y) {
176 for (
int x = 0;
x < writeSize[0]; ++
x) {
177 for (
int c = 0;
c < writeChannelCount; ++
c) {
178 dstPtr[
x * dstChannelCount +
c] = convertor.convert(srcPtr[
x * srcChannelCount +
c]);
181 srcPtr += srcSize[0] * srcChannelCount;
182 dstPtr += dstSize[0] * dstChannelCount;
189 const PXR_NS::GfVec2i &srcOffset,
190 const GfVec2i &srcDims,
194 uint8_t *dstPixels = _data.data();
196 const size_t formatSize = HdDataSizeOfFormat(_format);
197 dstPixels += srcOffset[1] * (formatSize * _width) + srcOffset[0] * formatSize;
201 case HdFormatUNorm8Vec2:
202 case HdFormatUNorm8Vec3:
203 case HdFormatUNorm8Vec4:
204 writePixels(srcPixels,
208 GfVec2i(_width, _height),
209 1 + (_format - HdFormatUNorm8),
214 case HdFormatSNorm8Vec2:
215 case HdFormatSNorm8Vec3:
216 case HdFormatSNorm8Vec4:
217 writePixels(srcPixels,
221 GfVec2i(_width, _height),
222 1 + (_format - HdFormatSNorm8),
226 case HdFormatFloat16:
227 case HdFormatFloat16Vec2:
228 case HdFormatFloat16Vec3:
229 case HdFormatFloat16Vec4:
230 writePixels(srcPixels,
233 reinterpret_cast<half *
>(dstPixels),
234 GfVec2i(_width, _height),
235 1 + (_format - HdFormatFloat16),
239 case HdFormatFloat32:
240 case HdFormatFloat32Vec2:
241 case HdFormatFloat32Vec3:
242 case HdFormatFloat32Vec4:
243 writePixels(srcPixels,
246 reinterpret_cast<float *
>(dstPixels),
247 GfVec2i(_width, _height),
248 1 + (_format - HdFormatFloat32));
254 writePixels(srcPixels,
257 reinterpret_cast<int *
>(dstPixels),
258 GfVec2i(_width, _height),
263 writePixels(srcPixels,
266 reinterpret_cast<int *
>(dstPixels),
267 GfVec2i(_width, _height),
271 case HdFormatInt32Vec2:
272 case HdFormatInt32Vec3:
273 case HdFormatInt32Vec4:
274 writePixels(srcPixels,
277 reinterpret_cast<int *
>(dstPixels),
278 GfVec2i(_width, _height),
279 1 + (_format - HdFormatInt32));
283 TF_RUNTIME_ERROR(
"HdCyclesRenderBuffer::WritePixels called with unsupported format.");
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
bool IsConverged() const override
void SetConverged(bool converged)
HdCyclesRenderBuffer(const PXR_NS::SdfPath &bprimId)
bool IsResourceUsed() const
bool Allocate(const PXR_NS::GfVec3i &dimensions, PXR_NS::HdFormat format, bool multiSampled) override
~HdCyclesRenderBuffer() override
bool IsMapped() const override
void SetResource(const PXR_NS::VtValue &resource)
void Finalize(PXR_NS::HdRenderParam *renderParam) override
void WritePixels(const float *pixels, const PXR_NS::GfVec2i &offset, const PXR_NS::GfVec2i &dims, int channels, bool isId=false)
PXR_NS::VtValue GetResource(bool multiSampled=false) const override
ccl_device_inline half float_to_half_image(float f)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE