Skip to content
Draft
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
33 changes: 30 additions & 3 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3079,15 +3079,23 @@ struct Dummy {
cs: Vec<u8>,
}

/// The stand-in pixel shader. Nothing is drawn with it (its vertex / mesh shader makes no
/// pixels), but its pipeline keeps the title's blend state, and that can be dual-source
/// blending (SRC1 factors on target 0: a retail game's forward transparency passes). A host that
/// builds the pixel stage for the blend state needs both colours then: Apple's Metal shader
/// converter (D3DMetal) refuses a pixel shader that writes SV_Target0 alone ("Failed to compile
/// fragment function", the pipeline a no-op). Hence SV_Target1 too; with the usual blending a
/// second output changes nothing.
const STANDIN_PS: &str = "struct O { float4 c0 : SV_Target0; float4 c1 : SV_Target1; };\nO main() { O o; o.c0 = float4(1, 0, 1, 1); o.c1 = float4(0, 0, 0, 0); return o; }\n";

/// Stand-in mesh shader and pixel shader (DXIL, as mesh pipelines need): one degenerate
/// triangle (DXC wants every output written), nothing drawn.
fn dummy_mesh() -> Option<&'static (Vec<u8>, Vec<u8>)> {
static D: OnceLock<Option<(Vec<u8>, Vec<u8>)>> = OnceLock::new();
D.get_or_init(|| {
use crate::gpu::recomp::dxc::compile;
let ms = "struct V { float4 p : SV_Position; };\n[outputtopology(\"triangle\")]\n[numthreads(1, 1, 1)]\nvoid main(out vertices V v[1], out indices uint3 t[1]) { SetMeshOutputCounts(1, 1); v[0].p = float4(0, 0, 0, 1); t[0] = uint3(0, 0, 0); }\n";
let ps = "float4 main() : SV_Target { return float4(1, 0, 1, 1); }\n";
match (compile(ms, "main", "ms_6_5", &[]), compile(ps, "main", "ps_6_0", &[])) {
match (compile(ms, "main", "ms_6_5", &[]), compile(STANDIN_PS, "main", "ps_6_0", &[])) {
(Ok(m), Ok(p)) => Some((m, p)),
(m, p) => {
crate::xlog_warn!("D3D12.X: stand-in mesh shaders: {:?} {:?}", m.err(), p.err());
Expand Down Expand Up @@ -3127,7 +3135,7 @@ fn dummy() -> &'static Dummy {
static D: OnceLock<Dummy> = OnceLock::new();
D.get_or_init(|| Dummy {
vs: compile("float4 main(uint id : SV_VertexID) : SV_Position { return float4(0, 0, 0, 1); }", "vs_5_0"),
ps: compile("float4 main() : SV_Target { return float4(1, 0, 1, 1); }", "ps_5_0"),
ps: compile(STANDIN_PS, "ps_5_0"),
cs: compile("[numthreads(1, 1, 1)] void main() {}", "cs_5_0"),
})
}
Expand Down Expand Up @@ -5022,6 +5030,25 @@ mod this_first_tests {
}
}

#[cfg(test)]
mod standin_tests {
use super::*;

/// The stand-in pixel shaders write SV_Target0 and SV_Target1: the pair a pipeline with a
/// title's dual-source blend state needs (Metal's shader converter refuses SV_Target0 alone).
#[test]
fn standin_pixel_shaders_write_both_dual_source_colours() {
let targets = |b: &[u8]| -> Vec<u32> {
crate::gpu::dxbc::signatures(b).1.iter().filter(|e| e.name.eq_ignore_ascii_case("SV_Target")).map(|e| e.index).collect()
};
assert_eq!(targets(&dummy().ps), [0, 1], "the DXBC stand-in");
match dummy_mesh() {
Some((_, ps)) => assert_eq!(targets(ps), [0, 1], "the DXIL stand-in of mesh pipelines"),
None => crate::gpu::recomp::runner::skip_test("no DXC"),
}
}
}

#[cfg(test)]
mod cache_report_tests {
use super::*;
Expand Down
Loading