formats: test what every DXGI number stores #123

Open
xiaotu030202 wants to merge 1 commit from upstream-pr/123 into main
xiaotu030202 commented 2026-11-25 14:10:58 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by xiaotu030202 on 2026-11-25T13:08:41Z.


What format decides, and why it was worth a test

For every texture, format picks how many bytes an element is, how many texels a block side holds, and whether there is a stencil plane. 93 of the 121 numbers the Windows SDK defines are grouped by size in one match:

19..=22 | 44..=47 => (4, 1, true),
23..=43 | 67 | 87..=93 | 116 | 117 => (4, 1, false),

There was no test for any of it. One bound moved by one — 19..=22 narrowed to 19..=21 — changes which formats are given a stencil plane, and a depth format read as having no stencil is a texture allocated half the size it needs. Nothing would have noticed.

Three tests, named against the SDK

The format names come from dxgiformat.h (Windows SDK 10.0.22621.0), so a wrong row is wrong about a number Microsoft names.

every_format_group_stores_what_the_sdk_says_it_does — 33 rows covering every group's bounds:

group example bytes block stencil
1..=4 R32G32B32A32_SINT 16 1 no
9..=18 R32G32_SINT 8 1 no
19..=22 D32_FLOAT_S8X24_UINT 4 1 yes
23..=43 R8G8B8A8_UNORM 4 1 no
44..=47 R24G8_TYPELESS 4 1 yes
48..=59 R8G8_TYPELESS 2 1 no
60..=65 R8_TYPELESS 1 1 no
67 R9G9B9E5_SHAREDEXP 4 1 no
70..=72, 79..=81 BC1_UNORM_SRGB 8 4 no
73..=78, 82..=84 BC7_UNORM_SRGB 16 4 no
85, 86, 115 B5G6R5_UNORM 2 1 no
87..=93 B8G8R8A8_UNORM 4 1 no
94..=99 BC6H_TYPELESS 16 4 no

the_formats_it_declines_are_the_ones_it_names — the numbers refused on purpose, so a change that starts answering one has to say why: 96-bit (5..=8, which the comment already excluded), FORCE_UINT (0), R1 and the two 4:2:2 YUV formats (66, 68, 69), the 15 video formats (100..=114), the SDK's newer video and sampler-feedback numbers (130..=132, 189..=190), and anything undefined.

the_console_only_numbers_are_the_sizes_this_code_assumes — 116..=120, which the Windows SDK does not name at all. They are answered here, so they are console numbers the GDK adds; the test records the sizes this code was written against rather than asserting them against a name, so whoever finds the real ones can correct the row.

Checked by mutation, not just by passing

A test that passes on the code as written proves little, so I moved the code under it and re-ran:

19..=22 -> 19..=21          FAILED   "22 (D32_FLOAT_S8X24_UINT) stencil"
70..=72 block 4 -> 1        FAILED   "70 (BC1_TYPELESS) texels a block side"

Both caught, with the row named in the message. Then restored.

Verification

Windows 11, Rust 1.98.1 (pinned), MSVC 14.44.35207. No game files, no GPU — this crate is pure byte arithmetic.

$ cargo test -p victory-formats
test result: ok. 27 passed; 0 failed; 4 ignored     (was 24 passed)

$ cargo clippy -p victory-formats --all-targets
clean

$ cargo xtask policy
asset policy: 172 files ok

The 4 ignored need reference data outside the repository (BCPack tables and chunks, XMA streams, a reference decoder). Nothing here changes them.

What this does not say

I did not find a wrong row. I went looking: 5..=8 looked like an oversight until dxgiformat.h showed they are the 96-bit formats the comment already excludes; 19..=22 looked shifted until the header showed the four depth-with-stencil numbers really are 19..=22. The mapping is right — it was just unheld.

I also looked at the two neighbouring shortcut: notes in this file (XOR tile modes _X/_T and MSAA addressing; render-target metadata planes) and left both alone: they say "add them when a title copies into or out of one", and there is no evidence one has, so a patch there would be speculation.

victory-formats has almost no contributions in flight — two of 34 open PRs touch it and both are elsewhere — which is why the unheld table seemed worth picking up.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6605208980 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/123). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T13:08:41Z. --- ## What `format` decides, and why it was worth a test For every texture, `format` picks how many bytes an element is, how many texels a block side holds, and **whether there is a stencil plane**. 93 of the 121 numbers the Windows SDK defines are grouped by size in one `match`: ```rust 19..=22 | 44..=47 => (4, 1, true), 23..=43 | 67 | 87..=93 | 116 | 117 => (4, 1, false), ``` There was no test for any of it. One bound moved by one — `19..=22` narrowed to `19..=21` — changes which formats are given a stencil plane, and a depth format read as having no stencil is a texture allocated **half the size it needs**. Nothing would have noticed. ## Three tests, named against the SDK The format names come from `dxgiformat.h` (Windows SDK 10.0.22621.0), so a wrong row is wrong about a number Microsoft names. **`every_format_group_stores_what_the_sdk_says_it_does`** — 33 rows covering every group's bounds: | group | example | bytes | block | stencil | |---|---|---|---|---| | 1..=4 | `R32G32B32A32_SINT` | 16 | 1 | no | | 9..=18 | `R32G32_SINT` | 8 | 1 | no | | **19..=22** | `D32_FLOAT_S8X24_UINT` | 4 | 1 | **yes** | | 23..=43 | `R8G8B8A8_UNORM` | 4 | 1 | no | | **44..=47** | `R24G8_TYPELESS` | 4 | 1 | **yes** | | 48..=59 | `R8G8_TYPELESS` | 2 | 1 | no | | 60..=65 | `R8_TYPELESS` | 1 | 1 | no | | 67 | `R9G9B9E5_SHAREDEXP` | 4 | 1 | no | | 70..=72, 79..=81 | `BC1_UNORM_SRGB` | 8 | **4** | no | | 73..=78, 82..=84 | `BC7_UNORM_SRGB` | 16 | **4** | no | | 85, 86, 115 | `B5G6R5_UNORM` | 2 | 1 | no | | 87..=93 | `B8G8R8A8_UNORM` | 4 | 1 | no | | 94..=99 | `BC6H_TYPELESS` | 16 | **4** | no | **`the_formats_it_declines_are_the_ones_it_names`** — the numbers refused on purpose, so a change that starts answering one has to say why: 96-bit (5..=8, which the comment already excluded), `FORCE_UINT` (0), `R1` and the two 4:2:2 YUV formats (66, 68, 69), the 15 video formats (100..=114), the SDK's newer video and sampler-feedback numbers (130..=132, 189..=190), and anything undefined. **`the_console_only_numbers_are_the_sizes_this_code_assumes`** — 116..=120, which **the Windows SDK does not name at all**. They are answered here, so they are console numbers the GDK adds; the test records the sizes this code was written against rather than asserting them against a name, so whoever finds the real ones can correct the row. ## Checked by mutation, not just by passing A test that passes on the code as written proves little, so I moved the code under it and re-ran: ``` 19..=22 -> 19..=21 FAILED "22 (D32_FLOAT_S8X24_UINT) stencil" 70..=72 block 4 -> 1 FAILED "70 (BC1_TYPELESS) texels a block side" ``` Both caught, with the row named in the message. Then restored. ## Verification Windows 11, Rust 1.98.1 (pinned), MSVC 14.44.35207. **No game files, no GPU** — this crate is pure byte arithmetic. ``` $ cargo test -p victory-formats test result: ok. 27 passed; 0 failed; 4 ignored (was 24 passed) $ cargo clippy -p victory-formats --all-targets clean $ cargo xtask policy asset policy: 172 files ok ``` The 4 ignored need reference data outside the repository (BCPack tables and chunks, XMA streams, a reference decoder). Nothing here changes them. ## What this does not say **I did not find a wrong row.** I went looking: 5..=8 looked like an oversight until `dxgiformat.h` showed they are the 96-bit formats the comment already excludes; 19..=22 looked shifted until the header showed the four depth-with-stencil numbers really are 19..=22. **The mapping is right — it was just unheld.** I also looked at the two neighbouring `shortcut:` notes in this file (XOR tile modes `_X`/`_T` and MSAA addressing; render-target metadata planes) and left both alone: they say "add them when a title copies into or out of one", and there is no evidence one has, so a patch there would be speculation. `victory-formats` has almost no contributions in flight — two of 34 open PRs touch it and both are elsewhere — which is why the unheld table seemed worth picking up.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/123:upstream-pr/123'
git switch 'upstream-pr/123'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/123'
git switch 'upstream-pr/123'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/123'
git switch 'upstream-pr/123'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/123'
git switch 'main'
git merge --squash 'upstream-pr/123'
git switch 'main'
git merge --ff-only 'upstream-pr/123'
git switch 'main'
git merge 'upstream-pr/123'
git push origin 'main'
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
Zettrox/ztrx!123
No description provided.