Take texture upload memory from the list's scratch pool #30

Merged
romainhedouin merged 1 commit from upstream-pr/30 into main 2026-11-25 17:09:21 +00:00
romainhedouin commented 2026-11-25 12:32:39 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by romainhedouin on 2026-11-25T12:32:39Z.


Each title copy from a buffer into a texture created a brand new D3D12 upload buffer, mapped it, and destroyed it at list reset (the code marked this as a shortcut to pool later). Now the bytes go into the list's scratch memory: pooled 512 KiB chunks that stay mapped and are reused once the GPU is done with them, at a 512-byte offset as D3D12 requires for texture copies. Copies over 512 KiB still get their own buffer, as before.

Per buffer-to-texture copy (up to 512 KiB) Before After
CreateCommittedResource 1 0 (steady state)
Map 1 0
Buffer destroyed at list reset 1 0

Counts from the code, not timings. Type-checked for Windows (cargo clippy --target x86_64-pc-windows-msvc, with and without --all-features, no new warnings); not run.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6604552859 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/30). Originally posted by [romainhedouin](https://github.com/romainhedouin) on 2026-11-25T12:32:39Z. --- Each title copy from a buffer into a texture created a brand new D3D12 upload buffer, mapped it, and destroyed it at list reset (the code marked this as a shortcut to pool later). Now the bytes go into the list's scratch memory: pooled 512 KiB chunks that stay mapped and are reused once the GPU is done with them, at a 512-byte offset as D3D12 requires for texture copies. Copies over 512 KiB still get their own buffer, as before. | Per buffer-to-texture copy (up to 512 KiB) | Before | After | |---|---|---| | `CreateCommittedResource` | 1 | 0 (steady state) | | `Map` | 1 | 0 | | Buffer destroyed at list reset | 1 | 0 | Counts from the code, not timings. Type-checked for Windows (`cargo clippy --target x86_64-pc-windows-msvc`, with and without `--all-features`, no new warnings); not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gut0to commented 2026-11-25 15:13:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:13:08Z.

Review: COMMENTED


AI-assisted review: I traced the scratch allocation alignment contract and the current test coverage.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6060252887 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/30#pullrequestreview-6060252887). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T15:13:08Z. **Review:** COMMENTED --- AI-assisted review: I traced the scratch allocation alignment contract and the current test coverage.
gut0to commented 2026-11-25 15:13:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:13:08Z.

Code review location: crates/victory-gpu/src/host.rs; line 2423

@@ -2410,10 +2419,11 @@ impl HostList {
             s.chunks.push(chunk);
             s.used = 0;
         }
-        let (_, data, gpu) = s.chunks[s.current];
-        let at = s.used;
-        s.used += len;
-        Some((gpu + at, (data + at as usize) as *mut u8))
+        let (buffer, data, gpu) = &s.chunks[s.current];
+        let at = s.used.next_multiple_of(align);

Could we add a Windows regression test that first allocates a 256-byte scratch span, then requests an upload span with 512-byte alignment and checks that the returned GPU offset is 512-byte aligned? This is the contract that makes the new pooled upload safe for placed footprints, and the mixed-alignment rollover path is currently untested. AI-assisted review.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4696953139 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/30#discussion_r4696953139). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-25T15:13:08Z. **Code review location:** `crates/victory-gpu/src/host.rs`; line 2423 ~~~~diff @@ -2410,10 +2419,11 @@ impl HostList { s.chunks.push(chunk); s.used = 0; } - let (_, data, gpu) = s.chunks[s.current]; - let at = s.used; - s.used += len; - Some((gpu + at, (data + at as usize) as *mut u8)) + let (buffer, data, gpu) = &s.chunks[s.current]; + let at = s.used.next_multiple_of(align); ~~~~ --- Could we add a Windows regression test that first allocates a 256-byte scratch span, then requests an upload span with 512-byte alignment and checks that the returned GPU offset is 512-byte aligned? This is the contract that makes the new pooled upload safe for placed footprints, and the mixed-alignment rollover path is currently untested. AI-assisted review.
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
Belobug/VIctory-Belobug-AMD!30
No description provided.