background preloader

Graphics optimizations

Facebook Twitter

Bit Twiddling Hacks. By Sean Eron Anderson seander@cs.stanford.edu Individually, the code snippets here are in the public domain (unless otherwise noted) — feel free to use them however you please. The aggregate collection and descriptions are © 1997-2005 Sean Eron Anderson. The code and descriptions are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY and without even the implied warranty of merchantability or fitness for a particular purpose. As of May 5, 2005, all the code has been tested thoroughly. Contents About the operation counting methodology When totaling the number of operations for algorithms here, any C operator is counted as one operation.

Compute the sign of an integer The last expression above evaluates to sign = v >> 31 for 32-bit integers. Alternatively, if you prefer the result be either -1 or +1, then use: sign = +1 | (v >> (sizeof(int) * CHAR_BIT - 1)); // if v < 0 then -1, else +1 On the other hand, if you prefer the result be either -1, 0, or +1, then use: 3D Programming - Weekly : Bounding Boxes. Bounding Box Types This article gives an overview of oriented bounding boxes, including source code. An oriented box is allowed to rotate freely, unlike a axis-aligned bounding box, which always remains aligned to the x,y, and z axes. Tests with oriented bounding boxes are more complicated, and thus slower, but they're also more accurate. I could also mention that spheres can be used as the least accurate bounding type, but I won't since I put Box Types in the section title =) Data Structure To store the box, we need to store a centerpoint, a rotation, and how far the box extends from the centerpoint in the x,y,z directions.

Functions This class contains the following functions: IsPointInBox: Tests if a point is in the box. Code Download bbox.h( 2KB ), bbox.cpp ( 5KB ) : An oriented bounding box class. External Link A while after I had first written a bounding box class, I found this article which inspired some code changes. 1307386738.pdf (application/pdf Object) My own little DirectX FAQ.

SSE Optimizations

CDWFS: Optimizing for SSE: A Case Study. Deprecated: Function eregi() is deprecated in /home/postgoodism/cortstratton.org/private/cortsite.php on line 19 Originally appeared in Hugi Issue #25 Table of Contents Introduction In this article I'll be describing the process of optimizing a piece of code to make use of Intel's SSE instruction set. We'll apply these techniques to a problem that often arises in computer graphics: you want to multiply a 3D vector by a 4x4 matrix. Naïve C++ So, hopefully you agree that it's important to have a fast software matrix-vector multiplier.

MatrixMultiply1 (100 cycles/vec) A brief note on cycle timings: the timings I give for each function were achieved when running the sample code on my 500 MHz Pentium 3. So sure, the function works - but if all you're looking for is code that WORKS, you wouldn't be reading Hugi, would you? Basic SSE Why does Chris's version run so fast? SIMD lends itself amazingly well to matrix operations. MatrixMultiply3 (43 cycles/vec) Batch Processing Better still! Prefetching.