microscrap/vulkan

Vulkan Bindings for The PHP Vulkan Extension

Maintainers

Package info

github.com/microscrap/vulkan

Homepage

pkg:composer/microscrap/vulkan

Transparency log

Statistics

Installs: 4

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.7.1 2026-08-09 18:56 UTC

This package is not auto-updated.

Last update: 2026-08-10 01:18:03 UTC


README

Docs Latest Version on Packagist Tests PHP Version Require ext-vulkan Total Downloads License

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 readonly data objects (VkInstance, VkPhysicalDevice, VkDevice, VkQueue, VkSurface, VkSwapchain)
  • Enum layer for common VkResult / VkPhysicalDeviceType values (cases FULLY UPPERCASE; no class constants)
  • C-style error handling: no exceptions in src/; details via vkLastError()
  • 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: createInstanceVk::createInstance().
  • Helpers prefix with vk and capitalize: createInstancevkCreateInstance().
  • 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