warp.Texture2D#

class warp.Texture2D(*args, **kwargs)[source]#

2D texture class.

Experimental

The texture API is experimental and subject to change without a formal deprecation cycle. See Texture for details.

This is a specialized version of Texture with dimensionality fixed to 2. Use this for explicit 2D texture creation and as a type hint in kernel parameters.

Example:

import warp as wp
import numpy as np

data = np.random.rand(256, 256, 4).astype(np.float32)
tex = wp.Texture2D(data, device="cuda:0")


@wp.kernel
def sample_kernel(tex: wp.Texture2D, output: wp.array(dtype=float)):
    tid = wp.tid()
    output[tid] = wp.texture_sample(tex, wp.vec2f(0.5, 0.5), dtype=float)
Parameters:
  • data (np.ndarray | array | None)

  • width (int)

  • height (int)

  • num_channels (int)

  • filter_mode (int)

  • address_mode (int | tuple[int, int] | None)

  • address_mode_u (int | None)

  • address_mode_v (int | None)

  • normalized_coords (bool)

  • device (DeviceLike)

  • surface_access (bool)

__init__(
data=None,
width=0,
height=0,
num_channels=4,
dtype=float32,
filter_mode=1,
address_mode=None,
address_mode_u=None,
address_mode_v=None,
normalized_coords=True,
device=None,
surface_access=False,
)[source]#
Parameters:
  • data (np.ndarray | array | None)

  • width (int)

  • height (int)

  • num_channels (int)

  • filter_mode (int)

  • address_mode (int | tuple[int, int] | None)

  • address_mode_u (int | None)

  • address_mode_v (int | None)

  • normalized_coords (bool)

  • device (DeviceLike)

  • surface_access (bool)

Methods

__init__([data, width, height, ...])

copy_from_array(src)

Copy from a CUDA 2D Warp array into this texture's CUDA array.

copy_to_array(dst)

Copy from this texture's CUDA array into a CUDA 2D Warp array.

Attributes

ADDRESS_BORDER

Return 0 for coordinates outside [0, 1].

ADDRESS_CLAMP

Clamp coordinates to [0, 1].

ADDRESS_MIRROR

Mirror coordinates at boundaries.

ADDRESS_WRAP

Wrap coordinates (tile the texture).

FILTER_LINEAR

Bilinear/trilinear filtering.

FILTER_POINT

Nearest-neighbor (point) filtering.

address_mode_u

Address mode for U axis.

address_mode_v

Address mode for V axis.

address_mode_w

Address mode for W axis (3D only).

cuda_array

CUDA array handle backing this texture.

cuda_surface

CUDA surface object handle backing this texture.

cuda_texture

CUDA texture object handle.

depth

Texture depth in pixels (1 for 2D textures).

dtype

Data type of the texture.

height

Texture height in pixels.

id

Device-independent texture identifier.

ndim

Texture dimensionality (1, 2, or 3).

normalized_coords

Whether texture uses normalized coordinates.

num_channels

Number of channels.

vars

width

Texture width in pixels.

vars: ClassVar[dict[str, Var]] = {'height': <warp._src.codegen.Var object>, 'width': <warp._src.codegen.Var object>}#
copy_from_array(src)[source]#

Copy from a CUDA 2D Warp array into this texture’s CUDA array.

Parameters:

src (array)

copy_to_array(dst)[source]#

Copy from this texture’s CUDA array into a CUDA 2D Warp array.

Parameters:

dst (array)