The xmem idea on NVIDIA under Proton: what works, and where it stops (measurements, no PR) #4508

Open
opened 2026-11-30 21:35:07 +00:00 by github-bot · 1 comment
Owner

@⁠superuser404notfound on GitHub · 2026-11-30 21:32 UTC · original

The xmem idea on NVIDIA under Proton: what works, and where it stops (measurements, no PR)

VIctory-xmem gets its speed on AMD by giving the card the title's memory itself (patched RADV: the title's pages mapped for the GPU, so nothing is copied up, landed back or watched). I tried how far the same idea gets on an NVIDIA card under Proton. Short version: the driver and Proton can be made to do the mechanics, but the title maps the same memory twice, and with VRAM behind it the CPU-side view becomes very slow to read, which xmem avoids with amdgpu kernel features NVIDIA lacks. Writing it down so nobody has to repeat the dead ends.

Setup: RTX 4080 16 GB, NVIDIA 620.73.04, i7-13700KF, 32 GB, CachyOS 7.3.6, Proton Experimental 11.0-20261123b with the view-tree wineserver, vkd3d-proton master 71cae091, main e1251c31 + #2585 + #2034. Resizable BAR on (a 16 GB DEVICE_LOCAL|HOST_VISIBLE type).

1. What the NVIDIA driver can do (native Linux test program)

  • VK_EXT_map_memory_placed is there (memoryMapPlaced true, alignment 4 KiB): ReBAR VRAM is mapped at exactly the address asked for.
  • CPU and GPU see each other's writes through it with no copy. CPU writes 7 GB/s, CPU reads 0.015 GB/s, GPU copies out of it at about 270 GB/s.
  • The same VRAM can be at two addresses at once: export the allocation as an opaque fd, import it a second time, place each VkDeviceMemory at its own address; both see each other's stores. (mremap of the mapping with old size 0 is refused, EFAULT.)
  • What it cannot do, unlike amdgpu: choose the GPU virtual address, or move pages between RAM and VRAM behind one mapping.

2. Getting it through Proton (two small patches, below)

  • winevulkan hides VK_EXT_map_memory_placed from applications (Wine uses it only for WoW64). A plain vkMapMemory of VRAM lands in memory Wine does not know about: VirtualQuery says MEM_FREE and VirtualProtect fails with 87, so our guards cannot work there.
  • Wine (win32u vulkan.c): vkMapMemory2KHR with VK_MEMORY_MAP_PLACED_BIT_EXT and an address is honoured when the application committed that range itself (one or several views side by side). Then VirtualQuery reports committed private memory, VirtualProtect works and a guard fault is caught and resumed normally. GetWriteWatch sees nothing there (not needed when the memory is shared).
  • vkd3d-proton: exporting a shared handle of a committed buffer gives handle 0 under Wine, so instead a buffer whose private data (GUID 5c4f1a00-7e57-4ace-9b1e-501aced00001) holds an address is remapped there on Map, through Wine's path above. A GPU_UPLOAD buffer then sits in VRAM at the chosen address, and D3D12 and the CPU see the same bytes.

3. Using it for renderer port 1's region

Port 1 in system memory is the known 2.6-3.3 fps case (the card reads the 174 MB constants/skinning buffer over the bus), so I tried the same region in VRAM: on the first port::place_in the 174 MB buffer at 0x4c7d0000 is copied, the title's views there become committed memory, a GPU_UPLOAD heap (CREATE_NOT_ZEROED, otherwise vkd3d's deferred clear wipes what was copied in) is placed at that address and handed back as the region. That part works ("title memory in place ... where the title has it").

Then the title stops itself about 1.4 s later (its own Breakpad report, an access violation reading [rcx+0xc] with rcx 0 at image +0x4e9b54a). The cause: the title maps the whole 185 MB section a second time, at 0x577d0000 right after its 32-bit reservation, which is not in the layer's views book. It writes its CPU-side data (a linked list of its own allocator, in the 27 MB GPU-read-only head of the buffer) through that second view. In a normal run the node at 0x4c86fff0 is written there about 60-70 ms after the port places the buffer; the writes do not fault on the read-only first view, they come from title code through the second one. After the move the second view still shows the old pages, so the title never sees its own write.

4. Why I stopped there

Mapping the VRAM at the second address too is possible (section 1, export plus second import), but that view is the one the title's CPU reads through, and from ReBAR VRAM that is about 1,000 times slower than system memory. xmem gets around it with amdgpu GEM objects that can live in GTT or VRAM and move between them; NVIDIA offers no equivalent. So on NVIDIA this would need a split by access pattern (CPU-read pages in RAM, GPU-heavy pages in VRAM) inside a buffer that the GPU sees as one resource, which D3D12 has no sane way to express. I do not think it pays off on this title without that.

Useful for anyone continuing: the second 32-bit view at reservation end + 0x200000 (whole section, offset 0), the CREATE_NOT_ZEROED trap, and that Wine needs the patch below before any placed mapping works for a 64-bit application.

Wine patch (dlls/win32u/vulkan.c)
diff --git a/dlls/win32u/vulkan.c b/dlls/win32u/vulkan.c
index 5401c56..750dd59 100644
--- a/dlls/win32u/vulkan.c
+++ b/dlls/win32u/vulkan.c
@@ -119,11 +119,14 @@ static struct instance *instance_from_handle( VkInstance handle )
     return CONTAINING_RECORD( object, struct instance, obj );
 }
 
+static BOOL schlong_app_placed; /* schlong: host supports placed maps for 64-bit applications */
+
 struct device_memory
 {
     struct vulkan_device_memory obj;
     VkDeviceSize size;
     void *vm_map;
+    BOOL app_placed; /* schlong: vm_map is the application's own committed range */
 
     D3DKMT_HANDLE local;
     D3DKMT_HANDLE global;
@@ -1077,6 +1080,15 @@ static VkResult init_physical_device( struct vulkan_physical_device *physical_de
         }
     }
 
+    /* schlong: let 64-bit applications place mappings into ranges they committed themselves */
+    if (!zero_bits && physical_device->extensions.has_VK_EXT_map_memory_placed && physical_device->extensions.has_VK_KHR_map_memory2)
+    {
+        VkPhysicalDeviceMapMemoryPlacedFeaturesEXT app_placed_feature = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAP_MEMORY_PLACED_FEATURES_EXT};
+        VkPhysicalDeviceFeatures2 app_features = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &app_placed_feature};
+        instance->p_vkGetPhysicalDeviceFeatures2KHR( host_physical_device, &app_features );
+        if (app_placed_feature.memoryMapPlaced && app_placed_feature.memoryUnmapReserve) schlong_app_placed = TRUE;
+    }
+
     if (zero_bits && physical_device->extensions.has_VK_EXT_external_memory_host && !physical_device->map_placed_align)
     {
         VkPhysicalDeviceExternalMemoryHostPropertiesEXT host_mem_props = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT};
@@ -1325,7 +1337,7 @@ static VkResult convert_device_create_info( struct vulkan_physical_device *physi
     if (device->extensions.has_VK_EXT_external_memory_dma_buf)
         device->extensions.has_VK_KHR_external_memory_fd = 1;
 
-    if (physical_device->map_placed_align)
+    if (physical_device->map_placed_align || schlong_app_placed)
     {
         VkPhysicalDeviceMapMemoryPlacedFeaturesEXT *map_placed_features;
 
@@ -1770,7 +1782,7 @@ static void win32u_vkFreeMemory( VkDevice client_device, VkDeviceMemory client_m
     device->p_vkFreeMemory( device->host.device, memory->obj.host.device_memory, NULL );
     instance->p_remove_object( instance, &memory->obj.obj );
 
-    if (memory->vm_map)
+    if (memory->vm_map && !memory->app_placed)
     {
         SIZE_T alloc_size = 0;
         NtFreeVirtualMemory( GetCurrentProcess(), &memory->vm_map, &alloc_size, MEM_RELEASE );
@@ -1852,6 +1864,42 @@ static VkResult win32u_vkMapMemory2KHR( VkDevice client_device, const VkMemoryMa
         return VK_SUCCESS;
     }
 
+    if (schlong_app_placed && !physical_device->map_placed_align && (map_info->flags & VK_MEMORY_MAP_PLACED_BIT_EXT))
+    {
+        const VkMemoryMapPlacedInfoEXT *asked = NULL;
+        const VkBaseInStructure *in;
+        MEMORY_BASIC_INFORMATION mbi;
+        SIZE_T got;
+
+        for (in = map_info->pNext; in; in = in->pNext)
+            if (in->sType == VK_STRUCTURE_TYPE_MEMORY_MAP_PLACED_INFO_EXT) asked = (const VkMemoryMapPlacedInfoEXT *)in;
+        if (!asked || !asked->pPlacedAddress) return VK_ERROR_MEMORY_MAP_FAILED;
+        /* The range must be the application's own committed memory, so that Wine knows the views;
+         * it may be several views side by side (placeholders the application split). */
+        {
+            char *walk = asked->pPlacedAddress, *end = (char *)asked->pPlacedAddress + memory->size;
+            while (walk < end)
+            {
+                if (NtQueryVirtualMemory( GetCurrentProcess(), walk, MemoryBasicInformation, &mbi, sizeof(mbi), &got ) ||
+                    mbi.State != MEM_COMMIT || !mbi.RegionSize)
+                {
+                    WARN( "placed address %p: %p is not committed (range %#llx bytes)\n", asked->pPlacedAddress, walk, (unsigned long long)memory->size );
+                    return VK_ERROR_MEMORY_MAP_FAILED;
+                }
+                walk = (char *)mbi.BaseAddress + mbi.RegionSize;
+            }
+        }
+        info.offset = 0;
+        info.size = VK_WHOLE_SIZE;
+        res = device->p_vkMapMemory2KHR( device->host.device, &info, data );
+        if (res != VK_SUCCESS) { ERR( "app placed map at %p failed: %d\n", asked->pPlacedAddress, res ); return res; }
+        memory->vm_map = asked->pPlacedAddress;
+        memory->app_placed = TRUE;
+        *data = (char *)memory->vm_map + map_info->offset;
+        TRACE( "application placed mapping %p\n", memory->vm_map );
+        return VK_SUCCESS;
+    }
+
     if (physical_device->map_placed_align)
     {
         SIZE_T alloc_size = memory->size;
@@ -1943,6 +1991,14 @@ static VkResult win32u_vkUnmapMemory2KHR( VkDevice client_device, const VkMemory
 
     res = device->p_vkUnmapMemory2KHR( device->host.device, &info );
 
+    if (res == VK_SUCCESS && memory->app_placed)
+    {
+        /* schlong: the range stays the application's; give it fresh anonymous pages again */
+        SIZE_T size = memory->size; void *base = memory->vm_map; ULONG old;
+        NtProtectVirtualMemory( GetCurrentProcess(), &base, &size, PAGE_NOACCESS, &old );
+        memory->vm_map = NULL; memory->app_placed = FALSE;
+        return res;
+    }
     if (res == VK_SUCCESS && memory->vm_map)
     {
         SIZE_T size = 0;
vkd3d-proton patch
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index 08b9e266..7336a83a 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -67,6 +67,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] =
 {
     /* KHR extensions */
     VK_EXTENSION(KHR_PUSH_DESCRIPTOR, KHR_push_descriptor),
+    VK_EXTENSION(KHR_MAP_MEMORY_2, KHR_map_memory2), /* schlong: placed maps */
     VK_EXTENSION(KHR_PIPELINE_LIBRARY, KHR_pipeline_library),
     VK_EXTENSION_DISABLE_COND(KHR_RAY_TRACING_PIPELINE, KHR_ray_tracing_pipeline, VKD3D_CONFIG_FLAG_STATIC(NO_DXR)),
     VK_EXTENSION_DISABLE_COND(KHR_ACCELERATION_STRUCTURE, KHR_acceleration_structure, VKD3D_CONFIG_FLAG_STATIC(NO_DXR)),
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 39e4b0b6..ddfb3ea2 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -2589,6 +2589,67 @@ static bool d3d12_resource_texture_validate_map(struct d3d12_resource *resource)
     return !invalid_map;
 }
 
+/* schlong: a buffer whose private data SCHLONG_PLACE holds an address is mapped exactly there
+ * (VK_EXT_map_memory_placed; the range must be committed by the application, see Wine's win32u patch). */
+static const GUID schlong_place_guid = {0x5c4f1a00, 0x7e57, 0x4ace, {0x9b, 0x1e, 0x50, 0x1a, 0xce, 0xd0, 0x00, 0x01}};
+
+static void schlong_place(struct d3d12_resource *resource)
+{
+    struct d3d12_device *device = resource->device;
+    const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+    struct vkd3d_memory_allocation *mem = &resource->mem;
+    VkMemoryMapPlacedInfoEXT placed;
+    PFN_vkMapMemory2KHR map2;
+    VkMemoryMapInfoKHR info;
+    UINT size = sizeof(void *);
+    void *at = NULL, *out = NULL;
+    VkResult vr;
+
+    if (FAILED(vkd3d_get_private_data(&resource->private_store, &schlong_place_guid, &size, &at)) || !at || size != sizeof(void *))
+        return;
+    if (mem->cpu_address == at)
+        return;
+    if (mem->chunk || mem->offset || !mem->cpu_address)
+    {
+        WARN("schlong: resource %p is not a dedicated mapped allocation (chunk %p, offset %#"PRIx64").\n", resource, mem->chunk, mem->offset);
+        return;
+    }
+    map2 = (PFN_vkMapMemory2KHR)device->vkd3d_instance->vk_procs.vkGetDeviceProcAddr(device->vk_device, "vkMapMemory2KHR");
+    if (!map2)
+    {
+        WARN("schlong: no vkMapMemory2KHR.\n");
+        return;
+    }
+    placed.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_PLACED_INFO_EXT;
+    placed.pNext = NULL;
+    placed.pPlacedAddress = at;
+    info.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_INFO_KHR;
+    info.pNext = &placed;
+    info.flags = VK_MEMORY_MAP_PLACED_BIT_EXT;
+    info.memory = mem->device_allocation.vk_memory;
+    info.offset = 0;
+    info.size = VK_WHOLE_SIZE;
+    VK_CALL(vkUnmapMemory(device->vk_device, mem->device_allocation.vk_memory));
+    vr = map2(device->vk_device, &info, &out);
+    if (vr == VK_SUCCESS && out == at)
+    {
+        TRACE("schlong: resource %p placed at %p.\n", resource, at);
+        mem->cpu_address = at;
+        /* A buffer placed at the start of a heap: the heap's own mapping moved with it. */
+        if (resource->heap && resource->heap->allocation.device_allocation.vk_memory == mem->device_allocation.vk_memory)
+            resource->heap->allocation.cpu_address = at;
+        return;
+    }
+    ERR("schlong: placed map of resource %p at %p failed: vr %d, got %p.\n", resource, at, vr, out);
+    if (vr == VK_SUCCESS)
+    {
+        mem->cpu_address = out;
+        return;
+    }
+    if ((vr = VK_CALL(vkMapMemory(device->vk_device, mem->device_allocation.vk_memory, 0, VK_WHOLE_SIZE, 0, &mem->cpu_address))))
+        ERR("schlong: could not map resource %p again: vr %d.\n", resource, vr);
+}
+
 static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(d3d12_resource_iface *iface, UINT sub_resource,
         const D3D12_RANGE *read_range, void **data)
 {
@@ -2625,6 +2686,9 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(d3d12_resource_iface *iface,
         return E_NOTIMPL;
     }
 
+    if (data && !d3d12_resource_is_texture(resource))
+        schlong_place(resource);
+
     if (data)
     {
         d3d12_resource_get_map_ptr(resource, data);
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 26b09c18..dae4459b 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -143,6 +143,7 @@ struct vkd3d_vulkan_info
     bool KHR_present_wait;
     bool KHR_present_id;
     bool KHR_maintenance5;
+    bool KHR_map_memory2;
     bool KHR_maintenance6;
     bool KHR_maintenance7;
     bool KHR_maintenance8;

🤖 Generated with Claude Code

**@⁠superuser404notfound** on GitHub · 2026-11-30 21:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/4507) ## The xmem idea on NVIDIA under Proton: what works, and where it stops (measurements, no PR) [VIctory-xmem](https://github.com/lobomfz/VIctory-xmem) gets its speed on AMD by giving the card the title's memory itself (patched RADV: the title's pages mapped for the GPU, so nothing is copied up, landed back or watched). I tried how far the same idea gets on an NVIDIA card under Proton. Short version: the driver and Proton can be made to do the mechanics, but the title maps the same memory twice, and with VRAM behind it the CPU-side view becomes very slow to read, which xmem avoids with amdgpu kernel features NVIDIA lacks. Writing it down so nobody has to repeat the dead ends. **Setup:** RTX 4080 16 GB, NVIDIA 620.73.04, i7-13700KF, 32 GB, CachyOS 7.3.6, Proton Experimental 11.0-20261123b with the view-tree wineserver, vkd3d-proton master `71cae091`, main `e1251c31` + #2585 + #2034. Resizable BAR on (a 16 GB DEVICE_LOCAL|HOST_VISIBLE type). ### 1. What the NVIDIA driver can do (native Linux test program) - `VK_EXT_map_memory_placed` is there (`memoryMapPlaced` true, alignment 4 KiB): ReBAR VRAM is mapped at exactly the address asked for. - CPU and GPU see each other's writes through it with no copy. CPU writes 7 GB/s, **CPU reads 0.015 GB/s**, GPU copies out of it at about 270 GB/s. - The same VRAM can be at **two addresses at once**: export the allocation as an opaque fd, import it a second time, place each `VkDeviceMemory` at its own address; both see each other's stores. (`mremap` of the mapping with old size 0 is refused, EFAULT.) - What it cannot do, unlike amdgpu: choose the GPU virtual address, or move pages between RAM and VRAM behind one mapping. ### 2. Getting it through Proton (two small patches, below) - winevulkan hides `VK_EXT_map_memory_placed` from applications (Wine uses it only for WoW64). A plain `vkMapMemory` of VRAM lands in memory Wine does not know about: `VirtualQuery` says MEM_FREE and `VirtualProtect` fails with 87, so our guards cannot work there. - **Wine (win32u `vulkan.c`):** `vkMapMemory2KHR` with `VK_MEMORY_MAP_PLACED_BIT_EXT` and an address is honoured when the application committed that range itself (one or several views side by side). Then `VirtualQuery` reports committed private memory, `VirtualProtect` works and a guard fault is caught and resumed normally. `GetWriteWatch` sees nothing there (not needed when the memory is shared). - **vkd3d-proton:** exporting a shared handle of a committed buffer gives handle 0 under Wine, so instead a buffer whose private data (GUID `5c4f1a00-7e57-4ace-9b1e-501aced00001`) holds an address is remapped there on `Map`, through Wine's path above. A `GPU_UPLOAD` buffer then sits in VRAM at the chosen address, and D3D12 and the CPU see the same bytes. ### 3. Using it for renderer port 1's region Port 1 in system memory is the known 2.6-3.3 fps case (the card reads the 174 MB constants/skinning buffer over the bus), so I tried the same region in VRAM: on the first `port::place_in` the 174 MB buffer at `0x4c7d0000` is copied, the title's views there become committed memory, a `GPU_UPLOAD` heap (`CREATE_NOT_ZEROED`, otherwise vkd3d's deferred clear wipes what was copied in) is placed at that address and handed back as the region. That part works ("title memory in place ... where the title has it"). Then the title stops itself about 1.4 s later (its own Breakpad report, an access violation reading `[rcx+0xc]` with rcx 0 at image +0x4e9b54a). The cause: **the title maps the whole 185 MB section a second time**, at `0x577d0000` right after its 32-bit reservation, which is not in the layer's views book. It writes its CPU-side data (a linked list of its own allocator, in the 27 MB GPU-read-only head of the buffer) through that second view. In a normal run the node at `0x4c86fff0` is written there about 60-70 ms after the port places the buffer; the writes do not fault on the read-only first view, they come from title code through the second one. After the move the second view still shows the old pages, so the title never sees its own write. ### 4. Why I stopped there Mapping the VRAM at the second address too is possible (section 1, export plus second import), but that view is the one the title's CPU **reads** through, and from ReBAR VRAM that is about 1,000 times slower than system memory. xmem gets around it with amdgpu GEM objects that can live in GTT or VRAM and move between them; NVIDIA offers no equivalent. So on NVIDIA this would need a split by access pattern (CPU-read pages in RAM, GPU-heavy pages in VRAM) inside a buffer that the GPU sees as one resource, which D3D12 has no sane way to express. I do not think it pays off on this title without that. Useful for anyone continuing: the second 32-bit view at reservation end + 0x200000 (whole section, offset 0), the `CREATE_NOT_ZEROED` trap, and that Wine needs the patch below before any placed mapping works for a 64-bit application. <details><summary>Wine patch (dlls/win32u/vulkan.c)</summary> ```diff diff --git a/dlls/win32u/vulkan.c b/dlls/win32u/vulkan.c index 5401c56..750dd59 100644 --- a/dlls/win32u/vulkan.c +++ b/dlls/win32u/vulkan.c @@ -119,11 +119,14 @@ static struct instance *instance_from_handle( VkInstance handle ) return CONTAINING_RECORD( object, struct instance, obj ); } +static BOOL schlong_app_placed; /* schlong: host supports placed maps for 64-bit applications */ + struct device_memory { struct vulkan_device_memory obj; VkDeviceSize size; void *vm_map; + BOOL app_placed; /* schlong: vm_map is the application's own committed range */ D3DKMT_HANDLE local; D3DKMT_HANDLE global; @@ -1077,6 +1080,15 @@ static VkResult init_physical_device( struct vulkan_physical_device *physical_de } } + /* schlong: let 64-bit applications place mappings into ranges they committed themselves */ + if (!zero_bits && physical_device->extensions.has_VK_EXT_map_memory_placed && physical_device->extensions.has_VK_KHR_map_memory2) + { + VkPhysicalDeviceMapMemoryPlacedFeaturesEXT app_placed_feature = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAP_MEMORY_PLACED_FEATURES_EXT}; + VkPhysicalDeviceFeatures2 app_features = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = &app_placed_feature}; + instance->p_vkGetPhysicalDeviceFeatures2KHR( host_physical_device, &app_features ); + if (app_placed_feature.memoryMapPlaced && app_placed_feature.memoryUnmapReserve) schlong_app_placed = TRUE; + } + if (zero_bits && physical_device->extensions.has_VK_EXT_external_memory_host && !physical_device->map_placed_align) { VkPhysicalDeviceExternalMemoryHostPropertiesEXT host_mem_props = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT}; @@ -1325,7 +1337,7 @@ static VkResult convert_device_create_info( struct vulkan_physical_device *physi if (device->extensions.has_VK_EXT_external_memory_dma_buf) device->extensions.has_VK_KHR_external_memory_fd = 1; - if (physical_device->map_placed_align) + if (physical_device->map_placed_align || schlong_app_placed) { VkPhysicalDeviceMapMemoryPlacedFeaturesEXT *map_placed_features; @@ -1770,7 +1782,7 @@ static void win32u_vkFreeMemory( VkDevice client_device, VkDeviceMemory client_m device->p_vkFreeMemory( device->host.device, memory->obj.host.device_memory, NULL ); instance->p_remove_object( instance, &memory->obj.obj ); - if (memory->vm_map) + if (memory->vm_map && !memory->app_placed) { SIZE_T alloc_size = 0; NtFreeVirtualMemory( GetCurrentProcess(), &memory->vm_map, &alloc_size, MEM_RELEASE ); @@ -1852,6 +1864,42 @@ static VkResult win32u_vkMapMemory2KHR( VkDevice client_device, const VkMemoryMa return VK_SUCCESS; } + if (schlong_app_placed && !physical_device->map_placed_align && (map_info->flags & VK_MEMORY_MAP_PLACED_BIT_EXT)) + { + const VkMemoryMapPlacedInfoEXT *asked = NULL; + const VkBaseInStructure *in; + MEMORY_BASIC_INFORMATION mbi; + SIZE_T got; + + for (in = map_info->pNext; in; in = in->pNext) + if (in->sType == VK_STRUCTURE_TYPE_MEMORY_MAP_PLACED_INFO_EXT) asked = (const VkMemoryMapPlacedInfoEXT *)in; + if (!asked || !asked->pPlacedAddress) return VK_ERROR_MEMORY_MAP_FAILED; + /* The range must be the application's own committed memory, so that Wine knows the views; + * it may be several views side by side (placeholders the application split). */ + { + char *walk = asked->pPlacedAddress, *end = (char *)asked->pPlacedAddress + memory->size; + while (walk < end) + { + if (NtQueryVirtualMemory( GetCurrentProcess(), walk, MemoryBasicInformation, &mbi, sizeof(mbi), &got ) || + mbi.State != MEM_COMMIT || !mbi.RegionSize) + { + WARN( "placed address %p: %p is not committed (range %#llx bytes)\n", asked->pPlacedAddress, walk, (unsigned long long)memory->size ); + return VK_ERROR_MEMORY_MAP_FAILED; + } + walk = (char *)mbi.BaseAddress + mbi.RegionSize; + } + } + info.offset = 0; + info.size = VK_WHOLE_SIZE; + res = device->p_vkMapMemory2KHR( device->host.device, &info, data ); + if (res != VK_SUCCESS) { ERR( "app placed map at %p failed: %d\n", asked->pPlacedAddress, res ); return res; } + memory->vm_map = asked->pPlacedAddress; + memory->app_placed = TRUE; + *data = (char *)memory->vm_map + map_info->offset; + TRACE( "application placed mapping %p\n", memory->vm_map ); + return VK_SUCCESS; + } + if (physical_device->map_placed_align) { SIZE_T alloc_size = memory->size; @@ -1943,6 +1991,14 @@ static VkResult win32u_vkUnmapMemory2KHR( VkDevice client_device, const VkMemory res = device->p_vkUnmapMemory2KHR( device->host.device, &info ); + if (res == VK_SUCCESS && memory->app_placed) + { + /* schlong: the range stays the application's; give it fresh anonymous pages again */ + SIZE_T size = memory->size; void *base = memory->vm_map; ULONG old; + NtProtectVirtualMemory( GetCurrentProcess(), &base, &size, PAGE_NOACCESS, &old ); + memory->vm_map = NULL; memory->app_placed = FALSE; + return res; + } if (res == VK_SUCCESS && memory->vm_map) { SIZE_T size = 0; ``` </details> <details><summary>vkd3d-proton patch</summary> ```diff diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 08b9e266..7336a83a 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -67,6 +67,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] = { /* KHR extensions */ VK_EXTENSION(KHR_PUSH_DESCRIPTOR, KHR_push_descriptor), + VK_EXTENSION(KHR_MAP_MEMORY_2, KHR_map_memory2), /* schlong: placed maps */ VK_EXTENSION(KHR_PIPELINE_LIBRARY, KHR_pipeline_library), VK_EXTENSION_DISABLE_COND(KHR_RAY_TRACING_PIPELINE, KHR_ray_tracing_pipeline, VKD3D_CONFIG_FLAG_STATIC(NO_DXR)), VK_EXTENSION_DISABLE_COND(KHR_ACCELERATION_STRUCTURE, KHR_acceleration_structure, VKD3D_CONFIG_FLAG_STATIC(NO_DXR)), diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 39e4b0b6..ddfb3ea2 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2589,6 +2589,67 @@ static bool d3d12_resource_texture_validate_map(struct d3d12_resource *resource) return !invalid_map; } +/* schlong: a buffer whose private data SCHLONG_PLACE holds an address is mapped exactly there + * (VK_EXT_map_memory_placed; the range must be committed by the application, see Wine's win32u patch). */ +static const GUID schlong_place_guid = {0x5c4f1a00, 0x7e57, 0x4ace, {0x9b, 0x1e, 0x50, 0x1a, 0xce, 0xd0, 0x00, 0x01}}; + +static void schlong_place(struct d3d12_resource *resource) +{ + struct d3d12_device *device = resource->device; + const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; + struct vkd3d_memory_allocation *mem = &resource->mem; + VkMemoryMapPlacedInfoEXT placed; + PFN_vkMapMemory2KHR map2; + VkMemoryMapInfoKHR info; + UINT size = sizeof(void *); + void *at = NULL, *out = NULL; + VkResult vr; + + if (FAILED(vkd3d_get_private_data(&resource->private_store, &schlong_place_guid, &size, &at)) || !at || size != sizeof(void *)) + return; + if (mem->cpu_address == at) + return; + if (mem->chunk || mem->offset || !mem->cpu_address) + { + WARN("schlong: resource %p is not a dedicated mapped allocation (chunk %p, offset %#"PRIx64").\n", resource, mem->chunk, mem->offset); + return; + } + map2 = (PFN_vkMapMemory2KHR)device->vkd3d_instance->vk_procs.vkGetDeviceProcAddr(device->vk_device, "vkMapMemory2KHR"); + if (!map2) + { + WARN("schlong: no vkMapMemory2KHR.\n"); + return; + } + placed.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_PLACED_INFO_EXT; + placed.pNext = NULL; + placed.pPlacedAddress = at; + info.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_INFO_KHR; + info.pNext = &placed; + info.flags = VK_MEMORY_MAP_PLACED_BIT_EXT; + info.memory = mem->device_allocation.vk_memory; + info.offset = 0; + info.size = VK_WHOLE_SIZE; + VK_CALL(vkUnmapMemory(device->vk_device, mem->device_allocation.vk_memory)); + vr = map2(device->vk_device, &info, &out); + if (vr == VK_SUCCESS && out == at) + { + TRACE("schlong: resource %p placed at %p.\n", resource, at); + mem->cpu_address = at; + /* A buffer placed at the start of a heap: the heap's own mapping moved with it. */ + if (resource->heap && resource->heap->allocation.device_allocation.vk_memory == mem->device_allocation.vk_memory) + resource->heap->allocation.cpu_address = at; + return; + } + ERR("schlong: placed map of resource %p at %p failed: vr %d, got %p.\n", resource, at, vr, out); + if (vr == VK_SUCCESS) + { + mem->cpu_address = out; + return; + } + if ((vr = VK_CALL(vkMapMemory(device->vk_device, mem->device_allocation.vk_memory, 0, VK_WHOLE_SIZE, 0, &mem->cpu_address)))) + ERR("schlong: could not map resource %p again: vr %d.\n", resource, vr); +} + static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(d3d12_resource_iface *iface, UINT sub_resource, const D3D12_RANGE *read_range, void **data) { @@ -2625,6 +2686,9 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(d3d12_resource_iface *iface, return E_NOTIMPL; } + if (data && !d3d12_resource_is_texture(resource)) + schlong_place(resource); + if (data) { d3d12_resource_get_map_ptr(resource, data); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 26b09c18..dae4459b 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -143,6 +143,7 @@ struct vkd3d_vulkan_info bool KHR_present_wait; bool KHR_present_id; bool KHR_maintenance5; + bool KHR_map_memory2; bool KHR_maintenance6; bool KHR_maintenance7; bool KHR_maintenance8; ``` </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:35:07 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-30 21:32 UTC · original

Please attach both logs from the run that went wrong. Without them we can only guess. Paste %LOCALAPPDATA% into the address bar of File Explorer to get there.

  1. The play log, in %LOCALAPPDATA%\victory\logs\: the newest victory-nvidia-play-<date>-<time>-<number>.log (from victory.exe) or victory-nvidia-<date>-<time>.log (from the script launcher). The window shows its path at the start, on the line Log: ....
  2. The crash log: %LOCALAPPDATA%\VIctory\data\7952987A\crashes.log, and, if there is one from that run, the newest victory-<date>-<time>-<number>.crash.log in %LOCALAPPDATA%\VIctory\data\7952987A\temp\.

Also say which GPU, Windows version (10 or 11)

**@⁠github-actions[bot]** on GitHub · 2026-11-30 21:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/4507#issuecomment-7292553666) Please attach both logs from the run that went wrong. Without them we can only guess. Paste `%LOCALAPPDATA%` into the address bar of File Explorer to get there. 1. The play log, in `%LOCALAPPDATA%\victory\logs\`: the newest `victory-nvidia-play-<date>-<time>-<number>.log` (from `victory.exe`) or `victory-nvidia-<date>-<time>.log` (from the script launcher). The window shows its path at the start, on the line `Log: ...`. 2. The crash log: `%LOCALAPPDATA%\VIctory\data\7952987A\crashes.log`, and, if there is one from that run, the newest `victory-<date>-<time>-<number>.crash.log` in `%LOCALAPPDATA%\VIctory\data\7952987A\temp\`. Also say which GPU, Windows version (10 or 11)
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA#4508
No description provided.