17

In this document (Apple's iOS documentation on OpenGL), Apple recommends using triangle strips over (indexed) triangles in OpenGL ES on iOS:

For best performance, your models should be submitted as a single unindexed triangle strip using glDrawArrays with as few duplicated vertices as possible.

However, Imagination Technologies (the creators of the graphics chip that's used in iOS devices) suggest the other way round in this document (POWERVR 3D Application Development Recommendations). They specifically write on page 11:

Using an indexed triangle list can be much more efficient than using strips.

My question: who is right? Or am I misunderstanding either document?

genpfault
  • 51,148
  • 11
  • 85
  • 139
zmippie
  • 1,509
  • 2
  • 17
  • 22

1 Answers1

14

TBH I'd believe powerVR. The PowerVR supports a post transform cache. This cache means that indices that are repeated relatively close to where they were last called can totally avoid a re-transform (It just pulls the already transformed value out of the cache). So in the case of a strip that goes 0, 1, 2, 3, 4, 5, 6, 7 it provides no bonus but, in reality, strips aren't generally that simple. There will be some vertex index re-use in there. That re-use can avoid the transform entirely. If strips are optimised to bear this in mind (See the NVTriStrip library!) then you can get MASSIVELY improved performance as many transforms just won't be performed.

Furthermore an added bonus of this is that triangle lists are no longer a performance hindrance as 2 of the vertices you are about to transform ARE in the cache and hence there is no performance hit (other than the upload of 6 bytes per triangle rather than 2 (ish) which is not much in the grand scheme of things). Furthermore because you have no need to perform strip "re-starts" (A restart is performed by repeating the last index of the last triangle and the first index of the next triangle. ie 0,1,2,2,3,3,4,5,6) some complex meshes can be faster than with strips. Add to that the fact that in a unindexed strip each repeated vertex must be sent down in its entirety the amount of data that needs to be sent can be a LOT higher than the amount that needs to be sent in an indexed list (as each vertex is only sent across once and the repeating is done in the far more compact indices).

Of course the MBX (iPhone 3G) does not support post-transform caches which is most likely where apple's advice comes from. The SGX (iPhone 3GS and above) does however so it really depends on what hardware you wish to target. If you are ok targetting 3GS and above then use indexing, otherwise don't. Of course supporting both methods out of the box will give best performance on both platforms.

Of course the best way to see is to try both methods (it really doesn't take long to do so) and see which performs better on the hardware!!

Community
  • 1
  • 1
Goz
  • 61,365
  • 24
  • 124
  • 204
  • Excellent advice Goz. I think it's strange that Apple goes through all the work "translating" the PowerVR recommendations in their own "Best practices" document, but turn these optimization suggestions around (strips vs. indexed tris). It could be for the reasons you say: pre 3GS hardware, but Apple is generally very up-to-date in its advice and focuses mainly on newer hardware. Testing this would indeed not be so difficult, but I wish I'd known about ImgTec's "recommendations" before because it would have saved me a LOT of time (I've created some very intricate strips, unneccesary...). – zmippie Dec 15 '10 at 12:02
  • @zmippie: I know what you mean on the annoyance, thats why libraries like NVTriStrip are so handy. From previous experience, though, I would >always< look for more than 1 piece of evidence on optimisation. Furthermore it is >always< best to check it for yourself (unless its a fundamental design decision ;)). – Goz Dec 15 '10 at 13:39
  • 1
    @Goz: You are, again, very right. I'm currently seeing evidence that in my particular case, even with (I think quite optimal) vertex sorting and index sorting, I cannot outperform GL_TRIANGLE_STRIPS with indexed GL_TRIANGLES. I'm going to see if indexed GL_TRIANGE_STRIPS can do me any good, and else it's back to just regular GL_TRIANGLE_STRIPS for me... Thanks again! – zmippie Dec 15 '10 at 20:45
  • That's odd, because when I've talked to Apple engineers they've recommended indexed triangle strips as the fastest data structure for these devices. I believe this can also be found on a couple of the WWDC and tech talk videos out there. I don't recall reading the advice about unindexed strips before. – Brad Larson Dec 15 '10 at 20:56
  • @Brad: He has said hes going to try that next. – Goz Dec 15 '10 at 21:01
  • @Goz - Sorry, the "that's odd" was directed at the documentation itself. It runs counter to what I've heard from the people at Apple I've talked to. – Brad Larson Dec 15 '10 at 22:26
  • @Brad: Ok, fair enough :) The only platform I ever came across where indexing wasn't a win was the PS2 and even then if you were doing massively complex vertex transforms it "could" end up more optimal using indexing ... in general though .. not. It was a really weird bit of hardware though ;) – Goz Dec 15 '10 at 22:38