-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throttle total resources used for environment maps #12320
base: main
Are you sure you want to change the base?
Conversation
Thank you for the pull request, @ggetz! ✅ We can confirm we have a CLA on file for you. |
@jjhembd Are you available to review? |
I tried this out, and for the "10 cubed" case, it seems to work at the first glance. prints the usual
Maybe someone can confirm or report something else. |
I have to emphasize that I don't even have a vague idea what ~"distributing 'browser resources' over multiple frames" means here (which 'resources' actually have to be 'distributed' in that manner?). But from the symptoms, it looks like this could be a true memory leak that either 1. kicks in in a single frame or 2. (after this PR) kicks in after multiple frames. Specifically, I'll probably have a look at that in the context of https://community.cesium.com/t/procedural-ibl-gpu-memory-leak/36760 and try to see if anything is "leaked" here (regardless of the number of frames that it is distributed over). Given that I'm not familiar with that part of the code, it would only be a short debugstepping-pass, but I'll give it a short try. |
I agree and I'm looking into that thread as well. I still think the change in this PR is good overall as it avoid running tons and tons of commands all in one frame. |
I added some debug logs, and pragmatically plugged https://github.com/greggman/webgl-memory into the code, to get an idea where the "leak" might be. (That's a pretty useful library, by the way). I used a slightly adjusted sandcastle for these tests (see below), to select more meaningful numbers of objects for that test. I'll post condensed versions of the console logs here. The message that starts with One cube
10 cubes
100 cubes
Summary:The number of 'texture' objects that are allocated is basically The total size of the allocated texture memory is
ConclusionIt just needs that much memory 🤷♂️ But from what I've grasped from looking over the code quickly, it looks like the // XXX
console.log("Destroy specular textures");
const length = manager._specularMapTextures.length;
for (let i = 0; i < length; ++i) {
manager._specularMapTextures[i] =
manager._specularMapTextures[i] && manager._specularMapTextures[i].destroy();
}
// XXX at
The sandcastle const viewer = new Cesium.Viewer("cesiumContainer", {
globe: false,
infoBox: false,
selectionIndicator: false,
shouldAnimate: true,
skyBox: false
});
viewer.scene.debugShowFramesPerSecond = true;
function createModel(url, height, amount = 1) {
viewer.entities.removeAll();
for (let i = 0; i < amount; i++){
const position = Cesium.Cartesian3.fromDegrees(
-123.0744619 + i * 0.0001,
44.0503706,
height,
);
const heading = Cesium.Math.toRadians(135);
const pitch = 0;
const roll = 0;
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
const entity = viewer.entities.add({
name: url,
position: position,
orientation: orientation,
model: {
uri: url,
// minimumPixelSize: 128,
maximumScale: 20000,
},
});
viewer.trackedEntity = entity;
}
}
const options = [
{
text: "Unlit Box - 1",
onselect: function () {
createModel("../../SampleData/models/BoxUnlit/BoxUnlit.gltf", 10.0, 1);
},
},
{
text: "Unlit Box - 10",
onselect: function () {
createModel("../../SampleData/models/BoxUnlit/BoxUnlit.gltf", 10.0, 10);
},
},
{
text: "Unlit Box - 100",
onselect: function () {
createModel("../../SampleData/models/BoxUnlit/BoxUnlit.gltf", 10.0, 100);
},
},
{
text: "Unlit Box - 1000",
onselect: function () {
createModel("../../SampleData/models/BoxUnlit/BoxUnlit.gltf", 10.0, 1000);
},
},
];
Sandcastle.addToolbarMenu(options); |
Description
As demonstrated in this Sandcastle example, it's possible for the environment map generation to puts a large load on browser resources when many models are added in the same frame, and that can cause the browser to hang and potentially crash.
This fix ensure that the environment map computations are distributed across several frames once they hit an upper limit, preventing the large simultaneous load on browser resources.
Issue number and link
N/A
Testing plan
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my changeI have updated the inline documentation, and included code examples where relevant