-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(core): Add gpu-only memory option for layer attributes #9919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -534,6 +534,32 @@ Layers may also include specialized loaders for their own use case, such as imag | |
| Find usage examples in the [data loading guide](../../developer-guide/loading-data.md). | ||
|
|
||
|
|
||
| #### `memory` ('default' | 'gpu-only', optional) {#memory} | ||
|
|
||
| - Default: `'default'` | ||
|
|
||
| Controls how deck.gl stores generated attribute data in memory. | ||
|
|
||
| - `'default'` retains CPU-side typed arrays alongside GPU buffers. This is the current behavior and enables CPU features such as bounds queries, attribute transitions, and partial updates using cached values. | ||
| - `'gpu-only'` uploads generated attributes to GPU buffers and then releases CPU copies. This minimizes CPU memory usage and pooling, but disables features that depend on CPU-side attribute values (e.g. `layer.getBounds()`, attribute transitions, CPU validations) and forces partial updates to regenerate whole attributes or perform GPU-side copies. | ||
|
|
||
| Use `'gpu-only'` when you are feeding data through GPU-heavy pipelines and do not rely on CPU-side attribute inspection. For example: | ||
|
|
||
| ```js | ||
| import {ScatterplotLayer} from '@deck.gl/layers'; | ||
|
|
||
| const layer = new ScatterplotLayer({ | ||
| id: 'points', | ||
| data, | ||
| memory: 'gpu-only', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to allow configuration per-attribute? In general transitions are not performed on all the attributes and it seems a shame to have to waste memory just to support a transition for a single attribute. E.g. a |
||
| getPosition: d => d.position, | ||
| getFillColor: [0, 128, 255] | ||
| }); | ||
| ``` | ||
|
|
||
| deck.gl will emit runtime warnings when a CPU-dependent feature is unavailable in this mode. | ||
|
|
||
|
|
||
| #### `fetch` (Function, optional) {#fetch} | ||
|
|
||
| Called to fetch and parse content from URLs. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,3 +75,16 @@ new Deck({ | |
| _typedArrayManagerProps: isMobile ? {overAlloc: 1, poolSize: 0} : null | ||
| }) | ||
| ``` | ||
|
|
||
| ### GPU-only layer attributes | ||
|
|
||
| Layers can opt into storing generated attributes only on the GPU by setting [`memory: 'gpu-only'`](../api-reference/core/layer.md#memory). In this mode, CPU-side typed arrays are released after upload, reducing application memory pressure and avoiding typed array pooling overhead. | ||
|
|
||
| Because CPU copies are not retained, features that depend on CPU-side attribute values are disabled or downgraded: | ||
|
|
||
| - Bounds calculations (`layer.getBounds()` and any culling logic that relies on it) return `null`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we compute the bounds before discarding the CPU data? |
||
| - Attribute transitions are skipped. | ||
| - Partial attribute updates regenerate whole attributes or fall back to GPU-side copies, so update ranges are ignored. | ||
| - CPU-side validations or transformations that require staging arrays will emit runtime warnings. | ||
|
|
||
| Use this mode when your rendering pipeline is GPU-driven and you do not need CPU inspection of attribute data. Switch back to the default memory behavior if you rely on the features above. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps go for
'cpu+gpu' | 'gpu'?'default'isn't very descriptive