More clean up
This commit is contained in:
parent
c94ffcc506
commit
f03da42b5e
43 changed files with 818 additions and 1076 deletions
|
|
@ -13,17 +13,26 @@ interface SimulationFramePipelines {
|
|||
eraserAgentPipeline: EraserAgentPipeline;
|
||||
eraserTexturePipeline: EraserTexturePipeline;
|
||||
diffusionPipeline: DiffusionPipeline;
|
||||
brushEffectDiffusionPipeline: DiffusionPipeline;
|
||||
renderPipeline: RenderPipeline;
|
||||
}
|
||||
|
||||
export class SimulationFrameRenderer {
|
||||
private static readonly SOURCE_ACTIVE_FRAMES_AFTER_WRITE = 600;
|
||||
|
||||
private sourceActiveFramesRemaining = 0;
|
||||
private sourceMapsCleared = true;
|
||||
|
||||
public constructor(
|
||||
private readonly device: GPUDevice,
|
||||
private readonly textures: SimulationTextures,
|
||||
private readonly pipelines: SimulationFramePipelines
|
||||
) {}
|
||||
|
||||
public resetSourceMapActivity(): void {
|
||||
this.sourceActiveFramesRemaining = 0;
|
||||
this.sourceMapsCleared = true;
|
||||
}
|
||||
|
||||
public execute(
|
||||
isErasing: boolean,
|
||||
canvasReadbackRequest?: CanvasReadbackRequest | null
|
||||
|
|
@ -31,6 +40,7 @@ export class SimulationFrameRenderer {
|
|||
const commandEncoder = this.device.createCommandEncoder();
|
||||
|
||||
this.textures.copyTrailMapAToB(commandEncoder);
|
||||
let wroteSourceMap = false;
|
||||
if (isErasing) {
|
||||
if (this.pipelines.eraserAgentPipeline.hasActiveMask()) {
|
||||
const eraserMask = this.textures.eraserMask.getTextureView();
|
||||
|
|
@ -38,18 +48,29 @@ export class SimulationFrameRenderer {
|
|||
commandEncoder,
|
||||
eraserMask,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.influenceMapA.getTextureView(),
|
||||
this.textures.trailMapB.getTextureView()
|
||||
);
|
||||
this.pipelines.eraserAgentPipeline.execute(commandEncoder, eraserMask);
|
||||
}
|
||||
} else {
|
||||
this.pipelines.brushPipeline.executeMultiTarget(
|
||||
wroteSourceMap = this.pipelines.brushPipeline.executeMultiTarget(
|
||||
commandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.influenceMapA.getTextureView()
|
||||
this.textures.sourceMapA.getTextureView()
|
||||
);
|
||||
}
|
||||
|
||||
if (wroteSourceMap) {
|
||||
this.sourceActiveFramesRemaining =
|
||||
SimulationFrameRenderer.SOURCE_ACTIVE_FRAMES_AFTER_WRITE;
|
||||
this.sourceMapsCleared = false;
|
||||
}
|
||||
|
||||
const useSourceMap = this.sourceActiveFramesRemaining > 0;
|
||||
if (!useSourceMap && !this.sourceMapsCleared) {
|
||||
this.textures.clearSourceMaps(commandEncoder);
|
||||
this.sourceMapsCleared = true;
|
||||
}
|
||||
|
||||
this.pipelines.agentPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.trailMapA.getTextureView(),
|
||||
|
|
@ -64,28 +85,24 @@ export class SimulationFrameRenderer {
|
|||
const canvasTexture = this.pipelines.renderPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.trailMapA.getTextureView(),
|
||||
this.textures.sourceMapA.getTextureView()
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
useSourceMap
|
||||
);
|
||||
canvasReadbackRequest?.encode(commandEncoder, canvasTexture);
|
||||
|
||||
if (useSourceMap) {
|
||||
this.pipelines.diffusionPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.sourceMapB.getTextureView(),
|
||||
this.textures.sourceMapB.getSize()
|
||||
);
|
||||
}
|
||||
this.device.queue.submit([commandEncoder.finish()]);
|
||||
canvasReadbackRequest?.afterSubmit();
|
||||
|
||||
const postRenderCommandEncoder = this.device.createCommandEncoder();
|
||||
this.pipelines.diffusionPipeline.execute(
|
||||
postRenderCommandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.sourceMapB.getTextureView(),
|
||||
this.textures.sourceMapB.getSize()
|
||||
);
|
||||
this.pipelines.brushEffectDiffusionPipeline.execute(
|
||||
postRenderCommandEncoder,
|
||||
this.textures.influenceMapA.getTextureView(),
|
||||
this.textures.influenceMapB.getTextureView(),
|
||||
this.textures.influenceMapB.getSize()
|
||||
);
|
||||
|
||||
this.device.queue.submit([postRenderCommandEncoder.finish()]);
|
||||
this.textures.swapBrushEffectMaps();
|
||||
if (useSourceMap) {
|
||||
this.textures.swapSourceMaps();
|
||||
this.sourceActiveFramesRemaining -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue