Skip to content

Commit 4abf31c

Browse files
thecodacusclaude
andcommitted
fix(renderer): make --gl egl/angle actually use the GPU; add GPU userspace to the Docker image
Plain --use-gl=egl / --use-gl=angle let headless Chromium fall back to SwiftShader even with a GPU and drivers present, so "GPU" renders silently ran on the CPU. egl now passes --use-angle=gl-egl and angle --use-angle=vulkan (verified on an NVIDIA RTX 3060 in Docker via the WebGL renderer string). The Studio image gains the Vulkan loader and GLVND EGL/GL (libvulkan1, libegl1, libgl1, libglvnd0), the NVIDIA Vulkan ICD and EGL vendor JSONs, and NVIDIA_DRIVER_CAPABILITIES=all, so a container run with --gpus all can render on the GPU. Without a GPU it still renders on the CPU. Measured: a GL-heavy 18-min video went from ~3 h to ~13 min. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6d6aca2 commit 4abf31c

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎Dockerfile‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#
99
# Usage:
1010
# docker run -v /path/to/projects:/workspace -v agent-persist:/persist -p 3000:3000 ghcr.io/thecodacus/rendiv-studio
11+
#
12+
# GPU rendering (NVIDIA, needs the NVIDIA Container Toolkit on the host): add `--gpus all` (compose:
13+
# deploy.resources.reservations.devices: [{driver: nvidia, count: all, capabilities: [gpu]}]) and render with
14+
# `--gl angle` (Vulkan) or `--gl egl`. Without a GPU the image still renders on the CPU (SwiftShader).
1115
# =============================================================================
1216

1317
# ---------------------------------------------------------------------------
@@ -70,8 +74,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
7074
make g++ python3 \
7175
# General utilities
7276
git curl \
77+
# GPU rendering: Vulkan loader + GLVND EGL/GL so headless Chromium can reach the host GPU driver that
78+
# --gpus injects. Without these it silently falls back to SwiftShader (CPU) even with a GPU passed in.
79+
libvulkan1 libegl1 libgl1 libglvnd0 \
7380
&& rm -rf /var/lib/apt/lists/*
7481

82+
# NVIDIA vendor files for the Vulkan loader and GLVND EGL. The NVIDIA Container Toolkit injects the driver libraries
83+
# (libGLX_nvidia / libEGL_nvidia) but not always these JSONs; harmless on machines without an NVIDIA GPU.
84+
RUN mkdir -p /usr/share/vulkan/icd.d /usr/share/glvnd/egl_vendor.d \
85+
&& printf '%s' '{"file_format_version":"1.0.0","ICD":{"library_path":"libGLX_nvidia.so.0","api_version":"1.3.0"}}' \
86+
> /usr/share/vulkan/icd.d/nvidia_icd.json \
87+
&& printf '%s' '{"file_format_version":"1.0.0","ICD":{"library_path":"libEGL_nvidia.so.0"}}' \
88+
> /usr/share/glvnd/egl_vendor.d/10_nvidia.json
89+
# Ask the NVIDIA runtime for the graphics libraries too (compute-only is the default and has no Vulkan/EGL)
90+
ENV NVIDIA_DRIVER_CAPABILITIES=all
91+
7592
# Install pnpm
7693
RUN corepack enable && corepack prepare [email protected] --activate
7794

‎docs/rendering-performance.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rendiv render src/index.tsx MyComp --frames 0-89
2525
| Bottleneck | Impact | Possible Fix |
2626
|---|---|---|
2727
| **PNG screenshots** | Every frame is captured as lossless PNG, which is slow to encode. JPEG would be ~3-5x faster per frame. | Add `--image-format jpeg` option for intermediate frames |
28-
| **Software GL rendering** | Browser uses `--use-angle=swiftshader` (CPU-based GL). Slow for Three.js/canvas-heavy compositions. | Use `--use-gl=egl` or native GPU on Linux; macOS GPU is less reliable headless |
28+
| **Software GL rendering** | Browser uses `--use-angle=swiftshader` (CPU-based GL). Slow for Three.js/canvas-heavy compositions. | Render with `--gl angle` (ANGLE on Vulkan) or `--gl egl` (ANGLE on EGL) on a Linux GPU. In Docker: run the image with `--gpus all` (NVIDIA Container Toolkit); the image ships the Vulkan/EGL loaders and NVIDIA vendor files. Measured on an RTX 3060: a GL-heavy 18-min video went from ~3 h (SwiftShader) to ~13 min. macOS GPU is less reliable headless |
2929
| **FFmpeg H.264 preset** | No `-preset` specified, defaults to `medium`. | Add `-preset ultrafast` for ~4x faster encoding (slightly larger file) or `-preset fast` for a good balance |
3030
| **FFmpeg hardware encoding** | CPU-only `libx264` encoder. | Use `h264_videotoolbox` (macOS) or `h264_nvenc` (NVIDIA) for GPU-accelerated encoding |
3131
| **holdRender polling** | Playwright's default `waitForFunction` polling interval (~100ms). | Reduce polling interval or switch to a notification-based approach |

‎packages/cli/src/commands/render.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const renderCommand = new Command('render')
6464
.option('--preset <preset>', 'FFmpeg encoding preset (ultrafast, fast, medium, slow, veryslow)')
6565
.option('--crf <number>', 'Quality factor 0-51, lower is better', '18')
6666
.option('--video-encoder <encoder>', 'Video encoder (libx264, h264_videotoolbox, h264_nvenc)')
67-
.option('--gl <renderer>', 'GL renderer (swiftshader, egl, angle)', 'swiftshader')
67+
.option('--gl <renderer>', 'GL renderer: swiftshader (CPU), egl (GPU: ANGLE on EGL/GLES), angle (GPU: ANGLE on Vulkan)', 'swiftshader')
6868
.option('--profiling', 'Enable per-frame profiling')
6969
.action(async (entry: string, compositionId: string, output: string, options: {
7070
props: string;

‎packages/renderer/src/browser.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ export interface OpenBrowserOptions {
99
let browserInstance: Browser | null = null;
1010
let currentGl: GlRenderer = 'swiftshader';
1111

12+
/**
13+
* Chromium flags per GL renderer.
14+
*
15+
* `egl` and `angle` must name an explicit ANGLE backend: plain `--use-gl=egl` / `--use-gl=angle` let headless
16+
* Chromium fall back to SwiftShader (software) even when a GPU and its drivers are present, so "GPU" renders were
17+
* silently running on the CPU. Verified on an NVIDIA RTX 3060 in Docker (WebGL renderer string):
18+
* egl → ANGLE (NVIDIA ..., OpenGL ES 3.2) via --use-angle=gl-egl
19+
* angle → ANGLE (NVIDIA, Vulkan 1.4 ...) via --use-angle=vulkan
20+
* Both need the GPU's Vulkan/EGL userspace (see the Dockerfile); without it Chromium still falls back to SwiftShader.
21+
*/
1222
function glArgs(gl: GlRenderer): string[] {
1323
switch (gl) {
1424
case 'egl':
15-
return ['--use-gl=egl'];
25+
return ['--use-gl=angle', '--use-angle=gl-egl'];
1626
case 'angle':
17-
return ['--use-gl=angle'];
27+
return ['--use-gl=angle', '--use-angle=vulkan'];
1828
case 'swiftshader':
1929
default:
2030
return ['--use-gl=angle', '--use-angle=swiftshader'];

‎packages/skills/rendiv-video/rules/cli-and-studio.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The output format is determined by the file extension (`.mp4` or `.webm`).
5252
| `--preset <preset>` | — | FFmpeg encoding preset (`ultrafast`, `fast`, `medium`, `slow`, `veryslow`) |
5353
| `--crf <number>` | `18` | Quality factor 0-51, lower is better |
5454
| `--video-encoder <enc>` | — | Video encoder (`libx264`, `h264_videotoolbox`, `h264_nvenc`) |
55-
| `--gl <renderer>` | `swiftshader` | GL renderer (`swiftshader`, `egl`, `angle`) |
55+
| `--gl <renderer>` | `swiftshader` | GL renderer: `swiftshader` (CPU), `egl` (GPU, ANGLE on EGL/GLES), `angle` (GPU, ANGLE on Vulkan). GPU modes need a GPU + its Vulkan/EGL userspace (the Docker image ships it; run with `--gpus all`) |
5656
| `--profiling` | off | Enable per-frame profiling with phase breakdown |
5757

5858
#### `rendiv still`

0 commit comments

Comments
 (0)