Try GPU upload heaps for descriptor stride tables #887

Open
github-bot wants to merge 1 commit from github-bot/gh-887 into main AGit
Owner

@⁠Lkxex on GitHub · 2026-11-25 11:53 UTC · original
Lkxex:exp/gpu-upload-descriptor-strides → main · +107 −16 · 3 files · 1 commits · draft

Experiment

Try placing the descriptor-stride table in CPU-visible VRAM on a supported discrete GPU. The table is 8 MiB per view heap and lives with that heap. Descriptor updates write it from the CPU, and shaders read it through a root SRV. The experiment moves GPU reads of this table to local memory. CPU updates still cross PCIe.

VICTORY_GPU_UPLOAD_STRIDES=1 enables the trial for stride tables. It checks the D3D12 architecture and GPU upload capability, leaves 10% local-budget headroom at allocation time, and falls back to the ordinary upload heap when support, room, or allocation is unavailable. The experiment is off by default.

Validation and measurement

  • The focused allocation and mapping test passed on WARP and the local D3D12 host. Both selected the ordinary upload heap, so the GPU upload path has no local hardware validation yet.
  • cargo check --locked -p victory and git diff --check passed. Validation used synthetic tests.
  • On supported NVIDIA hardware, check for the descriptor stride table in CPU-visible video memory log. Compare the same scene after shader warm-up with and without VICTORY_GPU_UPLOAD_STRIDES. Record frame time, GPU time, and local memory use. Keep VICTORY_QUEUE2 and the copy-back settings fixed between runs. The PCIe read/write trade-off and frame-time effect remain unmeasured.

Microsoft GPU upload heap specification · NVIDIA GPU upload heap guidance

AI-assisted change.

**@⁠Lkxex** on GitHub · 2026-11-25 11:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/887) `Lkxex:exp/gpu-upload-descriptor-strides` → `main` · +107 −16 · 3 files · 1 commits · draft ### Experiment Try placing the descriptor-stride table in CPU-visible VRAM on a supported discrete GPU. The table is 8 MiB per view heap and lives with that heap. Descriptor updates write it from the CPU, and shaders read it through a root SRV. The experiment moves GPU reads of this table to local memory. CPU updates still cross PCIe. `VICTORY_GPU_UPLOAD_STRIDES=1` enables the trial for stride tables. It checks the D3D12 architecture and GPU upload capability, leaves 10% local-budget headroom at allocation time, and falls back to the ordinary upload heap when support, room, or allocation is unavailable. The experiment is off by default. ### Validation and measurement - The focused allocation and mapping test passed on WARP and the local D3D12 host. Both selected the ordinary upload heap, so the GPU upload path has no local hardware validation yet. - `cargo check --locked -p victory` and `git diff --check` passed. Validation used synthetic tests. - On supported NVIDIA hardware, check for the `descriptor stride table in CPU-visible video memory` log. Compare the same scene after shader warm-up with and without `VICTORY_GPU_UPLOAD_STRIDES`. Record frame time, GPU time, and local memory use. Keep `VICTORY_QUEUE2` and the copy-back settings fixed between runs. The PCIe read/write trade-off and frame-time effect remain unmeasured. [Microsoft GPU upload heap specification](https://microsoft.github.io/DirectX-Specs/d3d/D3D12GPUUploadHeaps.html) · [NVIDIA GPU upload heap guidance](https://developer.nvidia.com/blog/optimizing-dx12-resource-uploads-to-the-gpu-using-gpu-upload-heaps/) AI-assisted change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:13 +00:00
Author
Owner

@⁠eazyves on GitHub · 2026-11-25 12:36 UTC · original · edited 2026-11-25 13:06 UTC

The GPU upload path works on an RX 9070 XT (RDNA4): here the table lands in a GPU upload heap. fbecee4, driver 32.0.32029.2010, Windows 11 26200, Ryzen 7 5800X3D.

descriptor_stride_upload_maps_and_keeps_the_standard_fallback prints heap type 2 with prefer_local off and 5 (GPU_UPLOAD) with it on, and passes, also with VICTORY_D3D12_DEBUG=1 in a diagnostics build.

A temporary test (not committed, release build) on an 8 MiB table, the heaps alternating, 6 measurements each:

upload heap (2) GPU upload heap (5)
CPU fills all 8 MiB in order 0.48 to 0.60 ms 0.73 to 0.86 ms
200,000 scattered 4-byte CPU writes 1.80 to 1.96 ms 1.79 to 1.87 ms
GPU copy to a readback buffer: dwords that are neither value written there 0 0

So filling in order costs about half as much again, and single slot writes cost the same here. These are CPU write times only. I did not measure shader reads, and I did not run the title, so nothing here says what it does to the frame time.

With VICTORY_GPU_UPLOAD_STRIDES=1, all 28 descriptor:: tests pass with the debug layer on. In 10 serial runs of the diagnostics victory-gpu lib tests with the switch and 10 without, the only test that failed was warp_budget_saturates_..., which fails on main too (#849).

From the diff: I found no CPU read of the table, only the zeroing and the slot write in descriptor/host.rs (around line 1603). And the description asks for supported NVIDIA hardware; AMD qualifies here as well.

Edit: other GPU tests and a large file copy from another session of mine may have been running on this machine at the time, so treat the write times as rough. The heap type and the data check don't depend on that.

No game data. AI-assisted (Claude Code); run on my machine.

**@⁠eazyves** on GitHub · 2026-11-25 12:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/887#issuecomment-7162607473) · edited 2026-11-25 13:06 UTC **The GPU upload path works on an RX 9070 XT (RDNA4): here the table lands in a GPU upload heap.** fbecee4, driver 32.0.32029.2010, Windows 11 26200, Ryzen 7 5800X3D. `descriptor_stride_upload_maps_and_keeps_the_standard_fallback` prints heap type 2 with `prefer_local` off and **5 (`GPU_UPLOAD`)** with it on, and passes, also with `VICTORY_D3D12_DEBUG=1` in a diagnostics build. A temporary test (not committed, release build) on an 8 MiB table, the heaps alternating, 6 measurements each: | | upload heap (2) | GPU upload heap (5) | |---|---|---| | CPU fills all 8 MiB in order | 0.48 to 0.60 ms | 0.73 to 0.86 ms | | 200,000 scattered 4-byte CPU writes | 1.80 to 1.96 ms | 1.79 to 1.87 ms | | GPU copy to a readback buffer: dwords that are neither value written there | 0 | 0 | So filling in order costs about half as much again, and single slot writes cost the same here. These are CPU write times only. I did not measure shader reads, and I did not run the title, so nothing here says what it does to the frame time. With `VICTORY_GPU_UPLOAD_STRIDES=1`, all 28 `descriptor::` tests pass with the debug layer on. In 10 serial runs of the diagnostics `victory-gpu` lib tests with the switch and 10 without, the only test that failed was `warp_budget_saturates_...`, which fails on `main` too (#849). From the diff: I found no CPU read of the table, only the zeroing and the slot write in `descriptor/host.rs` (around line 1603). And the description asks for supported NVIDIA hardware; AMD qualifies here as well. **Edit:** other GPU tests and a large file copy from another session of mine may have been running on this machine at the time, so treat the write times as rough. The heap type and the data check don't depend on that. No game data. AI-assisted (Claude Code); run on my machine.
Author
Owner

@⁠sawetco on GitHub · 2026-11-25 21:35 UTC · original

I tested the two GPU source changes from fbecee4 on an RTX 5070 (12 GB, 621.24), Ryzen 5 7600X, Windows 11 build 26300. The driver accepted both allocation types. The unit test reported heap type 2 with placement off and 5 with it on. Each enabled game run logged one 8,388,608-byte descriptor-stride table in CPU-visible video memory.

Shader reads after a CPU update were substantially faster on the GPU upload heap in an isolated D3D12 test. The compute shader reads each dword of an 8 MiB table once and produces 32,768 hashes. These are median GPU timestamps in microseconds over six measurements per cell, alternating heap order. The static warm-up uses the same shader. The update changes one dword per 256 bytes, in permuted order, with fresh values each time.

Immediately before the timed dispatch Shader access UPLOAD GPU_UPLOAD
Same table already read Linear 11.2 µs 11.9 µs
Same table already read Permuted 40.7 µs 41.4 µs
32,768 scattered CPU updates Linear 319.1 µs 36.4 µs
32,768 scattered CPU updates Permuted 5,625.5 µs 76.6 µs

The CPU update itself took a median of 247–252 µs across these cases. All 2,359,296 result hashes across 72 timed dispatches matched the CPU reference, including a third precondition that wrote a separate 128 MiB GPU buffer. The synthetic access pattern deliberately touches the entire table. Actual shaders can use a much smaller subset.

Gameplay on this downstream build gave mixed results. I applied the PR's two source-file hunks without edits to a local build based on vitutu1/victory-perf@97c3aa2 with the water and face fixes. Both settings used the same binary, a fresh copy of the same house save, 4,068 warm shader files, two pipeline-cache files, Series S at 0.5 render scale, and VICTORY_REBAR=0 for guest-memory windows.

Run order Stride-table placement Host presents/s Median interval P95 interval
1 UPLOAD 4.86 166.9 ms 390.1 ms
2 GPU_UPLOAD 5.72 164.1 ms 276.6 ms
3 GPU_UPLOAD 5.64 163.8 ms 306.1 ms
4 UPLOAD 6.10 156.3 ms 230.4 ms

These are 127 complete host Present intervals per run between frames 1920 and 2048, with Jason viewed side-on at the same porch in all eight endpoint images. I chose that window after checking the captures. The originally planned start at frame 1632 was still a loading transition in two runs. Idle animation, streaming and shadows varied. The direction of the gameplay difference reversed across pairs. This supports keeping the option available for targeted A/B tests.

A separate instrumented build also found redundant CPU stores while loading. The stride table starts at zero, and the heap already tracks which slots hold buffers. Omitting the zero store only when both the previous and new slot are non-buffers skipped 317,153 of 737,632 eligible store calls in one loading window (43.0%). A later black-screen-to-porch window skipped 466,915 of 959,757 (48.6%). Buffer-to-texture transitions still explicitly cleared the slot. The local slot-reuse test passed. A separate porch timing pair showed 5.49 vs 5.09 presents/s with suppression, so the counts alone do not justify enabling this change.

Standalone shader-read probe (C++, Windows SDK 10.0.26100, no game files)

Build in a Visual Studio x64 developer prompt using the command in the file header. The program prints CSV, checks both actual heap types and compares each GPU result with the CPU reference.

// Synthetic D3D12 shader-read benchmark. Build with a current Windows SDK:
// cl /nologo /O2 /EHsc /std:c++17 descriptor_stride_probe.cpp d3d12.lib dxgi.lib d3dcompiler.lib
#include <windows.h>
#include <d3d12.h>
#include <d3dcompiler.h>
#include <dxgi1_6.h>
#include <wrl/client.h>
#include <array>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <stdexcept>
#include <utility>
#include <vector>

using Microsoft::WRL::ComPtr;
constexpr UINT words = 2 * 1024 * 1024;
constexpr UINT lanes = 32768;
constexpr UINT resultBytes = lanes * sizeof(UINT);
constexpr UINT sweepBytes = 128 * 1024 * 1024;

const char shader[] = R"(
ByteAddressBuffer table : register(t0);
RWByteAddressBuffer outputData : register(u0);
cbuffer Mode : register(b0) { uint scatter; };
[numthreads(64,1,1)]
void readTable(uint3 id : SV_DispatchThreadID) {
    uint sum = 2166136261u;
    for (uint i = id.x; i < 2097152u; i += 32768u) {
        uint slot = scatter ? ((i * 1664525u + 1013904223u) & 2097151u) : i;
        sum = (sum * 16777619u) ^ table.Load(slot * 4);
    }
    outputData.Store(id.x * 4, sum);
}
[numthreads(64,1,1)]
void sweep(uint3 id : SV_DispatchThreadID) {
    for (uint i = id.x; i < 33554432u; i += 32768u)
        outputData.Store(i * 4, i * 2654435761u);
}
)";

void check(HRESULT hr, const char* step) {
    if (FAILED(hr)) {
        std::fprintf(stderr, "%s failed (HRESULT 0x%08lx)\n", step, static_cast<unsigned long>(hr));
        throw std::runtime_error(step);
    }
}

ComPtr<ID3D12Resource> buffer(ID3D12Device* device, D3D12_HEAP_TYPE type, UINT bytes,
                              D3D12_RESOURCE_STATES state, D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) {
    D3D12_HEAP_PROPERTIES heap{};
    heap.Type = type;
    heap.CreationNodeMask = heap.VisibleNodeMask = 1;
    D3D12_RESOURCE_DESC desc{};
    desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
    desc.Width = bytes;
    desc.Height = 1;
    desc.DepthOrArraySize = 1;
    desc.MipLevels = 1;
    desc.SampleDesc.Count = 1;
    desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
    desc.Flags = flags;
    ComPtr<ID3D12Resource> result;
    check(device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, state, nullptr,
                                          IID_PPV_ARGS(&result)), "create buffer");
    return result;
}

ComPtr<ID3D12PipelineState> pipeline(ID3D12Device* device, ID3D12RootSignature* root, const char* entry) {
    ComPtr<ID3DBlob> code, errors;
    auto hr = D3DCompile(shader, sizeof(shader) - 1, nullptr, nullptr, nullptr, entry,
                         "cs_5_1", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, &code, &errors);
    if (FAILED(hr) && errors) std::fprintf(stderr, "%s\n", static_cast<const char*>(errors->GetBufferPointer()));
    check(hr, entry);
    D3D12_COMPUTE_PIPELINE_STATE_DESC desc{};
    desc.pRootSignature = root;
    desc.CS = {code->GetBufferPointer(), code->GetBufferSize()};
    ComPtr<ID3D12PipelineState> result;
    check(device->CreateComputePipelineState(&desc, IID_PPV_ARGS(&result)), "create compute pipeline");
    return result;
}

void uavBarrier(ID3D12GraphicsCommandList* list, ID3D12Resource* resource) {
    D3D12_RESOURCE_BARRIER barrier{};
    barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
    barrier.UAV.pResource = resource;
    list->ResourceBarrier(1, &barrier);
}

uint32_t value(uint32_t i) { return ((i ^ (i >> 11)) * 2654435761u) + 97u; }

std::vector<UINT> referenceHashes(bool scatter, UINT salt) {
    std::vector<UINT> hashes(lanes, 2166136261u);
    for (UINT i = 0; i < words; ++i) {
        UINT slot = scatter ? ((i * 1664525u + 1013904223u) & (words - 1)) : i;
        UINT updated = value(slot) ^ (slot % 64 == 0 ? salt : 0);
        hashes[i % lanes] = (hashes[i % lanes] * 16777619u) ^ updated;
    }
    return hashes;
}

double updateTable(ID3D12Resource* table, UINT salt) {
    D3D12_RANGE noReads{};
    void* data = nullptr;
    auto start = std::chrono::steady_clock::now();
    check(table->Map(0, &noReads, &data), "map table for updates");
    for (UINT n = 0; n < lanes; ++n) {
        UINT slot = ((n * 1664525u + 1013904223u) & (lanes - 1)) * 64;
        static_cast<UINT*>(data)[slot] = value(slot) ^ salt;
    }
    table->Unmap(0, nullptr);
    return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start).count();
}

int run() {
    ComPtr<IDXGIFactory6> factory;
    ComPtr<IDXGIAdapter1> adapter;
    ComPtr<ID3D12Device> device;
    check(CreateDXGIFactory1(IID_PPV_ARGS(&factory)), "DXGI factory");
    check(factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE,
                                               IID_PPV_ARGS(&adapter)), "hardware adapter");
    DXGI_ADAPTER_DESC1 adapterInfo{};
    check(adapter->GetDesc1(&adapterInfo), "adapter description");
    check(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)), "D3D12 device");
    D3D12_FEATURE_DATA_D3D12_OPTIONS16 features{};
    check(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &features, sizeof(features)), "options 16");
    if ((adapterInfo.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) || !features.GPUUploadHeapSupported)
        throw std::runtime_error("A hardware adapter with GPU upload heaps is required.");

    D3D12_ROOT_PARAMETER params[3]{};
    params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
    params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
    params[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
    params[2].Constants.Num32BitValues = 1;
    D3D12_ROOT_SIGNATURE_DESC sig{};
    sig.NumParameters = 3;
    sig.pParameters = params;
    ComPtr<ID3DBlob> serialized;
    check(D3D12SerializeRootSignature(&sig, D3D_ROOT_SIGNATURE_VERSION_1, &serialized, nullptr), "serialize root");
    ComPtr<ID3D12RootSignature> root;
    check(device->CreateRootSignature(0, serialized->GetBufferPointer(), serialized->GetBufferSize(),
                                      IID_PPV_ARGS(&root)), "create root");
    auto reader = pipeline(device.Get(), root.Get(), "readTable");
    auto sweeper = pipeline(device.Get(), root.Get(), "sweep");

    const std::array<D3D12_HEAP_TYPE, 2> types{D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_GPU_UPLOAD};
    std::array<ComPtr<ID3D12Resource>, 4> tables;
    D3D12_RANGE empty{};
    for (UINT h = 0; h < tables.size(); ++h) {
        auto type = types[h % types.size()];
        tables[h] = buffer(device.Get(), type, words * sizeof(UINT), D3D12_RESOURCE_STATE_GENERIC_READ);
        D3D12_HEAP_PROPERTIES actual{};
        check(tables[h]->GetHeapProperties(&actual, nullptr), "check actual heap");
        if (actual.Type != type) throw std::runtime_error("Unexpected table heap type.");
        void* mapping = nullptr;
        check(tables[h]->Map(0, &empty, &mapping), "map table for writing");
        for (UINT i = 0; i < words; ++i) static_cast<UINT*>(mapping)[i] = value(i);
        tables[h]->Unmap(0, nullptr);
    }
    auto output = buffer(device.Get(), D3D12_HEAP_TYPE_DEFAULT, resultBytes, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
                         D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
    auto pressure = buffer(device.Get(), D3D12_HEAP_TYPE_DEFAULT, sweepBytes, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
                           D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
    auto readback = buffer(device.Get(), D3D12_HEAP_TYPE_READBACK, resultBytes + 16, D3D12_RESOURCE_STATE_COPY_DEST);
    const std::array<std::vector<UINT>, 2> expected{referenceHashes(false, 0), referenceHashes(true, 0)};
    ComPtr<ID3D12CommandQueue> queue;
    ComPtr<ID3D12CommandAllocator> allocator;
    ComPtr<ID3D12GraphicsCommandList> list;
    ComPtr<ID3D12Fence> fence;
    ComPtr<ID3D12QueryHeap> queries;
    D3D12_COMMAND_QUEUE_DESC q{};
    q.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
    check(device->CreateCommandQueue(&q, IID_PPV_ARGS(&queue)), "create queue");
    check(device->CreateCommandAllocator(q.Type, IID_PPV_ARGS(&allocator)), "create allocator");
    check(device->CreateCommandList(0, q.Type, allocator.Get(), nullptr, IID_PPV_ARGS(&list)), "create list");
    check(list->Close(), "close initial list");
    check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "create fence");
    D3D12_QUERY_HEAP_DESC queryDesc{D3D12_QUERY_HEAP_TYPE_TIMESTAMP, 2, 0};
    check(device->CreateQueryHeap(&queryDesc, IID_PPV_ARGS(&queries)), "create query heap");
    UINT64 frequency = 0, completed = 0;
    check(queue->GetTimestampFrequency(&frequency), "timestamp frequency");
    std::fprintf(stderr, "adapter=%ls frequency=%llu Hz table_bytes=%u lanes=%u\n",
                 adapterInfo.Description, frequency, words * 4, lanes);
    const char* conditions[] = {"warm", "after_128MiB_write", "after_32768_cpu_updates"};
    std::puts("repeat,access,precondition,heap,gpu_us,cpu_update_us,wrong_hashes");
    for (UINT repeat = 0; repeat <= 6; ++repeat) {
        for (UINT scatter = 0; scatter < 2; ++scatter) {
            UINT salt = 2654435761u * (1 + repeat * 2 + scatter);
            auto updated = referenceHashes(scatter != 0, salt);
            for (UINT condition = 0; condition < 3; ++condition) {
                for (UINT order = 0; order < 2; ++order) {
                    UINT h = (repeat + order) % 2;
                    bool dynamic = condition == 2;
                    auto* table = tables[h + (dynamic ? 2 : 0)].Get();
                    const auto& wanted = dynamic ? updated : expected[scatter];
                    double updateUs = dynamic ? updateTable(table, salt) : 0;
                    check(allocator->Reset(), "reset allocator");
                    check(list->Reset(allocator.Get(), nullptr), "reset list");
                    list->SetComputeRootSignature(root.Get());
                    list->SetComputeRootShaderResourceView(0, table->GetGPUVirtualAddress());
                    list->SetComputeRoot32BitConstant(2, scatter, 0);
                    if (!dynamic) {
                        auto* before = condition == 1 ? pressure.Get() : output.Get();
                        list->SetPipelineState(condition == 1 ? sweeper.Get() : reader.Get());
                        list->SetComputeRootUnorderedAccessView(1, before->GetGPUVirtualAddress());
                        list->Dispatch(lanes / 64, 1, 1);
                        // Order the cache-pressure pass even when it uses a different UAV.
                        uavBarrier(list.Get(), nullptr);
                    }
                    list->SetPipelineState(reader.Get());
                    list->SetComputeRootUnorderedAccessView(1, output->GetGPUVirtualAddress());
                    list->EndQuery(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0);
                    list->Dispatch(lanes / 64, 1, 1);
                    uavBarrier(list.Get(), output.Get());
                    list->EndQuery(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 1);
                    list->ResolveQueryData(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, readback.Get(), 0);
                    D3D12_RESOURCE_BARRIER copy{};
                    copy.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
                    copy.Transition = {output.Get(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
                                       D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE};
                    list->ResourceBarrier(1, &copy);
                    list->CopyBufferRegion(readback.Get(), 16, output.Get(), 0, resultBytes);
                    std::swap(copy.Transition.StateBefore, copy.Transition.StateAfter);
                    list->ResourceBarrier(1, &copy);
                    check(list->Close(), "close list");
                    ID3D12CommandList* lists[] = {list.Get()};
                    queue->ExecuteCommandLists(1, lists);
                    check(queue->Signal(fence.Get(), ++completed), "signal fence");
                    check(fence->SetEventOnCompletion(completed, nullptr), "wait for readback");
                    check(device->GetDeviceRemovedReason(), "GPU completion");
                    void* data = nullptr;
                    D3D12_RANGE range{0, resultBytes + 16};
                    check(readback->Map(0, &range, &data), "map completed readback");
                    auto* times = static_cast<const UINT64*>(data);
                    double us = static_cast<double>(times[1] - times[0]) * 1e6 / frequency;
                    auto* hashes = static_cast<const UINT*>(data) + 4;
                    UINT wrong = 0;
                    for (UINT i = 0; i < lanes; ++i) wrong += hashes[i] != wanted[i];
                    readback->Unmap(0, &empty);
                    if (repeat) std::printf("%u,%s,%s,%d,%.3f,%.3f,%u\n", repeat, scatter ? "permuted" : "linear",
                                            conditions[condition], types[h], us, updateUs, wrong);
                    if (wrong) throw std::runtime_error("GPU hashes differ from the CPU reference.");
                }
            }
        }
    }
    return 0;
}

int main() {
    try { return run(); }
    catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); return 1; }
}
**@⁠sawetco** on GitHub · 2026-11-25 21:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/887#issuecomment-7175274059) I tested the two GPU source changes from `fbecee4` on an RTX 5070 (12 GB, 621.24), Ryzen 5 7600X, Windows 11 build 26300. The driver accepted both allocation types. The unit test reported heap type 2 with placement off and 5 with it on. Each enabled game run logged one 8,388,608-byte descriptor-stride table in CPU-visible video memory. **Shader reads after a CPU update were substantially faster on the GPU upload heap in an isolated D3D12 test.** The compute shader reads each dword of an 8 MiB table once and produces 32,768 hashes. These are median GPU timestamps in microseconds over six measurements per cell, alternating heap order. The static warm-up uses the same shader. The update changes one dword per 256 bytes, in permuted order, with fresh values each time. | Immediately before the timed dispatch | Shader access | UPLOAD | GPU_UPLOAD | | --- | --- | ---: | ---: | | Same table already read | Linear | 11.2 µs | 11.9 µs | | Same table already read | Permuted | 40.7 µs | 41.4 µs | | 32,768 scattered CPU updates | Linear | 319.1 µs | 36.4 µs | | 32,768 scattered CPU updates | Permuted | 5,625.5 µs | 76.6 µs | The CPU update itself took a median of 247–252 µs across these cases. All 2,359,296 result hashes across 72 timed dispatches matched the CPU reference, including a third precondition that wrote a separate 128 MiB GPU buffer. The synthetic access pattern deliberately touches the entire table. Actual shaders can use a much smaller subset. **Gameplay on this downstream build gave mixed results.** I applied the PR's two source-file hunks without edits to a local build based on `vitutu1/victory-perf@97c3aa2` with the water and face fixes. Both settings used the same binary, a fresh copy of the same house save, 4,068 warm shader files, two pipeline-cache files, Series S at 0.5 render scale, and `VICTORY_REBAR=0` for guest-memory windows. | Run order | Stride-table placement | Host presents/s | Median interval | P95 interval | | ---: | --- | ---: | ---: | ---: | | 1 | UPLOAD | 4.86 | 166.9 ms | 390.1 ms | | 2 | GPU_UPLOAD | 5.72 | 164.1 ms | 276.6 ms | | 3 | GPU_UPLOAD | 5.64 | 163.8 ms | 306.1 ms | | 4 | UPLOAD | 6.10 | 156.3 ms | 230.4 ms | These are 127 complete host Present intervals per run between frames 1920 and 2048, with Jason viewed side-on at the same porch in all eight endpoint images. I chose that window after checking the captures. The originally planned start at frame 1632 was still a loading transition in two runs. Idle animation, streaming and shadows varied. The direction of the gameplay difference reversed across pairs. This supports keeping the option available for targeted A/B tests. A separate instrumented build also found redundant CPU stores while loading. The stride table starts at zero, and the heap already tracks which slots hold buffers. Omitting the zero store only when both the previous and new slot are non-buffers skipped 317,153 of 737,632 eligible store calls in one loading window (43.0%). A later black-screen-to-porch window skipped 466,915 of 959,757 (48.6%). Buffer-to-texture transitions still explicitly cleared the slot. The local slot-reuse test passed. A separate porch timing pair showed 5.49 vs 5.09 presents/s with suppression, so the counts alone do not justify enabling this change. <details> <summary>Standalone shader-read probe (C++, Windows SDK 10.0.26100, no game files)</summary> Build in a Visual Studio x64 developer prompt using the command in the file header. The program prints CSV, checks both actual heap types and compares each GPU result with the CPU reference. ```cpp // Synthetic D3D12 shader-read benchmark. Build with a current Windows SDK: // cl /nologo /O2 /EHsc /std:c++17 descriptor_stride_probe.cpp d3d12.lib dxgi.lib d3dcompiler.lib #include <windows.h> #include <d3d12.h> #include <d3dcompiler.h> #include <dxgi1_6.h> #include <wrl/client.h> #include <array> #include <chrono> #include <cstdint> #include <cstdio> #include <stdexcept> #include <utility> #include <vector> using Microsoft::WRL::ComPtr; constexpr UINT words = 2 * 1024 * 1024; constexpr UINT lanes = 32768; constexpr UINT resultBytes = lanes * sizeof(UINT); constexpr UINT sweepBytes = 128 * 1024 * 1024; const char shader[] = R"( ByteAddressBuffer table : register(t0); RWByteAddressBuffer outputData : register(u0); cbuffer Mode : register(b0) { uint scatter; }; [numthreads(64,1,1)] void readTable(uint3 id : SV_DispatchThreadID) { uint sum = 2166136261u; for (uint i = id.x; i < 2097152u; i += 32768u) { uint slot = scatter ? ((i * 1664525u + 1013904223u) & 2097151u) : i; sum = (sum * 16777619u) ^ table.Load(slot * 4); } outputData.Store(id.x * 4, sum); } [numthreads(64,1,1)] void sweep(uint3 id : SV_DispatchThreadID) { for (uint i = id.x; i < 33554432u; i += 32768u) outputData.Store(i * 4, i * 2654435761u); } )"; void check(HRESULT hr, const char* step) { if (FAILED(hr)) { std::fprintf(stderr, "%s failed (HRESULT 0x%08lx)\n", step, static_cast<unsigned long>(hr)); throw std::runtime_error(step); } } ComPtr<ID3D12Resource> buffer(ID3D12Device* device, D3D12_HEAP_TYPE type, UINT bytes, D3D12_RESOURCE_STATES state, D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) { D3D12_HEAP_PROPERTIES heap{}; heap.Type = type; heap.CreationNodeMask = heap.VisibleNodeMask = 1; D3D12_RESOURCE_DESC desc{}; desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; desc.Width = bytes; desc.Height = 1; desc.DepthOrArraySize = 1; desc.MipLevels = 1; desc.SampleDesc.Count = 1; desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; desc.Flags = flags; ComPtr<ID3D12Resource> result; check(device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, state, nullptr, IID_PPV_ARGS(&result)), "create buffer"); return result; } ComPtr<ID3D12PipelineState> pipeline(ID3D12Device* device, ID3D12RootSignature* root, const char* entry) { ComPtr<ID3DBlob> code, errors; auto hr = D3DCompile(shader, sizeof(shader) - 1, nullptr, nullptr, nullptr, entry, "cs_5_1", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, &code, &errors); if (FAILED(hr) && errors) std::fprintf(stderr, "%s\n", static_cast<const char*>(errors->GetBufferPointer())); check(hr, entry); D3D12_COMPUTE_PIPELINE_STATE_DESC desc{}; desc.pRootSignature = root; desc.CS = {code->GetBufferPointer(), code->GetBufferSize()}; ComPtr<ID3D12PipelineState> result; check(device->CreateComputePipelineState(&desc, IID_PPV_ARGS(&result)), "create compute pipeline"); return result; } void uavBarrier(ID3D12GraphicsCommandList* list, ID3D12Resource* resource) { D3D12_RESOURCE_BARRIER barrier{}; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; barrier.UAV.pResource = resource; list->ResourceBarrier(1, &barrier); } uint32_t value(uint32_t i) { return ((i ^ (i >> 11)) * 2654435761u) + 97u; } std::vector<UINT> referenceHashes(bool scatter, UINT salt) { std::vector<UINT> hashes(lanes, 2166136261u); for (UINT i = 0; i < words; ++i) { UINT slot = scatter ? ((i * 1664525u + 1013904223u) & (words - 1)) : i; UINT updated = value(slot) ^ (slot % 64 == 0 ? salt : 0); hashes[i % lanes] = (hashes[i % lanes] * 16777619u) ^ updated; } return hashes; } double updateTable(ID3D12Resource* table, UINT salt) { D3D12_RANGE noReads{}; void* data = nullptr; auto start = std::chrono::steady_clock::now(); check(table->Map(0, &noReads, &data), "map table for updates"); for (UINT n = 0; n < lanes; ++n) { UINT slot = ((n * 1664525u + 1013904223u) & (lanes - 1)) * 64; static_cast<UINT*>(data)[slot] = value(slot) ^ salt; } table->Unmap(0, nullptr); return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start).count(); } int run() { ComPtr<IDXGIFactory6> factory; ComPtr<IDXGIAdapter1> adapter; ComPtr<ID3D12Device> device; check(CreateDXGIFactory1(IID_PPV_ARGS(&factory)), "DXGI factory"); check(factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter)), "hardware adapter"); DXGI_ADAPTER_DESC1 adapterInfo{}; check(adapter->GetDesc1(&adapterInfo), "adapter description"); check(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)), "D3D12 device"); D3D12_FEATURE_DATA_D3D12_OPTIONS16 features{}; check(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &features, sizeof(features)), "options 16"); if ((adapterInfo.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) || !features.GPUUploadHeapSupported) throw std::runtime_error("A hardware adapter with GPU upload heaps is required."); D3D12_ROOT_PARAMETER params[3]{}; params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV; params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; params[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; params[2].Constants.Num32BitValues = 1; D3D12_ROOT_SIGNATURE_DESC sig{}; sig.NumParameters = 3; sig.pParameters = params; ComPtr<ID3DBlob> serialized; check(D3D12SerializeRootSignature(&sig, D3D_ROOT_SIGNATURE_VERSION_1, &serialized, nullptr), "serialize root"); ComPtr<ID3D12RootSignature> root; check(device->CreateRootSignature(0, serialized->GetBufferPointer(), serialized->GetBufferSize(), IID_PPV_ARGS(&root)), "create root"); auto reader = pipeline(device.Get(), root.Get(), "readTable"); auto sweeper = pipeline(device.Get(), root.Get(), "sweep"); const std::array<D3D12_HEAP_TYPE, 2> types{D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_GPU_UPLOAD}; std::array<ComPtr<ID3D12Resource>, 4> tables; D3D12_RANGE empty{}; for (UINT h = 0; h < tables.size(); ++h) { auto type = types[h % types.size()]; tables[h] = buffer(device.Get(), type, words * sizeof(UINT), D3D12_RESOURCE_STATE_GENERIC_READ); D3D12_HEAP_PROPERTIES actual{}; check(tables[h]->GetHeapProperties(&actual, nullptr), "check actual heap"); if (actual.Type != type) throw std::runtime_error("Unexpected table heap type."); void* mapping = nullptr; check(tables[h]->Map(0, &empty, &mapping), "map table for writing"); for (UINT i = 0; i < words; ++i) static_cast<UINT*>(mapping)[i] = value(i); tables[h]->Unmap(0, nullptr); } auto output = buffer(device.Get(), D3D12_HEAP_TYPE_DEFAULT, resultBytes, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); auto pressure = buffer(device.Get(), D3D12_HEAP_TYPE_DEFAULT, sweepBytes, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); auto readback = buffer(device.Get(), D3D12_HEAP_TYPE_READBACK, resultBytes + 16, D3D12_RESOURCE_STATE_COPY_DEST); const std::array<std::vector<UINT>, 2> expected{referenceHashes(false, 0), referenceHashes(true, 0)}; ComPtr<ID3D12CommandQueue> queue; ComPtr<ID3D12CommandAllocator> allocator; ComPtr<ID3D12GraphicsCommandList> list; ComPtr<ID3D12Fence> fence; ComPtr<ID3D12QueryHeap> queries; D3D12_COMMAND_QUEUE_DESC q{}; q.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; check(device->CreateCommandQueue(&q, IID_PPV_ARGS(&queue)), "create queue"); check(device->CreateCommandAllocator(q.Type, IID_PPV_ARGS(&allocator)), "create allocator"); check(device->CreateCommandList(0, q.Type, allocator.Get(), nullptr, IID_PPV_ARGS(&list)), "create list"); check(list->Close(), "close initial list"); check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), "create fence"); D3D12_QUERY_HEAP_DESC queryDesc{D3D12_QUERY_HEAP_TYPE_TIMESTAMP, 2, 0}; check(device->CreateQueryHeap(&queryDesc, IID_PPV_ARGS(&queries)), "create query heap"); UINT64 frequency = 0, completed = 0; check(queue->GetTimestampFrequency(&frequency), "timestamp frequency"); std::fprintf(stderr, "adapter=%ls frequency=%llu Hz table_bytes=%u lanes=%u\n", adapterInfo.Description, frequency, words * 4, lanes); const char* conditions[] = {"warm", "after_128MiB_write", "after_32768_cpu_updates"}; std::puts("repeat,access,precondition,heap,gpu_us,cpu_update_us,wrong_hashes"); for (UINT repeat = 0; repeat <= 6; ++repeat) { for (UINT scatter = 0; scatter < 2; ++scatter) { UINT salt = 2654435761u * (1 + repeat * 2 + scatter); auto updated = referenceHashes(scatter != 0, salt); for (UINT condition = 0; condition < 3; ++condition) { for (UINT order = 0; order < 2; ++order) { UINT h = (repeat + order) % 2; bool dynamic = condition == 2; auto* table = tables[h + (dynamic ? 2 : 0)].Get(); const auto& wanted = dynamic ? updated : expected[scatter]; double updateUs = dynamic ? updateTable(table, salt) : 0; check(allocator->Reset(), "reset allocator"); check(list->Reset(allocator.Get(), nullptr), "reset list"); list->SetComputeRootSignature(root.Get()); list->SetComputeRootShaderResourceView(0, table->GetGPUVirtualAddress()); list->SetComputeRoot32BitConstant(2, scatter, 0); if (!dynamic) { auto* before = condition == 1 ? pressure.Get() : output.Get(); list->SetPipelineState(condition == 1 ? sweeper.Get() : reader.Get()); list->SetComputeRootUnorderedAccessView(1, before->GetGPUVirtualAddress()); list->Dispatch(lanes / 64, 1, 1); // Order the cache-pressure pass even when it uses a different UAV. uavBarrier(list.Get(), nullptr); } list->SetPipelineState(reader.Get()); list->SetComputeRootUnorderedAccessView(1, output->GetGPUVirtualAddress()); list->EndQuery(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0); list->Dispatch(lanes / 64, 1, 1); uavBarrier(list.Get(), output.Get()); list->EndQuery(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 1); list->ResolveQueryData(queries.Get(), D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, readback.Get(), 0); D3D12_RESOURCE_BARRIER copy{}; copy.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; copy.Transition = {output.Get(), D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE}; list->ResourceBarrier(1, &copy); list->CopyBufferRegion(readback.Get(), 16, output.Get(), 0, resultBytes); std::swap(copy.Transition.StateBefore, copy.Transition.StateAfter); list->ResourceBarrier(1, &copy); check(list->Close(), "close list"); ID3D12CommandList* lists[] = {list.Get()}; queue->ExecuteCommandLists(1, lists); check(queue->Signal(fence.Get(), ++completed), "signal fence"); check(fence->SetEventOnCompletion(completed, nullptr), "wait for readback"); check(device->GetDeviceRemovedReason(), "GPU completion"); void* data = nullptr; D3D12_RANGE range{0, resultBytes + 16}; check(readback->Map(0, &range, &data), "map completed readback"); auto* times = static_cast<const UINT64*>(data); double us = static_cast<double>(times[1] - times[0]) * 1e6 / frequency; auto* hashes = static_cast<const UINT*>(data) + 4; UINT wrong = 0; for (UINT i = 0; i < lanes; ++i) wrong += hashes[i] != wanted[i]; readback->Unmap(0, &empty); if (repeat) std::printf("%u,%s,%s,%d,%.3f,%.3f,%u\n", repeat, scatter ? "permuted" : "linear", conditions[condition], types[h], us, updateUs, wrong); if (wrong) throw std::runtime_error("GPU hashes differ from the CPU reference."); } } } } return 0; } int main() { try { return run(); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); return 1; } } ``` </details>
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/887/head:github-bot/gh-887'
git switch 'github-bot/gh-887'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-887'
git switch 'github-bot/gh-887'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-887'
git switch 'github-bot/gh-887'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-887'
git switch 'main'
git merge --squash 'github-bot/gh-887'
git switch 'main'
git merge --ff-only 'github-bot/gh-887'
git switch 'main'
git merge 'github-bot/gh-887'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.