Skip to content

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

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:fix/indirect-rt-arena
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:fix/indirect-rt-arena

Conversation

@TheGeogeo

@TheGeogeo TheGeogeo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 6293c1c (d6b40a0a, same patch as 2bd79535). The head is now f4fc7623 on 58be9cd, with the same patch; runtime/ on main did not change between the two, so these were not rerun:

First run, on main a289278:

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)

@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent Windows check against parent a28927849 and PR head 2bd795357. Both d3d12_indirect_rt and d3d12_indirect_rt_upload_sysmem passed on both revisions with MSVC 19.44.35220, RelWithDebInfo, Windows 11 26100.7623, NVIDIA RTX 5070 Ti (610.74).

Both memory modes exercised BLAS clone and compaction. Each reported a compacted size of 1,152 bytes and the ray query produced one hit and one miss on both revisions. Core and synchronization validation were active, both test modes reported zero validation errors, and the validation self-test passed. This covers the older compiler. The 19.52-specific failure remains covered by the author's run.

Synthetic inputs only. AI-assisted: OpenAI Codex.

@Timon360SB

Copy link
Copy Markdown
Contributor

Independent testing results

Tested the indirect ray tracing scratch-size change on NVIDIA Blackwell hardware with Vulkan validation enabled.

Both BASE and HEAD exhibit a reproducible RayQueryKHR failure with matching acceleration structure validation diagnostics.

Tested revisions

  • BASE: a28927849adb4e40dfdec8c32fb6758dcd205a37
  • HEAD: 2bd795357da1b7a2a4215873aa32f64279f8d530

Test environment

Component Configuration
CPU AMD Ryzen 7 7800X3D
GPU NVIDIA GeForce RTX 5070 (Blackwell)
VRAM 12227 MiB
RAM 31.11 GiB
GPU driver 621.14
OS Windows 11 Pro, build 26200
Vulkan SDK 1.4.363.0
MSVC 19.44.35230
Windows SDK 10.0.26100.0
Resizable BAR Enabled

Test configuration

  • RelWithDebInfo, Ninja Multi-Config.
  • Selected CTest targets.
  • Vulkan core, GPU-assisted and synchronization validation enabled.
  • Three repetitions per revision per attempt.
  • Three independent queue attempts.
  • Existing compatible builds reused where available.

Both revisions compiled successfully.

Execution logs and run timestamps confirm that tests were executed again during subsequent attempts.

CTest results

Test BASE HEAD
d3d12_indirect_rt 0/9 0/9
d3d12_indirect_rt_upload_sysmem 0/9 0/9
vk_sync_validation 9/9 9/9
Total PASS 9/27 9/27
Status BASE HEAD Combined
PASS 9 9 18
FAIL 18 18 36
SKIP 0 0 0
Total 27 27 54

All 18 CTest process invocations completed with exit code 8 due to the indirect RT test failures.

RayQueryKHR failure

Both indirect RT test variants consistently reported:

FAIL: RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0
Ray query result Expected Actual
Hit 1 0
Miss 0 0

The failure reproduced in all 36 executions of the two indirect RT tests across BASE and HEAD.

Acceleration structure validation

The failing tests reported:

VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281

Representative diagnostic:

validation: vkCmdBuildAccelerationStructuresKHR():
pInfos[0].pGeometries[0].geometry.instances<VkAccelerationStructureInstance>[0].accelerationStructureReference (0xce80000) is an invalid acceleration structure reference.

The validation layer reports invalid acceleration structure references in the instance geometry passed to vkCmdBuildAccelerationStructuresKHR.

Property BASE HEAD
Indirect RT test failures 18 18
Occurrences of VUID-pInfos-12281 72 72
VUID occurrences per failing test 4 4

The same diagnostic category and functional failure were present on both revisions.

The exact root cause of the invalid acceleration structure references was not established during this verification.

Upload heap configurations

The failure reproduced with both upload heap configurations:

  • VRAM using DEVICE_LOCAL | HOST_VISIBLE memory with Resizable BAR.
  • System memory using LEONIDA_UPLOAD_SYSMEM.

Consequently, the observed failure was not limited to the VRAM upload heap configuration.

Successful subchecks

Despite the overall indirect RT test failures, the following subchecks passed consistently:

[PASS] ExecuteIndirect with suballocated argument and count buffers (count=0 skipped, count=1 rendered)
[PASS] KHR COMPACTED_SIZE postbuild (inline=1152, emit2=[1152, 1152])

The recorded compaction size results remained identical between BASE and HEAD.

No scratch-buffer GPU address arena exhaustion diagnostic matching the original reported failure was identified in the examined logs.

Compiler-specific limitation

The compiler used here was MSVC 19.44.35230.

This differs from MSVC 19.52.37029, which is associated with the nested std::max miscompilation addressed by this PR.

Therefore, these results do not independently reproduce or confirm the original compiler-specific fix.

Synchronization validation

All vk_sync_validation executions passed.

The expected intentional WRITE_AFTER_WRITE hazard without a barrier and zero errors with a barrier were observed consistently.

Conclusion

Result: FAIL on both revisions — no new failure introduced by HEAD was identified in the tested scenarios.

The indirect ray tracing tests consistently failed on both BASE and HEAD due to a RayQueryKHR output mismatch accompanied by invalid acceleration structure reference validation diagnostics.

The original compiler-specific scratch-size issue could not be independently verified with this MSVC version.

The acceleration structure reference issue appears to warrant separate investigation. Testing with the affected MSVC 19.52 toolchain would be required to directly verify the intended fix.

Testing was limited to one NVIDIA GPU, synthetic fixtures and validation-enabled execution. No real-title testing was performed.

AI-assisted log analysis and report preparation.

@TheGeogeo
TheGeogeo force-pushed the fix/indirect-rt-arena branch from 2bd7953 to d6b40a0 Compare November 24, 2026 19:45
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Rebased on main 6293c1c: the head is now d6b40a0a, with the same patch as 2bd79535 (git range-diff reports it unchanged).

CI. The failed run built this branch on a28927849, and both failures come from that base:

Both are in the new base. The new CI run has not finished, so this is read from the logs and those changes.

@Timon360SB's report (thanks). The RayQueryKHR miss and the four VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281 reports are the same on the base and on this branch, and #710 describes the same result under GPU-assisted validation on main: the layer replaces the instance's BLAS with its dummy one, so the ray misses. #710 changes how arena acceleration structures get their addresses, and says the RayQueryKHR check still misses under GPU-AV with it. I left that out of this pull request, which only changes the test's scratch-size calculation. I did not rerun GPU-AV.

Rerun on Windows 11, MSVC 19.52.37029 (RelWithDebInfo), RTX 3080, driver 621.24, on the new base:

AI-assisted: yes (Claude Code).

@TheGeogeo
TheGeogeo force-pushed the fix/indirect-rt-arena branch from d6b40a0 to f4fc762 Compare November 24, 2026 20:15
xel1uz pushed a commit to xel1uz/mandy that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** RT-4444-TARGET: where the device can't use a 4444 format as a colour attachment (NVIDIA), a B4G4R4A4 render target becomes an RGBA8 image. Its T#s keep the 4_4_4_4 format, and PSO RTV formats follow the image. Before this, the render target couldn't be created at all (size UINT64_MAX). sodove (5070 Ti) and SweatierKey approved.

**Why it's good:** The new d3d12_b4g4r4a4_target really runs here (not skipped): "B4G4R4A4_UNORM ... using RGBA8", OK, 0 validation errors. b5g5r5a1_uav, srgb_uav and vulkan_device also pass. **Follow-up, not a blocker:** sodove measured that the RGBA8 fallback stores clears at 8-bit precision instead of quantising to 4 bits (0/1920 texels matched WARP's 4-bit result), and buffer-footprint copies from it move 4-byte texels (documented in the code). Quantising on clear and store would close that gap.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: ProjectLeonida#517, ProjectLeonida#907, ProjectLeonida#927, ProjectLeonida#954 and ProjectLeonida#1074 merged onto main 32a5d96 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d96 too: a regression from ProjectLeonida#510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** VK-UAV-CLEAR-PACK16: B5G6R5, B5G5R5A1 and B4G4R4A4 join the UAV-clear layout table, with conversion checks and an exhaustive 65,536-word round trip. Timon360SB (2060S and 5070, 60/60) and SweatierKey approved. The current head b67109e is a content-identical rebase of the reviewed one.

**Why it's good:** uav_clear, short_uav_clear, b5g5r5a1_uav and replay_uav_clear_offset all pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d96 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d96 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** RT-TITLE-HOST-REGION: a test-only probe that imports a 185 MiB host region as a BDA buffer through VK_EXT_external_memory_host and checks coherence both ways. A machine that can't import exits 77 (skip). No runtime source changes. Timon360SB, madhyn (3060 Ti/Wine) and SweatierKey approved.

**Why it's good:** vk_host_region_import and its _validation variant: "185 MiB imported ... cpu-gpu-coherence=ok", 0 validation errors. Nit for a follow-up: the _validation test sets VK_VALIDATE_SYNC=1, which nothing in the tree reads; if sync validation is the goal, the Khronos layer setting is spelled differently, so that variant probably runs core validation only.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d96 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d96 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: TEST-INDIRECT-RT-ARENA: d3d12_indirect_rt_test replaces a nested std::max with an initializer-list std::max to work around an MSVC 19.52 miscompile. It's 6 lines. sodove passed both revisions, and the current head is a content-identical rebase.

Why it's good: indirect_rt and indirect_rt_upload_sysmem: PASS with 0 validation errors, and the RayQuery got hit=1 here under validation. Timon360SB's hit=0 on a 5070 with GPU-assisted validation shows up on the base too, so it isn't this PR.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d96 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d96 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

@QemmHD
QemmHD merged commit 22d044f into ProjectLeonida:main Nov 24, 2026
5 checks passed
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** RT-INPUT-SCRIPT-LENGTH: the shim's env() reader now handles values of any length (64 characters or more used to read as unset). The PR also adds the LEONIDA_INPUT_SCRIPT keyboard-pad scheduler (`button@seconds`, 300 ms presses), documented in docs/gameinput.md. That's a second topic, but the body says so, and both parts were reviewed. sodove checked 14/14 runs across lengths, with the control failing 12/12, and kawaii-shakal's harness follow-ups were addressed.

**Why it's good:** gameinput_host, gameinput and the new gameinput_script pass; with validation, gameinput_script passes and logs "8 accepted / 11 rejected". The parsing is bounded (strtod with end-pointer and finiteness checks) and reads only its own env var.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main 32a5d96 (after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain 32a5d96 too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
@TheGeogeo
TheGeogeo deleted the fix/indirect-rt-arena branch November 25, 2026 00:22
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.

4 participants