Shaders: capture hashes and copies a shader outside the capture lock #3295

Merged
Foniass merged 1 commit from upstream-pr/3295 into main 2026-11-29 22:18:46 +00:00
Foniass commented 2026-11-29 06:18:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T06:18:56Z.


Every pipeline creation passes its shaders through the capture
(statistics of submitted / unique shaders). It held the global STATE lock
while hashing the bytecode and copying it, so pipelines created on several
threads (the background pipeline workers) could wait on each other there
(not measured). The
hash is now computed before taking the lock, the bytecode is copied only
for a shader not seen before, and the per-kind statistics are counted in a
second short critical section.

Ported from amd-dev 48cf7139 (its gpu/shader.rs part), raylitebull.

What is in it

  • crates/xcl/src/gpu/shader.rs: capture hashes before locking, copies only a new shader, counts kinds in a second short section

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 7d52779e: 2604 passed, 4 failed, 49 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (E_OUTOFMEMORY from CreateComputePipelineState, seeds 70 / 545 / 1019 / 1507), the same as on main on this machine; they pass on another RTX 5070 Ti. SKIPPED GPU tests: 44 notices, almost all no wave64.
  • Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits).

Regression run

main:

xcl-smoke v1
commit: b10cc4c6766adc947c2054ada4a2af98be15108d
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16026 MB

this PR:

xcl-smoke v1
commit: 7d52779e107dc0b137d23a3bd99e7f283c2b8588
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1653 (PresentX 1653)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17393 MB

Not tested

  • lock contention before and after (not measured)
  • AMD GPUs

AI use

  • Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5548211426 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3295). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T06:18:56Z. --- Every pipeline creation passes its shaders through the capture (statistics of submitted / unique shaders). It held the global STATE lock while hashing the bytecode and copying it, so pipelines created on several threads (the background pipeline workers) could wait on each other there (not measured). The hash is now computed before taking the lock, the bytecode is copied only for a shader not seen before, and the per-kind statistics are counted in a second short critical section. Ported from amd-dev 48cf7139 (its gpu/shader.rs part), raylitebull. **What is in it** - `crates/xcl/src/gpu/shader.rs`: `capture` hashes before locking, copies only a new shader, counts kinds in a second short section **Tested** - NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 7d52779e: 2604 passed, 4 failed, 49 ignored. The 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3` (`E_OUTOFMEMORY` from `CreateComputePipelineState`, seeds 70 / 545 / 1019 / 1507), the same as on main on this machine; they pass on another RTX 5070 Ti. SKIPPED GPU tests: 44 notices, almost all `no wave64`. - Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits). **Regression run** main: ``` xcl-smoke v1 commit: b10cc4c6766adc947c2054ada4a2af98be15108d gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1565 (PresentX 1565) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16026 MB ``` this PR: ``` xcl-smoke v1 commit: 7d52779e107dc0b137d23a3bd99e7f283c2b8588 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1653 (PresentX 1653) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 17393 MB ``` **Not tested** - lock contention before and after (not measured) - AMD GPUs **AI use** - Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewDoing commented 2026-11-29 06:21:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T06:21:07Z.


Concurrent capture check on Ryzen 7 5700X3D, Windows, exact parent b10cc4c6 and head 7d52779e. Eight synchronized threads submitted 64 immutable 256 KiB containers each, alternating a shared input with a thread-specific one. Each fresh process therefore saw 512 submissions, 9 distinct contents, and 256 submissions each under cs and ps.

All 12 runs produced exactly 9 unique captures, 9 kind and unknown-part counts, both correct stage totals, and one byte-for-byte match under the expected FNV key for every input. The copy remains inside the first STATE lock on each unique hash. On this workload the parent copied 128 MiB there (512 inputs); the head copies 2.25 MiB (9 inputs) and hashes all 128 MiB outside the mutex.

For scale, six alternating paired runs of the optimized native CPU harness (base/head/head/base repeated) took 145.6–158.0 ms on the parent and 17.6–18.6 ms on the head for the worker section. The harness compiled the production capture/dedup/statistics prefix and container parsing, substituted a successful readability gate for owned buffers, and replaced downstream logging/dumping with an in-memory capture sink. This is workload wall time, not a measurement of time blocked inside the lock or end-to-end pipeline creation. It establishes the duplicate-heavy case; all-unique traffic still serializes the copies.

OpenAI Codex prepared and ran the synthetic controls and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7251801873 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3295#issuecomment-7251801873). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T06:21:07Z. --- Concurrent capture check on Ryzen 7 5700X3D, Windows, exact parent b10cc4c6 and head 7d52779e. Eight synchronized threads submitted 64 immutable 256 KiB containers each, alternating a shared input with a thread-specific one. Each fresh process therefore saw 512 submissions, 9 distinct contents, and 256 submissions each under cs and ps. All 12 runs produced exactly 9 unique captures, 9 kind and unknown-part counts, both correct stage totals, and one byte-for-byte match under the expected FNV key for every input. The copy remains inside the first STATE lock on each unique hash. On this workload the parent copied 128 MiB there (512 inputs); the head copies 2.25 MiB (9 inputs) and hashes all 128 MiB outside the mutex. For scale, six alternating paired runs of the optimized native CPU harness (base/head/head/base repeated) took 145.6–158.0 ms on the parent and 17.6–18.6 ms on the head for the worker section. The harness compiled the production capture/dedup/statistics prefix and container parsing, substituted a successful readability gate for owned buffers, and replaced downstream logging/dumping with an in-memory capture sink. This is workload wall time, not a measurement of time blocked inside the lock or end-to-end pipeline creation. It establishes the duplicate-heavy case; all-unique traffic still serializes the copies. OpenAI Codex prepared and ran the synthetic controls and drafted this report.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
xcl-dev/xcl!3295
No description provided.