Lighting Up a Billion Colors with a Million Lines of Code
The final installment in a series about building a mechanical video wall with advanced LED backlighting, covering a custom HDR-aware software pipeline built in C# with HLSL shaders, vector extensions, and zero-allocation architecture.
This is the concluding part of a series about creating a mechanical video wall with advanced backlighting. Here we describe the development of new software for controlling LED strips, which replaced a temporary solution created several years ago.
Key Features of the New Software
Main improvements:
- Captures images directly in HDR format without converting to SDR
- Uses floating-point numbers (float 32-bit) instead of 8-bit integers for each color channel
- Allows creating and editing effect chains in real time
- Analyzes the original HDR image directly on the GPU with minimal overhead
Architecture
The software is built as a video mixer using:
- Channels -- sources of one-dimensional images
- Effects -- data processors (swizzling, fill, glow)
- Output channel -- final post-processing before sending to the controller
Optimization Approach
The core philosophy: "allocate less frequently and consume as much memory as you want." This requires:
- Minimizing heap object creation
- Reusing buffers
- Avoiding garbage collector triggers
Experimental Primitives
mew -- lazy string concatenation on the stack (up to 48 fragments without allocations)
E.rr -- an error handling system without exceptions (logging and continuing execution)
Vist4, Vist16, Vist64 -- lists that store the first elements on the stack and the rest on the heap
ConcurrentBagSlim -- an optimized concurrent container
BeautifulTimer -- a precise timer based on the Windows multimedia API
Pepectors (Vector Extensions)
The most ambitious part of the project -- adding vector types to all C# scalars:
- float2, float3, float4 and analogs for all numeric types
- Angles: turns, radians, degrees (with implicit conversion)
- Fixed point: fxdlong
- Universal pepector -- a dynamic vector of any size and type
Key capabilities:
- HLSL-like syntax:
float3 color = (1, 2, 3); color *= 2; - Swizzling:
color.rgb = color.bgr; - Color space support (RGB to HSL and back)
- Atomic operations for 32-64 bit types
Interface Functionality
- Real-time analysis and display of the video wall
- Visualization of 2,315 LEDs
- Power consumption graphs per power supply unit
- Built-in code editor with syntax highlighting and autocomplete
- HDR support during screen analysis
Additional Effects
- Cursor tracking via a separate bright highlight spot
- New window detection with a flash at the approximate position
- Automatic brightness adjustment depending on TV positions
- Keyboard layout indicator (Russian/English)
Performance
When analyzing a 12K screen:
- GPU load: 0%
- CPU load: 0%
- Memory allocation frequency: 0 Hz
In minimized window mode, the software consumes less than 1% CPU and GPU.
Technical Stack
Although the software is written in C#, it is deeply integrated with:
- HLSL (GPU shaders)
- C++ (for performance-critical operations)
- Windows API (multimedia timers, screen capture)
The project remains in alpha and serves as an experimental platform for testing both technical and conceptual ideas. With a million lines of code driving 2,315 LEDs, it achieves what the author set out to do: light up a billion colors with zero perceptible overhead.