Skip to content

NF Firefox headless WebGL support; FIX Vertex in Firefox WebGL - #765

Open
kroq-gar78 wants to merge 2 commits into
gallantlab:devfrom
kroq-gar78:firefox
Open

kroq-gar78 wants to merge 2 commits into
gallantlab:devfrom
kroq-gar78:firefox

Conversation

@kroq-gar78

@kroq-gar78 kroq-gar78 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds support for Firefox in the headless WebGL renderer, and it also fixes Vertex rendering in Firefox (#375).

Summary

The user can now choose which browser to use in the relevant functions (headless_viewer, save_3d_views) with browser="chromium"|"firefox". Unlike with Chromium, Firefox needs a display buffer to render to. This means that either DISPLAY needs to be set, or the Xvfb package needs to be installed for truly headless support. (For simplicitly, Chromium is still the default.)

Headless support allows us to run tests for Firefox, which confirms #375 . The issue was that the colormapped surface_vertex shader declares more than 16 vertex attributes, which is WebGL's cap. Chromium (ANGLE) drops the unused ones before checking the limit, but Firefox (Mesa) does not, so the shader fails to link. (This failure is actually in the same vein as gh-714, but Chromium doesn't catch it.)

Changes

  1. Add headless Firefox support. A new webgl_browser() context manager in cortex/export/headless.py launches either browser and handles teardown. Headless Firefox needs an X display for WebGL, so when DISPLAY is unset it starts a private Xvfb. The browser and data type tests run in both browsers, and a new test checks that both browsers render each data type alike. The 8 Firefox cases hit by the bug are marked xfail(strict=True).
  2. Fix the shader. surface_vertex now declares only the attributes it reads, and 2D vertex data is packed into two vec2 attributes instead of four floats (shaderlib.js, dataset.js). The 8 xfails now pass.

Running the Firefox tests

CI still installs only Chromium, to keep runs short, so the Firefox tests skip there. To run them locally:

uv run playwright install firefox
sudo apt-get install xvfb      # not needed if DISPLAY is set
uv run pytest -k firefox

Testing

I ran the full suite on both commits:

@kroq-gar78 kroq-gar78 changed the title NF Firefox playwright support; FIX Vertex in Firefox NF Firefox headless webgl support; FIX Vertex in Firefox Oct 13, 2026
@kroq-gar78 kroq-gar78 changed the title NF Firefox headless webgl support; FIX Vertex in Firefox NF Firefox headless webgl support; FIX Vertex in Firefox webgl Oct 13, 2026
@kroq-gar78 kroq-gar78 changed the title NF Firefox headless webgl support; FIX Vertex in Firefox webgl NF Firefox headless WebGL support; FIX Vertex in Firefox WebGL Oct 13, 2026
@kroq-gar78
kroq-gar78 marked this pull request as ready for review October 13, 2026 21:23
kroq-gar78 and others added 2 commits October 16, 2026 15:23
headless_viewer, save_3d_views, and plot_panels gain a
browser="chromium"|"firefox" parameter; only the chosen browser needs to
be installed. Unlike Chromium's SwiftShader, Firefox needs an X display
for WebGL, so a private Xvfb is started when DISPLAY isn't set. The
webgl_browser() context manager launches either browser, rejects unknown
names, and owns browser and Xvfb teardown.

Tests:
- test_webgl_shaders links every shader variant in both browsers.
  Chromium's ANGLE drops unused attributes before enforcing
  GL_MAX_VERTEX_ATTRIBS; Firefox's Mesa counts every declaration.
- test_datatype_renders renders every dataview type in both browsers,
  and test_chromium_matches_firefox checks they agree.
- test_save_3d_views_headless and test_headless_viewer_opens_and_closes
  run in both browsers; the latter checks the browser and Xvfb exit.

The colormapped surface_vertex shader on a flatmap subject declares more
than 16 attributes, so in Firefox Vertex/Vertex2D render blank. Those 8
cases are xfail(strict=True) until the shader is fixed.

CI installs only Chromium, to stay short, so Firefox tests skip there.
They parametrize over testing_utils.BROWSERS; the FIREFOX_MISSING skip
reason says how to run them locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The surface_vertex shader declared two attributes (data2/data3) it only
reads for 2D vertex data, relying on the driver to prune them before
enforcing GL_MAX_VERTEX_ATTRIBS. Chromium's ANGLE does; Mesa's llvmpipe,
used by headless Firefox, counts every declaration, so the program fails
to link and the surface renders blank.

Declare only what is read: 2D vertex data packs both dimensions into the
.x/.y of two vec2 attributes instead of four floats, with the same
dimension-to-component mapping. Other dataviews declare just
data0/data1, and the placeholder attributes in mriview_surface.js go.

DataView._setPacked2D interleaves the two dimensions. setFrame keeps the
packed attributes of the current frame pair, so an unchanged frame costs
nothing and a one-frame step reuses the previous "next" frame. The
streaming fallback is shared with VertexData.set via
VertexData.framePair.

Together with gallantlab#715 (packing into auxdat.zw and flatbump), Firefox no
longer depends on attribute pruning. The 8 xfail Firefox tests now pass,
so the marks are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant