GPU/COM: return hidden sret out pointer in RAX from Heap/Resource/DescriptorHeap/Queue GetDesc #3056

Closed
RVZO6 wants to merge 1 commit from upstream-pr/3058 into main
RVZO6 commented 2026-11-26 05:43:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T05:43:06Z.


Problem

Under the Microsoft x64 calling convention (Return values), COM methods returning structs larger than 8 bytes by value write into the caller-supplied hidden sret pointer (out) and must return that same out pointer in RAX.

Four D3D12 COM GetDesc methods in victory-gpu currently return () instead of *mut ...:

  • ID3D12Heap::GetDesc (resource.rs::heap_desc, 48 B)
  • ID3D12Resource::GetDesc (resource.rs::resource_desc, 56 B)
  • ID3D12DescriptorHeap::GetDesc (descriptor.rs::desc, 16 B)
  • ID3D12CommandQueue::GetDesc (queue.rs::desc, 16 B)

Compare with allocation_info, allocation_info2, custom_heap_properties (resource.rs), and xsystem::analytics_info, which already return out. In --release builds, LLVM leaves a clobbered register (e.g. the vtable pointer) in RAX instead of out, so MSVC C++ callers chaining res->GetDesc().Width / heap->GetDesc().SizeInBytes via RAX read garbage or fault.

Fix

Change all four GetDesc implementations to return *mut HeapDesc / *mut ResourceDesc / *mut QueueDesc and return out. Disjoint from #933, #2193, and #2690 (which adjust ResourceDesc field values while keeping ()).

Verification

  • Extended resource::tests::heaps_are_zeroed_aligned_memory, descriptor::tests::heaps_hold_count_descriptors_from_their_start, and queue::tests::queue_signals_complete_at_once to call all four vtable slots as extern "system" fn(This, *mut T) -> *mut T and assert the returned pointer equals out.
  • Negative control in --release before fix: all 3 tests failed with vtable pointers (0x1405...) in RAX instead of the stack out pointer (0x7fffff...); all 3 pass in --release and debug after fix.
  • Verified green on windows-latest MSVC + WARP SM 6.6 CI (cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

<!-- greyfinch-sync:Marvisak/VIctory:issue:6620362327 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3058). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T05:43:06Z. --- ### Problem Under the Microsoft x64 calling convention (*Return values*), COM methods returning structs larger than 8 bytes by value write into the caller-supplied hidden `sret` pointer (`out`) **and must return that same `out` pointer in `RAX`**. Four D3D12 COM `GetDesc` methods in `victory-gpu` currently return `()` instead of `*mut ...`: - `ID3D12Heap::GetDesc` (`resource.rs::heap_desc`, 48 B) - `ID3D12Resource::GetDesc` (`resource.rs::resource_desc`, 56 B) - `ID3D12DescriptorHeap::GetDesc` (`descriptor.rs::desc`, 16 B) - `ID3D12CommandQueue::GetDesc` (`queue.rs::desc`, 16 B) Compare with `allocation_info`, `allocation_info2`, `custom_heap_properties` (`resource.rs`), and `xsystem::analytics_info`, which already return `out`. In `--release` builds, LLVM leaves a clobbered register (e.g. the vtable pointer) in `RAX` instead of `out`, so MSVC C++ callers chaining `res->GetDesc().Width` / `heap->GetDesc().SizeInBytes` via `RAX` read garbage or fault. ### Fix Change all four `GetDesc` implementations to return `*mut HeapDesc` / `*mut ResourceDesc` / `*mut QueueDesc` and return `out`. Disjoint from #933, #2193, and #2690 (which adjust `ResourceDesc` field values while keeping `()`). ### Verification - Extended `resource::tests::heaps_are_zeroed_aligned_memory`, `descriptor::tests::heaps_hold_count_descriptors_from_their_start`, and `queue::tests::queue_signals_complete_at_once` to call all four vtable slots as `extern "system" fn(This, *mut T) -> *mut T` and assert the returned pointer equals `out`. - Negative control in `--release` before fix: all 3 tests failed with vtable pointers (`0x1405...`) in `RAX` instead of the stack `out` pointer (`0x7fffff...`); all 3 pass in `--release` and debug after fix. - Verified green on `windows-latest` MSVC + WARP SM 6.6 CI (`cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, `xtask policy`, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919 - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
upstream-sync closed this pull request 2026-11-26 06:03:34 +00:00
fuzeofficlal commented 2026-11-26 06:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:55:34Z.

Review: APPROVED


Reviewed head 51f4e879 line-by-line (CI green):

  • Under the MSVC x64 C++ ABI, COM methods returning structs > 8 bytes by value (GetDesc) must return the hidden sret destination pointer in RAX; callers frequently dereference RAX directly for chained field reads.
  • All four GetDesc implementations (descriptor::desc, queue::desc, resource::heap_desc, resource::resource_desc) now return out, matching custom_heap_properties, and each has a regression assertion checking the returned pointer equals the caller's out pointer.

Clean ABI fix.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069202368 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3058#pullrequestreview-6069202368). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T05:55:34Z. **Review:** APPROVED --- Reviewed head `51f4e879` line-by-line (CI green): - Under the MSVC x64 C++ ABI, COM methods returning structs > 8 bytes by value (`GetDesc`) must return the hidden `sret` destination pointer in `RAX`; callers frequently dereference `RAX` directly for chained field reads. - All four `GetDesc` implementations (`descriptor::desc`, `queue::desc`, `resource::heap_desc`, `resource::resource_desc`) now return `out`, matching `custom_heap_properties`, and each has a regression assertion checking the returned pointer equals the caller's out pointer. Clean ABI fix.
kotekompotek commented 2026-11-26 06:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T05:59:30Z.

Review: APPROVED


Verified: MSVC's x64 sret convention returns the hidden out pointer in RAX — a void signature left it undefined for any title code that chains or inspects it. All four desc methods (descriptor Heap, queue, resource Heap, Resource) now return out; the queue test correctly handles both vtable layouts (desc slot 0xe0/0xd0 by signal_slot) and each asserts ret == out plus populated contents.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069234467 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3058#pullrequestreview-6069234467). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T05:59:30Z. **Review:** APPROVED --- Verified: MSVC's x64 sret convention returns the hidden out pointer in RAX — a void signature left it undefined for any title code that chains or inspects it. All four desc methods (descriptor Heap, queue, resource Heap, Resource) now return `out`; the queue test correctly handles both vtable layouts (desc slot 0xe0/0xd0 by signal_slot) and each asserts ret == out plus populated contents.
RVZO6 commented 2026-11-26 06:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T05:58:01Z.


Closing: after checking closed PR #2058's second-look review, Xbox D3D12.X GetDesc vtable slots take an explicit out-pointer returning void (the C++ inline wrapper returns its local copy), so no caller reads RAX. Apologies for the noise!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183967295 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3058#issuecomment-7183967295). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T05:58:01Z. --- Closing: after checking closed PR #2058's second-look review, Xbox D3D12.X `GetDesc` vtable slots take an explicit out-pointer returning `void` (the C++ inline wrapper returns its local copy), so no caller reads `RAX`. Apologies for the noise!

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!3056
No description provided.