ProjectScarlett runs at 7–10 fps with the GPU ~5% busy: every vkQueueSubmit spends ~13 ms in amdgpu userptr (HMM) validation of the imported title memory #669

Open
opened 2026-12-03 06:53:56 +00:00 by turboheadcrab · 6 comments
turboheadcrab commented 2026-12-03 06:53:56 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by turboheadcrab on 2026-12-03T06:53:56Z.


Summary

The intro movie, loading screens and account picker all run at 7–10 fps on an RX 9070 XT, while the GPU is about 5% busy. Profiling shows that the frame rate is limited by the kernel cost of each command submission. In every DRM_IOCTL_AMDGPU_CS, amdgpu re-walks the page tables of every userptr BO in the submission. Those BOs are the title memory that TuxBox imports through OpenExistingHeapFromAddress* (vkd3d-proton maps that to VK_EXT_external_memory_host). At the intro the game's GTT (drm-total-gtt) is about 1.4 GiB, and each submission costs about 13 ms of CPU time in the kernel, so the queue thread can't submit faster than about 70 times per second. The cost grows linearly with the imported size: a standalone Vulkan program reproduces it at about 8.4 ms per GiB, and after a new game the in-game cost climbs to 56 ms per submission until the title's watchdog fires (tables below).

System

  • TuxBox 106120ca (2026-12-02), packaged build, offline
  • RX 9070 XT (gfx1201), RADV from Mesa 26.3.1, kernel 7.3.5 (Fedora 45 based)
  • GE-Proton through umu
  • Ryzen 7 5800X3D, 32 GB RAM

Measurements (intro movie and loading screen, 2560x1440)

  • Frame rate: presented frames fall from about 600 per 10 s during startup to 72–84 per 10 s once the intro starts. The loading screen after it runs at the same rate.
  • Thread load (top -H): one vkd3d_queue thread at about 99% and one title thread at about 93%. The two Bink decode threads are at about 4% each. GPU busy is about 5%.
  • Time split (/proc/<tid>/stat, utime vs stime):
    • vkd3d_queue: about 0% user, about 98% kernel.
    • Title thread: about 64% user, 36% kernel.
    • Page faults: about 500/s on the queue thread, about 3/s on the title thread, so faults are not the cost.
  • perf record -g, 10 s, cpu-clock, both threads (inclusive shares of the vkd3d_queue thread's samples):
    ~100%  ioctl -> amdgpu_cs_ioctl   (90% under thunk64_vkQueueSubmit2, the rest has unresolved user frames)
     ~94%  amdgpu_cs_parser_bos
     ~90%  amdgpu_ttm_tt_get_user_pages -> amdgpu_hmm_range_get_pages -> hmm_range_fault
           self time: hmm_vma_handle_pte 43%, vm_normal_page 26%, hmm_vma_walk_pmd 12%
    
  • strace -T -e ioctl on the queue thread, 10 s:
    • 685 DRM_IOCTL_AMDGPU_CS calls (about 68 per second, about 9 per frame).
    • Each call: median 13.6 ms, p10 13.4 ms, p90 15.3 ms, max 19.5 ms.
    • Total: 9.61 s of the 10 s inside CS ioctls. The other ioctls (syncobj waits, GEM mmap) are microseconds.
  • Imported size: the DRM client's drm-total-gtt is about 1.4 GiB (TuxBox's ledger reports title pages 7131 MiB, so only part of the title memory is imported).
  • No huge pages: the process has AnonHugePages: 0 kB, and THP is set to madvise. Every page costs a PTE-level walk.
  • The title thread is mostly waiting: its samples are dominated by a yield loop (NtYieldExecution → sched_yield, plus getrusage) in title code. It appears to be waiting on GPU work that is queued behind the slow submissions.

Why this happens

Measured: the walk happens inside every CS (profile above), and its cost scales with the imported size (test below). My reading of the kernel and RADV, not verified in their source: amdgpu_cs_parser_bos calls amdgpu_ttm_tt_get_user_pages for every userptr BO in the submission's BO list, on every CS. It does this whether or not the range was invalidated. RADV appears to put every imported (userptr) allocation into every submission's BO list; the standalone test shows the cost even for an empty command buffer, with or without bufferDeviceAddress. The cost therefore grows with the total size of imported host memory times the number of submissions, and doesn't depend on what is drawn.

The UserptrRanges comment in runtime/d3d12/src/device/placement/lazy.rs already notes that amdgpu HMM validation rejects a CS when any page of a bound userptr BO is inaccessible. This report is about the time that validation takes.

Standalone reproduction (no TuxBox, no game)

A small native Vulkan program (about 110 lines of C, below) reproduces the problem without the game:

  • It imports anonymous, resident memory through VK_EXT_external_memory_host in 256 MiB chunks.
  • It then times 100 submit-and-wait cycles of an empty command buffer.
  • Same machine, RADV from Mesa 26.3.1, kernel 7.3.5.

4 KiB pages (MADV_NOHUGEPAGE), median per submission:

Imported Submit + wait Kernel CPU per submit
0 0.04 ms 0.02 ms
0.25 GiB 2.2 ms 2.1 ms
1 GiB 8.6 ms 8.7 ms
2 GiB 16.9 ms 16.8 ms
4 GiB 33.7 ms 33.7 ms
8 GiB 67.7 ms —
  • The cost grows in a straight line: about 8.4 ms per GiB imported, about 33 ns per 4 KiB page, on every submission. The empty command buffer doesn't reference that memory at all.
  • Turning off bufferDeviceAddress changes nothing (1 GiB: 8.5 ms, 4 GiB: 33.7 ms). RADV puts every imported allocation into every submission either way.
  • 2 MiB transparent huge pages (MADV_HUGEPAGE) cut the cost sharply: 1 GiB goes from 8.6 to 0.53 ms, and 4 GiB to 12.4 ms. At 4 GiB probably only part of the memory got huge pages, because RAM was fragmented with the game running at the same time.

The game's ~14 ms per submission therefore matches roughly 1.6 GiB of 4 KiB-page memory being imported through userptr at that point, out of the 7 GiB of title pages. Not all title pages seem to be imported.

userptr_submit.c
// Measures how vkQueueSubmit cost grows with the amount of host memory imported
// through VK_EXT_external_memory_host (amdgpu userptr BOs on RADV).
//
// For each size it imports anonymous memory in fixed-size chunks, keeps it
// resident, then submits an empty command buffer N times and reports the time
// per submit+wait and the kernel CPU time per submit.
//
// usage: userptr_submit [--no-bda] [--chunk-mib M] [--submits N] SIZE_GIB...
//   --no-bda  don't enable bufferDeviceAddress (vkd3d-proton enables it; on
//             RADV that puts every allocation into every submission)
//   --thp     back the imported memory with 2 MiB transparent huge pages
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <time.h>
#include <vulkan/vulkan.h>

#define CK(x) do { VkResult r_ = (x); if (r_ != VK_SUCCESS) { fprintf(stderr, "%s:%d %s = %d\n", __FILE__, __LINE__, #x, r_); exit(1); } } while (0)

static double now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec + t.tv_nsec / 1e9; }
static void cpu(double *u, double *s) {
    struct rusage r; getrusage(RUSAGE_THREAD, &r);
    *u = r.ru_utime.tv_sec + r.ru_utime.tv_usec / 1e6;
    *s = r.ru_stime.tv_sec + r.ru_stime.tv_usec / 1e6;
}
static int cmp(const void *a, const void *b) { double x = *(const double *)a, y = *(const double *)b; return (x > y) - (x < y); }

int main(int argc, char **argv) {
    int bda = 1, thp = 0, submits = 200; size_t chunk_mib = 256;
    int first = 1;
    for (; first < argc && argv[first][0] == '-'; first++) {
        if (!strcmp(argv[first], "--no-bda")) bda = 0;
        else if (!strcmp(argv[first], "--thp")) thp = 1;
        else if (!strcmp(argv[first], "--chunk-mib") && first + 1 < argc) chunk_mib = strtoul(argv[++first], 0, 10);
        else if (!strcmp(argv[first], "--submits") && first + 1 < argc) submits = atoi(argv[++first]);
        else { fprintf(stderr, "unknown option %s\n", argv[first]); return 2; }
    }
    if (first >= argc) { fprintf(stderr, "usage: %s [--no-bda] [--chunk-mib M] [--submits N] SIZE_GIB...\n", argv[0]); return 2; }

    VkApplicationInfo app = { VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_2 };
    VkInstanceCreateInfo ici = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app };
    VkInstance inst; CK(vkCreateInstance(&ici, 0, &inst));
    uint32_t n = 1; VkPhysicalDevice pd; vkEnumeratePhysicalDevices(inst, &n, &pd);
    if (!n) { fprintf(stderr, "no Vulkan device\n"); return 1; }

    VkPhysicalDeviceExternalMemoryHostPropertiesEXT hostp = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT };
    VkPhysicalDeviceVulkan12Properties p12 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES, .pNext = &hostp };
    VkPhysicalDeviceProperties2 props = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &p12 };
    vkGetPhysicalDeviceProperties2(pd, &props);
    printf("device: %s, driver: %s %s\n", props.properties.deviceName, p12.driverName, p12.driverInfo);
    printf("huge pages: %s, bufferDeviceAddress: %s, chunk: %zu MiB, submits per size: %d\n", thp ? "on" : "off", bda ? "on" : "off", chunk_mib, submits);

    float prio = 1;
    VkDeviceQueueCreateInfo qci = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .queueFamilyIndex = 0, .queueCount = 1, .pQueuePriorities = &prio };
    VkPhysicalDeviceVulkan12Features f12 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, .bufferDeviceAddress = bda };
    const char *ext[] = { "VK_EXT_external_memory_host" };
    VkDeviceCreateInfo dci = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = &f12, .queueCreateInfoCount = 1, .pQueueCreateInfos = &qci, .enabledExtensionCount = 1, .ppEnabledExtensionNames = ext };
    VkDevice dev; CK(vkCreateDevice(pd, &dci, 0, &dev));
    VkQueue q; vkGetDeviceQueue(dev, 0, 0, &q);
    PFN_vkGetMemoryHostPointerPropertiesEXT getHostProps = (PFN_vkGetMemoryHostPointerPropertiesEXT)vkGetDeviceProcAddr(dev, "vkGetMemoryHostPointerPropertiesEXT");

    VkCommandPoolCreateInfo pci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .queueFamilyIndex = 0 };
    VkCommandPool pool; CK(vkCreateCommandPool(dev, &pci, 0, &pool));
    VkCommandBufferAllocateInfo cai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, .commandPool = pool, .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, .commandBufferCount = 1 };
    VkCommandBuffer cb; CK(vkAllocateCommandBuffers(dev, &cai, &cb));
    VkCommandBufferBeginInfo bi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
    CK(vkBeginCommandBuffer(cb, &bi)); CK(vkEndCommandBuffer(cb));
    VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
    VkFence fence; CK(vkCreateFence(dev, &fci, 0, &fence));

    size_t chunk = chunk_mib << 20, imported = 0;
    VkDeviceMemory *mems = 0; size_t nmem = 0;
    double *t = malloc(sizeof(double) * submits);
    printf("\n%9s %8s %10s %10s %10s %14s\n", "imported", "chunks", "median_ms", "p10_ms", "p90_ms", "kernel_ms/sub");
    for (int a = first; a < argc; a++) {
        size_t want = (size_t)(atof(argv[a]) * (1 << 30));
        while (imported + chunk <= want) {
            void *p = mmap(0, chunk, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
            if (p == MAP_FAILED) { perror("mmap"); return 1; }
            madvise(p, chunk, thp ? MADV_HUGEPAGE : MADV_NOHUGEPAGE); // default 4 KiB pages, like the imported title memory
            memset(p, 1, chunk);                // resident, like the title memory
            VkMemoryHostPointerPropertiesEXT hp = { VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT };
            CK(getHostProps(dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, p, &hp));
            VkMemoryAllocateFlagsInfo flags = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO, .flags = bda ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0 };
            VkImportMemoryHostPointerInfoEXT imp = { VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT, .pNext = &flags, .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, .pHostPointer = p };
            VkMemoryAllocateInfo mai = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &imp, .allocationSize = chunk, .memoryTypeIndex = (uint32_t)__builtin_ctz(hp.memoryTypeBits) };
            mems = realloc(mems, sizeof(*mems) * (nmem + 1));
            CK(vkAllocateMemory(dev, &mai, 0, &mems[nmem++]));
            imported += chunk;
        }
        VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cb };
        for (int i = 0; i < 5; i++) { CK(vkQueueSubmit(q, 1, &si, fence)); CK(vkWaitForFences(dev, 1, &fence, 1, UINT64_MAX)); CK(vkResetFences(dev, 1, &fence)); }
        double u0, s0, u1, s1; cpu(&u0, &s0);
        for (int i = 0; i < submits; i++) {
            double t0 = now();
            CK(vkQueueSubmit(q, 1, &si, fence));
            CK(vkWaitForFences(dev, 1, &fence, 1, UINT64_MAX));
            t[i] = (now() - t0) * 1000;
            CK(vkResetFences(dev, 1, &fence));
        }
        cpu(&u1, &s1);
        qsort(t, submits, sizeof(double), cmp);
        printf("%7.2f GiB %8zu %10.3f %10.3f %10.3f %14.3f\n", imported / (double)(1 << 30), nmem,
               t[submits / 2], t[submits / 10], t[submits * 9 / 10], (s1 - s0) * 1000 / submits);
        fflush(stdout);
    }
    return 0;
}

In-game check: at the loading screen, the game's DRM client reports drm-total-gtt 1.38 GiB in /proc/<pid>/fdinfo. At 8.4 ms per GiB that predicts about 11.6 ms per submission. The measurement was 12.6–13.6 ms.

#666 (duplicate GPU page cluster imports since 106120ca, GTT growing to 18–27 GiB until RADV loses the device) is the same mechanism made worse:

  • Every one of those duplicate userptr BOs is also walked on every submission.
  • At 8.4 ms per GiB (standalone test), 5 GiB of imports means about 40 ms per CS, and 9.4 GiB about 80 ms. With about 9 submissions per frame, the frame rate collapses well before the device is lost.

This report is about the base cost that remains without duplicates: about 1.4 GiB of imports already costs about 12 ms per submission. That is the 7–10 fps intro and loading screen on 106120ca. #667 stops the runaway, but the imported size still grows during play, and the cost with it (table below).

Measured on this card, starting a new game, sampled every minute (drm-total-gtt from fdinfo, median DRM_IOCTL_AMDGPU_CS time over 3 s, presented frames per 10 s):

Build GTT CS per second CS median Frames per 10 s
106120ca 1.4 GiB (intro) 69 13.2 ms 72
106120ca 1.7 GiB 43 18.1 ms 50
106120ca 19.2 GiB — — device lost (Not enough memory for command submission), exit 3 at 750 s
#667 (2898c907) 1.4 GiB (intro) 74 12.6 ms 72
#667 1.5 GiB 60 14.4 ms 58
#667 2.9 GiB 17 26.3 ms 17
#667 3.0 GiB 24 38.2 ms 24
#667 4.1 GiB 18 52.0 ms 10
#667 4.3 GiB 9 56.2 ms 14
#667 — — — watchdog exe+0x23CF683, exit 5 at 938 s
  • #667 fixes the runaway on this card: GTT topped out at 4.3 GiB instead of 19 GiB, with no device loss.
  • The submission cost still follows GTT, rising from 13 ms to 56 ms. The game fell to 1–1.7 fps and then hit the title's 30 s main-thread watchdog (#215's address).
  • That watchdog may simply be how frames this slow end. The #666 author also saw it after their local fix.

Checked against the latest main (106120ca) and #667 on 2026-12-03.

Ideas (for the maintainers to judge)

  • Import only the ranges the GPU actually reads, and drop the imports when they're no longer needed, instead of whole title regions.
  • Keep GPU-only resources in device memory and copy into them, instead of aliasing title pages through userptr.
  • Submit fewer, larger batches: the cost is per CS, so 9 submissions per frame means 9 full walks.
  • Back the imported ranges with 2 MiB huge pages. This looks like the most promising fix: in the standalone test it made submissions about 16 times cheaper. But TuxBox has to arrange it itself, because changing the system setting doesn't help as things are. With THP set to always, only about 1 GiB of the 6 GiB resident memory became huge pages. The median CS time went from 13.6 to 12.6 ms (737 submissions in 10 s), and the intro stayed at 74–75 frames per 10 s. The imported title ranges apparently stay at 4 KiB pages, perhaps because of their alignment or per-page protection changes. Huge-page backing that TuxBox arranges itself (2 MiB-aligned reservations, no per-page protection changes) might do better.
<!-- greyfinch-sync:brcly/TuxBox:issue:6762679694 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669). Originally posted by [turboheadcrab](https://github.com/turboheadcrab) on 2026-12-03T06:53:56Z. --- ## Summary The intro movie, loading screens and account picker all run at 7–10 fps on an RX 9070 XT, while the GPU is about 5% busy. Profiling shows that the frame rate is limited by the kernel cost of each command submission. In every `DRM_IOCTL_AMDGPU_CS`, amdgpu re-walks the page tables of every userptr BO in the submission. Those BOs are the title memory that TuxBox imports through `OpenExistingHeapFromAddress*` (vkd3d-proton maps that to `VK_EXT_external_memory_host`). At the intro the game's GTT (`drm-total-gtt`) is about 1.4 GiB, and each submission costs about 13 ms of CPU time in the kernel, so the queue thread can't submit faster than about 70 times per second. The cost grows linearly with the imported size: a standalone Vulkan program reproduces it at about 8.4 ms per GiB, and after a new game the in-game cost climbs to 56 ms per submission until the title's watchdog fires (tables below). ## System - TuxBox 106120ca (2026-12-02), packaged build, offline - RX 9070 XT (gfx1201), RADV from Mesa 26.3.1, kernel 7.3.5 (Fedora 45 based) - GE-Proton through umu - Ryzen 7 5800X3D, 32 GB RAM ## Measurements (intro movie and loading screen, 2560x1440) - **Frame rate:** presented frames fall from about 600 per 10 s during startup to 72–84 per 10 s once the intro starts. The loading screen after it runs at the same rate. - **Thread load (`top -H`):** one `vkd3d_queue` thread at about 99% and one title thread at about 93%. The two Bink decode threads are at about 4% each. GPU busy is about 5%. - **Time split (`/proc/<tid>/stat`, utime vs stime):** - `vkd3d_queue`: about 0% user, **about 98% kernel**. - Title thread: about 64% user, 36% kernel. - Page faults: about 500/s on the queue thread, about 3/s on the title thread, so faults are not the cost. - **`perf record -g`, 10 s, cpu-clock, both threads** (inclusive shares of the `vkd3d_queue` thread's samples): ``` ~100% ioctl -> amdgpu_cs_ioctl (90% under thunk64_vkQueueSubmit2, the rest has unresolved user frames) ~94% amdgpu_cs_parser_bos ~90% amdgpu_ttm_tt_get_user_pages -> amdgpu_hmm_range_get_pages -> hmm_range_fault self time: hmm_vma_handle_pte 43%, vm_normal_page 26%, hmm_vma_walk_pmd 12% ``` - **`strace -T -e ioctl` on the queue thread, 10 s:** - 685 `DRM_IOCTL_AMDGPU_CS` calls (about 68 per second, about 9 per frame). - Each call: median 13.6 ms, p10 13.4 ms, p90 15.3 ms, max 19.5 ms. - Total: 9.61 s of the 10 s inside CS ioctls. The other ioctls (syncobj waits, GEM mmap) are microseconds. - **Imported size:** the DRM client's `drm-total-gtt` is about 1.4 GiB (TuxBox's ledger reports `title pages 7131 MiB`, so only part of the title memory is imported). - **No huge pages:** the process has `AnonHugePages: 0 kB`, and THP is set to `madvise`. Every page costs a PTE-level walk. - **The title thread is mostly waiting:** its samples are dominated by a yield loop (`NtYieldExecution` → `sched_yield`, plus `getrusage`) in title code. It appears to be waiting on GPU work that is queued behind the slow submissions. ## Why this happens Measured: the walk happens inside every CS (profile above), and its cost scales with the imported size (test below). My reading of the kernel and RADV, not verified in their source: `amdgpu_cs_parser_bos` calls `amdgpu_ttm_tt_get_user_pages` for every userptr BO in the submission's BO list, on every CS. It does this whether or not the range was invalidated. RADV appears to put every imported (userptr) allocation into every submission's BO list; the standalone test shows the cost even for an empty command buffer, with or without `bufferDeviceAddress`. The cost therefore grows with the total size of imported host memory times the number of submissions, and doesn't depend on what is drawn. The `UserptrRanges` comment in `runtime/d3d12/src/device/placement/lazy.rs` already notes that amdgpu HMM validation rejects a CS when any page of a bound userptr BO is inaccessible. This report is about the time that validation takes. ## Standalone reproduction (no TuxBox, no game) A small native Vulkan program (about 110 lines of C, below) reproduces the problem without the game: - It imports anonymous, resident memory through `VK_EXT_external_memory_host` in 256 MiB chunks. - It then times 100 submit-and-wait cycles of an **empty** command buffer. - Same machine, RADV from Mesa 26.3.1, kernel 7.3.5. 4 KiB pages (`MADV_NOHUGEPAGE`), median per submission: | Imported | Submit + wait | Kernel CPU per submit | |---|---|---| | 0 | 0.04 ms | 0.02 ms | | 0.25 GiB | 2.2 ms | 2.1 ms | | 1 GiB | 8.6 ms | 8.7 ms | | 2 GiB | 16.9 ms | 16.8 ms | | 4 GiB | 33.7 ms | 33.7 ms | | 8 GiB | 67.7 ms | — | - **The cost grows in a straight line: about 8.4 ms per GiB imported, about 33 ns per 4 KiB page, on every submission.** The empty command buffer doesn't reference that memory at all. - **Turning off `bufferDeviceAddress` changes nothing** (1 GiB: 8.5 ms, 4 GiB: 33.7 ms). RADV puts every imported allocation into every submission either way. - **2 MiB transparent huge pages (`MADV_HUGEPAGE`) cut the cost sharply:** 1 GiB goes from 8.6 to **0.53 ms**, and 4 GiB to 12.4 ms. At 4 GiB probably only part of the memory got huge pages, because RAM was fragmented with the game running at the same time. The game's ~14 ms per submission therefore matches roughly 1.6 GiB of 4 KiB-page memory being imported through userptr at that point, out of the 7 GiB of title pages. Not all title pages seem to be imported. <details><summary>userptr_submit.c</summary> ```c // Measures how vkQueueSubmit cost grows with the amount of host memory imported // through VK_EXT_external_memory_host (amdgpu userptr BOs on RADV). // // For each size it imports anonymous memory in fixed-size chunks, keeps it // resident, then submits an empty command buffer N times and reports the time // per submit+wait and the kernel CPU time per submit. // // usage: userptr_submit [--no-bda] [--chunk-mib M] [--submits N] SIZE_GIB... // --no-bda don't enable bufferDeviceAddress (vkd3d-proton enables it; on // RADV that puts every allocation into every submission) // --thp back the imported memory with 2 MiB transparent huge pages #define _GNU_SOURCE #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <sys/resource.h> #include <time.h> #include <vulkan/vulkan.h> #define CK(x) do { VkResult r_ = (x); if (r_ != VK_SUCCESS) { fprintf(stderr, "%s:%d %s = %d\n", __FILE__, __LINE__, #x, r_); exit(1); } } while (0) static double now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec + t.tv_nsec / 1e9; } static void cpu(double *u, double *s) { struct rusage r; getrusage(RUSAGE_THREAD, &r); *u = r.ru_utime.tv_sec + r.ru_utime.tv_usec / 1e6; *s = r.ru_stime.tv_sec + r.ru_stime.tv_usec / 1e6; } static int cmp(const void *a, const void *b) { double x = *(const double *)a, y = *(const double *)b; return (x > y) - (x < y); } int main(int argc, char **argv) { int bda = 1, thp = 0, submits = 200; size_t chunk_mib = 256; int first = 1; for (; first < argc && argv[first][0] == '-'; first++) { if (!strcmp(argv[first], "--no-bda")) bda = 0; else if (!strcmp(argv[first], "--thp")) thp = 1; else if (!strcmp(argv[first], "--chunk-mib") && first + 1 < argc) chunk_mib = strtoul(argv[++first], 0, 10); else if (!strcmp(argv[first], "--submits") && first + 1 < argc) submits = atoi(argv[++first]); else { fprintf(stderr, "unknown option %s\n", argv[first]); return 2; } } if (first >= argc) { fprintf(stderr, "usage: %s [--no-bda] [--chunk-mib M] [--submits N] SIZE_GIB...\n", argv[0]); return 2; } VkApplicationInfo app = { VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_2 }; VkInstanceCreateInfo ici = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app }; VkInstance inst; CK(vkCreateInstance(&ici, 0, &inst)); uint32_t n = 1; VkPhysicalDevice pd; vkEnumeratePhysicalDevices(inst, &n, &pd); if (!n) { fprintf(stderr, "no Vulkan device\n"); return 1; } VkPhysicalDeviceExternalMemoryHostPropertiesEXT hostp = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT }; VkPhysicalDeviceVulkan12Properties p12 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES, .pNext = &hostp }; VkPhysicalDeviceProperties2 props = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &p12 }; vkGetPhysicalDeviceProperties2(pd, &props); printf("device: %s, driver: %s %s\n", props.properties.deviceName, p12.driverName, p12.driverInfo); printf("huge pages: %s, bufferDeviceAddress: %s, chunk: %zu MiB, submits per size: %d\n", thp ? "on" : "off", bda ? "on" : "off", chunk_mib, submits); float prio = 1; VkDeviceQueueCreateInfo qci = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, .queueFamilyIndex = 0, .queueCount = 1, .pQueuePriorities = &prio }; VkPhysicalDeviceVulkan12Features f12 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, .bufferDeviceAddress = bda }; const char *ext[] = { "VK_EXT_external_memory_host" }; VkDeviceCreateInfo dci = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = &f12, .queueCreateInfoCount = 1, .pQueueCreateInfos = &qci, .enabledExtensionCount = 1, .ppEnabledExtensionNames = ext }; VkDevice dev; CK(vkCreateDevice(pd, &dci, 0, &dev)); VkQueue q; vkGetDeviceQueue(dev, 0, 0, &q); PFN_vkGetMemoryHostPointerPropertiesEXT getHostProps = (PFN_vkGetMemoryHostPointerPropertiesEXT)vkGetDeviceProcAddr(dev, "vkGetMemoryHostPointerPropertiesEXT"); VkCommandPoolCreateInfo pci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .queueFamilyIndex = 0 }; VkCommandPool pool; CK(vkCreateCommandPool(dev, &pci, 0, &pool)); VkCommandBufferAllocateInfo cai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, .commandPool = pool, .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, .commandBufferCount = 1 }; VkCommandBuffer cb; CK(vkAllocateCommandBuffers(dev, &cai, &cb)); VkCommandBufferBeginInfo bi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; CK(vkBeginCommandBuffer(cb, &bi)); CK(vkEndCommandBuffer(cb)); VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO }; VkFence fence; CK(vkCreateFence(dev, &fci, 0, &fence)); size_t chunk = chunk_mib << 20, imported = 0; VkDeviceMemory *mems = 0; size_t nmem = 0; double *t = malloc(sizeof(double) * submits); printf("\n%9s %8s %10s %10s %10s %14s\n", "imported", "chunks", "median_ms", "p10_ms", "p90_ms", "kernel_ms/sub"); for (int a = first; a < argc; a++) { size_t want = (size_t)(atof(argv[a]) * (1 << 30)); while (imported + chunk <= want) { void *p = mmap(0, chunk, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { perror("mmap"); return 1; } madvise(p, chunk, thp ? MADV_HUGEPAGE : MADV_NOHUGEPAGE); // default 4 KiB pages, like the imported title memory memset(p, 1, chunk); // resident, like the title memory VkMemoryHostPointerPropertiesEXT hp = { VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT }; CK(getHostProps(dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, p, &hp)); VkMemoryAllocateFlagsInfo flags = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO, .flags = bda ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0 }; VkImportMemoryHostPointerInfoEXT imp = { VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT, .pNext = &flags, .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, .pHostPointer = p }; VkMemoryAllocateInfo mai = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &imp, .allocationSize = chunk, .memoryTypeIndex = (uint32_t)__builtin_ctz(hp.memoryTypeBits) }; mems = realloc(mems, sizeof(*mems) * (nmem + 1)); CK(vkAllocateMemory(dev, &mai, 0, &mems[nmem++])); imported += chunk; } VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cb }; for (int i = 0; i < 5; i++) { CK(vkQueueSubmit(q, 1, &si, fence)); CK(vkWaitForFences(dev, 1, &fence, 1, UINT64_MAX)); CK(vkResetFences(dev, 1, &fence)); } double u0, s0, u1, s1; cpu(&u0, &s0); for (int i = 0; i < submits; i++) { double t0 = now(); CK(vkQueueSubmit(q, 1, &si, fence)); CK(vkWaitForFences(dev, 1, &fence, 1, UINT64_MAX)); t[i] = (now() - t0) * 1000; CK(vkResetFences(dev, 1, &fence)); } cpu(&u1, &s1); qsort(t, submits, sizeof(double), cmp); printf("%7.2f GiB %8zu %10.3f %10.3f %10.3f %14.3f\n", imported / (double)(1 << 30), nmem, t[submits / 2], t[submits / 10], t[submits * 9 / 10], (s1 - s0) * 1000 / submits); fflush(stdout); } return 0; } ``` </details> **In-game check:** at the loading screen, the game's DRM client reports `drm-total-gtt` 1.38 GiB in `/proc/<pid>/fdinfo`. At 8.4 ms per GiB that predicts about 11.6 ms per submission. The measurement was 12.6–13.6 ms. ## Related: #666 #666 (duplicate GPU page cluster imports since 106120ca, GTT growing to 18–27 GiB until RADV loses the device) is the same mechanism made worse: - Every one of those duplicate userptr BOs is also walked on every submission. - At 8.4 ms per GiB (standalone test), 5 GiB of imports means about 40 ms per CS, and 9.4 GiB about 80 ms. With about 9 submissions per frame, the frame rate collapses well before the device is lost. This report is about the base cost that remains without duplicates: about 1.4 GiB of imports already costs about 12 ms per submission. That is the 7–10 fps intro and loading screen on 106120ca. #667 stops the runaway, but the imported size still grows during play, and the cost with it (table below). **Measured on this card, starting a new game, sampled every minute** (`drm-total-gtt` from fdinfo, median `DRM_IOCTL_AMDGPU_CS` time over 3 s, presented frames per 10 s): | Build | GTT | CS per second | CS median | Frames per 10 s | |---|---|---|---|---| | 106120ca | 1.4 GiB (intro) | 69 | 13.2 ms | 72 | | 106120ca | 1.7 GiB | 43 | 18.1 ms | 50 | | 106120ca | 19.2 GiB | — | — | device lost (`Not enough memory for command submission`), exit 3 at 750 s | | #667 (2898c907) | 1.4 GiB (intro) | 74 | 12.6 ms | 72 | | #667 | 1.5 GiB | 60 | 14.4 ms | 58 | | #667 | 2.9 GiB | 17 | 26.3 ms | 17 | | #667 | 3.0 GiB | 24 | 38.2 ms | 24 | | #667 | 4.1 GiB | 18 | 52.0 ms | 10 | | #667 | 4.3 GiB | 9 | 56.2 ms | 14 | | #667 | — | — | — | watchdog `exe+0x23CF683`, exit 5 at 938 s | - #667 fixes the runaway on this card: GTT topped out at 4.3 GiB instead of 19 GiB, with no device loss. - The submission cost still follows GTT, rising from 13 ms to 56 ms. The game fell to 1–1.7 fps and then hit the title's 30 s main-thread watchdog (#215's address). - That watchdog may simply be how frames this slow end. The #666 author also saw it after their local fix. Checked against the latest main (106120ca) and #667 on 2026-12-03. ## Ideas (for the maintainers to judge) - Import only the ranges the GPU actually reads, and drop the imports when they're no longer needed, instead of whole title regions. - Keep GPU-only resources in device memory and copy into them, instead of aliasing title pages through userptr. - Submit fewer, larger batches: the cost is per CS, so 9 submissions per frame means 9 full walks. - Back the imported ranges with 2 MiB huge pages. This looks like the most promising fix: in the standalone test it made submissions about 16 times cheaper. But TuxBox has to arrange it itself, because changing the system setting doesn't help as things are. With THP set to `always`, only about 1 GiB of the 6 GiB resident memory became huge pages. The median CS time went from 13.6 to 12.6 ms (737 submissions in 10 s), and the intro stayed at 74–75 frames per 10 s. The imported title ranges apparently stay at 4 KiB pages, perhaps because of their alignment or per-page protection changes. Huge-page backing that TuxBox arranges itself (2 MiB-aligned reservations, no per-page protection changes) might do better.
JeffreyBytes commented 2026-12-03 07:36:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T07:36:52Z.


Same thing here on an RX 6700 XT (RDNA 2, 12 GB), RADV from Mesa 26.3.1, GE-Proton11-15, 32 GB RAM. I spent tonight bisecting it, so here's where the AMD side broke.

To keep shader prep out of the way I ran each older commit's providers with today's translator and DXC helper (TUXBOX_XSHADER / TUXBOX_PERSISTENT_DXC pointed at the current build). The only translator change between these commits and main is #534, so every run used the same runtime shader cache and only the providers differ.

Commit What happens
6d4f1cd7 (parent of 9c3cf86f) Intro video plays. Got further into the load than I've ever gotten on AMD, though at ~0.2 fps. No exit 5. It ran 531 s past the account picker and ended in a gfx ring page fault (TCP PERMISSION_FAULTS 0x3), which I also see on #667 builds, so I think that one is separate.
9c3cf86f Solid green intro video. RADV refuses the queue page mappings (E_NOTIMPL).
a789a4e4 (right before 106120ca) Green intro and cutscene videos, loading screen with no images, 0.3 fps. Ended in a title int3 at exe+0x5149AEC (exit 3) at 881 s.
106120ca + #667 Videos are back, but every run that doesn't hit the page fault above ends in the exe+0x23CF683 watchdog (exit 5), 150–300 s after the account picker.

So 6d4f1cd7 is the last commit before the AMD regression. 9c3cf86f breaks it (green screens), and 106120ca fixes the refusals by moving RADV to private backing, which turns it into the submission cost described here.

What I measured on 106120ca + #667 lines up with the numbers above:

  • The busiest vkd3d_queue thread is 85–90% kernel time for most of the run. perf has nearly all of it in amdgpu_cs_ioctl, mostly hmm_range_fault and amdgpu_vm_bo_update.
  • At the world load the live userptr imports jump from about 1.2k to 10–14k within ~500 frames, most of them single 64 KiB pages ("GPU page mapping"), and the watchdog fires shortly after. drm-total-gtt peaks at 4.3–4.5 GiB, vs ~3.5 GiB on 6d4f1cd7.
  • In the final stall the GPU is idle and the queue threads are asleep inside the CS ioctl (dma_fence_wait_any_timeout, mmu_interval_read_begin). The queues are stuck behind a texture publication fence whose reader signal sits in a vkQueueSubmit2 that hasn't returned.

Things that didn't help: THP never (page migration down about two-thirds, still exit 5 at 546 s) and TUXBOX_LAZY_PUBLICATION=0 (exit 5 at 372 s). One run each.

<!-- greyfinch-sync:brcly/TuxBox:comment:7371210234 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7371210234). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-03T07:36:52Z. --- Same thing here on an RX 6700 XT (RDNA 2, 12 GB), RADV from Mesa 26.3.1, GE-Proton11-15, 32 GB RAM. I spent tonight bisecting it, so here's where the AMD side broke. To keep shader prep out of the way I ran each older commit's providers with today's translator and DXC helper (`TUXBOX_XSHADER` / `TUXBOX_PERSISTENT_DXC` pointed at the current build). The only translator change between these commits and main is #534, so every run used the same runtime shader cache and only the providers differ. | Commit | What happens | |---|---| | `6d4f1cd7` (parent of `9c3cf86f`) | Intro video plays. Got further into the load than I've ever gotten on AMD, though at ~0.2 fps. No exit 5. It ran 531 s past the account picker and ended in a gfx ring page fault (TCP `PERMISSION_FAULTS 0x3`), which I also see on #667 builds, so I think that one is separate. | | `9c3cf86f` | Solid green intro video. RADV refuses the queue page mappings (`E_NOTIMPL`). | | `a789a4e4` (right before `106120ca`) | Green intro and cutscene videos, loading screen with no images, 0.3 fps. Ended in a title `int3` at `exe+0x5149AEC` (exit 3) at 881 s. | | `106120ca` + #667 | Videos are back, but every run that doesn't hit the page fault above ends in the `exe+0x23CF683` watchdog (exit 5), 150–300 s after the account picker. | So `6d4f1cd7` is the last commit before the AMD regression. `9c3cf86f` breaks it (green screens), and `106120ca` fixes the refusals by moving RADV to private backing, which turns it into the submission cost described here. What I measured on `106120ca` + #667 lines up with the numbers above: - The busiest `vkd3d_queue` thread is 85–90% kernel time for most of the run. perf has nearly all of it in `amdgpu_cs_ioctl`, mostly `hmm_range_fault` and `amdgpu_vm_bo_update`. - At the world load the live userptr imports jump from about 1.2k to 10–14k within ~500 frames, most of them single 64 KiB pages ("GPU page mapping"), and the watchdog fires shortly after. `drm-total-gtt` peaks at 4.3–4.5 GiB, vs ~3.5 GiB on `6d4f1cd7`. - In the final stall the GPU is idle and the queue threads are asleep inside the CS ioctl (`dma_fence_wait_any_timeout`, `mmu_interval_read_begin`). The queues are stuck behind a texture publication fence whose reader signal sits in a `vkQueueSubmit2` that hasn't returned. Things that didn't help: THP `never` (page migration down about two-thirds, still exit 5 at 546 s) and `TUXBOX_LAZY_PUBLICATION=0` (exit 5 at 372 s). One run each.
JeffreyBytes commented 2026-12-03 13:51:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T13:51:40Z.


@gtb-sbe I timed the view-creation wait you described in https://github.com/brcly/TuxBox/issues/533#issuecomment-7379297901, and it's large. Posting here since it's the same submission cost.

RX 6700 XT, RADV / Mesa 26.3.1, GE-Proton11-15, 106120ca + #667 with a temporary trace around the shared init queue in device/allocation.rs (with_init_transition): per kind, the call count, the time waiting for the queue's mutex, the time in WaitForSingleObject on the fence, and the slowest call. One run, new game, from the account picker through the load (about 250 s) until it ended in the gfx ring page fault (TCP PERMISSION_FAULTS 0x3) that I also see on other #667 runs.

Kind Calls Tiles bound Fence wait Mutex wait Slowest call
initialize_gpu_tiles 35,803 95,330 113.5 s 2 ms 17.5 s (1 tile)
reset_gpu_tiles 23,100 95,152 10.7 s 0 ms 83 ms
  • The title threads spent about 114 s of those ~250 s blocked in tile initialization. The mutex is never contended, so it's the submission itself, not threads queuing behind each other.
  • The cost of each wait follows the live host imports, as #669 describes. While fewer than about 1k "GPU page mapping" imports were live it was about 1.5 ms per call. At about 5k live imports it was 2.5–3.7 ms, and at 8–13k (819 MiB at the end) it was 10–41 ms per call.
  • One frame at 252 s took 18.1 s with only 174 ms of placement on the presenting thread. It lines up with the 17.5 s initialize_gpu_tiles call, so a view-creating thread held the title up.

I also tried cutting the number of imports. An experiment that imports the committed run of pages around a page, inside its 2 MiB cluster, instead of the single page, took the live single-page imports from 10–14k down to about 400. But the cluster windows grew to 3.8 GiB, GTT peaked at 4.7 GiB (4.3–4.5 GiB without it), and it still ended in the exe+0x23CF683 watchdog (exit 5) with a 49 s frame. So cutting the import count alone doesn't fix it, at least not without cutting the imported bytes too. One run.

So I think your suggestion is the bigger lever: if the creating thread didn't wait on the CPU (the queues that use the buffer wait on the fence on the GPU, or several views' tile initialization goes into one submission), most of those 114 s would come off the title's threads whatever each submission costs.

<!-- greyfinch-sync:brcly/TuxBox:comment:7380503963 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7380503963). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-03T13:51:40Z. --- @gtb-sbe I timed the view-creation wait you described in https://github.com/brcly/TuxBox/issues/533#issuecomment-7379297901, and it's large. Posting here since it's the same submission cost. RX 6700 XT, RADV / Mesa 26.3.1, GE-Proton11-15, `106120ca` + #667 with a temporary trace around the shared init queue in `device/allocation.rs` (`with_init_transition`): per kind, the call count, the time waiting for the queue's mutex, the time in `WaitForSingleObject` on the fence, and the slowest call. One run, new game, from the account picker through the load (about 250 s) until it ended in the gfx ring page fault (TCP `PERMISSION_FAULTS 0x3`) that I also see on other #667 runs. | Kind | Calls | Tiles bound | Fence wait | Mutex wait | Slowest call | |---|---|---|---|---|---| | `initialize_gpu_tiles` | 35,803 | 95,330 | 113.5 s | 2 ms | 17.5 s (1 tile) | | `reset_gpu_tiles` | 23,100 | 95,152 | 10.7 s | 0 ms | 83 ms | - The title threads spent about 114 s of those ~250 s blocked in tile initialization. The mutex is never contended, so it's the submission itself, not threads queuing behind each other. - The cost of each wait follows the live host imports, as #669 describes. While fewer than about 1k "GPU page mapping" imports were live it was about 1.5 ms per call. At about 5k live imports it was 2.5–3.7 ms, and at 8–13k (819 MiB at the end) it was 10–41 ms per call. - One frame at 252 s took 18.1 s with only 174 ms of placement on the presenting thread. It lines up with the 17.5 s `initialize_gpu_tiles` call, so a view-creating thread held the title up. I also tried cutting the number of imports. An experiment that imports the committed run of pages around a page, inside its 2 MiB cluster, instead of the single page, took the live single-page imports from 10–14k down to about 400. But the cluster windows grew to 3.8 GiB, GTT peaked at 4.7 GiB (4.3–4.5 GiB without it), and it still ended in the `exe+0x23CF683` watchdog (exit 5) with a 49 s frame. So cutting the import count alone doesn't fix it, at least not without cutting the imported bytes too. One run. So I think your suggestion is the bigger lever: if the creating thread didn't wait on the CPU (the queues that use the buffer wait on the fence on the GPU, or several views' tile initialization goes into one submission), most of those 114 s would come off the title's threads whatever each submission costs.
gtb-sbe commented 2026-12-03 14:00:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-03T14:00:04Z.


@JeffreyBytes thanks for timing it, 113.5 s of fence waits in ~250 s is more than I expected.

I read through the paths on 106120ca. The title-thread waits are initialize_gpu_tiles from register_buffer (buffer creation in a GPU reservation) and reset_gpu_tiles from refresh_cpu_pages, which runs at the start of every ExecuteCommandLists. Both go through InitTransition::wait_for_queue, so each call is one Signal plus a CPU wait. With #669 each Signal is a full CS that re-walks the userptr BOs.

What I have in mind:

  • initialize_gpu_tiles / reset_gpu_tiles only record the UpdateTileMappings and mark the init queue dirty, without a Signal or a wait.
  • At the start of each guest submission, if dirty, Signal once, then queue.Wait(init_fence, value) on the GPU. Many view creations between two submissions then cost one CS instead of one each, which I think matters more than where the wait happens.
  • Replaced tiles are held until the init fence passes their value instead of being dropped right after the call.
  • apply (initial state transitions) keeps its CPU wait, since it reuses the allocator.
  • Provider-internal queues that might read those buffers before a guest submission would need the same flush first. I haven't checked yet which of them touch reserved buffers.

@brcly does this fit with the XMem/D3D12 rework you're doing, or is that path changing anyway? If it fits, I'd write it with a Lanes scenario (buffer created on one thread, written on one queue and read on another with no host wait in between) and measure it on my RX 9060 XT before opening a PR.

<!-- greyfinch-sync:brcly/TuxBox:comment:7380726634 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7380726634). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-12-03T14:00:04Z. --- @JeffreyBytes thanks for timing it, 113.5 s of fence waits in ~250 s is more than I expected. I read through the paths on `106120ca`. The title-thread waits are `initialize_gpu_tiles` from `register_buffer` (buffer creation in a GPU reservation) and `reset_gpu_tiles` from `refresh_cpu_pages`, which runs at the start of every `ExecuteCommandLists`. Both go through `InitTransition::wait_for_queue`, so each call is one `Signal` plus a CPU wait. With #669 each `Signal` is a full CS that re-walks the userptr BOs. What I have in mind: - `initialize_gpu_tiles` / `reset_gpu_tiles` only record the `UpdateTileMappings` and mark the init queue dirty, without a `Signal` or a wait. - At the start of each guest submission, if dirty, `Signal` once, then `queue.Wait(init_fence, value)` on the GPU. Many view creations between two submissions then cost one CS instead of one each, which I think matters more than where the wait happens. - Replaced tiles are held until the init fence passes their value instead of being dropped right after the call. - `apply` (initial state transitions) keeps its CPU wait, since it reuses the allocator. - Provider-internal queues that might read those buffers before a guest submission would need the same flush first. I haven't checked yet which of them touch reserved buffers. @brcly does this fit with the XMem/D3D12 rework you're doing, or is that path changing anyway? If it fits, I'd write it with a Lanes scenario (buffer created on one thread, written on one queue and read on another with no host wait in between) and measure it on my RX 9060 XT before opening a PR.
JeffreyBytes commented 2026-12-03 14:07:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T14:07:25Z.


@gtb-sbe Batching to one CS per guest submission makes sense to me. I went through the provider's own queues on 106120ca for your open question (read only, nothing built yet), and found a few places outside the device init queue that rely on the CPU wait today:

  1. The page-mapping worker has its own init queue. "TuxBox page mappings" (commands/page_mapping/retirement.rs:48) keeps a private Mutex::new(None) slot, runs bind_published → reset_native_gpu_tiles (buffers.rs:395) on it, and then signals the job fence to 2 from the CPU (retirement.rs:70). The guest queue GPU-waits on that 2 (buffers.rs:858). Without the CPU wait, the guest queue would be released before the binds finish, and the guest-submission flush would flush the device init queue, not this one. The worker could signal 2 on the GPU from its own init queue after the binds, or keep its wait.
  2. Inline publication uses throwaway init queues. publish and publish_textures on the fast path (buffers.rs:353 and :844) pass &Mutex::new(None), so they create an init queue and drop it on return. A deferred mapping there would never be flushed.
  3. Guest page-mapping commands. refresh_cpu_pages (buffers.rs:779) resets tiles on the init queue, then gpu_updates and bind_live bind the same buffers on the guest queue. Deferred, the two binds on one resource are unordered, so it needs the flush before bind_live.
  4. Present. present.rs:259 calls gpu_mappings.refresh() and then gathers from page-mapped backing on the guest queue in placement::submit, so it needs the same flush.

In execute_locked, refresh() (submit.rs:226) is itself an init call, so the flush would go after it and before placement::submit (:372): the gathers and scatters in queue_use.rs and the memory-wait split lists run after that and read GPU-tile buffers.

The side queues look clear: the upload/residency transfer queue, the "TuxBox texture readback" copier, the lazy-publication copy queues, the BLAS builder and the detile-table upload only touch their own memory or provider-committed buffers.

I'm happy to test your branch on the RX 6700 XT (RDNA 2) with the same init-queue timing trace, so we'd have before and after numbers from two cards: on 106120ca + #667 it's 113.5 s of fence waits in about 250 s of loading.

<!-- greyfinch-sync:brcly/TuxBox:comment:7380926078 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7380926078). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-03T14:07:25Z. --- @gtb-sbe Batching to one CS per guest submission makes sense to me. I went through the provider's own queues on `106120ca` for your open question (read only, nothing built yet), and found a few places outside the device init queue that rely on the CPU wait today: 1. **The page-mapping worker has its own init queue.** "TuxBox page mappings" (`commands/page_mapping/retirement.rs:48`) keeps a private `Mutex::new(None)` slot, runs `bind_published` → `reset_native_gpu_tiles` (`buffers.rs:395`) on it, and then signals the job fence to 2 from the CPU (`retirement.rs:70`). The guest queue GPU-waits on that 2 (`buffers.rs:858`). Without the CPU wait, the guest queue would be released before the binds finish, and the guest-submission flush would flush the device init queue, not this one. The worker could signal 2 on the GPU from its own init queue after the binds, or keep its wait. 2. **Inline publication uses throwaway init queues.** `publish` and `publish_textures` on the fast path (`buffers.rs:353` and `:844`) pass `&Mutex::new(None)`, so they create an init queue and drop it on return. A deferred mapping there would never be flushed. 3. **Guest page-mapping commands.** `refresh_cpu_pages` (`buffers.rs:779`) resets tiles on the init queue, then `gpu_updates` and `bind_live` bind the same buffers on the guest queue. Deferred, the two binds on one resource are unordered, so it needs the flush before `bind_live`. 4. **Present.** `present.rs:259` calls `gpu_mappings.refresh()` and then gathers from page-mapped backing on the guest queue in `placement::submit`, so it needs the same flush. In `execute_locked`, `refresh()` (`submit.rs:226`) is itself an init call, so the flush would go after it and before `placement::submit` (`:372`): the gathers and scatters in `queue_use.rs` and the memory-wait split lists run after that and read GPU-tile buffers. The side queues look clear: the upload/residency transfer queue, the "TuxBox texture readback" copier, the lazy-publication copy queues, the BLAS builder and the detile-table upload only touch their own memory or provider-committed buffers. I'm happy to test your branch on the RX 6700 XT (RDNA 2) with the same init-queue timing trace, so we'd have before and after numbers from two cards: on `106120ca` + #667 it's 113.5 s of fence waits in about 250 s of loading.
gtb-sbe commented 2026-12-03 15:54:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-03T15:54:09Z.


I wrote the batched version and ran it once on my RX 9060 XT (RDNA 4, RADV / Mesa 26.3.1, GE-Proton11-15), on 106120ca + #667, against a run of the same build without it (same warm shader cache, default settings).

What the change does: initialize_gpu_tiles and reset_gpu_tiles only record the update. The next guest ExecuteCommandLists (before placement::submit), present, and the page-mapping command signal the init queue once and Wait on it on the GPU. Replaced tiles stay alive until that value is reached. bind_published (the worker and both inline paths) finishes the device init queue on the CPU before its own binds, so they can't land ahead of a deferred init. TUXBOX_TILE_INIT=wait restores the old behaviour. Lanes passes 33/33, and queue-page-mappings 5 of 5 times.

without with
Streaming thread samples in wait_for_queue < initialize_gpu_tiles 33.8 % 0 %
Game Running to the intro SRL (crash log timestamps) 485 s 174 s
End intro Prestream, no present for ~2 min, exit 5 same, exit 5
Peak adapter system memory 4,766 MiB 4,714 MiB

So the title's threads don't wait in view creation any more, and the load up to the intro is about 2.8 times shorter. It doesn't fix #669 itself: the run still ends in the same stall. The busiest vkd3d_queue thread spent 202 s of the 413 s run in the kernel (99 % of its CPU time, 60-100 % of every 10 s window during loading), and in the final stall the render thread is waiting in detile::Cache::upload with all queues idle, as before. Some of the freed time on the streaming thread went into host imports (PageCache::get_or_open, 0.6 % -> 8 %) and the mapped_texture mutex (2.2 % -> 9.9 %).

One run each, so treat the timings as rough. @JeffreyBytes the branch is gtb-sbe:d3d12-batched-tile-init (one commit on 106120ca, applies cleanly with #667) if you want to run it with your init-queue trace on the 6700 XT.

<!-- greyfinch-sync:brcly/TuxBox:comment:7383923658 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7383923658). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-12-03T15:54:09Z. --- I wrote the batched version and ran it once on my RX 9060 XT (RDNA 4, RADV / Mesa 26.3.1, GE-Proton11-15), on `106120ca` + #667, against a run of the same build without it (same warm shader cache, default settings). What the change does: `initialize_gpu_tiles` and `reset_gpu_tiles` only record the update. The next guest `ExecuteCommandLists` (before `placement::submit`), present, and the page-mapping command signal the init queue once and `Wait` on it on the GPU. Replaced tiles stay alive until that value is reached. `bind_published` (the worker and both inline paths) finishes the device init queue on the CPU before its own binds, so they can't land ahead of a deferred init. `TUXBOX_TILE_INIT=wait` restores the old behaviour. Lanes passes 33/33, and `queue-page-mappings` 5 of 5 times. | | without | with | |---|---|---| | Streaming thread samples in `wait_for_queue` < `initialize_gpu_tiles` | 33.8 % | 0 % | | `Game Running` to the intro SRL (crash log timestamps) | 485 s | 174 s | | End | intro `Prestream`, no present for ~2 min, exit 5 | same, exit 5 | | Peak adapter system memory | 4,766 MiB | 4,714 MiB | So the title's threads don't wait in view creation any more, and the load up to the intro is about 2.8 times shorter. It doesn't fix #669 itself: the run still ends in the same stall. The busiest `vkd3d_queue` thread spent 202 s of the 413 s run in the kernel (99 % of its CPU time, 60-100 % of every 10 s window during loading), and in the final stall the render thread is waiting in `detile::Cache::upload` with all queues idle, as before. Some of the freed time on the streaming thread went into host imports (`PageCache::get_or_open`, 0.6 % -> 8 %) and the `mapped_texture` mutex (2.2 % -> 9.9 %). One run each, so treat the timings as rough. @JeffreyBytes the branch is [`gtb-sbe:d3d12-batched-tile-init`](https://github.com/gtb-sbe/TuxBox/tree/d3d12-batched-tile-init) (one commit on `106120ca`, applies cleanly with #667) if you want to run it with your init-queue trace on the 6700 XT.
turboheadcrab commented 2026-12-03 16:44:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by turboheadcrab on 2026-12-03T16:44:52Z.


@JeffreyBytes the gfx ring page fault you see on #667 runs reproduces on RDNA 4. The build was 106120ca + #667 + #621, on an RX 9070 XT (RADV from Mesa 26.3.1, kernel 7.3.5), and it was a new game from the intro. #621 kept the watchdog off, so the run lasted until the fault.

Every minute, GTT (drm-total-gtt), the median DRM_IOCTL_AMDGPU_CS time over 3 s, and the frame rate:

After the new game GTT CS per second CS median fps
0 min 1.45 GiB 66 14 ms 6.3
+1 min 2.2 GiB 36 24 ms 3.6
+2 min 2.9 GiB 25 34 ms 1.1
+3 min 4.0 GiB 17 48 ms 1.2
+4 min 4.3 GiB 0 — 1.4
+5 min 4.3 GiB under 1 204 ms 1.4

The page fault came at 1,217 s:

  • Kernel log: [gfxhub] page fault, Faulty UTCL2 client ID: TCP (0x8), PERMISSION_FAULTS: 0x3, WALKER_ERROR: 0x0, MAPPING_ERROR: 0x0, RW: 0x0 (a read), on a vkd3d_queue thread, with MORE_FAULTS and 10 fault lines in a row on consecutive 4 KiB pages.
  • Then ring gfx_0.0.0 timeout, a successful ring reset, and RADV The CS has been cancelled because the context is lost.
  • Before it, the TuxBox log has 33 GPU worker fence stalled (texture readback and queued texture copy), 8 memory waits held past 5 s, and an 8.3 s placed-texture readback.

A second run of the same build, with TUXBOX_GPU_TIMING=1, ended the same way, only sooner. It faulted at 890 s, about 4 minutes after the new game, at 3.6 GiB GTT: the same [gfxhub] TCP PERMISSION_FAULTS 0x3 read fault, 10 in a row, then the ring reset. GPU timing shows the GPU nearly idle all the way up to the fault. The timed pipeline work was 0.85–3 ms per second in every 10 s window, and no single pipeline stood out. CS times in that run: 12.5–13.8 ms at 1.4 GiB, then 21.7 ms at 2.0 GiB and 39.4 ms at 3.6 GiB.

So on this card the CS cost tracks GTT the same way as on yours, up to the point where submissions nearly stop. Then the fault ends the run.

<!-- greyfinch-sync:brcly/TuxBox:comment:7385376485 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/669#issuecomment-7385376485). Originally posted by [turboheadcrab](https://github.com/turboheadcrab) on 2026-12-03T16:44:52Z. --- @JeffreyBytes the gfx ring page fault you see on #667 runs reproduces on RDNA 4. The build was `106120ca` + #667 + #621, on an RX 9070 XT (RADV from Mesa 26.3.1, kernel 7.3.5), and it was a new game from the intro. #621 kept the watchdog off, so the run lasted until the fault. Every minute, GTT (`drm-total-gtt`), the median `DRM_IOCTL_AMDGPU_CS` time over 3 s, and the frame rate: | After the new game | GTT | CS per second | CS median | fps | |---|---|---|---|---| | 0 min | 1.45 GiB | 66 | 14 ms | 6.3 | | +1 min | 2.2 GiB | 36 | 24 ms | 3.6 | | +2 min | 2.9 GiB | 25 | 34 ms | 1.1 | | +3 min | 4.0 GiB | 17 | 48 ms | 1.2 | | +4 min | 4.3 GiB | 0 | — | 1.4 | | +5 min | 4.3 GiB | under 1 | 204 ms | 1.4 | The page fault came at 1,217 s: - Kernel log: `[gfxhub] page fault`, `Faulty UTCL2 client ID: TCP (0x8)`, `PERMISSION_FAULTS: 0x3`, `WALKER_ERROR: 0x0`, `MAPPING_ERROR: 0x0`, `RW: 0x0` (a read), on a `vkd3d_queue` thread, with `MORE_FAULTS` and 10 fault lines in a row on consecutive 4 KiB pages. - Then `ring gfx_0.0.0 timeout`, a successful ring reset, and RADV `The CS has been cancelled because the context is lost`. - Before it, the TuxBox log has 33 `GPU worker fence stalled` (texture readback and queued texture copy), 8 memory waits held past 5 s, and an 8.3 s placed-texture readback. A second run of the same build, with `TUXBOX_GPU_TIMING=1`, ended the same way, only sooner. It faulted at 890 s, about 4 minutes after the new game, at 3.6 GiB GTT: the same `[gfxhub]` TCP `PERMISSION_FAULTS 0x3` read fault, 10 in a row, then the ring reset. GPU timing shows the GPU nearly idle all the way up to the fault. The timed pipeline work was 0.85–3 ms per second in every 10 s window, and no single pipeline stood out. CS times in that run: 12.5–13.8 ms at 1.4 GiB, then 21.7 ms at 2.0 GiB and 39.4 ms at 3.6 GiB. So on this card the CS cost tracks GTT the same way as on yours, up to the point where submissions nearly stop. Then the fault ends the run.
Sign in to join this conversation.
No labels
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.

Reference
brcly/TuxBox#669
No description provided.