Skip to content

Commit

Permalink
Merge pull request #12331 from CesiumGS/fix-resource-statistics-draft
Browse files Browse the repository at this point in the history
Draft for handling shared textures in statistics
  • Loading branch information
lilleyse authored Nov 27, 2024
2 parents 31fdab5 + 131ebff commit c403b50
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

##### Fixes :wrench:

- Fixed bug where shared external textures from glTF files were not accounted for in resource statistics. [#12331](https://github.com/CesiumGS/cesium/pull/12331)
- Fix label rendering bug in WebGL1 contexts. [#12301](https://github.com/CesiumGS/cesium/pull/12301)
- Fixed lag or crashes when loading many models in the same frame. [#12320](https://github.com/CesiumGS/cesium/pull/12320)
- Updated WMS example URL in UrlTemplateImageryProvider documentation to use an active service. [#12323](https://github.com/CesiumGS/cesium/pull/12323)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"asset": {
"version": "1.1"
},
"geometricError": 4096,
"root": {
"boundingVolume": {
"box": [
3.5,
0,
0.5,
3.5,
0,
0,
0,
0,
0,
0,
0,
0.5
]
},
"geometricError": 1024,
"children": [
{
"boundingVolume": {
"box": [
0.5,
0,
0.5,
0.5,
0,
0,
0,
0,
0,
0,
0,
0.5
]
},
"geometricError": 512,
"content": {
"uri": "plane-0.glb"
}
},
{
"boundingVolume": {
"box": [
2.5,
0,
0.5,
0.5,
0,
0,
0,
0,
0,
0,
0,
0.5
]
},
"geometricError": 512,
"content": {
"uri": "plane-1.glb"
}
},
{
"boundingVolume": {
"box": [
4.5,
0,
0.5,
0.5,
0,
0,
0,
0,
0,
0,
0,
0.5
]
},
"geometricError": 512,
"content": {
"uri": "plane-2.glb"
}
},
{
"boundingVolume": {
"box": [
6.5,
0,
0.5,
0.5,
0,
0,
0,
0,
0,
0,
0,
0.5
]
},
"geometricError": 512,
"content": {
"uri": "plane-3.glb"
}
}
],
"refine": "ADD"
}
}
3 changes: 2 additions & 1 deletion packages/engine/Source/Renderer/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import TextureMinificationFilter from "./TextureMinificationFilter.js";
* @property {number} [width] The pixel width of the texture. If not supplied, must be available from the source.
* @property {number} [height] The pixel height of the texture. If not supplied, must be available from the source.
* @property {boolean} [preMultiplyAlpha] If true, the alpha channel will be multiplied into the other channels.
* @property {string} [id] A unique identifier for the texture. If this is not given, then a GUID will be created.
*
* @private
*/
Expand Down Expand Up @@ -216,7 +217,7 @@ function Texture(options) {
? PixelFormat.compressedTextureSizeInBytes(pixelFormat, width, height)
: PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, height);

this._id = createGuid();
this._id = options.id ?? createGuid();
this._context = context;
this._textureFilterAnisotropic = context._textureFilterAnisotropic;
this._textureTarget = gl.TEXTURE_2D;
Expand Down
151 changes: 109 additions & 42 deletions packages/engine/Source/Scene/Cesium3DTilesetStatistics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defined from "../Core/defined.js";
import Model3DTileContent from "./Model/Model3DTileContent.js";

/**
* @private
Expand Down Expand Up @@ -29,6 +30,7 @@ function Cesium3DTilesetStatistics() {
// Memory statistics
this.geometryByteLength = 0;
this.texturesByteLength = 0;
this.texturesReferenceCounterById = {};
this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for
}

Expand All @@ -45,61 +47,123 @@ Cesium3DTilesetStatistics.prototype.clear = function () {
this.numberOfTilesCulledWithChildrenUnion = 0;
};

function updatePointAndFeatureCounts(statistics, content, decrement, load) {
/**
* Increment the counters for the points, triangles, and features
* that are currently selected for rendering.
*
* This will be called recursively for the given content and
* all its inner contents
*
* @param {Cesium3DTileContent} content
*/
Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
content,
) {
this.numberOfFeaturesSelected += content.featuresLength;
this.numberOfPointsSelected += content.pointsLength;
this.numberOfTrianglesSelected += content.trianglesLength;

// Recursive calls on all inner contents
const contents = content.innerContents;
const pointsLength = content.pointsLength;
const trianglesLength = content.trianglesLength;
const featuresLength = content.featuresLength;
const geometryByteLength = content.geometryByteLength;
const texturesByteLength = content.texturesByteLength;
const batchTableByteLength = content.batchTableByteLength;
if (defined(contents)) {
const length = contents.length;
for (let i = 0; i < length; ++i) {
this.incrementSelectionCounts(contents[i]);
}
}
};

if (load) {
statistics.numberOfFeaturesLoaded += decrement
? -featuresLength
: featuresLength;
statistics.numberOfPointsLoaded += decrement ? -pointsLength : pointsLength;
statistics.geometryByteLength += decrement
? -geometryByteLength
: geometryByteLength;
statistics.texturesByteLength += decrement
? -texturesByteLength
: texturesByteLength;
statistics.batchTableByteLength += decrement
? -batchTableByteLength
: batchTableByteLength;
/**
* Increment the counters for the number of features and points that
* are currently loaded, and the lengths (size in bytes) of the
* occupied memory.
*
* This will be called recursively for the given content and
* all its inner contents
*
* @param {Cesium3DTileContent} content
*/
Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
this.numberOfFeaturesLoaded += content.featuresLength;
this.numberOfPointsLoaded += content.pointsLength;
this.geometryByteLength += content.geometryByteLength;
this.batchTableByteLength += content.batchTableByteLength;

// When the content is not a `Model3DTileContent`, then its
// textures byte length is added directly
if (!(content instanceof Model3DTileContent)) {
this.texturesByteLength += content.texturesByteLength;
} else {
statistics.numberOfFeaturesSelected += decrement
? -featuresLength
: featuresLength;
statistics.numberOfPointsSelected += decrement
? -pointsLength
: pointsLength;
statistics.numberOfTrianglesSelected += decrement
? -trianglesLength
: trianglesLength;
// When the content is a `Model3DTileContent`, then increment the
// reference counter for all its textures. The byte length of any
// newly tracked texture to the total textures byte length
const textureIds = content.getTextureIds();
for (const textureId of textureIds) {
const referenceCounter =
this.texturesReferenceCounterById[textureId] ?? 0;
if (referenceCounter === 0) {
const textureByteLength = content.getTextureByteLengthById(textureId);
this.texturesByteLength += textureByteLength;
}
this.texturesReferenceCounterById[textureId] = referenceCounter + 1;
}
}

// Recursive calls on all inner contents
const contents = content.innerContents;
if (defined(contents)) {
const length = contents.length;
for (let i = 0; i < length; ++i) {
updatePointAndFeatureCounts(statistics, contents[i], decrement, load);
this.incrementLoadCounts(contents[i]);
}
}
}

Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
content,
) {
updatePointAndFeatureCounts(this, content, false, false);
};

Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
updatePointAndFeatureCounts(this, content, false, true);
};

/**
* Decrement the counters for the number of features and points that
* are currently loaded, and the lengths (size in bytes) of the
* occupied memory.
*
* This will be called recursively for the given content and
* all its inner contents
*
* @param {Cesium3DTileContent} content
*/
Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {
updatePointAndFeatureCounts(this, content, true, true);
this.numberOfFeaturesLoaded -= content.featuresLength;
this.numberOfPointsLoaded -= content.pointsLength;
this.geometryByteLength -= content.geometryByteLength;
this.batchTableByteLength -= content.batchTableByteLength;

// When the content is not a `Model3DTileContent`, then its
// textures byte length is subtracted directly
if (!(content instanceof Model3DTileContent)) {
this.texturesByteLength -= content.texturesByteLength;
} else {
// When the content is a `Model3DTileContent`, then decrement the
// reference counter for all its textures. The byte length of any
// texture that is no longer references is subtracted from the
// total textures byte length
const textureIds = content.getTextureIds();
for (const textureId of textureIds) {
const referenceCounter = this.texturesReferenceCounterById[textureId];
if (referenceCounter === 1) {
delete this.texturesReferenceCounterById[textureId];
const textureByteLength = content.getTextureByteLengthById(textureId);
this.texturesByteLength -= textureByteLength;
} else {
this.texturesReferenceCounterById[textureId] = referenceCounter - 1;
}
}
}
// Recursive calls on all inner contents
const contents = content.innerContents;
if (defined(contents)) {
const length = contents.length;
for (let i = 0; i < length; ++i) {
this.decrementLoadCounts(contents[i]);
}
}
};

Cesium3DTilesetStatistics.clone = function (statistics, result) {
Expand All @@ -124,6 +188,9 @@ Cesium3DTilesetStatistics.clone = function (statistics, result) {
statistics.numberOfTilesCulledWithChildrenUnion;
result.geometryByteLength = statistics.geometryByteLength;
result.texturesByteLength = statistics.texturesByteLength;
result.texturesReferenceCounterById = {
...statistics.texturesReferenceCounterById,
};
result.batchTableByteLength = statistics.batchTableByteLength;
};
export default Cesium3DTilesetStatistics;
Loading

0 comments on commit c403b50

Please sign in to comment.