warp.Texture#
- class warp.Texture(*args, **kwargs)[source]#
Unified texture 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.
This class handles 1D, 2D, and 3D textures. The dimensionality is provided explicitly via
ndimor by using theTexture1D,Texture2D, orTexture3Dsubclasses.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
wp.uint8,wp.uint16,wp.uint32,wp.int8,wp.int16,wp.int32,wp.float16, andwp.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.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__(
- data=None,
- width=0,
- height=0,
- depth=0,
- num_channels=1,
- dtype=float32,
- filter_mode=1,
- address_mode=None,
- address_mode_u=None,
- address_mode_v=None,
- address_mode_w=None,
- normalized_coords=True,
- device=None,
- ndim=None,
- surface_access=False,
Create a texture.
- Parameters:
data (np.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),(height, width, 2), or(height, width, 4). For 3D: shape(depth, height, width),(depth, height, width, 2), or(depth, height, width, 4). Supported dtypes:wp.uint8,wp.uint16,wp.uint32,wp.int8,wp.int16,wp.int32,wp.float16,wp.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 (int) – Filtering mode —
FILTER_POINTorFILTER_LINEAR.address_mode (int | tuple[int, ...] | None) – Address mode for all axes —
ADDRESS_WRAP,ADDRESS_CLAMP,ADDRESS_MIRROR, orADDRESS_BORDER. Can be a single int or a tuple of per-axis values.address_mode_u (int | None) – Per-axis address mode for U. Overrides
address_modeif specified.address_mode_v (int | None) – Per-axis address mode for V. Overrides
address_modeif specified.address_mode_w (int | 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.
ndim (int | None) – Explicit dimensionality (1, 2, or 3). Required when constructing the base
Textureclass directly.surface_access (bool) – If
Trueanddeviceis CUDA, allocates the backing CUDA array with surface load/store support socuda_surfacecan be used.
Methods
__init__([data, width, height, depth, ...])Create a texture.
Attributes
Return 0 for coordinates outside [0, 1].
Clamp coordinates to [0, 1].
Mirror coordinates at boundaries.
Wrap coordinates (tile the texture).
Bilinear/trilinear filtering.
Nearest-neighbor (point) filtering.
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.
- ADDRESS_WRAP = 0#
Wrap coordinates (tile the texture).
- ADDRESS_CLAMP = 1#
Clamp coordinates to [0, 1].
- ADDRESS_MIRROR = 2#
Mirror coordinates at boundaries.
- ADDRESS_BORDER = 3#
Return 0 for coordinates outside [0, 1].
- FILTER_POINT = 0#
Nearest-neighbor (point) filtering.
- FILTER_LINEAR = 1#
Bilinear/trilinear filtering.
- property cuda_texture: int[source]#
CUDA texture object handle.
- Returns:
CUDA
cudaTextureObject_thandle for CUDA textures.
- 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.