I’m attempting to use pstats to optimize a (very large) scene we’ve constructed. I’m having a bit of difficulty understanding the pstat information.
As I turn around in the scene (we use FPS controls), I get a lot of “popping” when I look towards larger areas of the scene. Pstats tells me that—as I would expect—we’re choking in the “opaque” draw bin.
My questions are: (1) exactly what happens in that step, and (2) is there a way to get an even finer-grained breakdown (as in, I’d like to know if its our textures or our poly-count that is most likely to be causing problems)?
“chugs” experienced while rotating around the view the scene for the first time are usually the result of texture loads, which Panda by default uploads to the graphics card only the first time they appear onscreen.
You can reduce chugs by telling Panda to load all of the textures in your scene up front. To do this, load your scene under a NodePath, and then issue the call nodePath.prepareScene(base.win.getGsg()), e.g.:
Mmm…, what do you mean by “popping” exactly ?
Is it the lag when performing a transition from [small number of vertices] to [huge number of vertices] view ?
What is currently your texture operations ? Are you using shaders, bilinear mipmapping, or using a LOT of large baked textures ?
From my experience using quite large baked texture (2k x 2k), yes there was a choke when the 1st time I looked at that object (less than 100 vtx).
Well, for that case, taken from the manual, will this work :
Ynjh, by “popping” I mean pretty much exactly what you described. Specifically, it’s when a new object comes into my field-of-view.
I had forgotten (again) that Panda lazy-loads texture content. We have some huge textures, so that looks like the culprit. Unfortunately, the popping keeps coming back after we use prepareScene (I would assume Panda is evicting things from the cache); running a flattenStrong on the visible terrain has essentially solved the problem on our end.
What are the advantages / disadvantages of flattenStrong vs. prepareScene? The obvious disadvantage to flattenStong is that we lose the tree hierarchy; are there any other side-effects? Also, does my hunch about cache-eviction foiling prepareScene sound reasonable?
This is not a cache that things would be evicted from so easily. If flattenStrong() is fixing the problem, it suggests that either prepareScene() is not working, or it is not a problem with textures.
The big side-effect of flattenStrong() is, indeed, losing the hierarchy; but this itself can have huge consequences. Most importantly, it may mean that culling is impeded, as formerly small pieces of the scene that used to be behind your camera now get combined with small pieces that are in front of your camera, and you end up with large pieces that always get drawn regardless of which way your camera is facing. Depending on the nature of your scene and the capabilities of your graphics card, this may or may not be a big deal, but usually it is not a good idea to call flattenStrong() on the whole scene for this reason (you can safely call flattenLight() or flattenMedium() on the whole scene, but flattenStrong() should generally be reserved for individual objects within the scene).
The easy way to test whether it is textures that are causing the chugs, or some other culprit, is by turning off textures, for instance with base.toggleTexture().
If turning off the textures eliminates the chugs, then it must be that prepareScene() is not working for some reason. (In this case, flattenStrong() would appear to solve the problem by causing the whole scene, including the textures that might initially be offscreen to be rendered as one big chunk. But that may or may not be an effective long-term solution.)
If turning off the textures does not eliminate the chugs, then it may be from some other source; for instance, from the vertex buffers that also get uploaded when you first render them. We have seen some graphics drivers that take an extraordinarily long time to upload vertex buffers, particularly in DX9 mode. You could try switching between OpenGL, DX8, and DX9, to see if this has any effect. (It’s a minor bug in prepareScene() that it uploads only the textures, not the vertex buffers. We never implemented the vertex buffer uploads because it never became an issue for us.)