Skip to content

fix: tolerate drivers that eliminate the mercator-only uniforms - #91

Open
giswqs wants to merge 1 commit into
carbonplan:mainfrom
giswqs:fix/inactive-mercator-uniforms
Open

fix: tolerate drivers that eliminate the mercator-only uniforms#91
giswqs wants to merge 1 commit into
carbonplan:mainfrom
giswqs:fix/inactive-mercator-uniforms

Conversation

@giswqs

@giswqs giswqs commented Sep 12, 2026

Copy link
Copy Markdown

Problem

On Mesa GPUs (Intel and AMD integrated graphics, llvmpipe) a layer whose store carries a CRS disappears as soon as MapLibre leaves the globe transition: at zoom 12 and above with the globe preset, and at every zoom in plain mercator. Nothing is reported in the UI. Reported against GeoLibre in opengeos/GeoLibre#2357, reproduced with the NOAA OISST sample and a small UTM store.

Cause

The flat source-projected (maplibre-proj4) vertex shader computes gl_Position from u_anchor_clip + deltaClip, so shift_x, shift_y and u_worldXOffset only feed the v_mercatorPos varying, which the fragment shader never reads. Mesa eliminates that chain at link time and reports the three uniforms inactive, while NVIDIA keeps them active. mustGetUniformLocation then throws Failed to get uniform location for shift_x on every frame, the program is never cached so it is recompiled each frame, and MapLibre's frame loop swallows the exception, so the layer silently stops drawing.

Verified by dumping the active uniforms in WebKitGTK on llvmpipe: the ECEF variant used below zoom 12 keeps all three, the flat variant compiled at zoom 12 loses them.

Fix

Look those three uniforms up with the non-throwing gl.getUniformLocation, the way matrix, u_eye_matrix and u_anchor_clip already are. A null location is a no-op for gl.uniform1f, so the upload sites need no changes. The fake GL fixture gains an inactiveUniforms option so tests can model a driver that drops them; two new tests cover the program build and the render path, and both fail without the fix.

Verified in GeoLibre against Mesa llvmpipe (WebKitGTK) and NVIDIA (Chrome): the layer now renders at zoom 12.5 and 14 in globe and at 11.5 and 13 in mercator, with no errors thrown.

Fixes opengeos/GeoLibre#2357

In the source-projected flat (wgs84) shader gl_Position is computed from
u_anchor_clip + deltaClip, so shift_x, shift_y and u_worldXOffset only feed
the v_mercatorPos varying, which the fragment shader never reads. Mesa
(Intel, AMD, llvmpipe) eliminates that chain at link time and reports the
three uniforms inactive; NVIDIA keeps them active. mustGetUniformLocation
then threw on every frame as soon as MapLibre left the globe transition
(zoom >= 12 with the globe preset, or any zoom in plain mercator), and
MapLibre's frame loop swallowed the exception, so the layer silently
vanished with no error in the UI.

Look those three uniforms up without throwing, the way matrix and
u_eye_matrix already are; a null location is a no-op for gl.uniform1f.
The fake GL fixture gains an inactiveUniforms option so the tests can model
a driver that drops them.

Fixes opengeos/GeoLibre#2357.
@vercel

vercel Bot commented Sep 12, 2026

Copy link
Copy Markdown

@giswqs is attempting to deploy a commit to the carbonplan Team on Vercel.

A member of the Team first needs to authorize it.

@giswqs

giswqs commented Sep 12, 2026

Copy link
Copy Markdown
Author

Here is a demo showing the layer disappears at high zoom level on my laptop.

https://zarr-layer.demo.carbonplan.org/?dataset=temperature_v3

screenrecording-2026-09-11_19-35-33.mp4

giswqs added a commit to opengeos/GeoLibre that referenced this pull request Sep 12, 2026
On Intel and AMD integrated graphics (Mesa) a Zarr layer with a CRS vanished
as soon as MapLibre left the globe transition: at zoom 12 and above with the
globe projection, and at every zoom in plain Mercator. @carbonplan/zarr-layer
compiles its flat source-projected shader there, where shift_x, shift_y and
u_worldXOffset only feed a varying the fragment shader never reads. Mesa
eliminates them at link time and reports them inactive, the renderer's strict
uniform lookup threw on every frame, and MapLibre's frame loop swallowed the
exception, so nothing surfaced in the UI. NVIDIA keeps the uniforms active,
which is why it never reproduced there.

Carry the upstream fix (carbonplan/zarr-layer#91) as a patch-package patch
until a release ships it: look those three uniforms up without throwing, as
the renderer already does for its matrix uniforms. A test pins the installed
bundle so a dependency bump that silently drops the patch fails the suite.

Fixes #2357
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.

[Bug]: Zarr layer stops rendering above zoom ~12

1 participant