microscrap / vulkan
Vulkan Bindings for The PHP Vulkan Extension
Requires
- php: ^8.3
- ext-vulkan: ^0.7.0
- microscrap/glfw: ^0.7.0
Requires (Dev)
- pestphp/pest: ^4
This package is not auto-updated.
Last update: 2026-08-10 01:18:03 UTC
README
Docs: ScrapyardIO ecosystem — microscrap/vulkan 0.7.x
PHP library that wraps the vulkan extension with global helpers, enums, and data objects. Every helper delegates to Microscrap\Bindings\Vulkan\Vk.
The package covers the entire extension surface (14 methods on Vulkan\Vk\Vk): instance/device lifecycle, queue selection, surface wrap/destroy, swapchain create/resize/destroy, and present-frame clear + optional menu/inner/accent rects. Window surfaces are created via microscrap/glfw (CLIENT_API = NO_API + glfwCreateWindowSurface).
Highlights
- Two calling styles — C-ish
vk*helpers (vkCreateInstance(...)) or static wrapper (Vk::createInstance(...)) - Opaque Vulkan handles wrapped in typed
final readonlydata objects (VkInstance,VkPhysicalDevice,VkDevice,VkQueue,VkSurface,VkSwapchain) - Enum layer for common
VkResult/VkPhysicalDeviceTypevalues (cases FULLY UPPERCASE; no class constants) - C-style error handling: no exceptions in
src/; details viavkLastError() - Coverage drift guard: a Pest test reflects the extension and fails if any extension method lacks a wrapper method or helper function
Requirements
- PHP 8.3+
- ext-vulkan ^0.7.0 — install from php-io-extensions/vulkan
- microscrap/glfw ^0.5.0 — for
vkCreateWindowSurface/ GLFW windowing peer - ext-glfw ^0.5.0 — required by microscrap/glfw
Installation
Confirm ext-vulkan (and ext-glfw if you need surfaces) are loaded:
php -m | grep -E 'vulkan|glfw'
composer require microscrap/vulkan
Composer autoloads src/Helpers/vk.php, registering the global vk* functions when the package is installed. Helpers are only defined if the name is not already taken (function_exists guard).
The two calling styles
C-ish — global functions with vk* names:
use Microscrap\Bindings\GLFW\Enums\ClientApi; use Microscrap\Bindings\GLFW\Enums\TrueFalse; use Microscrap\Bindings\GLFW\Enums\WindowHint; glfwInit(); glfwWindowHint(WindowHint::GLFW_CLIENT_API, ClientApi::GLFW_NO_API->value); $window = glfwCreateWindow(400, 600, 'vulkan'); $extensions = glfwGetRequiredInstanceExtensions(); $instance = vkCreateInstance($extensions, 'demo'); $created = vkCreateWindowSurface($instance, $window); $surface = $created['surface']; // ... enumerate devices, create device/queue/swapchain, presentFrame ... vkDestroySurface($instance, $surface); vkDestroyInstance($instance); glfwDestroyWindow($window); glfwTerminate();
OO-ish — static wrapper class, same behavior:
use Microscrap\Bindings\Vulkan\Vk; $instance = Vk::createInstance([], 'demo'); Vk::destroyInstance($instance);
Helpers never touch the extension directly; they delegate one-to-one to Vk, which is the only layer calling Vulkan\Vk\Vk. Both styles accept and return the same data objects (or the raw extension objects).
Name transforms
- Wrapper methods match the extension camelCase names:
createInstance→Vk::createInstance(). - Helpers prefix with
vkand capitalize:createInstance→vkCreateInstance(). - Convenience bridge (not on the extension):
Vk::createWindowSurface()/vkCreateWindowSurface()wraps glfw +wrapSurface.
Wrapper surface
| Method | Notes |
|---|---|
lastError |
Last Vulkan/loader error string |
createInstance / destroyInstance |
Instance lifecycle |
enumeratePhysicalDevices |
Physical devices with name/type/ids |
findGraphicsPresentQueue |
Queue family for graphics + present |
createDevice / destroyDevice |
Logical device |
getDeviceQueue |
Queue handle |
wrapSurface / destroySurface |
SurfaceKHR from fd |
createSwapchain / destroySwapchain / resizeSwapchain |
Presentable swapchain |
presentFrame |
Clear + optional UI rects |
Data objects live under Microscrap\Bindings\Vulkan\DataObjects. Enums live under Microscrap\Bindings\Vulkan\Enums.
License
MIT