mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: report Vulkan memory budgets without rejecting allocations (#2014)
Extend the VRAM setting to Vulkan memory-budget reports for DXVK and D3D12 while preserving real heap capacity and allocation results, removing the hard rejection that caused game crashes in FIT and Discord tests.
This commit is contained in:
1 parent
df76f66e8f
commit
d64205ba5b
43 files changed
+488
-38
No files matched your search
@@ -23,7 +23,8 @@
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/usr/local/bin/gamescope",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/bin/linuxarm64/driver_droiddeck.so",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so"
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so"
|
||||
],
|
||||
"ndk": true,
|
||||
"packages": [
|
||||
|
||||
+10
-4
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Builds VK_LAYER_DROIDDECK_gpu_load for the arm64 guest: tools/gpuload/build.sh [--native] OUT
|
||||
# OUT gets libVkLayer_droiddeck_gpuload.so and its implicit-layer manifest.
|
||||
# OUT gets libVkLayer_droiddeck_gpuload.so, libVkLayer_droiddeck_vramcap.so and their implicit-layer manifests.
|
||||
set -euo pipefail
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
repo=$(cd "$here/../.." && pwd)
|
||||
@@ -36,10 +36,15 @@ cmd=(sh -c '
|
||||
build/gpuload/test_gpuload_busy
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror -Ibuild/gpuload/include -Itools/gpuload/src -o build/gpuload/test_gpuload_ring tools/gpuload/tests/test_gpuload_ring.c
|
||||
build/gpuload/test_gpuload_ring
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror -Ibuild/gpuload/include -Itools/gpuload/src -pthread -Wno-unused-parameter -Wno-missing-field-initializers -o build/gpuload/test_vramcap_budget tools/gpuload/tests/test_vramcap_budget.c
|
||||
build/gpuload/test_vramcap_budget
|
||||
aarch64-linux-gnu-gcc -std=c11 -shared -fPIC -O2 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers \
|
||||
-fvisibility=hidden -pthread -Wl,-z,defs -Ibuild/gpuload/include -Itools/gpuload/src \
|
||||
-o build/gpuload/out/libVkLayer_droiddeck_gpuload.so tools/gpuload/src/vk_layer_droiddeck_gpuload.c
|
||||
aarch64-linux-gnu-strip --strip-unneeded build/gpuload/out/libVkLayer_droiddeck_gpuload.so')
|
||||
aarch64-linux-gnu-gcc -std=c11 -shared -fPIC -O2 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers \
|
||||
-fvisibility=hidden -pthread -Wl,-z,defs -Ibuild/gpuload/include -Itools/gpuload/src \
|
||||
-o build/gpuload/out/libVkLayer_droiddeck_vramcap.so tools/gpuload/src/vk_layer_droiddeck_vramcap.c
|
||||
aarch64-linux-gnu-strip --strip-unneeded build/gpuload/out/libVkLayer_droiddeck_gpuload.so build/gpuload/out/libVkLayer_droiddeck_vramcap.so')
|
||||
if [ "$native" = 1 ]; then
|
||||
(cd "$repo" && "${cmd[@]}")
|
||||
else
|
||||
@@ -47,7 +52,8 @@ else
|
||||
"${DROIDDECK_BUILD_IMAGE:-droiddeck-local-cross:24.04-v3}" "${cmd[@]}"
|
||||
fi
|
||||
|
||||
cp "$here/layer/VK_LAYER_DROIDDECK_gpu_load.json" "$work/out/"
|
||||
cp "$here/layer/VK_LAYER_DROIDDECK_gpu_load.json" "$here/layer/VK_LAYER_DROIDDECK_vram_cap.json" "$work/out/"
|
||||
mkdir -p "$out"
|
||||
cp "$work/out/libVkLayer_droiddeck_gpuload.so" "$work/out/VK_LAYER_DROIDDECK_gpu_load.json" "$out/"
|
||||
cp "$work/out/libVkLayer_droiddeck_gpuload.so" "$work/out/libVkLayer_droiddeck_vramcap.so" \
|
||||
"$work/out/VK_LAYER_DROIDDECK_gpu_load.json" "$work/out/VK_LAYER_DROIDDECK_vram_cap.json" "$out/"
|
||||
echo "built $out"
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"file_format_version": "1.2.0",
|
||||
"layer": {
|
||||
"name": "VK_LAYER_DROIDDECK_vram_cap",
|
||||
"type": "GLOBAL",
|
||||
"library_path": "/usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so",
|
||||
"api_version": "1.3.0",
|
||||
"implementation_version": "1",
|
||||
"description": "Reports a smaller video memory budget to DXVK and vkd3d-proton",
|
||||
"functions": {
|
||||
"vkNegotiateLoaderLayerInterfaceVersion": "DroidDeckVramCap_NegotiateLoaderLayerInterfaceVersion"
|
||||
},
|
||||
"enable_environment": {
|
||||
"DROIDDECK_VRAM_CAP": "1"
|
||||
},
|
||||
"disable_environment": {
|
||||
"DROIDDECK_VRAM_CAP_DISABLE": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vk_layer.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "vramcap_budget.h"
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
|
||||
static uint64_t g_cap;
|
||||
|
||||
__attribute__((constructor)) static void init(void) {
|
||||
g_cap = vramcap_parse_mb(getenv("DROIDDECK_VRAM_CAP_MB"));
|
||||
}
|
||||
|
||||
struct inst {
|
||||
struct inst *next_in_list;
|
||||
VkInstance handle;
|
||||
PFN_vkGetInstanceProcAddr gipa;
|
||||
PFN_vkDestroyInstance destroy;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 mem2;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 mem2_khr;
|
||||
};
|
||||
|
||||
struct dev {
|
||||
struct dev *next_in_list;
|
||||
VkDevice handle;
|
||||
PFN_vkGetDeviceProcAddr gdpa;
|
||||
PFN_vkDestroyDevice destroy;
|
||||
};
|
||||
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct inst *g_insts;
|
||||
static struct dev *g_devs;
|
||||
static int g_announced;
|
||||
|
||||
static void *key(const void *obj) { return *(void *const *)obj; }
|
||||
|
||||
static struct inst *inst_for(const void *obj) {
|
||||
struct inst *r;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (r = g_insts; r && key(r->handle) != key(obj); r = r->next_in_list) {}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return r;
|
||||
}
|
||||
|
||||
static struct dev *dev_for(const void *obj) {
|
||||
struct dev *r;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (r = g_devs; r && key(r->handle) != key(obj); r = r->next_in_list) {}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void say(const char *what) {
|
||||
fprintf(stderr, "[droiddeck-vram-cap] pid %d: %s\n", (int)getpid(), what);
|
||||
}
|
||||
|
||||
static void announce(void) {
|
||||
if (__atomic_exchange_n(&g_announced, 1, __ATOMIC_RELAXED)) return;
|
||||
char line[96];
|
||||
snprintf(line, sizeof(line), "reported device memory budget %llu MB", (unsigned long long)(g_cap >> 20));
|
||||
say(line);
|
||||
}
|
||||
|
||||
static void clamp_properties2(PFN_vkGetPhysicalDeviceMemoryProperties2 next, VkPhysicalDevice pd,
|
||||
VkPhysicalDeviceMemoryProperties2 *out) {
|
||||
next(pd, out);
|
||||
for (VkBaseOutStructure *s = out->pNext; s; s = s->pNext)
|
||||
if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT) {
|
||||
vramcap_budget(&out->memoryProperties, (VkPhysicalDeviceMemoryBudgetPropertiesEXT *)s, g_cap);
|
||||
if (g_cap) announce();
|
||||
}
|
||||
}
|
||||
|
||||
static void VKAPI_CALL GetMemoryProperties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) {
|
||||
struct inst *in = inst_for(pd);
|
||||
if (in) clamp_properties2(in->mem2, pd, out);
|
||||
}
|
||||
|
||||
static void VKAPI_CALL GetMemoryProperties2KHR(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) {
|
||||
struct inst *in = inst_for(pd);
|
||||
if (in) clamp_properties2(in->mem2_khr, pd, out);
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *ci, const VkAllocationCallbacks *alloc, VkInstance *out) {
|
||||
VkLayerInstanceCreateInfo *link = (VkLayerInstanceCreateInfo *)ci->pNext;
|
||||
while (link && !(link->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && link->function == VK_LAYER_LINK_INFO))
|
||||
link = (VkLayerInstanceCreateInfo *)link->pNext;
|
||||
if (!link) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr next_gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
link->u.pLayerInfo = link->u.pLayerInfo->pNext;
|
||||
PFN_vkCreateInstance create = (PFN_vkCreateInstance)next_gipa(VK_NULL_HANDLE, "vkCreateInstance");
|
||||
if (!create) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
struct inst *in = calloc(1, sizeof(*in));
|
||||
if (!in) return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
VkResult r = create(ci, alloc, out);
|
||||
if (r != VK_SUCCESS) { free(in); return r; }
|
||||
in->handle = *out;
|
||||
in->gipa = next_gipa;
|
||||
in->destroy = (PFN_vkDestroyInstance)next_gipa(*out, "vkDestroyInstance");
|
||||
in->mem2 = (PFN_vkGetPhysicalDeviceMemoryProperties2)next_gipa(*out, "vkGetPhysicalDeviceMemoryProperties2");
|
||||
in->mem2_khr = (PFN_vkGetPhysicalDeviceMemoryProperties2)next_gipa(*out, "vkGetPhysicalDeviceMemoryProperties2KHR");
|
||||
pthread_mutex_lock(&g_lock);
|
||||
in->next_in_list = g_insts;
|
||||
g_insts = in;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *alloc) {
|
||||
struct inst *in = inst_for(instance);
|
||||
if (!in) return;
|
||||
PFN_vkDestroyInstance destroy = in->destroy;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (struct inst **p = &g_insts; *p; p = &(*p)->next_in_list)
|
||||
if (*p == in) { *p = in->next_in_list; break; }
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
free(in);
|
||||
if (destroy) destroy(instance, alloc);
|
||||
}
|
||||
|
||||
static VkLayerDeviceCreateInfo *device_chain(const VkDeviceCreateInfo *ci, VkLayerFunction function) {
|
||||
VkLayerDeviceCreateInfo *c = (VkLayerDeviceCreateInfo *)ci->pNext;
|
||||
while (c && !(c->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && c->function == function))
|
||||
c = (VkLayerDeviceCreateInfo *)c->pNext;
|
||||
return c;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice pd, const VkDeviceCreateInfo *ci, const VkAllocationCallbacks *alloc,
|
||||
VkDevice *out) {
|
||||
VkLayerDeviceCreateInfo *link = device_chain(ci, VK_LAYER_LINK_INFO);
|
||||
if (!link) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
PFN_vkGetInstanceProcAddr next_gipa = link->u.pLayerInfo->pfnNextGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr next_gdpa = link->u.pLayerInfo->pfnNextGetDeviceProcAddr;
|
||||
link->u.pLayerInfo = link->u.pLayerInfo->pNext;
|
||||
struct inst *in = inst_for(pd);
|
||||
PFN_vkCreateDevice create = (PFN_vkCreateDevice)next_gipa(in ? in->handle : VK_NULL_HANDLE, "vkCreateDevice");
|
||||
if (!create) return VK_ERROR_INITIALIZATION_FAILED;
|
||||
struct dev *d = calloc(1, sizeof(*d));
|
||||
if (!d) return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
VkResult r = create(pd, ci, alloc, out);
|
||||
if (r != VK_SUCCESS) { free(d); return r; }
|
||||
d->handle = *out;
|
||||
d->gdpa = next_gdpa;
|
||||
d->destroy = (PFN_vkDestroyDevice)next_gdpa(*out, "vkDestroyDevice");
|
||||
pthread_mutex_lock(&g_lock);
|
||||
d->next_in_list = g_devs;
|
||||
g_devs = d;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *alloc) {
|
||||
struct dev *d = dev_for(device);
|
||||
if (!d) return;
|
||||
pthread_mutex_lock(&g_lock);
|
||||
for (struct dev **p = &g_devs; *p; p = &(*p)->next_in_list)
|
||||
if (*p == d) { *p = d->next_in_list; break; }
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
PFN_vkDestroyDevice destroy = d->destroy;
|
||||
free(d);
|
||||
if (destroy) destroy(device, alloc);
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetDeviceProcAddr(VkDevice device, const char *name);
|
||||
|
||||
EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetInstanceProcAddr(VkInstance instance, const char *name) {
|
||||
if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)CreateInstance;
|
||||
if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)DestroyInstance;
|
||||
if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)CreateDevice;
|
||||
if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)DestroyDevice;
|
||||
if (!strcmp(name, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetInstanceProcAddr;
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetDeviceProcAddr;
|
||||
if (!instance) return NULL;
|
||||
struct inst *in = inst_for(instance);
|
||||
if (!in) return NULL;
|
||||
if (g_cap) {
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2") && in->mem2) return (PFN_vkVoidFunction)GetMemoryProperties2;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2KHR") && in->mem2_khr)
|
||||
return (PFN_vkVoidFunction)GetMemoryProperties2KHR;
|
||||
}
|
||||
return in->gipa(instance, name);
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DroidDeckVramCap_GetDeviceProcAddr(VkDevice device, const char *name) {
|
||||
if (!strcmp(name, "vkGetDeviceProcAddr")) return (PFN_vkVoidFunction)DroidDeckVramCap_GetDeviceProcAddr;
|
||||
if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)DestroyDevice;
|
||||
struct dev *d = dev_for(device);
|
||||
if (!d) return NULL;
|
||||
return d->gdpa(device, name);
|
||||
}
|
||||
|
||||
EXPORT VKAPI_ATTR VkResult VKAPI_CALL DroidDeckVramCap_NegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *v) {
|
||||
if (v->loaderLayerInterfaceVersion > 2) v->loaderLayerInterfaceVersion = 2;
|
||||
v->pfnGetInstanceProcAddr = DroidDeckVramCap_GetInstanceProcAddr;
|
||||
v->pfnGetDeviceProcAddr = DroidDeckVramCap_GetDeviceProcAddr;
|
||||
v->pfnGetPhysicalDeviceProcAddr = NULL;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef VRAMCAP_BUDGET_H
|
||||
#define VRAMCAP_BUDGET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static inline uint64_t vramcap_parse_mb(const char *text) {
|
||||
if (!text || !*text) return 0;
|
||||
uint64_t value = 0, limit = UINT64_MAX >> 20;
|
||||
for (; *text; text++) {
|
||||
if (*text < '0' || *text > '9') return 0;
|
||||
unsigned digit = (unsigned)(*text - '0');
|
||||
if (value > (limit - digit) / 10) return 0;
|
||||
value = value * 10 + digit;
|
||||
}
|
||||
return value << 20;
|
||||
}
|
||||
|
||||
static inline VkDeviceSize vramcap_clamp(VkDeviceSize value, uint64_t cap) {
|
||||
return cap && value > cap ? cap : value;
|
||||
}
|
||||
|
||||
static inline void vramcap_budget(const VkPhysicalDeviceMemoryProperties *p,
|
||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT *budget, uint64_t cap) {
|
||||
for (uint32_t i = 0; i < p->memoryHeapCount && i < VK_MAX_MEMORY_HEAPS; i++)
|
||||
if (p->memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
|
||||
budget->heapBudget[i] = vramcap_clamp(budget->heapBudget[i], cap);
|
||||
budget->heapBudget[i] = vramcap_clamp(budget->heapBudget[i], p->memoryHeaps[i].size);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include "../src/vk_layer_droiddeck_vramcap.c"
|
||||
|
||||
static int instance_dispatch, device_dispatch;
|
||||
static void *instance_object = &instance_dispatch, *physical_object = &instance_dispatch;
|
||||
static void *device_object = &device_dispatch;
|
||||
static VkInstance instance;
|
||||
static VkPhysicalDevice physical;
|
||||
static VkDevice device;
|
||||
static unsigned allocations, frees, destroyed_devices, destroyed_instances;
|
||||
|
||||
static void VKAPI_CALL memory_properties(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties *out) {
|
||||
assert(pd == physical);
|
||||
*out = (VkPhysicalDeviceMemoryProperties){
|
||||
.memoryHeapCount = 3,
|
||||
.memoryHeaps = {{8ULL << 30, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT}, {4ULL << 30, 0},
|
||||
{512ULL << 20, VK_MEMORY_HEAP_DEVICE_LOCAL_BIT}},
|
||||
.memoryTypeCount = 1,
|
||||
.memoryTypes = {{VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0}},
|
||||
};
|
||||
}
|
||||
|
||||
static void VKAPI_CALL memory_properties2(VkPhysicalDevice pd, VkPhysicalDeviceMemoryProperties2 *out) {
|
||||
memory_properties(pd, &out->memoryProperties);
|
||||
for (VkBaseOutStructure *p = out->pNext; p; p = p->pNext)
|
||||
if (p->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT) {
|
||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT *b = (void *)p;
|
||||
b->heapBudget[0] = 6ULL << 30;
|
||||
b->heapBudget[1] = 3ULL << 30;
|
||||
b->heapBudget[2] = 256ULL << 20;
|
||||
b->heapUsage[0] = 3ULL << 30;
|
||||
}
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL allocate(VkDevice d, const VkMemoryAllocateInfo *info,
|
||||
const VkAllocationCallbacks *a, VkDeviceMemory *out) {
|
||||
assert(d == device && info->allocationSize == (3ULL << 30));
|
||||
*out = (VkDeviceMemory)(uintptr_t)++allocations;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL release(VkDevice d, VkDeviceMemory m, const VkAllocationCallbacks *a) {
|
||||
assert(d == device && m);
|
||||
frees++;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL destroy_device(VkDevice d, const VkAllocationCallbacks *a) {
|
||||
assert(d == device);
|
||||
destroyed_devices++;
|
||||
}
|
||||
|
||||
static void VKAPI_CALL destroy_instance(VkInstance in, const VkAllocationCallbacks *a) {
|
||||
assert(in == instance);
|
||||
destroyed_instances++;
|
||||
}
|
||||
|
||||
static PFN_vkVoidFunction VKAPI_CALL gdpa(VkDevice d, const char *name) {
|
||||
assert(d == device);
|
||||
if (!strcmp(name, "vkAllocateMemory")) return (PFN_vkVoidFunction)allocate;
|
||||
if (!strcmp(name, "vkFreeMemory")) return (PFN_vkVoidFunction)release;
|
||||
if (!strcmp(name, "vkDestroyDevice")) return (PFN_vkVoidFunction)destroy_device;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL create_device(VkPhysicalDevice pd, const VkDeviceCreateInfo *ci,
|
||||
const VkAllocationCallbacks *a, VkDevice *out) {
|
||||
assert(pd == physical);
|
||||
*out = device;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VkResult VKAPI_CALL create_instance(const VkInstanceCreateInfo *ci, const VkAllocationCallbacks *a, VkInstance *out) {
|
||||
*out = instance;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static PFN_vkVoidFunction VKAPI_CALL gipa(VkInstance in, const char *name) {
|
||||
assert(in == instance || in == VK_NULL_HANDLE);
|
||||
if (!strcmp(name, "vkCreateInstance")) return (PFN_vkVoidFunction)create_instance;
|
||||
if (!strcmp(name, "vkDestroyInstance")) return (PFN_vkVoidFunction)destroy_instance;
|
||||
if (!strcmp(name, "vkCreateDevice")) return (PFN_vkVoidFunction)create_device;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties")) return (PFN_vkVoidFunction)memory_properties;
|
||||
if (!strcmp(name, "vkGetPhysicalDeviceMemoryProperties2") || !strcmp(name, "vkGetPhysicalDeviceMemoryProperties2KHR"))
|
||||
return (PFN_vkVoidFunction)memory_properties2;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
assert(vramcap_parse_mb("2048") == (2ULL << 30));
|
||||
assert(vramcap_parse_mb(NULL) == 0 && vramcap_parse_mb("") == 0 && vramcap_parse_mb("0") == 0);
|
||||
const char *bad[] = {"-1", "+1", " 1024", "1024 ", "1GB", "18446744073709551616", "17592186044416"};
|
||||
for (size_t i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) assert(vramcap_parse_mb(bad[i]) == 0);
|
||||
assert(vramcap_parse_mb("17592186044415") == ((UINT64_MAX >> 20) << 20));
|
||||
|
||||
instance = (VkInstance)&instance_object;
|
||||
physical = (VkPhysicalDevice)&physical_object;
|
||||
device = (VkDevice)&device_object;
|
||||
g_cap = 2ULL << 30;
|
||||
VkLayerInstanceLink il = {.pfnNextGetInstanceProcAddr = gipa};
|
||||
VkLayerInstanceCreateInfo ic = {.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO,
|
||||
.function = VK_LAYER_LINK_INFO, .u.pLayerInfo = &il};
|
||||
VkInstanceCreateInfo ici = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = &ic};
|
||||
VkInstance got_instance;
|
||||
assert(CreateInstance(&ici, NULL, &got_instance) == VK_SUCCESS && got_instance == instance);
|
||||
VkPhysicalDeviceMemoryProperties p;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties get = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties");
|
||||
assert(get == memory_properties);
|
||||
get(physical, &p);
|
||||
assert(p.memoryHeaps[0].size == (8ULL << 30) && p.memoryHeaps[1].size == (4ULL << 30));
|
||||
assert(p.memoryHeaps[2].size == (512ULL << 20));
|
||||
assert(p.memoryTypes[0].propertyFlags == (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
|
||||
|
||||
const char *names[] = {"vkGetPhysicalDeviceMemoryProperties2", "vkGetPhysicalDeviceMemoryProperties2KHR"};
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT b = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT};
|
||||
VkPhysicalDeviceIDProperties id = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, .pNext = &b};
|
||||
VkPhysicalDeviceMemoryProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, .pNext = &id};
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties2 get2 = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, names[i]);
|
||||
get2(physical, &p2);
|
||||
assert(p2.memoryProperties.memoryHeaps[0].size == (8ULL << 30));
|
||||
assert(b.heapBudget[0] == g_cap && b.heapBudget[1] == (3ULL << 30));
|
||||
assert(b.heapBudget[2] == (256ULL << 20));
|
||||
assert(b.heapUsage[0] == (3ULL << 30));
|
||||
assert(p2.pNext == &id && id.pNext == &b);
|
||||
}
|
||||
|
||||
VkLayerDeviceLink dl = {.pfnNextGetInstanceProcAddr = gipa, .pfnNextGetDeviceProcAddr = gdpa};
|
||||
VkLayerDeviceCreateInfo dc = {.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO,
|
||||
.function = VK_LAYER_LINK_INFO, .u.pLayerInfo = &dl};
|
||||
VkDeviceCreateInfo dci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = &dc};
|
||||
VkDevice got_device;
|
||||
assert(CreateDevice(physical, &dci, NULL, &got_device) == VK_SUCCESS && got_device == device);
|
||||
PFN_vkAllocateMemory next_allocate = (void *)DroidDeckVramCap_GetDeviceProcAddr(device, "vkAllocateMemory");
|
||||
PFN_vkFreeMemory next_free = (void *)DroidDeckVramCap_GetDeviceProcAddr(device, "vkFreeMemory");
|
||||
assert(next_allocate == allocate && next_free == release);
|
||||
VkMemoryAllocateInfo ai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = 3ULL << 30};
|
||||
VkDeviceMemory blocks[2];
|
||||
for (unsigned i = 0; i < 2; i++) assert(next_allocate(device, &ai, NULL, &blocks[i]) == VK_SUCCESS);
|
||||
assert(allocations == 2);
|
||||
for (unsigned i = 0; i < 2; i++) next_free(device, blocks[i], NULL);
|
||||
assert(frees == 2);
|
||||
|
||||
g_cap = 0;
|
||||
assert(DroidDeckVramCap_GetInstanceProcAddr(instance, names[0]) == (PFN_vkVoidFunction)memory_properties2);
|
||||
assert(DroidDeckVramCap_GetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties") == (PFN_vkVoidFunction)memory_properties);
|
||||
PFN_vkDestroyDevice destroy = (void *)DroidDeckVramCap_GetInstanceProcAddr(instance, "vkDestroyDevice");
|
||||
assert(destroy == DestroyDevice);
|
||||
destroy(device, NULL);
|
||||
DestroyInstance(instance, NULL);
|
||||
assert(destroyed_devices == 1 && destroyed_instances == 1 && !g_devs && !g_insts);
|
||||
puts("test_vramcap_budget: ok");
|
||||
return 0;
|
||||
}
|
||||
@@ -360,6 +360,8 @@ def vram_cap(env):
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
result["DROIDDECK_VRAM_CAP"] = "1"
|
||||
result["DROIDDECK_VRAM_CAP_MB"] = value
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ def required():
|
||||
'layer/VK_LAYER_DROIDDECK_vr.json', 'layer/VK_LAYER_DROIDDECK_vr_implicit.json',
|
||||
'layer/libdroiddeck_vr_scheduling.so']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-gpuload/' + name for name in
|
||||
['libVkLayer_droiddeck_gpuload.so', 'VK_LAYER_DROIDDECK_gpu_load.json']]
|
||||
['libVkLayer_droiddeck_gpuload.so', 'VK_LAYER_DROIDDECK_gpu_load.json',
|
||||
'libVkLayer_droiddeck_vramcap.so', 'VK_LAYER_DROIDDECK_vram_cap.json']]
|
||||
for side in ['left', 'right']:
|
||||
paths += [f'assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/resources/rendermodels/droiddeck_hand_{side}/{name}'
|
||||
for name in [f'droiddeck_hand_{side}.json', 'hand.mtl', 'hand.png', 'hand_open.obj', 'hand_fist.obj',
|
||||
|
||||
@@ -747,6 +747,12 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
"dxgi.maxDeviceMemory = 2048; dxvk.maxFrameRate = 60")
|
||||
for off in ({}, {"BL_VRAM_MB": "0"}, {"BL_VRAM_MB": "lots"}, {"BL_VRAM_MB": "²"}, {"BL_VRAM_MB": "-1"}):
|
||||
self.assertNotIn("DXVK_CONFIG", cap(off))
|
||||
self.assertNotIn("DROIDDECK_VRAM_CAP", cap(off))
|
||||
self.assertNotIn("DROIDDECK_VRAM_CAP_MB", cap(off))
|
||||
|
||||
def test_the_vram_cap_also_turns_on_the_vulkan_layer_that_holds_the_game_to_it(self):
|
||||
env = MODULE["vram_cap"]({"BL_VRAM_MB": "3072", "DXVK_CONFIG": "dxgi.maxDeviceMemory = 16384"})
|
||||
self.assertEqual((env["DROIDDECK_VRAM_CAP"], env["DROIDDECK_VRAM_CAP_MB"]), ("1", "3072"))
|
||||
|
||||
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
|
||||
env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"}
|
||||
|
||||
Reference in new issue
Block a user