Skip to content

Backends ​

php-vio supports multiple GPU backends. Each backend implements the same vtable interface, so your rendering code works unchanged across platforms.

Selecting a Backend ​

php
// Auto-select best available (default)
$ctx = vio_create("auto", ["width" => 800, "height" => 600]);

// Explicit selection
$ctx = vio_create("opengl", [...]);
$ctx = vio_create("vulkan", [...]);
$ctx = vio_create("metal", [...]);
$ctx = vio_create("d3d11", [...]);   // Windows only
$ctx = vio_create("d3d12", [...]);   // Windows only
$ctx = vio_create("null", [...]);    // No-op backend for testing

Auto-selection is platform-specific:

PlatformPriority
macOSMetal > OpenGL
WindowsD3D12 > D3D11 > Vulkan > OpenGL
LinuxVulkan > OpenGL

"auto" skips a backend that reports VIO_FEATURE_3D_PIPELINE = 0 when a later candidate has one, ; on Linux machines without a Vulkan driver it resolves to OpenGL. "null" is never auto-selected. Override globally with the vio.default_backend INI setting.

With vio_create("auto", ["prefer" => "performance" | "quality" | "compat", "require" => [VIO_FEATURE_*, …]]) the fixed priority list is replaced by a ranking of each backend's preferred adapter (vendor profile, discrete before integrated, software rasterizers last, required features) – see vio_rank_backends(). "benchmark" => true measures the top candidates once and caches the result (vio_benchmark_backends()). vio_backend_info()["selected_by"] tells how a context was chosen.

On macOS, Vulkan (via MoltenVK) is supported but opt-in – you must request it explicitly.

OpenGL (3.0 – 4.6) ​

The most complete backend: every feature path exists here first.

PropertyValue
APIOpenGL, negotiated 4.6 → 3.0, core profile from 3.2 (vio_gl_info() shows what you got)
LoaderGLAD (vendored)
PlatformsmacOS, Linux, Windows
Headless✅ via a hidden window

OpenGL is the fallback on every platform. Compute, storage images and vertex-stage storage need a 4.3+ context (never on macOS, where Apple's GL stops at 4.1); the feature ladder lists which flag needs which core version or extension.

TIP

On macOS, OpenGL is deprecated by Apple but still functional at version 4.1. For production macOS apps, consider Metal.

Vulkan ​

Modern, low-overhead GPU API with explicit resource management.

PropertyValue
APIVulkan 1.3 (or 1.2 + dynamic rendering + synchronization2)
MemoryVulkan Memory Allocator (VMA)
PlatformsLinux, Windows, macOS (MoltenVK)
Headless✅

Vulkan 1.3 – or 1.2 with VK_KHR_dynamic_rendering and VK_KHR_synchronization2 – is required; a device without them is not chosen. The 3D pipeline compiles GLSL → SPIR-V → Vulkan GLSL (SPIRV-Cross) → SPIR-V and follows the D3D conventions (render-target row 0 = top, depth 0..1). vsync => false selects the IMMEDIATE present mode (MAILBOX → FIFO fallback).

macOS Setup (MoltenVK) ​

Vulkan on macOS requires MoltenVK as a translation layer:

bash
brew install molten-vk

# Set environment variables
export VK_DRIVER_FILES=/usr/local/etc/vulkan/icd.d/MoltenVK_icd.json
export DYLD_LIBRARY_PATH=/usr/local/lib

WARNING

macOS System Integrity Protection (SIP) strips DYLD_LIBRARY_PATH from child processes. This means Vulkan may not work when PHP is launched from certain contexts (e.g., IDE terminals). Run directly from a terminal session.

Metal ​

Apple's native GPU API. Best performance on macOS.

PropertyValue
APIMetal
LanguageObjective-C with ARC
PlatformsmacOS only
Headless✅

Metal is compiled with Objective-C (vio_metal.m) and uses CAMetalLayer for presentation. It is only available when built with --with-metal.

Metal 2D Pipeline ​

Since v1.4.0, Metal has a complete native 2D rendering pipeline:

  • MSL shaders for shapes (color-only) and sprites (textured)
  • Font atlas support via R8Unorm textures with swizzle (1,1,1,R)
  • Dynamic vertex buffer growth
  • Scissor clipping with HiDPI scaling
  • Pixel readback via vio_read_pixels() and vio_save_screenshot()

Performance ​

examples/bench_backends.php draws the same five scenes on every backend the build can open: 1280x720, headless, vsync off, 600 frames after 60 warm-up frames. The Mac tables give the frame time from vio_begin() to the return of vio_end() in microseconds, as median / 99th percentile. Measured with php-vio 2.44.1 and PHP 8.5.

Apple M5 (macOS 27.2)

SceneMetalOpenGL 4.1
2D: 500 rects66 / 188142 / 258
2D: 200 rects + 200 rounded rects + 50 texts185 / 211284 / 325
2D: 1000 rects + 100 texts277 / 296468 / 593
3D: 1000 draws, 2 uniforms each231 / 249616 / 675
3D: 10 000 instances, 1 draw130 / 146113 / 189

MacBook Pro, Intel Core i9-9880H (macOS 26.7) — Metal on either GPU (VIO_METAL_ADAPTER); OpenGL runs on the integrated GPU.

SceneMetal, Radeon Pro 5500MMetal, UHD 630OpenGL 4.1, UHD 630
2D: 500 rects158 / 286279 / 439441 / 1145
2D: 200 rects + 200 rounded rects + 50 texts542 / 706574 / 749878 / 1542
2D: 1000 rects + 100 texts836 / 1165937 / 1262666 / 854
3D: 1000 draws, 2 uniforms each574 / 800703 / 8771194 / 1496
3D: 10 000 instances, 1 draw170 / 273743 / 8421290 / 1429

Windows 11, NVIDIA GeForce RTX 2080 — here the table gives the time to issue the frame (vio_begin() to vio_draw_2d()), median in microseconds. Headless Vulkan and OpenGL contexts copy every presented frame back to the host, which makes their vio_end() take longer than on Direct3D, so the frame time would not compare the backends.

SceneDirect3D 12Direct3D 11Vulkan 1.3OpenGL 4.6
2D: 500 rects139126180672
2D: 200 rects + 200 rounded rects + 50 texts491453669941
2D: 1000 rects + 100 texts634601825986
3D: 1000 draws, 2 uniforms each83143411461028
3D: 10 000 instances, 1 draw4412312292
On both Macs Metal is the faster backend in most scenes and has the steadier frame times; OpenGL is ahead in two cells (10 000 instances on the M5 by the median, the text-heavy 2D scene on the Intel Mac). On the RTX 2080 Direct3D 11 issues a frame fastest in four of the five scenes and Direct3D 12 when one draw covers 10 000 instances; Vulkan and OpenGL spend more CPU time per frame. These numbers are CPU-side times of small scenes, each from one run on a desktop machine: they compare the cost of issuing draws, not GPU throughput. Run the script on your own machine before choosing a backend:
bash
php -d extension=vio examples/bench_backends.php            # every backend
php -d extension=vio examples/bench_backends.php metal,opengl 600 --json=bench.json

Direct3D 11 ​

Immediate-mode DirectX backend. Broad hardware compatibility on Windows.

PropertyValue
APIDirect3D 11 (Feature Level 11.0 / 11.1)
Shader Model5.0
PlatformsWindows only
Headless✅ via WARP software renderer

D3D11 uses an immediate-mode rendering model – draw commands are executed directly through ID3D11DeviceContext. This makes it simpler than D3D12 while still providing good performance. In headless mode, the backend automatically selects the WARP software renderer (Windows Advanced Rasterization Platform).

Shader Pipeline ​

GLSL shaders are automatically compiled through a multi-stage pipeline:

GLSL → SPIR-V (glslang) → HLSL (SPIRV-Cross) → DXBC (D3DCompile)

You write standard GLSL – the backend handles the rest. The transpiled HLSL targets Shader Model 5.0 (vs_5_0, ps_5_0).

Build Flags ​

cmd
configure --enable-vio --with-glfw=C:\deps\glfw --with-d3d11

Required libraries: d3d11.lib, dxgi.lib, d3dcompiler.lib, dxguid.lib.

TIP

D3D11 is a good choice for Windows applications that need to support older hardware or Windows 7/8.

Direct3D 12 ​

Modern, low-level DirectX backend with explicit resource management.

PropertyValue
APIDirect3D 12
Shader Model5.1 (FXC); 6.x with DXC via vio_create(['shader_model' => 6])
PlatformsWindows 10+ only
Headless✅ via WARP software renderer

D3D12 is the highest-priority backend on Windows. It uses explicit command lists, fence-based GPU synchronization, and a double-buffered swapchain with per-frame command allocators. This gives the driver less overhead and enables better GPU utilization.

Key Differences from D3D11 ​

AspectD3D11D3D12
Rendering modelImmediateCommand list recording
SynchronizationImplicitExplicit (fence-based)
Buffer alignment16-byte (constant buffers)256-byte (constant buffers)
Pipeline stateSeparate state objectsMonolithic PSO
Root signatureN/AShared across pipelines
Min. Windows710

Shader Pipeline ​

Same multi-stage pipeline as D3D11, but targets Shader Model 5.1 – or, with vio_create(['shader_model' => 6]) and dxcompiler.dll / dxil.dll, the highest Shader Model 6.x the device and DXC accept (DXIL). Ray tracing, mesh shaders, work graphs and several shader features need Shader Model 6; work graphs usually also need the D3D12 Agility SDK ('agility_sdk' => $dir). vio_swapchain_info() reports the shader model and the Agility SDK in use.

GLSL → SPIR-V (glslang) → HLSL (SPIRV-Cross) → DXBC (D3DCompile)

Build Flags ​

cmd
configure --enable-vio --with-glfw=C:\deps\glfw --with-d3d12

Required libraries: d3d12.lib, dxgi.lib, d3dcompiler.lib, dxguid.lib.

TIP

D3D12 is auto-selected as the preferred backend on Windows. Use "d3d11" explicitly if you need broader hardware support.

Null Backend ​

A no-op backend that accepts all calls but produces no output. Useful for:

  • Unit testing without GPU access
  • CI environments
  • Benchmarking PHP-side logic
php
$ctx = vio_create("null", ["width" => 64, "height" => 64]);

Querying Available Backends ​

php
// Number of registered backends
$count = vio_backend_count();

// List all backend names
$names = vio_backends();  // e.g. ["opengl", "vulkan", "metal", "null"]

// Get active backend name
$active = vio_backend_name($ctx);  // e.g. "opengl"

Backend Feature Matrix ​

Source of truth: each backend's supports_feature(); tests/core/074_backend_capability_matrix.phpt pins it. Query at runtime with vio_supports_feature() and vio_feature_info() (native or emulated). Many flags also depend on the device and driver – the table shows what a backend can provide, not what every GPU has.

FeatureOpenGLD3D11D3D12VulkanMetal
3D pipeline, instancing, native 2D batch✅✅✅✅✅
Render targets: HDR / depth-only / MSAA / cube / MRT (up to 8)✅✅✅✅✅ (MRT untested)
Layered targets, VIO_RT_ALL_LAYERS, multiple viewports✅✅✅✅✅
Depth of a colour target, raw readback✅✅✅✅✅ (untested)
Render targets as storage images❌❌✅✅❌
Compute, storage images, async compute✅ (GL ≥ 4.3)✅✅✅✅
Vertex- and fragment-stage storage✅ (GL ≥ 4.3)✅✅✅✅
Geometry shaders✅ (GL ≥ 3.2)✅✅✅✅ emulated (compute)
Tessellation✅ (GL ≥ 4.0)✅✅✅✅ (compute-based)
Multiview✅✅ emulated (instancing)✅✅✅ emulated (instancing)
Stencil, texture arrays, BC compression, KTX2✅✅✅✅✅
ASTC textureswith KHR_texture_compression_astc_ldr❌❌with textureCompressionASTC_LDR✅ (Apple GPUs)
Indirect draws✅ (GL ≥ 4.0)✅✅✅✅
Bundlesreplay✅ native✅ native✅ nativereplay
GPU timestamps✅ (GL ≥ 3.3)✅✅✅✅
On-disk shader cache✅ (GL ≥ 4.1)✅✅✅✅
Frame latency (waitable swapchain)❌✅✅❌✅
HDR10 output❌✅✅✅✅ (EDR displays)
Subgroups / quad ops✅❌✅ (SM 6)✅✅
Barycentrics, float16✅❌✅✅✅
64-bit atomics❌❌✅ (SM 6.6)✅❌
Variable rate shading (rate / per primitive / image)❌❌✅✅❌ (rate maps instead)
Bindless textures❌❌✅✅✅
Mesh / task shaders❌❌✅ (SM 6.5)✅✅ (Metal 3)
Ray queries❌❌✅ (DXR 1.1)✅✅
Ray tracing pipelines❌❌✅ (DXR 1.0)✅❌
Shader execution reordering, opacity micromaps❌❌✅ (DXR 1.2)✅❌
Sampler feedback (GLSL path / hardware)✅ / ❌✅ / ❌✅ / ✅✅ / ❌✅ / ❌
Cooperative matrices❌❌❌✅✅
Work graphs❌❌✅ (SM 6.8)❌❌
Long vectors❌❌✅ (SM 6.9, HLSL kernels)✅❌
Rasterization rate maps––––✅
Portable upscaling✅✅✅✅✅ (+ MetalFX spatial)
Native upscalers (FSR 3.1, DLSS)❌❌✅✅❌
vio_read_pixels(), recording / streaming capture✅✅✅✅✅

The null backend reports no GPU features.

Row order of render targets differs (OpenGL row 0 = bottom, D3D/Metal/Vulkan row 0 = top) – see Render Targets → Orientation.

Released under the MIT License.