diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 021bbccb2..843c81bca 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -293,7 +293,10 @@ bl_xprop_set_all() { export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11 if [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ]; then export VK_LAYER_PATH="$DROIDDECK_QUALCOMM_ROOT/wsi:$DROIDDECK_QUALCOMM_ROOT/lib" - export VK_INSTANCE_LAYERS=VK_LAYER_window_system_integration:VK_LAYER_HYBRIS_compat + # The placed-memory layer acts only for devices that ask for VK_EXT_map_memory_placed: + # Wine does for 32-bit games, whose mapped GPU memory must sit below 4 GiB. + export VK_INSTANCE_LAYERS=VK_LAYER_window_system_integration:VK_LAYER_HYBRIS_compat:VK_LAYER_DROIDDECK_placed_memory + export DROIDDECK_EXPERIMENTAL_PLACED_MEMORY=1 export VK_LOADER_DEBUG=error export WSI_X11_FORCE_SHM=1 DISABLE_GAMESCOPE_WSI=1 . "$DROIDDECK_QUALCOMM_ROOT/mesa/qualcomm-gl.sh" diff --git a/tools/qualcomm/README.md b/tools/qualcomm/README.md index b72b0e738..1a80b0976 100644 --- a/tools/qualcomm/README.md +++ b/tools/qualcomm/README.md @@ -4,7 +4,7 @@ The Linux backend uses the installed Qualcomm Vulkan HAL through a pinned libhyb ## Bridge patch for Android 14 loaders -The bridge creates the Vulkan instance through Android's `libvulkan.so` and then checks that this instance dispatches to the same HAL it loaded itself. Upstream compares only `vkGetPhysicalDeviceProperties`. Android 14's loader wraps that query (seen on an AYANEO Pocket FIT, Adreno 750, Qualcomm 0.762.24, SDK 34): it resolved into `libvulkan.so` while `vkGetPhysicalDeviceFeatures` resolved to the same `vulkan.adreno.so` entry from both sides, so every session failed with `Android instance and configured HAL use different dispatch implementations` and `vkCreateInstance` -9. `hybris-patches/0012-android-loader-wrapped-queries.patch` accepts the instance when any of five core physical-device queries resolves to the HAL's own entry; another driver matches none. `0013-calibrated-timestamps-khr-alias.patch` answers `vkGetPhysicalDeviceCalibrateableTimeDomainsKHR` and `vkGetCalibratedTimestampsKHR` with the HAL's EXT entries when it has only those (same signatures and time-domain values). The same Pocket FIT driver offers only `VK_EXT_calibrated_timestamps`; Zink called the KHR name, the desktop loader found no ICD entry and aborted (`ICD associated with VkPhysicalDevice does not support GetPhysicalDeviceCalibrateableTimeDomainsKHR`), which took down every OpenGL program, including Steam's update window and the browser's `glxinfo` check. `0014-trim-covered-host-memory-types.patch` stops reporting host-visible flags on memory types that another host-visible type of the same heap strictly contains (Pocket FIT: types 3-5 next to cached coherent type 6). No buffer or image there may use types 3-5 (buffers report 0x41, optimal images 0x1, linear 0x41), but DXVK 2.4 picks the first type with the requested flags and skipped type 6, so every DXVK title failed its first upload allocation (`DxvkMemoryAllocator: Memory allocation failed ... Mem types: 0,6`, then a null read in d3d11.dll). Indices and heaps are unchanged; `HYBRIS_VULKAN_KEEP_MEMORY_TYPES=1` reports the driver's flags. The bridge is rebuilt with wallentx's builder (`tools/hybris` at `4ed93fb9`, patches 0001-0011) plus these patches on DroidDeck-Components. +The bridge creates the Vulkan instance through Android's `libvulkan.so` and then checks that this instance dispatches to the same HAL it loaded itself. Upstream compares only `vkGetPhysicalDeviceProperties`. Android 14's loader wraps that query (seen on an AYANEO Pocket FIT, Adreno 750, Qualcomm 0.762.24, SDK 34): it resolved into `libvulkan.so` while `vkGetPhysicalDeviceFeatures` resolved to the same `vulkan.adreno.so` entry from both sides, so every session failed with `Android instance and configured HAL use different dispatch implementations` and `vkCreateInstance` -9. `hybris-patches/0012-android-loader-wrapped-queries.patch` accepts the instance when any of five core physical-device queries resolves to the HAL's own entry; another driver matches none. `0013-calibrated-timestamps-khr-alias.patch` answers `vkGetPhysicalDeviceCalibrateableTimeDomainsKHR` and `vkGetCalibratedTimestampsKHR` with the HAL's EXT entries when it has only those (same signatures and time-domain values). The same Pocket FIT driver offers only `VK_EXT_calibrated_timestamps`; Zink called the KHR name, the desktop loader found no ICD entry and aborted (`ICD associated with VkPhysicalDevice does not support GetPhysicalDeviceCalibrateableTimeDomainsKHR`), which took down every OpenGL program, including Steam's update window and the browser's `glxinfo` check. `0015-placed-memory-dedicated-export.patch` gives the placed-memory layer a mode for drivers that report OPAQUE_FD export as dedicated-only (Qualcomm). There, external buffers and images bind only to dedicated exported memory and cannot use the cached host-visible type, so the layer's export of every eligible resource broke DXVK (`Failed to bind image memory: VK_ERROR_INVALID_EXTERNAL_HANDLE`). In the new mode resources stay native and each host-visible allocation that is not dedicated already is dedicated to a hidden buffer of its size and exported; the driver binds other resources to it, and the dma-buf mapped at Wine's placed address is coherent with the GPU (tested on the Pocket FIT). Without placed mapping, 32-bit DXVK games failed every map (`Failed to map Vulkan memory: VK_ERROR_OUT_OF_HOST_MEMORY`) because the driver maps above 4 GiB. Qualcomm sessions load the layer with `DROIDDECK_EXPERIMENTAL_PLACED_MEMORY=1`; it acts only for devices that request `VK_EXT_map_memory_placed`. `0014-trim-covered-host-memory-types.patch` stops reporting host-visible flags on memory types that another host-visible type of the same heap strictly contains (Pocket FIT: types 3-5 next to cached coherent type 6). No buffer or image there may use types 3-5 (buffers report 0x41, optimal images 0x1, linear 0x41), but DXVK 2.4 picks the first type with the requested flags and skipped type 6, so every DXVK title failed its first upload allocation (`DxvkMemoryAllocator: Memory allocation failed ... Mem types: 0,6`, then a null read in d3d11.dll). Indices and heaps are unchanged; `HYBRIS_VULKAN_KEEP_MEMORY_TYPES=1` reports the driver's flags. The bridge is rebuilt with wallentx's builder (`tools/hybris` at `4ed93fb9`, patches 0001-0011) plus these patches on DroidDeck-Components. ## Imported AdrenoTools Qualcomm packages diff --git a/tools/qualcomm/hybris-patches/0015-placed-memory-dedicated-export.patch b/tools/qualcomm/hybris-patches/0015-placed-memory-dedicated-export.patch new file mode 100644 index 000000000..57031d054 --- /dev/null +++ b/tools/qualcomm/hybris-patches/0015-placed-memory-dedicated-export.patch @@ -0,0 +1,233 @@ +diff --git a/hybris/vulkan/placed/placed_layer.c b/hybris/vulkan/placed/placed_layer.c +index 15bf8f5..9dc8b7d 100644 +--- a/hybris/vulkan/placed/placed_layer.c ++++ b/hybris/vulkan/placed/placed_layer.c +@@ -37,7 +37,7 @@ + #define MAP_FIXED_NOREPLACE 0x100000 + #endif + +-enum backend { BACKEND_UNSUPPORTED, BACKEND_OPAQUE, BACKEND_NATIVE_ALIAS }; ++enum backend { BACKEND_UNSUPPORTED, BACKEND_OPAQUE, BACKEND_NATIVE_ALIAS, BACKEND_DEDICATED_EXPORT }; + + struct alloc { + VkAllocationCallbacks cb; +@@ -162,6 +162,7 @@ struct resource { + }; + struct memory { + VkDeviceMemory h; ++ VkBuffer hidden; + VkDeviceSize size; + int exportable, fd; + void *native, *alias; +@@ -477,10 +478,6 @@ static enum backend select_backend(struct instance *i, VkPhysicalDevice p) { + if (!properties) + return BACKEND_OPAQUE; + properties(p, &props); +- /* Preserve the original OPAQUE_FD path for non-Mali drivers. Some drivers +- * reject a combined capability query while supporting each real resource. */ +- if (props.vendorID != 0x13b5) +- return BACKEND_OPAQUE; + PFN_vkGetPhysicalDeviceExternalBufferProperties f = + (void *)iproc(i, "vkGetPhysicalDeviceExternalBufferProperties"); + if (!f) +@@ -494,11 +491,21 @@ static enum backend select_backend(struct instance *i, VkPhysicalDevice p) { + .handleType = OPAQUE}; + VkExternalBufferProperties out = {.sType = VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES}; + f(p, &in, &out); +- if ((out.externalMemoryProperties.externalMemoryFeatures & +- VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && +- (out.externalMemoryProperties.compatibleHandleTypes & OPAQUE)) ++ VkExternalMemoryFeatureFlags features = out.externalMemoryProperties.externalMemoryFeatures; ++ int exportable = (features & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) && ++ (out.externalMemoryProperties.compatibleHandleTypes & OPAQUE); ++ /* Qualcomm reports OPAQUE_FD export as dedicated-only: external resources then bind ++ * only to dedicated exported memory and cannot use the cached host-visible type. */ ++ if (props.vendorID != 0x13b5 && exportable && ++ (features & VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT)) ++ return BACKEND_DEDICATED_EXPORT; ++ if (exportable) + return BACKEND_OPAQUE; + } ++ /* Preserve the original OPAQUE_FD path for non-Mali drivers. Some drivers ++ * reject a combined capability query while supporting each real resource. */ ++ if (props.vendorID != 0x13b5) ++ return BACKEND_OPAQUE; + return have_mali_mapping_lock() ? BACKEND_NATIVE_ALIAS : BACKEND_UNSUPPORTED; + } + static VkResult VKAPI_CALL l_CreateDevice(VkPhysicalDevice p, const VkDeviceCreateInfo *ci, +@@ -609,7 +616,7 @@ static VkResult VKAPI_CALL l_CreateDevice(VkPhysicalDevice p, const VkDeviceCrea + for (uint32_t n = 0; n < d->props.memoryTypeCount; n++) + if (d->props.memoryTypes[n].propertyFlags & HOST) + d->host_bits |= 1u << n; +- if (d->active && d->backend == BACKEND_OPAQUE && !d->GetMemoryFdKHR) { ++ if (d->active && d->backend != BACKEND_NATIVE_ALIAS && !d->GetMemoryFdKHR) { + d->DestroyDevice(d->h, ac); + result = VK_ERROR_EXTENSION_NOT_PRESENT; + goto failed; +@@ -620,7 +627,10 @@ static VkResult VKAPI_CALL l_CreateDevice(VkPhysicalDevice p, const VkDeviceCrea + pthread_mutex_unlock(&lock); + if (d->active) + fprintf(stderr, "DD_PLACED device active backend=%s page=%zu host_bits=%08x\n", +- d->backend == BACKEND_NATIVE_ALIAS ? "native-alias" : "opaque", page_size(), ++ d->backend == BACKEND_NATIVE_ALIAS ? "native-alias" ++ : d->backend == BACKEND_DEDICATED_EXPORT ? "dedicated-export" ++ : "opaque", ++ page_size(), + d->host_bits); + chain_free(&chain); + dealloc(a, exts); +@@ -794,7 +804,7 @@ static VkResult VKAPI_CALL l_CreateBuffer(VkDevice h, const VkBufferCreateInfo * + return VK_ERROR_INITIALIZATION_FAILED; + if (!d->active) + return d->CreateBuffer(h, ci, ac, out); +- if (d->backend == BACKEND_NATIVE_ALIAS) ++ if (d->backend != BACKEND_OPAQUE) + return d->CreateBuffer(h, ci, ac, out); + if (unsupported_external(ci->pNext, 0)) + return VK_ERROR_INVALID_EXTERNAL_HANDLE; +@@ -845,7 +855,7 @@ static VkResult VKAPI_CALL l_CreateImage(VkDevice h, const VkImageCreateInfo *ci + return VK_ERROR_INITIALIZATION_FAILED; + if (!d->active) + return d->CreateImage(h, ci, ac, out); +- if (d->backend == BACKEND_NATIVE_ALIAS) ++ if (d->backend != BACKEND_OPAQUE) + return d->CreateImage(h, ci, ac, out); + if (unsupported_external(ci->pNext, 1)) + return VK_ERROR_INVALID_EXTERNAL_HANDLE; +@@ -978,7 +988,7 @@ static void VKAPI_CALL l_GetDeviceBufferMemoryRequirements( + d->GetDeviceBufferMemoryRequirements(h, in, out); + return; + } +- if (d->backend == BACKEND_NATIVE_ALIAS) { ++ if (d->backend != BACKEND_OPAQUE) { + d->GetDeviceBufferMemoryRequirements(h, in, out); + return; + } +@@ -1011,7 +1021,7 @@ static void VKAPI_CALL l_GetDeviceImageMemoryRequirements(VkDevice h, + d->GetDeviceImageMemoryRequirements(h, in, out); + return; + } +- if (d->backend == BACKEND_NATIVE_ALIAS) { ++ if (d->backend != BACKEND_OPAQUE) { + d->GetDeviceImageMemoryRequirements(h, in, out); + return; + } +@@ -1051,6 +1061,84 @@ static int allocation_chain_supported(const void *p) { + return 1; + } + static int has_import(const void *p) { return !allocation_chain_supported(p); } ++static void track_memory(struct device *d, struct memory *m) { ++ pthread_mutex_lock(&lock); ++ m->next = d->memories; ++ d->memories = m; ++ pthread_mutex_unlock(&lock); ++} ++/* Resources stay native. A host-visible allocation that is not dedicated already is ++ * dedicated to a hidden buffer of its size so that it can be exported; the driver binds ++ * other resources to it and the layer never uses the buffer. */ ++static VkResult allocate_dedicated_export(struct device *d, VkDevice h, ++ const VkMemoryAllocateInfo *ci, ++ const VkAllocationCallbacks *ac, VkDeviceMemory *out, ++ struct memory *m) { ++ int host = !!(d->host_bits & (1u << ci->memoryTypeIndex)); ++ const VkMemoryDedicatedAllocateInfo *ded = ++ (void *)find_chain(ci->pNext, VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO); ++ int own = ded && (ded->buffer || ded->image); ++ VkResult r; ++ if (!host || has_import(ci->pNext) || ++ find_chain(ci->pNext, VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO)) { ++ r = d->AllocateMemory(h, ci, ac, out); ++ goto done; ++ } ++ VkMemoryAllocateInfo copy = *ci; ++ VkMemoryDedicatedAllocateInfo hidden = {.sType = ++ VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO}; ++ VkExportMemoryAllocateInfo ext = {.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, ++ .handleTypes = OPAQUE}; ++ struct chain_copy chain = {.a = m->a}; ++ if (!own) { ++ VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, ++ .size = ci->allocationSize, ++ .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | ++ VK_BUFFER_USAGE_TRANSFER_DST_BIT, ++ .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; ++ VkMemoryRequirements req = {0}; ++ if (d->CreateBuffer(h, &bi, ac, &m->hidden) == VK_SUCCESS) { ++ d->GetBufferMemoryRequirements(h, m->hidden, &req); ++ if (!(req.memoryTypeBits & (1u << ci->memoryTypeIndex)) || ++ req.size < ci->allocationSize) { ++ d->DestroyBuffer(h, m->hidden, ac); ++ m->hidden = VK_NULL_HANDLE; ++ } ++ } else ++ m->hidden = VK_NULL_HANDLE; ++ if (!m->hidden) { ++ if (atomic_fetch_add(&failure_logs, 1) < 64) ++ fprintf(stderr, "DD_PLACED dedicated-export: no hidden buffer for size=%llu type=%u\n", ++ (unsigned long long)ci->allocationSize, ci->memoryTypeIndex); ++ r = d->AllocateMemory(h, ci, ac, out); ++ goto done; ++ } ++ hidden.buffer = m->hidden; ++ copy.allocationSize = req.size; ++ r = chain_edit(ci->pNext, hidden.sType, &hidden, m->a, &chain); ++ if (r != VK_SUCCESS) ++ goto failed; ++ ext.pNext = chain.head; ++ } else ++ ext.pNext = (void *)ci->pNext; ++ copy.pNext = &ext; ++ r = d->AllocateMemory(h, ©, ac, out); ++ chain_free(&chain); ++ if (r != VK_SUCCESS) ++ goto failed; ++ m->exportable = 1; ++done: ++ if (r != VK_SUCCESS) ++ goto failed; ++ m->h = *out; ++ track_memory(d, m); ++ return VK_SUCCESS; ++failed: ++ if (m->hidden) ++ d->DestroyBuffer(h, m->hidden, ac); ++ dealloc(m->a, m); ++ return r; ++} + static VkResult VKAPI_CALL l_AllocateMemory(VkDevice h, const VkMemoryAllocateInfo *ci, + const VkAllocationCallbacks *ac, VkDeviceMemory *out) { + struct device *d = get_device(h); +@@ -1084,6 +1172,8 @@ static VkResult VKAPI_CALL l_AllocateMemory(VkDevice h, const VkMemoryAllocateIn + pthread_mutex_unlock(&lock); + return VK_SUCCESS; + } ++ if (d->backend == BACKEND_DEDICATED_EXPORT) ++ return allocate_dedicated_export(d, h, ci, ac, out, m); + const VkExportMemoryAllocateInfo *existing = + (void *)find_chain(ci->pNext, VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO); + VkExportMemoryAllocateInfo ext = {.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, +@@ -1176,12 +1266,15 @@ static void VKAPI_CALL l_FreeMemory(VkDevice h, VkDeviceMemory memory, + break; + } + pthread_mutex_unlock(&lock); ++ VkBuffer hidden = m ? m->hidden : VK_NULL_HANDLE; + if (m) { + pthread_mutex_lock(&placement_lock); + cleanup_memory(d, m); + pthread_mutex_unlock(&placement_lock); + } + d->FreeMemory(h, memory, ac); ++ if (hidden) ++ d->DestroyBuffer(h, hidden, ac); + } + static VkResult VKAPI_CALL l_MapMemory(VkDevice h, VkDeviceMemory memory, VkDeviceSize offset, + VkDeviceSize size, VkMemoryMapFlags flags, void **out) { +@@ -1671,6 +1764,8 @@ static void VKAPI_CALL l_DestroyDevice(VkDevice h, const VkAllocationCallbacks * + while (d->memories) { + struct memory *m = d->memories; + d->memories = m->next; ++ if (m->hidden) ++ d->DestroyBuffer(h, m->hidden, m->a.custom ? &m->a.cb : NULL); + pthread_mutex_lock(&placement_lock); + cleanup_memory(d, m); + pthread_mutex_unlock(&placement_lock);