TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25602 17
GoCL – A C++20 Vulkan proxy with zero‑overhead dispatch, SPIR‑V rewriting, and lazy‑loaded backends

I’ve been working on a Vulkan optimisation layer and static library called GoCL. The C++ side ended up more interesting than I expected, so I wanted to share a few design choices.

It’s a Vulkan proxy (vulkan_proxy.so / vulkan‑1.dll) and a static library (GoCL_core.a) that adapts rendering to the GPU’s actual capabilities at runtime. The proxy intercepts Vulkan calls and modifies them before they reach the driver, while the static library provides the same logic directly to engines that link against it. All C++20.

C++ details that might interest this sub:

Capability oracle – on device creation, the engine queries every relevant physical device feature (texture compression, float16 support, descriptor indexing tiers, memory budget, etc.) and stores the result in a plain `DeviceCapabilities` struct. Every subsystem reads from that struct; there’s no virtual dispatch or runtime capability checks on the hot path. Decisions are data‑driven and branch‑predictable.
Proxy dispatch chain – the proxy hooks Vulkan entry points by patching a dispatch table (the loader’s vkGetDeviceProcAddr pattern). The table is populated at vkCreateDevice time. On Linux the library is linked with -Wl,-z,now so all dynamic symbols are resolved eagerly at load time. Callgrind confirms zero lazy‑binding overhead in the render loop – dlopen/dlsym calls appear only in initialisation functions.
SPIR‑V rewriting – unsupported shader features (FP16, oversized descriptor sets) are detected and the binary is rewritten before the driver sees it. The rewriter is a lightweight in‑memory pass that widens FP16 ops to FP32 and splits large descriptor bindings. No external compiler, no LLVM dependency; it’s just a handful of C++ functions operating on the SPIR‑V binary blob.
Lazy‑loaded transcoder – the heavy Basis Universal encoder (used for ASTC→ETC2 texture conversion) is separated into gocl_transcoder.so, loaded via dlopen / LoadLibrary only when an ASTC texture is encountered. The static initialisers of the transcoder are therefore never invoked unless actually needed, keeping the proxy’s baseline footprint minimal.
Zero per‑frame overhead – Callgrind instruction counts on a GTX 960M running 75+ Sascha Willems Vulkan examples: the proxy has \~3.8% fewer total instructions than native (3.806B vs 3.955B). FPS and frame times are identical within noise. All the work happens once at pipeline creation or texture load; the render loop is untouched.
Dual‑licensed under Apache‑2.0 OR MIT. Tested in CI with Mesa Lavapipe.

Architecture write‑up (covers the capability model, shader emulation, proxy internals, and the lazy‑load design):
GoCL – Architecture

GitHub: GoCL

Happy to discuss the C++ side – the capability oracle and the SPIR‑V rewriter in particular were fun to keep simple and predictable.

https://redd.it/1uu3392
@r_cpp
GitHub GoCL/docs/ARCHITECTURE.md at main · thee3rdplayer/GoCL GoCL is a cross‑generational Vulkan optimisation engine that adapts rendering to the GPU's real capabilities. It works as a static library for custom engines, or as an implicit Vulkan layer...
More from @r_cpp
  1. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  2. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  3. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  4. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  5. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
  6. Sep 11, 2026MSVC C++23: constexpr cmath with LLVM Libc https://devblogs.microsoft.com/cppblog/msvc-c23…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →