Sensor lifecycle#
The NyxCameraSensor integrates the Nyx renderer with Genesis using a render-on-read model. Scene.step() advances physics but does not render. Rendering is performed on the first read() call that follows a step, for every Nyx camera and every environment at once, and the resulting images are kept in GPU tensors that alias the renderer’s output until the simulation advances or a camera pose changes.
This page describes the sensor’s order of operations across its three phases: construction, build, and the per-step render-on-read cycle.
Lifecycle overview#
Phase |
Triggered by |
GPU work |
|---|---|---|
Construction |
None |
|
Build |
Renderer startup, GPU pairing, buffer allocation and import |
|
Render-on-read |
|
One batched upload, one batched render of every (env, camera) pair |
Cached read |
|
None |
Destruction |
Scene destruction |
Buffer release, renderer shutdown |
Construction#
scene.add_sensor(NyxCameraOptions(...)) instantiates a NyxCameraSensor from the given NyxCameraOptions and registers it with the sensor manager. The sensor options are stored on the instance. No renderer is created and no GPU resources are allocated.
A single scene can contain multiple Nyx sensors. They share a single renderer instance and a single shared image cache.
Build#
scene.build() calls build() on every sensor in registration order. For each Nyx sensor, build() performs the following steps:
Verify that torch has a GPU backend, CUDA or ROCm. A CPU-only torch raises immediately.
Attach to the shared metadata block used by every Nyx sensor in the scene.
Append a camera definition to the shared camera list (resolution, pose, clip planes, sample count, denoising, anti-aliasing, camera profile).
When the last Nyx sensor finishes building, that sensor performs the one-time scene initialisation:
Collect lights, environment maps, and light fields from every Nyx sensor.
Export a JSON scene description to
__nyx_cache__/<random>/, together with one camera-profile JSON per camera that did not supply its own (see Camera profiles).Create a single renderer instance. The internal viewport is sized to the maximum resolution across all sensors. The GPU is picked by memory size, or by vendor when
gpu_vendoris set on the first sensor.Pair the torch device with the GPU Nyx picked and make it the current torch device (see GPU backends: CUDA and ROCm).
Ask Nyx to allocate its interop buffers for
n_envsenvironments (rigid transforms, camera poses, deformable vertices / UVs / indices, and the packed colour output), then import every one of them as a torch tensor. The tensors alias Nyx’s memory.Upload static deformable data (UVs and fixed face indices) and replicate it to every env.
Hand every sensor a
(B, H, W, 3)uint8view into the packed colour output as its image cache entry.
After build() returns, the renderer is initialised and the sensor is ready to render on the next read().
Note
All Nyx sensors must be added before scene.build(). Adding sensors after the build is not supported.
Note
All Nyx sensors must use the same render_mode. The plugin raises an exception if the values diverge.
Render-on-read#
scene.step() advances the simulation and does not render. The next cam.read() triggers the render.
read() is inherited from BaseCameraSensor and runs the following steps:
Step |
Action |
|---|---|
1. Staleness check |
If the renderer last ran at a different global step than the simulator is at, every Nyx sensor’s |
2. Cached path |
If |
3. Pose update |
If the camera is attached to a rigid link, |
4. Render |
|
5. Mark fresh |
The |
6. Return |
The requested environments are sliced from the cached |
Because _render_current_state() renders every Nyx camera in one call, only the first read() of the step performs the render pass. Subsequent read() calls on other Nyx sensors in the same step return their pre-rendered image from the cache.
Render pass#
_render_current_state() is a short, fully batched sequence. There is no per-environment loop in Python.
Step |
Action |
|---|---|
1 |
|
2 |
For every attached sensor, |
3 |
|
4 |
For every Nyx sensor, its camera pose is written into the camera buffers in one batched copy: attached cameras write their per-env poses, static cameras broadcast a single pose over the env dimension. |
5 |
|
6 |
|
When the call returns, every sensor’s image view holds the current step’s frames for every env. All sensors are marked fresh and the last-render step is recorded.
Image cache#
The image cache is stored on NyxCameraSharedMetadata .image_cache as a dict[int, torch.Tensor] keyed by sensor index. Each entry is a strided view into the renderer’s packed colour output, created once at build time.
Property |
Value |
|---|---|
Shape |
|
Dtype |
|
Device |
The torch device paired with the renderer’s GPU (CUDA or ROCm) |
Sized per |
Sensor (different sensors may have different resolutions) |
Lifetime |
Tied to the scene; released on scene destruction |
cam.read().rgb returns that view, without a copy. The view is overwritten in place by every render pass, so call .clone() or .cpu() to keep a frame across steps.
The renderer’s internal viewport is sized to the maximum resolution across all Nyx sensors in the scene. Individual camera viewports are clipped to their configured resolution at render time.
Cache invalidation#
The cache is invalidated when:
The simulation advances.
scene.step()moves the global step counter, which marks every Nyx sensor stale on the nextread().An attached camera’s link moves. Handled inside
_render_current_state()viamove_to_attach(); the new transforms are pushed before rendering.update_camera_pose()is called. This detaches the camera from any rig and forces a re-render on the nextread().
The cache is not invalidated when:
cam.read()is called multiple times within the same step.Non-pose options such as
spp,denoiseorcamera_profileare mutated afterscene.build(). These options are read at build time only.
Multi-camera and multi-environment scenes#
The plugin enforces a single shared renderer per scene. This has three consequences:
All Nyx sensors must use the same
render_mode.All Nyx sensors must be registered before
scene.build()is called.Reading any one Nyx sensor renders all of them, for every environment. For setups with identical camera layouts per env, this is the intended behaviour. For setups with an expensive secondary camera that is read infrequently, the secondary camera is still rendered on every step where any Nyx sensor is read.
Environments are batched inside Nyx: one upload and one synchronization cover every env, and the per-env cost is GPU render time only. GPU time still scales with the number of (env, camera) pairs.
Destruction#
When the scene is destroyed, the shared metadata’s destroy() hook releases every imported buffer, closes the compute context, shuts the native renderer down, and removes the __nyx_cache__/<id>/ folder holding the scene description, the camera profiles and any exported .obj files.
Live window#
When open_window=True, the GUI event loop is serviced inside _render_current_state() via the renderer.update() call. This is the only point at which window events are pumped. The window size is set by window_size (default (1920, 1080)).
Warning
If cam.read() is not called every step, the live window appears frozen between reads. Call read() once per step for a smooth preview.
See also#
Quickstart — Minimal end-to-end script.
Concepts — Renderer states and asset model.
GPU backends: CUDA and ROCm — How the GPU is picked and how buffers are shared with torch.