bug(@typegpu/gl): long-lived roots retain unused uniforms and destroyed texture wrappers

Đã đóng
#3,153 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, typescript
Lĩnh vực
computer-graphics

Hướng nghiên cứu

Run pnpm verify in the linked reproduction, then read packages/typegpu-gl/src/tgpuRootWebGL.ts and packages/typegpu-gl/src/webglTexture.ts. Trace how root uniform and texture collections retain entries after resource retirement; done means destroyed texture wrappers are no longer retained by a live root and the issue's supported uniform retirement and pipeline-discovery behavior is resolved.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

While replacing resources on one long-lived GL root, I found that the root retains uniform records after callers drop them and texture wrappers after texture.destroy(). The collections grow with each replacement batch and only clear when root.destroy() runs.

Versions

  • @typegpu/gl: 0.12.5
  • typegpu: 0.12.6
  • Chromium: 153.0.8010.12
  • macOS: 27.0.1, arm64, Apple M4

I reproduced the retention with both ANGLE Metal and ANGLE SwiftShader.

Minimal reproduction

The repository https://github.com/Kaleidosium/typegpu-gl-retention-repro contains a small Vite page and a Playwright verification script. It uses no app code, shaders, rendering, images, or TypeGPU build plugin. After cloning it, run:

pnpm install
pnpm exec playwright install chromium
pnpm verify

The browser code creates one root and runs this batch three times:

import { d } from "typegpu";
import { initWithGL } from "@typegpu/gl";

const gl = new OffscreenCanvas(1, 1).getContext("webgl2");
if (!gl) throw new Error("WebGL2 is unavailable");
const root = initWithGL({ gl });

function allocate(count) {
  for (let i = 0; i < count; i++) {
    root.createUniform(d.vec4f);
    const texture = root.createTexture({
      size: [1, 1],
      format: "rgba8unorm",
    });
    texture.destroy();
  }
}

for (let batch = 0; batch < 3; batch++) allocate(100);

After each batch, the verifier forces garbage collection through CDP and reads the root's private collections. It releases its inspection handles after each read. There are no pipelines or caller-owned resource collections keeping these uniforms or textures alive.

Actual result

Checkpoint Root uniform records Raw uniform bytes Root texture wrappers Already destroyed texture wrappers
Initial 0 0 0 0
Batch 1 100 1,600 100 100
Batch 2 200 3,200 200 200
Batch 3 300 4,800 300 300
After root.destroy() 0 0 0 0

The verifier also confirms 300 native deleteTexture calls before root destruction. Native texture deletion works; the destroyed wrappers remain referenced by the root.

Source findings

In TgpuRootWebGL, createUniform() appends to #uniforms and createTexture() appends to #textures. Individual resource retirement does not remove these entries. GL uniforms have no public release method, and the internal uniform implementation's destroy() is a no-op.

createRenderPipeline() also passes this.#uniforms.slice() to the pipeline constructor, which scans the entire collection to find uniforms used by the shader. Its copy and scan therefore include historically created uniforms.

Root implementation, texture destruction.

Expected behavior

Destroyed texture wrappers should be eligible for collection while the root remains alive. For uniforms, is there an intended way to retire records that are no longer used by any pipeline? A supported retirement mechanism would let applications replace resources without retaining all historical records for the root's lifetime.

Pipeline binding discovery should also avoid work proportional to every uniform ever created on the root, where possible.

This report concerns JavaScript bookkeeping retention. The reproduction does not measure physical driver memory or establish a performance regression.

Ngôn ngữ chính
TypeScript
Star
3.3k
Fork
143
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
72

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của software-mansion/TypeGPU

Tất cả issue của software-mansion/TypeGPU

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.