Repository navigation
feat: add webgl-only endpoints - #10504
Conversation
|
As of today, the WebGPU path adds ~400k to supported layers. |
9325b52 to
b3e267f
Compare
|
400kb or 400k lines? |
|
Nice exposition.
To go further, one idea would be to use vite/webpack/node conditions - these lets the build system pick export path via config, across many modules, (importantly, apps don't need to hard code their import selection with subpaths). While there are still complications, it is possible that this could make this code splitting approach tolerable. Conditions proposal
Conceptually: {
"exports": {
".": {
"types": "./dist/index.d.ts",
"deck-gl:webgpu-only": {
"import": "./dist-webgpu/index.js",
"require": "./dist-webgpu/index.cjs"
},
"deck-gl:webgl-only": {
"import": "./dist-webgl/index.js",
"require": "./dist-webgl/index.cjs"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
}
}Applications retain normal imports: import {Deck} from '@deck.gl/core';
import {GeoJsonLayer} from '@deck.gl/layers';
import {TileLayer} from '@deck.gl/geo-layers';A legacy WebGL-only Vite application would configure: export default defineConfig({
resolve: {
conditions: ['deck-gl:webgl-only']
}
});
These are established conditional-export mechanisms in Vite, Webpack, and Node. This has several advantages over the current PR:
The stripping transform can largely remain an internal build mechanism.
|
|
Also I am a bit worried about dual build times, it is already a heavy repo to work in, some optimization in that regard would be nice. |
|
@chrisgervang My bad, that last number was including the webgpu adapter. It should be ~90KB minified. |
|
@ibgreen The only doubled up part of the build process is TypeScript transpilation, which is pretty fast. |
|
Switched to condition exports. |
|
First I've heard of conditions, I think that's a nice solution for this. I'm generally in favor of the default experience being the most convenient one to use, rather than the most optimal - and this aligns with that prioritization. As an aside, I wonder if this would be a good option to add to react-map-gl as well in the next major release, since applications tend to use one map or the other (especially for legacy-mapbox). |
There was a problem hiding this comment.
Looking good:
- The conditional-export direction is preferable to
/webgpusubpaths or dynamic shader imports: - the normal entry remains WebGPU-capable,
- while WebGL-only applications get a static graph without runtime chunks (micro-stutters).
deck.gl feedback notes
- The PR description is stale—it still documents the deleted
/webgpuentry points and reversed default behavior. We should replace it with the conditional-export contract and bundler examples.
Complications:
- Vite's
resolve.conditionsis non-inheriting, so an example containing only['deck-gl:webgl-only']drops Vite'smodule,browser, anddevelopment|productiondefaults; - Webpack likewise needs
['deck-gl:webgl-only', '...']to retain its defaults.
Is it possible to add package-level validation for both ESM and CommonJS condition resolution?
- a WebGL render using the alternate output, an output-size/WGSL scan,
- and a default-build WebGPU test.
deck.gl-community implications
Given the ongoing WebGPU porting work in deck.gl-community, this PR should really be accompanied by a companion PR in that repo, it could add a compatibility matrix or canary integration covering:
- default deck.gl + community WebGPU shader/browser tests;
- WebGL-only condition + a community WebGL bundle/render;
- explicit behavior when a WebGPU device is supplied to a WebGL-only graph.
Until dependent shader-bearing packages adopt the same condition, this should be described as “deck.gl packages without WebGPU assets,” not necessarily an application-wide WebGL-only bundle.
| "bootstrap": "yarn && ocular-bootstrap", | ||
| "clean": "ocular-clean", | ||
| "build": "npm run clean && ocular-build && lerna run build", | ||
| "build": "npm run clean && node scripts/set-webgpu-build.mjs false && ocular-build core,extensions,layers,mesh-layers,aggregation-layers,geo-layers && node scripts/move-webgl-output.mjs && node scripts/set-webgpu-build.mjs true && ocular-build && lerna run build", |
There was a problem hiding this comment.
This sequence mutates the tracked root tsconfig.json to includesWebGPU: false, then restores it only after the first build and move succeed. If either step fails, the checkout remains in WebGL-only mode and a later direct build can silently emit the wrong variant. Could we use a separate WebGL-only tsconfig/build option, or run the toggle through a wrapper with try/finally that always restores the canonical configuration.
There was a problem hiding this comment.
I thought about it, then decided that it's not a big deal because the transform does not affect anything but the build process...
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "deck-gl:webgl-only": { |
There was a problem hiding this comment.
This condition name and behavior need to be treated as an ecosystem contract, not just a deck.gl implementation detail. deck.gl-community is actively adding native WGSL and currently publishes a single distribution.
Resolver conditions only affect packages that implement the same branch, so selecting this condition would strip some deck.gl WGSL while leaving community WGSL and possibly the WebGPU adapter in the application graph.
Before publishing this API, could we decide whether the shared condition should be ecosystem-scoped (for example visgl:webgl-only) or explicitly document that dependent packages should implement deck-gl:webgl-only, and provide reusable build tooling rather than requiring them to copy this private transformer.
There was a problem hiding this comment.
I prefer deck-gl if all WebGPU code paths in deck.gl-community eventually are fed into Deck.
There was a problem hiding this comment.
Or deckgl:webgl-only?
|
Upstreamed the ts transform to dev-tools |
dd77201 to
3f8c71f
Compare
|
Updated after offline discussion:
|
Background
Dual-publish core and layer catalogues to a second
/webgpuendpoint. The default endpoint will have WGSL source stripped and only supports WebGL. The new endpoint will support both devices. To opt-in WebGPU, an app may just append/webgputo the import paths, and it prefer creating a WebGPU device if available.Change List
webgpuAdapterin default devicePropsNext Step