Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions crates/victory-shader/src/emit/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ impl SigElement {
}
}

/// The console packs elements of different interpolation modes into one
/// row (a constant front face beside a linear coordinate, say); DXIL needs
/// one mode per row. Each later mode of a row moves to a free row of its
/// own, shared by that row's elements of the mode. Code addresses elements
/// by id and stages link by semantic, so only the signatures change.
/// Elements without a mode (0) are left where they are.
pub(crate) fn separate_interpolation(elements: &mut [SigElement]) {
let mut next = elements
.iter()
.filter_map(|e| e.row)
.max()
.map_or(0, |r| r + 1);
// (row, the row's first mode)
let mut first: Vec<(u32, u8)> = Vec::new();
// ((old row, mode), new row)
let mut moved: Vec<((u32, u8), u32)> = Vec::new();
for e in elements.iter_mut() {
let (Some(row), mode) = (e.row, e.interp) else {
continue;
};
if mode == 0 {
continue;
}
match first.iter().find(|f| f.0 == row) {
None => first.push((row, mode)),
Some(&(_, m)) if m == mode => {}
Some(_) => {
let to = match moved.iter().find(|m| m.0 == (row, mode)) {
Some(&(_, to)) => to,
None => {
moved.push(((row, mode), next));
next += 1;
next - 1
}
};
e.row = Some(to);
}
}
}
}

/// `ISG1`/`OSG1`: 32-byte rows, then the names.
pub(crate) fn signature(elements: &[SigElement], input: bool) -> Vec<u8> {
let mut out = Vec::new();
Expand Down Expand Up @@ -377,4 +418,35 @@ mod tests {
.collect();
assert_eq!(hex, "900150983cd24fb0d6963f7d28e17f72");
}

fn element(name: &str, row: u32, col: u8, interp: u8) -> SigElement {
SigElement {
name: name.into(),
index: 0,
kind: 0,
comp: 9,
interp,
row: Some(row),
col,
cols: 1,
usage: 1,
half: false,
}
}

#[test]
fn rows_of_mixed_interpolation_are_separated() {
let mut e = vec![
element("A", 0, 0, 2),
element("B", 0, 1, 1),
element("C", 1, 0, 2),
element("D", 0, 2, 1),
element("E", 0, 3, 2),
element("F", 1, 1, 0),
];
separate_interpolation(&mut e);
let rows: Vec<u32> = e.iter().map(|e| e.row.unwrap()).collect();
// B and D (constant) share a new row; A and E stay; F has no mode.
assert_eq!(rows, [0, 2, 1, 2, 0, 1]);
}
}
2 changes: 2 additions & 0 deletions crates/victory-shader/src/emit/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ impl Shader {
pub fn finish(mut self) -> Vec<u8> {
let ud_size = (self.user_data * 4).next_multiple_of(16);
self.fix_user_data_size(ud_size);
container::separate_interpolation(&mut self.inputs);
container::separate_interpolation(&mut self.outputs);
let mut resources = None;
let mut bindings = Vec::new();
let i32c = |s: &mut Self, v: u32| {
Expand Down