Skip to content

d3d12: preserve GPU writes to adjacent buffers in either address order - #2352

Open
ecox982745 wants to merge 2 commits into
ProjectLeonida:mainfrom
ecox982745:fix-adjacent-writeback-ranges
Open

ecox982745 wants to merge 2 commits into
ProjectLeonida:mainfrom
ecox982745:fix-adjacent-writeback-ranges

Conversation

@ecox982745

@ecox982745 ecox982745 commented Nov 26, 2026 •

Copy link
Copy Markdown

Claimed as RT-TITLE-WRITEBACK-ADJACENT-RANGES. This is the follow-up requested after #2129 landed.

Depends on: #2129 (merged into main through #2350).

What changed

When a submission wrote two adjacent placed buffers in descending address order, the queued interval kept the higher starting address. The lower buffer’s GPU results never reached the CPU pages. The tracker now merges touching and overlapping intervals under their lowest address and charges only newly covered bytes against the per-submission cap.

The GPU regression writes two adjacent 64 KiB buffers in one command list. It checks both address orders with different expected values, then checks every word in both buffers, including all 32,640 words outside the written portions.

Verification

  • Before the fix. On main at fbf100b1b, the new RTX 4090 test failed on the first word of the lower buffer when the upper address was submitted first. Expected 0xa00000c7, read 0x00001770.
  • After the fix. Both address orders passed. The placed-buffer and window write-back tests each passed three times with Vulkan validation enabled and three times with it disabled on the integrated tree. All six related CTests passed with validation enabled on both the submitted commit and its integration with main.
  • CPU range accounting. A separate harness compared the production insertion code against a byte-set model over all 46,656 ordered triples of intervals in an eight-byte address space, with caps of five bytes and two ranges. The parent disagreed on 37,831 sequences. The fix matched at every insertion, including refused insertions.
  • The integrated tree passed the CPU translator suite (500 files, 6,365 tests, zero failed files). The changed-file game-data check and git diff --check passed.

GPUs tested: NVIDIA GeForce RTX 4090, driver 616.64, Windows 11. All test inputs were synthetic.

AI-assisted: Yes, OpenAI Codex (GPT-6).

Integration

The runtime fix is f3c29e4e7. The test-only follow-up b27c441f98 uses the same two-address submission helper as main. The fixture points its descriptor table at four untouched words in the first buffer so that changing submission order changes the expected output. The production diff is the same range-accounting change. Two-file diff against the tested main

GitHub's test merge 7a8508296d combined main ef8fbf09f3 and this PR at b27c441f98, producing the exact tree tested locally (e97148a439).

  • On plain main with the same fixture, submitting the higher address first left word 0 of the lower buffer at 0x00001770 instead of 0xa000d830. Running the lower-address-first case first passed all 32,768 words, then the higher-address-first case left word 0 at the prior result (0xa0001830).
  • On the test merge, both address orders matched all 32,768 words. Both d3d12_placed_write_back and d3d12_title_window_write_back passed three consecutive runs on the RTX 4090 with Khronos validation enabled, with no validation messages. Both CTests also passed on the PR head.

Merge all touching intervals under their lowest address. Charge only the
newly covered bytes before changing the per-submission map. Check both
GPU dispatch orders and the untouched words in two adjacent buffers.

AI-assisted by OpenAI Codex (GPT-6).

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built this head with MSVC and ran d3d12_title_va and d3d12_title_va_shadow on Windows 11. Both passed, including adjacent buffer GPU writes in both address orders. GPU: NVIDIA GeForce RTX 5070, driver 610.88. No findings from these checks.

AI-assisted.

@ecox982745

Copy link
Copy Markdown
Author

Thanks for the RTX 5070 run. The two named CTests exercise the general title-address and shadow paths. The adjacent-buffer checks run in a separate CTest, d3d12_placed_write_back, which invokes the same executable with --placed-writeback. For a 5070 result on both address orders, the command from a configured build directory is:

ctest -V -R "^d3d12_placed_write_back$"

I reran that target on an RTX 4090 after #2356 changed the runtime defaults. With the PR fixture on unpatched main at 246791612, the higher-address-first case still failed on word 0 of the lower buffer (read 0x00001770, expected 0xa00000c7). With #2352 head f3c29e4e7 merged locally onto that same main (tree 6e0f2654f), both orders passed and all six related CTests passed with Vulkan validation enabled. Windows 11, NVIDIA 616.64, synthetic buffers.

AI-assisted verification by OpenAI Codex (GPT-6).

@ecox982745

Copy link
Copy Markdown
Author

I tested #2352 together with #2404 on a physical RTX 4090 under Windows 11, with Vulkan validation enabled. Both changes applied cleanly to 55e2bd9e9e. The build used #2352 at f3c29e4e73 and #2404 at 46aeaaefab (combined tree 380ce092ad).

Runtime under test Result with the same adjacent-buffer regression
Base + #2404 Upper-address-first failed at word 0. Read 00001770, expected a00000c7.
Base + #2404 + #2352 Both address orders passed. Each order checked all 32,768 words across the two adjacent buffers, including the untouched words.

All eight related CTests passed on the combined build, covering title addresses, shadow buffers, geometry views, title-window limits, and write-back. The test log contained no Vulkan validation errors. These were synthetic GPU tests. A story-mode run is still needed to establish the gameplay impact.

@akimfomin

Copy link
Copy Markdown
Contributor

#2352 still applies cleanly after #2404 entered main. I verified 46aeaaef is an ancestor of d1dff7949be62b6609c3c2ca937df7f50fbf1305, and merged only #2352 at f3c29e4e7380a3851d1c54ce671e84e0eecb26da into that receiver. It produced tree 406a2eddf41bc16c01a40c83ed196ddd64dae47a without conflicts. This updates the receiving baseline from the previous paired RTX 4090 run.

On that tree the exact entry point is ctest -R '^d3d12_placed_write_back$' -V to assert both adjacent-buffer orders. No extra #2404 cherry-pick is needed. My separate Windows configuration stopped at the root-signature 1.2 SDK requirement, so I have a Git result only for this new baseline. PortBridge · AI-assisted comparison.

@ecox982745

Copy link
Copy Markdown
Author

I ran the requested CTest on the exact integration tree 406a2eddf41bc16c01a40c83ed196ddd64dae47a, which includes #2404 and #1867. On a physical RTX 4090 (Windows 11, NVIDIA 616.64, Vulkan validation enabled), d3d12_placed_write_back passed in both address orders. On plain d1dff7949b with the identical test source, upper-address-first still failed at word 0: read 00001770, expected a00000c7.

I also extended the fixture locally to three adjacent 64 KiB buffers on one allocation. Each order ran in a fresh process. Here 0, 1, and 2 are the low, middle, and high buffers. A passing run matched all 49,152 words, including those outside the three write regions.

Runtime Passing submission orders Failing submission orders
d1dff7949b 012, 021, 201 102, 120, 210
Same main + #2352 at f3c29e4e73 All six None

For 210, the first mismatch on main was word 16,384, the first word of the middle buffer. The three-buffer runs logged no Vulkan validation errors.

All eight title-address and write-back CTests passed on the integration, along with the three existing-heap variants. Those three variants logged VUID-vkDestroyDevice-device-05137 at teardown despite passing. The same message appeared when I ran d3d12_existing_heap on plain main. These were synthetic GPU readbacks. AI-assisted verification.

…sion helper

Use the existing shader table to select a distinct four-word input for each address order. Keep the full-allocation readback and reuse the helper from upstream instead of changing its call convention.

AI-assisted-by: OpenAI Codex (GPT-6)
@ecox982745
ecox982745 marked this pull request as ready for review November 28, 2026 04:40
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head b27c441f9 and re-tested on Windows 11 + NVIDIA GeForce RTX 5070 12 GB (MSVC 19.44, Ninja Release).

  • note_title_write_back() cleanly merges all overlapping/adjacent ranges [first, last) in either address order, charges only newly covered bytes (added_bytes = (merged_end - begin) - replaced_bytes) with an overflow-safe cap check (added_bytes > kTitleWriteBackBytes - title_write_back_bytes), and replaces the merged span via insert_or_assign + erase.
  • Built d3d12_title_va_test and ran ctest --output-on-failure -V:
    • d3d12_title_va: passed
    • d3d12_title_va_shadow: passed
    • d3d12_title_window_write_back: passed
    • d3d12_placed_write_back: passed (0.19 s; both upper-first and lower-first adjacent buffer writes merged into one 128 KiB range and matched expected words).

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
AI-assisted (Antigravity, Gemini).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Physical RADV gfx906 (fixed subgroup 64), Wine, synchronization validation enabled. I ran the same d3d12_placed_write_back fixture against main 4a54aedcb and this head b27c441f9 merged with it. Main failed when the higher-address buffer was submitted first: all 64 output words in the lower buffer were wrong. The merge returned all 64 correctly. The upper buffer and all guard words matched on both builds; reversing the submission order also passed on both. Both fences completed in each ordering.

The registered placed-write-back, window-write-back and shadow-keep/refill CTests went from 2/3 to 3/3; no validation errors, synchronization hazards or device loss in either build.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants