Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/vkb_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ void vkb_caps_patch_features(const vkb_pd_caps *caps, VkPhysicalDeviceFeatures *
set_feature(caps, VKB_EMU_DUAL_SRC, &f->dualSrcBlend);
set_feature(caps, VKB_EMU_FILL_MODE, &f->fillModeNonSolid);
set_feature(caps, VKB_EMU_MULTI_VIEWPORT, &f->multiViewport);
if (caps->missing & VKB_CAP_HIDE_MULTI_VIEWPORT) f->multiViewport = VK_FALSE;
set_feature(caps, VKB_EMU_MULTI_DRAW, &f->multiDrawIndirect);
}

Expand Down
3 changes: 2 additions & 1 deletion common/vkb_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static inline VkFormat vkb_bgr10_rgba(VkFormat f)
* (Mali r18-r26, Vulkan 1.1: Zink requires it; server_emu_imageless.c) */
#define VKB_EMU_MEM_BUDGET (1u << 26) /* VK_EXT_memory_budget answered by the server where the driver has none (every Mali):
* DXVK and vkd3d-proton clients only (server_memory.c memb_fill) */
#define VKB_CAP_HIDE_MULTI_VIEWPORT (1u << 27) /* report multiViewport and shaderOutputViewportIndex unavailable, even when emulated */
#define VKB_EMU_ROBUST2_ACCESS (1u << 19) /* robustBufferAccess2/robustImageAccess2 reported where the driver's robustness2
* has nullDescriptor only (Mali-G715 r54p3); core robustness on instead (DXVK 3) */

Expand All @@ -87,7 +88,7 @@ typedef struct vkb_server_pd_info {
uint32_t emu; /* VKB_EMU_* the server will perform */
uint32_t emu_available; /* VKB_EMU_* the server could perform */
uint32_t real_api_version;
uint32_t missing; /* VKB_EMU_* features the GPU lacks (emulated or not) */
uint32_t missing; /* VKB_EMU_* features the GPU lacks (emulated or not), plus VKB_CAP_* report masks */
uint32_t client_knobs; /* VKB_KNOB_*: the client's switches from the server (per-game presets) */
uint32_t cached_types; /* server memory types whose shared pages can be CPU-cached (cached readback); 0: none */
uint32_t cached_flags; /* VKB_CACHED_*: who may use them */
Expand Down
28 changes: 28 additions & 0 deletions server/server_driverid.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,34 @@ int vkb_arm_driver(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_ap
return vkb_driver_is_arm(&p, vkb_driver_id(dt, pd, inst_api));
}

/* Mali-G615 r44p1 ignores gl_ViewportIndex written from a vertex shader (MaliBridge issue #72).
* Keep this narrow: it must be Arm's proprietary driver, not a similarly named Mesa/PanVK device,
* and the r44p1 build must be identified from driverInfo or the encoded driverVersion. */
int vkb_mali_g615_r44p1(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_api)
{
VkPhysicalDeviceProperties p;
if (!dt || !dt->vkGetPhysicalDeviceProperties) return 0;
dt->vkGetPhysicalDeviceProperties(pd, &p);
if (!strstr(p.deviceName, "Mali-G615")) return 0;

uint32_t driver_id = vkb_driver_id(dt, pd, inst_api);
if (!vkb_driver_is_arm(&p, driver_id)) return 0;

VkPhysicalDeviceDriverProperties dp = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES};
uint32_t api = p.apiVersion < inst_api ? p.apiVersion : inst_api;
if (dt->vkGetPhysicalDeviceProperties2 && inst_api >= VK_API_VERSION_1_1 &&
(api >= VK_API_VERSION_1_2 || has_driver_properties(dt, pd))) {
VkPhysicalDeviceProperties2 p2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &dp};
dt->vkGetPhysicalDeviceProperties2(pd, &p2);
}
for (const char *s = dp.driverInfo; (s = strstr(s, "r44p1")); s += 5)
if (s[5] < '0' || s[5] > '9') return 1;

uint32_t r = p.driverVersion >> 22;
uint32_t patch = (p.driverVersion >> 12) & 0x3ffu;
return r == 44 && patch == 1;
}

const char *vkb_driver_id_name(uint32_t id)
{
switch (id) {
Expand Down
7 changes: 7 additions & 0 deletions server/server_emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,12 @@ uint32_t vkb_emu_detect(const vkb_dispatch *idt, VkPhysicalDevice pd, uint32_t *
uint32_t emu = 0;
VkPhysicalDeviceProperties props;
idt->vkGetPhysicalDeviceProperties(pd, &props);
int viewport_index_broken = vkb_mali_g615_r44p1(idt, pd, VK_API_VERSION_1_3);
if (viewport_index_broken) {
VKB_ONCE(VKB_LOG_INFO,
"multi-viewport: Mali-G615 r44p1 ignores a vertex shader's ViewportIndex; reporting multiViewport off");
f.multiViewport = VK_FALSE;
}
/* vkd3d-proton (every D3D12 game) wants vertexAttributeInstanceRateZeroDivisor too. Mali-G925 on
* Android 16 has the KHR extension without it (and without supportsNonZeroFirstInstance): such a
* divisor is taken as missing and emulated whole - the emulation does both, at any firstInstance. */
Expand Down Expand Up @@ -993,6 +999,7 @@ uint32_t vkb_emu_detect(const vkb_dispatch *idt, VkPhysicalDevice pd, uint32_t *
if (!f.dualSrcBlend) miss |= VKB_EMU_DUAL_SRC;
if (!f.fillModeNonSolid) miss |= VKB_EMU_FILL_MODE;
if (!f.multiViewport) miss |= VKB_EMU_MULTI_VIEWPORT;
if (viewport_index_broken) miss |= VKB_CAP_HIDE_MULTI_VIEWPORT;
if (!f.multiDrawIndirect) miss |= VKB_EMU_MULTI_DRAW;
if (emu & VKB_EMU_MAINT6) miss |= VKB_EMU_MAINT6;
if (emu & VKB_EMU_PUSH_DESC) miss |= VKB_EMU_PUSH_DESC;
Expand Down
23 changes: 22 additions & 1 deletion server/server_promote.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ typedef struct promo_gpu {
uint32_t drv_api; /* the driver's (or VKBRIDGE_FAKE_API's) */
uint32_t offered; /* the version the app sees: drv_api when nothing is promoted */
uint32_t spv_max; /* the SPIR-V version the driver takes */
int viewport_index_broken; /* Mali-G615 r44p1 ignores VS BuiltIn ViewportIndex */
int shuffle; /* subgroup shuffles in the driver: dynamic-id broadcasts lowered to them */
uint32_t lanes; /* without shuffles: the largest subgroup, each dynamic-id broadcast a chain over its lanes */
int active; /* translation wrappers on (VKBRIDGE_PROMOTE_API not 0, driver below 1.3) */
Expand Down Expand Up @@ -682,6 +683,9 @@ static void fill_core_features(const translate *x, const promo_gpu *g, VkBaseOut
if (r->ext_off == NONE) v = exts_has(x->exts, feat_structs[r->ef].ext);
else if (x->slots[r->ef].p) v = *(const VkBool32 *)((const uint8_t *)x->slots[r->ef].p + r->ext_off);
if (r->ef == EF_PRIVATE) v = VK_TRUE; /* the client's own (descriptor.c) */
if (g && g->viewport_index_broken && r->ef == EF_VPLAYER &&
r->core_off == offsetof(VkPhysicalDeviceVulkan12Features, shaderOutputViewportIndex))
v = VK_FALSE;
*(VkBool32 *)((uint8_t *)c + r->core_off) = v;
}
/* A shuffle where the driver has them, else a chain of constant-lane broadcasts (spirv_downgrade.h). */
Expand Down Expand Up @@ -733,6 +737,15 @@ static void q_props(void *ctx, void *head)
q->d->vkGetPhysicalDeviceProperties2(q->pd, head);
}

static void mask_viewport_index_features(const promo_gpu *g, VkPhysicalDeviceFeatures2 *f)
{
if (!g || !g->viewport_index_broken) return;
f->features.multiViewport = VK_FALSE;
for (VkBaseOutStructure *b = (VkBaseOutStructure *)f->pNext; b; b = b->pNext)
if (b->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES)
((VkPhysicalDeviceVulkan12Features *)b)->shaderOutputViewportIndex = VK_FALSE;
}

static void append(char *buf, size_t cap, const char *s)
{
size_t l = strlen(buf);
Expand All @@ -753,6 +766,7 @@ static void record_plain(const vkb_dispatch *d, VkPhysicalDevice pd)
g.drv_api = driver_api(p.apiVersion);
g.offered = g.drv_api;
snprintf(g.name, sizeof(g.name), "%s", p.deviceName);
g.viewport_index_broken = vkb_mali_g615_r44p1(d, pd, p.apiVersion);
g.push = p.limits.maxPushConstantsSize;
g.int64 = f.shaderInt64 != 0;
pthread_mutex_lock(&gpus_lock);
Expand All @@ -771,13 +785,16 @@ void vkb_promote_decide(const vkb_dispatch *d, VkPhysicalDevice pd)
memset(&g, 0, sizeof(g));
VkPhysicalDeviceIDProperties id = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES};
VkPhysicalDeviceSubgroupProperties sg = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES, &id};
VkPhysicalDeviceDriverProperties dp = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES};
id.pNext = &dp;
VkPhysicalDeviceProperties2 p2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &sg};
d->vkGetPhysicalDeviceProperties2(pd, &p2);
memcpy(g.uuid, id.deviceUUID, VK_UUID_SIZE);
g.real_api = p2.properties.apiVersion;
g.drv_api = driver_api(p2.properties.apiVersion);
g.offered = g.drv_api;
snprintf(g.name, sizeof(g.name), "%s", p2.properties.deviceName);
g.viewport_index_broken = vkb_mali_g615_r44p1(d, pd, p2.properties.apiVersion);
g.push = p2.properties.limits.maxPushConstantsSize;
VkPhysicalDeviceFeatures2 base = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
d->vkGetPhysicalDeviceFeatures2(pd, &base);
Expand Down Expand Up @@ -1013,6 +1030,7 @@ static VKAPI_ATTR void VKAPI_CALL pr_GetPhysicalDeviceFeatures2(VkPhysicalDevice
const promo_gpu *g = gpu_of(t, pd);
if (!g || !g->active) {
t->real.vkGetPhysicalDeviceFeatures2(pd, f);
mask_viewport_index_features(g, f);
return;
}
ext_list el;
Expand All @@ -1021,13 +1039,15 @@ static VKAPI_ATTR void VKAPI_CALL pr_GetPhysicalDeviceFeatures2(VkPhysicalDevice
if (!x) {
free(el.e);
t->real.vkGetPhysicalDeviceFeatures2(pd, f);
mask_viewport_index_features(g, f);
return;
}
x->drv = g->drv_api;
x->exts = &el;
query_ctx q = {&t->real, pd};
chain_query(x, f, q_features, &q);
fill_core_features(x, g, x->core);
mask_viewport_index_features(g, f);
if (!BELOW(g->offered, V13)) {
VkBaseOutStructure *pv = find_in_chain(f, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES);
if (pv) ((VkPhysicalDevicePrivateDataFeatures *)pv)->privateData = VK_TRUE; /* the client's own */
Expand All @@ -1042,7 +1062,8 @@ void vkb_promote_instance_install(vkb_srv_table *t)
int any = 0;
pthread_mutex_lock(&gpus_lock);
const promo_gpu *list = t->promote_ui ? gpus_ui : gpus;
for (int i = 0; i < ngpus; i++) any |= list[i].offered != list[i].real_api || list[i].active; /* VKBRIDGE_FAKE_API alone too */
for (int i = 0; i < ngpus; i++)
any |= list[i].offered != list[i].real_api || list[i].active || list[i].viewport_index_broken;
pthread_mutex_unlock(&gpus_lock);
if (!any) return;
t->dt.vkGetPhysicalDeviceProperties = pr_GetPhysicalDeviceProperties;
Expand Down
1 change: 1 addition & 0 deletions server/vkb_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ uint32_t vkb_steam_api_cap(const vkb_srv_table *t, VkPhysicalDevice pd);
uint32_t vkb_driver_id(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_api);
int vkb_driver_is_arm(const VkPhysicalDeviceProperties *p, uint32_t driver_id);
int vkb_arm_driver(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_api);
int vkb_mali_g615_r44p1(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_api); /* issue #72 */
const char *vkb_driver_id_name(uint32_t id);
void vkb_driver_log(const vkb_dispatch *dt, VkPhysicalDevice pd, uint32_t inst_api); /* the self-test's line */
PFN_vkGetInstanceProcAddr vkb_driverid_imitate_gipa(PFN_vkGetInstanceProcAddr gipa); /* VKBRIDGE_FAKE_DRIVER (host tests) */
Expand Down