[PR #954] [MERGED] test: indirect RT scratch size without nested std::max, miscompiled by MSVC 19.52 (TEST-INDIRECT-RT-ARENA) #991

Closed
opened 2026-11-26 20:19:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/954
Author: @TheGeogeo
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/indirect-rt-arena


📝 Commits (1)

  • f4fc762 test: compute the indirect RT scratch size without nested std::max (TEST-INDIRECT-RT-ARENA)

📊 Changes

1 file changed (+4 additions, -2 deletions)

View changed files

📝 runtime/test/d3d12_indirect_rt_test.cpp (+4 -2)

📄 Description

Claimed in the coordination issue as: TEST-INDIRECT-RT-ARENA

What and why

d3d12_indirect_rt and d3d12_indirect_rt_upload_sysmem stopped at GPU address arena full ... buffer size in KiB: 105903 and FAIL: CreateCommittedResource(compaction/clone buffers) on an RTX 3080.

The sizes are not the problem. Printed on that GPU, in bytes (hex, result/scratch): BLAS a00/200, TLAS 800/300, the compaction BLAS from the layer a00/200, and from vkGetAccelerationStructureBuildSizesKHR b00/500. The compaction scratch buffer should be 0x600 bytes.

The cause is the compiler. MSVC 19.52.37029 (toolset 14.52) at /O2 /Ob1 compiles the test's

std::max<UINT64>(tlas_info.ScratchDataSizeInBytes,
                 std::max<UINT64>(blas_compact_info.ScratchDataSizeInBytes, compact_vk_sizes.buildScratchSize))

to this. _Right$ is meant to hold the inner result, but nothing in main stores it under that name. It shares its stack slot with tv7896, the saved vkDestroyDevice pointer. The code loads that pointer and reads the first eight bytes of the function as the size:

lea    rax, QWORD PTR tlas_info$65[rbp-248]
cmp    QWORD PTR tlas_info$65[rbp-248], rcx
cmovb  rax, QWORD PTR _Right$[rbp-256]
mov    rdx, QWORD PTR [rax]

That value is not a size, so arena_allocate refused it for being larger than the arena. The message prints the size through int(Width / 1024), so 105903 may be truncated.

The fix takes the maximum of the three values with one std::max over a list (and includes <algorithm> for it). The layer and the arena allocator are unchanged. Nothing is skipped.

Tested

Windows 11, MSVC 19.52.37029 (RelWithDebInfo).

After the rebase on main 6293c1c4 (d6b40a0a, same patch as 2bd79535). The head is now f4fc7623 on 58be9cdf, with the same patch; runtime/ on main did not change between the two, so these were not rerun:

  • With the test source from main, both tests fail with arena full ... buffer size in KiB: 105903. With this commit both pass, 4 runs out of 4.
  • Full ctest -j 1 --timeout 300: 259 passed, 1 failed, 12 skipped, gameinput disabled. The failure is d3d12_execute_indirect_validation, also failing in the first run below (#1066 is open for it). The skipped tests are the 12 listed below.
  • The XMA2 decoder was not built on this PC (its cargo step failed), so the CI link error fixed by #877 was not reproduced here.

First run, on main a2892784:

  • Before: both tests fail as above, and the failure repeats on every run. After: both pass. With LEONIDA_ARENA_LOG=1 the first allocation after the RT buffers is 0x600 bytes, as expected.
  • The unmodified test source compiled with the 14.51 toolset (19.51.36263) and linked with the same libraries passes on the same GPU; its listing has no such cmovb. Compiled with 14.52 and linked the same way, it fails. Adding only a printf of the values after the calculation also made the 14.52 build pass, so the failure depends on the surrounding code.
  • The listings of the five gta6rt_d3d12_com sources, built with the same flags, have no cmov from a _Left$/_Right$ slot that is never stored.
  • Both tests were rebuilt and rerun after adding <algorithm>: pass.
  • Full ctest -j 1 --timeout 300: 257 passed, 1 failed, 12 skipped (the log of the baseline f3e26be7: 255 passed, 3 failed, 12 skipped). The only failure is d3d12_execute_indirect_validation, which also fails in the baseline and is known (#306, #749). Every other result is unchanged. Skipped, as in the baseline (the run predates the <algorithm> line): shader_library_corpus, bink_decode, bink_abi, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio, vk_sync_validation, d3d12_sparse_queue_family_contract, d3d12_rgb9e5_rtv, d3d12_boot_movie, d3d12_first_light. Disabled: gameinput.
  • git diff --check and python -I scripts/check_no_game_data.py runtime/test/d3d12_indirect_rt_test.cpp: clean.
  • #444 (a902c78a) and #710 (296508e1) each merge onto this commit without conflicts. Neither changes this calculation. Those merged trees were not built.

No CPU regression: the fault is in the code the compiler makes for this function, and a small standalone copy of the calculation, built with the same options, does not reproduce it.

With GPU-assisted validation on, the RayQueryKHR check misses on main and on this branch alike, with four VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281 reports; #710 describes the same result and covers the addresses. It is a separate topic and was not rerun here.

Not covered: the parts of these tests that need glslangValidator (the drawing and RayQueryKHR checks) are not built on this PC, the validation layer was off, GCC and Clang were not used. Whether other MSVC 14.52 builds have the same fault elsewhere was only checked in the files above.

GPUs tested: NVIDIA GeForce RTX 3080, driver 621.24, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/954 **Author:** [@TheGeogeo](https://github.com/TheGeogeo) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/indirect-rt-arena` --- ### 📝 Commits (1) - [`f4fc762`](https://github.com/ubiquitarianism/leonida/commit/f4fc7623c0b81dce364dcf3d227114f644f8831d) test: compute the indirect RT scratch size without nested std::max (TEST-INDIRECT-RT-ARENA) ### 📊 Changes **1 file changed** (+4 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/test/d3d12_indirect_rt_test.cpp` (+4 -2) </details> ### 📄 Description Claimed in the coordination issue as: [TEST-INDIRECT-RT-ARENA](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136007972) ### What and why `d3d12_indirect_rt` and `d3d12_indirect_rt_upload_sysmem` stopped at `GPU address arena full ... buffer size in KiB: 105903` and `FAIL: CreateCommittedResource(compaction/clone buffers)` on an RTX 3080. The sizes are not the problem. Printed on that GPU, in bytes (hex, result/scratch): BLAS `a00`/`200`, TLAS `800`/`300`, the compaction BLAS from the layer `a00`/`200`, and from `vkGetAccelerationStructureBuildSizesKHR` `b00`/`500`. The compaction scratch buffer should be `0x600` bytes. The cause is the compiler. MSVC 19.52.37029 (toolset 14.52) at `/O2 /Ob1` compiles the test's ```cpp std::max<UINT64>(tlas_info.ScratchDataSizeInBytes, std::max<UINT64>(blas_compact_info.ScratchDataSizeInBytes, compact_vk_sizes.buildScratchSize)) ``` to this. `_Right$` is meant to hold the inner result, but nothing in `main` stores it under that name. It shares its stack slot with `tv7896`, the saved `vkDestroyDevice` pointer. The code loads that pointer and reads the first eight bytes of the function as the size: ``` lea rax, QWORD PTR tlas_info$65[rbp-248] cmp QWORD PTR tlas_info$65[rbp-248], rcx cmovb rax, QWORD PTR _Right$[rbp-256] mov rdx, QWORD PTR [rax] ``` That value is not a size, so `arena_allocate` refused it for being larger than the arena. The message prints the size through `int(Width / 1024)`, so `105903` may be truncated. The fix takes the maximum of the three values with one `std::max` over a list (and includes `<algorithm>` for it). The layer and the arena allocator are unchanged. Nothing is skipped. ### Tested Windows 11, MSVC 19.52.37029 (`RelWithDebInfo`). After the rebase on `main` 6293c1c4 (`d6b40a0a`, same patch as `2bd79535`). The head is now `f4fc7623` on 58be9cdf, with the same patch; `runtime/` on `main` did not change between the two, so these were not rerun: - With the test source from `main`, both tests fail with `arena full ... buffer size in KiB: 105903`. With this commit both pass, 4 runs out of 4. - Full `ctest -j 1 --timeout 300`: 259 passed, 1 failed, 12 skipped, `gameinput` disabled. The failure is `d3d12_execute_indirect_validation`, also failing in the first run below (#1066 is open for it). The skipped tests are the 12 listed below. - The XMA2 decoder was not built on this PC (its cargo step failed), so the CI link error fixed by #877 was not reproduced here. First run, on `main` a2892784: - Before: both tests fail as above, and the failure repeats on every run. After: both pass. With `LEONIDA_ARENA_LOG=1` the first allocation after the RT buffers is `0x600` bytes, as expected. - The unmodified test source compiled with the 14.51 toolset (19.51.36263) and linked with the same libraries passes on the same GPU; its listing has no such `cmovb`. Compiled with 14.52 and linked the same way, it fails. Adding only a `printf` of the values after the calculation also made the 14.52 build pass, so the failure depends on the surrounding code. - The listings of the five `gta6rt_d3d12_com` sources, built with the same flags, have no `cmov` from a `_Left$`/`_Right$` slot that is never stored. - Both tests were rebuilt and rerun after adding `<algorithm>`: pass. - Full `ctest -j 1 --timeout 300`: 257 passed, 1 failed, 12 skipped (the log of the baseline f3e26be7: 255 passed, 3 failed, 12 skipped). The only failure is `d3d12_execute_indirect_validation`, which also fails in the baseline and is known (#306, #749). Every other result is unchanged. Skipped, as in the baseline (the run predates the `<algorithm>` line): `shader_library_corpus`, `bink_decode`, `bink_abi`, `bink_play_headless`, `fsr_dispatch`, `bvh_builder`, `bink_audio`, `vk_sync_validation`, `d3d12_sparse_queue_family_contract`, `d3d12_rgb9e5_rtv`, `d3d12_boot_movie`, `d3d12_first_light`. Disabled: `gameinput`. - `git diff --check` and `python -I scripts/check_no_game_data.py runtime/test/d3d12_indirect_rt_test.cpp`: clean. - #444 (a902c78a) and #710 (296508e1) each merge onto this commit without conflicts. Neither changes this calculation. Those merged trees were not built. No CPU regression: the fault is in the code the compiler makes for this function, and a small standalone copy of the calculation, built with the same options, does not reproduce it. With GPU-assisted validation on, the RayQueryKHR check misses on `main` and on this branch alike, with four `VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281` reports; #710 describes the same result and covers the addresses. It is a separate topic and was not rerun here. Not covered: the parts of these tests that need `glslangValidator` (the drawing and `RayQueryKHR` checks) are not built on this PC, the validation layer was off, GCC and Clang were not used. Whether other MSVC 14.52 builds have the same fault elsewhere was only checked in the files above. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.24, Windows 11 AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:43 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#991
No description provided.