Commits

Cliff Biffle committed bc68584

Separated the ray projection transform into X and Y components. This saves 297KiB of hot memory in the depth map, which should now fit quite comfortably in cache.

Comments (0)

Files changed (2)

KVAbstractRenderer.h

 // Abstract base class for KVRenderers.  Factors out a wee
 // bit of boilerplate code.
 @interface KVAbstractRenderer : NSObject <KVRenderer> {
-  vec2f_t rayField[240][320];
+  float yRays[240];
+  float xRays[320];
 }
 
 // These properties are synthesized for the benefit of

KVAbstractRenderer.m

     yRay = cy;
     ySign = -1.F;
   }
-  vec2f_t ray = rayField[yRay][xRay];
   *coord = (vec3f_t) {
-    ray.x * z * xSign,
-    ray.y * z * ySign,
+    xRays[xRay] * z * xSign,
+    yRays[yRay] * z * ySign,
     z
   };
 }
   const float fovX = fovXDegrees / 180.F * (float) M_PI;
   for (int y = 0; y < 240; y++) {
     float theta = (y / 320.F) * fovX/2.F;
-    for (int x = 0; x < 320; x++) {
-      float psi = (x / 320.F) * fovX/2.F;
-      rayField[y][x] = (vec2f_t) {
-        .x = sinf(psi),
-        .y = sinf(theta),
-      };
-    }
+    yRays[y] = sinf(theta);
+  }
+  for (int x = 0; x < 320; x++) {
+    float psi = (x / 320.F) * fovX/2.F;
+    xRays[x] = sinf(psi);
   }
 }