Table of Contents
A minimal Triton windowing demo example with ray tracing and GUI.
-
GLFW windowing (OpenGL 4.3 core)
-
PyOpenGL rendering (fullscreen triangle)
-
Dear ImGui Bundle UI overlay
-
CUDA–OpenGL SSBO interop (when OpenGL context is on an NVIDIA GPU and CUDA interop is available)
-
Torch tensor view via DLPack (no copy when interop + same device)
-
Triton kernels writing into the buffer
The renderer is ping-pong double-buffered.
Rendering modes (selected automatically)
The code will pick the least-copy path at runtime:
-
Zero-copy (best, WIP):
-
OpenGL SSBO mapped as a CUDA graphics resource
-
Torch tensor view created over the mapped device pointer (via CuPy + DLPack)
-
Triton writes directly into the mapped SSBO (no extra copies)
-
-
GPU copy (still fast, WIP):
-
Triton writes into a persistent Torch tensor (compute device)
-
Buffer is mapped on the OpenGL CUDA device
-
A device-to-device copy is issued into the mapped SSBO
-
If devices differ and peer access is supported, a peer copy is used
-
-
-
Host staging (fallback, working):
-
Triton writes into a persistent Torch tensor
-
Copy to persistent pinned host staging buffer
-
Upload into OpenGL SSBO via
glBufferSubData
-
What runs on the GPU
Per frame (ping-pong):
-
OpenGL draws a fullscreen triangle; fragment shader reads SSBO(front)
-
Triton produces the next frame into SSBO(back) (zero-copy) OR into a Torch tensor then copies
-
swap(front, back)
Controls
ImGui panel:
-
Sphere center / radius / color
-
Camera orbit yaw/pitch/distance/FOV
-
Light direction
-
Toggles: sphere enabled, animate
Requirements
-
Linux host with NVIDIA GPU + drivers (for CUDA + Triton)
-
WSL2 can work with some setup like
export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
-
-
OpenGL 4.3+ (SSBO)
-
Python 3.10+
-
PyTorch (CUDA build), Triton
-
cuda-python (for CUDA-OpenGL interop path)
-
CuPy (only required for the true zero-copy Torch view over a mapped SSBO)
-
imgui-bundle
Quickstart (VS Code Dev Container)
-
On the host:
-
Reopen in container.
-
Run:
python3 -m triton_windowing --width 1280 --height 720 --buffering 1
Optional:
python3 -m triton_windowing --compute-device 0 --gl-device 0
ESC to exit.
