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