HDK
|
#include <IMX_Buffer.h>
Public Member Functions | |
IMX_Buffer () | |
Creates a new buffer. You must call setSize to make this buffer usable. More... | |
IMX_Buffer (int width, int height, CE_Image::StorageType storage, int channels) | |
Create and call setSize. More... | |
IMX_Buffer (const IMX_Buffer &other) | |
IMX_Buffer (IMX_Buffer &&other) noexcept | |
IMX_Buffer (const PXL_Raster &rp) | |
~IMX_Buffer () override | |
EntryType | poolTypeID () const override |
void | copyMetadata (const IMX_Buffer &source) |
void | copyStorageType (const IMX_Buffer &i) |
Set storesIntegers, isFixedPoint, bytes, channels. More... | |
void | setStorageType (CE_Image::StorageType storage, int channels) |
Set storesIntegers, isFixedPoint, bytes, channels. More... | |
void | setStorageType (CE_Image::StorageType storage) |
Set storesIntegers, isFixedPoint, bytes. More... | |
void | setStorageBytes (int) |
void | setStorageBytes (int, bool) |
void | setChannels (int channels) |
Set channels, don't change storesIntegers, isFixedPoint, or bytes. More... | |
CE_Image::StorageType | getStorageType () const |
Get the data type used to store pixel data for each channel. More... | |
bool | storesIntegers () const |
Does this buffer store integers? More... | |
bool | isFixedPoint () const |
Does this buffer use fixed point to store non-integer data? More... | |
int | getChannels () const |
Get the number of channels per pixel. More... | |
int | getStorageBytes () const |
Number of bytes per channel. More... | |
void | setBufferSize (int width, int height) |
Sets size of this buffer. More... | |
exint | bufferWidth () const |
Get width (number of columns in a row) of the buffer. More... | |
exint | bufferHeight () const |
Get height (number of rows) of the buffer. More... | |
int64 | getBufferSize () const |
Returns the number of bytes required to store the entire buffer. More... | |
void | setBufferXforms (const UT_Vector2F &buffer_to_image_scale, const UT_Vector2F &buffer_to_image_xlate, const UT_Vector2F &buffer_from_image_scale, const UT_Vector2F &buffer_from_image_xlate, const UT_Vector2F &buffer_to_pixel_scale, const UT_Vector2F &buffer_to_pixel_xlate, const UT_Matrix4F &image_to_world, const UT_Matrix4F &world_to_image, const UT_Matrix4F &camera_to_world, const UT_Vector3F &camera_image_pos) |
Set transform between image and buffer space. More... | |
void | setBorder (IMX_BorderType border) |
Sets the border type of this image. Constant means it is zero. More... | |
IMX_BorderType | getBorderType () const |
Returns type of the border. More... | |
void | setTypeInfo (IMX_TypeInfo typeinfo) |
Sets the semantic type info of this image. More... | |
IMX_TypeInfo | getTypeInfo () const |
Returns the semantic type. More... | |
void | setStatProjection (IMX_Projection projection) |
IMX_Projection | statProjection () const |
Returns the projection type. More... | |
void | setDefaultColor (const UT_Vector4F &) |
UT_Vector4F | getDefaultColor () const |
UT_Vector4I | getDefaultColorI () const |
return the current integer value, which might be different More... | |
void | copy (const IMX_Buffer &other) |
IMX_Buffer & | operator= (const IMX_Buffer &other) |
void | deepCopy (const IMX_Buffer &other) |
void | swap (IMX_Buffer &other) |
IMX_Buffer & | operator= (IMX_Buffer &&other) |
bool | stealable () const |
void | setStealable (bool v) const |
bool | isAligned (const IMX_Buffer &src) const |
True if the buffer pixels line up: width and the transforms from image space match. More... | |
void | copyBuffer (const IMX_Buffer &other) |
Only copy the buffer pointers, the stat data is left unchanged. More... | |
void | moveBuffer (IMX_Buffer &src) |
Move the buffer to this from src, src is left dirty. More... | |
void | makeBufferUnique () |
void | adoptRaster (PXL_Raster &raster, bool convert_colorspace) |
void | copyOrConvert (const IMX_Buffer &other) |
bool | extract (void *dst, exint dstsize, CE_Image::StorageType dststorage, int dstchannels) const |
bool | insert (const void *src, exint srcsize, CE_Image::StorageType srcstorage, int srcchannels) |
UT_UniquePtr< TIL_Raster > | buildRaster () const |
const UT_SharedPtr < CE_BufferHostByte > & | CPUBufferPtr () const |
for debugging More... | |
const UT_SharedPtr< CE_Image > & | GPUBufferPtr () const |
void | setPixelV4 (int x, int y, const UT_Vector4F &c) |
Sets an individual pixel. More... | |
void | setPixelF (int x, int y, fpreal32 i) |
void | setPixelI (int x, int y, int i) |
UT_Vector4F | getPixelV4 (int x, int y) const |
Fetches the value of an individual pixel. More... | |
int | getPixelI (int x, int y) const |
UT_Vector4F | getPixelV4 (fpreal64 x, fpreal64 y) const |
void | getPixelRaw (UT_Array< uint8 > &dest, int x, int y) const |
const int16 * | getCPUBufferRFixed16 () const |
int16 * | getCPUBufferWFixed16 () |
const uint8 * | getCPUBufferRFixed8 () const |
uint8 * | getCPUBufferWFixed8 () |
const fpreal16 * | getCPUBufferRF16 () const |
fpreal16 * | getCPUBufferWF16 () |
const fpreal32 * | getCPUBufferRF32 () const |
fpreal32 * | getCPUBufferWF32 () |
const unsigned char * | getCPUBufferRI8 () const |
unsigned char * | getCPUBufferWI8 () |
const int16 * | getCPUBufferRI16 () const |
int16 * | getCPUBufferWI16 () |
const int32 * | getCPUBufferRI32 () const |
int32 * | getCPUBufferWI32 () |
void * | getCPUBuffer (bool read, bool write) |
void * | getCPUBufferR () const |
void * | getCPUBufferW () |
template<CE_Image::StorageType STORAGE> | |
const CE_StorageTypeTraits < STORAGE >::DataType * | getCPUBufferR () const |
template<CE_Image::StorageType STORAGE> | |
CE_StorageTypeTraits< STORAGE > ::DataType * | getCPUBuffer (bool read, bool write) |
CE_Image & | getGPUBuffer (bool read, bool write) |
const CE_Image & | getGPUBufferR () const |
CE_Image & | getGPUBufferW () |
bool | isOnGPU () const |
Returns true if this buffer's data is currently on the GPU. More... | |
bool | isOnCPU () const |
cl::Buffer | getGPUStat () const |
bool | isDirty () const |
False if there are computed pixels in the CPU or GPU buffer. More... | |
void | freeBuffers () |
Frees the pixel memory (also does setDirty()) More... | |
void | destroy () |
Frees all the memory used by buffer. More... | |
bool | allocated () const |
True if getCPU/GPUBuffer has been done since last freeBuffers() More... | |
void | setConstantV4 (const UT_Vector4F &i) |
void | setConstantV3 (const UT_Vector3F &i) |
void | setConstantF (fpreal32 i=0.0f) |
void | setConstantI (int32 i=0) |
void | setUninitialized () |
bool | isConstant () const |
bool | validateBuffer () const |
template<typename T > | |
void | matchAndCopyToVoxels (UT_VoxelArray< T > &dest) const |
int64 | getMemoryUsage () const |
int64 | getDeviceMemoryUsage () const |
![]() | |
IMX_PoolEntry () | |
Creates a new buffer. You must call setSize to make this buffer usable. More... | |
virtual | ~IMX_PoolEntry () |
IMX_PoolEntry (const IMX_PoolEntry &)=delete | |
IMX_PoolEntry & | operator= (const IMX_PoolEntry &)=delete |
bool | isInUseGPU () const |
void | setInUseGPUFlag () const |
void | clearInUseGPUFlag () const |
Protected Member Functions | |
void | poolResetGPUBuffer () override |
These implement methods required by the pool. More... | |
void | poolSetOnGPU (bool ongpu) override |
Update OnGPU. More... | |
bool | poolIsGPUBufferEmpty () const override |
True if the gpu buffer is null. More... | |
bool | poolIsGPUBufferValid () const override |
True if the gpu buffer is not null and valid. More... | |
bool | poolSwapGPUBuffer (IMX_PoolEntry *otherbase) override |
True if the swap does something. More... | |
void | poolShallowCopyGPUBuffer (const IMX_PoolEntry *srcbase) override |
Shallow copy. More... | |
Friends | |
class | IMX_Layer |
class | IMX_CEMemoryPool |
Additional Inherited Members | |
![]() | |
enum | EntryType { EntryType::BUFFER = 0, EntryType::VDB } |
To avoid the need for dynamic casts: More... | |
![]() | |
int | myGPUInUseCount = 0 |
The per-pixel data for a single IMX_Layer
Buffer has several formats to store data in, for instance whether it is on the GPU or CPU. Buffers are converted by copying, or snippets are used to change the OpenCL code reading them. As some translators can work in-place, the format is considered a setting of the Buffer, rather than having different Buffer subclasses for each format.
This is a first working version of such a buffer, though it's missing a lot of features. There's only one supported format (32-bit float), between 1 and 4 channels. This is stored in an array, flattened over the rows first. There is also GPU storage that this buffer uses. States of these buffers (i.e. do they contain up-to-date information?) are encoded in the two boolean flags (myOnCPU and myOnGPU). When the user asks IMX_Buffer something that must access its storage, that storage is first automatically synchronized before the request is fulfilled.
Definition at line 133 of file IMX_Buffer.h.
IMX_Buffer::IMX_Buffer | ( | ) |
Creates a new buffer. You must call setSize to make this buffer usable.
IMX_Buffer::IMX_Buffer | ( | int | width, |
int | height, | ||
CE_Image::StorageType | storage, | ||
int | channels | ||
) |
Create and call setSize.
|
inline |
Definition at line 141 of file IMX_Buffer.h.
|
inlinenoexcept |
Definition at line 142 of file IMX_Buffer.h.
IMX_Buffer::IMX_Buffer | ( | const PXL_Raster & | rp | ) |
|
override |
void IMX_Buffer::adoptRaster | ( | PXL_Raster & | raster, |
bool | convert_colorspace | ||
) |
Adopt a PXL_Raster into the underlying IMX_Buffer. The buffer's storage type and number of channels must be set before calling. Steals the PXL_Raster data if compatible. Does OCIO transform from raster's space to scene linear if convert is set.
|
inline |
True if getCPU/GPUBuffer has been done since last freeBuffers()
Definition at line 405 of file IMX_Buffer.h.
|
inline |
Get height (number of rows) of the buffer.
Definition at line 185 of file IMX_Buffer.h.
|
inline |
Get width (number of columns in a row) of the buffer.
Definition at line 183 of file IMX_Buffer.h.
UT_UniquePtr<TIL_Raster> IMX_Buffer::buildRaster | ( | ) | const |
Constructs a TIL_Raster matching our storage/channel depth. Will be packed. TIL_Raster is subclass from PXL_Raster.
void IMX_Buffer::copy | ( | const IMX_Buffer & | other | ) |
Assignment operators; after executing these functions, this buffer will have the same size and data as other.
void IMX_Buffer::copyBuffer | ( | const IMX_Buffer & | other | ) |
Only copy the buffer pointers, the stat data is left unchanged.
void IMX_Buffer::copyMetadata | ( | const IMX_Buffer & | source | ) |
Copy everything except the buffer allocations, leaving the buffers dirty. This avoids any chance that writing pixels to this will modify the original. It also avoids shared pointer overhead and keeping buffers around longer than needed.
void IMX_Buffer::copyOrConvert | ( | const IMX_Buffer & | other | ) |
copy the buffer, converting betwen storage types if needed and doing a shallow copy if possible
|
inline |
Set storesIntegers, isFixedPoint, bytes, channels.
Definition at line 154 of file IMX_Buffer.h.
|
inline |
for debugging
Definition at line 290 of file IMX_Buffer.h.
void IMX_Buffer::deepCopy | ( | const IMX_Buffer & | other | ) |
Deep copy operator. Unlike copy() (which shares the buffers of the source), this version allocates a new buffer and copies the data into it. This can throw CE exceptions.
void IMX_Buffer::destroy | ( | ) |
Frees all the memory used by buffer.
bool IMX_Buffer::extract | ( | void * | dst, |
exint | dstsize, | ||
CE_Image::StorageType | dststorage, | ||
int | dstchannels | ||
) | const |
Copies the buffer into the provided flat destination buffer. The provided size is checked against required size and ASSERT and no copy & return false if a mis-match.
void IMX_Buffer::freeBuffers | ( | ) |
Frees the pixel memory (also does setDirty())
IMX_BorderType IMX_Buffer::getBorderType | ( | ) | const |
Returns type of the border.
int64 IMX_Buffer::getBufferSize | ( | ) | const |
Returns the number of bytes required to store the entire buffer.
|
inline |
Get the number of channels per pixel.
Definition at line 176 of file IMX_Buffer.h.
|
inline |
Returns a void pointer to the CPU buffer. If a read-only buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!
Definition at line 337 of file IMX_Buffer.h.
|
inline |
Returns this buffer's data array. If read is true, isDirty must be false. If write is true then it turns off isDirty by setting isOnCPU() and turning off isOnGPU() (it is assuming caller will actually write the buffer) If a read-only buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!
Definition at line 358 of file IMX_Buffer.h.
|
inline |
Definition at line 339 of file IMX_Buffer.h.
|
inline |
Returns this buffer's read-only data array. If this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!
Definition at line 345 of file IMX_Buffer.h.
|
inline |
Definition at line 323 of file IMX_Buffer.h.
|
inline |
Definition at line 325 of file IMX_Buffer.h.
|
inline |
Return pointer to CPU buffer (caller must ask for correct data type) If a read buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!
Definition at line 319 of file IMX_Buffer.h.
|
inline |
Definition at line 321 of file IMX_Buffer.h.
|
inline |
Definition at line 329 of file IMX_Buffer.h.
|
inline |
Definition at line 331 of file IMX_Buffer.h.
|
inline |
Definition at line 327 of file IMX_Buffer.h.
|
inline |
Definition at line 340 of file IMX_Buffer.h.
|
inline |
Definition at line 324 of file IMX_Buffer.h.
|
inline |
Definition at line 326 of file IMX_Buffer.h.
|
inline |
Definition at line 320 of file IMX_Buffer.h.
|
inline |
Definition at line 322 of file IMX_Buffer.h.
|
inline |
Definition at line 330 of file IMX_Buffer.h.
|
inline |
Definition at line 332 of file IMX_Buffer.h.
|
inline |
Definition at line 328 of file IMX_Buffer.h.
UT_Vector4F IMX_Buffer::getDefaultColor | ( | ) | const |
UT_Vector4I IMX_Buffer::getDefaultColorI | ( | ) | const |
return the current integer value, which might be different
int64 IMX_Buffer::getDeviceMemoryUsage | ( | ) | const |
CE_Image& IMX_Buffer::getGPUBuffer | ( | bool | read, |
bool | write | ||
) |
Returns this buffer's GPU storage object. If read is true, isDirty must be false. If write is true then it turns off isDirty by setting isOnGPU() and turning off isOnCPU() (it is assuming caller will actually write the buffer) When using one of these methods, this buffer must be guarded with the in-use GPU flag. See setInUseGPUFlag() documentation for more information. Can throw CE exceptions.
const CE_Image& IMX_Buffer::getGPUBufferR | ( | ) | const |
|
inline |
Definition at line 373 of file IMX_Buffer.h.
cl::Buffer IMX_Buffer::getGPUStat | ( | ) | const |
Returns the stat buffer on the GPU, copying it there if necessary. This can throw CE exceptions.
int64 IMX_Buffer::getMemoryUsage | ( | ) | const |
UT_Vector4F IMX_Buffer::getPixelV4 | ( | int | x, |
int | y | ||
) | const |
Fetches the value of an individual pixel.
UT_Vector4F IMX_Buffer::getPixelV4 | ( | fpreal64 | x, |
fpreal64 | y | ||
) | const |
Fetches the value at the provided coordinates, using bilinear filtering. Returns value of the nearest pixel for integer buffers.
|
inline |
Number of bytes per channel.
Definition at line 178 of file IMX_Buffer.h.
|
inline |
Get the data type used to store pixel data for each channel.
Definition at line 170 of file IMX_Buffer.h.
IMX_TypeInfo IMX_Buffer::getTypeInfo | ( | ) | const |
Returns the semantic type.
|
inline |
Definition at line 291 of file IMX_Buffer.h.
bool IMX_Buffer::insert | ( | const void * | src, |
exint | srcsize, | ||
CE_Image::StorageType | srcstorage, | ||
int | srcchannels | ||
) |
Copies the provided flat buffer into this buffer. The provided size is checked against required size and ASSERT and no copy & return false if a mis-match.
bool IMX_Buffer::isAligned | ( | const IMX_Buffer & | src | ) | const |
True if the buffer pixels line up: width and the transforms from image space match.
|
inline |
Definition at line 422 of file IMX_Buffer.h.
|
inline |
False if there are computed pixels in the CPU or GPU buffer.
Definition at line 393 of file IMX_Buffer.h.
|
inline |
Does this buffer use fixed point to store non-integer data?
Definition at line 174 of file IMX_Buffer.h.
|
inline |
Returns true if this buffer's data is currently on the CPU (this is not necessarily !isOnGPU()).
Definition at line 383 of file IMX_Buffer.h.
|
inline |
Returns true if this buffer's data is currently on the GPU.
Definition at line 376 of file IMX_Buffer.h.
void IMX_Buffer::makeBufferUnique | ( | ) |
Stop sharing the buffers (so that writes don't affect other layers that have called copyBuffer() on this or vice versa).
void IMX_Buffer::matchAndCopyToVoxels | ( | UT_VoxelArray< T > & | dest | ) | const |
Resizes dest to match dimensions of this image (its Z-resolution is set to 1) and copies this buffer's data into it. Number of channels in the image should equal tuple size of T. If this layer is dirty, simply sizes the voxel array without touching its values.
void IMX_Buffer::moveBuffer | ( | IMX_Buffer & | src | ) |
Move the buffer to this from src, src is left dirty.
|
inline |
Definition at line 232 of file IMX_Buffer.h.
|
inline |
Definition at line 240 of file IMX_Buffer.h.
|
inlineoverrideprotectedvirtual |
True if the gpu buffer is null.
Implements IMX_PoolEntry.
Definition at line 451 of file IMX_Buffer.h.
|
inlineoverrideprotectedvirtual |
True if the gpu buffer is not null and valid.
Implements IMX_PoolEntry.
Definition at line 456 of file IMX_Buffer.h.
|
inlineoverrideprotectedvirtual |
These implement methods required by the pool.
Resets the GPU Buffer pointer.
Implements IMX_PoolEntry.
Definition at line 441 of file IMX_Buffer.h.
|
inlineoverrideprotectedvirtual |
|
inlineoverrideprotectedvirtual |
|
inlineoverrideprotectedvirtual |
True if the swap does something.
Implements IMX_PoolEntry.
Definition at line 461 of file IMX_Buffer.h.
|
inlineoverridevirtual |
Implements IMX_PoolEntry.
Definition at line 146 of file IMX_Buffer.h.
void IMX_Buffer::setBorder | ( | IMX_BorderType | border | ) |
Sets the border type of this image. Constant means it is zero.
void IMX_Buffer::setBufferXforms | ( | const UT_Vector2F & | buffer_to_image_scale, |
const UT_Vector2F & | buffer_to_image_xlate, | ||
const UT_Vector2F & | buffer_from_image_scale, | ||
const UT_Vector2F & | buffer_from_image_xlate, | ||
const UT_Vector2F & | buffer_to_pixel_scale, | ||
const UT_Vector2F & | buffer_to_pixel_xlate, | ||
const UT_Matrix4F & | image_to_world, | ||
const UT_Matrix4F & | world_to_image, | ||
const UT_Matrix4F & | camera_to_world, | ||
const UT_Vector3F & | camera_image_pos | ||
) |
Set transform between image and buffer space.
Set channels, don't change storesIntegers, isFixedPoint, or bytes.
Definition at line 411 of file IMX_Buffer.h.
|
inline |
Definition at line 410 of file IMX_Buffer.h.
void IMX_Buffer::setConstantV4 | ( | const UT_Vector4F & | i | ) |
Make entire image the same color. This is optimized internally to a 1x1 buffer
void IMX_Buffer::setDefaultColor | ( | const UT_Vector4F & | ) |
Set the default color. This is returned for uncalculatable pixels, and to expand integer vectors from 2,3 to 4. Other usage is not yet determined. Initial value is 0,0,0,1 (may change)
Definition at line 298 of file IMX_Buffer.h.
Definition at line 302 of file IMX_Buffer.h.
|
inline |
Sets an individual pixel.
Definition at line 294 of file IMX_Buffer.h.
void IMX_Buffer::setStatProjection | ( | IMX_Projection | projection | ) |
These are the projections in the stat, you want to actually work at imx layer to ensure you update the transforms. Sets the projection of this image.
|
inline |
Can be used to control what stealable() subsequently returns. If set to true, indicates to the verbs that this buffer may be stolen from.
Definition at line 247 of file IMX_Buffer.h.
Set number of bytes per channel, don't change storesIntegers, isFixedPoint, or channels
Set bytes per channel and isFixedPoint, doesn't change channels. Also sets storesIntegers to false. TODO: should this fail if storesIntegers() is already true? (FIXED_POINT_STORAGE)
void IMX_Buffer::setStorageType | ( | CE_Image::StorageType | storage, |
int | channels | ||
) |
Set storesIntegers, isFixedPoint, bytes, channels.
void IMX_Buffer::setStorageType | ( | CE_Image::StorageType | storage | ) |
Set storesIntegers, isFixedPoint, bytes.
void IMX_Buffer::setTypeInfo | ( | IMX_TypeInfo | typeinfo | ) |
Sets the semantic type info of this image.
|
inline |
Marks that this buffer is not initialized. This means that when a read buffer is requested, we won't bother doing any copying or data validation. This is useful if you bind this as a read-write layer to a kernel, but will be doing the initialization in the same kernel. Copying from an unitialized buffer will inherit this flag without moving any data. This flag gets cleared when someone writes to this buffer.
Definition at line 420 of file IMX_Buffer.h.
IMX_Projection IMX_Buffer::statProjection | ( | ) | const |
Returns the projection type.
|
inline |
True if data in this buffer may be stolen from (or changed) by the verbs even if it's an input.
Definition at line 244 of file IMX_Buffer.h.
|
inline |
Does this buffer store integers?
Definition at line 172 of file IMX_Buffer.h.
void IMX_Buffer::swap | ( | IMX_Buffer & | other | ) |
bool IMX_Buffer::validateBuffer | ( | ) | const |
|
friend |
Definition at line 548 of file IMX_Buffer.h.
Definition at line 135 of file IMX_Buffer.h.