Repository navigation
perf(shader): record a BDA fault with one atomic claim and branch-free stores - #20870
Conversation
…e stores record_bda_fault is inlined into every guest memory access and AMD's compiler ignores DontInline, so its atomic OR, compare-exchange lock, conditional stores and release store were copied about 1,540 times into vkQuake's ray-traced shadow compute shader. The fault record now has a claim word: one atomic OR claims it and sets a sticky other-fault bit, and the winner's fields go to the record while every other caller's go to a discard word, with no branch. The rect-list recorder claims the same word, and the driver reads the other-fault bit from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This pull request is labeled |
|
Windows NVIDIA check of head Setup: Windows 11 Home 10.0.26300, i9-13900K, WinLibs GCC 15.2.0, Release, RTX 4080 (
The one test not run on both sides is Not checked: AMD, Linux, macOS, any commercial title. AI-assisted: yes |
|
Tested merged onto
|
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Tested on Cyberpunk 2077 (PPSA03974) 02.120.000, the intro movie at 3200x1800, Windows 11 (10.0.26200), RTX 5090 (NVIDIA 617.42), Ryzen 9 9950X3D, WinLibs GCC 15.2 Release. Base: current
About 7% below the boots around it. That is a single boot and inside the drift I see between boots here, so I'm not calling it a slowdown; I'll repeat it next session and post the result here. No errors or aborts. |
What
record_bda_faultis called at every guest-memory access that can fault. It is markedDontInline, but AMD's Windows compiler (LLPC) inlines it anyway: removing the flag from a captured module changes nothing (75.8 s against 76.7 s). In vkQuake's ray-traced shadow compute shader (PPSA99010, program0x20c60f400) it ends up about 1,540 times in the inlined module, from 326 call sites, many of them inside other inlined helpers.otherFaultsinside a branch, a compare-exchange lock onstate, six stores inside a second branch, and a release atomic store ofReady. That pipeline takes 75–85 s to create on an RX 7900 XT, well past any title's GPU wait, so vkQuake shows no frame on a cold cache.claimword in place ofotherFaults, plusdiscardandreservedwords (32 → 40 bytes):claimsets bit 0 (claimed) and, unless the reason isUnaligned, bit 1 (another fault). The caller that finds bit 0 clear in the old value wins.Readygo to the record. Every other caller writes the same values todiscardinstead, through anOpSelected index, so the function has no branches.stateis written only by the winner, so no plain store races an atomic. The losers' stores todiscardrace only with each other, and nothing reads that word.BdaResources::checkFaultreads the other-fault flag fromclaimthroughBdaAbi::OtherFaults, and checksclaimwhere it checkedotherFaults.OtherFaultsis added to the shader-cache reviewed names: it only reads a record on the host.SpirvFaultReportOnlyaccepts an access-chain index that is anOpSelectof two constants in the record. Without this, every shader would lose its report-only fault slot.BdaExecutionandBdaResourcesread the flag throughOtherFaults, andShaderMemory's "fault recorded outsiderecord_bda_fault" check counts the claim OR.checkFaultline changed here. Whichever merges second keeps both lines.StopBdaInvocationIfin the same file but not the recorder.Tested
How the recorder was found, on SPIR-V captured from vkQuake with
APS5_DUMP_COMPUTE_PIPELINESand edited by hand. Each variant was timed withagc_compute_pipeline_replay, AMD's driver cache moved aside before every compile:record_bda_faultout took the pipeline from 76.7 s to 28.4 s. Every load and store stayed in the module.otherFaultsas a separate atomic OR took 55.2–56.3 s against 47.7–50.0 s without it.Readystore: 75.2 s;This branch (4003dfc) against
main(03dc6b3), on modules captured from vkQuake built from each:record_bda_fault: 39 → 37 instructions, 3 → 1 atomics.mainand the other 13 helpers are instruction-for-instruction identical, and both passspirv-val.pipeline_create, two runs each in alternating order, driver cache moved aside each time:main77.9 s and 91.7 s, this branch 56.0 s and 59.9 s (about 32% less).Vulkan tests with
ANYPS5_REQUIRE_VULKAN=1, every test fromagc_driver_bda_device_tests,agc_shader_memory_tests,agc_driver_graphics_tests,agc_rect_list_position_invariant_tests,agc_spirv_lds_atomic_lock_testsandagc_bda_atomics_tests:BdaExecution.tools/check_conventions.pypasses.tools/pr_overlap.py --branch: fix(agc): write back BDA stores into writable heap mirrors #12840 is the only line overlap, described above. The PRs it could not compare are the descriptor-heap stack (feat(agc): GPU descriptor heap on VK_EXT_descriptor_heap (APS5_GPU_HEAP) #9508, feat(agc): look up table images at run time through a device image table on the GPU heap (APS5_GPU_PATH) #7642, feat(agc): serve lane-keyed, pointer and runtime image-table columns #10193, feat(agc): resolve table samplers through device image keys #13928, feat(agc): resolve runtime sampler addresses through device image keys #13929), which carries merges ofmain, plus fix(shader): mask writes after barrier-safe BDA faults #7392 and older PRs that only share test files.Performance (Performance report form): AMD Radeon RX 7900 XT, AMD proprietary driver 26.10.1 (LLPC), Windows 11 Pro 26H2 (build 26300), Ryzen 9 7900X.
r_rtshadows 1), AMD's driver cache moved aside,APS5_PROFILE_DRAW=1. The driver's own line for the ray-traced shadow compute pipeline (program0x20c60f400):mainb7aeb6f:[dispatch] created a pipeline for 152566 SPIR-V words in 83856 ms[dispatch] created a pipeline for 152602 SPIR-V words in 56888 msAPS5_TRACE_SECONDS=10:20and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. Frame p50/p90/p99/max is 16.684/16.902/16.994/17.155 ms onmainand 16.686/16.881/16.979/17.103 ms here, 1,199 presents each (vsync at 60 Hz). Traces attached.main(eef7373):{"commit":"eef73731fc92","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"10:20"},"gpu":"AMD Radeon RX 7900 XT","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 7900X 12-Core Processor","cpu_threads":24,"memory_mib":31904,"title_id":"PPSA99051","title":"Surround Sound Studio","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 10:20","first_present":598,"ms":20003.061},"presents":1199,"frame_ms":{"p50":16.684,"p90":16.902,"p99":16.994,"max":17.155},"gpu_busy_ms_per_present":5.519,"worker_busy_pct":{"queue worker 0x0":4.208},"phase_totals_ms":{"Driver.Completion":0.948,"Driver.Draw":278.912,"Driver.Draw.device_setup":13.327,"Driver.Draw.draw_enqueued":31.404,"Driver.Draw.post_compile_prepare":1.140,"Driver.Draw.prepare":37.523,"Driver.Draw.shader_compile_and_link":191.531,"Driver.EndSubmission":1.118,"Driver.Packet":839.379,"Driver.Packet.device_lock":3.112,"Driver.Packet.draw":281.854,"Driver.Packet.execute":19.748,"Driver.Packet.flip_flush":67.080,"Driver.Packet.flush_between_packets":4.269,"Driver.Packet.pipeline_drain":427.702,"Driver.Packet.pipeline_prepare":4.949,"Driver.Packet.prepare_memory":5.778,"Driver.Present":1259.366,"Driver.Present.acquire_image":684.134,"Driver.Present.device_setup":0.508,"Driver.Present.gpu_mutex_wait":2.593,"Driver.Present.inflight_wait":3.124,"Driver.Present.present_display_buffer":165.136,"Driver.Present.queue_present":312.326,"Driver.Present.release_and_callback":1.070,"Driver.Present.render_fence_wait":86.797,"Driver.Present.resize":2.544,"Driver.Present.validate":0.490,"Driver.Suspend":0.319,"GpuMutex.wait.draw":0.148,"GpuMutex.wait.flush":0.003,"GpuMutex.wait.present":0.126,"GpuMutex.wait.wait":0.963,"Graphics.Draw":715.029,"Graphics.Draw.draw_and_resource_release":689.922,"Graphics.Draw.index_upload":0.552,"Graphics.Draw.validate":18.526,"Graphics.Draw.vertex_upload":2.936,"Recorder.Reap":39.924,"Recorder.Submit":183.398,"Recorder.WaitSerial":15.402,"Resources.Complete":53.338,"Resources.Prepare":63.071,"Shader.DrawStage":163.411,"Shader.DrawStage.capture_resources":108.032,"Shader.DrawStage.materialize":27.595,"Shader.DrawStage.prepared_invocation":26.079,"VideoOut.Flip":18914.471,"VideoOut.Flip.completion_mutex_wait":1.140,"VideoOut.Flip.config_mutex_wait":0.099,"VideoOut.Flip.frame_limit":2.608,"VideoOut.Flip.notify_game":41.991,"VideoOut.Flip.present":1262.496,"VideoOut.Flip.validate":0.927,"VideoOut.Flip.vblank_wait":17565.379,"VideoOut.Flip.window_prepare":2.530,"VideoOut.Flip.window_title":51.000,"VideoOut.Readiness":1.571,"VideoOut.Readiness.locks_validate":0.335,"Vulkan.Acquire":682.802,"Vulkan.Acquire.acquire_fence_wait":599.639,"Vulkan.Acquire.acquire_image":78.857,"Vulkan.Acquire.fence_reset":2.142,"Vulkan.Acquire.retired_swapchains":1.697,"Vulkan.Present":90.815,"Vulkan.Present.command_record_scale":36.700,"Vulkan.Present.pixel_upload":2.317,"Vulkan.Present.queue_submit":50.981,"Vulkan.QueuePresent":310.611,"Vulkan.QueuePresent.queue_present":308.923,"Vulkan.Retire":86.948,"Vulkan.Retire.wait":79.343},"top_phases_ms_per_frame":{"VideoOut.Flip":15.775,"VideoOut.Flip.vblank_wait":14.650,"VideoOut.Flip.present":1.053,"Driver.Present":1.050,"Driver.Packet":0.700,"Graphics.Draw":0.596,"Graphics.Draw.draw_and_resource_release":0.575,"Driver.Present.acquire_image":0.571},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":4796,"Graphics.Barrier.label-run":7194,"Graphics.Barrier.present-blit":2398,"Graphics.RenderPass":2398,"Graphics.RenderPass.Close.new-batch":2398,"Graphics.RenderPass.Continued":5995},"trace_dropped":false,"trace":"aps5-trace-eef73731fc92-3184.json.gz"}This PR (4003dfc):
{"commit":"4003dfc38385","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"10:20"},"gpu":"AMD Radeon RX 7900 XT","driver":"AMD proprietary driver 26.10.1 (LLPC)","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 7900X 12-Core Processor","cpu_threads":24,"memory_mib":31904,"title_id":"PPSA99051","title":"Surround Sound Studio","content_version":"01.000.003","resolution":"3840x2160","window":{"spec":"seconds 10:20","first_present":598,"ms":20003.066},"presents":1199,"frame_ms":{"p50":16.686,"p90":16.881,"p99":16.979,"max":17.103},"gpu_busy_ms_per_present":5.633,"worker_busy_pct":{"queue worker 0x0":4.261},"phase_totals_ms":{"Driver.Completion":0.968,"Driver.Draw":276.248,"Driver.Draw.device_setup":12.243,"Driver.Draw.draw_enqueued":31.224,"Driver.Draw.post_compile_prepare":1.209,"Driver.Draw.prepare":37.265,"Driver.Draw.shader_compile_and_link":190.418,"Driver.EndSubmission":1.097,"Driver.Packet":849.923,"Driver.Packet.device_lock":3.087,"Driver.Packet.draw":279.350,"Driver.Packet.execute":18.724,"Driver.Packet.flip_flush":64.438,"Driver.Packet.flush_between_packets":4.466,"Driver.Packet.pipeline_drain":444.152,"Driver.Packet.pipeline_prepare":4.910,"Driver.Packet.prepare_memory":5.994,"Driver.Present":1268.685,"Driver.Present.acquire_image":682.413,"Driver.Present.device_setup":0.558,"Driver.Present.gpu_mutex_wait":2.358,"Driver.Present.inflight_wait":2.935,"Driver.Present.present_display_buffer":166.564,"Driver.Present.queue_present":312.609,"Driver.Present.release_and_callback":1.117,"Driver.Present.render_fence_wait":96.682,"Driver.Present.resize":2.276,"Driver.Present.validate":0.570,"Driver.Suspend":0.290,"GpuMutex.wait.draw":0.001,"GpuMutex.wait.flush":0.250,"GpuMutex.wait.present":0.077,"Graphics.Draw":705.779,"Graphics.Draw.draw_and_resource_release":682.562,"Graphics.Draw.index_upload":0.580,"Graphics.Draw.validate":17.391,"Graphics.Draw.vertex_upload":2.213,"Recorder.Reap":38.966,"Recorder.Submit":172.835,"Recorder.WaitSerial":14.826,"Resources.Complete":53.897,"Resources.Prepare":62.929,"Shader.DrawStage":163.105,"Shader.DrawStage.capture_resources":108.432,"Shader.DrawStage.materialize":28.004,"Shader.DrawStage.prepared_invocation":25.051,"VideoOut.Flip":18906.607,"VideoOut.Flip.completion_mutex_wait":0.981,"VideoOut.Flip.config_mutex_wait":0.091,"VideoOut.Flip.frame_limit":2.755,"VideoOut.Flip.notify_game":22.507,"VideoOut.Flip.present":1272.018,"VideoOut.Flip.validate":0.886,"VideoOut.Flip.vblank_wait":17565.121,"VideoOut.Flip.window_prepare":2.295,"VideoOut.Flip.window_title":54.096,"VideoOut.Readiness":1.559,"VideoOut.Readiness.locks_validate":0.360,"Vulkan.Acquire":681.163,"Vulkan.Acquire.acquire_fence_wait":597.879,"Vulkan.Acquire.acquire_image":79.125,"Vulkan.Acquire.fence_reset":2.070,"Vulkan.Acquire.retired_swapchains":1.706,"Vulkan.Present":91.493,"Vulkan.Present.command_record_scale":36.351,"Vulkan.Present.pixel_upload":2.427,"Vulkan.Present.queue_submit":51.917,"Vulkan.QueuePresent":310.850,"Vulkan.QueuePresent.queue_present":309.266,"Vulkan.Retire":96.674,"Vulkan.Retire.wait":89.093},"top_phases_ms_per_frame":{"VideoOut.Flip":15.769,"VideoOut.Flip.vblank_wait":14.650,"VideoOut.Flip.present":1.061,"Driver.Present":1.058,"Driver.Packet":0.709,"Graphics.Draw":0.589,"Graphics.Draw.draw_and_resource_release":0.569,"Driver.Present.acquire_image":0.569},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":4797,"Graphics.Barrier.label-run":7194,"Graphics.Barrier.present-blit":2398,"Graphics.RenderPass":2398,"Graphics.RenderPass.Close.new-batch":2398,"Graphics.RenderPass.Continued":5995},"trace_dropped":false,"trace":"aps5-trace-4003dfc38385-20976.json.gz"}Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)