Texture blocks: place the title's textures with tight alignment (from #306, alone on main) #459

Manually merged
github merged 2 commits from github-bot/gh-459 into main 2026-12-04 17:31:57 +00:00 AGit
Owner

@⁠LOCKhart07 on GitHub · 2026-12-04 12:32 UTC · original
LOCKhart07:tight-textures-on-main → main · +451 −7 · 1 files · 2 commits · merged 2026-12-04 17:30 UTC

One commit from #306 (9bba82d), taken out of the hardware ray-tracing stack and put on main by itself. It touches pool.rs only, nothing of hardware ray tracing, and adds no switch.

What changes

Every texture cut from a texture block was asked at 64 KiB, so each took a multiple of 64 KiB, and most of the title's textures are small.

Now a texture is asked with D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT where the host says it has it (D3D12_FEATURE_D3D12_TIGHT_ALIGNMENT, tier 1 or more), and its piece is the size at the alignment the host answers. A host without the tier is asked as before.

This is not the earlier 4 KiB placement (VICTORY_POOL_SMALL, removed after two device losses on 2026-11-25): that one asked at 4 KiB and, refused, asked again at 0; the flag is never refused. What those losses were was not proven.

Checked on main 0fd7614

  • The commit applies with no conflict.
  • cargo clippy --release -p victory-gpu --all-targets for x86_64-pc-windows-msvc: 40 warnings, as on main; the one in pool.rs is on main too.
  • pool:: and card_pool:: tests under Wine 9.0: 10 passed, 0 failed. The machine has no card, so the two tests that place real textures (a_placed_texture_holds_its_heap, small_textures_placed_back_to_back_keep_their_own_bytes) had no device to place them on: their pass here says nothing.

Measured, and what is not

The numbers in the commit message are from the stack, on an RX 9070 XT (RADV), 2560x1440, six minutes, against the run before it (not a pair): rounding 1,161 MB to 108 MB, texture blocks 64 to 56, slots held back for want of room on the card 152 to 0. There the new test compared 500 reads and none differed.

Not measured: a play of this branch alone on main, the new test on a card on this branch, and any card but the RX 9070 XT.


Generated by Claude Code

**@⁠LOCKhart07** on GitHub · 2026-12-04 12:32 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/459) `LOCKhart07:tight-textures-on-main` → `main` · +451 −7 · 1 files · 2 commits · merged 2026-12-04 17:30 UTC One commit from #306 (`9bba82d`), taken out of the hardware ray-tracing stack and put on main by itself. It touches `pool.rs` only, nothing of hardware ray tracing, and adds no switch. ## What changes Every texture cut from a texture block was asked at 64 KiB, so each took a multiple of 64 KiB, and most of the title's textures are small. Now a texture is asked with `D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT` where the host says it has it (`D3D12_FEATURE_D3D12_TIGHT_ALIGNMENT`, tier 1 or more), and its piece is the size at the alignment the host answers. A host without the tier is asked as before. This is not the earlier 4 KiB placement (`VICTORY_POOL_SMALL`, removed after two device losses on 2026-11-25): that one asked at 4 KiB and, refused, asked again at 0; the flag is never refused. What those losses were was not proven. ## Checked on main `0fd7614` - The commit applies with no conflict. - `cargo clippy --release -p victory-gpu --all-targets` for `x86_64-pc-windows-msvc`: 40 warnings, as on main; the one in `pool.rs` is on main too. - `pool::` and `card_pool::` tests under Wine 9.0: 10 passed, 0 failed. The machine has no card, so the two tests that place real textures (`a_placed_texture_holds_its_heap`, `small_textures_placed_back_to_back_keep_their_own_bytes`) had no device to place them on: their pass here says nothing. ## Measured, and what is not The numbers in the commit message are from the stack, on an RX 9070 XT (RADV), 2560x1440, six minutes, against the run before it (not a pair): rounding 1,161 MB to 108 MB, texture blocks 64 to 56, slots held back for want of room on the card 152 to 0. There the new test compared 500 reads and none differed. Not measured: a play of this branch alone on main, the new test on a card on this branch, and any card but the RX 9070 XT. --- _Generated by [Claude Code](https://claude.ai/code)_
Every texture cut from a texture block was asked at 64 KiB, so each took a multiple of 64 KiB. Most of the title's textures are small: their copy footprints came to 1,599 MB in 2,760 MB of pieces, 1,161 MB of rounding.

Now a texture is asked with D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT where the host says it has it (D3D12_FEATURE_D3D12_TIGHT_ALIGNMENT, tier 1 or more), and its piece is the size at the alignment the host answers: 4 KiB multiples for a small one (256 bytes for the smallest), 64 KiB as before for a large one. The host is asked once and the texture is made with the description the size was asked for. A host without the tier is asked as before.

The earlier 4 KiB placement (VICTORY_POOL_SMALL, removed after two device losses on 2026-11-25) asked at 4 KiB and, refused, asked again at 0; the flag is never refused. What those losses were was not proven. The new test places 11 kinds of small texture three times over back to back from 0x6000 into a heap (the kind and place of those losses first), in each of the three ways of asking, writes every level with bytes of its own, reads them back by a copy and then by a shader through a view of the whole chain and one of each level, and compares with the same texture on a 64 KiB multiple: 500 reads compared, none differ, on an RX 9070 XT (RADV), where the driver lays such textures out at 4 KiB (so nothing is padded).

Measured there, 2560x1440, six minutes with the camera turning, against the run before it (not a pair: the scene streams): rounding 1,161 MB -> 108 MB (2,014 MB of footprints in 2,123 MB of pieces); texture blocks 64 -> 56; slots held back for want of room on the card 152 -> 0; host copies let go for room 6,495 MB -> 3,359 MB; card in use 13,326 -> 13,020 MB with 415 MB more of texture loaded. No error line, no device loss, the picture looked right.

Tests: pool 14 passed (the new one among them), resource 16, texture 11.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 12:33:33 +00:00
A block is a heap aligned to 64 KiB, so a piece's place in it is aligned to no more than that, and a multisampled texture wants 4 MiB (asked in review of #306). None reaches the blocks: the one caller of texture_with_growth sends only single-sampled textures, and the blocks' heaps take no render targets or depth. A debug_assert on the alignment the host answers says so if that ever changes; a release build is as before.

Tests, under Wine: pool 10 passed, in the release profile the tests run in, where the assert is not compiled: it is not exercised by them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 14:10 UTC · original

Checked 51704b2 on native Windows with one NVIDIA desktop card and WARP.

On this setup the change is inert. Both devices answer CheckFeatureSupport(D3D12_FEATURE(54)) with S_OK and tier 0, so tight() (pool.rs:958-970) is false, the flag is never added (pool.rs:988), and every texture is asked at alignment 0 and lands on a 64 KiB multiple exactly like main. The block it replaces asked at 0 twice on main (main pool.rs:963-969), so nothing is lost there. That also means the tight path itself never ran here. What I say about it below comes from reading the code, and the only run of it so far is the RX 9070 XT one in the description.

The runtime does know both values. Feature 54 is accepted with a 4 byte struct and refused with 8, while 55 and 200 are refused. Flag 0x400 is taken with no debug message, while 0x200 and 0x800 are rejected as the video LUT flags and 0x1000 as unrecognized bits. The installed SDK header is too old to show either name, so this is the best check I had.

From the code

  • Only textures the title fills get here. fills() drops render target, depth and UAV (resource.rs:1596-1598), and the caller also wants sample_count <= 1 and no clear value (resource.rs:3062-3063). Block heaps are ALLOW_ONLY_NON_RT_DS_TEXTURES (pool.rs:1011).
  • The piece is sized by info.SizeInBytes and aligned to info.Alignment.max(1) (pool.rs:997-998), and Ranges::take rounds each start up to that alignment for that request (pool.rs:148-173). Neighbours with different alignments can't overlap, and I found no fixed 64 KiB outside the tests in pool.rs.
  • The texture is made with the same description the size was asked for, flag included (pool.rs:991, 1040). The allocation info cache key includes Flags (pool.rs:938).
  • Reserved textures the title fills can still take the block path (resource.rs:3058-3075 doesn't check reserved). Main does the same, so that's not new.
  • The tier is held in a process-wide OnceLock rather than per device (pool.rs:959). Harmless with one host device.

Local probe (not pushed)

I made a device on each adapter with the debug layer on, asked GetResourceAllocationInfo at 0, 4 KiB, 64 KiB and with 0x400, and then placed 13 eligible textures back to back in one heap using the PR's rule and again with the flag forced on.

texture align 0 4 KiB, NVIDIA / WARP 0x400
BC1 256x256, 9 mips 64K 48K / 44K 64K @ 64K
BC1 64x64, 7 mips 64K 8K / 4K 64K @ 64K
RGBA8 1x1 64K 4K 64K @ 64K
RGBA8 256x256, 9 mips 384K refused, warning 1380 384K @ 64K
RGBA8 64x64 render target 64K refused, error 721 64K @ 64K

Both placements gave 13 of 13 placed with no debug messages and no device removal on either adapter. Three deliberately bad calls (a non-small texture at 4 KiB, a 64 KiB texture at offset 0x100, and a render target in the non-RT/DS heap) each returned E_INVALIDARG with a message, so the layer was listening. One side note is that a 64x64 UAV texture gets 16K at 4K on both adapters, so the reason UAV is kept out is fills() and not the alignment rule. I didn't probe depth.

Tests

  • small_textures_placed_back_to_back_keep_their_own_bytes passes on both adapters, with 500 reads compared and none differing. In the "tight flag" mode every kind came back 64 KiB at 64 KiB, so on Windows it repeats the alignment 0 mode. The WARP run had VICTORY_D3D12_DEBUG=1 set, but the test doesn't read the message queue, so treat it as a pass and nothing more.
  • On NVIDIA, the pool:: filter (which also picks up card_pool) gave 10/10 against 9 on main, texture 11/11 with 3 ignored, and resource 15/16. The failure is buffer_data_reaches_the_host_texture at resource.rs:4483 under 2 threads. It passes alone and fails the same way on main 0fd7614.
  • On WARP, pool:: gave 10/10, resource 16/16 and texture 11/11.

One idea for tier 0 hosts. Main's comment meant to ask small textures at 4 KiB, but it set the alignment to 0 before the first ask, so it never did. On both adapters here the plain small-resource rule does work (the 4 KiB column above, e.g. BC1 64x64 at 8K instead of 64K), and the runtime refuses the textures that don't qualify. So a fallback that asks at 4 KiB when the tier is 0 and takes the 64 KiB answer when that's refused would give Windows hosts most of the saving too. That's a separate change though, not something this PR breaks.

From the Windows side there is no regression, because hosts that report tier 0 behave as main does. Whether tight placement is right on a host that reports tier 1 still rests on the RADV run.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 14:10 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/459#issuecomment-7413943759) Checked 51704b2 on native Windows with one NVIDIA desktop card and WARP. On this setup the change is inert. Both devices answer `CheckFeatureSupport(D3D12_FEATURE(54))` with S_OK and tier 0, so `tight()` (pool.rs:958-970) is false, the flag is never added (pool.rs:988), and every texture is asked at alignment 0 and lands on a 64 KiB multiple exactly like main. The block it replaces asked at 0 twice on main (main pool.rs:963-969), so nothing is lost there. That also means the tight path itself never ran here. What I say about it below comes from reading the code, and the only run of it so far is the RX 9070 XT one in the description. The runtime does know both values. Feature 54 is accepted with a 4 byte struct and refused with 8, while 55 and 200 are refused. Flag 0x400 is taken with no debug message, while 0x200 and 0x800 are rejected as the video LUT flags and 0x1000 as unrecognized bits. The installed SDK header is too old to show either name, so this is the best check I had. From the code - Only textures the title fills get here. `fills()` drops render target, depth and UAV (resource.rs:1596-1598), and the caller also wants `sample_count <= 1` and no clear value (resource.rs:3062-3063). Block heaps are `ALLOW_ONLY_NON_RT_DS_TEXTURES` (pool.rs:1011). - The piece is sized by `info.SizeInBytes` and aligned to `info.Alignment.max(1)` (pool.rs:997-998), and `Ranges::take` rounds each start up to that alignment for that request (pool.rs:148-173). Neighbours with different alignments can't overlap, and I found no fixed 64 KiB outside the tests in pool.rs. - The texture is made with the same description the size was asked for, flag included (pool.rs:991, 1040). The allocation info cache key includes `Flags` (pool.rs:938). - Reserved textures the title fills can still take the block path (resource.rs:3058-3075 doesn't check `reserved`). Main does the same, so that's not new. - The tier is held in a process-wide `OnceLock` rather than per device (pool.rs:959). Harmless with one host device. Local probe (not pushed) I made a device on each adapter with the debug layer on, asked `GetResourceAllocationInfo` at 0, 4 KiB, 64 KiB and with 0x400, and then placed 13 eligible textures back to back in one heap using the PR's rule and again with the flag forced on. | texture | align 0 | 4 KiB, NVIDIA / WARP | 0x400 | |---|---|---|---| | BC1 256x256, 9 mips | 64K | 48K / 44K | 64K @ 64K | | BC1 64x64, 7 mips | 64K | 8K / 4K | 64K @ 64K | | RGBA8 1x1 | 64K | 4K | 64K @ 64K | | RGBA8 256x256, 9 mips | 384K | refused, warning 1380 | 384K @ 64K | | RGBA8 64x64 render target | 64K | refused, error 721 | 64K @ 64K | Both placements gave 13 of 13 placed with no debug messages and no device removal on either adapter. Three deliberately bad calls (a non-small texture at 4 KiB, a 64 KiB texture at offset 0x100, and a render target in the non-RT/DS heap) each returned E_INVALIDARG with a message, so the layer was listening. One side note is that a 64x64 UAV texture gets 16K at 4K on both adapters, so the reason UAV is kept out is `fills()` and not the alignment rule. I didn't probe depth. Tests - `small_textures_placed_back_to_back_keep_their_own_bytes` passes on both adapters, with 500 reads compared and none differing. In the "tight flag" mode every kind came back 64 KiB at 64 KiB, so on Windows it repeats the alignment 0 mode. The WARP run had `VICTORY_D3D12_DEBUG=1` set, but the test doesn't read the message queue, so treat it as a pass and nothing more. - On NVIDIA, the `pool::` filter (which also picks up card_pool) gave 10/10 against 9 on main, texture 11/11 with 3 ignored, and resource 15/16. The failure is `buffer_data_reaches_the_host_texture` at resource.rs:4483 under 2 threads. It passes alone and fails the same way on main 0fd7614. - On WARP, `pool::` gave 10/10, resource 16/16 and texture 11/11. One idea for tier 0 hosts. Main's comment meant to ask small textures at 4 KiB, but it set the alignment to 0 before the first ask, so it never did. On both adapters here the plain small-resource rule does work (the 4 KiB column above, e.g. BC1 64x64 at 8K instead of 64K), and the runtime refuses the textures that don't qualify. So a fallback that asks at 4 KiB when the tier is 0 and takes the 64 KiB answer when that's refused would give Windows hosts most of the saving too. That's a separate change though, not something this PR breaks. From the Windows side there is no regression, because hosts that report tier 0 behave as main does. Whether tight placement is right on a host that reports tier 1 still rests on the RADV run. AI-assisted: yes
github manually merged commit b9ca410336 into main 2026-12-04 17:31:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.