Closed Bug 1922992 Opened 11 months ago Closed 3 months ago

[WebGPU] Instant multi-GB memory increase on https://webgpu.github.io/webgpu-samples/samples/resizeCanvas

Categories

(Core :: Graphics: WebGPU, defect)

defect

Tracking

()

RESOLVED FIXED
141 Branch
Tracking Status
firefox-esr128 --- unaffected
firefox131 --- wontfix
firefox132 --- disabled
firefox133 --- disabled
firefox139 --- disabled
firefox140 --- disabled
firefox141 --- fixed

People

(Reporter: mayankleoboy1, Assigned: aleiserson)

References

(Regression, )

Details

(Keywords: regression)

Crash Data

Attachments

(2 files)

Go to https://webgpu.github.io/webgpu-samples/samples/resizeCanvas

AR: Instant multi-GB continuous memory increase
ER: Not so

Bisection: bug 1906679

In full-screen window, the memory rise is so rapid that you cant capture any profile or about:memory.
But of you reduce the window size, the memory rise is less rapid (though still quite fast).
I managed to capture a profile with the "webgpu" preset logging: https://share.firefox.dev/3zPyEaY

Set release status flags based on info from the regressing bug 1906679

:teoxoy, since you are the author of the regressor, bug 1906679, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(ttanasoaia)
Severity: -- → S3
Flags: needinfo?(ttanasoaia)

Has the situation improved?

Flags: needinfo?(mayankleoboy1)

I can still repro.
profile with webgpu preset logging: https://share.firefox.dev/3EdyOui

Flags: needinfo?(mayankleoboy1)

Not sure this is right bugreport or not but I've got wrong behavior.

Attached file text.txt

That looks like a different issue on another sample, could you open a new bug for it?

I believe the specific problem here (on my Metal device at least) is that GPUTexture.destroy() doesn't do anything. Texture memory only gets freed on GC, even though explicitly calling destroy() sounds like it should deallocate as soon as possible.
The resizeCanvas sample creates a new multisampled texture and destroys the old one every frame, so that's why its memory usage spikes.

Here is a minimal example:

const device = await (await navigator.gpu.requestAdapter()).requestDevice();

let texture;

function recreateTexture() {
  if (texture) {
    // Texture memory isn't actually freed until GC on Firefox
    texture.destroy();
  }
  
  texture = device.createTexture({
    size: [800, 800],
    format: navigator.gpu.getPreferredCanvasFormat(),
    usage: GPUTextureUsage.RENDER_ATTACHMENT,
  });

  const commandEncoder = device.createCommandEncoder();
  const passEncoder = commandEncoder.beginRenderPass({
    colorAttachments: [{
      view: texture.createView(),
      loadOp: "clear",
      storeOp: "store",
    }]
  });

  passEncoder.end();
  device.queue.submit([commandEncoder.finish()]);

  requestAnimationFrame(recreateTexture);
}

requestAnimationFrame(recreateTexture);

I opened an issue in upstream wgpu for the potential cause: https://github.com/gfx-rs/wgpu/issues/7697

Duplicate of this bug: 1913420

ashivaram264 thanks for fixing this! I confirmed that the fix upstream resolves the issue.

Depends on: webgpu-update-wgpu
Duplicate of this bug: 1878534

Copying crash signatures from duplicate bugs.

Crash Signature: [@ wgpu_hal::vulkan::<T>::from]
Depends on: 1969027
No longer depends on: webgpu-update-wgpu

The fix for this has now landed in firefox and is in the latest nightly. The demo is working for me on Mac, but I have the impression this issue was most problematic on Windows. Since Teo verified the fix previously, I am going to close the bug anyways.

Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Assignee: nobody → aleiserson
Target Milestone: --- → 141 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: