WebGPU Renderer now awaits the submitted work in the old device's queue before destroying it

This commit is contained in:
Rezmason
2025-05-26 12:03:52 -07:00
parent 83f1eb07c3
commit 0884c6a4de
2 changed files with 11 additions and 6 deletions

View File

@@ -24,16 +24,16 @@ export default ({ device, cache, canvasFormat, canvasContext }) => {
const assets = [loadShader(device, cache, "shaders/wgsl/endPass.wgsl")];
const loaded = (async () => {
const [imageShader] = await Promise.all(assets);
const [endShader] = await Promise.all(assets);
renderPipeline = await device.createRenderPipelineAsync({
layout: "auto",
vertex: {
module: imageShader.module,
module: endShader.module,
entryPoint: "vertMain",
},
fragment: {
module: imageShader.module,
module: endShader.module,
entryPoint: "fragMain",
targets: [
{

View File

@@ -184,6 +184,7 @@ export default class REGLRenderer extends Renderer {
await this.#rebuildingPipeline;
this.#renderFunc(performance.now());
if (oldDevice != null) {
await oldDevice.queue.onSubmittedWorkDone();
oldDevice.destroy();
}
}
@@ -202,10 +203,14 @@ export default class REGLRenderer extends Renderer {
destroy() {
if (this.destroyed) return;
if (this.#device != null) {
this.#device.destroy(); // This also destroys any objects created with the device
this.#device = null;
const oldDevice = this.#device;
if (oldDevice != null) {
(async () => {
await oldDevice.queue.onSubmittedWorkDone();
oldDevice.destroy();
});
}
this.#device = null;
super.destroy();
}
}