Skip to content

feat!: borrow supplied GPU geometry and buffers by default - #4198

Open
ibgreen wants to merge 1 commit into
codex/resource-ownership-pocfrom
codex/borrow-geometry-by-default
Open

ibgreen wants to merge 1 commit into
codex/resource-ownership-pocfrom
codex/borrow-geometry-by-default

Conversation

@ibgreen

@ibgreen ibgreen commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Goals

Switch bare GPU geometry and buffer inputs to borrowing after applications have access to explicit ownership descriptors. This is the breaking follow-up to #4193. Review and land #4193 first.

Changes

  • Model borrows supplied GPUGeometry on construction and replacement. CPU geometry uploads remain model-owned.
  • GPUGeometry borrows supplied vertex and index buffers. GPUTableGeometry borrows its supplied index buffer and retains the existing table storage policy.
  • The Arrow mesh renderer releases its shared geometry after its draw and picking models. ArrowTableGeometry explicitly owns the index buffer it creates. Migrate exclusive model fixtures to explicit ownership.
  • Align the null backend with ordinary sampler borrowing and keep internally created DynamicTexture samplers with the underlying texture across resize.
  • Document migration in the upgrade guide and exercise the new bare defaults alongside unchanged explicit claims and borrows.

Note

Medium Risk
Breaking change to resource ownership lifetimes that may cause GPU memory leaks in caller code that previously relied on models or GPU geometries automatically destroying bare resources.

Overview
Changes default resource ownership so bare GPUGeometry and Buffer inputs are borrowed rather than destroyed by their recipients. Model now borrows bare GPUGeometry inputs on construction and replacement, while GPUGeometry and GPUTableGeometry borrow bare vertex and index buffers. CPU geometry uploaded by a model continues to be owned by that model.

Explicit {own: resource} descriptors can be used when the receiver should take ownership and manage cleanup. Additionally, DynamicTexture and the null backend are aligned to handle bare sampler borrowing without custom legacy branches. Documentation, examples, and test suites are updated to reflect the new borrowing defaults.

Reviewed by Cursor Bugbot for commit b43c093. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge, with only the earlier non-blocking request for sampler lifetime tests remaining.

Findings

  1. P2 Sampler cleanup lacks tests ▶

Summary

Supplied GPU geometry and buffers are now borrowed by default.

  • Models borrow supplied GPU geometry and own only CPU uploads.
  • Geometry containers borrow bare buffers unless they explicitly claim them.
  • Dynamic textures keep their sampler when they resize.

No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Caller[Caller or existing owner] -->|owns| Geometry[Supplied GPU geometry]
  Model[Model] -.->|borrows| Geometry
  Geometry -.->|borrows bare buffers| Buffers[Supplied GPU buffers]
  CPU[CPU geometry] -->|uploaded by Model| Upload[Model-owned GPU geometry]
  Upload -->|owns| Created[Uploaded buffers]
Loading

Reviews (2) · Last reviewed commit: "Borrow supplied GPU geometry and buffers..." · Reviewed by Greptile

Comment on lines +371 to +372
this.texture.setSampler(prev.sampler);
if (prev.sampler.owner === prev) this.texture.takeOwnershipOf(prev.sampler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Sampler cleanup lacks tests

DynamicTexture now delegates sampler cleanup to the underlying texture and keeps the current sampler across resize(). The existing resize test only checks timestamps and generation, so it would miss early destruction or a leak. Add assertions that replacement destroys an owned sampler, resize keeps the current sampler alive, final cleanup destroys it, and borrowed samplers survive. This is non-blocking test coverage feedback.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ibgreen
ibgreen force-pushed the codex/borrow-geometry-by-default branch from 291e80a to b43c093 Compare December 4, 2026 16:32

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b43c093. Configure here.

if (prev.sampler.owner === prev) this.texture.takeOwnershipOf(prev.sampler);
}
this.texture.setSampler(prev.sampler);
if (prev.sampler.owner === prev) this.texture.takeOwnershipOf(prev.sampler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Resize claims borrowed first-parent samplers

Medium Severity

DynamicTexture.resize() now calls setSampler with a bare prev.sampler. A bare sampler attachment claims a still-pending first-parent sampler, so a sampler that was only borrowed is taken over by the replacement texture. Destroying the dynamic texture then releases a sampler the caller still expected to own or offer to another texture.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b43c093. Configure here.

This branch has not been deployed

No deployments
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.

1 participant