Files
ppsspp/Common
Chris Healy 9ed5dcdc27 GPU: Use inversesqrt for light distance and half-vector calculations
Replace length()/normalize() with inversesqrt() pattern for better
performance on mobile GPUs. The inversesqrt instruction is a single
hardware operation, while length() requires sqrt(dot()) and normalize()
requires inversesqrt internally plus a multiply.

Changes:
1. Light distance calculation:
   Before: distance = length(toLight); toLight /= distance;
   After:  distSq = dot(toLight, toLight);
           invDist = inversesqrt(distSq);
           distance = distSq * invDist;
           toLight *= invDist;

2. Specular half-vector normalization:
   Before: ldot = dot(normalize(toLight + vec3(0,0,1)), worldnormal);
   After:  halfVec = toLight + vec3(0,0,1);
           halfInvLen = inversesqrt(dot(halfVec, halfVec));
           ldot = dot(halfVec, worldnormal) * halfInvLen;

Also reuses distSq in attenuation calculation to avoid recomputing
distance*distance.

Offline shader compiler results (vertex shader with 4-light ubershader):

Mali (malioc):
  G31 (Bifrost): 44.90 -> 40.50 cycles (-9.8%)
  G52 (Bifrost): 14.97 -> 13.50 cycles (-9.8%)
  G310 (Valhall): 13.88 -> 12.88 cycles (-7.2%)
  G57 (Valhall):  7.60 ->  6.97 cycles (-8.3%)

PowerVR (Profiling Compilers):
  Series 8 GE8300: 322 -> 302 ALU cycles (-6.2%)
  Series 9 GM9445: 296 -> 280 ALU cycles (-5.4%)
  Series B BXM:    560 -> 540 instructions (-3.6%)

Signed-off-by: Chris Healy <cphealy@gmail.com>
2026-03-08 19:13:41 -07:00
..
2025-02-11 10:43:39 -06:00
2026-02-26 23:41:38 +01:00
2026-02-23 14:22:30 +01:00
2026-02-15 19:57:56 +01:00
2026-01-19 15:47:40 +01:00
…
…
2025-08-31 13:37:43 +02:00
2025-01-08 17:02:39 +01:00
…
…
2025-01-23 13:28:51 +01:00
2026-01-30 14:10:32 +01:00
2024-11-04 23:14:39 +01:00
2025-04-23 22:08:40 +02:00
2025-09-02 13:26:04 +02:00
2025-08-31 13:37:43 +02:00
…
…
…
2025-08-26 10:50:56 +02:00