Skip to content

Commit

Permalink
Add snapshow facility, record scene pass as a RenderBundle for reuse,
Browse files Browse the repository at this point in the history
and reuse if present.
  • Loading branch information
aardgoose committed Oct 16, 2023
1 parent f8ab8ac commit 309f9db
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/jsm/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class Backend {

destroyAttribute( attribute ) { }

// snapshot

createSnapshot() {}

destroySnapshot() {}

// canvas

updateSize() { }
Expand Down
12 changes: 12 additions & 0 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ class Renderer {

}

createSnapshot() {

this.backend.createSnapshot();

}

destroySnapshot() {

this.backend.destroySnapshot();

}

dispose() {

this.info.dispose();
Expand Down
56 changes: 56 additions & 0 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class WebGPUBackend extends Backend {
this.textureUtils = new WebGPUTextureUtils( this );
this.occludedResolveCache = new Map();

this.createSnapshotBundle = false;
this.snapshotRenderBundles = null;

}

async init( renderer ) {
Expand Down Expand Up @@ -135,6 +138,12 @@ class WebGPUBackend extends Backend {

beginRender( renderContext ) {

if ( this.createSnapshotBundle ) {

return this._beginCreateSnapshot( renderContext );

}

const renderContextData = this.get( renderContext );

const device = this.device;
Expand Down Expand Up @@ -369,6 +378,25 @@ class WebGPUBackend extends Backend {

}

if ( this.createSnapshotBundle ) {

this.createSnapshotBundle = false;

this.snapshotRenderBundles = [ renderContextData.currentPass.finish() ];

// start real pass

this.beginRender( renderContext );


}

if ( this.snapshotRenderBundles !== null ) {

renderContextData.currentPass.executeBundles( this.snapshotRenderBundles );

}

renderContextData.currentPass.end();

if ( occlusionQueryCount > 0 ) {
Expand Down Expand Up @@ -606,6 +634,8 @@ class WebGPUBackend extends Backend {

draw( renderObject, info ) {

if ( this.snapshotRenderBundles !== null ) return;

const { object, geometry, context, pipeline } = renderObject;

const bindingsData = this.get( renderObject.getBindings() );
Expand Down Expand Up @@ -923,6 +953,18 @@ class WebGPUBackend extends Backend {

}

createSnapshot() {

this.createSnapshotBundle = true;

}

destroySnapshot() {

this.snapshotRenderBundles = null;

}

// canvas

updateSize() {
Expand Down Expand Up @@ -1080,6 +1122,20 @@ class WebGPUBackend extends Backend {

}

_beginCreateSnapshot( renderContext ) {

const renderContextData = this.get( renderContext );

renderContextData.currentPass = this.device.createRenderBundleEncoder( {
colorFormats: [ GPUTextureFormat.BGRA8Unorm ],
depthStencilFormat: this._getDepthBufferGPU( renderContext ).format,
sampleCount: this.parameters.sampleCount
} );

renderContextData.currentSets = { attributes: {} };

}

}

export default WebGPUBackend;

0 comments on commit 309f9db

Please sign in to comment.