Commit graph

20058 commits

Author SHA1 Message Date
Kovid Goyal
c0a5e2cf37
Use an accurate title for the overlay showing startup errors
Errors during startup that are not caused by invalid config lines, such
as failing to listen on the remote control socket, were shown under the
title "Errors parsing configuration" with the heading "In final effective
configuration". The title now reflects whether the errors are config
parse errors, startup errors or both.
2026-11-18 08:26:43 +05:30
Kovid Goyal
df1fda1032
Wayland: Limit rendering to 120 FPS soon after a resize
For a second after a resize, render frames are not used, so that the
resized buffer is filled immediately. This meant that continuous output
was rendered as fast as possible, about 900 FPS, during that second.
Now only the first render after the resize is immediate, subsequent
renders are limited to 120 FPS, unless a render frame arrives sooner.
2026-11-18 08:26:43 +05:30
Kovid Goyal
87292a4862
Remove stale UNIX sockets when listening for remote control
If the socket file for --listen-on was left behind by a kitty instance
that was killed, binding to it failed, so remote control was disabled
and an error was shown over the program. Now, if no process is listening
on the socket, it is removed and binding is retried. A socket that a
process is listening on and files that are not sockets are never
removed, and the error shown includes the reason for the failure.
2026-11-18 08:26:43 +05:30
Kovid Goyal
d92e3beb00
Replace sync_to_monitor and repaint_delay with render_interval
The new render_interval option either syncs redraws to the monitor
(the default), optionally with a minimum interval between frames, or
redraws on a schedule with a minimum interval between frames. The
interval is now enforced per OS window, including when output is being
parsed, which the old repaint_delay was not.

On X11, render frames are now provided by the Present extension, with
libxcb-present loaded at runtime. Frames are requested lazily on X11,
since a pending NotifyMSC request delays buffer presentation by the GPU
driver under Xwayland. Xwayland completing requests early and failing to
report vertical blanks for long periods are handled. Without Present,
kitty falls back to blocking buffer swaps as before.

Render frames now only wake up the main loop when something is waiting
for them, so animations such as the eased cursor blink are no longer
sampled at the monitor refresh rate. On Wayland, frame callbacks are
also used when not syncing to the monitor, to stop rendering hidden
windows.

The removed options are converted to render_interval if it is not
specified anywhere, including in other config files and overrides,
otherwise they are ignored with a warning.

Also fix gen config failing on options whose type is a builtin.
2026-11-18 08:26:43 +05:30
Kovid Goyal
5f10981217
Fix CI failures from the SIMD UTF-8 decoder changes
The SIMD UTF-8 decoders read up to a vector past the end of their input,
which is fine for real callers that have slack after their data, but
test_utf8_decode_to_sentinel passed the Python buffer directly, so the
new long input test triggered heap-buffer-overflow reports under ASAN.
Copy the input into a padded buffer, as the other SIMD test helpers do.

Also fix clang-format violations and broken references to the removed
input_delay option in the changelog that failed the docs build.
2026-11-18 08:26:43 +05:30
Kovid Goyal
47ce69be22
Read variable font data from WOFF and WOFF2 files in font selection
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>
2026-11-18 08:26:43 +05:30
Kovid Goyal
04bce42d2f
ARM optimisations for new new UTF8 decoder 2026-11-18 08:26:43 +05:30
Kovid Goyal
a2486447c4
Speed up drawing of cells with many combining chars
- Add runs of plain combining chars to a cell with a single lookup in
  the text cache, rather than one for each char, which also added the
  intermediate texts of the cell to the cache.

- Also collect garbage in the text cache when starting a new line, not
  just when starting to draw text, as a single draw can add a great many
  entries, making the cache slower to use the larger it grows.

- Size the hash map of the text cache for the expected number of entries
  after garbage collection, to avoid repeatedly rehashing it as it grows.

This makes the unique multi-codepoint cells benchmark ~80% faster.

The differential test of batched drawing now compares cells by content,
since cells with multiple codepoints store indices into the text cache,
which change as intermediate texts are no longer added to it.
2026-11-18 08:26:43 +05:30
Kovid Goyal
327e5f7ae1
Do not require AVX-512 VBMI2 for the AVX-512 SIMD code
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.
2026-11-18 08:26:43 +05:30
Kovid Goyal
2f80a43caa
Much faster SIMD UTF-8 decoding of valid UTF-8
Decode 64 byte blocks of valid UTF-8 containing no ESC using the
approach of simdutf: blocks are validated with the lookup tables of
Keiser and Lemire and converted twelve bytes at a time using shuffles
looked up from a mask of the bytes that end code points, with fast
paths for runs of ASCII, two byte and three byte sequences. Anything
else, ESC, invalid UTF-8 and the end of the input, is decoded as
before.

The shuffle tables are generated by gen/utf8_decode_tables.py.

This decodes the text of the unicode benchmark 2.6 times faster, faster
than simdutf's own conversion with error checking, and speeds up the
unicode benchmark by ~8%.

The new AVX2 decoder is faster than the AVX-512 one, so remove the
AVX-512 decoder and use the AVX2 one on CPUs with AVX-512 as well.

Also add a test comparing the SIMD decoders with the scalar one on long
inputs, which exercise the decoding of blocks, as the existing tests use
short inputs.
2026-11-18 08:26:43 +05:30
Kovid Goyal
f08d996b42
Avoid store forwarding stalls when writing wide char cells
Building the cells of wide chars with bitfield initializers made
compilers write parts of them to the stack and reload them with wider
loads, which stalls on store forwarding on every call of the batched
non-ASCII draw path and for every wide char drawn by the scalar path.
Build the cells from constant words in registers instead, using helpers
shared by both paths.

This speeds up the unicode benchmark by ~6%.
2026-11-18 08:26:43 +05:30
Kovid Goyal
a141844c52
Use a compact per char draw info table in the batched draw path
Decoding the packed bitfields of CharProps took about half the
instructions of the batched non-ASCII draw loop. Precompute, for each
distinct CharProps value, the number of cells a char occupies and its
grapheme segmentation property, and use that in the loop instead.

This speeds up the unicode benchmark by ~8%.

Also add test cases for a batched run that stops at an existing
multicell char after an unpaired regional indicator, which the random
test cases did not cover.
2026-11-18 08:26:43 +05:30
Kovid Goyal
a30c428389
Speed up parsing of CSI codes and erasing of lines
- Check for multicell chars in the erased range before looking for them
  cell by cell, with a branch free check that reads only the word of each
  cell containing the multicell flag. The common case is a line with no
  multicell chars.

- Add a fast path that parses CSI codes of the common form, an optional
  private marker, numeric params separated by ; or : and the final byte,
  in a single pass, falling back to the generic CSI parser for anything
  else.

- Do not call the UTF-8 decoder for no text when an escape code directly
  follows another one, and start parsing CSI codes right after ESC [
  rather than in the next iteration of the parse loop.

This speeds up the CSI benchmark by 25% to 30% and the truecolor
benchmarks by ~10%.

A differential test compares the fast path and the generic CSI parser on
random input, and a new test covers erasing parts of multicell chars,
which no existing test did.
2026-11-18 08:26:43 +05:30
Kovid Goyal
22cb56ea17
Add a batched draw path for runs of non-ASCII text
Draw runs of non-ASCII chars that each start a new cell of width one or
two in a tight loop, with the run invariant checks done once and state
kept in locals, falling back to the scalar path for anything that needs
special handling: combining chars, zero width chars, the image
placeholder, existing multicell cells, wrapping, insert mode and charset
translation.

Cells are written as 64 bit values built in registers, since assembling
them as structs makes compilers go through the stack with partial stores
that stall on store forwarding. The grapheme segmentation step is cached
as it depends only on the state and the segmentation property of the
char, which repeat in a run of text, breaking the chain of dependent
table lookups between consecutive chars.

This speeds up the unicode benchmark by ~30%, drawing CJK text by ~70%.

A differential test compares the batched and scalar paths on random
operations.
2026-11-18 08:26:43 +05:30
Kovid Goyal
598cc8e27d
benchmark kitten: Add benchmarks for text with many distinct colors
Add truecolor_text, where every char has a random 24-bit foreground,
palette16_text, the same but with only 16 distinct colors, and
halfblocks, rows of half blocks with random 24-bit foreground and
background as written by terminal image viewers.

The existing benchmarks use either no colors or a handful of fixed
SGR codes, which favors terminals that store styles in a per page
deduplicated table rather than in each cell. These benchmarks measure
the cost of output with many distinct styles, which is common in
practice.
2026-11-18 08:26:42 +05:30
Kovid Goyal
39fc561cec
Remove input_delay and parse output as soon as it is received
Holding large chunks of input for input_delay left the parser idle about
30% of the time during bulk output: the parser started only when the
buffer was nearly full, and freed space only at the end of a pass, so the
I/O thread could not read while the parser worked.

Now the I/O thread wakes the main loop whenever new input arrives and no
wakeup is already outstanding, and a parse pass compacts the buffer as it
goes, waking the I/O thread if the buffer had filled up. A pass parses at
most 1MB of input so that a continuous stream cannot starve rendering and
event handling.

This raises parser utilization during kitten __benchmark__ from ~70% to
~97% and throughput by 12% to 30% depending on the kind of output.
2026-11-18 08:26:42 +05:30
Kovid Goyal
aba6d85ed5
macOS: shave another 30ms of startup time by initializing while slow python imports are being done 2026-11-18 08:26:42 +05:30
Kovid Goyal
af1754f1b8
macOS: minor fixes to the new C based font selection code 2026-11-18 08:26:42 +05:30
Kovid Goyal
5a510a76bb
Prepare the builtin NERD font in the font selection thread
Loading the builtin NERD font, which includes a fontconfig match for its
hinting settings, was done on the main thread when the results of font
selection were first used. Do the slow parts of it in the font selection
thread instead. On Linux the PostScript name is read from the name table
of the font file and the fontconfig match is done in the thread, and the
FreeType face, which is only used for fallback, is created when first
needed. On macOS the font descriptor is created in the thread.

This saves ~0.6ms on the main thread during startup on Linux.
2026-11-18 08:26:42 +05:30
Kovid Goyal
ab13e6562d
Add a --debug-startup command line flag
Prints the time taken by the various phases of startup, measured from
when the launcher started, including the time spent in the threads that
load the GPU driver and select fonts and how long the main thread waited
for them. Printing stops after the first frame is presented.
2026-11-18 08:26:42 +05:30
Kovid Goyal
060712d388
Select fonts in C, in a thread, during startup
Font selection was done in Python on the main thread, taking ~15ms at
startup on Linux and much more on macOS, where all installed fonts were
listed from CoreText and converted to Python, taking ~165ms.

Port the selection algorithm to pure C in font-select.c, with platform
backends in fontconfig.c and core_text.m, so that it can run in a thread
started by set_font_family(). The results are used when the first font
group is created, typically when the first OS Window is created. The
data for variable fonts is read from the font tables by C code that does
not use Python or FreeType.

The fontconfig backend lists all monospace fonts once and filters them
in C, as listing fonts is dominated by scanning all fonts. The CoreText
backend queries only the needed font families and PostScript names
instead of all installed fonts.

On Linux, the selected fonts are identical to those selected by the
previous Python implementation for ~1400 font specifications, including
variable fonts. The CoreText backend has not yet been compiled or tested.
2026-11-18 08:26:42 +05:30
Kovid Goyal
4d215c965d
Fix position and scale of the live resize text
The viewport was being reset to the pre-resize size on every render,
so the resizing text overlay was drawn into a stale viewport, making it
off center and scaled inversely to the window size.

Fixes #10814
2026-11-18 08:26:42 +05:30
Kovid Goyal
e8725a1986
Import the boss, session and shader modules after initializing glfw
These modules are slow to import, so import them in _run_app() and
load_all_shaders() instead of at the top of kitty/main.py, so that on
Wayland they are imported while the GPU driver is loaded in a thread
started by init_glfw(), instead of before it. Previously the driver
thread overlapped only with loading fonts and the main thread then had
to wait ~10ms for it. Now it finishes well before the first OS Window
is created.
2026-11-18 08:26:42 +05:30
Kovid Goyal
4a71009354
Wayland: Load the GPU driver in a thread
Connecting to the GPU driver takes ~25ms with Vulkan, almost all of it
in the Vulkan loader and the GPU drivers it loads. On Wayland, where the
connection to the compositor can be used from multiple threads, do it in
a thread started by glfw_init(), so that it overlaps with loading fonts
and creating the startup sessions. It is waited for when the first OS
Window is created.

Only the first candidate driver is tried in the thread, the remaining
ones, if any, are tried synchronously when waiting, as the software
OpenGL driver modifies environment variables, which is not thread safe.

Together with the previous startup changes, this reduces the time to
the first frame by ~25-35ms.
2026-11-18 08:26:42 +05:30
Kovid Goyal
04c4e3d152
Vulkan: Create the swapchain with the right present mode the first time
The swapchain was created with the FIFO present mode and then recreated
on the first frame, because the swap interval of the window was set
only after the surface was created. Pass the initial swap interval to
the driver in GPUSurfaceConfig so the swapchain is created correctly
when the surface is created.
2026-11-18 08:26:42 +05:30
Kovid Goyal
4079b366aa
Do not import the launch module when there are no watchers
Creating the first window imported kitty.launch, which is slow to
import, just to find out there are no watchers to load. This delayed
the launch of the first child by a few ms.
2026-11-18 08:26:42 +05:30
Kovid Goyal
de8e0f03b9
Disable garbage collection during startup
Python garbage collections triggered while importing modules, parsing
the config and creating the first window cost ~10ms and find almost
nothing to collect. Disable the collector until the main loop starts,
then freeze the, mostly long lived, objects created during startup so
they are not repeatedly scanned by later collections.
2026-11-18 08:26:42 +05:30
Kovid Goyal
0ed4b715ed
Fix margins drawn with the wrong viewport with the Vulkan driver
The viewport is driver state shared by all surfaces with Vulkan (and
Metal), unlike OpenGL where it is per context. It was set only when an
OS Window's size changed, so a resize of another OS Window could leave
a stale viewport in place, causing the border/margin rects to be drawn
at the wrong size. Set it every time an OS Window is rendered.

Fixes #10813
2026-11-18 08:26:42 +05:30
Kovid Goyal
5632280cba
Update shell.nix for vulkan support 2026-11-18 08:26:42 +05:30
Kovid Goyal
08a1bf9028
Fix freeze build failure 2026-11-18 08:26:41 +05:30
Kovid Goyal
df55c5f015
Bump generated MSL version to that used on macOS 14 2026-11-18 08:26:41 +05:30
Kovid Goyal
96e11ccec7
macOS: Fix notification urgency being ignored
The switch mapping urgency to interruption level had no break statements, so
every notification ended up with the Active interruption level. Also use
Time Sensitive rather than Critical for urgency 2, as Critical requires a
special entitlement from Apple.
2026-11-18 08:26:41 +05:30
Kovid Goyal
fcc99a2d2d
macOS: Require macOS 14 and drop code for older versions
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.
2026-11-18 08:26:41 +05:30
Kovid Goyal
b901c11a03
macOS: CVDisplayLink -> CADisplayLink 2026-11-18 08:26:41 +05:30
Kovid Goyal
d6fbe9d180
Fix the colors of the live resize text
The text showing the size of the window in cells during a live resize
is drawn directly into the window after the layers are composited, when
encoding to sRGB is disabled, so its linear colors were output as is,
making them too dark, for example #ffcc00 was drawn as #ff9a00. Encode
the output to sRGB when drawing alpha masks into the window, or when the
window does not support that, pass the colors without linearizing them.
The software rendering banner now uses the same code.
2026-11-18 08:26:41 +05:30
Kovid Goyal
2b4422cc9a
Add software rendering as a fallback GPU driver
On Linux and BSD, kitty now falls back to rendering on the CPU with the
Mesa lavapipe (Vulkan) or llvmpipe (OpenGL) software renderers when no
usable GPU is found, such as in virtual machines or with broken GPU
drivers. This is the new software value of the gpu_driver option, last
in the default list.

Drivers are now told which kind of renderer they may use. The software
candidates use only software renderers: Vulkan selects CPU devices and
OpenGL sets LIBGL_ALWAYS_SOFTWARE and __GLX_VENDOR_LIBRARY_NAME while
the renderer is chosen, restoring them afterwards so they are not passed
on to child programs. The other candidates reject software renderers,
unless they are last, so that a working GPU, even one usable only by a
later driver, is always preferred to the CPU. Previously, on systems
with a GPU usable only with OpenGL, kitty would use lavapipe. Drivers
report whether they render in software in their capabilities.

Failing to initialize the GPU driver for the first window is no longer
fatal: the window is recreated with the next driver, as is already done
for failures creating surfaces. OpenGL can only detect that it is using
llvmpipe once a context is current.

When software rendering is used, a message saying so is shown at the
top of every OS window for five seconds after it is first rendered.
2026-11-18 08:26:41 +05:30
Kovid Goyal
d537ce2a9a
Simplify is_selected buffer Metal compatibility 2026-11-18 08:26:41 +05:30
Kovid Goyal
a9dc72e522
Get Metal driver working 2026-11-18 08:26:41 +05:30
Kovid Goyal
ca5b72bd26
Add a Metal GPU driver and an MSL shader target
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.
2026-11-18 08:26:41 +05:30
Kovid Goyal
813e8cefd0
Build the Vulkan GPU driver in the Linux binary builds
Add vulkan-headers to the Linux dependencies, and fail freezing on Linux
if either the OpenGL or the Vulkan GPU driver, or the built-in shaders
for its shader target, are missing. Document vulkan-headers as a build
dependency.
2026-11-18 08:26:41 +05:30
Kovid Goyal
d96a5b2a0c
Add a Vulkan GPU driver
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.
2026-11-18 08:26:41 +05:30
Kovid Goyal
6c25fbecca
Add a SPIR-V shader target for the built-in and custom shaders
Shader targets of the form spirv-NN (for SPIR-V N.N) compile each
program to a single SPIR-V module containing the entry points for all
stages, along with the same backend neutral program metadata as for
GLSL. The compiled modules are validated with spirv-val, when it is
available. Custom shaders are compiled at runtime for SPIR-V targets as
well, and the tests compile and validate all bundled custom shaders for
SPIR-V in addition to the target of the loaded driver.

The program metadata now includes the names of the entry points, which
are passed to drivers in GPUShaderSource, since a module can contain
the entry points of several stages. compile_program() accepts binary
shaders as bytes.

This replaces the unused, untargeted .spv files that were built before.
2026-11-18 08:26:41 +05:30
Kovid Goyal
161ddb09fc
Use the coordinate conventions of Vulkan and Metal for the GPU API
Pixel coordinates of viewports, scissor rectangles and read back pixels
now have their origin at the top left of the render target, rows are
read back top to bottom, NDC y=-1 is the top of the viewport and render
targets have their top row at texture coordinate t=0, the same as
uploaded images. Vulkan and Metal drivers can then render with no flips
at all.

The OpenGL driver is now the special case. Framebuffer objects already
behave this way, so it converts only when rendering to a window: vertex
shaders negate gl_Position.y via a kitty_flip_y uniform that the GLSL
fixup adds, viewport and scissor y coordinates are converted, rows of
read back pixels are reversed and copying to a texture uses a flipping
blit.

kitty's code gets simpler: viewports and scissor rectangles no longer
need the framebuffer height, screenshots no longer need their rows
flipped and textures produced by rendering are sampled the same way as
uploaded ones. The rounded rect shader no longer uses SV_Position, whose
origin differs between backends.

User facing custom shader UV coordinates are unchanged, still with
their origin at the bottom left.

Rendering is pixel identical to before.
2026-11-18 08:26:41 +05:30
Kovid Goyal
d1f8962e43
Add a gpu_driver option to choose between GPU drivers with fallback
The gpu_driver option is an ordered list of the GPU drivers to try,
defaulting to metal, vulkan, opengl. Drivers that are not part of the
build are skipped.

Add connect() to the GPU driver API. It is called once the windowing
system has been initialized, with the connection to the display, so
that drivers can check that they are able to render to windows on it,
before any windows are created. The driver is now loaded after
glfwInit() for this reason. If a driver cannot connect, the next one is
tried. If the driver fails to choose a visual or create a surface for
the first window, before any GPU resources exist, kitty switches to the
next usable driver and creates the window again.

--debug-rendering reports the driver used and why others were rejected.
2026-11-18 08:26:41 +05:30
Kovid Goyal
9ae52b5476
Pass the uniform parameters of shaders in a single push constant block
Declare the uniform parameters of every program as a single Params
struct, shared by all stages of the program, in a push constant block,
instead of as uniform parameters of the entry points. Slang lays out
the uniform parameters of each entry point starting at offset zero, so
the vertex and fragment parameters overlap, which Vulkan does not allow
in push constants. A single block shared by all stages is also what
Metal wants, and it is still emitted as loose uniforms for OpenGL.

The build now fails if a program has entry point uniform parameters or
more than 128 bytes of them, the push constant size guaranteed by Vulkan.

Since a program now has at most one block of uniform parameters, drop
the stage from GPUParamBlock, bump the GPU API version, and simplify
the lookup of parameters by name in kitty, as each name is now present
in only one parameter block.
2026-11-18 08:26:40 +05:30
Kovid Goyal
afb34c1ed5
fix build on macOS 2026-11-18 08:26:40 +05:30
Kovid Goyal
1dba9eba6d
Replace loose uniforms with parameter blocks
The small, frequently changing parameters of a pipeline, the uniform
parameters of each entry point and uniform blocks whose contents are
constant for the lifetime of a pipeline (currently only the gamma LUT),
are now parameter blocks whose layout comes from the shader reflection
data. kitty writes their contents into memory it owns and passes changed
blocks to the driver with set_params() just before drawing, instead of
setting individual uniforms by location.

This is the only way parameters are set, so the GL specific
pipeline_uniform_slot() and set_uniform_*() functions are gone from the
driver API. Drivers are free to implement parameter blocks as they see
fit: the OpenGL driver uses loose uniforms, uploading only the fields that
changed, Vulkan would use push constants and Metal set*Bytes().

Pipeline creation, including all parsing of the program metadata, now
lives in kitty/gpu.c.
2026-11-18 08:26:40 +05:30
Kovid Goyal
6859aef001
Declare texture and uniform block binding slots in the shaders
Every texture and uniform block in kitty's shaders now declares its
binding slot with [[vk::binding(N)]], from a single documented table,
SHADER_BINDING_SLOTS, which the shader build verifies. Slots are unique
across shaders and kinds of resource, as Vulkan requires, and so that
resources bound once and used by many programs, such as the sprite
textures, are never displaced by another program's bindings.

The slots are passed to the C code in the program metadata, which no
longer hard codes texture units or uniform buffer binding points, and no
longer sets sampler uniforms or calls glUniformBlockBinding() equivalents.
Instead the driver receives the slots when a pipeline is created. The
OpenGL driver applies them to the linked program since OpenGL 3 has no
layout(binding) qualifiers; targets where the slots are part of the
compiled code can ignore them.
2026-11-18 08:26:40 +05:30
Kovid Goyal
9f776800f6
Make shader targets driver defined and program metadata reflection based
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.
2026-11-18 08:26:40 +05:30
Kovid Goyal
b46525072b
Move OpenGL context creation from glfw into the GPU 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.
2026-11-18 08:26:40 +05:30