The C font selection code read font tables only from sfnt files, so
variable fonts in WOFF/WOFF2 files had no variable data, causing wrong
faces to be selected, for example, for FiraCode-VF.woff2.
Read WOFF tables using zlib and WOFF2 tables using brotli, decompressing
only the prefix of the stream containing the needed tables, in fixed
size chunks so that memory use does not depend on possibly corrupt
offsets. kitty now links against libbrotlidec on platforms other than
macOS.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VBMI2 was only used by the AVX-512 UTF-8 decoder, which has been
removed, so CPUs with AVX-512 F, BW and VL but not VBMI2, such as
Skylake-X, can now use the AVX-512 implementations of the remaining
functions.
Increase the minimum supported macOS version from 12 to 14. Remove the
CVDisplayLink fallback, using only CADisplayLink. Since CADisplayLink fires
on the main thread, the display link locking and cross thread dispatch are no
longer needed. Also remove other code paths that were only used on macOS
versions older than 14.
On macOS, kitty now tries to render using Metal, falling back to OpenGL,
see the gpu_driver option. The driver has not yet been compiled or run
on macOS, it was written on Linux and only syntax checked against stub
headers.
Shader targets of the form msl-NN (for MSL N.N) compile each program to
a single MSL source file containing the entry points for all stages,
compiled by the driver at runtime, for the built-in and custom shaders.
slangc ignores [[vk::binding]] for Metal, so the program metadata keeps
the kitty binding slots and passes the argument table indices assigned
by slangc as native names. The push constant block, emitted as an
ordinary constant buffer, is recognized by the name of its type. As
Metal has y=1 at the top in NDC, the generated code is fixed up to
negate the y coordinate of the position output by vertex entry points.
Layouts that would differ because bool is a single byte in MSL are
rejected. The MSL is validated with the Metal compiler when available.
The MSL shaders are temporarily built on all platforms, for development.
The driver follows the design of the Vulkan driver: command buffers with
serials and at most three in flight, copy on write of buffer storage the
GPU may still use, private textures uploaded with blits from staging
memory, pipeline variants created when first used and a CAMetalLayer
per window. Vertex inputs whose offset or stride is not a multiple of
four bytes, as Metal requires, are repacked into a cached copy.
On Linux and BSD, kitty now renders using Vulkan 1.3, falling back to
OpenGL if Vulkan is not available, see the gpu_driver option. The driver
is built when the Vulkan headers are present, libvulkan is loaded at
runtime.
The driver implements the immediate mode GPU API on top of a small ring
of command buffers, submitted when windows are presented or when the CPU
needs results, such as when reading back pixels. It uses dynamic
rendering, synchronization2, push descriptors for textures and uniform
buffers and push constants for the uniform parameters of pipelines.
Buffers are host visible and written only by the CPU, with copy on write
of storage still in use by the GPU, which preserves the OpenGL semantics
the rest of kitty relies on without the CPU ever waiting for the GPU.
Pipelines have variants for each render target format, blend mode and
set of vertex input formats, created when first used. Vertex strides are
dynamic state.
Rendering is pixel identical to OpenGL in the screenshot comparisons,
with the validation layers reporting no errors.
Integer textures are now declared in the shaders with their actual
number of channels, as Vulkan requires the format of the image in the
SPIR-V to match the texture. Drivers that cannot determine the size of
uniform blocks, such as Vulkan without SPIR-V reflection, can now report
it as zero.
Each GPU driver now declares the shader target it consumes (glsl-140 for
the OpenGL driver), a fixed property available as soon as the driver is
loaded. setup.py compiles the built-in shaders for the targets of the
drivers it builds, into a directory per target, and custom shaders are
compiled at runtime for the target of the loaded driver. The GLSL_VERSION
constant is no longer exported to Python.
The program metadata passed to the C code is now generated from the
reflection data produced by slangc and is backend neutral: vertex input
locations, uniform names, uniform block sizes and array layouts, all
identified by their names in the Slang source. Block sizes are verified
against the driver. The only target specific part is a map from Slang
names to the identifiers in the compiled code, which the OpenGL driver
needs to look up parameters by name and which is passed to the driver
when creating a pipeline. The driver no longer needs to be queried for
uniform array layouts.
The debug config output now uses the name reported by the driver.
glfw is now a windowing only library. It no longer creates OpenGL
contexts and contains no GLX, EGL, NSGL or OSMesa code. Instead it
exposes native window handles, and the GPU driver creates surfaces that
render into them, owning everything needed to render and present, such
as OpenGL contexts or, in future, Vulkan swapchains.
The GPU driver API (now version 2) gains surfaces: creation from native
X11, Wayland and Cocoa windows, making current, resizing, presenting,
swap interval, handling native view changes and recreation (macOS) and
choosing the X11 visual before window creation. The OpenGL driver
implements them with GLX on X11, EGL on Wayland and NSGL on macOS, all
ported from glfw, loading every library at runtime.
glfw gains a GLFW_X11_VISUAL_ID window hint, a native surface changed
callback (used on macOS where the NSOpenGLContext must be updated) and
glfwWindowContentsPresented(), which on Wayland commits surface state
after a frame is presented. The OpenGL context API, hints and the
share parameter of glfwCreateWindow() are removed.
The macOS (NSGL) code is untested as it could not be built.
All OpenGL calls now live in gpu/opengl, which is built as kitty/opengl.so,
next to the glfw backends. glfw_init() is passed the path to the driver and
loads it. The driver is initialized once the first OpenGL context is
current. fast_data_types no longer links against libGL.
kitty/gpu.c contains the driver loader and the higher level helpers
(programs and their metadata, vertex array objects, viewport stack) that
were previously in kitty/gl.c, implemented on top of the driver API.
shaders.c and the rest of kitty use only the driver API.
Also remove the unused GL_* constants and the unused bind_program,
create_vao, etc. functions exported to Python.
Every snapshot is encrypted with AES-256-GCM using a random key, stored
in the login keychain under a random id. The name of every file is
authenticated, so files cannot be swapped. The key is deleted before the
snapshot whenever it is removed, so copies of the snapshot left on disk
or in backups cannot be read.
The keychain is never allowed to show any UI. If storing the key fails
nothing is saved, if reading it fails the snapshot is deleted, with the
error logged in both cases.
The key is generated, stored and read only in C, in mlocked memory that
is cleared when freed, via a new random_secret() and the Keychain
functions in cocoa_window.m.
Optimise the AVX 2 implementation reducing number of operations per block
and also add an AVX-512 implementation used when the CPU supports it at
runtime.