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

Manually merged
github merged 1 commit from github-bot/gh-145 into main 2026-11-27 00:51:19 +00:00 AGit
Owner

@⁠ItsMariusBC on GitHub · 2026-11-26 20:31 UTC · original
ItsMariusBC:fix/render-target-view-format → main · +135 −8 · 5 files · 1 commits · merged 2026-11-26 22:38 UTC

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)
**@⁠ItsMariusBC** on GitHub · 2026-11-26 20:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145) `ItsMariusBC:fix/render-target-view-format` → `main` · +135 −8 · 5 files · 1 commits · merged 2026-11-26 22:38 UTC ## 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)
OMSetRenderTargets and ClearRenderTargetView bound the host texture of
the view's resource and ignored the view's own format, which says how
writes are stored. The title draws its boot movie through a plain view
(R8G8B8A8_UNORM) of an sRGB texture: drawn into the texture itself, the
picture was encoded a second time and shown too bright.

A view that names the other format of its texture's sRGB pair now draws
through a host view of the texture in that format, kept with the
texture. The Windows host already passes the title's description to
CreateRenderTargetView.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:31:36 +00:00
Author
Owner

@⁠ItsMariusBC on GitHub · 2026-11-26 20:37 UTC · original

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.
**@⁠ItsMariusBC** on GitHub · 2026-11-26 20:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145#issuecomment-7202906339) 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.
github manually merged commit f70696e74f into main 2026-11-27 00:51:19 +00:00
Author
Owner

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

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

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 22:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/145#pullrequestreview-6081182914) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.