
Hardware Scan-Line Triangle Rasterizer

Synthesisable fixed-function triangle rasterizer in SystemVerilog using signed fixed-point arithmetic throughout. Two builds are included: a scalar baseline (1 pixel/cycle) and a SIMD variant (OUT_W=8, 8 pixels/cycle as a masked warp). Both share the same arithmetic core, command front end, and verification infrastructure.
What It Does
Takes a flat list of screen-space triangles with per-vertex RGB and renders them to a framebuffer through a fixed-function pipeline: edge setup, scan conversion, barycentric interpolation, Gouraud shading, and framebuffer writeback.
For 3D scenes, model, view, and perspective projection transforms run per frame in a host preprocessing step that emits projected 2D screen-space triangles to the hardware pipeline.
Architecture
Scalar datapath:
cmd_proc → edge_setup → rasterizer → frag_fifo → interp → pixel_shader → framebuffer
SIMD datapath:
cmd_proc → edge_setup → rasterizer(OUT_W=8) → warp_fifo → simd_interp → simd_pixel_shader → writeback_coalescer → framebuffer_mp
The SIMD rasterizer tests 8 horizontally adjacent pixels per cycle using a combinational generate loop over the row-start accumulators. Output is a masked warp: out_mask is 8 bits, one per lane, with lanes outside the triangle or past the row end already zeroed. framebuffer_mp has 8 independent write ports, all firing in the same clock edge.
Core Arithmetic
All arithmetic is signed fixed-point. Vertex coordinates are 16-bit signed. The SX macro sign-extends them to 32 bits before any multiply to prevent cross-product overflow on large triangles.
Edge equations. For edge $i \to j$:
$$E_{ij}(x,y) = A_{ij}\,x + B_{ij}\,y + C_{ij}$$A pixel is inside the triangle when all three evaluations are non-negative simultaneously. $A$, $B$, $C$ are computed once at triangle load, so the scan walk advances across pixels using additions alone: stepping right adds $A$, and stepping down adds $B$.
Barycentric weights are the edge equation values themselves, forwarded directly from the coverage test without extra arithmetic stages.
Gouraud shading blends per-vertex colors weighted by the barycentric coordinates, accumulated in 48-bit intermediates, divided by area2, and clamped to [0, 255].
Winding is normalized at load time by checking area2[31] and negating all six coefficients if negative, allowing the SCAN state to apply a uniform >= 0 coverage check on every pixel.
Performance
| Scene | Triangles | Pixels | Scalar (cycles) | SIMD (cycles) | Speedup |
|---|---|---|---|---|---|
| Hello Triangle | 1 | 25,313 | 50,670 | 6,580 | 7.7x |
| Quads | 8 | 63,000 | 125,220 | 16,300 | 7.7x |
| Sunset | 20 | 72,752 | 146,736 | 19,426 | 7.6x |
Scalar throughput is 0.50 px/cyc across all three scenes. SIMD throughput is 3.85 to 3.87 px/cyc on the larger axis-aligned triangles, approaching the 4.0 px/cyc theoretical ceiling at 50% fill efficiency for warp size 8. The sunset’s small triangles (157 to 160 pixels each) pull the average to 3.75 px/cyc due to partial-warp overhead at row ends. Rasterizer backpressure is zero across all three SIMD runs.
Scenes
Hello triangle, quads, and sunset were the primary regression targets across both builds.

| Quads | Sunset |
|---|---|
![]() | ![]() |
Photograph reconstruction using png2scene.py, which converts any image to a scene file by splitting it into an NxN cell grid and emitting two triangles per cell. At 256-cell resolution on a 256x256 framebuffer: 131,072 triangles.
| 6k triangles | 32k triangles | Final |
|---|---|---|
![]() | ![]() | ![]() |
3D animation target: a layer-by-layer Rubik’s cube solve. 3x3 cube, 54 stickers, 6 independent face colors, 3 independently rotating layers. The solve sequence is F R' F' R U R U' R' F R U R' U' R' F' R U' R'.

Verification
Constrained-random regression testbench (tb_gpu_top_cr.sv) with a Python golden model. 14 coverage buckets:
random_ccw random_cw degenerate_collin degenerate_samept
fully_offscreen partially_clipped thin_sliver full_screen
axis_aligned near_horizontal near_vertical screen_corner
single_row random_extra
Five independent checker blocks run cycle-by-cycle: cmd-proc protocol, rasterizer output bounds, FIFO push/pop integrity, pipeline drain (pixel conservation), and framebuffer write bounds.
Results against 98 triangles across all 14 buckets:
Triangles submitted : 98
Degenerate (dropped) : 14
Pixel count checks : 98 pass / 0 fail
CMD-proto errors : 0
Rast OOB pixel errors : 0
FIFO overflow errors : 0
FIFO underflow errors : 0
Pipeline drain errors : 0
FB OOB write errors : 0
FB write-during-clear : 0
Earlier Design Iterations
Iteration 1: per-lane FIFOs with round-robin arbitration. The first multi-lane prototype kept a single-pixel rasterizer feeding 4 per-lane FIFOs, with a free-running round-robin counter popping one lane per cycle. Under uneven triangle coverage, fuller lanes backpressured the rasterizer; when the scan stalled mid-row and resumed, queued pixel coordinates drifted out of alignment with the arbitration counter, causing out-of-order writes and diagonal gradient artifacts. This showed that lane ordering needed to travel in lockstep with pixel masks rather than through independent per-lane queues.
| Hello Triangle (Iteration 1) | Quads (Iteration 1) |
|---|---|
![]() | ![]() |
Iteration 2: warp batching scheduler FSM. The second iteration batched single-pixel rasterizer outputs into 8-lane warps before interpolation. This revealed two bottlenecks: a one-cycle DISPATCH-to-ACCUMULATE transition window could miss rast_done on partial tail warps, and serializing 8 lanes through a 1-pixel/cycle writeback coalescer capped downstream throughput to 1 pixel per 8 cycles whenever warps were full. That pointed directly to wide rasterization paired with multi-port framebuffer writeback.
| Hello Triangle (Iteration 2) | Quads (Iteration 2) |
|---|---|
![]() | ![]() |
Final SIMD architecture. Extending the rasterizer with OUT_W=8 evaluates 8 horizontally adjacent pixels in parallel per cycle, feeds a unified 16-entry warp FIFO into the SIMD interpolator and shader, and commits up to 8 valid pixels per clock through framebuffer_mp’s 8 parallel write ports.
| Hello Triangle (final) | Quads (final) | Sunset (final) |
|---|---|---|
![]() | ![]() | ![]() |












