Search by

jovian / venusian-sdl3

projectsaturnstudios

The 'sdl3' stager and GPU driver for Venusian topside: staged windows, and SDL's GPU API as a device, on SDL 3 through ext-sdl3, on macOS and Linux.

v0.11.0 2026-11-08 15:32 UTC

This package is auto-updated.

Last update: 2026-12-03 14:57:09 UTC


README

The sdl3 stager and GPU driver for Venusian topside: staged windows, and SDL's GPU API as a device, on SDL 3 through ext-sdl3, on macOS and Linux.

Requirements

  • PHP 8.4, ext-sdl3 ^0.11.0 and SDL 3.
  • The test suite also needs ext-posi, and the package does not. ext-posi writes the memory a GPU test hands over as an address and reads the pixels read() answers; it is in require-dev and suggest, never require. A test that needs it is skipped where it is not loaded.

Install

composer require jovian/venusian-sdl3

The provider is discovered through extra.venusian.providers and merges config/sdl3.php.

Configuration

'surface' => env('SDL3_SURFACE', 'surface'),

The kind of surface a window is made with, fixed when the window is created: surface, SDL's window surface, shows frames from memory; metal lends the window's CAMetalLayer to the metal GPU driver and needs ext-metal; sdl3 lends the SDL_Window to the sdl3 GPU driver, or shows frames from memory as surface does, one or the other for a window; opengl lends SDL's OpenGL context (CGLContextObj on macOS, EGLContext on Linux) to the opengl GPU driver, shows no memory and needs ext-opengl; vulkan lends the window's surface create-info (VkMetalSurfaceCreateInfoEXT on macOS, X11 or Wayland on Linux) to the vulkan GPU driver, shows no memory and needs ext-vulkan. Publish the file with the sdl3-config tag.

Usage

With WINDOW_DRIVER=sdl3, topside's Windows opens SDL windows:

use Surface\Windows\Windows;

$window = Windows::open('Orrery', 1024, 768)->show();
$window->setShown($list);   // a draw list, drawn by the configured engine

A window opens hidden until show(). The surface kind shows premultiplied BGRA or RGBA frames: it blits the rects that changed from the frame's memory to the window's surface, and SDL converts them to that surface's format.

GPU driver

With GPU_DRIVER=sdl3, topside's Gpu gives one SDL GPU device for the process:

use Surface\Gpu\Gpu;
use Surface\Gpu\PassSpec;
use Surface\Gpu\TextureSpec;
use Surface\NutsAndBolts\Color;
use Surface\NutsAndBolts\FormatSpec;
use Surface\Contracts\Gpu\TextureUse;
use Surface\Contracts\Gpu\TextureFormat;

$device = Gpu::device();
$texture = $device->texture(new TextureSpec(320, 240, TextureFormat::RGBA8, [TextureUse::TARGET]));

$commands = $device->commands();
$commands->render(new PassSpec($texture, clear: new Color(1.0, 0.5, 0.0, 1.0)))->end();
$commands->submit();

$memory = $device->read($texture, FormatSpec::rgba8Premultiplied());   // a PixelMemory, top row first

A shader is handed over in the language SDL takes on the platform: Metal's shading language, named msl, on macOS, and SPIR-V, named spirv, on Linux, with its entry point.

What a shader binds In msl In spirv
texture slot n, with its sampler [[texture(n)]] and [[sampler(n)]] set 0 (vertex) or 2 (fragment), binding n
uniform-block slot n [[buffer(n)]] set 1 (vertex) or 3 (fragment), binding n
vertex buffer n [[buffer(14 + n)]] its vertex input

Gpu::target($window) answers the target for an SDL_Window the device claims, the same one for the same window while it lives. Its image has the window's size in pixels, and present() copies what fits.

Earlier code

The package's earlier engine, drawer and stager are kept in deprecated/, deprecated2/ and deprecated3/, and their tests in deprecated3-tests/. None is autoloaded or run.

Security

See SECURITY.md.

License

MIT. See LICENSE.