mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 14:45:29 +00:00
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.
131 lines
4.9 KiB
C
131 lines
4.9 KiB
C
/*
|
|
* functions.h
|
|
* Copyright (C) 2026 Kovid Goyal <kovid at kovidgoyal.net>
|
|
*
|
|
* Distributed under terms of the GPL3 license.
|
|
*/
|
|
|
|
// The Vulkan functions used by the driver. libvulkan is loaded at runtime,
|
|
// so that kitty has no link time dependency on it, and these are loaded from
|
|
// it with vkGetInstanceProcAddr() and vkGetDeviceProcAddr().
|
|
|
|
#pragma once
|
|
|
|
#define VK_NO_PROTOTYPES
|
|
#define VK_USE_PLATFORM_XLIB_KHR
|
|
#define VK_USE_PLATFORM_WAYLAND_KHR
|
|
#include <vulkan/vulkan.h>
|
|
|
|
// Functions that need no instance
|
|
#define VK_GLOBAL_FUNCTIONS(X) \
|
|
X(vkCreateInstance) \
|
|
X(vkEnumerateInstanceExtensionProperties) \
|
|
X(vkEnumerateInstanceLayerProperties) \
|
|
X(vkEnumerateInstanceVersion)
|
|
|
|
#define VK_INSTANCE_FUNCTIONS(X) \
|
|
X(vkDestroyInstance) \
|
|
X(vkEnumeratePhysicalDevices) \
|
|
X(vkGetPhysicalDeviceProperties) \
|
|
X(vkGetPhysicalDeviceProperties2) \
|
|
X(vkGetPhysicalDeviceFeatures2) \
|
|
X(vkGetPhysicalDeviceQueueFamilyProperties) \
|
|
X(vkGetPhysicalDeviceMemoryProperties) \
|
|
X(vkGetPhysicalDeviceFormatProperties) \
|
|
X(vkEnumerateDeviceExtensionProperties) \
|
|
X(vkCreateDevice) \
|
|
X(vkGetDeviceProcAddr) \
|
|
X(vkDestroySurfaceKHR) \
|
|
X(vkGetPhysicalDeviceSurfaceSupportKHR) \
|
|
X(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \
|
|
X(vkGetPhysicalDeviceSurfaceFormatsKHR) \
|
|
X(vkGetPhysicalDeviceSurfacePresentModesKHR)
|
|
|
|
// Only the functions of the windowing system in use are loaded
|
|
#define VK_XLIB_FUNCTIONS(X) \
|
|
X(vkCreateXlibSurfaceKHR) \
|
|
X(vkGetPhysicalDeviceXlibPresentationSupportKHR)
|
|
|
|
#define VK_WAYLAND_FUNCTIONS(X) \
|
|
X(vkCreateWaylandSurfaceKHR) \
|
|
X(vkGetPhysicalDeviceWaylandPresentationSupportKHR)
|
|
|
|
// Loaded only if the debug utils extension is enabled
|
|
#define VK_DEBUG_FUNCTIONS(X) \
|
|
X(vkCreateDebugUtilsMessengerEXT) \
|
|
X(vkDestroyDebugUtilsMessengerEXT) \
|
|
X(vkSetDebugUtilsObjectNameEXT)
|
|
|
|
#define VK_DEVICE_FUNCTIONS(X) \
|
|
X(vkDestroyDevice) \
|
|
X(vkGetDeviceQueue) \
|
|
X(vkDeviceWaitIdle) \
|
|
X(vkQueueWaitIdle) \
|
|
X(vkQueueSubmit2) \
|
|
X(vkQueuePresentKHR) \
|
|
X(vkCreateSwapchainKHR) \
|
|
X(vkDestroySwapchainKHR) \
|
|
X(vkGetSwapchainImagesKHR) \
|
|
X(vkAcquireNextImageKHR) \
|
|
X(vkCreateCommandPool) \
|
|
X(vkDestroyCommandPool) \
|
|
X(vkResetCommandPool) \
|
|
X(vkAllocateCommandBuffers) \
|
|
X(vkBeginCommandBuffer) \
|
|
X(vkEndCommandBuffer) \
|
|
X(vkCreateFence) \
|
|
X(vkDestroyFence) \
|
|
X(vkWaitForFences) \
|
|
X(vkGetFenceStatus) \
|
|
X(vkResetFences) \
|
|
X(vkCreateSemaphore) \
|
|
X(vkDestroySemaphore) \
|
|
X(vkAllocateMemory) \
|
|
X(vkFreeMemory) \
|
|
X(vkMapMemory) \
|
|
X(vkUnmapMemory) \
|
|
X(vkCreateBuffer) \
|
|
X(vkDestroyBuffer) \
|
|
X(vkGetBufferMemoryRequirements) \
|
|
X(vkBindBufferMemory) \
|
|
X(vkCreateImage) \
|
|
X(vkDestroyImage) \
|
|
X(vkGetImageMemoryRequirements) \
|
|
X(vkBindImageMemory) \
|
|
X(vkCreateImageView) \
|
|
X(vkDestroyImageView) \
|
|
X(vkCreateSampler) \
|
|
X(vkDestroySampler) \
|
|
X(vkCreateShaderModule) \
|
|
X(vkDestroyShaderModule) \
|
|
X(vkCreateDescriptorSetLayout) \
|
|
X(vkDestroyDescriptorSetLayout) \
|
|
X(vkCreatePipelineLayout) \
|
|
X(vkDestroyPipelineLayout) \
|
|
X(vkCreateGraphicsPipelines) \
|
|
X(vkDestroyPipeline) \
|
|
X(vkCmdPipelineBarrier2) \
|
|
X(vkCmdBeginRendering) \
|
|
X(vkCmdEndRendering) \
|
|
X(vkCmdBindPipeline) \
|
|
X(vkCmdSetViewport) \
|
|
X(vkCmdSetScissor) \
|
|
X(vkCmdBindVertexBuffers2) \
|
|
X(vkCmdBindIndexBuffer) \
|
|
X(vkCmdDrawIndexed) \
|
|
X(vkCmdPushConstants) \
|
|
X(vkCmdPushDescriptorSetKHR) \
|
|
X(vkCmdCopyBufferToImage) \
|
|
X(vkCmdCopyImageToBuffer) \
|
|
X(vkCmdCopyImage) \
|
|
X(vkCmdBlitImage) \
|
|
X(vkCmdClearAttachments)
|
|
|
|
#define VK_DECLARE_FUNCTION(name) extern PFN_##name name;
|
|
VK_GLOBAL_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
VK_INSTANCE_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
VK_XLIB_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
VK_WAYLAND_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
VK_DEBUG_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
VK_DEVICE_FUNCTIONS(VK_DECLARE_FUNCTION)
|
|
extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|