Repository navigation
shader/emit: cache immediate sampler handles in entry block (D3D12-SHADER-SAMPLER-HANDLE-CACHE) - #2862
shader/emit: cache immediate sampler handles in entry block (D3D12-SHADER-SAMPLER-HANDLE-CACHE)#2862djrolfes wants to merge 1 commit into
Conversation
|
Independent Rust check of I ran the full native AI-assisted with OpenAI Codex. |
KelboLive
left a comment
There was a problem hiding this comment.
The hoist is sound: only immediate (Source::Constant) samplers reach this helper, bound as root-signature static samplers, so the binding is uniform and valid at entry, and entry dominates every block. Loop and branch-chosen cases behave (same slot dedups; distinct slots get their own handles and a uniform phi picks one). 406/0/5 here.
Three things:
cmpin the key is redundant.register_sampleralready gives a distinct slot per(descriptor words, cmp)and sets the bit before returning it, so the slot alone identifies the sampler — droppingcmpchanges nothing and all sampler tests still pass. Either drop it or say in the comment that the cache relies on that slot↔descriptor invariant._blockis now dead (four call sites still passself.cur/arm). Remove the parameter so nobody reintroduces "create in the use block" by mistake.- The new test does not test placement. Replacing
let block = self.entrywithlet block = _blockleaves the whole 406-test suite green, even though a handle created in one branch and reused in a sibling is a dominance violation — the test is named…emitted_once_in_entry…but never inspects the block and never uses the handle. Either assert the instruction lives inentry(a smallModuleaccessor) or drive a realsampleLevelfrom two sibling blocks and validate withdxil.dll, aswaterfall_tests::immediate_sampler_chosen_by_control_flowalready does.
Also: assert_ne!(h0_a, h1_a) passes even with the cache keyed by cmp alone (slot 0 non-cmp vs slot 1 cmp); two samplers of the same kind would pin the slot field.
|
RUN (native Windows 10 + RTX 5070 verification; #2857, #2860, and #2862 merged cleanly together onto
GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver AI-assisted: Antigravity |
VERIFY-2862 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS. The change does what it says, and it also closes a debug-build panic that the pull request does not mention. Head 1. What it changes
// main
pub fn sampler_handle(&mut self, block: usize, n: u32) -> V {
…
let h = self.op(block, "createHandleFromBinding", …);
…
}The pull request emits one handle per pub fn sampler_handle(&mut self, _block: usize, n: u32) -> V {
let is_cmp = n < u64::BITS && self.cmp_samplers >> n & 1 != 0;
if let Some(&(_, _, h)) = self.sampler_handles.iter().find(|&&(slot, c, _)| slot == n && c == is_cmp) {
return h;
}
…
let block = self.entry;
let h = self.op(block, "createHandleFromBinding", …);
…
self.sampler_handles.push((n, is_cmp, h));
h
}The callers pass the block they are in — 2. Red and green, and the discrimination
With only the cache lookup removed (the pull request's test kept): 3. The panic this also fixesThe new code guards the comparison-sampler bit with // main
let cmp = if self.cmp_samplers >> n & 1 != 0 { 0x8000 } else { 0 };
This is the same family as #2858 (an unchecked arithmetic operation on a value the title controls, reaching a panic), and it is not mentioned in the pull request's own text. Whether 4. What the new test does not checkThe test is called The placement is unambiguous in the code ( 5. What I did not check
AI-assisted: MiniMax M3.1 Flash. |
Claimed in the coordination issue as:
D3D12-SHADER-SAMPLER-HANDLE-CACHE(claim comment)What and why
Cache immediate sampler handles (
createHandleFromBinding+annotateHandle) once inself.entryinsideShader::sampler_handle(d3d12/crates/leonida-shader/src/emit/shader.rs), bringing it into parity withroot_cbv_handle,root_srv_handle, androot_uav_handle.main,root_cbv_handle,root_srv_handle, androot_uav_handlealready emit their binding handle once inself.entryand cache it, whereassampler_handleemitted a freshcreateHandleFromBinding+annotateHandlepair at every call site in every basic block.sampler_handles: Vec<(u32, bool, V)>keyed by(slot, is_cmp)(withn < u64::BITSguard before shiftingself.cmp_samplers), emits the handle pair inself.entry(which dominates all blocks), and returns the cached handle on subsequent calls. Completely orthogonal to open PR#2687(which hoistscreateHandleFromHeap, notcreateHandleFromBinding).d3d12/crates/leonida-shader/src/emit/shader.rs:526–625) + red→green unit test verifying handle reuse across sibling branches and valid DXIL serialization + MEASURED 300 s in-game gate (2 consecutive 310 s PASS runs) on exact PR headacae5b879.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/shader.rs→ exit 0.cargo test --locked -p leonida-shader:origin/main(only the new#[cfg(test)]module applied, no production change):acae5b879(rebased ontocd73ddab7):docs/game_gate.md) on exact PR headacae5b879(leonida.exe--profile play --features mimalloc,dlss,diagnostics, Series S + DLSS Quality 1280×720 → 1920×1080):1,155 → 422in the background during Pass 2, accounting for the lower transient median FPS compared to fully-cached non-DXIL-changing builds)310.14 s(world_at_s = 79.39 s,>= 300 srequired)world + 60 sto stop):719presented frames (759total world presents),7.22median FPS (9.00end-window median FPS as background PSO compilation drained),1,674.72 msp95 frame time (4,445.5median draws/frame)5.127 s(<= 10.0 srequired)6,299 MiB(<= 7,400 MiBguard)0device losses,0crashes/faults,0panics,0kernelNVRM: Xiderrors311.00 sin-world,386frames,5.21median FPS,8.672 slongest present gap,6,043 MiBpeak VRAM,0device losses/crashes/faults/panics/Xids)GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (authored by Gemini 4 Neon; audited and approved in a separate independent review pass by Gemini 4 Neon).
Checklist
main(cd73ddab7) and merges cleanly.check_no_game_data.pyclean).docs/design.md(n/a — entry-block handle caching matching existing root handle helpers).acae5b879).