Skip to content
Niffoxic

Fox CPU Rasterizer

A multithreaded software renderer and runtime scene editor: every triangle, pixel and skinned vertex on the CPU.

Type
Optimisation · C++23
Role
Solo: renderer, threading, SIMD, ECS, CPU skinning, post-processing, editor, profiling and benchmarks
Stack
C++23 · SSE / AVX2 · Multithreading · Custom ECS · Dear ImGui · Tracy
Links
Source on GitHub ↗
Fox CPU Rasterizer

10.9× faster than the baseline renderer; a 391k-triangle scene with CPU skinning and post effects at 1080p.

faster than the single-threaded baseline renderer on the same scene (5.70 to 0.52 ms)
10.9×
of that on a single thread: the algorithm and data layout, not just more cores
3.9×
triangles with 5 CPU-skinned characters, rain and bloom at 1080p
390,961
scaling of the post effects from 1 to 32 threads
11–14×

Overview

How far can one CPU go as a real-time 3D renderer with no GPU rasterisation at all? I treated it as an optimisation problem. The starting point was a working but slow baseline renderer: one thread, a per-pixel barycentric test, 5.7 ms for 49 simple objects at 1024×768. I profiled it, then rewrote it around an edge-function rasteriser, lock-free band threading, SIMD and a data-oriented ECS. Then I built a real scene on top: a 391k-triangle lava island with animated characters, rain, bloom and other effects, plus a runtime editor to place and tweak everything live. I measured every step with Tracy and a benchmark harness, and the profiler shows where the next win is. DirectX 11 is only used to show the finished image.

The full demo, with captions: CPU skinning, post effects, rain, reflections, the runtime editor and the 3.2-million-triangle stress test. Most of it is rendered frame by frame; the editor part is live.

What I built

  • Software rasteriser Every transform, clip, depth test, texture lookup and lighting calculation runs on the CPU. An edge-function rasteriser with incremental stepping, perspective-correct texturing and flat per-triangle lighting.
  • Lock-free threading A persistent worker pool woken per pass. The screen is split into bands, one per thread, so threads never share pixels and need no locks or atomics. The same pool runs the raster pass and every post effect.
  • SIMD and memory SSE whole-triangle frustum rejection, SIMD normal sums, non-temporal framebuffer clears, AVX2 builds and 64-byte aligned buffers.
  • Data-oriented scene My own archetype ECS (fecs): meshes, transforms and materials live in packed arrays the renderer walks in order.
  • CPU animation and effects Skeletal skinning per character, plus exposure, contrast, saturation, vignette, rain, bloom, screen-space reflections, fog, depth of field and god rays.
  • Editor and profiling A Dear ImGui editor with picking, gizmos and scene.json save/load. Tracy zones on every stage and every worker band, and a harness that times each stage across thread counts and resolutions.

Results

11 figures
The 390,961-triangle lava island, drawn and lit entirely on the CPU: 38–55 ms per frame at 1920×1080 with the shipped 9 threads on a Ryzen 9 9950X.
FIG. 1The 390,961-triangle lava island, drawn and lit entirely on the CPU: 38–55 ms per frame at 1920×1080 with the shipped 9 threads on a Ryzen 9 9950X.
Same scenes, same geometry, same resolution as the baseline renderer. My renderer lights each triangle once instead of per pixel, so the images aren't pixel-identical.
FIG. 2Same scenes, same geometry, same resolution as the baseline renderer. My renderer lights each triangle once instead of per pixel, so the images aren't pixel-identical.
Skeletal animation skinned on the CPU every frame, each character with its own animation state: 2 ms for 5 characters.
FIG. 3Skeletal animation skinned on the CPU every frame, each character with its own animation state: 2 ms for 5 characters.
The heavy scene at 1080p across thread counts. Per-pixel passes scale almost linearly; the raster pass stops at 3.8×, and the profiler shows why.
FIG. 4The heavy scene at 1080p across thread counts. Per-pixel passes scale almost linearly; the raster pass stops at 3.8×, and the profiler shows why.
Tracy profile: each thread owns a horizontal band of the screen. The bands over the island take 3× longer than the bands over flat lava, and every band re-transforms the whole scene. The next step is binning triangles into tiles once and handing them out dynamically.
FIG. 5Tracy profile: each thread owns a horizontal band of the screen. The bands over the island take 3× longer than the bands over flat lava, and every band re-transforms the whole scene. The next step is binning triangles into tiles once and handing them out dynamically.
The runtime editor: spawn static and animated meshes, pick and move them with the mouse, tweak every effect live and save the scene to JSON.
FIG. 6The runtime editor: spawn static and animated meshes, pick and move them with the mouse, tweak every effect live and save the scene to JSON.
The raw raster output, before any post effects.
FIG. 7The raw raster output, before any post effects.
The same frame with the full CPU effects stack: exposure, contrast, vignette, rain, bloom and fog.
FIG. 8The same frame with the full CPU effects stack: exposure, contrast, vignette, rain, bloom and fog.
Screen-space reflections and rain on the default scene, which runs at about 110 fps (21k triangles).
FIG. 9Screen-space reflections and rain on the default scene, which runs at about 110 fps (21k triangles).
Depth of field and god rays, also on the CPU.
FIG. 10Depth of field and god rays, also on the CPU.
Stress test: 3.2 million triangles with 60 extra CPU-skinned characters. It still renders, at about 4 fps.
FIG. 11Stress test: 3.2 million triangles with 60 extra CPU-skinned characters. It still renders, at about 4 fps.

Hard parts

  • Measuring before optimising: repeated runs, per-stage timers and a Tracy capture, with the numbers reported honestly. On a two-chiplet CPU, where Windows places the threads moves 1080p frame time between 38 and 55 ms.
  • The raster pass scales only 3.8× at 32 threads. The profiler found the reasons (band imbalance and repeated vertex work) and the fix (bin triangles into tiles once, then hand tiles out dynamically).
  • Benchmarking found a latent bug: the band splitter can round past the last row at thread counts the app never shipped with. A one-line clamp fixes it.

Limits

What it doesn't do yet
  • The heavy scene runs at 18–26 fps live, not 60. The default scene runs at about 110 fps.
  • The looping clip of the heavy scene was rendered frame by frame for smooth playback.
  • Directional light only, simple screen-space reflections, and Windows only.
Harsh Dubey

Harsh Dubey

Graphics and game programmer. MSc Games Engineering (Distinction), University of Warwick.

About me