Skip to content

Commit 32fc887

Browse files
authored
Emit override-redirected functions in deterministic order (#137)
## Problem `Redirector::into_module` topologically sorts functions so dependents are emitted before their callers, but it drives the emission order by iterating a `HashMap`. That order is valid but arbitrary and reseeds every process, so a module that uses a function `override` (the redirector only runs when an override is present) composes to **byte-different output on every run**. This breaks gpu-driver shader caching. ## Fix Use an `IndexMap` so the `retain()` loop visits functions in the deterministic source-arena order; same-level functions then emit in a stable order. Behaviour is otherwise unchanged, this path is only reachable when a function override exists, and `indexmap` is already a dependency.
1 parent 5119786 commit 32fc887

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/redirect.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::collections::{HashMap, HashSet};
1+
use std::collections::HashSet;
22

3+
use indexmap::IndexMap;
34
use naga::{Block, Expression, Function, Handle, Module, Statement};
45
use thiserror::Error;
56

@@ -183,8 +184,9 @@ impl Redirector {
183184
}
184185

185186
pub fn into_module(self) -> Result<naga::Module, RedirectError> {
186-
// reorder functions so that dependents come first
187-
let mut requirements: HashMap<_, _> = self
187+
// reorder functions so that dependents come first. IndexMap (not HashMap)
188+
// so the emission order is deterministic across runs.
189+
let mut requirements: IndexMap<_, _> = self
188190
.module
189191
.functions
190192
.iter()

0 commit comments

Comments
 (0)