Open hordurj opened 2 months ago
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.
@hordurj Would you be able to check if https://github.com/hexops/mach/pull/1289 fixes this leak?
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?