feat(vkbridge): Vulkan bridge core - codegen, wire runtime, server, client ICD, WSI

Generated from vk.xml 1.3.247; server shares host-visible memory via a
self-tested strategy (hostptr/dmabuf/ahb). vulkaninfo runs through it on host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KZqR8XUE8czvGzEpgSCVQR
This commit is contained in:
ahmadandClaude Opus 5.5 authored and Ahmad Sayed Alsayed Ebrahim committed 2026-10-10 14:27:54 +03:00
1 parent 8ac555664a
commit a8fd343fc1
67 files changed
+82811

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
*
* Feature emulation: entry point. What the GPU lacks and the bridge can make up for is decided
* here per physical device; the client reports those features as present, the server strips
* them from vkCreateDevice and installs wrappers in the device's dispatch table.
*/
#define _GNU_SOURCE
#include "vkb_server.h"
#include "server_emu.h"
#include <stdlib.h>
#include <string.h>
static int env_off(const char *name)
{
const char *v = getenv(name);
return v && !strcmp(v, "0");
}
uint32_t vkb_emu_detect(const vkb_dispatch *idt, VkPhysicalDevice pd)
{
VkPhysicalDeviceFeatures f;
idt->vkGetPhysicalDeviceFeatures(pd, &f);
uint32_t n = 0;
idt->vkEnumerateDeviceExtensionProperties(pd, NULL, &n, NULL);
VkExtensionProperties *e = calloc(n ? n : 1, sizeof(*e));
idt->vkEnumerateDeviceExtensionProperties(pd, NULL, &n, e);
int divisor = 0, depth_clip = 0;
for (uint32_t i = 0; i < n; i++) {
if (!strcmp(e[i].extensionName, "VK_EXT_vertex_attribute_divisor") ||
!strcmp(e[i].extensionName, "VK_KHR_vertex_attribute_divisor"))
divisor = 1;
if (!strcmp(e[i].extensionName, "VK_EXT_depth_clip_enable")) depth_clip = 1;
}
free(e);
/* VKBRIDGE_FAKE_MISSING=bc,divisor,clip,cull,depthclip pretends the GPU lacks them (host tests). */
const char *fake = getenv("VKBRIDGE_FAKE_MISSING");
if (fake) {
if (strstr(fake, "bc")) f.textureCompressionBC = VK_FALSE;
if (strstr(fake, "divisor")) divisor = 0;
if (strstr(fake, "clip")) f.shaderClipDistance = VK_FALSE;
if (strstr(fake, "cull")) f.shaderCullDistance = VK_FALSE;
if (strstr(fake, "depthclip")) depth_clip = 0;
}
uint32_t emu = 0;
if (!f.textureCompressionBC && vkb_emu_bcn_supported(idt, pd) && !env_off("VKBRIDGE_EMU_BCN")) emu |= VKB_EMU_BCN;
if (!divisor && !env_off("VKBRIDGE_EMU_DIVISOR")) emu |= VKB_EMU_DIVISOR;
if (!f.shaderClipDistance && !env_off("VKBRIDGE_EMU_CLIP")) emu |= VKB_EMU_CLIP_DISTANCE;
if (!f.shaderCullDistance && !env_off("VKBRIDGE_EMU_CULL")) emu |= VKB_EMU_CULL_DISTANCE;
if (!depth_clip && f.depthClamp && !env_off("VKBRIDGE_EMU_DEPTHCLIP")) emu |= VKB_EMU_DEPTH_CLIP;
/* PointSize in geometry/tessellation stages: stripped when the feature is missing. */
if (!f.shaderTessellationAndGeometryPointSize && (f.geometryShader || f.tessellationShader)) emu |= VKB_EMU_POINT_SIZE;
return emu & VKB_EMU_IMPLEMENTED;
}
/* Remove a structure from a pNext chain (the chain lives in the request's arena). */
static void chain_remove(VkDeviceCreateInfo *ci, VkStructureType t)
{
VkBaseOutStructure *prev = (VkBaseOutStructure *)ci;
while (prev->pNext) {
if (prev->pNext->sType == t) prev->pNext = prev->pNext->pNext;
else prev = prev->pNext;
}
}
static VkPhysicalDeviceFeatures *find_features(VkDeviceCreateInfo *ci)
{
if (ci->pEnabledFeatures) return (VkPhysicalDeviceFeatures *)ci->pEnabledFeatures;
for (VkBaseOutStructure *b = (VkBaseOutStructure *)ci->pNext; b; b = b->pNext)
if (b->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2) return &((VkPhysicalDeviceFeatures2 *)b)->features;
return NULL;
}
void vkb_emu_device_create_info(vkb_srv_table *inst, VkPhysicalDevice pd, uint32_t emu, VkDeviceCreateInfo *ci, vkb_arena *a)
{
VkPhysicalDeviceFeatures real;
inst->real.vkGetPhysicalDeviceFeatures(pd, &real);
VkPhysicalDeviceFeatures *f = find_features(ci);
if (f) {
/* pEnabledFeatures came from the request: it is ours to change. Anything the client asked
* for that the GPU does not have is either emulated or would fail the call. */
VkBool32 *want = (VkBool32 *)f;
const VkBool32 *have = (const VkBool32 *)&real;
for (size_t i = 0; i < sizeof(*f) / sizeof(VkBool32); i++) {
if (want[i] && !have[i]) want[i] = VK_FALSE;
}
}
if (emu & VKB_EMU_DIVISOR) chain_remove(ci, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT);
if (emu & VKB_EMU_DEPTH_CLIP) chain_remove(ci, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT);
(void)a;
}
void vkb_emu_device_init(vkb_srv_table *dev, uint32_t emu)
{
if (!emu) return;
vkb_emu_device *e = calloc(1, sizeof(*e));
e->flags = emu;
e->dev = dev;
pthread_mutex_init(&e->lock, NULL);
dev->emu = e;
vkb_emu_install(dev);
}
void vkb_emu_device_destroy(vkb_srv_table *dev)
{
if (!dev->emu) return;
vkb_emu_uninstall(dev);
pthread_mutex_destroy(&dev->emu->lock);
free(dev->emu);
dev->emu = NULL;
}