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 <CE/CE_Image.h>
13 #include <CE/CE_Precision.h>
14 #include <SYS/SYS_Align.h>
15 #include <SYS/SYS_Compiler.h>
16 #include <SYS/SYS_Inline.h>
17 #include <UT/UT_Vector4.h>
18 #include <UT/UT_Matrix4.h>
19 #include <UT/UT_SharedPtr.h>
20 
21 class PXL_Raster;
22 class TIL_Raster;
23 
24 // The following enums and the stat structure must exactly match the definitions
25 // in the imx.h OpenCL header.
26 /// Controls returned values for coordinates that fall outside the image.
27 enum class IMX_BorderType
28 {
29  IMX_CONSTANT = 0,
30  IMX_CLAMP,
31  IMX_MIRROR,
32  IMX_WRAP
33 };
34 IMX_API size_t format(char *buffer, size_t buffer_size, const IMX_BorderType &v);
35 
36 enum class IMX_TypeInfo
37 {
38  IMX_NONE = 0,
39  IMX_COLOR,
41  IMX_VECTOR,
42  IMX_NORMAL,
45  IMX_ID,
46  IMX_MASK,
47  IMX_SDF,
49 };
50 IMX_API size_t format(char *buffer, size_t buffer_size, const IMX_TypeInfo &v);
51 
52 /// This structure contains the metadata of an image, including its buffer
53 /// transform, resolution, and border properties.
54 struct IMX_Stat
55 {
58 
59  CEfloatD<CE_32> myBufferToImage[4] = {0, 0, 0, 0};
60  CEfloatD<CE_32> myImageToBuffer[4] = {0, 0, 0, 0};
61  CEfloatD<CE_32> myBufferToPixel[4] = {0, 0, 0, 0};
62 
63  CEfloatD<CE_32> myDefaultFColor[4] = {0, 0, 0, 0};
64  CEintD<CE_32> myDefaultIColor[4] = {0, 0, 0, 0};
65 
67  int myChannels = 0;
68  int myStrideX = 0;
69  int myStrideY = 0;
70 
73  CE_Image::StorageType myStorage = CE_Image::StorageType::FLOAT16;
74 
75  bool operator==(const IMX_Stat& other) const
76  {
77  for (int i = 0; i < 4; i++)
78  {
79  if (myBufferToImage[i] != other.myBufferToImage[i] ||
80  myImageToBuffer[i] != other.myImageToBuffer[i] ||
81  myBufferToPixel[i] != other.myBufferToPixel[i] ||
82  myDefaultFColor[i] != other.myDefaultFColor[i] ||
83  myDefaultIColor[i] != other.myDefaultIColor[i])
84  {
85  return false;
86  }
87  }
88 
89  if (myImageToWorld != other.myImageToWorld ||
91  {
92  return false;
93  }
94 
95  if (myResolution[0] != other.myResolution[0] ||
96  myResolution[1] != other.myResolution[1])
97  {
98  return false;
99  }
100 
101  if (myChannels != other.myChannels ||
102  myStrideX != other.myStrideX ||
103  myStrideY != other.myStrideY ||
104  myBorder != other.myBorder ||
105  myTypeInfo != other.myTypeInfo ||
106  myStorage != other.myStorage)
107  {
108  return false;
109  }
110 
111  return true;
112  }
113 
114  bool operator!=(const IMX_Stat& other) const
115  {
116  return !(*this == other);
117  }
118 };
119 
120 /// The traditional allocator will align to the size of the type, which in this
121 /// case is char - however, in order to maximize the chances of vectorized
122 /// instructions being generated, we'll align to the size of the cache line.
123 ///
124 /// Note: We don't have a cross-platform method to determine the size of the
125 /// cache line, so we'll just assume 64 bytes.
127 {
128 public:
129  explicit IMX_CPU_Image() = default;
130 
131  explicit IMX_CPU_Image(const exint size)
132  : myData((uint8*)SYSamalloc(size, ALIGNMENT))
133  , myDataSize(size)
134  , myStorageMode(StorageMode::STORE_ALIGNED)
135  {
136  }
137 
139  {
141  (uint8*)SYSamalloc(other.myDataSize, ALIGNMENT), other.myDataSize);
142  memcpy(myData, other.myData, other.myDataSize);
143  }
144 
145  IMX_CPU_Image(IMX_CPU_Image &&other) noexcept
146  : myData(other.myData)
147  , myDataSize(other.myDataSize)
148  , myStorageMode(other.myStorageMode)
149  {
150  other.myData = nullptr;
151  other.myDataSize = 0;
152  other.myStorageMode = StorageMode::STORE_UNDEFINED;
153  }
154 
156  {
158  (uint8*)SYSamalloc(other.myDataSize, ALIGNMENT), other.myDataSize);
159  memcpy(myData, other.myData, other.myDataSize);
160  return *this;
161  }
162 
164  {
165  freeData();
166 
167  myData = (uint8*)data;
168  myDataSize = size;
169  myStorageMode = StorageMode::STORE_ALIGNED;
170  }
171 
172  void adoptFromMalloc(void *data, const exint size)
173  {
174  freeData();
175 
176  myData = (uint8*)data;
177  myDataSize = size;
178  myStorageMode = StorageMode::STORE_MALLOC;
179  }
180 
181  void adoptFromNew(void *data, const exint size)
182  {
183  freeData();
184 
185  myData = (uint8*)data;
186  myDataSize = size;
187  myStorageMode = StorageMode::STORE_NEW;
188  }
189 
191  {
192  freeData();
193  }
194 
195  /// The buffer data. It's the user's responsibility to interpret this in
196  /// the correct data type. The IMX_CPU_Image retains ownership of this
197  /// buffer.
198  void *data() const { return myData; }
199 
200  /// The size of the buffer data in bytes.
201  exint size() const { return myDataSize; }
202 private:
203  const int ALIGNMENT = 64; // bytes
204 
205  enum class StorageMode
206  {
208  STORE_NEW,
209  STORE_MALLOC,
211  };
212 
213  void freeData()
214  {
215  if (!myData)
216  return;
217 
218  switch (myStorageMode)
219  {
220  case StorageMode::STORE_MALLOC: free(myData); break;
221  case StorageMode::STORE_NEW: delete[] myData; break;
222  case StorageMode::STORE_ALIGNED: SYSafree(myData); break;
224  default: UT_ASSERT(0 && "Unknown storage mode");
225  }
226 
227  myStorageMode = StorageMode::STORE_UNDEFINED;
228  myData = nullptr;
229  myDataSize = 0;
230  }
231 
232  uint8 *myData = nullptr;
233  exint myDataSize = 0; // bytes
234  StorageMode myStorageMode = StorageMode::STORE_UNDEFINED;
235 };
236 
237 /// The per-pixel data for a single IMX_Layer
238 ///
239 /// Buffer has several formats to store data in, for instance whether it is on the
240 /// GPU or CPU. Buffers are converted by copying, or snippets are used to change the
241 /// OpenCL code reading them. As some translators can work in-place, the format is
242 /// considered a setting of the Buffer, rather than having different Buffer
243 /// subclasses for each format.
244 ///
245 /// This is a first working version of such a buffer, though it's missing a lot
246 /// of features. There's only one supported format (32-bit float), between 1 and
247 /// 4 channels. This is stored in an array, flattened over the rows first. There
248 /// is also GPU storage that this buffer uses. States of these buffers (i.e. do
249 /// they contain up-to-date information?) are encoded in the two boolean flags
250 /// (myOnCPU and myOnGPU). When the user asks IMX_Buffer
251 /// something that must access its storage, that storage is first automatically
252 /// synchronized before the request is fulfilled.
253 
255 {
256  friend class IMX_Layer;
257  friend class COP_OpenFXImage;
258 public:
259  /// Creates a new buffer. You must call setSize to make this buffer usable.
260  IMX_Buffer();
261  /// Create and call setSize
263  IMX_Buffer(const IMX_Buffer &other) { copy(other); }
264  IMX_Buffer(IMX_Buffer && other) noexcept { swap(other); }
265  IMX_Buffer(const PXL_Raster &rp);
266  ~IMX_Buffer();
267 
268  /// Copy everything except the buffer allocations, leaving the buffers dirty.
269  /// This avoids any chance that writing pixels to this will modify the original.
270  /// It also avoids shared pointer overhead and keeping buffers around longer than needed.
271  void copyMetadata(const IMX_Buffer& source);
272 
273  /// Set storesIntegers, bytes, channels
275  { setStorageType(i.getStorageType(), i.getChannels()); }
276  /// Set storesIntegers, bytes, channels
277  void setStorageType(CE_Image::StorageType storage, int channels);
278  /// Set storesIntegers, bytes
279  void setStorageType(CE_Image::StorageType storage);
280  /// Set number of bytes per channel, don't change storesIntegers or channels
281  void setStorageBytes(int);
282  /// Set channels, don't change storesIntegers or bits
283  void setChannels(int channels);
284  /// Get the data type used to store pixel data for each channel.
285  CE_Image::StorageType getStorageType() const { return myCPUStat.myStorage; }
286  /// Does this buffer store integers?
287  bool storesIntegers() const { return CE_Image::storesIntegers(myCPUStat.myStorage); }
288  /// Get the number of channels per pixel.
289  int getChannels() const { return myCPUStat.myChannels; }
290  /// Number of bytes per channel
291  int getStorageBytes() const { return CE_Image::getBytes(myCPUStat.myStorage); }
292 
293  /// Sets size of this buffer.
294  void setBufferSize(int width, int height);
295  /// Get width (number of columns in a row) of the buffer.
296  int bufferWidth() const { return myCPUStat.myResolution[0]; }
297  /// Get height (number of rows) of the buffer.
298  int bufferHeight() const { return myCPUStat.myResolution[1]; }
299  /// Returns the number of bytes required to store the entire buffer.
300  int64 getBufferSize() const;
301 
302  /// Set transform between image and buffer space
303  void setBufferXforms(
304  const UT_Vector2F &buffer_to_image_scale,
305  const UT_Vector2F &buffer_to_image_xlate,
306  const UT_Vector2F &buffer_from_image_scale,
307  const UT_Vector2F &buffer_from_image_xlate,
308  const UT_Vector2F &buffer_to_pixel_scale,
309  const UT_Vector2F &buffer_to_pixel_xlate,
310  const UT_Matrix4F &image_to_world,
311  const UT_Matrix4F &world_to_image
312  );
313 
314  /// Sets the border type of this image. Constant means it is zero.
315  void setBorder(IMX_BorderType border);
316  /// Returns type of the border.
317  IMX_BorderType getBorderType() const;
318 
319  /// Sets the semantic type info of this image.
320  void setTypeInfo(IMX_TypeInfo typeinfo);
321  /// Returns type of the border.
322  IMX_TypeInfo getTypeInfo() const;
323 
324  /// Set the default color. This is returned for uncalculatable pixels, and
325  /// to expand integer vectors from 2,3 to 4. Other usage is not yet
326  /// determined. Initial value is 0,0,0,1 (may change)
327  void setDefaultColor(const UT_Vector4F&);
328  UT_Vector4F getDefaultColor() const;
329  /// return the current integer value, which might be different
330  UT_Vector4I getDefaultColorI() const;
331 
332  /// Assignment operators; after executing these functions, this buffer will
333  /// have the same size and data as other.
334  void copy(const IMX_Buffer &other);
335  IMX_Buffer &operator=(const IMX_Buffer &other) { copy(other); return *this; }
336  /// Deep copy operator. Unlike copy() (which shares the buffers of the
337  /// source), this version allocates a new buffer and copies the data into
338  /// it.
339  /// This can throw CE exceptions.
340  void deepCopy(const IMX_Buffer &other);
341 
342  void swap(IMX_Buffer &other);
343  IMX_Buffer &operator=(IMX_Buffer &&other) { swap(other); return *this; }
344 
345  /// True if data in this buffer may be stolen from (or changed) by the verbs
346  /// even if it's an input.
347  bool stealable() const { return myStealable; }
348  /// Can be used to control what stealable() subsequently returns. If set to
349  /// true, indicates to the verbs that this buffer may be stolen from.
350  void setStealable(bool v) const { myStealable = v; }
351  /// True if the buffer pixels line up: width and the transforms from image space match.
352  bool isAligned(const IMX_Buffer &src) const;
353 
354  /// Only copy the buffer pointers, the stat data is left unchanged
355  void copyBuffer(const IMX_Buffer &other);
356  /// Move the buffer to this from src, src is left dirty
357  void moveBuffer(IMX_Buffer &src);
358  /// Stop sharing the buffers (so that writes don't affect other layers that
359  /// have called copyBuffer() on this or vice versa).
360  void makeBufferUnique();
361 
362  /// Adopt a PXL_Raster into the underlying IMX_Buffer. The buffer's storage
363  /// type and number of channels must be set before calling.
364  /// Steals the PXL_Raster data if compatible.
365  /// Does OCIO transform from raster's space to scene linear if
366  /// convert is set.
367  void adoptRaster(PXL_Raster &raster, bool convert_colorspace);
368 
369  /// copy the buffer, converting betwen storage types if needed and doing a shallow copy
370  /// if possible
371  void copyOrConvert(const IMX_Buffer& other);
372 
373  /// Constructs a TIL_Raster matching our storage/channel depth.
374  /// Will be packed.
375  /// TIL_Raster is subclass from PXL_Raster.
376  UT_UniquePtr<TIL_Raster> buildRaster() const;
377 
378  /// for debugging
379  const UT_SharedPtr<IMX_CPU_Image> & CPUBufferPtr() const { return myCPUBuffer; }
380  const UT_SharedPtr<CE_Image> & GPUBufferPtr() const { return myGPUBuffer; }
381 
382  /// Sets an individual pixel.
383  void setPixelV4(int x, int y, const UT_Vector4F& c)
384  {
385  setPixelV4Internal(x, y, c, true);
386  }
387  void setPixelF(int x, int y, fpreal32 i)
388  {
389  setPixelV4Internal(x, y, UT_Vector4F(i, i, i, i), true);
390  }
391  void setPixelI(int x, int y, int i)
392  {
393  setPixelIInternal(x, y, i, true);
394  }
395 
396  /// Fetches the value of an individual pixel.
397  UT_Vector4F getPixelV4(int x, int y) const;
398  int getPixelI(int x, int y) const;
399  /// Fetches the value at the provided coordinates, using bilinear filtering.
400  /// Returns value of the nearest pixel for integer buffers.
401  UT_Vector4F getPixelV4(fpreal64 x, fpreal64 y) const;
402 
403  /// Return pointer to CPU buffer (caller must ask for correct data type)
404  /// If a read buffer is requested and this buffer is constant, the buffer
405  /// will be compressed (i.e. of size equal to the number of channels)!
406  const fpreal16* getCPUBufferRF16() const { return getCPUBufferR<CE_Image::FLOAT16>(); }
407  fpreal16* getCPUBufferWF16() { return getCPUBuffer<CE_Image::FLOAT16>(false,true); }
408  const fpreal32* getCPUBufferRF32() const { return getCPUBufferR<CE_Image::FLOAT32>(); }
409  fpreal32* getCPUBufferWF32() { return getCPUBuffer<CE_Image::FLOAT32>(false,true); }
410  const unsigned char* getCPUBufferRI8() const { return getCPUBufferR<CE_Image::INT8>(); }
411  unsigned char* getCPUBufferWI8() { return getCPUBuffer<CE_Image::INT8>(false,true); }
412  const int16* getCPUBufferRI16() const { return getCPUBufferR<CE_Image::INT16>(); }
413  int16* getCPUBufferWI16() { return getCPUBuffer<CE_Image::INT16>(false,true); }
414  const int32* getCPUBufferRI32() const { return getCPUBufferR<CE_Image::INT32>(); }
415  int32* getCPUBufferWI32() { return getCPUBuffer<CE_Image::INT32>(false,true); }
416  /// Returns a void pointer to the CPU buffer.
417  /// If a read-only buffer is requested and this buffer is constant, the
418  /// buffer will be compressed (i.e. of size equal to the number of
419  /// channels)!
420  void* getCPUBuffer(bool read, bool write)
421  { return getCPUBufferInternal(read, write, write); }
422  /// Returns this buffer's read-only data array.
423  /// If this buffer is constant, the buffer will be compressed (i.e. of size
424  /// equal to the number of channels)!
425  template <CE_Image::StorageType STORAGE>
427  {
428  return cast<STORAGE>(getCPUBufferRInternal());
429  }
430 
431  /// Returns this buffer's data array. If read is true, isDirty must
432  /// be false. If write is true then it turns off isDirty by setting
433  /// isOnCPU() and turning off isOnGPU() (it is assuming caller will actually
434  /// write the buffer)
435  /// If a read-only buffer is requested and this buffer is constant, the
436  /// buffer will be compressed (i.e. of size equal to the number of
437  /// channels)!
438  template <CE_Image::StorageType STORAGE>
439  typename CE_StorageTypeTraits<STORAGE>::DataType *getCPUBuffer(bool read, bool write)
440  {
441  return cast<STORAGE>(getCPUBufferInternal(read, write, write));
442  }
443 
444  /// Returns this buffer's GPU storage object. If read is true, isDirty must
445  /// be false. If write is true then it turns off isDirty by setting
446  /// isOnGPU() and turning off isOnCPU() (it is assuming caller will actually
447  /// write the buffer)
448  /// When using one of these methods, this buffer must be guarded with the
449  /// in-use GPU flag. See setInUseGPUFlag() documentation for more
450  /// information.
451  /// Can throw CE exceptions.
452  CE_Image &getGPUBuffer(bool read, bool write);
453  const CE_Image &getGPUBufferR() const;
454  CE_Image &getGPUBufferW() { return getGPUBuffer(false, true); }
455 
456  /// Returns true if this buffer's data is currently on the GPU.
457  bool isOnGPU() const
458  {
459  return myOnGPU;
460  }
461 
462  /// Returns true if this buffer's data is currently on the CPU (this is not
463  /// necessarily !isOnGPU()).
464  bool isOnCPU() const
465  {
466  return myOnCPU;
467  }
468 
469  /// Returns whether the GPU data for this image is currently being used by
470  /// someone.
471  bool isInUseGPU() const
472  {
473  return myGPUInUseCount.relaxedLoad() != 0;
474  }
475  /// Increments the user count of our GPU data. If there are no active users
476  /// of the GPU data, the memory pool will be able to unload the buffer.
477  /// When using one of the getGPUBuffer() methods, the in-use GPU flag must
478  /// be set to prevent the GPU data from getting unloaded:
479  /// // Set the in-use flag before grabbing the GPU buffer.
480  /// buffer.setInUseGPUFlag();
481  /// CE_Image& img = buffer.getGPUBufferW();
482  /// // Do stuff with the CE_Image (i.e. queue up an OpenCL command with
483  /// // it, can be asynchronous).
484  /// ...
485  /// // Flip the flag that we set earlier.
486  /// buffer.clearInUseGPUFlag();
487  void setInUseGPUFlag() const
488  {
489  myGPUInUseCount.add(1);
490  }
491  /// Decrements the user count of our GPU data. If there are no active users
492  /// of the GPU data, the memory pool will be able to unload this buffer.
493  /// See setInUseGPUFlag() documentation for how these methods must be used.
494  /// This method also refreshes the buffer in the eyes of the memory pool,
495  /// making it less likely to get evicted.
496  void clearInUseGPUFlag() const;
497 
498  /// Returns the stat buffer on the GPU, copying it there if necessary.
499  /// This can throw CE exceptions.
500  cl::Buffer getGPUStat() const;
501 
502  /// False if there are computed pixels in the CPU or GPU buffer
503  bool isDirty() const { return !myOnGPU && !myOnCPU; }
504  /// Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true
505  void setDirty() { myOnGPU = myOnCPU = myIsConstant = false; }
506  /// Frees the pixel memory (also does setDirty())
507  void freeBuffers();
508  /// Frees all the memory used by buffer
509  void destroy();
510  /// True if getCPU/GPUBuffer has been done since last freeBuffers()
511  bool allocated() const { return myCPUBuffer || myGPUBuffer; }
512 
513  /// Make entire image the same color. This is optimized internally to a 1x1
514  /// buffer
515  void setConstantV4(const UT_Vector4F &i);
516  void setConstantV3(const UT_Vector3F &i) { setConstantV4(UT_Vector4F(i, 1)); }
517  void setConstantF(fpreal32 i = 0.0f) { setConstantV4(UT_Vector4F(i, i, i, i)); }
518  void setConstantI(int32 i = 0);
519 
520  /// Marks that this buffer is not initialized. This means that when a read
521  /// buffer is requested, we won't bother doing any copying or data
522  /// validation. This is useful if you bind this as a read-write layer to a
523  /// kernel, but will be doing the initialization in the same kernel. Copying
524  /// from an unitialized buffer will inherit this flag without moving any
525  /// data. This flag gets cleared when someone writes to this buffer.
526  void setUninitialized() { myIsUninitialized = true; }
527 
528  bool isConstant() const { return myIsConstant; }
529 
530  /// Resizes dest to match dimensions of this image (its Z-resolution is set
531  /// to 1) and copies this buffer's data into it. Number of channels in the
532  /// image should equal tuple size of T.
533  /// If this layer is dirty, simply sizes the voxel array without touching
534  /// its values.
535  template <typename T>
536  void matchAndCopyToVoxels(UT_VoxelArray<T>& dest) const;
537 
538 private:
539  /// Initialize all the fields (used by constructors)
540  void init(int width, int height, CE_Image::StorageType storage, int channels);
541 
542  /// Gets the CPU buffer, allocate and/or copy the GPU one if necessary. If
543  /// expand_constant is true and this buffer is constant, the storage will be
544  /// uncompressed before returning a pointer.
545  void *getCPUBufferInternal(bool read, bool write, bool expand_constant);
546  void *getCPUBufferRInternal() const;
547  void *getCPUBufferW()
548  {
549  return getCPUBufferInternal(false, true, true);
550  }
551  /// Internal methods to set the pixel value. If expand_constant is true and
552  /// this buffer is constant, the storage will be uncompressed first,
553  /// retaining any previous data.
554  void setPixelV4Internal(int x, int y, const UT_Vector4F& val,
555  bool expand_constant);
556  void setPixelIInternal(int x, int y, int val, bool expand_constant);
557 
558  /// Queues up commands that transfer this buffer's GPU storage to main
559  /// memory. TODO: this is non-blocking, make sure that's okay...
560  void unloadFromGPU();
561 
562  /// Cast void* pointer to correct type for storage. Includes an assert to make
563  /// sure the storage type is the same one this buffer is using.
564  template <CE_Image::StorageType STORAGE>
566  cast(void *p)
567  {
568  UT_ASSERT(STORAGE == myCPUStat.myStorage);
569  return (typename CE_StorageTypeTraits<STORAGE>::DataType *) p;
570  }
571  template <CE_Image::StorageType STORAGE>
573  cast(const void *p) const
574  {
575  UT_ASSERT(STORAGE == myCPUStat.myStorage);
576  return (const typename CE_StorageTypeTraits<STORAGE>::DataType *) p;
577  }
578 
579  UT_SharedPtr<IMX_CPU_Image> myCPUBuffer;
580  /// All changes to this member (the shared pointer) must be done by the
581  /// memory pool!!!
582  UT_SharedPtr<CE_Image> myGPUBuffer;
583 
584  /// CPU version of the stat buffer; this is always assumed to be clean.
585  IMX_Stat myCPUStat;
586  /// GPU backing of stat buffer.
587  mutable cl::Buffer myGPUStat;
588  mutable bool myGPUStatClean = false;
589 
590  /// This pair of flags hold the state of data that lives in the two storage
591  /// spots.
592  bool myOnCPU = false;
593  bool myOnGPU = false;
594 
595  /// Number of current users of the GPU memory from this buffer.
596  mutable SYS_AtomicInt32 myGPUInUseCount;
597 
598  /// If true only allocate a 1x1 buffer
599  bool myIsConstant = false;
600  /// If true, we won't actually do any data copying or validation when a read
601  /// is requested.
602  bool myIsUninitialized = false;
603  /// Can data of this buffer be stolen by the verbs? TODO: who should reset
604  /// this and when?
605  mutable bool myStealable = true;
606 
607  friend class IMX_CEMemoryPool;
608 };
609 
610 /// Returns the label for the supplied border type
IMX_Buffer & operator=(const IMX_Buffer &other)
Definition: IMX_Buffer.h:335
fpreal16 * getCPUBufferWF16()
Definition: IMX_Buffer.h:407
CE_Image & getGPUBufferW()
Definition: IMX_Buffer.h:454
int int32
Definition: SYS_Types.h:39
CE_StorageTypeTraits< STORAGE >::DataType * getCPUBuffer(bool read, bool write)
Definition: IMX_Buffer.h:439
static bool storesIntegers(StorageType t)
Definition: CE_Image.h:38
bool operator==(const IMX_Stat &other) const
Definition: IMX_Buffer.h:75
const UT_SharedPtr< CE_Image > & GPUBufferPtr() const
Definition: IMX_Buffer.h:380
CEfloatD< CE_32 > myImageToBuffer[4]
Definition: IMX_Buffer.h:60
bool isOnCPU() const
Definition: IMX_Buffer.h:464
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
int myStrideX
Definition: IMX_Buffer.h:68
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
IMX_Buffer(const IMX_Buffer &other)
Definition: IMX_Buffer.h:263
const unsigned char * getCPUBufferRI8() const
Definition: IMX_Buffer.h:410
int64 exint
Definition: SYS_Types.h:125
void SYSafree(void *p)
Definition: SYS_Align.h:105
CEfloatD< CE_32 > myBufferToImage[4]
Definition: IMX_Buffer.h:59
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7172
void * SYSamalloc(size_t b)
Definition: SYS_Align.h:103
GLint y
Definition: glcorearb.h:103
void setStealable(bool v) const
Definition: IMX_Buffer.h:350
IMX_TypeInfo myTypeInfo
Definition: IMX_Buffer.h:72
void adoptFromMalloc(void *data, const exint size)
Definition: IMX_Buffer.h:172
void * getCPUBuffer(bool read, bool write)
Definition: IMX_Buffer.h:420
int16 * getCPUBufferWI16()
Definition: IMX_Buffer.h:413
IMX_CPU_Image(const IMX_CPU_Image &other)
Definition: IMX_Buffer.h:138
float fpreal32
Definition: SYS_Types.h:200
void setPixelF(int x, int y, fpreal32 i)
Definition: IMX_Buffer.h:387
IMX_CPU_Image & operator=(const IMX_CPU_Image &other)
Definition: IMX_Buffer.h:155
IMX_API size_t format(char *buffer, size_t buffer_size, const IMX_BorderType &v)
void setUninitialized()
Definition: IMX_Buffer.h:526
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void * data() const
Definition: IMX_Buffer.h:198
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
IMX_CPU_Image()=default
int bufferHeight() const
Get height (number of rows) of the buffer.
Definition: IMX_Buffer.h:298
CE_Image::StorageType getStorageType() const
Get the data type used to store pixel data for each channel.
Definition: IMX_Buffer.h:285
UT_Matrix4F myWorldToImage
Definition: IMX_Buffer.h:57
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLfloat f
Definition: glcorearb.h:1926
IMX_BorderType
Controls returned values for coordinates that fall outside the image.
Definition: IMX_Buffer.h:27
Definition: core.h:760
SYS_FORCE_INLINE const X * cast(const InstancablePtr *o)
void setDirty()
Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true.
Definition: IMX_Buffer.h:505
fpreal32 * getCPUBufferWF32()
Definition: IMX_Buffer.h:409
IMX_TypeInfo
Definition: IMX_Buffer.h:36
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:343
void setPixelV4(int x, int y, const UT_Vector4F &c)
Sets an individual pixel.
Definition: IMX_Buffer.h:383
void adoptFromAlignedMalloc(void *data, const exint size)
Definition: IMX_Buffer.h:163
int myChannels
Definition: IMX_Buffer.h:67
CEintD< CE_32 > myResolution[2]
Definition: IMX_Buffer.h:66
#define SYS_FALLTHROUGH
Definition: SYS_Compiler.h:68
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
exint size() const
The size of the buffer data in bytes.
Definition: IMX_Buffer.h:201
int getChannels() const
Get the number of channels per pixel.
Definition: IMX_Buffer.h:289
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
const int32 * getCPUBufferRI32() const
Definition: IMX_Buffer.h:414
IMX_CPU_Image(IMX_CPU_Image &&other) noexcept
Definition: IMX_Buffer.h:145
bool isInUseGPU() const
Definition: IMX_Buffer.h:471
bool isDirty() const
False if there are computed pixels in the CPU or GPU buffer.
Definition: IMX_Buffer.h:503
GLint GLenum GLint x
Definition: glcorearb.h:409
const fpreal32 * getCPUBufferRF32() const
Definition: IMX_Buffer.h:408
void setConstantV3(const UT_Vector3F &i)
Definition: IMX_Buffer.h:516
bool isOnGPU() const
Returns true if this buffer's data is currently on the GPU.
Definition: IMX_Buffer.h:457
void setConstantF(fpreal32 i=0.0f)
Definition: IMX_Buffer.h:517
int myStrideY
Definition: IMX_Buffer.h:69
IMX_BorderType myBorder
Definition: IMX_Buffer.h:71
void copyStorageType(const IMX_Buffer &i)
Set storesIntegers, bytes, channels.
Definition: IMX_Buffer.h:274
GLsizeiptr size
Definition: glcorearb.h:664
const UT_SharedPtr< IMX_CPU_Image > & CPUBufferPtr() const
for debugging
Definition: IMX_Buffer.h:379
const fpreal16 * getCPUBufferRF16() const
Definition: IMX_Buffer.h:406
GLint GLint GLsizei GLint border
Definition: glcorearb.h:108
UT_Vector4T< fpreal32 > UT_Vector4F
void adoptFromNew(void *data, const exint size)
Definition: IMX_Buffer.h:181
const CE_StorageTypeTraits< STORAGE >::DataType * getCPUBufferR() const
Definition: IMX_Buffer.h:426
StorageType
Definition: CE_Image.h:27
IMX_CPU_Image(const exint size)
Definition: IMX_Buffer.h:131
short int16
Definition: SYS_Types.h:37
void setInUseGPUFlag() const
Definition: IMX_Buffer.h:487
bool operator!=(const IMX_Stat &other) const
Definition: IMX_Buffer.h:114
GLuint GLfloat * val
Definition: glcorearb.h:1608
int getStorageBytes() const
Number of bytes per channel.
Definition: IMX_Buffer.h:291
bool isConstant() const
Definition: IMX_Buffer.h:528
bool allocated() const
True if getCPU/GPUBuffer has been done since last freeBuffers()
Definition: IMX_Buffer.h:511
Memory buffer interface.
Definition: cl.hpp:1867
GLint GLsizei width
Definition: glcorearb.h:103
#define IMX_API
Definition: IMX_API.h:8
static int getBytes(StorageType t)
Definition: CE_Image.h:39
int bufferWidth() const
Get width (number of columns in a row) of the buffer.
Definition: IMX_Buffer.h:296
UT_Matrix4F myImageToWorld
Definition: IMX_Buffer.h:56
typename CE_PrecisionResolver< P >::device_float_type CEfloatD
Definition: CE_Precision.h:63
bool storesIntegers() const
Does this buffer store integers?
Definition: IMX_Buffer.h:287
int32 * getCPUBufferWI32()
Definition: IMX_Buffer.h:415
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
void setPixelI(int x, int y, int i)
Definition: IMX_Buffer.h:391
CEfloatD< CE_32 > myBufferToPixel[4]
Definition: IMX_Buffer.h:61
bool stealable() const
Definition: IMX_Buffer.h:347
IMX_Buffer(IMX_Buffer &&other) noexcept
Definition: IMX_Buffer.h:264
unsigned char * getCPUBufferWI8()
Definition: IMX_Buffer.h:411
CEfloatD< CE_32 > myDefaultFColor[4]
Definition: IMX_Buffer.h:63
const int16 * getCPUBufferRI16() const
Definition: IMX_Buffer.h:412
Definition: format.h:895
CEintD< CE_32 > myDefaultIColor[4]
Definition: IMX_Buffer.h:64
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:64
CE_Image::StorageType myStorage
Definition: IMX_Buffer.h:73
GLenum src
Definition: glcorearb.h:1793