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
19 changes: 17 additions & 2 deletions crates/xcl/src/gpu/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,27 @@ pub fn scan(d: &[u8], from: usize) -> Vec<Record> {
out
}

/// Inflate a raw deflate slice to `expected` bytes. `None` when the stream is not valid deflate.
pub fn inflate_slice(compressed: &[u8], expected: usize) -> Option<Vec<u8>> {
let unpacked = miniz_oxide::inflate::decompress_to_vec_with_limit(compressed, expected).ok()?;
(unpacked.len() == expected).then_some(unpacked)
}

/// Inflate a record. `None` when the stream is not valid deflate.
pub fn inflate(d: &[u8], r: &Record) -> Option<Vec<u8>> {
let end = r.data.checked_add(r.csize)?;
let compressed = d.get(r.data..end)?;
let unpacked = miniz_oxide::inflate::decompress_to_vec_with_limit(compressed, r.usize).ok()?;
(unpacked.len() == r.usize).then_some(unpacked)
inflate_slice(compressed, r.usize)
}

/// Stage prefix of a shader name (`PS_Foo` → `PS`, `effect:CS_Foo` → `CS`).
/// Requires an explicit `_` separator and non-empty suffix so names like `Asset01` do not collide
/// with `AS`.
pub fn name_stage(name: &str) -> Option<&'static str> {
let base = name.rsplit(':').next()?;
if base.as_bytes().get(2) != Some(&b'_') || base.len() <= 3 {
return None;
}
let up = base.get(..2)?.to_ascii_uppercase();
["PS", "VS", "MS", "GS", "CS", "HS", "DS", "AS"].into_iter().find(|s| *s == up)
}
Expand Down Expand Up @@ -129,6 +139,11 @@ mod tests {
assert_eq!(recs[0].flag, 50);
assert_eq!(name_stage(&recs[0].name), Some("PS"));
assert_eq!(name_stage("ptfx_x"), None);
assert_eq!(name_stage("Asset01"), None);
assert_eq!(name_stage("asset_pixel"), None);
assert_eq!(name_stage("CS_"), None);
assert_eq!(name_stage("fx:cs_Test"), Some("CS"));
assert_eq!(name_stage("CS_Test"), Some("CS"));
}

/// An effect-qualified name is one record under its full name, also when the `:` byte
Expand Down
10 changes: 10 additions & 0 deletions crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,16 @@ fn console_mesh_with(
finish_two_pass_compiled(cs, record, ps)
}

/// The mesh-shader (NGG) program of a console MS container for explicit `windows` (used by
/// offline / startup precompilation to populate the exact same `translated/v2` and DXIL caches
/// as `console_mesh`).
pub fn console_mesh_in(blob: &[u8], split_wave64: bool, windows: u32) -> Result<TwoPass, String> {
let dir = dxc::cache_dir();
console_mesh_with(blob, None, split_wave64, windows, &dir, shader_cache(), |code, rodata, ms, wave64| {
compile_console_mesh(blob, code, rodata, ms, wave64, windows, split_wave64)
})
}

/// The mesh-shader (NGG) program of a console MS container; the pass-through carries what
/// the pixel shader `ps` (its container: console or PC) reads.
pub fn console_mesh(blob: &[u8], ps: Option<&[u8]>, split_wave64: bool) -> Result<TwoPass, String> {
Expand Down
Loading
Loading