SdlVulkan.Renderer
3.4.431
dotnet add package SdlVulkan.Renderer --version 3.4.431
NuGet\Install-Package SdlVulkan.Renderer -Version 3.4.431
<PackageReference Include="SdlVulkan.Renderer" Version="3.4.431" />
<PackageVersion Include="SdlVulkan.Renderer" Version="3.4.431" />
<PackageReference Include="SdlVulkan.Renderer" />
paket add SdlVulkan.Renderer --version 3.4.431
#r "nuget: SdlVulkan.Renderer, 3.4.431"
#:package SdlVulkan.Renderer@3.4.431
#addin nuget:?package=SdlVulkan.Renderer&version=3.4.431
#tool nuget:?package=SdlVulkan.Renderer&version=3.4.431
SdlVulkan.Renderer
SDL3 + Vortice.Vulkan rendering library built on DIR.Lib primitives.
Types
SdlVulkanWindow— SDL3 window with Vulkan instance and surface lifecycle. Creates maximized, resizable windows with Vulkan surface.VulkanContext— Vulkan device, command buffers, sync management.MaxFramesInFlight = 2with per-frame vertex buffers. Two construction modes:VulkanContext.Create(instance, surface, w, h, ...)— on-screen path with a swapchain tied to anSdlVulkanWindow.VulkanContext.CreateOffscreen(instance, w, h, ...)— headless path rendering to a standaloneVkImage; no surface, no swapchain, no SDL window. See Headless / offscreen rendering below.
VkRenderer—Renderer<VulkanContext>implementation with FillRectangle, DrawRectangle, FillEllipse, DrawText, plus batched glyph and persistent-vertex-buffer draw APIs. ExposesFontAtlasDirtyso callers can trigger redraws after glyph rasterization. HasBeginFrame/BeginOffscreenFramevariants that match the twoVulkanContextmodes.VkPipelineSet— GLSL 450 shader compilation and Vulkan pipeline creation (flat, textured, ellipse, stroke, SDF, blend variants).VkFontAtlas— Dynamic bitmap glyph atlas with ManagedFontRasterizer (from DIR.Lib) rasterization and Vulkan texture upload. Supports grow (512→4096), deferred eviction, andskipUnflushedto prevent sampling stale GPU texture data.VkSdfFontAtlas— Signed-distance-field glyph atlas side-car for resolution-independent text.SdfRasterSize = 128,fwidth-driven AA in the fragment shader auto-tunes to ±0.5 screen pixels at any zoom. Single-channel R8_Unorm texture, keyed on(font, size, character, charCode)so CID subset fonts don't collide.
Font Atlas Lifecycle
Per frame:
BeginFrame()/BeginOffscreenFrame()— handles deferred eviction, runsOnPreFlush(pre-warm callback), callsFlush(cmd)on both atlases, runsOnPreRenderPass(texture uploads), thenBeginRenderPass.Flush(cmd)— uploads dirty staging region to GPU viavkCmdCopyBufferToImage.DrawText(...)→GetGlyph(...)— cache hit returns UV coords; miss rasterizes into staging.GetGlyph(..., skipUnflushed: true)— in draw loops, returns zero-width for glyphs not yet uploaded. Pair withPreWarmGlyphinOnPreFlushif drawing a glyph that wasn't shown last frame (first-frame glyph flicker).
Thread safety: vkDeviceWaitIdle() before reusing the shared upload buffer (prevents race with MaxFramesInFlight = 2).
Diagnostic logging (Console.Error): [FontAtlas] / [VkRenderer] prefixed lines for Flush, Grow, EvictAll, cache miss, Resize. Capture with 2>stderr.log.
Usage
using SdlVulkan.Renderer;
using var window = SdlVulkanWindow.Create("My App", 800, 600);
window.GetSizeInPixels(out var w, out var h);
var ctx = VulkanContext.Create(window.Instance, window.Surface, (uint)w, (uint)h);
var renderer = new VkRenderer(ctx, (uint)w, (uint)h);
while (running)
{
if (!renderer.BeginFrame(bgColor)) { renderer.Resize(w, h); continue; }
renderer.FillRectangle(rect, color);
renderer.DrawText("Hello", fontPath, 14f, white, layout);
renderer.EndFrame();
if (renderer.FontAtlasDirty) needsRedraw = true;
}
Headless / offscreen rendering
VulkanContext.CreateOffscreen builds a context that renders to a single VkImage instead of a swapchain. No VkSurfaceKHR, no SDL window, no VK_KHR_swapchain device extension requested — useful for tests, thumbnail / raster workers, CI without a display server, and server-side rendering.
using SdlVulkan.Renderer;
using Vortice.Vulkan;
using static Vortice.Vulkan.Vulkan;
// Minimal instance — no windowing extensions needed.
vkInitialize().CheckResult();
VkInstanceCreateInfo ici = new();
vkCreateInstance(&ici, null, out var instance).CheckResult();
const uint W = 1920, H = 1080;
using var ctx = VulkanContext.CreateOffscreen(instance, W, H);
using var renderer = new VkRenderer(ctx, W, H);
renderer.BeginOffscreenFrame(new DIR.Lib.RGBAColor32(255, 255, 255, 255));
renderer.FillRectangle(new RectInt(new(100, 100), new(400, 300)), red);
renderer.DrawText("Hello", fontPath, 14f, black, layout);
renderer.EndOffscreenFrame();
ctx.WaitOffscreenFrameComplete();
byte[] rgba = ctx.ReadbackOffscreenRgba(); // top-down, 4 bytes per pixel
// Pipe rgba into PNG encoder / image library of choice.
The offscreen path reuses all existing pipelines, MSAA slots, sync objects, and vertex ring buffers. Only the swapchain acquire/present is replaced by vkCmdCopyImageToBuffer into a host-visible staging buffer.
Runtime requirements (native)
At runtime you need the Vulkan loader plus an ICD (driver). Nothing else: no X11 / Wayland, no SDL native, no DirectX.
- Windows:
vulkan-1.dll(shipped with any modern GPU driver; also installable via the Vulkan SDK). - Linux:
libvulkan.so.1+ an ICD. Options in increasing order of portability:- GPU driver (Mesa
radv/intel_anv/ NVIDIA proprietary) — fastest. - Mesa
lavapipe/llvmpipe— software rasterizer. 5–20× slower but fully headless. Apt:mesa-vulkan-drivers. - Google SwiftShader — alternative software ICD.
- GPU driver (Mesa
- macOS / iOS: MoltenVK (Vulkan on Metal). Untested for offscreen here but no reason it shouldn't work.
SDL3-CS remains a package reference because the on-screen path uses it. Its P/Invokes are lazy — libSDL3.so / SDL3.dll is never loaded if SdlVulkanWindow is not instantiated, so the offscreen path has no SDL runtime dependency.
CI setup
On a fresh Ubuntu runner (GitHub Actions ubuntu-latest, Azure Pipelines, GitLab):
- run: sudo apt-get update && sudo apt-get install -y libvulkan1 mesa-vulkan-drivers vulkan-tools
- run: dotnet test
vulkan-tools is optional but gives you vulkaninfo --summary for sanity-checking which ICD the runner loaded. For deterministic behaviour across runners, pin to lavapipe:
- run: echo "VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json" >> $GITHUB_ENV
Containers: add the same two packages to your image. The offscreen path doesn't require a tty, display variable, or privileged mode.
Dependencies
- DIR.Lib — Rendering primitives + FreeType glyph rasterization
- SDL3-CS — SDL3 bindings
- Vortice.Vulkan — Vulkan bindings
- Vortice.ShaderCompiler — GLSL to SPIR-V
License
MIT
Rationale: Why SDL3 + Vortice.Vulkan
This library exists because the TianWen project needed a path to HDR display output (HDR10, scRGB, wide color gamut) that its previous Silk.NET + OpenGL stack could not deliver. The investigation below documents the alternatives considered and why SDL3 (via edwardgushchin/SDL3-CS) + Vortice.Vulkan won. This is decision rationale, not documentation of current features — check the types list above for what the library actually does today.
Why OpenGL was a dead end for HDR
- GPU vendors (NVIDIA, AMD) block 10-bit and floating-point pixel formats for OpenGL in windowed mode.
- The Windows HDR compositor (DWM) requires a DXGI swapchain, which only DirectX can drive natively.
- GLFW has no HDR support — glfw issue #890 open since 2016, never implemented.
- GLFW 3.4 (Feb 2024) shipped without it; a proposed
GLFW_FLOAT_PIXEL_TYPEpatch was never merged. - Silk.NET's
WindowHintBoolends atSrgbCapable/DoubleBuffer— no float pixel type or HDR color space.
Why Vulkan
Vulkan supports HDR output via VK_EXT_swapchain_colorspace + HDR10 surface formats.
| Platform | OpenGL | Vulkan | HDR possible? |
|---|---|---|---|
| Windows | Native | Native | Yes (Vulkan HDR swapchain) |
| Linux | Native | Native | Yes (if compositor supports) |
| macOS | Deprecated (frozen at 4.1) | MoltenVK | No (Metal HDR needs separate path) |
| Android | OpenGL ES | Native | Yes (Android 10+) |
| iOS | OpenGL ES (deprecated) | MoltenVK | No (same as macOS) |
| Web/WASM | WebGL | No | No |
Shader migration effort: low. GLSL shaders compile to SPIR-V with minimal mechanical
changes (#version 330 core to #version 450, uniforms packed into UBOs, explicit
layout(binding=N), build-time compile via glslc / glslangValidator or runtime
via Vortice.ShaderCompiler). Shader math (MTF stretch, Hermite soft-knee, WCS
deprojection, histogram) stays identical.
API migration effort: high. The real work was replacing ~2000 lines of OpenGL API calls with swapchain setup, descriptor sets, pipeline objects, command buffers, and synchronization.
Silk.NET status at the time of the decision
- v2.23.0 (Jan 2026) — stable, quarterly maintenance releases.
- 3.0:
develop/3.0branch exists, tracking issue #209 open since June 2020 (5.5+ years). Complete rewrite of bindings generation, no release date, lead developer (Perksey) less active, WebGPU bindings planned. - Silk.NET's prior usage in TianWen was well-contained: 4 source files, 3 NuGet packages, AOT with trimmer warning suppressions.
- Verdict: not dead, but 3.0 had been in development for years; 2.x worked fine for OpenGL but was a dead end for Vulkan/HDR on any near-term horizon.
Known Silk.NET-side blockers
- macOS regression: Silk.NET 2.21+ cannot create GLFW Vulkan windows on macOS (#2440); 2.20 worked.
- MoltenVK not fully conformant: translates Vulkan to Metal, supports Vulkan 1.4 but some features missing; HDR swapchain extensions may not be implemented.
- Web target lost: Vulkan has no browser support (WebGPU would be the path forward).
Alternatives evaluated (March 2026)
Veldrid — avoid (dead project)
- Last commit: March 2024. Latest NuGet: v4.9.0 (Feb 2023). 159 open issues.
- Clean abstraction (Vulkan, D3D11, Metal, OpenGL) but author (mellinoe) has moved on.
- Targets .NET 6 / netstandard2.0, not .NET 10. No AOT testing. No HDR.
Avalonia + GPU interop — consider only if full UI rewrite desired
- 30K+ stars, extremely active. .NET 10 supported.
- Has
GpuInteropsample with Vulkan demo viaCompositionDrawingSurface. - Gives a proper UI framework (menus, panels, dialogs) — could replace hand-built text/panel rendering.
- But: GPU interop is low-level (manage your own Vulkan context inside a compositor callback). HDR depends on the SkiaSharp compositor pipeline (no HDR). Very high migration effort, only worth it if replacing the hand-built UI.
SDL3 (.NET bindings)
- SDL3 itself: 15K stars, actively developed, battle-tested.
- Three competing .NET bindings: ppy/SDL3-CS (osu! team, most production-tested), edwardgushchin/SDL3-CS, flibitijibibo/SDL3-CS.
- SDL3 has native Vulkan surface creation +
SDL_GPUabstraction (Vulkan/D3D12/Metal with automatic shader cross-compilation). - HDR output support at the windowing level.
- SDL3 + keep OpenGL: replaces only GLFW windowing/input. Medium effort. But HDR
is still blocked because SDL3's OpenGL renderer hardcodes
SDL_COLORSPACE_SRGB. - SDL3 + SDL_GPU: higher-level Vulkan-like API with shader translation. Medium-high effort.
Evergine Vulkan.NET — best raw Vulkan bindings, no ecosystem
- 284 stars. Source-generated from Vulkan headers (always up-to-date).
- Targets .NET 8+. Full HDR access via raw swapchain formats.
- Raw bindings only — no windowing, no VMA, no shader compiler. Very high migration effort; 5-10x more code than OpenGL for the same result.
Vortice.Vulkan — best raw Vulkan ecosystem (chosen)
- 371 stars (Vulkan), 1.1K stars (Windows/D3D). Last commit: Feb 2026. Only 2 open issues.
- Explicitly targets net9.0 + net10.0. Pure managed C# bindings (
delegate* unmanagedfunction pointers, no P/Invoke).IsAotCompatible = true. - Bundles VMA (Vulkan Memory Allocator), SPIRV-Cross, and shaderc as companion packages.
- Caveat: single maintainer (bus factor of 1).
WebGPU via wgpu-native — future option, not ready
- wgpu-native: 1.2K stars. Translates to Vulkan/D3D12/Metal.
- .NET bindings immature (Evergine WebGPU.NET Nov 2025, WebGPUSharp 14 stars).
- Shader language is WGSL (GLSL would need porting). HDR not yet in WebGPU spec.
- Revisit when .NET bindings mature.
Why Vortice.Vulkan + edwardgushchin/SDL3-CS
edwardgushchin/SDL3-CS uses LibraryImport (source-generated, AOT-safe) — preferred
over ppy/SDL3-CS which uses old DllImport. SDL3-CS.Native NuGet ships desktop
natives; Android works but needs manual lib bundling.
| Platform | Vulkan | SDL3 native | AOT | HDR |
|---|---|---|---|---|
| Windows x64 | Native | NuGet | Yes | Yes (Vulkan HDR swapchain) |
| Windows ARM64 | Native | NuGet | Yes | Yes |
| Linux x64 | Native (Mesa/NVIDIA) | NuGet | Yes | Possible (Wayland + Vulkan) |
| Linux ARM64 | Native (Mesa) | NuGet | Yes | Limited |
| macOS x64 | MoltenVK | NuGet | Yes | MoltenVK limitations |
| macOS ARM64 | MoltenVK | NuGet | Yes | MoltenVK limitations |
| Android | Native | Manual bundling | Partial | Yes |
| iOS | MoltenVK (must bundle) | Not shipped | Yes | Limited |
SDL3 HDR support: SDL.window.HDR_enabled, SDL.window.SDR_white_level,
SDL.window.HDR_headroom display properties, plus PQ (ST 2084) and HLG transfer
characteristics. Combined with Vulkan VK_COLOR_SPACE_HDR10_ST2084_EXT swapchain,
full HDR output is achievable.
SDL3 Vulkan surface creation: SDL.VulkanLoadLibrary() auto-finds MoltenVK on macOS;
SDL.VulkanCreateSurface() returns a VkSurfaceKHR that pairs directly with
Vortice.Vulkan.
Could we have stayed on Silk.NET by fixing it upstream?
macOS Vulkan regression (#2440) — small PR, uncertain merge timeline
GLFW 3.4 changed Vulkan detection on macOS; glfwVulkanSupported() can't find the
Vulkan loader even though Silk.NET ships it (Silk.NET.Vulkan.Loader.Native). GLFW 3.4
added glfwInitVulkanLoader() which could solve this.
Possible fixes: call glfwInitVulkanLoader() with a custom vkGetInstanceProcAddr
before glfwInit(); set VK_ICD_FILENAMES at the bundled MoltenVK ICD; ensure the
Vulkan loader is on DYLD_LIBRARY_PATH.
Status: no PRs submitted, zero maintainer engagement on the issue. Silk.NET 2.x is in maintenance mode (14-month gap between 2.22 and 2.23), team focused on 3.0. Trivial PRs merge in 0-11 days; no evidence of substantive external feature PRs merging recently.
HDR - not feasible within Silk.NET's GLFW-based windowing
- GLFW has no API for HDR pixel formats, transfer functions, or color spaces.
- GLFW's own HDR issue (#890) open since 2016.
- Silk.NET's Vulkan bindings already cover all HDR swapchain extensions — the blocker is purely windowing.
- Would require replacing GLFW with SDL3 as windowing backend (huge change) or platform-specific code.
| Path | macOS fix | HDR | Effort | Risk |
|---|---|---|---|---|
| Fix Silk.NET upstream | Small PR, may wait months | Blocked by GLFW | Low for macOS, impossible for HDR | PR rot |
| Vortice.Vulkan + SDL3-CS | SDL3 auto-detects MoltenVK | Full HDR built into SDL3 | High (rewrite renderer) | Two active projects |
Comparison matrix
| Option | Maintenance | Vulkan | HDR | AOT | Migration | Shaders kept? |
|---|---|---|---|---|---|---|
| Silk.NET 2.x (stay) | Moderate | Via 3.0 someday | No | Yes | None | Yes |
| Silk.NET 2.x + macOS PR | Moderate | Yes (with fix) | No | Yes | None | Yes |
| SDL3 + OpenGL | Excellent | Surface only | No | Yes | Medium | Yes |
| SDL3 + SDL_GPU | Excellent | Under the hood | Possible | Yes | Medium-high | Rewrite to SDL_GPU |
| Vortice.Vulkan + SDL3 (chosen) | Good | Full | Yes | Yes | Very high | GLSL to SPIR-V |
| Evergine Vulkan.NET + SDL3 | Excellent | Full | Yes | Yes | Very high | GLSL to SPIR-V |
| Avalonia + Vulkan interop | Excellent | Yes (interop) | No | Improving | Very high | Rewrite |
| WebGPU/wgpu | Weak (.NET) | Under the hood | Not yet | Possible | High | GLSL to WGSL |
SDL3 + OpenGL HDR was corrected to No during evaluation: SDL3's OpenGL renderer
hardcodes SDL_COLORSPACE_SRGB as the only accepted output. No float pixel formats,
no scRGB, no HDR10 via OpenGL on any platform.
What to watch
- SDL3_GPU maturity — could simplify Vulkan over time.
- WebGPU .NET bindings — if they mature, a future browser target becomes possible.
- Silk.NET 3.0 — if it ever ships with working Vulkan + a non-GLFW windowing path, the comparison may change.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DIR.Lib (>= 2.4.531)
- SDL3-CS (>= 3.5.0-preview.20260213-150035)
- Vortice.ShaderCompiler (>= 1.9.0)
- Vortice.Vulkan (>= 3.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.4.431 | 35 | 4/25/2026 |
| 3.4.421 | 252 | 4/21/2026 |
| 3.3.411 | 28 | 4/21/2026 |
| 3.2.381 | 53 | 4/20/2026 |
| 3.1.371 | 122 | 4/16/2026 |
| 3.0.351 | 35 | 4/16/2026 |
| 3.0.341 | 37 | 4/15/2026 |
| 1.8.331 | 30 | 4/14/2026 |
| 1.8.311 | 36 | 4/14/2026 |
| 1.8.301 | 29 | 4/14/2026 |
| 1.8.291 | 32 | 4/13/2026 |
| 1.7.281 | 97 | 4/7/2026 |
| 1.6.271 | 37 | 4/7/2026 |
| 1.6.261 | 197 | 4/1/2026 |
| 1.6.251 | 35 | 4/1/2026 |
| 1.6.242 | 28 | 3/31/2026 |
| 1.6.231 | 29 | 3/31/2026 |
| 1.6.221 | 27 | 3/31/2026 |
| 1.6.211 | 30 | 3/31/2026 |
| 1.6.201 | 34 | 3/31/2026 |