renderer-vulkan
Garnet Vulkan renderer
require "garnet-renderer-vulkan" provides Garnet::Vulkan::Renderer over the same generic graphics values as OpenGL and Metal. The renderer depends on the general-purpose Vulkan shard, using its typed devices, descriptors, resources, command buffers and queues. No C++ bridge is required.
renderer = Garnet::Vulkan::Renderer.new
begin
output = renderer.render(draws, Garnet::Graphics::RenderTarget.new(256, 256))
native = output.to_gpu(renderer)
pixels = renderer.readback(output) # explicit readback only
ensure
renderer.close
end
The complete window example uses the separate GLFW Vulkan host. Offscreen use needs no window library.
The current Garnet profile implements indexed XY/UV triangles, rotated atlas regions, copied transforms, tint, nearest/linear clamp sampling, RGBA8 sRGB/linear inputs and straight/premultiplied alpha. Outputs are immutable versions of linear premultiplied RGBA8 textures with top-left coordinates. These constraints and the built-in shaders belong to this renderer, not the Vulkan API shard.
Texture and mesh preparation caches weakly reference generic source identities. Cache hits avoid opening IO; misses decode/upload through transient staging into device resources. Retained native outputs survive evict; collect reclaims expired cache entries. present also sweeps automatically every auto_collect_interval (two seconds by default; nil disables it), so removing content from a scene is enough to release its GPU copies once the GC has reclaimed the source. Explicit close invalidates renderer outputs and drops its native references. The Vulkan shard owns resource and submission lifetimes; retained native wrappers can keep allocations alive beyond renderer shutdown. Surface and swapchain teardown remains explicit so the host can safely destroy its window. GPU-native textures are reused on their producing renderer; foreign-device imports are rejected. Memory-backed sources retain their bytes by design; file-backed sources do not retain decoded data.
The renderer is confined to its owner thread. Upload, rendering, readback and presentation currently wait for completion. Asynchronous frames, deferred retirement, custom material pipelines and render-thread orchestration remain future work. The general-purpose Vulkan shard leaves these decisions to its callers.
Requires Crystal 1.19.1+ and a Vulkan loader/driver. The 2D and 3D shaders are the SPIR-V that garnet shaders build generates into graphics from one Slang source per program, so building needs no shader compiler. scripts/check-vulkan gpu, parity and build verify resources, compare all shared fixture channels against OpenGL within two byte levels, and build the window example. Run it with GARNET_EXAMPLE_FRAMES=120 "${TMPDIR:-/tmp}/garnet-renderer-vulkan-example". Current hardware validation is macOS/MoltenVK; other OS, mobile and console targets are not yet validated.
Mixed composition
This renderer also accepts Graphics::Drawing, including vector/mesh/image content, group opacity, alpha/luminance/inverted masks and viewport outputs. See scene, vector, and the shared gallery. Mask sampling and composition remain native GPU operations.
Gradient materials use local geometry coordinates and native fragment evaluation on this backend. Linear and centered radial gradients support pad/repeat/reflect spread and up to 16 stops. See the shared paint contract for interpolation and limits.
Image-pattern materials support per-axis repeat/reflect/pad/transparent addressing and local paint transforms. Native shaders honor atlas rotation/trim and filter premultiplied texels without atlas-neighbor bleed. Captured GPU textures are valid pattern sources; see the image-pattern contract.
The shared composition pipeline also supports two-circle gradients, Gaussian blur, color-matrix effect chains and all sixteen isolated blend modes. See the graphics effect contract for ordering, color space and limits. These are native GPU passes; optional Clipper2 geometry arrives as ordinary meshes.
renderer-vulkan
- 0
- 0
- 0
- 2
- 6
- 14 minutes ago
- November 30, 2026
MIT License
Wed, 02 Dec 2026 12:03:55 GMT