Formats: reserve texture metadata memory in XG layouts #263

Closed
Quat3rnion wants to merge 1 commit from upstream-pr/263 into main
Quat3rnion commented 2026-11-24 01:53:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T01:53:40Z.


What

Render targets and depth buffers carry compression metadata (HTILE, CMASK,
DCC) on the console. The XG layout reported only the data planes, so a title
that sized a pool from it could run out of memory. This adds a conservative
metadata reservation after the data planes in the reported size and
alignment.

The exact metadata plane shapes depend on the GPU's pipe configuration and
their XG usage codes are not published. Rather than invent plane types that
a title might try to copy from, this reserves upper-bound memory (one eighth
of the data for depth, one sixteenth for color, rounded to 64 KiB) and leaves
the plane list and the host's data-plane layout unchanged. Sampled textures
get no reservation.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace with PR #112's Linux build fix applied locally (not part of this PR): 167 passed, 0 failed, 3 ignored. Three new tests cover sampled versus render targets, offset/overflow behaviour and the XG layout output.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. Windows-only tests were not run; there is no Windows host here.
  • cargo xtask policy passes (150 files ok). No game files or data from them were added.
  • Not tested: a real title or console GPU. If the title expects distinct metadata planes rather than a larger total, this change does not supply them.

Checklist

  • cargo fmt on the changed hunks; workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572810808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/263). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T01:53:40Z. --- ## What Render targets and depth buffers carry compression metadata (HTILE, CMASK, DCC) on the console. The XG layout reported only the data planes, so a title that sized a pool from it could run out of memory. This adds a conservative metadata reservation after the data planes in the reported size and alignment. The exact metadata plane shapes depend on the GPU's pipe configuration and their XG usage codes are not published. Rather than invent plane types that a title might try to copy from, this reserves upper-bound memory (one eighth of the data for depth, one sixteenth for color, rounded to 64 KiB) and leaves the plane list and the host's data-plane layout unchanged. Sampled textures get no reservation. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace` with PR #112's Linux build fix applied locally (not part of this PR): 167 passed, 0 failed, 3 ignored. Three new tests cover sampled versus render targets, offset/overflow behaviour and the XG layout output. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. Windows-only tests were not run; there is no Windows host here. - `cargo xtask policy` passes (150 files ok). No game files or data from them were added. - Not tested: a real title or console GPU. If the title expects distinct metadata planes rather than a larger total, this change does not supply them. ## Checklist - [x] `cargo fmt` on the changed hunks; workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
jeremygold02 commented 2026-11-24 06:55:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:01:40Z.


Tested the open PR at head 50d27a5a9237aaf00fee8090fc236e0358a90f2f (still current when refreshed before posting).

  • cargo test --locked -p victory-formats metadata_ — passed metadata_reserves_room_only_for_render_targets and metadata_never_overlaps_or_overflows, covering sampled versus render-target reservations, 1D handling, alignment and overflow bounds in texture.rs.
  • cargo test --locked -p victory-hle render_targets_reserve_metadata_memory — passed render_targets_reserve_metadata_memory, exercising the XG layout response for color/depth size and alignment while checking data-plane count in xg.rs.

These are synthetic unit tests; a real title or console GPU was not exercised.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121638689 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/263#issuecomment-7121638689). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:01:40Z. --- Tested the open PR at head `50d27a5a9237aaf00fee8090fc236e0358a90f2f` (still current when refreshed before posting). - `cargo test --locked -p victory-formats metadata_` — passed `metadata_reserves_room_only_for_render_targets` and `metadata_never_overlaps_or_overflows`, covering sampled versus render-target reservations, 1D handling, alignment and overflow bounds in [texture.rs](https://github.com/Marvisak/VIctory/blob/50d27a5a9237aaf00fee8090fc236e0358a90f2f/crates/victory-formats/src/texture.rs). - `cargo test --locked -p victory-hle render_targets_reserve_metadata_memory` — passed `render_targets_reserve_metadata_memory`, exercising the XG layout response for color/depth size and alignment while checking data-plane count in [xg.rs](https://github.com/Marvisak/VIctory/blob/50d27a5a9237aaf00fee8090fc236e0358a90f2f/crates/victory-hle/src/modules/xg.rs). These are synthetic unit tests; a real title or console GPU was not exercised.
mercuryVM commented 2026-11-24 13:16:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T13:16:37Z.

Review: APPROVED


Tested e5eaf4a on Windows 11, RTX 5070, MSVC: cargo test -p victory-formats -p victory-hle 110 passed, including metadata_reserves_room_only_for_render_targets.

  • Reporting extra size and alignment only for render-capable 2D/3D textures, after the data planes, can only make a title's pool larger. The host keeps rendering into the data planes and never reads that memory, so over-reserving is the safe direction, and not inventing plane types a title could copy from is the right call.
  • One gap in the "upper bound" claim: for multisampled colour targets the console also allocates FMASK, which isn't in the doc's HTILE/CMASK/DCC list. At 8× MSAA, FMASK is about 4 bytes per pixel against 32 bytes of sample data, which is 1/8, more than the 1/16 used for colour. Using the depth divisor (8) when samples > 1, or adding FMASK explicitly, would keep the bound true for MSAA targets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039855864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/263#pullrequestreview-6039855864). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T13:16:37Z. **Review:** APPROVED --- Tested e5eaf4a on Windows 11, RTX 5070, MSVC: `cargo test -p victory-formats -p victory-hle` 110 passed, including `metadata_reserves_room_only_for_render_targets`. - Reporting extra size and alignment only for render-capable 2D/3D textures, after the data planes, can only make a title's pool larger. The host keeps rendering into the data planes and never reads that memory, so over-reserving is the safe direction, and not inventing plane types a title could copy from is the right call. - One gap in the "upper bound" claim: for multisampled colour targets the console also allocates FMASK, which isn't in the doc's HTILE/CMASK/DCC list. At 8× MSAA, FMASK is about 4 bytes per pixel against 32 bytes of sample data, which is 1/8, more than the 1/16 used for colour. Using the depth divisor (8) when `samples > 1`, or adding FMASK explicitly, would keep the bound true for MSAA targets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 00:05:21 +00:00
Marvisak commented 2026-11-25 00:06:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:01:05Z.


Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148045052 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/263#issuecomment-7148045052). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:01:05Z. --- Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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
Marvisak/VIctory!263
No description provided.