shader: the vertex buffer table is not read from user data where root views are title memory #260

Merged
Sandile-0511 merged 2 commits from upstream-pr/260 into main 2026-11-27 08:10:19 +00:00
Sandile-0511 commented 2026-11-27 05:37:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T05:37:57Z.


What this changes

Fixes a black window from the first frame on main (seen on 76c001a and on 2a3b03d): the menus and the boot movie's sound play with no picture. A guessed vertex program's vertex buffer table was read from user data that no host fills.

Since 8f8d72a (#207), a vertex or pixel program translated with zero_copy_memory reads a root descriptor's address from its user data, because root views are title memory there. The vertex buffer table of a guessed vertex program (graphics::VERTEX_TABLE, slot 253) is a RootType::Descriptor in the layout too. A program that copies s0/s1 before loading through them (s_mov_b32 s2, s0; s_mov_b32 s3, s1; s_load_dwordx4 s[8:11], s[2:3]) reaches Lower::user for that parameter, which now returned the user-data dwords. The host has no root argument for slot 253, gave 0, and the vertex fetch read nothing. The draws are still recorded and encoded, so the frame counters look normal.

Lower::user now leaves the vertex table out of that arm, which is what it did before 8f8d72a. Root SRVs and UAVs still go through the page table, so #207's fix for vertex buffers whose pages are mapped apart in the pool is unchanged.

Possibly related: #246 reports a black window at 76c001a. I can't tell from that report whether this is its cause.

How it was tested

  • cargo test -p victory-shader -p victory-hle and cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass. New tests the_vertex_tables_address_used_as_a_number_is_refused (the negative asked for in review) and the_vertex_table_is_not_read_from_user_data_where_root_views_are_title_memory: without the change it fails with [UserData { index: 0, slot: 253, root: Descriptor, dword: 0 }, UserData { index: 1, slot: 253, root: Descriptor, dword: 1 }].
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (clean, run on a Mac)
  • cargo xtask policy (369 files ok)
  • Ran the game (M5, 24 GB, Series S profile). How it was found: a bisect between 23911f5 and 76c001a by the contents of the game window ended at 8f8d72a. A temporary log line in the draw path then showed every menu pipeline's vertex binding with user data 253:Descriptor:0 and 253:Descriptor:1; with this change they are gone. Results, one run each:
Build Window
76c001a black, movie sound plays
76c001a with the stage != Cs condition of 8f8d72a turned off menus and movie
76c001a with this change menus and movie
2a3b03d black: six captures of the window from 40 to 89 s
2a3b03d with this change menus and movie; the world is still black (#182)

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none added)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5521795167 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/260). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T05:37:57Z. --- ## What this changes Fixes a black window from the first frame on `main` (seen on `76c001a` and on `2a3b03d`): the menus and the boot movie's sound play with no picture. A guessed vertex program's vertex buffer table was read from user data that no host fills. Since 8f8d72a (#207), a vertex or pixel program translated with `zero_copy_memory` reads a root descriptor's address from its user data, because root views are title memory there. The vertex buffer table of a guessed vertex program (`graphics::VERTEX_TABLE`, slot 253) is a `RootType::Descriptor` in the layout too. A program that copies s0/s1 before loading through them (`s_mov_b32 s2, s0; s_mov_b32 s3, s1; s_load_dwordx4 s[8:11], s[2:3]`) reaches `Lower::user` for that parameter, which now returned the user-data dwords. The host has no root argument for slot 253, gave 0, and the vertex fetch read nothing. The draws are still recorded and encoded, so the frame counters look normal. `Lower::user` now leaves the vertex table out of that arm, which is what it did before 8f8d72a. Root SRVs and UAVs still go through the page table, so #207's fix for vertex buffers whose pages are mapped apart in the pool is unchanged. Possibly related: #246 reports a black window at `76c001a`. I can't tell from that report whether this is its cause. ## How it was tested - [x] `cargo test -p victory-shader -p victory-hle` and `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass. New tests `the_vertex_tables_address_used_as_a_number_is_refused` (the negative asked for in review) and `the_vertex_table_is_not_read_from_user_data_where_root_views_are_title_memory`: without the change it fails with `[UserData { index: 0, slot: 253, root: Descriptor, dword: 0 }, UserData { index: 1, slot: 253, root: Descriptor, dword: 1 }]`. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (clean, run on a Mac) - [x] `cargo xtask policy` (369 files ok) - [x] Ran the game (M5, 24 GB, Series S profile). How it was found: a bisect between 23911f5 and 76c001a by the contents of the game window ended at 8f8d72a. A temporary log line in the draw path then showed every menu pipeline's vertex binding with user data `253:Descriptor:0` and `253:Descriptor:1`; with this change they are gone. Results, one run each: | Build | Window | |---|---| | 76c001a | black, movie sound plays | | 76c001a with the `stage != Cs` condition of 8f8d72a turned off | menus and movie | | 76c001a with this change | menus and movie | | 2a3b03d | black: six captures of the window from 40 to 89 s | | 2a3b03d with this change | menus and movie; the world is still black (#182) | ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none added) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
LakshanSivakumar commented 2026-11-27 06:48:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T06:48:35Z.


Thank you for the bisect and for naming the commit that introduced it. The change is one condition and the log line (253:Descriptor:0/1) makes the cause easy to follow.

Before it can merge:

  1. Please add a negative: a vertex program that uses s0/s1 of the vertex table in another way than as the address of a load (for example adds an offset, or stores it) must still be refused. From reading Lower::user it returns the missing value there, but a test should say so.
  2. Please give the comparison by output fingerprint over the corpus for the vertex stage (gained, regressed, changed). I expect no program to lose translation and only the ones that copy s0/s1 to change.
  3. The text says the window is black from the first frame on main. Your table shows 2a3b03d reaching menus and movie with this change and the world still black. Please say which commit shows the black menus.

Animacustoms reports in #258 a black picture during the intro on current main. This may be the cause. I have not checked.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7211866601 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/260#issuecomment-7211866601). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T06:48:35Z. --- Thank you for the bisect and for naming the commit that introduced it. The change is one condition and the log line (`253:Descriptor:0/1`) makes the cause easy to follow. Before it can merge: 1. Please add a negative: a vertex program that uses s0/s1 of the vertex table in another way than as the address of a load (for example adds an offset, or stores it) must still be refused. From reading `Lower::user` it returns the missing value there, but a test should say so. 2. Please give the comparison by output fingerprint over the corpus for the vertex stage (gained, regressed, changed). I expect no program to lose translation and only the ones that copy s0/s1 to change. 3. The text says the window is black from the first frame on `main`. Your table shows 2a3b03d reaching menus and movie with this change and the world still black. Please say which commit shows the black menus. Animacustoms reports in #258 a black picture during the intro on current main. This may be the cause. I have not checked.
Sandile-0511 commented 2026-11-27 07:46:34 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T07:46:34Z.


Thank you for the review. All three are done; the new test is in 8612fe4.

1. The negative. the_vertex_tables_address_used_as_a_number_is_refused: three vertex programs that use s0 of the vertex table as a number (exported as it is; copied to another SGPR and exported; with an offset added and exported) are refused with "a root descriptor", with and without zero_copy_memory. Without the change the first of them translates with zero_copy_memory, the address read from user data, so the test fails there: that accept goes away with the fix too.

2. Corpus, by output fingerprint. 21,608 containers (every shader the title registered in a run that reached the prologue world), translated with emit::translate_with and the native host's options; this branch against 2a3b03d1. Two sweeps of one build are identical.

Stage Shaders Translate on both Gained Regressed Output changed Refused on both, for another reason
Vertex 8,847 8,163 0 0 415 0
Pixel 10,000 7,888 0 0 0 0
Compute 2,761 1,428 0 0 0 0

The 415 are exactly the vertex shaders whose translation on main has user data of slot 253: all 415 have it on main, none has it on the branch, and no shader that has it is unchanged. For all 415 the rest of what the host is told (HostShader without the DXIL) is identical; only the two dwords are gone. 43 of the 415 were bound in that run, 6 of them before the first world frame.

3. Which commit shows the black menus. Both mains I have run. The description named only the first; I have corrected it.

Build Window
76c001a black from the first frame, the movie's sound playing (where the bisect was done)
2a3b03d black: six captures of the window from 40 to 89 s, all black, with 10,114 draws recorded and encoded by frame 2,240 and no error
2a3b03d with this branch the boot movie's picture in the captures at 50, 70, 80 and 89 s (9,053 draws by frame 2,304, no error)

The two 2a3b03d rows are from today: one run each, each build in a target directory of its own.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7212806277 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/260#issuecomment-7212806277). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T07:46:34Z. --- Thank you for the review. All three are done; the new test is in 8612fe4. **1. The negative.** `the_vertex_tables_address_used_as_a_number_is_refused`: three vertex programs that use s0 of the vertex table as a number (exported as it is; copied to another SGPR and exported; with an offset added and exported) are refused with "a root descriptor", with and without `zero_copy_memory`. Without the change the first of them translates with `zero_copy_memory`, the address read from user data, so the test fails there: that accept goes away with the fix too. **2. Corpus, by output fingerprint.** 21,608 containers (every shader the title registered in a run that reached the prologue world), translated with `emit::translate_with` and the native host's options; this branch against `2a3b03d1`. Two sweeps of one build are identical. | Stage | Shaders | Translate on both | Gained | Regressed | Output changed | Refused on both, for another reason | |---|---|---|---|---|---|---| | Vertex | 8,847 | 8,163 | 0 | 0 | 415 | 0 | | Pixel | 10,000 | 7,888 | 0 | 0 | 0 | 0 | | Compute | 2,761 | 1,428 | 0 | 0 | 0 | 0 | The 415 are exactly the vertex shaders whose translation on main has user data of slot 253: all 415 have it on main, none has it on the branch, and no shader that has it is unchanged. For all 415 the rest of what the host is told (`HostShader` without the DXIL) is identical; only the two dwords are gone. 43 of the 415 were bound in that run, 6 of them before the first world frame. **3. Which commit shows the black menus.** Both mains I have run. The description named only the first; I have corrected it. | Build | Window | |---|---| | `76c001a` | black from the first frame, the movie's sound playing (where the bisect was done) | | `2a3b03d` | black: six captures of the window from 40 to 89 s, all black, with 10,114 draws recorded and encoded by frame 2,240 and no error | | `2a3b03d` with this branch | the boot movie's picture in the captures at 50, 70, 80 and 89 s (9,053 draws by frame 2,304, no error) | The two `2a3b03d` rows are from today: one run each, each build in a target directory of its own.
LakshanSivakumar commented 2026-11-27 08:10:19 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:10:19Z.


Thank you. All three points are answered. I ran the branch over my own corpus as well (33,625 containers, by output fingerprint, against main): vertex 415 changed, nothing gained or lost; pixel and compute unchanged. That is your table exactly.

Merged. For testers: if your picture is black in the intro with the sound playing (#258, #265), please update to current main and try again.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213229546 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/260#issuecomment-7213229546). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:10:19Z. --- Thank you. All three points are answered. I ran the branch over my own corpus as well (33,625 containers, by output fingerprint, against main): vertex 415 changed, nothing gained or lost; pixel and compute unchanged. That is your table exactly. Merged. For testers: if your picture is black in the intro with the sound playing (#258, #265), please update to current main and try again.
Sign in to join this conversation.
No reviewers
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
LakshanSivakumar/Native-Victory-macOS!260
No description provided.