Skip to content

Commit b067191

Browse files
authored
Inspector: WebGL2 backend version (#31982)
* inspector webgl * Update clean-page.js * update * update * Update webgpu_instance_mesh.jpg * puppeteer: add exception `webgpu_volume_lighting`, `webgpu_volume_lighting_rectarea`
1 parent 94ca22d commit b067191

File tree

13 files changed

+108
-9
lines changed

13 files changed

+108
-9
lines changed

examples/jsm/inspector/Inspector.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Inspector extends RendererInspector {
2727
profiler.addTab( parameters );
2828

2929
const viewer = new Viewer();
30+
viewer.hide();
3031
profiler.addTab( viewer );
3132

3233
const performance = new Performance();
@@ -79,7 +80,7 @@ class Inspector extends RendererInspector {
7980

8081
if ( renderer.info.frame > 1 && animationLoop !== null ) {
8182

82-
this.resolveConsoleOnce( 'info', 'TIP: "computeAsync()" was called while a "setAnimationLoop()" is active. This is probably not necessary, use "compute()" instead.' );
83+
this.resolveConsoleOnce( 'log', 'TIP: "computeAsync()" was called while a "setAnimationLoop()" is active. This is probably not necessary, use "compute()" instead.' );
8384

8485
}
8586

@@ -91,7 +92,7 @@ class Inspector extends RendererInspector {
9192

9293
if ( this.once[ key ] !== true ) {
9394

94-
this.resolveConsole( 'log', message );
95+
this.resolveConsole( type, message );
9596
this.once[ key ] = true;
9697

9798
}
@@ -303,8 +304,26 @@ class Inspector extends RendererInspector {
303304
resolveViewer() {
304305

305306
const nodes = this.currentNodes;
306-
307307
const renderer = this.getRenderer();
308+
309+
if ( nodes.length === 0 ) return;
310+
311+
if ( ! renderer.backend.isWebGPUBackend ) {
312+
313+
this.resolveConsoleOnce( 'warn', 'Inspector: Viewer is only available with WebGPU.' );
314+
315+
return;
316+
317+
}
318+
319+
//
320+
321+
if ( ! this.viewer.isVisible ) {
322+
323+
this.viewer.show();
324+
325+
}
326+
308327
const canvasDataList = nodes.map( node => this.getCanvasDataByNode( node ) );
309328

310329
this.viewer.update( renderer, canvasDataList );

examples/jsm/inspector/RendererInspector.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,16 @@ export class RendererInspector extends InspectorBase {
186186

187187
for ( const stats of frame.computes ) {
188188

189-
stats.gpu = renderer.backend.getTimestamp( stats.uid );
189+
if ( renderer.backend.hasTimestamp( stats.uid ) ) {
190+
191+
stats.gpu = renderer.backend.getTimestamp( stats.uid );
192+
193+
} else {
194+
195+
stats.gpu = 0;
196+
stats.gpuNotAvailable = true;
197+
198+
}
190199

191200
}
192201

@@ -212,7 +221,16 @@ export class RendererInspector extends InspectorBase {
212221

213222
for ( const stats of frame.renders ) {
214223

215-
stats.gpu = renderer.backend.getTimestamp( stats.uid );
224+
if ( renderer.backend.hasTimestamp( stats.uid ) ) {
225+
226+
stats.gpu = renderer.backend.getTimestamp( stats.uid );
227+
228+
} else {
229+
230+
stats.gpu = 0;
231+
stats.gpuNotAvailable = true;
232+
233+
}
216234

217235
}
218236

@@ -254,7 +272,7 @@ export class RendererInspector extends InspectorBase {
254272

255273
const renderer = this.getRenderer();
256274

257-
return renderer !== null && renderer.backend.isWebGPUBackend;
275+
return renderer !== null;
258276

259277
}
260278

examples/jsm/inspector/tabs/Performance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Performance extends Tab {
131131

132132
setText( item.data[ 0 ], item.userData.name );
133133
setText( item.data[ 1 ], data.cpu.toFixed( 2 ) );
134-
setText( item.data[ 2 ], data.gpu.toFixed( 2 ) );
134+
setText( item.data[ 2 ], stats.gpuNotAvailable === true ? '-' : data.gpu.toFixed( 2 ) );
135135
setText( item.data[ 3 ], data.total.toFixed( 2 ) );
136136

137137
//
56 KB
Loading
47.5 KB
Loading
53.2 KB
Loading
39.9 KB
Loading
6.33 KB
Loading

src/nodes/core/InspectorNode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Node from './Node.js';
2+
import InspectorBase from '../../renderers/common/InspectorBase.js';
23
import { addMethodChaining, nodeObject } from '../tsl/TSLCore.js';
34
import { NodeUpdateType } from './constants.js';
5+
import { warnOnce } from '../../utils.js';
46

57
/**
68
* InspectorNode is a wrapper node that allows inspection of node values during rendering.
@@ -92,6 +94,12 @@ class InspectorNode extends Node {
9294

9395
}
9496

97+
if ( builder.renderer.backend.isWebGPUBackend !== true && builder.renderer.inspector.constructor !== InspectorBase ) {
98+
99+
warnOnce( 'TSL: ".toInspector()" is only available with WebGPU.' );
100+
101+
}
102+
95103
return node;
96104

97105
}

src/renderers/common/Backend.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ class Backend {
473473

474474
}
475475

476+
/**
477+
* Returns all timestamp frames for the given type.
478+
*
479+
* @param {string} type - The type of the time stamp.
480+
* @return {Array<number>} The timestamp frames.
481+
*/
476482
getTimestampFrames( type ) {
477483

478484
const queryPool = this.timestampQueryPool[ type ];
@@ -481,15 +487,49 @@ class Backend {
481487

482488
}
483489

484-
getTimestamp( uid ) {
490+
/**
491+
* Returns the query pool for the given uid.
492+
*
493+
* @param {string} uid - The unique identifier.
494+
* @return {TimestampQueryPool} The query pool.
495+
*/
496+
_getQueryPool( uid ) {
485497

486498
const type = uid.startsWith( 'c:' ) ? TimestampQuery.COMPUTE : TimestampQuery.RENDER;
487499
const queryPool = this.timestampQueryPool[ type ];
488500

501+
return queryPool;
502+
503+
}
504+
505+
/**
506+
* Returns the timestamp for the given uid.
507+
*
508+
* @param {string} uid - The unique identifier.
509+
* @return {number} The timestamp.
510+
*/
511+
getTimestamp( uid ) {
512+
513+
const queryPool = this._getQueryPool( uid );
514+
489515
return queryPool.getTimestamp( uid );
490516

491517
}
492518

519+
/**
520+
* Returns `true` if a timestamp for the given uid is available.
521+
*
522+
* @param {string} uid - The unique identifier.
523+
* @return {boolean} Whether the timestamp is available or not.
524+
*/
525+
hasTimestamp( uid ) {
526+
527+
const queryPool = this._getQueryPool( uid );
528+
529+
return queryPool.hasTimestamp( uid );
530+
531+
}
532+
493533
/**
494534
* Returns `true` if the given 3D object is fully occluded by other
495535
* 3D objects in the scene. Backends must implement this method by using

0 commit comments

Comments
 (0)