warp.Texture#
- class warp.Texture(*args, **kwargs)[source]#
Texture base class for hardware-accelerated sampling on GPU and software sampling on CPU.
Experimental
The texture API is experimental and subject to change without a formal deprecation cycle.
Textures provide hardware-accelerated filtering and addressing for regularly gridded data on CUDA devices. On CPU, software-based filtering and addressing is used. Supports linear/bilinear/trilinear interpolation and various addressing modes (wrap, clamp, mirror, border).
Supports
warp.uint8,warp.uint16,warp.uint32,warp.int8,warp.int16,warp.int32,warp.float16, andwarp.float32data types. Unsigned integer textures are read as normalized floats in [0, 1]; signed integer textures are normalized to [-1, 1]; float types are returned as-is.This class should not be instantiated directly. A specific subclass should be used instead (
Texture1D,Texture2D, orTexture3D).Example:
import warp as wp import numpy as np # Create a 1D texture data_1d = np.random.rand(256).astype(np.float32) tex1d = wp.Texture1D(data_1d, device="cuda:0") # Create a 2D texture data_2d = np.random.rand(256, 256).astype(np.float32) tex2d = wp.Texture2D(data_2d, device="cuda:0") # Create a 3D texture data_3d = np.random.rand(64, 64, 64).astype(np.float32) tex3d = wp.Texture3D(data_3d, device="cuda:0")
- __init__(
- ndim,
- data=None,
- width=0,
- height=0,
- depth=0,
- num_channels=0,
- dtype=None,
- filter_mode=TextureFilterMode.LINEAR,
- address_mode=TextureAddressMode.CLAMP,
- address_mode_u=None,
- address_mode_v=None,
- address_mode_w=None,
- normalized_coords=True,
- device=None,
- surface_access=False,
- cuda_array=0,
Create a texture.
- Parameters:
ndim (int) – Number of texture dimensions.
data (numpy.ndarray | array | None) – Initial texture data as a NumPy array or Warp array. For 1D: shape
(width,)or(width, num_channels). For 2D: shape(height, width)or(height, width, num_channels). For 3D: shape(depth, height, width)or(depth, height, width, num_channels). Supported dtypes:warp.uint8,warp.uint16,warp.uint32,warp.int8,warp.int16,warp.int32,warp.float16,warp.float32.width (int) – Texture width (required if
dataisNone).height (int) – Texture height (required if
dataisNone).depth (int) – Texture depth (required if
dataisNonefor 3D textures).num_channels (int) – Number of channels (1, 2, or 4). Only used when
dataisNone.dtype – Data type. Only used when
dataisNone; otherwise inferred from the data.filter_mode (TextureFilterMode) – Filtering mode, see
TextureFilterMode.address_mode (TextureAddressMode | tuple[TextureAddressMode, ...]) – Address mode for all axes, see
TextureAddressMode. Can be a single int or a tuple of per-axis values.address_mode_u (TextureAddressMode | None) – Per-axis address mode for U. Overrides
address_modeif specified.address_mode_v (TextureAddressMode | None) – Per-axis address mode for V. Overrides
address_modeif specified.address_mode_w (TextureAddressMode | None) – Per-axis address mode for W (3D only). Overrides
address_modeif specified.normalized_coords (bool) – If
True, coordinates are in[0, 1]range. IfFalse, coordinates are in texel space.device (DeviceLike) – Device on which to create the texture.
surface_access (bool) – If
Trueanddeviceis CUDA, allocates the backing CUDA array with surface load/store support socuda_surfacecan be used.cuda_array (int) – CUDA array handle to wrap an external texture (
cudaArray_t).
Methods
__init__(ndim[, data, width, height, depth, ...])Create a texture.
copy_from(src)Copy texture data from a source.
copy_from_array(src)Copy from a CUDA Warp array into this texture's CUDA array.
copy_to(dst)Copy texture data to a destination.
copy_to_array(dst)Copy from this texture's CUDA array into a CUDA Warp array.
Attributes
Address mode for U axis.
Address mode for V axis.
Address mode for W axis (3D only).
CUDA array handle backing this texture.
CUDA surface object handle backing this texture.
CUDA texture object handle.
Texture depth in pixels (1 for 2D textures).
Data type of the texture.
Texture height in pixels.
Device-independent texture identifier.
Texture dimensionality (1, 2, or 3).
Whether texture uses normalized coordinates.
Number of channels.
Texture width in pixels.
- copy_from(src)[source]#
Copy texture data from a source.
- Parameters:
src (array | numpy.ndarray | Texture) – The source can be a Warp array on the same device as the texture, a CPU Warp array, a NumPy array, or another texture.
- copy_to(dst)[source]#
Copy texture data to a destination.
- Parameters:
dst (array | numpy.ndarray | Texture) – The destination can be a Warp array on the same device as the texture, a CPU Warp array, a NumPy array, or another texture.
- copy_from_array(src)[source]#
Copy from a CUDA Warp array into this texture’s CUDA array. Deprecated, use
Texture.copy_from()method instead.- Parameters:
src (array)
- copy_to_array(dst)[source]#
Copy from this texture’s CUDA array into a CUDA Warp array. Deprecated, use
Texture.copy_to()method instead.- Parameters:
dst (array)
- property id: int[source]#
Device-independent texture identifier.
On CUDA textures, this is the same handle as
cuda_texture(cudaTextureObject_t). On host textures, this is the backing host texture handle.
- property cuda_array: int[source]#
CUDA array handle backing this texture.
- Returns:
CUDA
cudaArray_thandle for CUDA textures.