Joe Ganley

I make software and sometimes other things.

 

Due to Blogger's termination of support for FTP, this blog is no longer active.

It is possible that some links from here, particularly those within the site, are now broken. If you encounter one of those, your best bet is to go to the new front page and hunt for it from there.

Most, but not all, of the blog's posts are on this page; the archives are here.

 

I had a dream last night that I had implemented OpenGL in JavaScript on the HTML5 canvas (yes, this is the sort of thing I dream about). Not hardware acceleration, just a 3D graphics context with an OpenGL API. For a few minutes after I woke up, this seemed like a good idea. Then my head cleared, and I realized that OpenGL is a pretty clumsy API to choose if you're not getting hardware acceleration in return, but that nonetheless a 3D graphics context for canvas, written in pure JavaScript, could be useful.

Looking around, I found a blog post that lists four efforts along these lines (no pun intended). They are pretty impressive, but it seems that performance is likely to be acceptable only for fairly simple scenes. Nevertheless, these are very much what I was thinking of doing, and their performance is at least as good as I would have expected, so kudos to their authors.

Dropping the pure-JavaScript requirement, we come to the Canvas:3D project, which is a Mozilla plugin that provides direct access to hardware acceleration through the HTML5 canvas using OpenGL. (There is a similar project for the Opera browser as well.) Having to install a plugin rubs me the wrong way, but it sounds as if this might be integrated into Firefox in the not too distant future.

Until then, probably the most sensible way to implement hardware-accelerated 3D graphics in a web browser is to use Flash.

Labels: , , , ,

Comments (0)
 
Michael Abrash has a series of articles appearing in Dr. Dobb's currently. The subject of the articles is code optimization, but the thing I found most interesting is the code being optimized. It is a software-only rasterizer. I wouldn't have thought it possible (even for Michael Abrash) to get DirectX7 performance in software. But most of all, it's noteworthy that state-of-the-art graphics hardware and drivers still have so many bugs and portability problems that Abrash finds it worthwhile to spend a lot of time and sacrifice two generations off the state of the art in order to avoid them. I certainly feel his pain, and I'm jealous that he is able to focus on a single type of processor and thus achieve this level of optimization.

The other thing that caught my eye was an illustration of how on modern processors, optimization can be extremely nonobvious. The example was a subproblem I've solved before: Given a value x between 0 and 1 and an array of ascending values in the same range, figure out which pair of values x falls between. I used a binary search. It turns out that on the x86, binary search is predicted poorly by the processor's branch prediction logic, while in a linear search every compare but the last one is predicted correctly. A mispredicted branch is very expensive. So, for a small number of bins a linear search is 30-50% faster (!), and the problem size has to reach 64 bins before the improved asymptotic efficiency of the binary search actually beats the linear search in real life. My problem had at most a few tens of bins, and the search was deep in an inner loop, so this would have been useful information to have known.

Labels: ,

Comments (0)