warp.RegisteredGLBuffer#
- class warp.RegisteredGLBuffer(*args, **kwargs)[source]#
Helper class to register a GL buffer with CUDA so that it can be mapped to a Warp array.
Example usage:
import warp as wp import numpy as np from pyglet.gl import * wp.init() # create a GL buffer gl_buffer_id = GLuint() glGenBuffers(1, gl_buffer_id) # copy some data to the GL buffer glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_id) gl_data = np.arange(1024, dtype=np.float32) glBufferData(GL_ARRAY_BUFFER, gl_data.nbytes, gl_data.ctypes.data, GL_DYNAMIC_DRAW) glBindBuffer(GL_ARRAY_BUFFER, 0) # register the GL buffer with CUDA cuda_gl_buffer = wp.RegisteredGLBuffer(gl_buffer_id) # map the GL buffer to a Warp array arr = cuda_gl_buffer.map(dtype=wp.float32, shape=(1024,)) # launch a Warp kernel to manipulate or read the array wp.launch(my_kernel, dim=1024, inputs=[arr]) # unmap the GL buffer cuda_gl_buffer.unmap()
- __init__(
- gl_buffer_id,
- device=None,
- flags=NONE,
- fallback_to_copy=True,
- Parameters:
gl_buffer_id (int) – The OpenGL buffer id (GLuint).
device (Device | str | None) – The device to register the buffer with. If None, the current device will be used.
flags (int) – A combination of the flags constants
NONE,READ_ONLY, andWRITE_DISCARD.fallback_to_copy (bool) – If True and CUDA/OpenGL interop is not available, fall back to copy operations between the Warp array and the OpenGL buffer. Otherwise, a
RuntimeErrorwill be raised.
Note
The
fallback_to_copyoption (to use copy operations if CUDA graphics interop functionality is not available) requires pyglet version 2.0 or later. Install viapip install pyglet==2.*.
Methods
__init__(gl_buffer_id[, device, flags, ...])map(dtype, shape)Map the OpenGL buffer to a Warp array.
unmap()Unmap the OpenGL buffer.
Attributes
Flag that specifies no hints about how this resource will be used.
Flag that specifies that CUDA will not write to this resource.
Flag that specifies that CUDA will not read from this resource and will write over the entire contents of the resource, so none of the data previously stored in the resource will be preserved.
- NONE = 0#
Flag that specifies no hints about how this resource will be used. It is therefore assumed that this resource will be read from and written to by CUDA. This is the default value.
- READ_ONLY = 1#
Flag that specifies that CUDA will not write to this resource.
- WRITE_DISCARD = 2#
Flag that specifies that CUDA will not read from this resource and will write over the entire contents of the resource, so none of the data previously stored in the resource will be preserved.