phpolygon / php-vio
PHP extension for GPU rendering (OpenGL, Vulkan, Metal), audio, video recording, streaming, and input
Package info
Language:C
Type:php-ext
Ext name:ext-vio
pkg:composer/phpolygon/php-vio
Requires
- php: >=8.5
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 2.25.0
- 2.24.3
- 2.24.2
- 2.24.1
- 2.24.0
- 2.23.0
- 2.22.0
- 2.21.0
- 2.20.0
- 2.19.0
- 2.18.0
- 2.17.0
- 2.16.0
- 2.15.0
- 2.14.0
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.23.0
- 1.22.0
- 1.21.1
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.1
- 1.19.0
- 1.18.1
- 1.18.0
- 1.17.0
- 1.16.2
- 1.16.1
- 1.16.0
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.9
- 1.10.8
- 1.10.7
- 1.10.6
- 1.10.5
- 1.10.4
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.0
- 1.8.15
- 1.8.14
- 1.8.13
- 1.8.10
- 1.8.9
- 1.8.8
- 1.8.7
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.7.0
- 1.6.0
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.5
- 1.2.1
- 1.2.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feat/text-bitmap
- dev-fix/compute-async-params
- dev-fix/gl-s3tc-enums
- dev-fix/compute-buffer-bindings
- dev-feat/gap-phase5-vulkan-hdr
- dev-feat/gap-phase5-vulkan-texarray-vrs
- dev-feat/gap-phase5-vulkan-rt
- dev-feat/gap-phase5-vulkan-3d
- dev-feat/gap-phase5-shading-rate
- dev-feat/gap-phase5-texture-arrays
- dev-feat/gap-phase5-gpu-mipmaps
- dev-feat/gap-phase5-indirect-draw
- dev-feat/gap-phase5-shader-model-6
- dev-feat/gap-phase5-hdr-output
- dev-feat/gap-phase5-shader-cache
- dev-feat/gap-phase5-gpu-timestamps
- dev-feat/gap-phase5-uint16-indices
- dev-feat/gap-phase5-pso-state
- dev-feat/per-attachment-blend
- dev-fix/pending-texture-lifetime
- dev-feat/geometry-tessellation-stages
- dev-fix/opengl-spirv-uniform-names
- dev-fix/opengl-context-generation
- dev-feat/d3d-vulkan-gap-plan
- dev-feat/vertex-storage-buffers
- dev-feat/texture-3d
- dev-fix/window-fullscreen-exit
- dev-feat/cross-platform-thermal
- dev-feat/ios-support
- dev-fix/d3d12-clearvalue-noise
- dev-fix/d3d11-warm-offscreen
- dev-feat/vulkan-2d
- dev-dx11_dx12
This package is auto-updated.
Last update: 2026-09-11 10:34:50 UTC
README
A PHP extension that brings GPU rendering, audio, video recording, streaming, and input handling to PHP. Foundation layer for the PHPolygon game engine.
Features
- Multi-Backend GPU Rendering — Direct3D 12, Direct3D 11, Metal, Vulkan (MoltenVK), OpenGL 4.1
- 2D Batch Renderer — Rects, circles, lines, sprites, text (z-sorted, up to 4096 items)
- 3D Pipeline — Meshes, shaders, pipelines, textures, uniform/storage buffers
- Shader Toolchain — GLSL to SPIR-V compilation, reflection, cross-compilation
- Audio — Playback via miniaudio (MP3, WAV, FLAC)
- Video Recording — H.264 encoding via FFmpeg (with VideoToolbox HW acceleration)
- Network Streaming — RTMP and SRT via FFmpeg
- Input — Keyboard, mouse, and gamepad support via GLFW
- Headless Mode — Offscreen rendering for tests and visual regression testing
- Plugin System — Extensible output/input/filter plugins
- Cross-Platform — macOS, Linux, Windows
Gallery
Every image below is rendered headless by examples/gallery.php
(php -d extension=vio examples/gallery.php [backend]); the PNGs live in docs/gallery/.
They double as a smoke test of each feature path on a real backend.
Requirements
- PHP >= 8.5
All native libraries are optional — the extension compiles and runs without them, features are simply unavailable at runtime:
| Library | Feature | Build Flag |
|---|---|---|
| GLFW 3.4 | Windowing, input, gamepad | --with-glfw |
| glslang | GLSL to SPIR-V compilation | --with-glslang |
| SPIRV-Cross | Shader reflection & transpilation | --with-spirv-cross |
| Vulkan SDK | Vulkan backend | --with-vulkan |
| FFmpeg | Video recording & streaming | --with-ffmpeg |
| Metal (macOS framework) | Metal backend | --with-metal |
| Direct3D 11 (Windows SDK) | Direct3D 11 backend | --with-d3d11 (Windows, on by default) |
| Direct3D 12 (Windows SDK) | Direct3D 12 backend | --with-d3d12 (Windows, on by default) |
Installation
Via PIE (PHP Installer for Extensions)
pie install phpolygon/php-vio
Pre-built Binaries
Download platform-specific binaries from the Releases page. Available for:
- Linux x86_64 / ARM64
- macOS x86_64 (Intel) / ARM64 (Apple Silicon)
- Windows x64
From Source (macOS)
brew install glfw glslang spirv-cross ffmpeg
phpize
./configure --enable-vio --with-glfw --with-glslang --with-spirv-cross \
--with-vulkan --with-ffmpeg --with-metal
make -j$(sysctl -n hw.ncpu)
sudo make install
From Source (Linux)
# Ubuntu/Debian sudo apt install php-dev libglfw3-dev glslang-dev libvulkan-dev \ libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \ spirv-cross libspirv-cross-c-shared-dev phpize ./configure --enable-vio --with-glfw --with-glslang --with-spirv-cross \ --with-vulkan --with-ffmpeg make -j$(nproc) sudo make install
Windows
On Windows, no build toolchain is needed — PHP extensions are distributed as pre-compiled DLLs. Download the matching DLL from the Releases page (match your PHP version and thread-safety mode), then:
- Copy
php_vio.dllinto your PHPext\directory - Add
extension=vioto yourphp.ini - Restart PHP / your web server
All backends use conditional compilation (#ifdef HAVE_*), so builds without certain dependencies compile fine — those features are simply unavailable at runtime.
Quick Start
<?php // Create a window with OpenGL backend $ctx = vio_create("opengl", [ "width" => 800, "height" => 600, "title" => "Hello VIO", ]); while (!vio_should_close($ctx)) { vio_begin($ctx); vio_clear($ctx, 0.1, 0.1, 0.1); // 2D drawing vio_rect($ctx, 50, 50, 200, 100, ["color" => 0xFF0000FF]); vio_circle($ctx, 400, 300, 60, ["color" => 0x00FF00FF]); vio_draw_2d($ctx); vio_end($ctx); vio_poll_events($ctx); } vio_close($ctx); vio_destroy($ctx);
API Overview
71 functions across these categories:
| Category | Functions |
|---|---|
| Context | vio_create, vio_begin, vio_end, vio_clear, vio_close, vio_destroy |
| Input | vio_key_pressed, vio_mouse_position, vio_mouse_button, vio_on_key |
| 2D | vio_rect, vio_circle, vio_line, vio_sprite, vio_text, vio_draw_2d |
| 3D | vio_mesh, vio_shader, vio_pipeline, vio_bind_pipeline, vio_draw |
| Textures | vio_texture, vio_bind_texture, vio_texture_load_async |
| Fonts | vio_font, vio_text, vio_text_measure, vio_font_load_async |
| Buffers | vio_uniform_buffer, vio_update_buffer |
| Audio | vio_audio_load, vio_audio_play, vio_audio_pause, vio_audio_stop |
| Recording | vio_recorder, vio_recorder_capture, vio_recorder_stop |
| Streaming | vio_stream, vio_stream_push, vio_stream_stop |
| Headless | vio_read_pixels, vio_save_screenshot, vio_compare_images |
| Shaders | vio_shader_reflect, shader compilation via glslang |
| Plugins | vio_plugins, vio_plugin_info |
Full API documentation: see vio.stub.php
Backends
| Backend | Status | Platforms |
|---|---|---|
| Direct3D 12 | Stable | Windows only |
| Direct3D 11 | Stable | Windows only |
| Metal | Stable | macOS only |
| OpenGL 4.1 | Stable | macOS, Linux, Windows |
| Vulkan | Experimental | macOS (MoltenVK), Linux, Windows |
| Null | Stable | All (for unit testing) |
Backend auto-selection is platform-specific:
- Windows: Direct3D 12 → Direct3D 11 → Vulkan → OpenGL
- macOS: Metal → OpenGL (Vulkan via MoltenVK is opt-in, not auto)
- Linux: Vulkan → OpenGL
Null is never auto-selected; request it explicitly with vio_create("null") for headless tests. Override auto-selection per call (vio_create("d3d11")) or globally via the vio.default_backend INI setting.
Performance: Metal vs OpenGL
Benchmarked on Apple M2 Pro (macOS 26.4, 1280x720, VSync off). Measures draw + flush time only (excludes present/VSync wait).
| Scenario | Metal (median) | OpenGL (median) | Delta |
|---|---|---|---|
| 500 rects | 192 us | 179 us | +7% |
| 200 rects + 200 rounded rects + 50 text | 323 us | 313 us | +3% |
| 1000 rects + 100 text | 301 us | 374 us | -20% |
Tail latency (frame time consistency):
| Percentile | Metal | OpenGL |
|---|---|---|
| p95 | 306-601 us | 437-754 us |
| p99 | 375-674 us | 907-953 us |
Metal is slightly slower on simple scenes due to command encoding overhead, but 20% faster on heavy scenes (1000+ draw calls with text). More importantly, Metal delivers 30-40% better tail latency — fewer frame time spikes and more consistent rendering.
Testing
NO_INTERACTION=1 TEST_PHP_EXECUTABLE=$(which php) \ php run-tests.php -d extension=$PWD/modules/vio.so tests/
93 PHPT tests, grouped by topic under tests/ (core/, backends/, render3d/, render2d/, input/, window/, media/) — headless rendering with pixel verification, 2D/3D pipelines, shaders, compute, audio, input, and the per-backend capability matrix. run-tests.php recurses into the folders; pass a single folder to run one area.













