[pr-fix][shaders][linux-proton][NVIDIA] Constant tables from a root SRV under Wine, not in-shader arrays (#298) #394

Open
uuwf0 wants to merge 1 commit from uuwf0/Darner:pr-fix/code-table-root-srv into main
First-time contributor

Run in the game on Linux/Proton only (RTX 5090). Not run on Windows, where nothing changes unless DARNER_CODE_TABLE_ROOT=1 is set.

Fixes #298

Contributor role (optional)

  • Fluxer ID: 1578060959296000000

What it changes

  • The problem on main: #298. On an RTX 5090 under Proton, every run hangs 3 to 25 s after the world starts rendering: Xid 13 ... MMU Fault on driver 620.73, Xid 109 CTX SWITCH TIMEOUT on 615.78, and vkd3d-proton only logs Failed to wait for Vulkan timeline semaphore, vr 2. The same PC under Windows 11 runs fine.

A program's constant table (the data the console compiler appends to the code and reads through s_getpc_b64) is lowered to an internal constant array in the shader (constant_global("code", …) in Lower::code_dword). vkd3d-proton turns that into a SPIR-V Private per-thread array, which NVIDIA's Linux driver keeps in per-thread scratch memory (about 125 MB per KB of table).

This change ports VictoryArch's "M16a" fix (branch darner-up94, 7bc606d), on its own: under Wine, the table is read from a raw root SRV that the host fills once per distinct table.

  • darner-shader: SLOT_CODE_TABLE (t249) and SLOT_CODE_TABLE_PS (t248, pixel shaders) in ROOT_CBV_SPACE. code_dword reads the dword with rawBufferLoad instead of indexing the array, using the same clamp to the last dword. HostShader::code_table carries the dwords to the host.
  • darner-gpu: code_table_address packs the tables into default-heap buffers (4 MiB chunks, 256-byte steps), copies them in once with inplace::Rig and waits for the copy. Identical tables share one copy. draw.rs binds the address as a root SRV, and the slot is skipped where title roots are read. A pipeline whose table cannot be placed is refused with a reason (logged once).
  • When it is on: under Wine (set_host_wine(on_wine()), at device start-up and in darner translate/warm), off elsewhere. DARNER_CODE_TABLE_ROOT=1 turns it on anywhere, =0 off anywhere. The log says constant tables read from root SRVs when it is on.
  • Cache: the choice is the fifth value of host_settings(), so it is in the shader cache key. shader_cache::FORMAT is now 2, because entries now carry the table.

How it was tested

  • Tested revision: ab1c30d (on main f3840d7)

  • Commands and results (Linux, cross-built with cargo xwin, Wine for the tests):

    • Gate 1: cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean.
    • Gate 2: the same with --all-features: clean.
    • Gate 3: cargo xwin test --workspace --locked --target x86_64-pc-windows-msvc --no-fail-fast -- --skip oracle64::legacy_mul_forms_are_exact under Wine (no D3D12 in the prefix, so tests that need a card fail or skip). Branch: 3238 passed, 108 failed; main f3840d7 with the same command: 3238 passed, 107 failed. The lists match except 3 tests that failed only on the branch and 2 only on main, all timing tests (fence::tests::a_null_event_blocks_until_the_value_is_reached, modules::xmem::tests::a_title_thread_goes_on_using_the_rest_of_a_view, run::tests::late_dll_publishes_to_other_threads_only_after_attach_succeeds; on main crash::tests::concurrent_crash_records_stay_together, queue::tests::a_queued_wait_or_signal_keeps_its_fence). Rerun alone on the branch, 3 times each: 3/3, 2/3 and 3/3 pass. The skipped test walks all 2^32 floats and had not finished after 14 minutes in a debug build under Wine; it is untouched here.
    • Not run on Windows.
    • New test pipeline::host::tests::constant_tables_live_in_the_cards_memory, under Wine with vkd3d-proton 0959f0e on the RTX 5090: passes and reaches its last check (tables in a default heap, read back as written, 256-byte steps, the same table at the same address).
    • cargo xtask policy: 555 files ok.
  • Changes a default: yes, under Wine/Proton only. Windows is unchanged.

  • A/B result, same PC (RTX 5090), Proton Experimental, driver 615.78.08, the same automated input each run:

    A (table in the shader) B (table in a root SRV)
    VictoryArch exe (7bc606d), from #298 Xid 109 6 s after the world started rendering, 2 of 2 runs (DARNER_CODE_TABLE_PRIVATE=1) 117 s in the world, 2048+ frames, no Xid
    This branch (ab1c30d), run 1 Xid 109 CTX SWITCH TIMEOUT 7 s after the world started rendering (DARNER_CODE_TABLE_ROOT=0) 2048 frames in the world (171 s), no Xid; log: constant tables read from root SRVs
    This branch (ab1c30d), run 2 Xid 109 CTX SWITCH TIMEOUT 4 s after the world started rendering 2048 frames in the world (213 s), no Xid

    VictoryArch reports no frame-time change from this fix (46 ms against 44 to 46 ms around it, under Proton).

  • Gates run on that revision: 1, 2 and 3 (3 under Wine, see above), all cross-built on Linux. Not run on Windows.

  • Gameplay: RTX 5090, Series X profile, 1080p to 1440p, DLSS quality, no frame generation, ray tracing off; the settings from #298 (DARNER_AMBIENT=0.8, DARNER_PORT_CONSTANTS=1), the same in A and B. Runs are automated: the profile picker is passed with scripted Enter presses (DARNER_KEYS, DARNER_CONTROLS=keyboard, DARNER_MNK=1), then the world loads with no further input; PASS means 2048 frames shown in the world with no Xid in journalctl -k. No frame-time comparison was made (A never gets that far).

  • Shader wave sizes tested: 32 lanes (the host reports host wave lanes min=32 max=32).

  • Hardware dependence: the hang is seen on NVIDIA's Linux driver (620.73 and 615.78). Untested on other cards under Proton (AMD/RADV, Intel). The switch is on for them too under Wine, since the table read is the same either way.

  • Coverage gaps: no translator unit test lowers a program through the root-SRV path (the lowering is exercised in the game only). Not run on Windows with DARNER_CODE_TABLE_ROOT=1.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #292 (constant reads stay inside real CBVs; also lower.rs/shader.rs/shader_cache.rs), #303 and #312 (shader_cache.rs keys), #349 (Wine test fixes in pipeline/host.rs). None moves constant tables.
  • Replaces or overlaps: none found
**Run in the game on Linux/Proton only (RTX 5090). Not run on Windows, where nothing changes unless `DARNER_CODE_TABLE_ROOT=1` is set.** Fixes #298 ## Contributor role (optional) - Fluxer ID: 1578060959296000000 ## What it changes - The problem on main: #298. On an RTX 5090 under Proton, every run hangs 3 to 25 s after the world starts rendering: `Xid 13 ... MMU Fault` on driver 620.73, `Xid 109 CTX SWITCH TIMEOUT` on 615.78, and vkd3d-proton only logs `Failed to wait for Vulkan timeline semaphore, vr 2`. The same PC under Windows 11 runs fine. A program's constant table (the data the console compiler appends to the code and reads through `s_getpc_b64`) is lowered to an internal constant array in the shader (`constant_global("code", …)` in `Lower::code_dword`). vkd3d-proton turns that into a SPIR-V `Private` per-thread array, which NVIDIA's Linux driver keeps in per-thread scratch memory (about 125 MB per KB of table). This change ports VictoryArch's "M16a" fix (branch darner-up94, 7bc606d), on its own: under Wine, the table is read from a raw root SRV that the host fills once per distinct table. - `darner-shader`: `SLOT_CODE_TABLE` (t249) and `SLOT_CODE_TABLE_PS` (t248, pixel shaders) in `ROOT_CBV_SPACE`. `code_dword` reads the dword with `rawBufferLoad` instead of indexing the array, using the same clamp to the last dword. `HostShader::code_table` carries the dwords to the host. - `darner-gpu`: `code_table_address` packs the tables into default-heap buffers (4 MiB chunks, 256-byte steps), copies them in once with `inplace::Rig` and waits for the copy. Identical tables share one copy. `draw.rs` binds the address as a root SRV, and the slot is skipped where title roots are read. A pipeline whose table cannot be placed is refused with a reason (logged once). - **When it is on:** under Wine (`set_host_wine(on_wine())`, at device start-up and in `darner translate`/`warm`), off elsewhere. `DARNER_CODE_TABLE_ROOT=1` turns it on anywhere, `=0` off anywhere. The log says `constant tables read from root SRVs` when it is on. - **Cache:** the choice is the fifth value of `host_settings()`, so it is in the shader cache key. `shader_cache::FORMAT` is now 2, because entries now carry the table. ## How it was tested - Tested revision: ab1c30d (on main f3840d7) - Commands and results (Linux, cross-built with `cargo xwin`, Wine for the tests): - Gate 1: `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings`: clean. - Gate 2: the same with `--all-features`: clean. - Gate 3: `cargo xwin test --workspace --locked --target x86_64-pc-windows-msvc --no-fail-fast -- --skip oracle64::legacy_mul_forms_are_exact` under Wine (no D3D12 in the prefix, so tests that need a card fail or skip). Branch: 3238 passed, 108 failed; main f3840d7 with the same command: 3238 passed, 107 failed. The lists match except 3 tests that failed only on the branch and 2 only on main, all timing tests (`fence::tests::a_null_event_blocks_until_the_value_is_reached`, `modules::xmem::tests::a_title_thread_goes_on_using_the_rest_of_a_view`, `run::tests::late_dll_publishes_to_other_threads_only_after_attach_succeeds`; on main `crash::tests::concurrent_crash_records_stay_together`, `queue::tests::a_queued_wait_or_signal_keeps_its_fence`). Rerun alone on the branch, 3 times each: 3/3, 2/3 and 3/3 pass. The skipped test walks all 2^32 floats and had not finished after 14 minutes in a debug build under Wine; it is untouched here. - Not run on Windows. - New test `pipeline::host::tests::constant_tables_live_in_the_cards_memory`, under Wine with vkd3d-proton 0959f0e on the RTX 5090: passes and reaches its last check (tables in a default heap, read back as written, 256-byte steps, the same table at the same address). - `cargo xtask policy`: 555 files ok. - Changes a default: yes, under Wine/Proton only. Windows is unchanged. - A/B result, same PC (RTX 5090), Proton Experimental, driver 615.78.08, the same automated input each run: | | A (table in the shader) | B (table in a root SRV) | |---|---|---| | VictoryArch exe (7bc606d), from #298 | Xid 109 6 s after the world started rendering, 2 of 2 runs (`DARNER_CODE_TABLE_PRIVATE=1`) | 117 s in the world, 2048+ frames, no Xid | | This branch (ab1c30d), run 1 | Xid 109 CTX SWITCH TIMEOUT 7 s after the world started rendering (`DARNER_CODE_TABLE_ROOT=0`) | 2048 frames in the world (171 s), no Xid; log: `constant tables read from root SRVs` | | This branch (ab1c30d), run 2 | Xid 109 CTX SWITCH TIMEOUT 4 s after the world started rendering | 2048 frames in the world (213 s), no Xid | VictoryArch reports no frame-time change from this fix (46 ms against 44 to 46 ms around it, under Proton). - Gates run on that revision: 1, 2 and 3 (3 under Wine, see above), all cross-built on Linux. Not run on Windows. - Gameplay: RTX 5090, Series X profile, 1080p to 1440p, DLSS quality, no frame generation, ray tracing off; the settings from #298 (`DARNER_AMBIENT=0.8`, `DARNER_PORT_CONSTANTS=1`), the same in A and B. Runs are automated: the profile picker is passed with scripted Enter presses (`DARNER_KEYS`, `DARNER_CONTROLS=keyboard`, `DARNER_MNK=1`), then the world loads with no further input; PASS means 2048 frames shown in the world with no Xid in `journalctl -k`. No frame-time comparison was made (A never gets that far). - Shader wave sizes tested: 32 lanes (the host reports `host wave lanes min=32 max=32`). - Hardware dependence: the hang is seen on NVIDIA's Linux driver (620.73 and 615.78). Untested on other cards under Proton (AMD/RADV, Intel). The switch is on for them too under Wine, since the table read is the same either way. - Coverage gaps: no translator unit test lowers a program through the root-SRV path (the lowering is exercised in the game only). Not run on Windows with `DARNER_CODE_TABLE_ROOT=1`. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #292 (constant reads stay inside real CBVs; also `lower.rs`/`shader.rs`/`shader_cache.rs`), #303 and #312 (`shader_cache.rs` keys), #349 (Wine test fixes in `pipeline/host.rs`). None moves constant tables. - Replaces or overlaps: none found
A program's constant table (the data the console compiler appends to the
code and reads through s_getpc_b64) was lowered to an internal constant
array. vkd3d-proton turns it into a SPIR-V Private per-thread array, which
NVIDIA's Linux driver keeps in per-thread scratch memory; an RTX 5090 under
Proton hung a few seconds after the world started rendering (Xid 13 on
620.73, Xid 109 on 615.78). The same PC under Windows 11 runs fine.

Under Wine the table is now read with rawBufferLoad from a raw root SRV
(t249, t248 for pixel shaders, in ROOT_CBV_SPACE) that the host fills once
per distinct table in the card's memory. DARNER_CODE_TABLE_ROOT=1 turns it
on anywhere and =0 off anywhere. The choice is part of host_settings(), and
so of the shader cache key; shader_cache FORMAT 2 carries the table.

Ported from VictoryArch's "M16a" (darner-up94, 7bc606d), on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uuwf0 changed title from [pr-fix][shaders][linux-proton][NVIDIA] Constant tables from a root SRV under Wine, not in-shader arrays (#298) to [pr-fix][shaders][linux-proton][NVIDIA] Constant tables from a root SRV under Wine, not in-shader arrays (#298) 2026-12-04 19:23:33 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr-fix/code-table-root-srv:uuwf0-pr-fix/code-table-root-srv'
git switch 'uuwf0-pr-fix/code-table-root-srv'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'uuwf0-pr-fix/code-table-root-srv'
git switch 'uuwf0-pr-fix/code-table-root-srv'
git rebase 'main'
git switch 'main'
git merge --ff-only 'uuwf0-pr-fix/code-table-root-srv'
git switch 'uuwf0-pr-fix/code-table-root-srv'
git rebase 'main'
git switch 'main'
git merge --no-ff 'uuwf0-pr-fix/code-table-root-srv'
git switch 'main'
git merge --squash 'uuwf0-pr-fix/code-table-root-srv'
git switch 'main'
git merge --ff-only 'uuwf0-pr-fix/code-table-root-srv'
git switch 'main'
git merge 'uuwf0-pr-fix/code-table-root-srv'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!394
No description provided.