Skip to content

fix(deck.gl-geotiff): draw 16-bit images in Firefox - #773

Merged
kylebarron merged 2 commits into
mainfrom
kyle/norm16-fallback
Oct 22, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/norm16-fallback

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Before:
ff-s2-before-logs

After:
ff-s2-rebased

Before:
ff-u16-before-logs

After:
ff-u16-rebased

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Closes #648.

Firefox's WebGL2 doesn't support EXT_texture_norm16, so it can't create r16unorm, rg16unorm or rgba16unorm textures. COGLayer uploads every 16-bit unsigned COG in one of these formats, and MultiCOGLayer does the same for 16-bit bands such as Sentinel-2's. luma.gl doesn't check that the format is supported, so the upload fails without an error and nothing draws.

When the device can't create one of these formats, both layers now divide the samples by 65535 and upload them as the matching 32-bit float format (r32float, rg32float or rgba32float). Shaders read the same 0-1 values either way, so LinearRescale ranges and nodata values work unchanged. If the device can't linearly filter float32 textures, they sample nearest instead. That check reads device.features.has("float32-filterable"), because luma.gl's isTextureFormatFilterable returns true for float formats on every WebGL2 device.

Devices with EXT_texture_norm16, such as Chrome, Edge and Safari, upload exactly as before. On devices without it:

  • 16-bit data takes twice the GPU memory.
  • Converting it costs about 0.3 ms per 512x512 band on the main thread, measured in Firefox.
  • MultiCOGLayer now reports the bytes it uploads, so the tile cache counts the float32 size.

Checked in Firefox 155 and Chrome 155 on macOS:

  • Firefox: the Sentinel-2 example and a uint16 test COG in COGLayer draw nothing on main and draw with this change. They still draw with OES_texture_float_linear hidden, sampling nearest.
  • Chrome with EXT_texture_norm16 hidden: the Sentinel-2 example draws, and 98.2% of its pixels are identical to the native r16unorm output. The rest differ by at most 3/255.

🤖 Written by Claude Code

…rmalized textures

Firefox's WebGL2 has no EXT_texture_norm16, so r16unorm, rg16unorm and
rgba16unorm uploads fail and 16-bit images draw nothing. When the device
can't create one of those formats, upload the samples divided by 65535
as the matching 32-bit float format, so shaders read the same values.
Sample nearest if the device can't filter float32.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 22, 2026

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This was a lot cleaner than I was expecting it to be.

@kylebarron
kylebarron merged commit da2d563 into main Oct 22, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/norm16-fallback branch October 22, 2026 17:38
kylebarron added a commit that referenced this pull request Oct 22, 2026
Since #773, createBandTexture gives a band nearest filtering when the
device can't filter its format, such as a 16-bit band uploaded as
r32float without float32-filterable. Applying `resampling: "linear"` at
render time switched those textures back to linear, which leaves them
incomplete, so they read as 0. Check `isFilterable` there too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 22, 2026
Since #773, createBandTexture gives a band nearest filtering when the
device can't filter its format, such as a 16-bit band uploaded as
r32float without float32-filterable. Applying `resampling: "linear"` at
render time switched those textures back to linear, which leaves them
incomplete, so they read as 0. Check `isFilterable` there too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 22, 2026
Since #773, createBandTexture gives a band nearest filtering when the
device can't filter its format, such as a 16-bit band uploaded as
r32float without float32-filterable. Applying `resampling: "linear"` at
render time switched those textures back to linear, which leaves them
incomplete, so they read as 0. Check `isFilterable` there too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron added a commit that referenced this pull request Oct 22, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

`MultiCOGLayer` creates its band textures itself and always filters them
linearly, with no way to change it. This adds `resampling?: "linear" |
"nearest"`, defaulting to `"linear"` (today's behavior).

Nearest shows the data's own pixels. It also matters with an exact-match
nodata filter such as `FilterNoDataVal`: linear filtering blends the
nodata value into the pixels next to it, so they no longer match it and
draw as a rim around nodata areas.

The filter is applied each time a tile is rendered, not only when its
textures are created. luma.gl stores the filter on each texture, and
`renderTile` runs for every loaded tile whenever the layer's props
change, so switching `resampling` updates loaded tiles without fetching
them again. A band whose format the device can't filter, such as a
16-bit band stored as `r32float` on a device without
`float32-filterable` (#773), stays nearest either way.

The Sentinel-2 example gets a Resampling selector.

This replaces #640's `bandSampler: SamplerProps` with a smaller API.
Thanks to @willjnz for the original PR, and to @earlybard for the nodata
case.

Closes #640
Ref #215

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: William Jones <[email protected]>
kylebarron added a commit that referenced this pull request Oct 22, 2026
…COGLayer (experimental) (#777)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

`MultiCOGLayer` only uploaded `Uint8Array` and `Uint16Array` bands, so a
source with any other sample type, such as Int16 or Float32, threw
`Unsupported typed array type` on every tile.

Signed integers, `uint32` and floats now upload as `r32float`, converted
to `Float32Array` where needed, so the shader reads raw sample values.
Integer texture formats would need an integer sampler, which
`CompositeBands`' `sampler2D` can't read. Integers past 2^24 and
`Float64Array` samples round to float32.

These bands sample nearest where the device can't filter float32
textures: `createBandTexture` and the `resampling` prop from #775 both
check with `isFilterable` from #773. luma.gl's
`isTextureFormatFilterable` reports `r32float` as filterable on every
WebGL2 device. A linear sampler without `OES_texture_float_linear`
leaves the texture incomplete, so the scene draws black.

`uint8` and `uint16` bands still reach the render pipeline normalized to
0-1, while every other type keeps its raw value. The `renderPipeline`
docs now say so, since nodata values and rescale ranges depend on it.
They also mark the other types as experimental: that split is likely to
change so that every type arrives in the same units. The tile cache
counts the float32 bytes uploaded, which for Int16 is twice the source
size.

Thanks to @earlybard for #650, which this finishes. His two commits are
kept, followed by merges of main (resolved onto #773's
`createBandTexture`) and docs commits.

Checked in Chrome 155 on macOS with the Int16 scene from #650 (Digital
Earth Australia Sentinel-2 ARD, nodata -999):

- main: nothing draws, and every tile throws `Unsupported typed array
type: Int16Array`.
- This branch: the scene draws, and its nodata area is transparent.
- This branch with `OES_texture_float_linear` hidden: the scene draws,
sampling nearest. #650's own fallback drew it black.
- The Sentinel-2 example's `uint16` scene is unchanged.

Closes #650

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Dylan Jenkins <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallbacks for unsupported texture formats / WebGL extensions not available

1 participant