d3d12/vulkan: write NaN depth clears with a copy on AMD (D3D-CLEAR-NAN-DEPTH) #787
Closed
leonida/mandy
bvtterbroot wants to merge 0 commits from
nan-depth-clear into main
pull from: nan-depth-clear
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!787
Loading…
Reference in a new issue
No description provided.
Delete branch "nan-depth-clear"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
On AMD,
d3d12_clearstays red even with #516: AMD's Vulkan driver stores 1.0 for a NaN depth clear value, so a D3D12 clear that WARP and native D3D12 store as NaN comes back as 1.0. This writes such a clear with a copy, which the driver does not touch, so the layer matches WARP on every vendor.Builds on #516 (its two commits are the first two here; the change is the last commit). D3D-CLEAR-NAN-DEPTH, follow-up to #506. Supersedes the test-only draft #307, which reports the same driver behaviour on an RX 9070 XT.
What changes
runtime/src/vulkan_replay.h: withVK_EXT_depth_range_unrestrictedenabled, a depth clear whose value is NaN on aD32_SFLOATorD32_SFLOAT_S8_UINTdepth plane is avkCmdFillBufferof the value's 32 bits into transfer scratch (one rectangle's worth,copy_scratch), then onevkCmdCopyBufferToImageregion per cleared rectangle (the whole mip without rectangles), on the depth aspect only. A stencil cleared in the same call is still a clear, of the stencil aspect alone. Every other clear is unchanged, and without the extension NaN is still cleared to 0 as #516 does.runtime/test/d3d12_clear_test.cpp: two more edge cases onD32_FLOAT_S8X24_UINTwith DEPTH | STENCIL: NaN with stencil 0x11 / 0x22 in the rectangle, and NaN then 0.5 in the rectangle. Depth and stencil are checked against WARP and the expected value, in both the unrestricted and the--restricted-depthrun.docs/d3d12_vulkan.md: the driver behaviour and the copy, under "Depth clears".Tested
AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359, Windows 11, MSVC 14.44, Vulkan SDK 1.4.363.0. No game files.
main21625bca):d3d12_clearfails with and withoutLEONIDA_VK_VALIDATION=1, all 15 texelsdepth clear with NaN (0,0): layer cleared 1, expected nan.d3d12_clear,d3d12_clear_restricted_depth,d3d12_clear_formatsandd3d12_rgb9e5_rtvpass, 3 runs each with and withoutLEONIDA_VK_VALIDATION=1, no validation messages.depth clear with NaN: 5x3 depth texels matched (WARP parity),D32_S8 clear with NaN and stencil: 5x3 depth and stencil texels matched (WARP parity).d3d12_clearfails again withlayer cleared 1, expected nan.ctest: 300/304. The 4 failures are onmainon this PC too and are tracked elsewhere:vk_queue_query_sync(OLD-6149),d3d12_texture_tiles,d3d12_execute_indirect_validation(#504),d3d12_pipeline_library_host(finding in #14).mainhasd3d12_clearas a fifth.python -Itests/test_ctest_registration.py,test_docs_list_items.py,test_docs_repeated_lines.py,test_docs_table_ids.py,test_exe_checklist.py: pass.scripts/check_no_game_data.pyon the changed files: exit 0.Not tested: NVIDIA and Intel. There the copy replaces a clear that already stored NaN, so the result should not change, but a run with
ctest -R d3d12_clearon one of them would confirm it.AI-assisted (Claude Code wrote the change and ran the tests).
🤖 Generated with Claude Code
Tested head
0d69d1be6on two more AMD generations, RDNA4 and RDNA2, on the same 26.11.2 driver: it fixes both.Setup: Windows 11 10.0.26200.9974, AMD 26.11.2, Vulkan SDK 1.4.363.0, MSVC 19.44,
RelWithDebInfo. Radeon RX 9070 (RDNA4 / GFX1201, driver 32.0.32029.2010) and the Ryzen 5 7600X iGPU (RDNA2 / gfx1036, 32.0.21045.29003), each selected withLEONIDA_VK_DEVICE. Base is your base,maind0da7dade.ctest -R "^(d3d12_clear|d3d12_clear_restricted_depth|d3d12_clear_formats|d3d12_rgb9e5_rtv)$", each GPU withLEONIDA_VK_VALIDATION0 and 1:maind0da7daded3d12_clearfails (2/3 pass):a NaN depth stays NaN (0,0): layer cleared 1, WARP nan, every texeld3d12_clearfails the same way (2/3 pass)LEONIDA_VK_VALIDATION=1runs.d3d12_clear_testrun directly on each GPU printsdepth clear with NaN: 5x3 depth texels matched (WARP parity)and both newD32_S8cases (with NaN and stencil,with NaN, then 0.5 in the rectangle) as5x3 depth and stencil texels matched (WARP parity).So the driver behaviour is the same on RDNA2, RDNA3 (your 7900 XTX) and RDNA4, and the copy path covers all three.
I also read the runtime diff (
vulkan_replay.h,vulkan_backend.h,d3d12_vulkan_device.cpp,d3d12_com.h,vk_test_device.h) and found nothing to flag:nan_depth_copyonly takes NaN onD32_SFLOAT/D32_SFLOAT_S8_UINTwith the extension enabled, so other clears stay on the old path.memcpy), with the scratch sized for the largest rectangle and the 4-byte offset alignment checked.view_range, which is bounds-checked and neverVK_REMAINING_ARRAY_LAYERS.cleared.aspectMaskalone, and a depth-only clear skips the clear. I didn't repeat the negative control or the fullctest. Like you, I have no NVIDIA or Intel run.No game files. AI-assisted: yes
Tested 0d69d1be6 applied onto main 23c459644 on an AMD Radeon RX 7900 XT: d3d12_clear fails on main (NaN depth clear reads back 1.0) and passes with this PR, 3/3 runs. The new d3d12_clear_restricted_depth passes 3/3. No new failures in the full ctest run.
Hardware/software: AMD Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (Adrenalin 26.11.2, Vulkan 1.4.359, offers VK_EXT_depth_range_unrestricted), Windows 11 build 26300, VS 2022 (x64, RelWithDebInfo), Vulkan SDK 1.4.363.0.
Build:
Targeted tests, 3 runs each on main and on the PR (third run with
LEONIDA_VK_VALIDATION=1):On main, d3d12_clear fails in the NaN depth case: all 15 texels of the 5x3 D32_FLOAT target read back 1.0 where WARP has NaN:
With validation on, main also reports 4 errors for VUID-VkClearDepthStencilValue-depth-00022 (depth 1.5, -0.5 and NaN passed to vkCmdClearDepthStencilImage / vkCmdClearAttachments without VK_EXT_depth_range_unrestricted enabled).
With the PR, every d3d12_clear run prints:
and d3d12_clear_restricted_depth prints the same five depth lines with "(restricted Vulkan depth)", i.e. 1.5/-0.5 clamped to 1/0 and NaN stored as 0. The validation-on runs of all four tests report no validation errors. Unchanged on both trees: d3d12_clear_formats "251 matched WARP, 0 differ, 0 failed", d3d12_rgb9e5_rtv "full and rectangle clears match all 15 packed texels".
Full ctest on the PR build, once:
The four remaining failures also fail on main and are unrelated to depth clears. Skipped/disabled tests are the same 13 on both.
Note:
--restricted-depthruns only check_depth_clear_edge_values and returns; the volume, castable-RTV and RTV/DSV clear checks are covered only by the unrestricted d3d12_clear run.Independent GPU verification on a second AMD RDNA2 device (plus NVIDIA cross-check). AI-assisted verification by Devin.
Setup
0d69d1be6("Merge main into nan-depth-clear"), detached checkout, incrementalcmake --build runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo, built clean.origin/main6261ca916, full rebuild in a separate worktree (runtime/build, same toolchain).AMD Radeon iGPU (RDNA2 gfx1035, driver 24.10.24, Vulkan 1.3.280)
NVIDIA RTX 4070 SUPER
Results
AMD iGPU — NaN depth clear
Baseline
origin/main(6261ca916),d3d12_clear: FAILED — reproduces the reported bug on this RDNA2 iGPU:All 15 NaN-clear texels read back as
1instead of NaN — same "driver stores 1.0 for NaN clear values" behaviour the PR describes, now confirmed on an AMD RDNA2 iGPU with driver 24.10.24 (much older than the 26.11.2 used for the author's RX 7900 XTX check).PR head
0d69d1be6,d3d12_clear: PASSED (7.94 s first run, 2.60 s warm) withLEONIDA_VK_VALIDATION=1— no validation errors.d3d12_clear_restricted_depthandd3d12_clear_formatsalso pass.Wider
-R "clear"subset on the PR head: 8/8 passed (d3d12_uav_clear,d3d12_short_uav_clear,d3d12_clear,d3d12_clear_restricted_depth,d3d12_clear_formats,clear_color,replay_clear_gate,replay_uav_clear_offset).NVIDIA RTX 4070 SUPER
-R "clear": 8/8 passed, includingd3d12_clear.origin/maind3d12_clear: passed — NVIDIA's driver never showed the NaN→1.0 defect, so this is a no-op there as expected.Regression sweep (AMD iGPU, PR head)
scripts/run_gpu_tests.py --build runtime/build --require-pass(translated 258/258 shaders,spirv-valskipped — not on PATH): 224/249 passed, 20 skipped. The only 4 failures are all pre-existing on this iGPU and unrelated to clears:cs_imgload_d16_tfe,cs_imgload_tfe— known issue #31ms_clip,ms_wave_info_s3— device crash on this iGPU, open issues #802/#808ms_v5_workgroupalso reported FAIL but only becausespirv-valisn't on PATH in this shell — environmental, not a code failure)Verdict
Verified on a second AMD device: the fill + buffer-to-image copy path fixes NaN depth clears on RDNA2 gfx1035 / driver 24.10.24, not just RDNA3. Before/after on the same machine is unambiguous:
origin/mainfailsd3d12_clearwith 15 texels reading1instead of NaN; this PR's head passes with validation layers on. No clear-related regressions on either GPU.