gpu(native): read the guessed pipelines' polygon offset from the register image #67

Manually merged
github merged 2 commits from gh-pr/67/head into gh-pr/67/base 2026-11-26 14:45:04 +00:00
Owner

@⁠Olima34 on GitHub · 2026-11-26 12:50 UTC · original
Olima34:fix/guessed-depth-bias → main · +24 −4 · 2 files · 2 commits · merged 2026-11-26 13:34 UTC

What this changes

Closes #18: the part left after #25, decoding the depth bias for guessed pipelines.

Graphics::guess_from now reads the three polygon offset floats that sit 0x24, 0x20 and 0x1c bytes before the blend block of the 0x1c8 register image (listed in native-host.md as "floats (polygon offset): not used yet") into the guessed state's depth bias. victory-metal already passes that bias to setDepthBias:slopeScale:clamp: on every draw since #25.

  • The floats are taken in register order, PA_SU_POLY_OFFSET_CLAMP, _FRONT_SCALE and _FRONT_OFFSET (0x28b7c to 0x28b84). They are converted back the way AMD's PAL writes them in CmdSetDepthBiasState: the clamp as it is, the slope scale times 16 ("HW applies a factor of 1/16th to the Z gradients"), and D3D12's integer bias as a float. So DepthBias is the offset, SlopeScaledDepthBias is the scale / 16 and DepthBiasClamp is the clamp.
  • They are read only when POLY_OFFSET_FRONT_ENABLE (bit 11 of PA_SU_SC_MODE_CNTL) is set. All four PA_SU_SC_MODE_CNTL values in the table set it, along with bit 12, the back face's.
  • A variant's rasterizer record (0x1b8) still replaces it, as it does for culling.
  • Pipelines whose floats are zero get the same state as before.

This is a guess, and it is marked as one in the code and in native-host.md. I don't have the game, so which float is which was not checked against real images. What supports the guess: the two constants just before the floats (0x8, 0x1000) look like PA_SU_LINE_CNTL and PA_SC_LINE_CNTL (0x1000 is DX10_DIAMOND_TEST_ENA), so these words look like a raster group. Also, the 16.0 seen is a slope scale of 1 in hardware units. A quick check on images dumped with VICTORY_DUMP_DESC_DIR: the word 0x1c back should only ever hold whole numbers, and 16.0 should be at 0x20 back. If the order turns out different, the fix is one line.

The docs change also refreshes the "State" bullet of the guessed-pipelines list. It still said "no culling, depth less-equal with writes", but those have been read from the image since f280b71.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: every test passes except the 16 that build the native probe (native_probe, native_list_imports). Those need Homebrew's LLVM (llvm-dlltool), which this Mac doesn't have. This change doesn't touch those crates.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with --all-features
  • cargo xtask policy
  • victory-gpu tests on arm64: blend_is_read_from_the_register_image now also checks that the bias is read and handed to Metal in its order (bias, slope scale, clamp), and that there is none without POLY_OFFSET_FRONT_ENABLE. The test fails without the change (left: (0, 0.0, 0.0), right: (29, 0.003, 1.0)). With the Metal Shader Converter 4.0 installed, the whole victory-gpu suite passes (155 tests, including the Metal render test depth_bias_resets_between_draws_in_the_same_pass), and so does victory-metal (15 tests).
  • Ran the game: not done, as I have no copy of it here.

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
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Olima34** on GitHub · 2026-11-26 12:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/67) `Olima34:fix/guessed-depth-bias` → `main` · +24 −4 · 2 files · 2 commits · merged 2026-11-26 13:34 UTC ## What this changes Closes #18: the part left after #25, decoding the depth bias for guessed pipelines. `Graphics::guess_from` now reads the three polygon offset floats that sit 0x24, 0x20 and 0x1c bytes before the blend block of the 0x1c8 register image (listed in native-host.md as "floats (polygon offset): not used yet") into the guessed state's depth bias. `victory-metal` already passes that bias to `setDepthBias:slopeScale:clamp:` on every draw since #25. - The floats are taken in register order, `PA_SU_POLY_OFFSET_CLAMP`, `_FRONT_SCALE` and `_FRONT_OFFSET` (0x28b7c to 0x28b84). They are converted back the way AMD's PAL writes them in `CmdSetDepthBiasState`: the clamp as it is, the slope scale times 16 ("HW applies a factor of 1/16th to the Z gradients"), and D3D12's integer bias as a float. So `DepthBias` is the offset, `SlopeScaledDepthBias` is the scale / 16 and `DepthBiasClamp` is the clamp. - They are read only when `POLY_OFFSET_FRONT_ENABLE` (bit 11 of `PA_SU_SC_MODE_CNTL`) is set. All four `PA_SU_SC_MODE_CNTL` values in the table set it, along with bit 12, the back face's. - A variant's rasterizer record (0x1b8) still replaces it, as it does for culling. - Pipelines whose floats are zero get the same state as before. **This is a guess, and it is marked as one** in the code and in native-host.md. I don't have the game, so which float is which was not checked against real images. What supports the guess: the two constants just before the floats (0x8, 0x1000) look like `PA_SU_LINE_CNTL` and `PA_SC_LINE_CNTL` (0x1000 is `DX10_DIAMOND_TEST_ENA`), so these words look like a raster group. Also, the 16.0 seen is a slope scale of 1 in hardware units. A quick check on images dumped with `VICTORY_DUMP_DESC_DIR`: the word 0x1c back should only ever hold whole numbers, and 16.0 should be at 0x20 back. If the order turns out different, the fix is one line. The docs change also refreshes the "State" bullet of the guessed-pipelines list. It still said "no culling, depth less-equal with writes", but those have been read from the image since f280b71. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: every test passes except the 16 that build the native probe (`native_probe`, `native_list_imports`). Those need Homebrew's LLVM (`llvm-dlltool`), which this Mac doesn't have. This change doesn't touch those crates. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`, also with `--all-features` - [x] `cargo xtask policy` - [x] `victory-gpu` tests on arm64: `blend_is_read_from_the_register_image` now also checks that the bias is read and handed to Metal in its order (bias, slope scale, clamp), and that there is none without `POLY_OFFSET_FRONT_ENABLE`. The test fails without the change (`left: (0, 0.0, 0.0)`, `right: (29, 0.003, 1.0)`). With the Metal Shader Converter 4.0 installed, the whole `victory-gpu` suite passes (155 tests, including the Metal render test `depth_bias_resets_between_draws_in_the_same_pass`), and so does `victory-metal` (15 tests). - [ ] Ran the game: not done, as I have no copy of it here. ## 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 - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
The three floats 0x24, 0x20 and 0x1c bytes before the blend block of the
0x1c8 register image are taken as PA_SU_POLY_OFFSET_CLAMP, _FRONT_SCALE and
_FRONT_OFFSET (register order, as AMD's PAL writes them: slope scale in
1/16ths, D3D12's integer bias as a float). They become the guessed state's
depth bias when POLY_OFFSET_FRONT_ENABLE is set, which victory-metal already
passes to setDepthBias:slopeScale:clamp:. The order is a guess, marked in the
code and explained in native-host.md with how to check it.

Closes #18
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:01 +00:00
github manually merged commit 0ce3d37268 into gh-pr/67/base 2026-11-26 14:45:04 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 13:26 UTC · original · approved these changes

Code, tests, and docs/native-host.md changes look solid: Graphics::guess_from reads PA_SU_POLY_OFFSET_CLAMP, _FRONT_SCALE (/ 16.0), and _FRONT_OFFSET into g.bias when POLY_OFFSET_FRONT_ENABLE is set, clearly marked as a guess in code and docs, and blend_is_read_from_the_register_image pins the field order and enable bit. Approving; waiting on CI to pass before merging.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 13:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/67#pullrequestreview-6074930416) · **approved these changes** Code, tests, and `docs/native-host.md` changes look solid: `Graphics::guess_from` reads `PA_SU_POLY_OFFSET_CLAMP`, `_FRONT_SCALE` (/ 16.0), and `_FRONT_OFFSET` into `g.bias` when `POLY_OFFSET_FRONT_ENABLE` is set, clearly marked as a guess in code and docs, and `blend_is_read_from_the_register_image` pins the field order and enable bit. Approving; waiting on CI to pass before merging.
This discussion has been locked. Commenting is limited to contributors.
No description provided.