LJYC

VISERA II

A 2D game engine I wrote myself2025 – 2026

After finishing Visera, my previous graphics experimentation platform, I wanted to build a 2D engine that could really take a game all the way to completion and release. I did not spend my energy inventing clever concepts from scratch. Instead, with a pragmatic engineer’s eye, I carefully took apart the architectural strengths of mature engines such as Unreal Engine, trimmed and absorbed them to the actual scale of my own product, and solved problems stably and efficiently in the form that fit best.

Visera II is written throughout in C++23 Modules and Vulkan: a frame is relayed lock-free across the main thread, the render thread and the RHI thread, and the execution order of RenderPasses and the Vulkan layout barriers are derived automatically by a RenderGraph that is recompiled every frame. In the end I used it to make and release Fire Meow, a small arcade shooter for Windows and macOS.

Chapter 1THREADS

Borrowing the concurrency skeleton of mature engines,
three threads relay one frame

Once a game runs script logic, multi-stage rendering and low-level graphics calls at the same time, crowding them all onto one thread means a slowdown anywhere drags the whole frame. Following Unreal Engine’s approach to multithreaded rendering, I split a Visera II frame across three threads with clear responsibilities: the main thread runs game logic and collects draw data; the render thread (called the Graphics thread in the code) batches, compiles the RenderGraph and records the engine’s command list; the RHI (render hardware interface) thread deals exclusively with Vulkan and is responsible for submission and presentation.

Threads hand work over through two kinds of lock-free queue: SPSC (single producer, single consumer) always has one writer and one reader, while MPSC (multiple producers, single consumer) lets any thread post and a single thread take; both queues follow the 1024cores algorithms and UE5’s implementation. The whole pipeline keeps its pace with two explicit limits, so that upstream stages cannot run ahead without bound:

  1. SCRIPTScript

    Every frame the main loop calls the script’s OnTick(dt); when the script writes visera.drawSprite({ … }), the rendering module holds on to it first.

  2. MAINMain thread

    When Render() is called at the end of the frame, the main thread packs the draws, lights, and view and projection matrices into an FRenderTask and hands it to the render thread through TSPSCChannel<FRenderTask>; if the previous frame has not been taken yet, the main thread stops and waits on FrameConsumedEvent.

    At most1frame ahead
  3. RENDERRender thread

    Once the render thread has the task, it first asks the RHI for a frame slot (the frame number modulo 3); when 3 frames are already in flight, it waits on FrameSlotFreeEvent. With a slot in hand it batches sprites, uploads instance data, and compiles and executes the RenderGraph, recording a byte-stream command list made of 23 kinds of custom instruction, which goes to the RHI thread through a TSPSCQueue; a used list is cleared, shrunk to a 64 KB high-water mark and sent back through a reverse TSPSCQueue for reuse.

    At most3frames in flight
  4. RHIRHI thread

    Vulkan calls are concentrated on this thread. It consumes two queues in turn: one carries the command lists sent by the render thread, the other the immediate tasks that any thread posts through a TMPSCQueue (creating the swapchain, creating resources, Present); when both are empty it sleeps on WakeEvent.

  5. GPU

    Every frame is submitted to the GPU with a fence, and only after the GPU finishes drawing and signals is the matching frame slot released; released resources likewise go into a recycle bin first and are destroyed once the associated fence completes.

Slow one stage down and see where the threads before it are held back

The main thread is at most 1 frame ahead and the GPU has at most 3 frames in flight; at run time both limits show up as waiting. Open the simulation below and slow any stage down to see how the downstream stages go idle and how the upstream ones are held back, step by step, by the backpressure at these two points.

Main thread

TSPSCChannel<FRenderTask>

Render thread

TSPSCQueueCommand lists

TSPSCQueueSent back after use

TMPSCQueueImmediate tasks

RHI thread

Frames in flight

GPU

Which frame is being worked on; colors by frame slot
Held back by a limit, waiting
Nothing to do
Time runs from left to right; the far right is now.

Chapter 2RENDER GRAPH

Recompile the RenderGraph every frame,
and leave ordering and Vulkan barriers to the compiler

The easiest place to trip when writing Vulkan directly is keeping resource state in sync. The same texture is written as a color attachment in one stage and must be switched to shader sampling for reading in the next, and every such change of usage needs an accurate layout transition barrier. Once passes are added to or removed from the rendering flow, maintaining the execution order and the barriers by hand is both tedious and easy to get wrong.

So that writing rendering code only means caring about what each pass itself reads and writes, I split a frame into RenderPasses and leave their arrangement to a RenderGraph that is recompiled every frame. Each pass is declared with just two lambdas: Setup states the textures it reads and writes and their usage, and Execute records the draw commands. Compilation proceeds in four steps:

One frame’s RenderGraph: nine passes. A line means one pass reads a texture that another pass writes.
Root: a pass that writes an external resource
Culled
Writes an external resource: the back buffer, or a texture exported to the cache

Change the graph

Turn off a read in the graph above, or stop exporting the trail history to the cache, and you can see directly which passes get culled and how the execution order and barriers are rearranged with it.

Declare

Passes are registered by priority; when one pass reads a texture that another pass writes, a dependency edge is created between them automatically.

Click any pass in the graph to see what it declares in Setup.

Chapter 3MODULES

Pragmatic assembly, technical probing and decisive subtraction

Beyond the threads and the render graph, the modules around the engine follow the same principle: integrate what is mature and usable as it is, wrap the core pain points myself in a thin, steady layer of abstraction, and cut the baggage that does not fit without hesitation.

4 draws

Batched sprite drawing

The render thread groups this frame’s draws by a “material + mesh” key; each instance takes 80 bytes written into the current frame slot’s instance buffer, and each group issues just one Draw(6, N), drawing all N copies at once.

JavaScript · V8
OnInit()Called once after loading
OnTick(dt)Called by the main loop every frame
What scripts can use
  • Drawing sprites
  • Keyboard and mouse input
  • Wwise audio
  • Logging
  • Main-window settings

Probing the scripting layer (V8 + JavaScript)

Early on the engine tried C# (.NET); later I deliberately switched to an embedded V8 running JavaScript. This was more a conscious technical probe: I wanted to try, with my own hands, a scripting approach different from the routes common in Unity and Godot. Once the entry script is loaded, OnInit() is called, the main loop calls OnTick(dt) every frame, and the interfaces exposed to scripts cover drawing sprites, keyboard and mouse input, Wwise audio, logging and main-window settings.

The hot tier is a row of resources in order of most recent use; once it is full, the oldest drops into the cold tier. On a hit in the cold tier, if the object is still alive, it goes back to the front of the hot tier. Hot tier · LRU · strong references New → old Hit and still alive: back to hot Evicted from hot, into cold Cold tier · weak references

A two-tier hot and cold resource cache

Images and shaders first enter an LRU hot tier weighted by bytes (64 MB for images, 32 MB for shaders, held by strong references); when it fills up, the least recently used entries are pushed into the cold tier, which keeps only weak references; if the object is still alive when it is requested again, it is promoted straight back to the hot tier.

Three queues, critical, normal and spam, each drained by quota every frame; the commands are merged and then handed to Wwise. Critical64 Normal256 Spam128 Wwise Drained by quota each frame, at most 512 in total

A front-end queue for Wwise audio

On top of Wwise I added a multi-queue command front end. Any thread can post commands into three MPSC queues, critical, normal and spam; every frame the main thread takes them out by per-queue quotas of 64, 256 and 128, with the per-frame total capped at 512, merges the same parameter of the same emitter into its last setting, and submits everything to Wwise together after rate limiting.

Subtraction is part of being pragmatic too. Along the way I cut part of the editor (Studio) I had been building, as well as heavy dependencies such as EnTT. For one thing, while moving the whole repository to C++23 Modules, heavily templated libraries like EnTT were not stable enough under the module mechanism, and removing it was the only way to keep the build and the architecture clean. For another, this was also when I began to realize that a heavyweight editor in the traditional sense is no longer a must for building an engine in the new era.

Fire Meow in play: on a lawn, a small cat with a pink bow is surrounded by a crowd of little yellow flames; three red hearts at the top left, a score of 161 at the top right.
A screenshot of the game from itch.io.

Chapter 4FIRE MEOW

Closing the loop with Fire Meow,
and seeing the real cost of going cross-platform

Whether an engine is any good only counts once a game has actually been made with it and shipped. With Visera II I made Fire Meow, a fast-paced arcade shooter, and packaged and released Windows and macOS versions, live on itch.io. On screen a little cat with a bow stands in the middle of a meadow: WASD to move, the mouse to aim and shoot the flames swarming in, and defeating elite flames lets you pick up three kinds of upgrade, Agile, Guardian and Mighty.

Download and play · itch.io

itch.io has two downloads, one for Windows and one for macOS.

Thumbnail of the demo video: the GAME OVER screen on the lawn, with the cat standing in the middle. Watch the demo videoYouTube · 28 s

Taking the engine all the way to release gave me more than a small playable game; it gave me hands-on experience that reading documentation alone could never provide. Going cross-platform with Vulkan plus MoltenVK, the code really does run and the game really does ship; but only when it comes down to day-to-day tuning and distribution does the engineering cost fully show: on macOS, behind a translation layer, I could not directly use the platform’s native graphics development tools for profiling and debugging, and even the final packaging and distribution stage met a good deal of added resistance.

Together with rethinking the traditional editor during development, these first-hand judgments left by Visera II became the direct starting point for the architectural choices I made later when conceiving Verdandi (native Vulkan + Metal on the two platforms, and a redefined role for the editor).