PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

OpenGL ES Software Renderer / 2300 discussion

This was part of the thread Your thoughts on runtime code generation/modification..., but I took the thread OT. So I've moved the OT posts into this new thread.

Digby wrote:I saw a message on this OpenGL ES compliant library on the Khronos.org site earlier this week. It also claims to use self-generating code for the inner loops of its rasterizer.

Click here


I've mentioned this before, but so far the only two games (that I know of) supporting OpenGL ES (ES Quake and MotoGP) both rely almost entirely on extensions to do the rendering. Without those extensions the bus bandwidth kills performance, and the GPU is hardly utilized at all (relative to its potential). This will be the norm.

Now this is purely my opinion, based on experience from both implementing a full blown OpenGL ES application, as well as implementing my own software 3D engine. At this time I think it is very premature to have a software based OpenGL ES renderer. One reason is the extensions I've already mentioned. There is no compatability at this time because OpenGL ES as currently described is not being used for actual hardware drivers (to clarify, it is properly supported, but extensions have to be used to make proper use of the hardware). Now from the software point of view, given a PPC's limited processing power, a less robust and less general purpose API is ideal for performance reasons. For example, PocketGL (and Varium, as it was originally derived from PocketGL) has a pool of vectors (the positional component), and specific vertices point to those vectors. Even with fans and strips, there are still many verts that could be shared that aren't. This is especially true with typical BSP geometry (as opposed to detail meshes, where just one or two textures can be skinned across hundreds of polys). With a custom API that segregates vertices from their positional vector component, you can completely eliminate translating and projecting the same vertex (specifically, multiple vertices with the same position) multiple times per frame. Now that's a huge deal. Transformation and polygon / span setup are more costly than rasterization (when highly optimized ASM rasterizers are used). Again, with BSPs, you can easily end up transforming and projecting each vertex at least twice. When the transformation occurs in hardware, and the geometry is already cached, then that has virtually no affect on performance.

So my point is that it is impossible to implement the fastest and leanest possible 3D engine while having to adhere to an API like OpenGL ES (which was designed for hardware rendering). The only other purpose then of supporting OpenGL ES is for portability, yet immediately out of the gate proprietary extensions are already being used for all rendering, breaking compatibility (at least for now)

Dan East
I agree with Dan. OpenGL has always been a really bad API for software rendering. With the limited processing power of handheld devices, this gets even worst.
Dan East wrote:-*- snip -*- At this time I think it is very premature to have a software based OpenGL ES renderer. One reason is the extensions I've already mentioned. There is no compatability at this time because OpenGL ES as currently described is not being used for actual hardware drivers (to clarify, it is properly supported, but extensions have to be used to make proper use of the hardware).
-*- snip -*-
So my point is that it is impossible to implement the fastest and leanest possible 3D engine while having to adhere to an API like OpenGL ES (which was designed for hardware rendering). The only other purpose then of supporting OpenGL ES is for portability, yet immediately out of the gate proprietary extensions are already being used for all rendering, breaking compatibility (at least for now)

Yes and no. I think part of the motiviation behind this implementation (besides giving me the opportunity to play with compilers and geometry :D ) is to provide a low-cost platform for experimenting with this API especially for the rest of us who do not have NDA-type access to pre-released hardware. The alternative is either to cook up something yourself, or to work with the API idiosyncrasies of other 3d libs out there.

And, you could even use the source of this project as a starting point for cooking up something yourself: Once you strip away the gl... wrapper, it's just a C++ class library that contains stuff like Texture, Matrix, Rasterizer, Context, etc.

At this point, there is really no easy access to OpenGL ES for Windows Mobile, even though most other mobile platforms provide or have announced the availability of software renderers for situations where no hardware is around. For ESQuake, those specific extensions that you where implying above do not seem to be too difficult to incorporate in software once the standard gets published later this year (I guess we all have signed the NDA for that...). Others are, but then again the JIT approach will ensure that they do not affect performance as long as you do not use them.

As for software renderers, people tend to stick to their gadgets a while, so from a commercial perspective there is probably going to be a space for software based renderers. Just looking at those n-gage titles, for example.

On the other hand, whether this specific implementation of a software renderer is ever going to be competetive with any of the commercial $$$ offerings will ultimately depend on the overall interest and support by the community.

Cheers,
HM
Without those extensions the bus bandwidth kills performance, and the GPU is hardly utilized at all (relative to its potential).


In this case, what you have to do is make the GPU do more work per triangle being drawn by the card. Use things like multitexture, alpha blending, mipmapping, or bilinear filtering to make the game look better to amortize the cost of sending the vertex data across the bus. If you have to pay the penalty you might as well never let the GPU go idle and have a better looking game.

Transformation and polygon / span setup are more costly than rasterization (when highly optimized ASM rasterizers are used).


I would think triangle size and what sort of processing you have to do per-pixel wouldn't make this necessarily true in all cases. What is the average triangle size in a game like Varium?


I don't know why OpenGL ES doesn't support display lists. You'd think they would realize that there is a big benefit to sending the data to the driver once, even in a software implementation. In order to do multipass rendering techniques like light mapping, you're going to have to send the vertex data to the driver twice, or you end up doing the transform/light/clip stuff yourself and pass in post-processed vertices that are already in screen space. That's not exactly a stellar API design to have every app doing its own transform/lighting/clip code.

Dan, if I understand you correctly, you're talking about submitting a list of vertices and then being able to describe how those vertices are connected into triangles via a separate index list? Offhand, I don't remember how that's done with OpenGL, but D3D uses vertex buffers and index buffers to do exactly this. Furthermore once you hand one of these vertex buffers off to a driver, it is free to rearrange the data or store it in some GPU-friendly format for more efficient rendering since your app must make an explicit "lock" call to get access to the vertex data. As you can imagine, this works really well with static geometry where you lock/load/unlock and forget it. I don't know if OpenGL ES is going to have something like that in their 1.1 release this summer. They were going to do something at GDC this week. Maybe there will be more details after GDC is over.
Digby wrote:Dan, if I understand you correctly, you're talking about submitting a list of vertices and then being able to describe how those vertices are connected into triangles via a separate index list? Offhand, I don't remember how that's done with OpenGL, but D3D uses vertex buffers and index buffers to do exactly this. Furthermore once you hand one of these vertex buffers off to a driver, it is free to rearrange the data or store it in some GPU-friendly format for more efficient rendering since your app must make an explicit "lock" call to get access to the vertex data. As you can imagine, this works really well with static geometry where you lock/load/unlock and forget it. I don't know if OpenGL ES is going to have something like that in their 1.1 release this summer. They were going to do something at GDC this week. Maybe there will be more details after GDC is over.

As I understand, Dan's point is that you would like to go beyond vertex buffers, essentially have some kind of glDrawMesh call that would render the whole mesh, resolving face vertex, normal & texture coordinates as necessary. I have this already as a planned extension, even though I would prefer seeing some kind of support through the "official" API.

- HM
well, what would be great is something like "per attribute indexed arrays".

standard opengl vertex arrays just allow one index for all attributes of a vertex (position, normal, texcoord, etc.). for a software renderer it would be great to supply different indices for each of these, so that coords can be shared even when normals and/or texcoords are not, etc.

anyway it makes sense to cache transformed vertices of vertex arrays such as mesa does...

Daniel
Digby wrote:In this case, what you have to do is make the GPU do more work per triangle being drawn by the card. Use things like multitexture, alpha blending, mipmapping, or bilinear filtering to make the game look better to amortize the cost of sending the vertex data across the bus. If you have to pay the penalty you might as well never let the GPU go idle and have a better looking game.


The 2300 can render millions of polys per second, with bilinear filtering. There is simply no chance of trying to push that much geometry from system RAM to VRAM real time. The 2300 does not support multitexture.

Digby wrote:I don't know why OpenGL ES doesn't support display lists. You'd think they would realize that there is a big benefit to sending the data to the driver once, even in a software implementation. In order to do multipass rendering techniques like light mapping, you're going to have to send the vertex data to the driver twice, or you end up doing the transform/light/clip stuff yourself and pass in post-processed vertices that are already in screen space. That's not exactly a stellar API design to have every app doing its own transform/lighting/clip code.


There are already the ARB extensions for VBOs in OpenGL, so I assume the consortium decided that those extensions could be used if desired. Which is exactly what has happened. Since the 2300 can't do multitexturing you have to do separate 2 passes for lightmaps anyway.

Digby wrote:Dan, if I understand you correctly, you're talking about submitting a list of vertices and then being able to describe how those vertices are connected into triangles via a separate index list? Offhand, I don't remember how that's done with OpenGL, but D3D uses vertex buffers and index buffers to do exactly this. Furthermore once you hand one of these vertex buffers off to a driver, it is free to rearrange the data or store it in some GPU-friendly format for more efficient rendering since your app must make an explicit "lock" call to get access to the vertex data. As you can imagine, this works really well with static geometry where you lock/load/unlock and forget it. I don't know if OpenGL ES is going to have something like that in their 1.1 release this summer. They were going to do something at GDC this week. Maybe there will be more details after GDC is over.


Yes, ATI has a further extension (that I don't believe I can discuss because I'm still under NDA and they haven't released the spec publicly that I know of) that does exactly what you describe. It allows you to cache actual geometry of fans and strips to render detail-type meshes. You are still limited to rendering with a single texture per call, which is why I say it is really for detail meshes / entity models.

I have converted Varium to run on the 2300 (OpenGL ES or OpenGL), but I ran into even more issues. Varium uses models similar to Half Life that have hierarchical set of bones (transformation matrices) that the model vertices are bound to. Even with hardware rendering I still have to do all of those transformations in software, and worse, I have to upload that geometry every frame because it is not static. Games like MotoGP, with very high poly bikes that are nothing more than a huge static blobs of polys, can achieve really high poly counts on the 2300 because the entire world and everything in it can be cached. In ES Quake I cache all models (which of course means caching every animation frame for each), but I cannot cache the world. Quake uses a BSP (duh!), which allows the most efficient culling out of world polys, so in order to be able to specify on a poly by poly basis which should be rendered I could not cache those polys. ATI considered adding some sort of extension to work around that, but it wasn't reasonable in the time frame we were working in. ES Quake performs well, but it is always hindered by a significant amount of floating point math buried deep in its core (in the scripting engine, physics and collision detection, etc), as well as having to push the BSP polys across the bus each frame. 100% of the actual rendering (including particle effects, etc) is converted to fixed point.

Dan East
If the 2300's only strong suit is being able to render a gazillion polygons per second w/o being able to perform more complex per-pixel ops, and it has a brain dead bus, what good is it? It would seem to me that ATI overdesigned the wrong part of the chip.
It does mipmapping, bilinear filtering, blending, etc. So I'm not sure what specific pixel operations you're talking about. Of course it doesn't have a pixel shader or any of the other cutting edge stuff.

Dan East
Does it do full screen anti-aliasing (FSAA)?

You get my point, right? Since it's impossible to send enough polys to the GPU to keep it busy due to the bus limitation, you're better off sending fewer polys but making them look better using more of the rasterization features of the chip. I've got the 2300 docs around here someplace and I should probably look at exactly what sort of pixel ops they can do, but mainly it's things that increase the fillrate and produce a higher quality result: alpha blending, specular, fog, anti-aliasing, trilinear mipmapping, perspective correct texturing, bump mapping, etc..

If the ATI guys designed a chip that can handle more polygons than the bus can supply, they only way you're going to work around that sort of hardware limitation is to get the GPU to do more work with the polys it gets in an attempt to produce a better looking image. If the 2300 doesn't have these additional "per-pixel" related features I've listed above, then you're screwed. If what they've done is spent all their gates on being able to process as many "simple" polys as possible then it seems to me that they've made a huge design mistake due to the limited bus bandwith.
Digby wrote:
If the ATI guys designed a chip that can handle more polygons than the bus can supply, they only way you're going to work around that sort of hardware limitation is to get the GPU to do more work with the polys it gets in an attempt to produce a better looking image. If the 2300 doesn't have these additional "per-pixel" related features I've listed above, then you're screwed. If what they've done is spent all their gates on being able to process as many "simple" polys as possible then it seems to me that they've made a huge design mistake due to the limited bus bandwith.

At GDC Intel was showcasing some prototypes of their upcoming processors plus multi-media accelarators (official announcement to come in the "very near future"). Anyway, I asked one of the guys about the CPU -> GPU bottleneck issue and he said that the new architecture would include a high-speed bus interface ("similar to what we did with AGP") between CPU and GPU.

- HM

PS: Is there a way to rename a thread? This topic mutated significantly from what the subject says...
I don't really see the point of OpenGL ES any more. I was expecting something cut-down enough to be implemented efficently in software. Amongst other things, this would include not relying on depth buffers...

As it is, it's fairly clearly *not* aimed at software implementations. So why not just use bog standard OpenGL, ? Or a 'MiniGL/QuakeGL' type implementation, as proved so successful on the PC?

I though fixed-point maths may be the main issue - but is it even an issue if it's aimed at hardware implementations that will almost inevitably get T+L (if not complete shaders support) in a couple of generations time.

And doesn't regular OpenGL support the likes of glVertex3i() anyway? and transformations could probably be implemented in fixed point internally?
One of the primary differences of OpenGL ES is to force passing of data by array, thus doing away with the glBegin and glEnd paradigm (which I never liked anyway - why in the world would I want the overhead of a function call for every single vertex I want to pass?).

So OpenGL ES in a large way represents a lean and mean OpenGL that no longer has to be backwards compatible. In other words, a lot like what OpenGL would look like if it were done right in the first place without so many redundant layers.

I know I'm starting to sound like a broken record (because I've said this a couple times in the past). When it comes to hardware rendering, where all transformations and projections are done in hardware with high accuracy, including a texture matrix, there is no need at all for a fixed point type. You can simply use full blown integers, and scale the matrix to affect fixed point against the type. For example, if you are using 16.16 on the software side, then you can pass those verts as GL_INT, and scale the matrix by 1/(1<<16).

Of course all of that is completely out of the question for software rendering, especially when we talk about also using a texture matrix which allows the same technique with texture coords.

However OpenGL ES does have Fixed Point types, although they did not end up being used at all in MotoGP and ES Quake. We decided it was far more important to reduce the data size and go with shorts and use the above technique than to treat them as formal fixed point . So at this point I do feel that the Fixed Point types were included specifically for software renderers.

Dan East
Most rasterization hardware accepts some form of fixed point directly, so if you had hardware rasterization only and your app (or the API) had to perform vertex transformation and lighting itself, fixed point makes still makes sense.

The problem with the OpenGL ES vertex arrays are that the current implementation kills parallelism between the CPU and GPU. Your app has to wait until the GPU has finished using the contents of the vertex array (i.e. rendering) before it can continue. Either that, or the driver has to make an internal copy of your vertex data, return execution to your app and asynchronously render polygons from the copied buffer. If it used this approach it would have to perform this internal copy operation for every vertex of every frame even though the data might not have changed from frame to frame.
Vertex Buffer Objects allow you to copy the geometry to the VRAM once and reuse it, assuming your geometry is static.

Dan East
which means that vertex buffers objects really make sense as soon as you have vertex shaders.
i assume we won't see these very soon on mobile devices...

Daniel
Are VBOs in OpenGL ES 1.1? They aren't in 1.0 so I'm assuming you're talking about some sort of extension mechanism? If memory serves, in OpenGL there are API extensions and vendor-specific extensions. I hope that VBOs are in the former category to provide less of headache for developers that wanted to use the feature.

Vertex buffers work for skinned characters too. You just need to be able to pass in vertex blending weights and perform transformations on the bones by changing their individual matrices. The vertex data doesn't have to be touched by the application and can remain in dedicated GPU (video) memory. I'm guessing that OpenGL ES doesn't support any of this though (maybe through an extension?).
Digby wrote:Are VBOs in OpenGL ES 1.1? They aren't in 1.0 so I'm assuming you're talking about some sort of extension mechanism? If memory serves, in OpenGL there are API extensions and vendor-specific extensions. I hope that VBOs are in the former category to provide less of headache for developers that wanted to use the feature.

Vertex buffers work for skinned characters too. You just need to be able to pass in vertex blending weights and perform transformations on the bones by changing their individual matrices. The vertex data doesn't have to be touched by the application and can remain in dedicated GPU (video) memory. I'm guessing that OpenGL ES doesn't support any of this though (maybe through an extension?).

These (rather high-end) features are of course at the exact opposite end of what would be realistically feasible for a software renderer. So assuming OpenGL ES would provide VBOs, ARB_matrix_palette and ARB_vertex_blend extensions, this would still not solve the problem for software renderers. Instead, the concatenation of multiple transformation would make the problem Dan pointed out even worse!

- HM
From the hardware perspective, VBOs provide a method to cache something (geometry, texture coords, colors, etc) in VRAM. I'm talking about glGenBuffersARB, glBindBufferARB and glBufferDataARB.

Now this could be used to advantage with a software renderer as well. When glBufferDataARB is called to indicate GL_STATIC_DRAW_ARB we know the data is static, and we can assume that the programmer knows this data should be reusable across multiple frames. So whenever glBindBufferARB then glDrawArrays / glDrawElements is called the geometry could be scanned and converted into an array of elements (on the software renderer side). Thus any duplicate vertices could be referenced to a single positional value, which would result in less translations and projections. Further, the geometry could be converted into some proprietary format (for example, including flags to indicate which geometry has already been transformed and projected for the current frame). This type of processing could only be done after the call to glDrawArrays / glDrawElements, because only then would the exact format of the data be known.

I'm half thinking aloud here, but I don't see how optimizations of this sort could hurt. If VBOs are used properly then really they should only be uploaded during initialization, so the extra overhead of indexing the geometry would only happen the first type the geometry is rendered.

Dan East
Dan East wrote:From the hardware perspective, VBOs provide a method to cache something (geometry, texture coords, colors, etc) in VRAM. I'm talking about glGenBuffersARB, glBindBufferARB and glBufferDataARB.

I'm half thinking aloud here, but I don't see how optimizations of this sort could hurt. If VBOs are used properly then really they should only be uploaded during initialization, so the extra overhead of indexing the geometry would only happen the first type the geometry is rendered.

This is true, even though in practice you would end up holding the same structure 3-times(!) in memory:

a.) Your original mesh
b.) the unrolled version that you need to pass the triangular mesh correctly through the API, and
c.) the optimized version, which essentially is a reconstruction of a.) within the OpenGL implementation.

Also, c. would requireing some kind of hashing on the *values* of your vertices & normals. I think even with GL_STATIC_DRAW_ARB you would not be allowed to throw away b.), but I might be wrong here, so please correct me. Daniel (drgoldie) essentially proposed as a better and simpler option to provide glMultiDrawArrays & glMultiDrawElements, which would be used with precomputed strides and fans. Personally I'd still prefer a solution where you could just dump your Maya/3dmax export down the rendering pipeline, similar to what PocketGL is doing.

- HM
The software side doesn't need to keep its "a" copy, unless the geometry needs to be unloaded and reloaded multiple times during that "level" (which would be a poor practice). I don't see any reason to keep a copy of b around either. Just as with uploading textures, there is no need to keep a copy on the software side.

ATI already has some extensions that sound very similar to what you describe, however they aren't public yet. I just tried searching for the API names on Google (web + usenet) and still can't find them. I'll drop ATI an email today to see if I can post this API, because it would definitely be in your best interest to support the same extensions as the ATI OpenGL ES driver, instead of creating your own that serves the same purpose.

Dan East
Dan East wrote:The software side doesn't need to keep its "a" copy, unless the geometry needs to be unloaded and reloaded multiple times during that "level" (which would be a poor practice).

I see, for each level you would read from external storage and pump directly into the driver, then get rid of the memory image.

So what you propose is the following: When setting a VBO for vertices and normals with STATIC_DRAW specified, instead of loading the data I should create an index mapping m[] and a new array of vertex data v[] such that v[m[i]] is the original vertex data at index i. v[] would include some state flags and a cache of the last current projection of the vertex. Similar for normals, colors and texture coordinates.

Hey, did we just solve the problem of efficiently rendering meshes with a software renderer through the OpenGL API? :idea:

Dan East wrote:
ATI already has some extensions that sound very similar to what you describe, however they aren't public yet. I just tried searching for the API names on Google (web + usenet) and still can't find them. I'll drop ATI an email today to see if I can post this API, because it would definitely be in your best interest to support the same extensions as the ATI OpenGL ES driver, instead of creating your own that serves the same purpose.


What I found is http://oss.sgi.com/projects/ogl-sample/registry/ATI/element_array.txt, but if there is anything else it would be great to learn about it.

- hm
I've already emailed you, but I'll post this here as well.

According to ATI, they will release the extension specs "soon".

The API you linked to above is not the ATI extension in question.

Dan East