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
31 changes: 25 additions & 6 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ pub fn run(
t.unlisted
);
println!(
"I/O {} of {} vertex and pixel programs raised ({} interpolations, \
"I/O {} of {} vertex, geometry and pixel programs raised ({} interpolations, \
{} vertex values; exports {:?}, {} still f16 pairs)",
t.io_raised, t.io_programs, t.interpolated, t.vertex_values, t.exports, t.compressed
);
println!(
"DXIL {} emitted of {} vertex and pixel programs; {} validated, {} pipelines",
"DXIL {} emitted of {} vertex, geometry and pixel programs; {} validated, {} pipelines",
t.emitted, t.emit_programs, t.validated, t.pipelines
);
println!(
Expand Down Expand Up @@ -508,14 +508,22 @@ fn translate(
};
for p in programs {
t.programs += 1;
match victory_shader::range::build(&p.patched_code(), p.wave64, p.vgprs) {
match p
.translation_code()
.and_then(|code| victory_shader::range::build(&code, p.wave64, p.vgprs))
{
Ok((program, structured)) => {
t.translated += 1;
t.instructions += program.blocks.iter().map(|b| b.insts.len()).sum::<usize>();
// Per-lane descriptors are traced on the per-lane form; its
// failure is listed after the resources' and I/O's.
let lanes = structured.as_ref().ok();
let res = match resource::track(&program, &p.layout, p.stage, lanes) {
let io = io::raise(&program, &p);
let res = match &io {
Ok(io) => resource::track_io(&program, &p.layout, p.stage, lanes, io),
Err(_) => resource::track(&program, &p.layout, p.stage, lanes),
};
let res = match res {
Ok(r) => {
tally_resources(&p, &r, t);
Some(r)
Expand All @@ -531,12 +539,12 @@ fn translate(
None
}
};
let graphics = matches!(p.stage, HwStage::Vs | HwStage::Ps);
let graphics = matches!(p.stage, HwStage::Vs | HwStage::Ps | HwStage::Gs);
let compute = p.stage == HwStage::Cs;
let mut raised = None;
if graphics || compute || p.stage == HwStage::Ms {
t.io_programs += usize::from(graphics);
match io::raise(&program, &p) {
match io {
Ok(r) => {
if graphics {
tally_io(&r, t);
Expand Down Expand Up @@ -620,6 +628,8 @@ fn check(
let made = match shader.stage {
HwStage::Vs => h.pipeline(&shader, stub_ps).map(drop),
HwStage::Cs => h.compute_pipeline(&shader).map(drop),
HwStage::Gs => host::stub_vs(&shader)
.and_then(|vs| h.geometry_pipeline(&vs, &shader, stub_ps).map(drop)),
HwStage::Ms => h.mesh_pipeline(&shader, stub_ps).map(drop),
_ => host::stub_vs(&shader).and_then(|vs| h.pipeline(&vs, &shader).map(drop)),
};
Expand Down Expand Up @@ -703,6 +713,15 @@ fn counter(t: &mut Tally, stage: HwStage, k: usize) -> &mut usize {

fn tally_io(r: &io::Io, t: &mut Tally) {
t.io_raised += 1;
if let Some(gs) = &r.geometry {
for op in gs.messages.values() {
let name = match op {
victory_shader::geometry::StreamOp::Emit(_) => "geometry vertex",
victory_shader::geometry::StreamOp::Cut => "strip cut",
};
*t.exports.entry(name).or_default() += 1;
}
}
for (_, i) in &r.interps {
match i {
io::Interp::Interpolated { .. } => t.interpolated += 1,
Expand Down
14 changes: 4 additions & 10 deletions crates/victory-gpu/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
//! containers are shared by content hash and translated once, on first
//! use (decision 0003).
//!
//! shortcut: only vertex plus pixel pipelines from streams and compute
//! pipelines get host pipelines; mesh, tessellation and geometry stages,
//! and the plain graphics description, keep their containers only. The 32-byte
//! Host graphics streams support vertex, geometry, mesh and pixel stages.
//! Tessellation and the plain graphics description keep their containers only. The 32-byte
//! packet after the header stays zero: titles only copy it inline, which
//! our null command-list limits keep from running.
#![allow(clippy::not_unsafe_ptr_arg_deref)]
Expand Down Expand Up @@ -187,18 +186,13 @@ fn with_resources(
container: &[u8],
host: victory_shader::emit::HostShader,
) -> Result<Translated, String> {
use victory_shader::{Container, FourCC, HwStage};
use victory_shader::{Container, FourCC};
let c = Container::parse(container).map_err(|e| e.to_string())?;
let used = match c.part(FourCC::DXIL).or(c.part(FourCC::ACCC)) {
Some(part) => victory_shader::native_programs(part.data)
.map_err(|e| e.to_string())?
.into_iter()
.find(|p| {
matches!(
p.stage,
HwStage::Vs | HwStage::Ps | HwStage::Ms | HwStage::Cs
)
})
.find(|p| p.stage == host.stage)
.map(|p| p.used)
.unwrap_or_default(),
None => Vec::new(),
Expand Down
59 changes: 41 additions & 18 deletions crates/victory-gpu/src/pipeline/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,18 @@ impl HostPipeline {
if compute.is_none()
&& shaders
.iter()
.any(|s| !matches!(s.stage, "vertex" | "pixel" | "mesh"))
.any(|s| !matches!(s.stage, "vertex" | "pixel" | "geometry" | "mesh"))
{
return refuse(
"only vertex, mesh, pixel and compute stages are translated",
"only vertex, geometry, mesh, pixel and compute stages are translated",
shaders,
);
}
let mesh = find("mesh");
let geometry = find("geometry");
if mesh.is_some() && geometry.is_some() {
return refuse("geometry and mesh stages in one pipeline", shaders);
}
let stages = if let Some(cs) = compute {
vec![(cs, D3D12_SHADER_VISIBILITY_ALL)]
} else {
Expand All @@ -425,6 +429,7 @@ impl HostPipeline {
};
let mut stages = vec![first];
stages.extend(find("pixel").map(|ps| (ps, D3D12_SHADER_VISIBILITY_PIXEL)));
stages.extend(geometry.map(|gs| (gs, D3D12_SHADER_VISIBILITY_GEOMETRY)));
stages
};
if mesh.is_some() && !host()?.mesh_shaders() {
Expand Down Expand Up @@ -688,24 +693,42 @@ impl HostPipeline {
});
}

// Rectangle lists: a geometry shader made for the vertex shader adds
// each rectangle's fourth corner (else rectangles are expanded on
// the CPU from vertex inputs, see `draw`).
let gs = match (g.topology.0, stages.first().and_then(|(s, _)| s.translated())) {
(RECTANGLES, Some(vs)) => match victory_shader::emit::rectangle_gs(&vs.host.dxil) {
Ok(gs) => gs,
Err(e) => {
tracing::warn!(error = %e, ?shaders, "no rectangle geometry shader");
Vec::new()
let pixel = stages
.iter()
.position(|(_, vis)| *vis == D3D12_SHADER_VISIBILITY_PIXEL)
.map_or_else(Default::default, code);
// A translated geometry stage (which does not complete
// rectangles); or, for rectangle lists, a geometry shader made
// for the vertex shader that adds each rectangle's fourth corner
// (else rectangles are expanded on the CPU from vertex inputs,
// see `draw`). Only the made shader completes rectangles.
let (gs, rectangles) =
match (geometry, g.topology.0, stages.first().and_then(|(s, _)| s.translated())) {
(Some(gs), RECTANGLES, _) => {
let _ = gs;
return refuse("a geometry stage drawing rectangle lists", shaders);
}
},
_ => Vec::new(),
};
(Some(gs), _, _) => (
gs.translated()
.map_or_else(Vec::new, |s| s.host.dxil.clone()),
false,
),
(None, RECTANGLES, Some(vs)) => {
match victory_shader::emit::rectangle_gs(&vs.host.dxil) {
Ok(gs) => (gs, true),
Err(e) => {
tracing::warn!(error = %e, ?shaders, "no rectangle geometry shader");
(Vec::new(), false)
}
}
}
_ => (Vec::new(), false),
};
let desc = D3D12_GRAPHICS_PIPELINE_STATE_DESC {
// SAFETY: a borrowed pointer the description never releases.
pRootSignature: unsafe { std::mem::transmute_copy(&root) },
VS: code(0),
PS: code(1),
PS: pixel,
GS: D3D12_SHADER_BYTECODE {
pShaderBytecode: if gs.is_empty() { std::ptr::null() } else { gs.as_ptr().cast() },
BytecodeLength: gs.len(),
Expand All @@ -729,7 +752,7 @@ impl HostPipeline {
let name = super::library::name(
"graphics",
&root_blob,
&[&code_bytes(&code(0)), &code_bytes(&code(1)), &gs],
&[&code_bytes(&code(0)), &code_bytes(&pixel), &gs],
&state,
);
let started = std::time::Instant::now();
Expand Down Expand Up @@ -765,7 +788,7 @@ impl HostPipeline {
return None;
}
};
tracing::info!(?shaders, ms = started.elapsed().as_millis(), rectangles = !gs.is_empty(), "host pipeline");
tracing::info!(?shaders, ms = started.elapsed().as_millis(), rectangles, "host pipeline");
crate::host::name(&pso, || format!("{shaders:?}"));
tracing::debug!(
?shaders,
Expand All @@ -783,7 +806,7 @@ impl HostPipeline {
root,
stages: bound,
name: format!("{shaders:?}"),
rectangles: !gs.is_empty(),
rectangles,
slots: g.slots(),
inputs: g.elements(),
marks,
Expand Down
2 changes: 1 addition & 1 deletion crates/victory-shader/src/emit/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub(crate) struct Binding {
}

pub(crate) struct Psv<'a> {
/// PSV shader kind: 0 pixel, 1 vertex, 5 compute.
/// PSV shader kind: 0 pixel, 1 vertex, 2 geometry, 5 compute, 13 mesh.
pub stage: u8,
/// Vertex: writes `SV_Position`. Pixel: writes depth.
pub flag: bool,
Expand Down
Loading