Commit graph

5 commits

Author SHA1 Message Date
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
Kovid Goyal
ae69df7c69
Move the kitty OpenGL code into a dynamically loaded GPU driver
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.
2026-11-18 08:26:40 +05:30
Kovid Goyal
0051fc799d
Add a backend neutral GPU driver API
gpu/api.h defines the interface between kitty and dynamically loaded GPU
drivers. It uses only standard C types, with opaque 64 bit handles for all
resources, so that it can be implemented with OpenGL, Vulkan or Metal.
2026-11-18 08:26:40 +05:30