native: a render target view draws in the format it names #145

Merged
ItsMariusBC merged 1 commit from upstream-pr/145 into main 2026-11-26 22:38:17 +00:00
ItsMariusBC commented 2026-11-26 20:31:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-26T20:31:12Z.


What this changes

On the native host, OMSetRenderTargets and ClearRenderTargetView now draw in the format the render target view names. This is the boot movie shown too bright ("colours look off" in #110).

Cause. glue::targets bound the host texture of the view's resource and never read the view's description. The view's format says how writes are stored. The title draws its boot movie through a plain view (R8G8B8A8_UNORM, 28) of an sRGB texture (29): the picture is display values already, and drawn into the sRGB texture itself it was encoded a second time.

The Windows host does not have this: Host::rtv passes the title's description to CreateRenderTargetView.

Fix. Title::target_of gives what a view draws into: the host texture, or a host view of it in the other format of its sRGB pair when the title's view names that one. The view is kept with the texture, so the same targets are still the same Rc from one call to the next. TargetFormats takes the view's format, so the pipeline matches the attachment.

Limits:

  • Only the two sRGB pairs the native host knows: R8G8B8A8 and B8G8R8A8, UNORM against UNORM_SRGB.
  • The view's other fields (mip, slice) are still not read.

How it was tested

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • Ran the game: Series S, 75 s (boot movie), on 49e7c64 plus this change. Not run again after the rebase on 57b7ebd.

New test a_render_target_view_stores_in_the_format_it_names clears half grey through a view and reads the texture's bytes, for four cases:

Texture View Stored
29 (sRGB) 28 (plain) 128
28 (plain) 29 (sRGB) 188
29 (sRGB) none 188
28 (plain) 28 (plain) 128

Without the change it fails on the first case, which stores 188.

In the game: with a temporary log line (not in this pull request), one such view is made in the run, about 33 s in, when the movie starts: texture Rgba8UnormSrgb, view Rgba8Unorm. By eye the movie's colours are now right; before, it looked as if brightness was turned all the way up.

cargo xtask policy passes.

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 (no guess: the view's format is in the title's description; native-host.md has a paragraph on it)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5516758136 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145). Originally posted by [ItsMariusBC](https://github.com/ItsMariusBC) on 2026-11-26T20:31:12Z. --- ## What this changes On the native host, `OMSetRenderTargets` and `ClearRenderTargetView` now draw in the format the render target view names. This is the boot movie shown too bright ("colours look off" in #110). **Cause.** `glue::targets` bound the host texture of the view's resource and never read the view's description. The view's format says how writes are stored. The title draws its boot movie through a plain view (R8G8B8A8_UNORM, 28) of an sRGB texture (29): the picture is display values already, and drawn into the sRGB texture itself it was encoded a second time. The Windows host does not have this: `Host::rtv` passes the title's description to `CreateRenderTargetView`. **Fix.** `Title::target_of` gives what a view draws into: the host texture, or a host view of it in the other format of its sRGB pair when the title's view names that one. The view is kept with the texture, so the same targets are still the same `Rc` from one call to the next. `TargetFormats` takes the view's format, so the pipeline matches the attachment. Limits: - Only the two sRGB pairs the native host knows: R8G8B8A8 and B8G8R8A8, UNORM against UNORM_SRGB. - The view's other fields (mip, slice) are still not read. ## How it was tested - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] Ran the game: Series S, 75 s (boot movie), on 49e7c64 plus this change. Not run again after the rebase on 57b7ebd. New test `a_render_target_view_stores_in_the_format_it_names` clears half grey through a view and reads the texture's bytes, for four cases: | Texture | View | Stored | | --- | --- | --- | | 29 (sRGB) | 28 (plain) | 128 | | 28 (plain) | 29 (sRGB) | 188 | | 29 (sRGB) | none | 188 | | 28 (plain) | 28 (plain) | 128 | Without the change it fails on the first case, which stores 188. In the game: with a temporary log line (not in this pull request), one such view is made in the run, about 33 s in, when the movie starts: texture `Rgba8UnormSrgb`, view `Rgba8Unorm`. By eye the movie's colours are now right; before, it looked as if brightness was turned all the way up. `cargo xtask policy` passes. ## 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 (no guess: the view's format is in the title's description; native-host.md has a paragraph on it) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
ItsMariusBC commented 2026-11-26 20:37:39 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-26T20:37:39Z.


Run again after the rebase: main 0ae6cfc with this branch and #144 merged on top, Series S, 75 s, cold shader cache, same Mac.

  • No exception and no Metal error in the log.
  • By eye: the boot movie's colours are right.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7202906339 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145#issuecomment-7202906339). Originally posted by [ItsMariusBC](https://github.com/ItsMariusBC) on 2026-11-26T20:37:39Z. --- Run again after the rebase: main 0ae6cfc with this branch and #144 merged on top, Series S, 75 s, cold shader cache, same Mac. - No exception and no Metal error in the log. - By eye: the boot movie's colours are right.
LakshanSivakumar commented 2026-11-26 22:38:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T22:38:14Z.

Review: APPROVED


Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6081182914 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145#pullrequestreview-6081182914). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T22:38:14Z. **Review:** APPROVED --- Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
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!145
No description provided.