Skip to content
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

Text: Leaks memory if no text is being displayed #1252

Open
hordurj opened this issue Aug 24, 2024 · 1 comment
Open

Text: Leaks memory if no text is being displayed #1252

hordurj opened this issue Aug 24, 2024 · 1 comment
Labels
bug Something isn't working needs-triage Issues that need triaging

Comments

@hordurj
Copy link
Contributor

hordurj commented Aug 24, 2024

If no text is being displayed then gfx.Text.updatePipeline leaks memory when used in d3d12.

There is a defer on encoder.release but that does not seem to be sufficient to release the resources that the d3d12 backend allocates when the encoder is created. To fully release encoder.finish needs to be called and the resulting command needs to be submitted to the queue.

Two things to consider here:

  1. There is no need to create the encoder unless it will be used. I.e. check num_texts and glyphs.items.len before creating it. So that is a simple fix to the current issue.
  2. Check why it is not sufficient to call release on the encoder if it was not used. Do other backends have the same behavior?
@hordurj hordurj added bug Something isn't working needs-triage Issues that need triaging labels Aug 24, 2024
@hordurj
Copy link
Contributor Author

hordurj commented Aug 24, 2024

When the CommandEncoder is created in the d3d12 there is also an underlying CommandBuffer and a ReferenceTracker created. The reference tracker keeps track of references to buffer and other resources used by the commands. The commands can extend beyond the lifetime of the command encoder, so the reference tracker is not destroyed until the command has been completed on the gpu device queue.

To allow cancelling a command encoder, it would be possible to monitor if finish was called on it or not. If finish was not called then the release of the commandencoder could handle destruction of resources that would otherwise be released after they were submitted to the device queue.

A side note.
In sysgpu there is a function tick(). But it is not called anywhere in mach. This means for the d3d12 implementation, the referencetracker are releaseed in processQueuedOperations when a new commandAllocator is created when the CommandBuffer is initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issues that need triaging
Projects
None yet
Development

No branches or pull requests

1 participant