Repository navigation
NF Firefox headless WebGL support; FIX Vertex in Firefox WebGL - #765
Open
kroq-gar78 wants to merge 2 commits into
Open
kroq-gar78 wants to merge 2 commits into
kroq-gar78 wants to merge 2 commits into
Conversation
headless_viewer, save_3d_views, and plot_panels gain a browser="chromium"|"firefox" parameter; only the chosen browser needs to be installed. Firefox needs a real or virtual X display to create its WebGL context (unlike Chromium's bundled SwiftShader), so when DISPLAY isn't set a private Xvfb is started, which picks its own display via -displayfd. The webgl_browser() context manager launches either browser the way the viewer does, rejects unknown browser names, and owns the browser and Xvfb teardown; _PlaywrightThread and the shader tests both use it. Tests: - test_webgl_shaders links every shader variant in both browsers. They count vertex attributes differently: Chromium's ANGLE drops declared-but-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 the two browsers agree on each type. - test_save_3d_views_headless runs in both browsers, covering the browser argument of save_3d_views. - test_headless_viewer_opens_and_closes runs in both browsers and checks that the browser and any Xvfb it started have exited after the context. The colormapped surface_vertex shader on a flatmap subject declares more than 16 attributes, so in Firefox four shader variants fail to link and Vertex/Vertex2D render blank. Those 8 cases are marked xfail(strict=True) until the shader is fixed. CI deliberately installs only Chromium, to keep CI runs short, so the Firefox tests skip there. The workflow and AGENTS.md say so. Browser tests parametrize over testing_utils.BROWSERS, read from the BrowserName literal, whose Firefox case carries the FIREFOX_MISSING skip mark; its reason says how to run them locally (playwright install firefox, plus Xvfb). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The surface_vertex shader declared two vertex attributes it never reads outside 2D vertex data (data2/data3), relying on the driver to eliminate them before enforcing GL_MAX_VERTEX_ATTRIBS (16 on all software rasterizers here). Chromium's ANGLE does prune unused declarations; Mesa's llvmpipe, used by headless Firefox, counts every declared attribute. When the program exceeds the limit it fails to link and the surface renders blank. Declare only what is actually read: 2D vertex data packs both dimensions into the .x/.y of two vec2 attributes instead of four separate floats. The dimension-to-component mapping is unchanged (.x is dim 0, data0 is frame f, data1 is frame f+1). Other dataviews declare just data0/data1, and the data2/data3 placeholder attributes in mriview_surface.js go. DataView._setPacked2D interleaves the two dimensions to match. setFrame runs on every animation frame during playback, so it keeps the packed attributes of the current frame pair: an unchanged frame costs nothing and a one-frame step reuses the previous "next" frame. The streaming next-frame fallback is shared with VertexData.set via VertexData.framePair. This complements gallantlab#715, which packed wmarea/pialarea into auxdat.zw and flatheight/flatBumpNorms into flatbump; with both, Firefox no longer needs the unused data attributes to be pruned. The 8 Firefox shader-link and vertex-render tests marked xfail now pass, so the marks are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kroq-gar78
marked this pull request as ready for review
October 13, 2026 21:23
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for Firefox in the headless WebGL renderer, and it also fixes
Vertexrendering in Firefox (#375).Summary
The user can now choose which browser to use in the relevant functions (
headless_viewer,save_3d_views) withbrowser="chromium"|"firefox". Unlike with Chromium, Firefox needs a display buffer to render to. This means that eitherDISPLAYneeds to be set, or theXvfbpackage 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_vertexshader 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
webgl_browser()context manager incortex/export/headless.pylaunches either browser and handles teardown. Headless Firefox needs an X display for WebGL, so whenDISPLAYis 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 markedxfail(strict=True).surface_vertexnow declares only the attributes it reads, and 2D vertex data is packed into twovec2attributes 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 firefoxTesting
I ran the full suite on both commits: