3 ms·
This is something different from what game engines do. A game engine can typically just walk the scene graph, emitting draw calls as it encounters potentially v
by pcwalton 9y ago
This is something different from what game engines do. A game engine can typically just walk the scene graph, emitting draw calls as it encounters potentially visible objects. The equivalent approach on the Web would be walking the render tree/frame tree, issuing draw calls as it goes.
This is indeed the traditional method that Gecko and WebKit used to use, but it has a lot of problems, which are why Blink and Gecko use display lists:
1. The CSS 2.1 Appendix E painting order is complex: it's not enough to traverse the tree in breadth-first or depth-first order. You could get around that by traversing the tree multiple times, as Blink and WebKit do, but that gets complex. It's a lot more straightforward, not to mention cache friendlier, to build display items into a list and then later sort them into the proper CSS stacking order. This is actually similar to what game engines do for transparent objects (assuming they actually care about rendering them properly and aren't using any fancy OIT techniques).
2. For security reasons, these days you don't want direct GPU access in the same process as JavaScript. Display lists enable an elegant solution to this, as they can be transmitted over IPC to a trusted process.
3. Display lists can be rendered in a separate thread from the layout and/or JavaScript execution, enabling better use of concurrency.
4. Unlike a typical game, which has the luxury of being able to build up vertex and index buffers beforehand and can cache them on the individual nodes in the scene graph, on the Web each individual display item only has a tiny amount of GPU data. Slow rendering on the Web is often the result of "death by a thousand cuts", where the GPU is swamped in draw calls from lots of unrelated items. The only scalable solution to this problem is to batch across display items, using knowledge of the entire scene to construct VBOs and IBOs. This is only possible if the renderer has a global view of the entire scene, and the display list is a natural way to achieve that.
I certainly think that Web browsers can learn a lot from game engines (and WebRender is designed to do just that). But display lists are one of those cases in which the problem space is just different: trying to do exactly what a game engine does doesn't work well.
- Rusky 9y agoDisplay lists actually remind me a lot of sprite batching, where game engines also build up VBOs based on the whole scene. Probably not as common in 3D (maybe particles?) but standard practice for 2D. And for what it's worth, the last game engine I worked on used display lists for opaque objects as well as transparent- that let us sort by material (to reduce state changes) and approximate depth (to reduce overdraw). We just regenerated and sorted this list every frame from scratch.
- Jasper_ 9y agoI'd also add: Game content is not built in a vacuum, and is built by a team of people who were trained on the engine and have a large bag of tools to help improve performance. You can't just plug a random scene into any game engine and expect it to perform beautifully. There is good tech in game engines, but a lot of it comes down to an incredible amount of manual labor because you can target the internals of the engine. The web has to handle any random content thrown at it.