Yuvi GD
YUVI

Chitra 2D Render Engine

Chitra is a specialized C99 2D graphics engine architected for retained UI systems and game overlays. It features reservation-first handles, decoupled 30-bit Draw Order sorting, hardware scissor batching, single-upload typography synchronization, and state-aware draw call coalescing over Sokol GFX.

Technologies Used

C99CMakeSokol GFXSokol AppFontstashstb_truetypeearcut.h

Plugin Info

In Development
startDate: 2026-09-23
platform: Desktop (Windows, Linux, macOS via Sokol GFX / SDL3)

System Topology & Gallery

diagram
1 / 3
100%

Chitra Architecture and Smart Pacing

Chitra (from the Sanskrit चित्र, meaning a picture, painting, or visual art) is a high-performance, lightweight, data-oriented 2D rendering engine implemented in pure C99. It was engineered from the ground up to eliminate the core performance bottlenecks plaguing modern desktop user interfaces: pointer-chasing scene graphs, recursive layout traversals, mid-frame GPU driver stalls, and continuous CPU battery drain during idle frames.

Traditional retained UI engines construct deep object-oriented node graphs (Node* parent, std::vector<Node*> children), forcing the CPU to jump across fragmented heap allocations and incur constant L1/L2 data cache misses. Conversely, immediate-mode GUI libraries force the CPU to re-traverse the entire interface and regenerate thousands of vertex buffers every frame, wasting immense compute on completely static screens.

Chitra eliminates both failure modes through a breakthrough Data-Oriented Dynamic 2-Table Architecture (CommandTable + free_list). Element metadata is packed into dense 16-byte slots (Chitra_CommandSlot), allowing four slots to align perfectly across a single 64-byte CPU cache line. When an element is destroyed, its handle is recycled into a LIFO stack in $O(1)$ time, clustering active handles near index zero. Geometry is stored in dedicated, contiguous per-pipeline staging arrays in system RAM (40-byte Shape vertices and 20-byte Text/Texture/Mesh vertices), eliminating the GPU warp thread divergence caused by monolithic "God Shaders".

To achieve maximum batching throughput without imposing artificial depth ceilings, Chitra completely decouples the 32-bit element handle from its 64-bit sort key. By allocating a full 30 bits to Draw Order, Chitra provides 1,073,741,823 distinct visual layers (~1.07 billion)—perfectly matching the quad capacity of a 32-bit Index Buffer. Active elements are paired into 16-byte Chitra_SortEntry structs and sorted via an 8-pass Least Significant Digit (LSD) Radix Sort in under 15 microseconds for 1,000 entries.

Chitra solves runtime memory fragmentation with Dead-Memory Hole-Skipping. When dynamic text grows or shrinks, trailing or abandoned vertices are recorded as dead holes in RAM; memory is never shifted with expensive memmove() operations. During draw generation, the 32-bit index buffer stream emits indices exclusively for active geometry, naturally jumping over dead holes with zero GPU fillrate penalty. Furthermore, a 34-bit state mask (key & 0x00000003FFFFFFFFULL) strips the top Draw Order bits, coalescing elements across different visual layers into single GPU draw calls if their scissor clip, pipeline, and texture match.

Engineered for extreme energy efficiency, Chitra delivers fluid 240Hz+ high-refresh-rate rendering during interactions, yet instantly drops to 0.0% CPU and GPU utilization when the scene is static via OS-native waitable handles (MsgWaitForMultipleObjectsEx on Windows, nanosleep on POSIX) coupled with a 3-frame countdown flush for multi-buffered display swapchains.

Core Capabilities

Data-Oriented Dynamic 2-Table Model (16B slots + LIFO free_list stack recycler)

Decoupled 30-Bit Draw Order Sort Key supporting ~1.07 billion visual layers

Zero-cost dead memory hole-skipping via 32-bit Index Buffer (SG_INDEXTYPE_UINT32)

Microsecond 8-pass LSD Radix Sort using cache-line aligned 16-byte SortEntry structs

State-aware batch coalescing via 34-bit bitmask (0x00000003FFFFFFFFULL)

Analytic SDF rounded rectangles, borders, and pills evaluated in fragment shaders

Decoupled typography with zero-allocation CPU layout metrics and single-upload atlas sync

True 0.0% CPU and GPU idle utilization via OS waitable objects and 3-frame swapchain flush

Strict 4-layer decoupling (HAL, RHI, Engine Core, Client) supporting future SDL3 & SDL_GPU

Architectural Implementation

01Dynamic 2-Table Memory Model & Hole-Skipping

Replaces pointer-chasing scene graphs with a flat 16-byte CommandTable array and a dynamic LIFO free_list stack. Mutations execute as O(1) in-place RAM writes without shifting memory. Resized or deleted geometry leaves dead memory holes that the 32-bit GPU index buffer naturally leaps over at zero GPU cost.

02Decoupled 30-Bit Sort Key & LSD Radix Sorter

Decouples the 32-bit command handle from the 64-bit sort key, allocating 30 bits to Draw Order (~1.07 billion layers), 16 bits to Scissor Clips, 5 bits to Pipelines, and 13 bits to Textures. 16-byte SortEntry structs align four per 64-byte L1 cache line, sorting 1,000 active elements in under 15 microseconds.

03State-Aware Batch Coalescing

Evaluates GPU hardware state boundaries using a 34-bit bitmask (key & 0x00000003FFFFFFFFULL). Quads on different visual layers sharing identical scissor clip, shader pipeline, and texture coalesce into a single GPU draw call while preserving strict Painter order.

04Decoupled Typography & Single-Upload Rule

Separates font layout calculation (chitra_measure_text runs purely on CPU font tables without allocating vertices) from GPU rendering. New glyphs rasterized into the CPU atlas buffer are uploaded to GPU VRAM exactly once per frame prior to rendering, completely preventing mid-frame driver stalls.

05Event-Driven 0.0% Idle Frame Pacing

Drops CPU and GPU load to true 0.0% during static scenes by suspending the thread on OS waitable handles (MsgWaitForMultipleObjectsEx on Windows, nanosleep on POSIX). Upon visual mutation, a 3-frame countdown ensures double- and triple-buffered swapchains present smoothly without tearing.

Yuvi GD

Game Developer & 3D Artist crafting immersive digital experiences. Pushing the boundaries of interactive technology.

Services

  • Game Development
  • Technical Art & Pipeline
  • Full-Stack Web Development
  • Custom Software Solutions
  • Utilities & Network Systems

Get In Touch

Email:
Yuvi_GD@outlook.com

Discord:
yuvi_gd

© 2026 Yuvi GD. All rights reserved.

Built with Next.js, Three.js & Tailwind CSS