Skip to content
Merged
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
17 changes: 17 additions & 0 deletions crates/victory-gpu/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ pub(crate) struct Translated {
pub(crate) picks: std::sync::atomic::AtomicU8,
}

impl Shader {
/// Whether the raw shader container contains `needle` (used to match
/// embedded shader names across permutations).
pub(super) fn container_has(&self, needle: &[u8]) -> bool {
!needle.is_empty() && self.container.windows(needle.len()).any(|w| w == needle)
}

/// Whether this shader is a ped texture compositor / decoration bake stage.
#[cfg(windows)]
pub(super) fn is_bake(&self) -> bool {
let h = self.hash.as_str();
crate::draw::BAKE_PIXEL_SHADERS.contains(&h)
|| crate::draw::BAKE_GEOMETRY_SHADERS.contains(&h)
|| self.container_has(b"BakeDecorations")
}
}

#[cfg(windows)]
impl Shader {
/// The translation, made on first use; a shader that does not
Expand Down
15 changes: 3 additions & 12 deletions crates/victory-gpu/src/pipeline/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,7 @@ impl HostPipeline {
};
tracing::info!(?shaders, "host pipeline");
crate::host::name(&pso, || format!("{shaders:?}"));
let is_bake_shader = bound.iter().any(|s| {
let h = s.shader.hash.as_str();
crate::draw::BAKE_PIXEL_SHADERS.contains(&h) || crate::draw::BAKE_GEOMETRY_SHADERS.contains(&h)
});
let is_bake_shader = bound.iter().any(|s| s.shader.is_bake());
return Some(HostPipeline {
compute: true,
mesh: false,
Expand Down Expand Up @@ -694,10 +691,7 @@ impl HostPipeline {
};
tracing::info!(?shaders, "host mesh pipeline");
crate::host::name(&pso, || format!("{shaders:?}"));
let is_bake_shader = bound.iter().any(|s| {
let h = s.shader.hash.as_str();
crate::draw::BAKE_PIXEL_SHADERS.contains(&h) || crate::draw::BAKE_GEOMETRY_SHADERS.contains(&h)
});
let is_bake_shader = bound.iter().any(|s| s.shader.is_bake());
return Some(HostPipeline {
compute: false,
mesh: true,
Expand Down Expand Up @@ -815,10 +809,7 @@ impl HostPipeline {
cull = g.rasterizer.CullMode.0,
"host graphics state"
);
let is_bake_shader = bound.iter().any(|s| {
let h = s.shader.hash.as_str();
crate::draw::BAKE_PIXEL_SHADERS.contains(&h) || crate::draw::BAKE_GEOMETRY_SHADERS.contains(&h)
});
let is_bake_shader = bound.iter().any(|s| s.shader.is_bake());
Some(HostPipeline {
compute: false,
mesh: false,
Expand Down
64 changes: 60 additions & 4 deletions crates/victory-gpu/src/pipeline/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) struct Pending {
fn named(shaders: &[Arc<Shader>], name: &[u8]) -> bool {
shaders
.iter()
.any(|s| s.stage == "compute" && s.container.windows(name.len()).any(|w| w == name))
.any(|s| s.stage == "compute" && s.container_has(name))
}

fn left_out(shaders: &[Arc<Shader>]) -> Option<&'static str> {
Expand Down Expand Up @@ -87,9 +87,26 @@ fn left_out(shaders: &[Arc<Shader>]) -> Option<&'static str> {
None
}

/// Confirmed first-scene producers. Prepare these at creation even on a cold
/// launch so cutscene lighting, tiling, and bakes never miss their first frame.
/// Confirmed first-scene producers (ped head blendshapes/stretch, neural
/// facial compute-graph ops, ped skinning, visibility, tiling, and decoration
/// bake pixel shaders). Prepare these at creation and prioritize them on the
/// screen workers so character faces/heads and opening-scene lighting never
/// miss their first frame behind cold world shaders.
fn scene_input(shaders: &[Arc<Shader>]) -> bool {
const COMPUTE_PRODUCERS: [&[u8]; 12] = [
b"CS_ComputeBlendshapeMappings",
b"CS_BlendshapeTranslations",
b"CS_ReconstructBlendshapeNormals",
b"CS_ComputeStickyLips",
b"CS_ResetStretch",
b"CS_AccumStretch",
b"CS_FinalizeStretch",
b"CS_PedStandardSkinning_",
b"CS_PosOnlyLodSkinning",
b"CS_GenWorldAabbs",
b"Operation_",
b"Technique_",
];
shaders.iter().any(|s| {
matches!(
s.hash.as_str(),
Expand All @@ -100,6 +117,8 @@ fn scene_input(shaders: &[Arc<Shader>]) -> bool {
| "2cc4c197ee29e291"
| "369cbe906ea72764"
) || crate::draw::BAKE_PIXEL_SHADERS.contains(&s.hash.as_str())
|| (s.stage == "compute"
&& COMPUTE_PRODUCERS.iter().any(|name| s.container_has(name)))
})
}

Expand All @@ -118,9 +137,11 @@ impl Pending {
}
key.update(graphics.as_ref().map(|g| g.describe()).unwrap_or_default().as_bytes());
let scene_input = scene_input(&shaders);
let bake_mesh = shaders.iter().any(|s| s.container_has(b"BakeDecorations"));
let screen = (graphics.as_ref().is_some_and(|g| g.screen_pass())
&& shaders.iter().all(|s| s.stage != "mesh"))
|| scene_input;
|| scene_input
|| bake_mesh;
let left_out = left_out(&shaders);
Pending {
screen,
Expand Down Expand Up @@ -663,4 +684,39 @@ mod tests {
assert!(queue.pop(true, 1).is_none());
assert!(Arc::ptr_eq(&queue.pop(false, 1).unwrap(), &world));
}

#[test]
fn ped_head_skinning_and_graph_compute_shaders_are_scene_inputs() {
for name in [
b"CS_ComputeBlendshapeMappings_54139280".as_slice(),
b"CS_PedStandardSkinning_0_15f19d85",
b"CS_PosOnlyLodSkinning_f1f31b8d",
b"CS_ResetStretch_8009c8e4",
b"CS_MatMulAlignedOperation_5ccdaacf",
b"CS_ReduceSumTechnique_da205a95",
] {
let s = super::super::shader("compute", name);
let p = Pending::new(vec![s], None);
assert!(p.scene_input, "expected scene_input for {}", String::from_utf8_lossy(name));
assert!(p.screen, "expected screen priority for {}", String::from_utf8_lossy(name));
}

let world_cs = super::super::shader("compute", b"CS_SomeWorldPass");
let world_p = Pending::new(vec![world_cs], None);
assert!(!world_p.scene_input);
assert!(!world_p.screen);

let non_cs = super::super::shader("pixel", b"PS_Operation_Test");
let non_cs_p = Pending::new(vec![non_cs], None);
assert!(!non_cs_p.scene_input);
}

#[test]
fn bake_decorations_mesh_gets_screen_priority_and_is_bake() {
let bake_ms = super::super::shader("mesh", b"MSNC_VS_BakeDecorations_test");
assert!(bake_ms.is_bake());
let p = Pending::new(vec![bake_ms], None);
assert!(!p.scene_input);
assert!(p.screen);
}
}
Loading