Skip to content

Commit

Permalink
Merge pull request #5188 from rahwang/per-tile-stats
Browse files Browse the repository at this point in the history
Per tile stats
  • Loading branch information
lilleyse authored May 3, 2017
2 parents 43075de + bed4f78 commit fca40cb
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 57 deletions.
4 changes: 4 additions & 0 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ define([
}
this._viewerRequestVolume = viewerRequestVolume;

this._commandsLength = 0;

/**
* The error, in meters, introduced if this tile is rendered and its children are not.
* This is used to compute Screen-Space Error (SSE), i.e., the error measured in pixels.
Expand Down Expand Up @@ -851,9 +853,11 @@ define([
* @private
*/
Cesium3DTile.prototype.update = function(tileset, frameState) {
var initCommandLength = frameState.commandList.length;
applyDebugSettings(this, tileset, frameState);
this._content.update(tileset, frameState);
this._transformDirty = false;
this._commandsLength = frameState.commandList.length - initCommandLength;
};

var scratchCommandList = [];
Expand Down
90 changes: 77 additions & 13 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ define([
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile.
* @param {Boolean} [options.debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content.
* @param {Boolean} [options.debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile.
* @param {Boolean} [options.debugShowGeometricError=false] For debugging only. When true, draws labels to indicate the geometric error of each tile
* @param {Boolean} [options.debugShowGeometricError=false] For debugging only. When true, draws labels to indicate the geometric error of each tile.
* @param {Boolean} [options.debugShowRenderingStatistics=false] For debugging only. When true, draws labels to indicate the number of commands, points, triangles and features for each tile.
* @param {Boolean} [options.debugShowMemoryUsage=false] For debugging only. When true, draws labels to indicate the texture and vertex memory in megabytes used by each tile.
* @param {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the tileset casts or receives shadows from each light source.
* @param {Boolean} [options.skipLODs=true] Determines if level-of-detail skipping optimization should be used.
* @param {Number} [options.skipSSEFactor=10] Multiplier defining the minimum screen space error to skip when loading tiles. Used in conjuction with skipLevels to determine which tiles to load.
Expand Down Expand Up @@ -401,7 +403,29 @@ define([
* @default false
*/
this.debugShowGeometricError = defaultValue(options.debugShowGeometricError, false);
this._geometricErrorLabels = undefined;
this._tileInfoLabels = undefined;

/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the number of commands, points, triangles and features for this tile.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowRenderingStatistics = defaultValue(options.debugShowRenderingStatistics, false);

/**
* This property is for debugging only; it is not optimized for production use.
* <p>
* When true, draws labels to indicate the vertex and texture memory usage.
* </p>
*
* @type {Boolean}
* @default false
*/
this.debugShowMemoryUsage = defaultValue(options.debugShowMemoryUsage, false);

/**
* The event fired to indicate progress of loading new tiles. This event is fired when a new tile
Expand Down Expand Up @@ -1838,10 +1862,10 @@ define([

var scratchCartesian2 = new Cartesian3();

function updateGeometricErrorLabels(tileset, frameState) {
function updateTileInfoLabels(tileset, frameState) {
var selectedTiles = tileset._selectedTiles;
var length = selectedTiles.length;
tileset._geometricErrorLabels.removeAll();
tileset._tileInfoLabels.removeAll();
for (var i = 0; i < length; ++i) {
var tile = selectedTiles[i];
var boundingVolume = tile._boundingVolume.boundingVolume;
Expand All @@ -1858,12 +1882,49 @@ define([
normal = Cartesian3.multiplyByScalar(normal, 0.75 * radius, scratchCartesian2);
position = Cartesian3.add(normal, boundingVolume.center, scratchCartesian2);
}
tileset._geometricErrorLabels.add({
text: tile.geometricError.toString(),
position: position

var labelString = '';
var attributes = 0;

if (tileset.debugShowGeometricError) {
labelString += '\nGeometric error: ' + tile.geometricError;
attributes++;
}
if (tileset.debugShowRenderingStatistics) {
labelString += '\nCommands: ' + tile._commandsLength;
attributes++;

// Don't display number of points or triangles if 0.
var numberOfPoints = tile.content.pointsLength;
if (numberOfPoints > 0) {
labelString += '\nPoints: ' + tile.content.pointsLength;
attributes++;
}
var numberOfTriangles = tile.content.trianglesLength;
if (numberOfTriangles > 0) {
labelString += '\nTriangles: ' + tile.content.trianglesLength;
attributes++;
}

labelString += '\nFeatures: ' + tile.content.featuresLength;
attributes ++;
}

if (tileset.debugShowMemoryUsage) {
labelString += '\nTexture Memory: ' + (tile.content.textureMemorySizeInBytes / 1048576.0).toFixed(3);
labelString += '\nVertex Memory: ' + (tile.content.vertexMemorySizeInBytes / 1048576.0).toFixed(3);
attributes += 2;
}

tileset._tileInfoLabels.add({
text : labelString.substring(1),
position : position,
font : (19-attributes) + 'px sans-serif',
showBackground : true,
disableDepthTestDistance : Number.POSITIVE_INFINITY
});
}
tileset._geometricErrorLabels.update(frameState);
tileset._tileInfoLabels.update(frameState);
}

var stencilClearCommand = new ClearCommand({
Expand Down Expand Up @@ -1948,13 +2009,13 @@ define([
// Number of commands added by each update above
tileset._statistics.numberOfCommands = (commandList.length - numberOfInitialCommands);

if (tileset.debugShowGeometricError) {
if (!defined(tileset._geometricErrorLabels)) {
tileset._geometricErrorLabels = new LabelCollection();
if (tileset.debugShowGeometricError || tileset.debugShowRenderingStatistics || tileset.debugShowMemoryUsage) {
if (!defined(tileset._tileInfoLabels)) {
tileset._tileInfoLabels = new LabelCollection();
}
updateGeometricErrorLabels(tileset, frameState);
updateTileInfoLabels(tileset, frameState);
} else {
tileset._geometricErrorLabels = tileset._geometricErrorLabels && tileset._geometricErrorLabels.destroy();
tileset._tileInfoLabels = tileset._tileInfoLabels && tileset._tileInfoLabels.destroy();
}
}

Expand Down Expand Up @@ -2115,6 +2176,9 @@ define([
* @see Cesium3DTileset#isDestroyed
*/
Cesium3DTileset.prototype.destroy = function() {
// Destroy debug labels
this._tileInfoLabels = this._tileInfoLabels && this._tileInfoLabels.destroy();

// Traverse the tree and destroy all tiles
if (defined(this._root)) {
var stack = scratchStack;
Expand Down
1 change: 0 additions & 1 deletion Source/Scene/Instanced3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ define([
this.featurePropertiesDirty = false;

this._features = undefined;

initialize(this, arrayBuffer, byteOffset);
}

Expand Down
5 changes: 0 additions & 5 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3356,11 +3356,6 @@ define([

function triangleCountFromPrimitiveIndices(primitive, indicesCount) {
switch (primitive.mode) {
case PrimitiveType.POINTS:
case PrimitiveType.LINES:
case PrimitiveType.LINE_LOOP:
case PrimitiveType.LINE_STRIP:
return 0;
case PrimitiveType.TRIANGLES:
return (indicesCount / 3);
case PrimitiveType.TRIANGLE_STRIP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ define([
var displayPanelContents = document.createElement('div');
var updatePanelContents = document.createElement('div');
var loggingPanelContents = document.createElement('div');
var tileInfoPanelContents = document.createElement('div');
var stylePanelContents = document.createElement('div');

var properties = document.createElement('div');
Expand All @@ -152,7 +153,6 @@ define([
displayPanelContents.appendChild(makeCheckbox('showBoundingVolumes', 'Bounding Volumes'));
displayPanelContents.appendChild(makeCheckbox('showContentBoundingVolumes', 'Content Volumes'));
displayPanelContents.appendChild(makeCheckbox('showRequestVolumes', 'Request Volumes'));
displayPanelContents.appendChild(makeCheckbox('showGeometricError', 'Geometric Error'));

updatePanelContents.appendChild(makeCheckbox('freezeFrame', 'Freeze Frame'));
updatePanelContents.appendChild(makeCheckbox('dynamicScreenSpaceError', 'Dynamic Screen Space Error'));
Expand Down Expand Up @@ -196,17 +196,23 @@ define([
errorBox.setAttribute('data-bind', 'text: editorError');
stylePanelContents.appendChild(errorBox);

tileInfoPanelContents.appendChild(makeCheckbox('showGeometricError', 'Geometric Error'));
tileInfoPanelContents.appendChild(makeCheckbox('showRenderingStatistics', 'Rendering Statistics'));
tileInfoPanelContents.appendChild(makeCheckbox('showMemoryUsage', 'Memory Usage (MB)'));

var tilesetPanel = makeSection('Tileset', 'tilesetVisible', 'toggleTileset', tilesetPanelContents);
var displayPanel = makeSection('Display', 'displayVisible', 'toggleDisplay', displayPanelContents);
var updatePanel = makeSection('Update', 'updateVisible', 'toggleUpdate', updatePanelContents);
var loggingPanel = makeSection('Logging', 'loggingVisible', 'toggleLogging', loggingPanelContents);
var tileInfoPanel = makeSection('Tile Info', 'tileInfoVisible', 'toggleTileInfo', tileInfoPanelContents);
var stylePanel = makeSection('Style', 'styleVisible', 'toggleStyle', stylePanelContents);

// first add and bind all the toggleable panels
element.appendChild(tilesetPanel);
element.appendChild(displayPanel);
element.appendChild(updatePanel);
element.appendChild(loggingPanel);
element.appendChild(tileInfoPanel);
element.appendChild(stylePanel);

knockout.applyBindings(viewModel, element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ define([
*/
this.styleVisible = false;

/**
* Gets or sets the flag to show the tile info section. This property is observable.
*
* @type {Boolean}
* @default false
*/
this.tileInfoVisible = false;

/**
* Gets or sets the JSON for the tileset style. This property is observable.
*
Expand All @@ -234,7 +242,7 @@ define([
this._feature = undefined;

knockout.track(this, ['performance', 'inspectorVisible', '_statsText', '_pickStatsText', '_editorError', 'showPickStats', 'showStats',
'tilesetVisible', 'displayVisible', 'updateVisible', 'loggingVisible', 'styleVisible', 'styleString', '_feature']);
'tilesetVisible', 'displayVisible', 'updateVisible', 'loggingVisible', 'styleVisible', 'tileInfoVisible', 'styleString', '_feature']);

this._properties = knockout.observable({});
/**
Expand Down Expand Up @@ -317,6 +325,7 @@ define([
}
}
});

/**
* Gets or sets the flag to enable picking. This property is observable.
*
Expand Down Expand Up @@ -428,6 +437,27 @@ define([
*/
this.showRequestVolumes = false;

var freezeFrame = knockout.observable();
knockout.defineProperty(this, 'freezeFrame', {
get : function() {
return freezeFrame();
},
set : function(value) {
freezeFrame(value);
if (that._tileset) {
that._tileset.debugFreezeFrame = value;
that._scene.debugShowFrustumPlanes = value;
}
}
});
/**
* Gets or sets the flag to suspend updates. This property is observable.
*
* @type {Boolean}
* @default false
*/
this.freezeFrame = false;

var showGeometricError = knockout.observable();
knockout.defineProperty(this, 'showGeometricError', {
get : function() {
Expand All @@ -448,26 +478,47 @@ define([
*/
this.showGeometricError = false;

var freezeFrame = knockout.observable();
knockout.defineProperty(this, 'freezeFrame', {
var showRenderingStatistics = knockout.observable();
knockout.defineProperty(this, 'showRenderingStatistics', {
get : function() {
return freezeFrame();
return showRenderingStatistics();
},
set : function(value) {
freezeFrame(value);
showRenderingStatistics(value);
if (that._tileset) {
that._tileset.debugFreezeFrame = value;
that._scene.debugShowFrustumPlanes = value;
that._tileset.debugShowRenderingStatistics = value;
}
}
});
/**
* Gets or sets the flag to suspend updates. This property is observable.
* Displays the number of commands, points, triangles and features used per tile. This property is observable.
* @memberof Cesium3DTilesInspectorViewModel.prototype
*
* @type {Boolean}
* @default false
*/
this.freezeFrame = false;
this.showRenderingStatistics = false;

var showMemoryUsage = knockout.observable();
knockout.defineProperty(this, 'showMemoryUsage', {
get : function() {
return showMemoryUsage();
},
set : function(value) {
showMemoryUsage(value);
if (that._tileset) {
that._tileset.debugShowMemoryUsage = value;
}
}
});
/**
* Displays the memory used per tile. This property is observable.
* @memberof Cesium3DTilesInspectorViewModel.prototype
*
* @type {Boolean}
* @default false
*/
this.showMemoryUsage = false;

var maximumScreenSpaceError = knockout.observable();
knockout.defineProperty(this, 'maximumScreenSpaceError', {
Expand Down Expand Up @@ -573,8 +624,9 @@ define([
this._style = undefined;
this._shouldStyle = false;
this._definedProperties = ['properties', 'dynamicScreenSpaceError', 'colorBlendMode', 'picking', 'colorize', 'wireframe', 'showBoundingVolumes',
'showContentBoundingVolumes', 'showRequestVolumes', 'showGeometricError', 'freezeFrame', 'maximumScreenSpaceError',
'dynamicScreenSpaceErrorDensity', 'dynamicScreenSpaceErrorDensitySliderValue', 'dynamicScreenSpaceErrorFactor', 'pickActive'];
'showContentBoundingVolumes', 'showRequestVolumes', 'freezeFrame', 'maximumScreenSpaceError', 'dynamicScreenSpaceErrorDensity',
'dynamicScreenSpaceErrorDensitySliderValue', 'dynamicScreenSpaceErrorFactor', 'pickActive', 'showGeometricError',
'showRenderingStatistics', 'showMemoryUsage'];
this._removePostRenderEvent = scene.postRender.addEventListener(function() {
that._update();
});
Expand Down Expand Up @@ -680,8 +732,10 @@ define([
'showBoundingVolumes',
'showContentBoundingVolumes',
'showRequestVolumes',
'freezeFrame',
'showGeometricError',
'freezeFrame'];
'showRenderingStatistics',
'showMemoryUsage'];
var length = settings.length;
for (var i = 0; i < length; ++i) {
var setting = settings[i];
Expand Down Expand Up @@ -785,6 +839,13 @@ define([
this.styleVisible = !this.styleVisible;
};

/**
* Toggles the visibility of the tile info section
*/
Cesium3DTilesInspectorViewModel.prototype.toggleTileInfo = function() {
this.tileInfoVisible = !this.tileInfoVisible;
};

/**
* Trims tile cache
*/
Expand Down
Loading

0 comments on commit fca40cb

Please sign in to comment.