HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMX_Buffer.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #pragma once
9 
10 #include "IMX_API.h"
11 
12 #include "IMX_Types.h"
13 #include "IMX_PoolEntry.h"
14 
15 #include <CE/CE_Image.h>
16 #include <CE/CE_Precision.h>
17 #include <SYS/SYS_Align.h>
18 #include <SYS/SYS_Compiler.h>
19 #include <SYS/SYS_Inline.h>
20 #include <UT/UT_Vector4.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_SharedPtr.h>
23 
24 #include <CE/CE_BufferHost.h>
25 #include <CE/CE_BufferDevice.h>
26 
27 class PXL_Raster;
28 class TIL_Raster;
29 
30 /// This structure contains the metadata of an image, including its buffer
31 /// transform, resolution, and border properties.
32 struct IMX_Stat
33 {
37 
38  CEfloatD<CE_32> myBufferToImage[4] = {0, 0, 0, 0};
39  CEfloatD<CE_32> myImageToBuffer[4] = {0, 0, 0, 0};
40  CEfloatD<CE_32> myBufferToPixel[4] = {0, 0, 0, 0};
41  CEfloatD<CE_32> myCameraImagePos[4] = {0, 0, 0, 0}; // Last float is padding
42 
43  CEfloatD<CE_32> myDefaultFColor[4] = {0, 0, 0, 0};
44  CEintD<CE_32> myDefaultIColor[4] = {0, 0, 0, 0};
45 
47  int myChannels = 0;
48  int myStrideX = 0;
49  int myStrideY = 0;
50 
53  CE_Image::StorageType myStorage = CE_Image::StorageType::FLOAT16;
55 
56  /// Write our fields into the provided options:
57  void copyToOptions(UT_Options &opt) const;
58  /// Load ourselves from the options, ignoring fields we don't know
59  void updateFromOptions(const UT_Options &opt);
60 
61  bool operator==(const IMX_Stat& other) const
62  {
63  for (int i = 0; i < 4; i++)
64  {
65  if (myBufferToImage[i] != other.myBufferToImage[i] ||
66  myImageToBuffer[i] != other.myImageToBuffer[i] ||
67  myBufferToPixel[i] != other.myBufferToPixel[i] ||
68  myDefaultFColor[i] != other.myDefaultFColor[i] ||
69  myDefaultIColor[i] != other.myDefaultIColor[i])
70  {
71  return false;
72  }
73  }
74 
75  for (int i = 0; i < 3; ++i) // Don't compare the padding float
76  {
77  if (myCameraImagePos[i] != other.myCameraImagePos[i])
78  {
79  return false;
80  }
81  }
82 
83  if (myImageToWorld != other.myImageToWorld ||
84  myWorldToImage != other.myWorldToImage ||
86  {
87  return false;
88  }
89 
90  if (myResolution[0] != other.myResolution[0] ||
91  myResolution[1] != other.myResolution[1])
92  {
93  return false;
94  }
95 
96  if (myChannels != other.myChannels ||
97  myStrideX != other.myStrideX ||
98  myStrideY != other.myStrideY ||
99  myBorder != other.myBorder ||
100  myTypeInfo != other.myTypeInfo ||
101  myStorage != other.myStorage ||
102  myProjection != other.myProjection)
103  {
104  return false;
105  }
106 
107  return true;
108  }
109 
110  bool operator!=(const IMX_Stat& other) const
111  {
112  return !(*this == other);
113  }
114 };
115 
116 /// The per-pixel data for a single IMX_Layer
117 ///
118 /// Buffer has several formats to store data in, for instance whether it is on the
119 /// GPU or CPU. Buffers are converted by copying, or snippets are used to change the
120 /// OpenCL code reading them. As some translators can work in-place, the format is
121 /// considered a setting of the Buffer, rather than having different Buffer
122 /// subclasses for each format.
123 ///
124 /// This is a first working version of such a buffer, though it's missing a lot
125 /// of features. There's only one supported format (32-bit float), between 1 and
126 /// 4 channels. This is stored in an array, flattened over the rows first. There
127 /// is also GPU storage that this buffer uses. States of these buffers (i.e. do
128 /// they contain up-to-date information?) are encoded in the two boolean flags
129 /// (myOnCPU and myOnGPU). When the user asks IMX_Buffer
130 /// something that must access its storage, that storage is first automatically
131 /// synchronized before the request is fulfilled.
132 
134 {
135  friend class IMX_Layer;
136 public:
137  /// Creates a new buffer. You must call setSize to make this buffer usable.
138  IMX_Buffer();
139  /// Create and call setSize
141  IMX_Buffer(const IMX_Buffer &other) { copy(other); }
142  IMX_Buffer(IMX_Buffer && other) noexcept { swap(other); }
143  IMX_Buffer(const PXL_Raster &rp);
144  ~IMX_Buffer() override;
145 
146  EntryType poolTypeID() const override { return EntryType::BUFFER; }
147 
148  /// Copy everything except the buffer allocations, leaving the buffers dirty.
149  /// This avoids any chance that writing pixels to this will modify the original.
150  /// It also avoids shared pointer overhead and keeping buffers around longer than needed.
151  void copyMetadata(const IMX_Buffer& source);
152 
153  /// Set storesIntegers, isFixedPoint, bytes, channels
156  /// Set storesIntegers, isFixedPoint, bytes, channels
158  /// Set storesIntegers, isFixedPoint, bytes
160  /// Set number of bytes per channel, don't change storesIntegers,
161  /// isFixedPoint, or channels
162  void setStorageBytes(int);
163  /// Set bytes per channel and isFixedPoint, doesn't change channels. Also
164  /// sets storesIntegers to false. TODO: should this fail if storesIntegers()
165  /// is already true? (FIXED_POINT_STORAGE)
166  void setStorageBytes(int, bool);
167  /// Set channels, don't change storesIntegers, isFixedPoint, or bytes
168  void setChannels(int channels);
169  /// Get the data type used to store pixel data for each channel.
170  CE_Image::StorageType getStorageType() const { return myCPUStat.myStorage; }
171  /// Does this buffer store integers?
172  bool storesIntegers() const { return CE_Image::storesIntegers(myCPUStat.myStorage); }
173  /// Does this buffer use fixed point to store non-integer data?
174  bool isFixedPoint() const { return CE_Image::isFixedPoint(myCPUStat.myStorage); }
175  /// Get the number of channels per pixel.
176  int getChannels() const { return myCPUStat.myChannels; }
177  /// Number of bytes per channel
178  int getStorageBytes() const { return CE_Image::getBytes(myCPUStat.myStorage); }
179 
180  /// Sets size of this buffer.
181  void setBufferSize(int width, int height);
182  /// Get width (number of columns in a row) of the buffer.
183  exint bufferWidth() const { return myCPUStat.myResolution[0]; }
184  /// Get height (number of rows) of the buffer.
185  exint bufferHeight() const { return myCPUStat.myResolution[1]; }
186  /// Returns the number of bytes required to store the entire buffer.
187  int64 getBufferSize() const;
188 
189  /// Set transform between image and buffer space
190  void setBufferXforms(
191  const UT_Vector2F &buffer_to_image_scale,
192  const UT_Vector2F &buffer_to_image_xlate,
193  const UT_Vector2F &buffer_from_image_scale,
194  const UT_Vector2F &buffer_from_image_xlate,
195  const UT_Vector2F &buffer_to_pixel_scale,
196  const UT_Vector2F &buffer_to_pixel_xlate,
197  const UT_Matrix4F &image_to_world,
198  const UT_Matrix4F &world_to_image,
199  const UT_Matrix4F &camera_to_world,
200  const UT_Vector3F &camera_image_pos
201  );
202 
203  /// Sets the border type of this image. Constant means it is zero.
205  /// Returns type of the border.
207 
208  /// Sets the semantic type info of this image.
209  void setTypeInfo(IMX_TypeInfo typeinfo);
210  /// Returns the semantic type.
211  IMX_TypeInfo getTypeInfo() const;
212 
213  /// These are the projections in the stat, you want to actually
214  /// work at imx layer to ensure you update the transforms.
215  /// Sets the projection of this image.
217  /// Returns the projection type
219 
220 
221  /// Set the default color. This is returned for uncalculatable pixels, and
222  /// to expand integer vectors from 2,3 to 4. Other usage is not yet
223  /// determined. Initial value is 0,0,0,1 (may change)
224  void setDefaultColor(const UT_Vector4F&);
226  /// return the current integer value, which might be different
228 
229  /// Assignment operators; after executing these functions, this buffer will
230  /// have the same size and data as other.
231  void copy(const IMX_Buffer &other);
232  IMX_Buffer &operator=(const IMX_Buffer &other) { copy(other); return *this; }
233  /// Deep copy operator. Unlike copy() (which shares the buffers of the
234  /// source), this version allocates a new buffer and copies the data into
235  /// it.
236  /// This can throw CE exceptions.
237  void deepCopy(const IMX_Buffer &other);
238 
239  void swap(IMX_Buffer &other);
240  IMX_Buffer &operator=(IMX_Buffer &&other) { swap(other); return *this; }
241 
242  /// True if data in this buffer may be stolen from (or changed) by the verbs
243  /// even if it's an input.
244  bool stealable() const { return myStealable; }
245  /// Can be used to control what stealable() subsequently returns. If set to
246  /// true, indicates to the verbs that this buffer may be stolen from.
247  void setStealable(bool v) const { myStealable = v; }
248  /// True if the buffer pixels line up: width and the transforms from image space match.
249  bool isAligned(const IMX_Buffer &src) const;
250 
251  /// Only copy the buffer pointers, the stat data is left unchanged
252  void copyBuffer(const IMX_Buffer &other);
253  /// Move the buffer to this from src, src is left dirty
254  void moveBuffer(IMX_Buffer &src);
255  /// Stop sharing the buffers (so that writes don't affect other layers that
256  /// have called copyBuffer() on this or vice versa).
257  void makeBufferUnique();
258 
259  /// Adopt a PXL_Raster into the underlying IMX_Buffer. The buffer's storage
260  /// type and number of channels must be set before calling.
261  /// Steals the PXL_Raster data if compatible.
262  /// Does OCIO transform from raster's space to scene linear if
263  /// convert is set.
264  void adoptRaster(PXL_Raster &raster, bool convert_colorspace);
265 
266  /// copy the buffer, converting betwen storage types if needed and doing a shallow copy
267  /// if possible
268  void copyOrConvert(const IMX_Buffer& other);
269 
270 
271  /// Copies the buffer into the provided flat destination buffer.
272  /// The provided size is checked against required size and ASSERT
273  /// and no copy & return false if a mis-match.
274  bool extract(void *dst, exint dstsize,
275  CE_Image::StorageType dststorage,
276  int dstchannels) const;
277  /// Copies the provided flat buffer into this buffer.
278  /// The provided size is checked against required size and ASSERT
279  /// and no copy & return false if a mis-match.
280  bool insert(const void *src, exint srcsize,
281  CE_Image::StorageType srcstorage,
282  int srcchannels);
283 
284  /// Constructs a TIL_Raster matching our storage/channel depth.
285  /// Will be packed.
286  /// TIL_Raster is subclass from PXL_Raster.
288 
289  /// for debugging
290  const UT_SharedPtr<CE_BufferHostByte> &CPUBufferPtr() const { return myCPUBuffer; }
291  const UT_SharedPtr<CE_Image> &GPUBufferPtr() const { return myGPUBuffer; }
292 
293  /// Sets an individual pixel.
294  void setPixelV4(int x, int y, const UT_Vector4F& c)
295  {
296  setPixelV4Internal(x, y, c, true);
297  }
298  void setPixelF(int x, int y, fpreal32 i)
299  {
300  setPixelV4Internal(x, y, UT_Vector4F(i, i, i, i), true);
301  }
302  void setPixelI(int x, int y, int i)
303  {
304  setPixelIInternal(x, y, i, true);
305  }
306 
307  /// Fetches the value of an individual pixel.
308  UT_Vector4F getPixelV4(int x, int y) const;
309  int getPixelI(int x, int y) const;
310  /// Fetches the value at the provided coordinates, using bilinear filtering.
311  /// Returns value of the nearest pixel for integer buffers.
313  // Fetches the raw buffer at x, y
314  void getPixelRaw(UT_Array<uint8> &dest, int x, int y) const;
315 
316  /// Return pointer to CPU buffer (caller must ask for correct data type)
317  /// If a read buffer is requested and this buffer is constant, the buffer
318  /// will be compressed (i.e. of size equal to the number of channels)!
319  const int16* getCPUBufferRFixed16() const { return getCPUBufferR<CE_Image::FIXED16>(); }
320  int16* getCPUBufferWFixed16() { return getCPUBuffer<CE_Image::FIXED16>(false,true); }
321  const uint8* getCPUBufferRFixed8() const { return getCPUBufferR<CE_Image::FIXED8>(); }
322  uint8* getCPUBufferWFixed8() { return getCPUBuffer<CE_Image::FIXED8>(false,true); }
323  const fpreal16* getCPUBufferRF16() const { return getCPUBufferR<CE_Image::FLOAT16>(); }
324  fpreal16* getCPUBufferWF16() { return getCPUBuffer<CE_Image::FLOAT16>(false,true); }
325  const fpreal32* getCPUBufferRF32() const { return getCPUBufferR<CE_Image::FLOAT32>(); }
326  fpreal32* getCPUBufferWF32() { return getCPUBuffer<CE_Image::FLOAT32>(false,true); }
327  const unsigned char* getCPUBufferRI8() const { return getCPUBufferR<CE_Image::INT8>(); }
328  unsigned char* getCPUBufferWI8() { return getCPUBuffer<CE_Image::INT8>(false,true); }
329  const int16* getCPUBufferRI16() const { return getCPUBufferR<CE_Image::INT16>(); }
330  int16* getCPUBufferWI16() { return getCPUBuffer<CE_Image::INT16>(false,true); }
331  const int32* getCPUBufferRI32() const { return getCPUBufferR<CE_Image::INT32>(); }
332  int32* getCPUBufferWI32() { return getCPUBuffer<CE_Image::INT32>(false,true); }
333  /// Returns a void pointer to the CPU buffer.
334  /// If a read-only buffer is requested and this buffer is constant, the
335  /// buffer will be compressed (i.e. of size equal to the number of
336  /// channels)!
337  void* getCPUBuffer(bool read, bool write)
338  { return getCPUBufferInternal(read, write, write); }
339  void *getCPUBufferR() const { return getCPUBufferRInternal(); };
340  void *getCPUBufferW() { return getCPUBuffer(false, true); }
341  /// Returns this buffer's read-only data array.
342  /// If this buffer is constant, the buffer will be compressed (i.e. of size
343  /// equal to the number of channels)!
344  template <CE_Image::StorageType STORAGE>
346  {
347  return cast<STORAGE>(getCPUBufferRInternal());
348  }
349 
350  /// Returns this buffer's data array. If read is true, isDirty must
351  /// be false. If write is true then it turns off isDirty by setting
352  /// isOnCPU() and turning off isOnGPU() (it is assuming caller will actually
353  /// write the buffer)
354  /// If a read-only buffer is requested and this buffer is constant, the
355  /// buffer will be compressed (i.e. of size equal to the number of
356  /// channels)!
357  template <CE_Image::StorageType STORAGE>
358  typename CE_StorageTypeTraits<STORAGE>::DataType *getCPUBuffer(bool read, bool write)
359  {
360  return cast<STORAGE>(getCPUBufferInternal(read, write, write));
361  }
362 
363  /// Returns this buffer's GPU storage object. If read is true, isDirty must
364  /// be false. If write is true then it turns off isDirty by setting
365  /// isOnGPU() and turning off isOnCPU() (it is assuming caller will actually
366  /// write the buffer)
367  /// When using one of these methods, this buffer must be guarded with the
368  /// in-use GPU flag. See setInUseGPUFlag() documentation for more
369  /// information.
370  /// Can throw CE exceptions.
371  CE_Image &getGPUBuffer(bool read, bool write);
372  const CE_Image &getGPUBufferR() const;
373  CE_Image &getGPUBufferW() { return getGPUBuffer(false, true); }
374 
375  /// Returns true if this buffer's data is currently on the GPU.
376  bool isOnGPU() const
377  {
378  return myOnGPU;
379  }
380 
381  /// Returns true if this buffer's data is currently on the CPU (this is not
382  /// necessarily !isOnGPU()).
383  bool isOnCPU() const
384  {
385  return myOnCPU;
386  }
387 
388  /// Returns the stat buffer on the GPU, copying it there if necessary.
389  /// This can throw CE exceptions.
390  cl::Buffer getGPUStat() const;
391 
392  /// False if there are computed pixels in the CPU or GPU buffer
393  bool isDirty() const { return !myOnGPU && !myOnCPU; }
394 private:
395  /// Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true
396  /// This is internal only as isConstant should not be adjusted by
397  /// external users.
398  void setDirty() { myOnGPU = myOnCPU = myIsConstant = false; }
399 public:
400  /// Frees the pixel memory (also does setDirty())
401  void freeBuffers();
402  /// Frees all the memory used by buffer
403  void destroy();
404  /// True if getCPU/GPUBuffer has been done since last freeBuffers()
405  bool allocated() const { return myCPUBuffer || myGPUBuffer; }
406 
407  /// Make entire image the same color. This is optimized internally to a 1x1
408  /// buffer
409  void setConstantV4(const UT_Vector4F &i);
411  void setConstantF(fpreal32 i = 0.0f) { setConstantV4(UT_Vector4F(i, i, i, i)); }
412  void setConstantI(int32 i = 0);
413 
414  /// Marks that this buffer is not initialized. This means that when a read
415  /// buffer is requested, we won't bother doing any copying or data
416  /// validation. This is useful if you bind this as a read-write layer to a
417  /// kernel, but will be doing the initialization in the same kernel. Copying
418  /// from an unitialized buffer will inherit this flag without moving any
419  /// data. This flag gets cleared when someone writes to this buffer.
420  void setUninitialized() { myIsUninitialized = true; }
421 
422  bool isConstant() const { return myIsConstant; }
423 
424  bool validateBuffer() const;
425 
426  /// Resizes dest to match dimensions of this image (its Z-resolution is set
427  /// to 1) and copies this buffer's data into it. Number of channels in the
428  /// image should equal tuple size of T.
429  /// If this layer is dirty, simply sizes the voxel array without touching
430  /// its values.
431  template <typename T>
432  void matchAndCopyToVoxels(UT_VoxelArray<T>& dest) const;
433 
434  int64 getMemoryUsage() const;
435  int64 getDeviceMemoryUsage() const;
436 
437 protected:
438  /// These implement methods required by the pool.
439 
440  /// Resets the GPU Buffer pointer.
441  void poolResetGPUBuffer() override
442  {
443  myGPUBuffer.reset();
444  }
445  /// Update OnGPU
446  void poolSetOnGPU(bool ongpu) override
447  {
448  myOnGPU = ongpu;
449  }
450  /// True if the gpu buffer is null.
451  bool poolIsGPUBufferEmpty() const override
452  {
453  return myGPUBuffer.get() == nullptr;
454  }
455  /// True if the gpu buffer is not null and valid.
456  bool poolIsGPUBufferValid() const override
457  {
458  return myGPUBuffer.get() && myGPUBuffer->isValid();
459  }
460  /// True if the swap does something
461  bool poolSwapGPUBuffer(IMX_PoolEntry *otherbase) override
462  {
463  IMX_Buffer *other = UTverify_cast<IMX_Buffer *>(otherbase);
464 
465  if (myGPUBuffer == other->myGPUBuffer)
466  return false;
467 
468  myGPUBuffer.swap(other->myGPUBuffer);
469  return true;
470  }
471  /// Shallow copy
472  void poolShallowCopyGPUBuffer(const IMX_PoolEntry *srcbase) override
473  {
474  const IMX_Buffer *src = UTverify_cast<const IMX_Buffer *>(srcbase);
475 
476  myGPUBuffer = src->myGPUBuffer;
477  }
478 
479 private:
480  /// Initialize all the fields (used by constructors)
481  void init(int width, int height, CE_Image::StorageType storage, int channels);
482 
483  /// Allocates a GPU Buffer, doing proper synchronization with
484  /// the CE Pool. NOTE: If the GPU buffer is the right size, it will
485  /// be re-used.
486  void allocateCEBuffer(exint width, exint height);
487 
488  /// Gets the CPU buffer, allocate and/or copy the GPU one if necessary. If
489  /// expand_constant is true and this buffer is constant, the storage will be
490  /// uncompressed before returning a pointer.
491  void *getCPUBufferInternal(bool read, bool write, bool expand_constant);
492  void *getCPUBufferRInternal() const;
493 
494  /// Internal methods to set the pixel value. If expand_constant is true and
495  /// this buffer is constant, the storage will be uncompressed first,
496  /// retaining any previous data.
497  void setPixelV4Internal(int x, int y, const UT_Vector4F& val,
498  bool expand_constant);
499  void setPixelIInternal(int x, int y, int val, bool expand_constant);
500 
501  /// Queues up commands that transfer this buffer's GPU storage to main
502  /// memory.
503  void unloadFromGPU() override;
504 
505  /// Cast void* pointer to correct type for storage. Includes an assert to make
506  /// sure the storage type is the same one this buffer is using.
507  template <CE_Image::StorageType STORAGE>
509  cast(void *p)
510  {
511  UT_ASSERT(STORAGE == myCPUStat.myStorage);
512  return (typename CE_StorageTypeTraits<STORAGE>::DataType *) p;
513  }
514  template <CE_Image::StorageType STORAGE>
516  cast(const void *p) const
517  {
518  UT_ASSERT(STORAGE == myCPUStat.myStorage);
519  return (const typename CE_StorageTypeTraits<STORAGE>::DataType *) p;
520  }
521 
523  /// All changes to this member (the shared pointer) must be done by the
524  /// memory pool!!!
525  UT_SharedPtr<CE_Image> myGPUBuffer;
526 
527  /// CPU version of the stat buffer; this is always assumed to be clean.
528  IMX_Stat myCPUStat;
529  /// GPU backing of stat buffer, considered not-writable so
530  /// only update in-place if unique.
531  mutable UT_SharedPtr<CE_BufferDeviceByte> myGPUStat;
532  mutable bool myGPUStatClean = false;
533 
534  /// This pair of flags hold the state of data that lives in the two storage
535  /// spots.
536  bool myOnCPU = false;
537  bool myOnGPU = false;
538 
539  /// If true only allocate a 1x1 buffer
540  bool myIsConstant = false;
541  /// If true, we won't actually do any data copying or validation when a read
542  /// is requested.
543  bool myIsUninitialized = false;
544  /// Can data of this buffer be stolen by the verbs? TODO: who should reset
545  /// this and when?
546  mutable bool myStealable = true;
547 
548  friend class IMX_CEMemoryPool;
549 };
550 
552 
553 /// Returns the label for the supplied border type
555 
IMX_Buffer & operator=(const IMX_Buffer &other)
Definition: IMX_Buffer.h:232
void setStorageType(CE_Image::StorageType storage, int channels)
Set storesIntegers, isFixedPoint, bytes, channels.
fpreal16 * getCPUBufferWF16()
Definition: IMX_Buffer.h:324
void copyBuffer(const IMX_Buffer &other)
Only copy the buffer pointers, the stat data is left unchanged.
void makeBufferUnique()
CE_Image & getGPUBufferW()
Definition: IMX_Buffer.h:373
int int32
Definition: SYS_Types.h:39
CE_StorageTypeTraits< STORAGE >::DataType * getCPUBuffer(bool read, bool write)
Definition: IMX_Buffer.h:358
static bool storesIntegers(StorageType t)
Definition: CE_Image.h:41
bool isAligned(const IMX_Buffer &src) const
True if the buffer pixels line up: width and the transforms from image space match.
bool operator==(const IMX_Stat &other) const
Definition: IMX_Buffer.h:61
static bool isFixedPoint(StorageType t)
Definition: CE_Image.h:42
IMX_BorderType getBorderType() const
Returns type of the border.
void * getCPUBufferW()
Definition: IMX_Buffer.h:340
const UT_SharedPtr< CE_Image > & GPUBufferPtr() const
Definition: IMX_Buffer.h:291
UT_Matrix4F myCameraToWorld
Definition: IMX_Buffer.h:36
void moveBuffer(IMX_Buffer &src)
Move the buffer to this from src, src is left dirty.
CEfloatD< CE_32 > myImageToBuffer[4]
Definition: IMX_Buffer.h:39
const uint8 * getCPUBufferRFixed8() const
Definition: IMX_Buffer.h:321
int64 getBufferSize() const
Returns the number of bytes required to store the entire buffer.
bool isOnCPU() const
Definition: IMX_Buffer.h:383
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
int myStrideX
Definition: IMX_Buffer.h:48
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
Definition: IMX_PoolEntry.h:23
IMX_Buffer(const IMX_Buffer &other)
Definition: IMX_Buffer.h:141
void setStorageBytes(int)
UT_Vector4F getDefaultColor() const
void setTypeInfo(IMX_TypeInfo typeinfo)
Sets the semantic type info of this image.
IMX_TypeInfo
Definition: IMX_Types.h:34
IMX_Projection
Definition: IMX_Types.h:54
const unsigned char * getCPUBufferRI8() const
Definition: IMX_Buffer.h:327
int64 exint
Definition: SYS_Types.h:125
CEfloatD< CE_32 > myBufferToImage[4]
Definition: IMX_Buffer.h:38
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7440
void destroy()
Frees all the memory used by buffer.
EntryType
To avoid the need for dynamic casts:
Definition: IMX_PoolEntry.h:27
GLint y
Definition: glcorearb.h:103
void setStealable(bool v) const
Definition: IMX_Buffer.h:247
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
IMX_TypeInfo myTypeInfo
Definition: IMX_Buffer.h:52
CE_Image & getGPUBuffer(bool read, bool write)
void swap(IMX_Buffer &other)
void copyOrConvert(const IMX_Buffer &other)
bool isFixedPoint() const
Does this buffer use fixed point to store non-integer data?
Definition: IMX_Buffer.h:174
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3556
void * getCPUBuffer(bool read, bool write)
Definition: IMX_Buffer.h:337
int16 * getCPUBufferWI16()
Definition: IMX_Buffer.h:330
float fpreal32
Definition: SYS_Types.h:200
void freeBuffers()
Frees the pixel memory (also does setDirty())
void setPixelF(int x, int y, fpreal32 i)
Definition: IMX_Buffer.h:298
void setUninitialized()
Definition: IMX_Buffer.h:420
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void setConstantI(int32 i=0)
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
OIIO_FORCEINLINE bool extract(const vbool4 &a)
Definition: simd.h:3542
CE_Image::StorageType getStorageType() const
Get the data type used to store pixel data for each channel.
Definition: IMX_Buffer.h:170
void copyMetadata(const IMX_Layer &a)
Definition: IMX_Layer.h:211
void setChannels(int channels)
Set channels, don't change storesIntegers, isFixedPoint, or bytes.
UT_Matrix4F myWorldToImage
Definition: IMX_Buffer.h:35
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLfloat f
Definition: glcorearb.h:1926
void setBorder(IMX_BorderType border)
Sets the border type of this image. Constant means it is zero.
UT_UniquePtr< TIL_Raster > buildRaster() const
SYS_FORCE_INLINE const X * cast(const InstancablePtr *o)
fpreal32 * getCPUBufferWF32()
Definition: IMX_Buffer.h:326
void matchAndCopyToVoxels(UT_VoxelArray< T > &dest) const
int getPixelI(int x, int y) const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
IMX_Buffer & operator=(IMX_Buffer &&other)
Definition: IMX_Buffer.h:240
IMX_Projection statProjection() const
Returns the projection type.
void setPixelV4(int x, int y, const UT_Vector4F &c)
Sets an individual pixel.
Definition: IMX_Buffer.h:294
int64 getDeviceMemoryUsage() const
int myChannels
Definition: IMX_Buffer.h:47
void poolSetOnGPU(bool ongpu) override
Update OnGPU.
Definition: IMX_Buffer.h:446
bool validateBuffer() const
bool poolIsGPUBufferEmpty() const override
True if the gpu buffer is null.
Definition: IMX_Buffer.h:451
CEintD< CE_32 > myResolution[2]
Definition: IMX_Buffer.h:46
IMX_Projection myProjection
Definition: IMX_Buffer.h:54
bool poolSwapGPUBuffer(IMX_PoolEntry *otherbase) override
True if the swap does something.
Definition: IMX_Buffer.h:461
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
UT_Vector4I getDefaultColorI() const
return the current integer value, which might be different
IMX_Buffer()
Creates a new buffer. You must call setSize to make this buffer usable.
int getChannels() const
Get the number of channels per pixel.
Definition: IMX_Buffer.h:176
virtual void unloadFromGPU()=0
HUSD_API const char * raster()
IMX_API const char * COPgetBorderTypeString(const IMX_BorderType &border)
Returns the label for the supplied border type.
long long int64
Definition: SYS_Types.h:116
int16 * getCPUBufferWFixed16()
Definition: IMX_Buffer.h:320
exint bufferHeight() const
Get height (number of rows) of the buffer.
Definition: IMX_Buffer.h:185
uint8 * getCPUBufferWFixed8()
Definition: IMX_Buffer.h:322
const int32 * getCPUBufferRI32() const
Definition: IMX_Buffer.h:331
const CE_Image & getGPUBufferR() const
bool isDirty() const
False if there are computed pixels in the CPU or GPU buffer.
Definition: IMX_Buffer.h:393
GLint GLenum GLint x
Definition: glcorearb.h:409
IMX_TypeInfo getTypeInfo() const
Returns the semantic type.
const fpreal32 * getCPUBufferRF32() const
Definition: IMX_Buffer.h:325
const UT_SharedPtr< CE_BufferHostByte > & CPUBufferPtr() const
for debugging
Definition: IMX_Buffer.h:290
void setConstantV3(const UT_Vector3F &i)
Definition: IMX_Buffer.h:410
~IMX_Buffer() override
bool isOnGPU() const
Returns true if this buffer's data is currently on the GPU.
Definition: IMX_Buffer.h:376
void setConstantF(fpreal32 i=0.0f)
Definition: IMX_Buffer.h:411
void getPixelRaw(UT_Array< uint8 > &dest, int x, int y) const
int myStrideY
Definition: IMX_Buffer.h:49
IMX_BorderType myBorder
Definition: IMX_Buffer.h:51
void copyStorageType(const IMX_Buffer &i)
Set storesIntegers, isFixedPoint, bytes, channels.
Definition: IMX_Buffer.h:154
void poolShallowCopyGPUBuffer(const IMX_PoolEntry *srcbase) override
Shallow copy.
Definition: IMX_Buffer.h:472
void * getCPUBufferR() const
Definition: IMX_Buffer.h:339
GLenum GLenum dst
Definition: glcorearb.h:1793
A map of string to various well defined value types.
Definition: UT_Options.h:84
const fpreal16 * getCPUBufferRF16() const
Definition: IMX_Buffer.h:323
GLint GLint GLsizei GLint border
Definition: glcorearb.h:108
UT_Vector4T< fpreal32 > UT_Vector4F
const CE_StorageTypeTraits< STORAGE >::DataType * getCPUBufferR() const
Definition: IMX_Buffer.h:345
StorageType
Definition: CE_Image.h:27
short int16
Definition: SYS_Types.h:37
cl::Buffer getGPUStat() const
IMX_BorderType
Controls returned values for coordinates that fall outside the image.
Definition: IMX_Types.h:21
bool operator!=(const IMX_Stat &other) const
Definition: IMX_Buffer.h:110
GLuint GLfloat * val
Definition: glcorearb.h:1608
exint bufferWidth() const
Get width (number of columns in a row) of the buffer.
Definition: IMX_Buffer.h:183
void updateFromOptions(const UT_Options &opt)
Load ourselves from the options, ignoring fields we don't know.
const int16 * getCPUBufferRFixed16() const
Definition: IMX_Buffer.h:319
int getStorageBytes() const
Number of bytes per channel.
Definition: IMX_Buffer.h:178
bool isConstant() const
Definition: IMX_Buffer.h:422
bool allocated() const
True if getCPU/GPUBuffer has been done since last freeBuffers()
Definition: IMX_Buffer.h:405
Memory buffer interface.
Definition: cl.hpp:1867
UT_Vector4F getPixelV4(int x, int y) const
Fetches the value of an individual pixel.
GLint GLsizei width
Definition: glcorearb.h:103
void copyToOptions(UT_Options &opt) const
Write our fields into the provided options:
#define IMX_API
Definition: IMX_API.h:8
static int getBytes(StorageType t)
Definition: CE_Image.h:43
UT_Matrix4F myImageToWorld
Definition: IMX_Buffer.h:34
void setBufferSize(int w, int h)
typename CE_PrecisionResolver< P >::device_float_type CEfloatD
Definition: CE_Precision.h:68
bool storesIntegers() const
Does this buffer store integers?
Definition: IMX_Buffer.h:172
int32 * getCPUBufferWI32()
Definition: IMX_Buffer.h:332
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
IMX_API CE_Image::StorageType IMXgetStorageTypeFromRaster(const PXL_Raster &rp)
IMX_Projection projection() const
Camera.
Definition: IMX_Layer.h:97
void setPixelI(int x, int y, int i)
Definition: IMX_Buffer.h:302
CEfloatD< CE_32 > myBufferToPixel[4]
Definition: IMX_Buffer.h:40
void adoptRaster(PXL_Raster &raster, bool convert_colorspace)
void setConstantV4(const UT_Vector4F &i)
bool stealable() const
Definition: IMX_Buffer.h:244
CEfloatD< CE_32 > myCameraImagePos[4]
Definition: IMX_Buffer.h:41
EntryType poolTypeID() const override
Definition: IMX_Buffer.h:146
IMX_Buffer(IMX_Buffer &&other) noexcept
Definition: IMX_Buffer.h:142
unsigned char * getCPUBufferWI8()
Definition: IMX_Buffer.h:328
void setDefaultColor(const UT_Vector4F &)
CEfloatD< CE_32 > myDefaultFColor[4]
Definition: IMX_Buffer.h:43
int64 getMemoryUsage() const
void setStatProjection(IMX_Projection projection)
const int16 * getCPUBufferRI16() const
Definition: IMX_Buffer.h:329
bool poolIsGPUBufferValid() const override
True if the gpu buffer is not null and valid.
Definition: IMX_Buffer.h:456
CEintD< CE_32 > myDefaultIColor[4]
Definition: IMX_Buffer.h:44
void poolResetGPUBuffer() override
These implement methods required by the pool.
Definition: IMX_Buffer.h:441
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
typename CE_PrecisionResolver< P >::device_int_type CEintD
Definition: CE_Precision.h:69
void deepCopy(const IMX_Buffer &other)
CE_Image::StorageType myStorage
Definition: IMX_Buffer.h:53
GLenum src
Definition: glcorearb.h:1793