Author Topic: INFO: Draw calls not geometry as a bottleneck in NWN.  (Read 2871 times)

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #90 on: May 03, 2014, 04:07:52 pm »


               


Ah, thanks for explaining that.


Anyway, concerning drawcalls, what I'm trying to say is that we haven't really tested yet how many you need to have before it starts actually affecting performance.




 


I don't think that's the right question. As far as tiles are concerned, counting draw calls is irrelevent. Counting polys is what matters. The number of polys in all the meshes in camera-shot.


 


In my test results, looking at a scene with about 100k polys total (the camera 'c' columns), reducing total draw calls in the scene from 2752 (the 1x1 case) to just 32 (the 16x8 case) by compacting meshes, made no difference to the frame rate (well, actually it got slightly worse, but only slightly).


               
               

               
            

Legacy_Zwerkules

  • Hero Member
  • *****
  • Posts: 1997
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #91 on: May 03, 2014, 04:22:19 pm »


               


Meshes that are rendered with a bitmap that has transparent areas (fences, gratings, leaves on trees, for example) don't have to be attached to an 'a' node but it's better if they are because if they are not, some graphics cards and some drivers will leave a white margin around the opaque parts, which looks bad.




 


As long as those transparent meshes are rendered after all the meshes that are behind or under them and the transparency hint is greater than 0 it seems they work without any problems at least I've always gotten rid of the white margins this way. I think they should only be linked to the a-node if there's still a white margin showing after making sure the transparency hint is set correctly and they are rendered after the meshes behind them. Also if they are linked to the a-node they won't tilefade.


One problem I always have with transparent meshes is that a blue margin appears around them if the 'sam' of a door is behind them. This is also the case if the mesh is linked to the a-node, probably because the 'sam' of a door is animated, too.


               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #92 on: May 03, 2014, 05:15:43 pm »


               

<punching a...>


 


Not to derail this too far, but if you dig into my "tile" class placeable you'll see I now normally use "[ mdlname ]a" in place of a rootdummy for hanging my non-skin mesh on.


Without that I get those "OR" voids OMB mentioned for the water.


 


In the most recent case, my Spirit Smoke, putting the mesh on a rootdummy or giving the mdl a "Character" class made whatever was behind the smoke flicker in and out of view, mostly depending on camera angle and distance to the mesh.


Hanging it on an 'a' node and making the mdl "Tile" fixed the problem and allowed the texture's .TXI to work properly.


 


Edited: Basically (my theory), "Tile" 'a' node mesh have a different shader path than "Character", and this is determined by the class defined in the model.


Tile-static have a different path than placeable-static, but this is determined by the actual type of model loaded (e.g. tile models loaded as placeables (tile-magic) seem to follow the placeable shader path).


 


<...'a' ticket>



               
               

               
            

Legacy_OldTimeRadio

  • Hero Member
  • *****
  • Posts: 2307
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #93 on: May 03, 2014, 06:38:37 pm »


               


Anyway, by now, do we have anything concrete saying that drawcalls are ever an issue in NWN? Before considering to consolidate meshes, we really need to answer that.




I've come to this conclusion that they are an issue in NWN, partly through the process of elimination and partly through deductive reasoning. 


 


I invite alternative opinions but the way I see it, there are going to be three possible things which would limit the GFX engine: Geometry, Texture Memory and Draw calls.  There's one other factor, the overhead of the sound system, that I'm leaving out intentionally because, for what I'm getting at, it didn't appear to be a factor.  In your mind imagine a laggy, overstuffed scene, filled with placeables and creatures and spell effects and just freeze it, that whole scene, in your mind's eye.  The scene could be almost anything where your FPS drops, though, like a busy scene in TNO.  So what's causing the FPS to drop?


 


Is it the geometry?  Conventional wisdom would always say "Yes, there's just too many polys in the scene".  I used to subscribe to this, too, but when I actually tried to find what the limits for polys were, I found (except for the polys per node limit OldMansBeard mentioned) that there weren't any.  The context in which this is taking place is one where shadows are turned off, BTW.  I once did a proof of concept conversion of this insane mesh (~1,2 million tris) as a static placeable and it worked- until I whipped out my torch and the vertex lighting destroyed itself, giving me a bluescreen.  But I could back off to things like Megaton from Fallout 3 or the Spelljammer Merchant and they worked.  By all conventional wisdom, neither of those things should be possible at all much less run well for how heavy they are.  But more than that, they represent a functioning, workable paradigm that blows that laggy scene I asked you to imagine right out of the water, poly-wise.  So I removed pure geometry from consideration.


 


Is it the textures? I looked at this, too, a few different ways.  TGAs max out at 2048x2048 and DDS files at 4096x4096.  Even with the compression, DDS files that size are around 11 megs apiece.  The filesize on a 2048x2048 TGA is something insane, like 16mb a pop.  Since it would seem to be the less-optimized of the two, and since static placeables are still subject to TXI functions, I loaded no less than 8 cycling animations (watermarked so I could be sure they were using different textures) using 2048x2048 textures (which were also partly transparent) and those played nicely too.  That's almost 200mb of unique texture memory being consumed which is also, in my guess anyway, far more than even that laggy scene we're trying to get to the bottom of would be using.  So I removed texture memory from consideration.


 


Is it the draw calls? Draw calls were the last remaining thing I could possibly describe that unexpected FPS hit with but just that, itself, wasn't enough.  But using a debugger, I could see the huge number of draw calls the game was making and that tipped the balance more than anything else.  Except for emitters, some of which are definitely optimized to reduce draw calls internally, most official content and most community-made things aren't efficiently created, using separate textures and meshes which increase the draw calls.  A lot.  I can't easily get a count of the draw calls on whole scenes because NWN does not apparently make its draw calls to a specific OpenGL "context".  It just shoots them out.  I can step through them and count them manually but I can't (yet) get an automated draw call count because those performance meters are specific to measure the draw calls directed at a specific context, either Context 1 or Context 2.  Also, how many draw calls is too many?  Totally depends on your graphics card and CPU.  I tend to make things that are playable on my P4 (circa 2005) with a GeForce2 Ti (circa 2001) in it, just sort of because.  Not all draw calls carry the same weight (because some draw operations, for instance, might involve transparency) but I hear numbers like 500, under 2000, that kind of thing.  Across the board (this is the deductive part) draw calls are to be avoided because too many will slow down FPS.  And so I haven't been able to eliminate draw calls from the candidates, nor do I have something else I can point to. 


 




Anyway, concerning drawcalls, what I'm trying to say is that we haven't really tested yet how many you need to have before it starts actually affecting performance.




 


Because there are a few variables involved, one thing I've seen bandied about online is a test that goes something like this:  Get VSync on so you have a clear handle on the number of full frames that are hitting the monitor.  So, 60, 75, whatever your refresh rate is.  Find/make a scene which reduces your framerate some considerable amount, say to 30 FPS with VSynched maximum of 60.  Then lower your resolution.  If the FPS do not go up, then the FPS is being limited because of too many draw calls.  I don't have much time, but I'm hoping to take known or generally agreed-on laggy non-shadowed areas and try to analyze them.


 


Do you or anyone else have what they think are good candidates for testing this?  Official content would be preferable to community-made stuff.


               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #94 on: May 03, 2014, 07:03:11 pm »


               

Okay.


 


OTR's tests on placeables indicate that draw calls matter for placeables and it's worthwhile to think about minimising them.


My tests on tiles indicate that draw calls don't matter for tiles and it's counterproductive to try to minimise them.


 


Conclusion: tiles and placeables are different.


 


We're both right '<img'>



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #95 on: May 03, 2014, 07:08:51 pm »


               

@OTR


 


Well, the ideal way to test is always to minimize the amount of variables.


 


You could try to compare FPS on a complex object (perhaps your spelljammer ship?) as one mesh with the same object but split into several meshes. Depending on how the NWN render engine is designed, it is however possible to render multiple meshes in one drawcall, so would have to check to make sure it actually results in additional drawcalls with the gDEBugger. If it doesn't, you may perhaps separate the ship into several placeable models and see if that increase the amount of drawcalls, then test on that.



               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #96 on: May 03, 2014, 07:12:59 pm »


               

<counting...>


 


As I see it, there are at least 6 different rendering pipelines:


 


  1. Tile-static

  2.    
  3. Tile-dynamic

  4.    
  5. Placeable-static

  6.    
  7. Placeable-dynamic

  8.    
  9. Effect

  10.    
  11. Item

Each of these handles draw distance, txi, alpha, etc in slightly different manner. (Edit: Skin-mesh! You can *not* set skinmesh to static! It will crash the client)


Each of these really need to be considered as separate renders, for optimization purposes.


I really wish Peachykeen was around to comment on this, with all that work on NWShader :-P


 


<...on all his fingers>



               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #97 on: May 04, 2014, 11:01:41 am »


               

Well now, not to put the cat among the pigeons, but ...


 


I've tried taking the last test set-up and making all the tiles null (just walkmeshes and lights), so the area looks blank, then defining static placeables using the non-null chunked tile models and painting the areas with those instead. So the areas look exactly the same, they are made of the same meshes but all the visible meshes are moved off the tiles and onto placeables.


 


Result? There's no difference. For all the chunk sizes, for all the camera positions, there's not so much as 1fps difference between tiles and placeables.


 


Like for like, tiles and static placeables cost the same. ':huh:'


 


I think it's time someone else did some testing. Maybe I'm doing something horrendously wrong ?


               
               

               
            

Legacy_Zwerkules

  • Hero Member
  • *****
  • Posts: 1997
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #98 on: May 04, 2014, 11:38:27 am »


               


Result? There's no difference. For all the chunk sizes, for all the camera positions, there's not so much as 1fps difference between tiles and placeables.


 


Like for like, tiles and static placeables cost the same. ':huh:'


 


I think it's time someone else did some testing. Maybe I'm doing something horrendously wrong ?




That's interesting. Did any of those placeables have transparent parts?


I once created an area where nearly all the tiles had the variations with trees on them and the area lagged. So I changed a lot of the tiles to variations without trees and added the trees as placeables. I even added more trees than before and the lag was still gone.


               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #99 on: May 04, 2014, 01:33:48 pm »


               


That's interesting. Did any of those placeables have transparent parts?


I once created an area where nearly all the tiles had the variations with trees on them and the area lagged. So I changed a lot of the tiles to variations without trees and added the trees as placeables. I even added more trees than before and the lag was still gone.




No, all the transparent parts had been removed from the tiles. It was all just static meshes.


 


I could try restoring the fences and splotches and doing the comparison again. The V1 models had the transparent parts (transparencyhint 1) consolidated, not hung from 'a' nodes. I'll try using those.


 


(edit - added)


 


I tried that. There is a slight improvement in fps with placeables as against tiles, when the models include transparent parts. It's only 2~3 fps in this case, but the frame rate is probably dominated by the static meshes anyway. Figures for the Camera B - looking down at a crossroads with one building visible in each quadrant, using 4x4 chunks (models 4000x4000 cm):



                              Tiles    Placeables
Without Fences & Splotches      115         115
With Fences & Splotches         104         107

So it's not a huge difference, but it is in that direction.



               
               

               
            

Legacy_OldTimeRadio

  • Hero Member
  • *****
  • Posts: 2307
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #100 on: May 05, 2014, 05:02:06 pm »


               

@OldMansBeard -  Thank you, again, for your testing.  As with previous tests, I can't find anything in your methodology which doesn't appear to be sound.  I'm puzzled by the slight FPS increase.  But I can't argue with the numbers.  Very puzzled radio over here.


 


@Zarathustra217 - The Spelljammer placeable isn't consolidated.  Or, at least not perfectly.  There are 217 chunks (about the same as 13-14 "beggar" NPC models, draw call-wise), IIRC.  Each chunk ranges from somewhere around a 1,000 tris on up to 10,000 or so per mesh node.  But, yeah, something like that (or a couple of them) in non-optimized form to take down the FPS and then consolidated versions of the same, even partly consolidated, should yield something useful.

@Rolo - First, that's a good list.  Second, I wish PeachyKeen was around as well.  I don't think it's poor form to mention this out in the open because so much time has passed but, as a person who kept an eye on Voodoo Shader development, it appeared to me that at some point NWN 1 got dropped from the list of supported games.  The project would appear to be dead, so it may be a moot point but  I remember reading, either on the old social site's NWN 1 or 2 forum a message by him that there was something about the pipeline in NWN 1 that was really inefficient that he was not happy about.  After reading the message, I was never able to find it again and I wasn't able to get in touch with him over the IRC or via PM and I've always wished I could have remembered what it was.  I wish the scope of that project could have been a little more limited, because I think it could have gone much farther.  Oh well.


 


@Zwerkules - Do you happen to recall whether this was in a situation with shadows on or off?



               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #101 on: May 05, 2014, 05:36:33 pm »


               

<peering into the...>


 


My reasoning for differentiating the static placeables and static tiles is probably on the CPU-side of the pipeline, but there, non-the-less. Put down a static placeable like my Skyball (radius is iirc 200m or 300m), load the game and from the origin, walk away. At about 40m from the origin, the placeable will fade out, while the tiles are still drawn... (Edit: That's 40m away from the no-mesh origin and 40m *closer* to the mesh)


 


Further, let me theorize that weapons and *heads* are in the *effects* pipeline (or their own) rather than the item pipeline. If you walk behind the wrong kind of effect, weapons and heads vanish :-) Of course, you get behind *some* effects and everything but tiles vanish :-P


 


<...murky murky past>



               
               

               
            

Legacy_Zwerkules

  • Hero Member
  • *****
  • Posts: 1997
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #102 on: May 05, 2014, 06:24:51 pm »


               


@Zwerkules - Do you happen to recall whether this was in a situation with shadows on or off?




Shadows were turned on, but neither the trees on the tiles nor the placeables had shadows.


               
               

               
            

Legacy_NWN_baba yaga

  • Hero Member
  • *****
  • Posts: 1944
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #103 on: May 06, 2014, 01:37:36 pm »


               

I´m very late to the party but can someone tell me what to do in the future to improve the performance in words that are simple;)


 


thanks all:)



               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
INFO: Draw calls not geometry as a bottleneck in NWN.
« Reply #104 on: May 06, 2014, 06:20:56 pm »


               


I´m very late to the party but can someone tell me what to do in the future to improve the performance in words that are simple;)


 


thanks all:)




Turn off shadows '<img'>