Skip to content

fix: attempt to fix memory leaks by recreating kernels when needed#145

Open
Saschl wants to merge 1 commit intoflybywiresim:mainfrom
Saschl:fix/ram-is-expensive
Open

fix: attempt to fix memory leaks by recreating kernels when needed#145
Saschl wants to merge 1 commit intoflybywiresim:mainfrom
Saschl:fix/ram-is-expensive

Conversation

@Saschl
Copy link
Copy Markdown
Contributor

@Saschl Saschl commented Feb 5, 2026

As noticed by @frayien and @tracernz creating a GPU kernel with dynamicOutput might create memory leaks each time "setOutput" is called. This PR disables dynamicOutput and recreates the kernels if the output sizes change.

this.uploadWorldMapToGPU.output[1] !== worldHeight
) {
if (this.uploadWorldMapToGPU !== null) this.uploadWorldMapToGPU.destroy();
this.uploadWorldMapToGPU = this.createUploadWorldMapToGPUKernel().setOutput([worldWidth, worldHeight]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could pass the output size array into the kernel creation functions, and put it in the output property of the kernel settings object to avoid calling setOutput altogether.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea

Comment on lines +72 to +81
private createUploadWorldMapToGPUKernel(): IKernelRunShortcut {
return this.gpu.createKernel(uploadTextureData, {
argumentTypes: { texture: 'Array', width: 'Integer' },
dynamicArguments: true,
dynamicOutput: false,
pipeline: true,
immutable: false,
tactic: 'speed',
});
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

e.g.

Suggested change
private createUploadWorldMapToGPUKernel(): IKernelRunShortcut {
return this.gpu.createKernel(uploadTextureData, {
argumentTypes: { texture: 'Array', width: 'Integer' },
dynamicArguments: true,
dynamicOutput: false,
pipeline: true,
immutable: false,
tactic: 'speed',
});
}
private createUploadWorldMapToGPUKernel(output: [number, number]): IKernelRunShortcut {
return this.gpu.createKernel(uploadTextureData, {
argumentTypes: { texture: 'Array', width: 'Integer' },
dynamicArguments: true,
dynamicOutput: false,
pipeline: true,
immutable: false,
tactic: 'speed',
output,
});
}

@Saschl Saschl mentioned this pull request Feb 5, 2026
@tracernz tracernz mentioned this pull request Apr 2, 2026
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.

2 participants