From f03fe38b72e5356d2db4b5e7857b48e9005cba88 Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:09:40 -0500 Subject: [PATCH] Rect lists: the GS carries flat outputs, v0 the provoking vertex The rect list GS was refused for a VS with integer outputs and for a PS that reads flat, because which vertex of a rect gives a flat value was not established. Those pipelines fell back to the CPU expansion, which only handles DrawInstanced with vertex buffers: their indexed draws, and vertices made from the vertex index alone, drew half of each rect. AMD's register references (R6xx, SI, CIK) define PA_SU_SC_MODE_CNTL.PROVOKING_VTX_LAST for every primitive: "Defines which vertex of a primitive is used for attribute components when flat shading is enabled", 0 = First Vtx (D3D), 1 = Last Vtx (OGL). The Evergreen / Cayman programming guide (5.2) has a flat attribute as the provoking vertex's value with gradients of 0. Mesa sets the bit from state alone, with no exception for rect lists. So under D3D's setting a rect's flat value is its first vertex's. This is not measured on a rect. The GS now emits both triangles starting with v[0] (the halves along the diagonal through v0, in the winding of v0 v1 v2), so every flat input takes v0's value in both, and the fourth vertex's integer outputs are v[0]'s. Smooth outputs are as before: the same plane on either diagonal. pso::ps_reads_flat and reads_flat had no other use and are removed. runner::draw_gs_indexed draws an indexed triangle list for the test. Assisted-by: Claude Code (Claude Fable 5.2) Co-Authored-By: Claude --- crates/xcl/src/gpu/recomp/emit.rs | 61 +++++++++++-------- crates/xcl/src/gpu/recomp/pso.rs | 31 +--------- crates/xcl/src/gpu/recomp/runner.rs | 60 +++++++++++++++++-- crates/xcl/src/gpu/recomp/tests.rs | 90 ++++++++++++++++++++++------- crates/xcl/src/hle/d3d12x/real.rs | 11 +--- 5 files changed, 165 insertions(+), 88 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 5a63c3c2b..1d5ef0139 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4557,40 +4557,53 @@ fn out_struct(h: &mut String, name: &str, outputs: &[SigElement]) { /// two is not always the same vertex: Mesa's radeonsi blits send (x1,y1), (x1,y2), (x2,y1) – v0 /// – and xf86-video-ati's r600 EXA (x1,y1), (x1,y2), (x2,y2) – v1. The corner is the vertex /// sharing x with one of the others and y with the other; the fourth vertex is the opposite -/// corner, a + b - corner, with every output taken the same way (both drivers' texture +/// corner, a + b - corner, with every float output taken the same way (both drivers' texture /// coordinates rely on the implied corner continuing them linearly). Only for three vertices /// with one positive w – then a + b - corner is the same in clip and screen space and every /// interpolation mode agrees; three that are not such corners, or differ in w, stay the one -/// triangle they make. Refused (Err): integer outputs, which are flat – which vertex of a rect -/// gives a flat value is not established, so neither is how the two halves would carry it -/// (the PS side: `pso::ps_reads_flat`). -pub fn rect_list_gs(outputs: &[SigElement]) -> Result { - if let Some(e) = ranked(outputs, true).iter().find(|e| hlsl_type(e) != "float") { - return Err(format!("{} is an integer output (flat)", e.semantic())); - } +/// triangle they make. +/// +/// Flat values are the rect's first vertex's: both triangles start with v[0], which is where +/// the PC takes a flat input from (an integer input, or what the translation declares +/// `nointerpolation` for `v_interp_mov_f32`), and the fourth vertex's integer outputs are +/// v[0]'s. On the console the first vertex is the provoking one of every primitive under +/// D3D's setting – AMD's register references (R6xx, SI, CIK), PA_SU_SC_MODE_CNTL +/// .PROVOKING_VTX_LAST: "Defines which vertex of a primitive is used for attribute components +/// when flat shading is enabled", "0 = First Vtx (D3D)"; the Evergreen / Cayman programming +/// guide, 5.2: a flat attribute is the provoking vertex's value with gradients of 0. Neither +/// says so of a rect in particular, and it is not measured on one. +pub fn rect_list_gs(outputs: &[SigElement]) -> String { let mut h = String::new(); h.push_str("// generated by XCL: a console rect list's rectangles (three corners, the fourth implied)\n"); out_struct(&mut h, "XclOut", outputs); h.push_str("[maxvertexcount(6)]\nvoid main(triangle XclOut v[3], inout TriangleStream s)\n{\n"); - h.push_str(" s.Append(v[0]);\n s.Append(v[1]);\n s.Append(v[2]);\n"); - h.push_str(" if (!(v[0].pos.w > 0.0 && v[1].pos.w == v[0].pos.w && v[2].pos.w == v[0].pos.w))\n return;\n"); + // the corner c: x shared with a and y with b, or the other way round (a = c + 1, b = c + 2); // one w: clip-space x and y compare as the screen's do - h.push_str(" float2 q[3] = { v[0].pos.xy, v[1].pos.xy, v[2].pos.xy };\n"); - // the corner c: x shared with a and y with b, or the other way round (a = c + 1, b = c + 2) - h.push_str(" uint c = 3u;\n [unroll] for (uint i = 0u; i < 3u; i++) {\n"); - h.push_str(" float2 p = q[i], a = q[(i + 1u) % 3u], b = q[(i + 2u) % 3u];\n"); - h.push_str(" bool corner = (p.x == a.x && p.y == b.y) || (p.x == b.x && p.y == a.y);\n"); - h.push_str(" bool degenerate = all(p == a) || all(p == b) || all(a == b);\n"); - h.push_str(" if (c == 3u && corner && !degenerate)\n c = i;\n }\n"); - h.push_str(" if (c == 3u)\n return;\n"); - h.push_str(" XclOut k = v[c], a = v[(c + 1u) % 3u], b = v[(c + 2u) % 3u];\n XclOut d = a;\n"); + h.push_str(" uint c = 3u;\n"); + h.push_str(" if (v[0].pos.w > 0.0 && v[1].pos.w == v[0].pos.w && v[2].pos.w == v[0].pos.w) {\n"); + h.push_str(" float2 q[3] = { v[0].pos.xy, v[1].pos.xy, v[2].pos.xy };\n"); + h.push_str(" [unroll] for (uint i = 0u; i < 3u; i++) {\n"); + h.push_str(" float2 p = q[i], a = q[(i + 1u) % 3u], b = q[(i + 2u) % 3u];\n"); + h.push_str(" bool corner = (p.x == a.x && p.y == b.y) || (p.x == b.x && p.y == a.y);\n"); + h.push_str(" bool degenerate = all(p == a) || all(p == b) || all(a == b);\n"); + h.push_str(" if (c == 3u && corner && !degenerate)\n c = i;\n }\n }\n"); + h.push_str(" if (c == 3u) {\n s.Append(v[0]);\n s.Append(v[1]);\n s.Append(v[2]);\n return;\n }\n"); + h.push_str(" XclOut k = v[c], a = v[(c + 1u) % 3u], b = v[(c + 2u) % 3u];\n XclOut d = v[0];\n"); h.push_str(" d.pos = a.pos + b.pos - k.pos;\n"); - for k in 0..ranked(outputs, true).len() { - let _ = writeln!(h, " d.p{k} = a.p{k} + b.p{k} - k.p{k};"); + for (k, e) in ranked(outputs, true).iter().enumerate() { + if hlsl_type(e) == "float" { + let _ = writeln!(h, " d.p{k} = a.p{k} + b.p{k} - k.p{k};"); + } } - // (c, a, b) is the first triangle's winding; (a, d, b) – its point reflection – keeps it - h.push_str(" s.RestartStrip();\n s.Append(a);\n s.Append(d);\n s.Append(b);\n}\n"); - Ok(h) + // (corner, a, b) is v0 v1 v2 in its order or rotated; (corner, a, d), (corner, d, b) and + // (a, d, b) wind as it does. Of those, the two halves that both hold v0, v0 first: + // v0 v1 d, v0 d v2 (corner v0) – v0 v1 v2, v0 v2 d (v1) – v0 v1 v2, v0 d v1 (v2) + h.push_str(" s.Append(v[0]);\n s.Append(v[1]);\n"); + h.push_str(" if (c == 0u)\n s.Append(d);\n else\n s.Append(v[2]);\n"); + h.push_str(" s.RestartStrip();\n s.Append(v[0]);\n"); + h.push_str(" if (c == 1u) {\n s.Append(v[2]);\n s.Append(d);\n } else {\n s.Append(d);\n"); + h.push_str(" if (c == 0u)\n s.Append(v[2]);\n else\n s.Append(v[1]);\n }\n}\n"); + h } /// Second pass of the mesh mode: a mesh shader that turns the records written by the diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index 68c7b099c..99a30940c 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -589,36 +589,7 @@ pub fn rect_list_gs(vs: &[u8]) -> Result, String> { if outputs.is_empty() { return Err("the VS has no output signature".into()); } - Ok(dxc::compile_cached(&super::emit::rect_list_gs(&outputs)?, "main", "gs_6_6")?.0) -} - -/// Whether the console PS `ps` (its container) reads an attribute flat: an integer input, or a -/// `v_interp_mov_f32` – what the translation declares `nointerpolation` (`emit`, `XclIn`). A rect -/// list's flat values are not carried by `rect_list_gs` (see there). -pub fn ps_reads_flat(ps: &[u8]) -> Result { - let sh = xbox::parse(ps).ok_or("not a console shader container")?; - let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 5)).ok_or("no PS hardware variant")?; - let Some(Mode::Pixel(psi)) = interface(ps, &sh, f) else { - return Err("unknown PS interface".into()); - }; - if super::ranked(&psi.inputs, false).iter().any(|e| e.component_type != 3) { - return Ok(true); - } - let p = f.programs.first().ok_or("FSSM without a program")?; - reads_flat(&f.data[p.offset..p.offset + p.len]) -} - -/// Whether PS code has a `v_interp_mov_f32`. -pub fn reads_flat(code: &[u8]) -> Result { - let mut off = 0usize; - while off + 4 <= code.len() { - let d = crate::gpu::rdna2::decode(&code[off..], off as u64).map_err(|e| format!("+{off:#x}: cannot decode ({e:?})"))?; - if d.inst.name.eq_ignore_ascii_case("v_interp_mov_f32") { - return Ok(true); - } - off += d.len; - } - Ok(false) + Ok(dxc::compile_cached(&super::emit::rect_list_gs(&outputs), "main", "gs_6_6")?.0) } /// XCL shader ABI root signature (see the module docs); `graphics` allows an input layout. diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs index 33c45e864..c7f9cc42f 100644 --- a/crates/xcl/src/gpu/recomp/runner.rs +++ b/crates/xcl/src/gpu/recomp/runner.rs @@ -648,7 +648,23 @@ pub fn draw_gs( size: u32, clear: [f32; 4], ) -> Result, String> { - draw_gs_views(vs, gs, ps, layout, vertices, stride, sgprs, mem, &[], &[], size, clear) + draw_gs_views(vs, gs, ps, layout, vertices, stride, &[], sgprs, mem, &[], &[], size, clear) +} + +/// `draw_gs` of an indexed triangle list (`indices`). +#[allow(clippy::too_many_arguments)] +pub fn draw_gs_indexed( + vs: &[u8], + gs: Option<&[u8]>, + ps: &[u8], + layout: &[VertexElement], + vertices: &[f32], + stride: u32, + indices: &[u32], + size: u32, + clear: [f32; 4], +) -> Result, String> { + draw_gs_views(vs, gs, ps, layout, vertices, stride, indices, &[], &[], &[], &[], size, clear) } /// `draw` with textures and samplers in the directly indexed heaps (see `ViewTexture`). @@ -666,7 +682,7 @@ pub fn draw_views( size: u32, clear: [f32; 4], ) -> Result, String> { - draw_gs_views(vs, None, ps, layout, vertices, stride, sgprs, mem, textures, samplers, size, clear) + draw_gs_views(vs, None, ps, layout, vertices, stride, &[], sgprs, mem, textures, samplers, size, clear) } #[allow(clippy::too_many_arguments)] @@ -677,6 +693,7 @@ fn draw_gs_views( layout: &[VertexElement], vertices: &[f32], stride: u32, + indices: &[u32], sgprs: &[u32], mem: &[u32], textures: &[ViewTexture], @@ -722,7 +739,7 @@ fn draw_gs_views( pd.RTVFormats[0] = DXGI_FORMAT_R32G32B32A32_FLOAT; let pso: ID3D12PipelineState = dev.CreateGraphicsPipelineState(&pd).map_err(|x| format!("CreateGraphicsPipelineState: {x}"))?; let draw = Draw { sgprs: sgprs.to_vec(), scissor: [0, 0, size as i32, size as i32] }; - draw_on_multi(dev, &pso, &rs, vertices, stride, &[draw], mem, textures, samplers, size, clear) + draw_indexed_on(dev, &pso, &rs, vertices, stride, indices, &[draw], mem, textures, samplers, size, clear) } } @@ -842,6 +859,25 @@ pub fn draw_on_multi( samplers: &[D3D12_SAMPLER_DESC], size: u32, clear: [f32; 4], +) -> Result, String> { + draw_indexed_on(dev, pso, rs, vertices, stride, &[], draws, mem, textures, samplers, size, clear) +} + +/// `draw_on_multi`, the draws indexed when there are `indices` (one index buffer for all). +#[allow(clippy::too_many_arguments)] +fn draw_indexed_on( + dev: &ID3D12Device, + pso: &ID3D12PipelineState, + rs: &ID3D12RootSignature, + vertices: &[f32], + stride: u32, + indices: &[u32], + draws: &[Draw], + mem: &[u32], + textures: &[ViewTexture], + samplers: &[D3D12_SAMPLER_DESC], + size: u32, + clear: [f32; 4], ) -> Result, String> { unsafe { let queue: ID3D12CommandQueue = @@ -928,11 +964,27 @@ pub fn draw_on_multi( list.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); let vbv = D3D12_VERTEX_BUFFER_VIEW { BufferLocation: upload.GetGPUVirtualAddress(), SizeInBytes: vb_bytes as u32, StrideInBytes: stride }; list.IASetVertexBuffers(0, Some(&[vbv])); + let _index_buf = if indices.is_empty() { + None + } else { + let bytes = (indices.len() * 4) as u64; + let b = buffer(dev, bytes, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ, false)?; + let mut p = std::ptr::null_mut(); + b.Map(0, None, Some(&mut p)).map_err(e)?; + std::ptr::copy_nonoverlapping(indices.as_ptr(), p as *mut u32, indices.len()); + b.Unmap(0, None); + list.IASetIndexBuffer(Some(&D3D12_INDEX_BUFFER_VIEW { BufferLocation: b.GetGPUVirtualAddress(), SizeInBytes: bytes as u32, Format: DXGI_FORMAT_R32_UINT })); + Some(b) + }; for (k, d) in draws.iter().enumerate() { list.SetGraphicsRootUnorderedAccessView(0, io_buf.GetGPUVirtualAddress() + (k * KERNEL_SGPRS * 4) as u64); let [left, top, right, bottom] = d.scissor; list.RSSetScissorRects(&[windows::Win32::Foundation::RECT { left, top, right, bottom }]); - list.DrawInstanced((vertices.len() as u32 * 4) / stride, 1, 0, 0); + if indices.is_empty() { + list.DrawInstanced((vertices.len() as u32 * 4) / stride, 1, 0, 0); + } else { + list.DrawIndexedInstanced(indices.len() as u32, 1, 0, 0, 0); + } } list.ResourceBarrier(&[transition(&rt, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE)]); let dst = D3D12_TEXTURE_COPY_LOCATION { diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 37f443b40..596a74198 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -1641,33 +1641,19 @@ fn gpu_graphics_vs_ps_draw() { } } -/// `emit::rect_list_gs` refuses integer (flat) outputs and declares the VS's output struct. +/// `emit::rect_list_gs` declares the VS's output struct; the fourth vertex is v[0] with its +/// float outputs continued from the other three, its integer (flat) ones left as v[0]'s. #[test] fn rect_list_gs_outputs() { - let float = [el("SV_Position", 0, 1, 3, 0, 0xF), el("TEXCOORD", 0, 0, 3, 1, 0xF), el("SV_ClipDistance", 0, 2, 3, 2, 1)]; - let h = super::emit::rect_list_gs(&float).unwrap(); - assert!(h.contains("triangle XclOut v[3]") && h.contains("d.p0 = a.p0 + b.p0 - k.p0;") && h.contains("d.p1 = a.p1 + b.p1 - k.p1;"), "{h}"); - let flat = [el("SV_Position", 0, 1, 3, 0, 0xF), el("TEXCOORD", 0, 0, 1, 1, 0xF)]; - assert!(super::emit::rect_list_gs(&flat).unwrap_err().contains("TEXCOORD0")); + let outputs = [el("SV_Position", 0, 1, 3, 0, 0xF), el("TEXCOORD", 0, 0, 3, 1, 0xF), el("TEXCOORD", 1, 0, 1, 2, 0xF), el("SV_ClipDistance", 0, 2, 3, 3, 1)]; + let h = super::emit::rect_list_gs(&outputs); + assert!(h.contains("triangle XclOut v[3]") && h.contains("XclOut d = v[0];"), "{h}"); + assert!(h.contains("d.p0 = a.p0 + b.p0 - k.p0;") && h.contains("d.p2 = a.p2 + b.p2 - k.p2;") && !h.contains("d.p1 ="), "{h}"); if super::dxc::location().is_ok() { super::dxc::compile(&h, "main", "gs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{h}")); } } -/// A PS with `v_interp_mov_f32` reads flat (`pso::reads_flat`): its rect list keeps no GS. -#[test] -fn rect_list_ps_reads_flat() { - let mov = prog(&[ - ("V_INTERP_MOV_F32", "ENC_VINTRP", &[("VDST", 4), ("VSRC", 2), ("ATTR", 0), ("ATTRCHAN", 0)], None), - ]); - let p2 = prog(&[ - ("V_INTERP_P1_F32", "ENC_VINTRP", &[("VDST", 4), ("VSRC", 0), ("ATTR", 0), ("ATTRCHAN", 0)], None), - ("V_INTERP_P2_F32", "ENC_VINTRP", &[("VDST", 4), ("VSRC", 1), ("ATTR", 0), ("ATTRCHAN", 0)], None), - ]); - assert!(super::pso::reads_flat(&mov).unwrap()); - assert!(!super::pso::reads_flat(&p2).unwrap()); -} - /// `emit::rect_list_gs` on the full-screen pass a downstream build (theaustinayers/xcl, build 5, /// via #189) reports from a retail title: positions (−1,1) (−1,−1) (1,−1), texture coordinates /// (0,0) (0,1) (1,1), the shared corner v1 and the implied one (1,1) with (1,0). Plain HLSL @@ -1687,7 +1673,7 @@ fn gpu_rect_list_fullscreen_order() { let ps_hlsl = "float4 main(float4 pos : SV_Position, float4 uv : TEXCOORD0) : SV_Target { return uv; }\n"; let vs = super::dxc::compile(vs_hlsl, "main", "vs_6_6", &[]).unwrap(); let ps = super::dxc::compile(ps_hlsl, "main", "ps_6_6", &[]).unwrap(); - let gs_hlsl = super::emit::rect_list_gs(&outputs).unwrap(); + let gs_hlsl = super::emit::rect_list_gs(&outputs); let gs = super::dxc::compile(&gs_hlsl, "main", "gs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{gs_hlsl}")); let layout = [ runner::VertexElement { semantic: "POSITION", index: 0, format: DXGI_FORMAT_R32G32B32A32_FLOAT, offset: 0 }, @@ -1713,6 +1699,66 @@ fn gpu_rect_list_fullscreen_order() { } } +/// A console rect list with flat outputs – an integer one, and a float one the PS reads +/// `nointerpolation` (what `v_interp_mov_f32` is translated to) – drawn indexed through +/// `emit::rect_list_gs`, the corner at v0, v1 or v2: the whole rect is drawn, the smooth output +/// continues into the implied corner's half, and both flat ones are the rect's first vertex's +/// in both halves. On the console that is the provoking vertex under D3D's setting +/// (PA_SU_SC_MODE_CNTL.PROVOKING_VTX_LAST = 0, see `emit::rect_list_gs`). Synthetic: not a +/// measurement of the hardware. Without the GS part of every rect stays clear. +#[test] +fn gpu_rect_list_flat_outputs() { + if !gpu_ready() { + return; + } + use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32_UINT}; + let outputs = [el("SV_Position", 0, 1, 3, 0, 0xF), el("TEXCOORD", 0, 0, 3, 1, 0xF), el("TEXCOORD", 1, 0, 1, 2, 0xF), el("TEXCOORD", 2, 0, 3, 3, 0xF)]; + let vs_hlsl = "struct V { float4 pos : SV_Position; float4 uv : TEXCOORD0; uint4 id : TEXCOORD1; float4 tint : TEXCOORD2; };\nV main(float4 pos : POSITION, uint id : ID) { V o; o.pos = pos; o.uv = float4(pos.xy, 0.0, 1.0); o.id = uint4(id, 0u, 0u, 0u); o.tint = float4(id * 0.125, 0.0, 0.0, 0.0); return o; }\n"; + let ps_hlsl = "float4 main(float4 pos : SV_Position, float4 uv : TEXCOORD0, nointerpolation uint4 id : TEXCOORD1, nointerpolation float4 tint : TEXCOORD2) : SV_Target { return float4(uv.xy, id.x, tint.x); }\n"; + let vs = super::dxc::compile(vs_hlsl, "main", "vs_6_6", &[]).unwrap(); + let ps = super::dxc::compile(ps_hlsl, "main", "ps_6_6", &[]).unwrap(); + let gs_hlsl = super::emit::rect_list_gs(&outputs); + let gs = super::dxc::compile(&gs_hlsl, "main", "gs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{gs_hlsl}")); + let layout = [ + runner::VertexElement { semantic: "POSITION", index: 0, format: DXGI_FORMAT_R32G32B32A32_FLOAT, offset: 0 }, + runner::VertexElement { semantic: "ID", index: 0, format: DXGI_FORMAT_R32_UINT, offset: 16 }, + ]; + // a 3 × 2 grid: columns x = -0.75, 0, 0.75, rows y = -0.5, 0.5; vertex 2·column + row has id = its number + 1 + let grid: Vec = (0..6u32).flat_map(|v| [[-0.75f32, 0.0, 0.75][v as usize / 2], [-0.5f32, 0.5][v as usize % 2], 0.0, 1.0, f32::from_bits(v + 1)]).collect(); + let (left, right) = ([-0.75f32, 0.0, -0.5, 0.5], [0.0f32, 0.75, -0.5, 0.5]); + let (n, clear) = (16usize, [0.0f32, 0.0, 1.0, 0.5]); + // (indices, the rects (x1, x2, y1, y2) and their first vertex's id) + for (name, indices, rects) in [ + ("corner v0", vec![0u32, 1, 2], vec![(left, 1.0f32)]), + ("corner v1", vec![0, 1, 3], vec![(left, 1.0)]), + ("corner v1, the other way round", vec![1, 0, 2], vec![(left, 2.0)]), + ("corner v2", vec![1, 2, 0], vec![(left, 2.0)]), + ("two rects sharing vertices", vec![0, 1, 2, 5, 3, 2], vec![(left, 1.0), (right, 6.0)]), + ] { + let run = |with_gs: bool| runner::draw_gs_indexed(&vs, with_gs.then_some(gs.as_slice()), &ps, &layout, &grid, 20, &indices, n as u32, clear).unwrap(); + let wrong = |px: &[[f32; 4]], report: bool| { + let mut wrong = 0; + for y in 0..n { + for x in 0..n { + let (fx, fy) = ((x as f32 + 0.5) / 8.0 - 1.0, 1.0 - (y as f32 + 0.5) / 8.0); + let rect = rects.iter().find(|&&([x1, x2, y1, y2], _)| fx > x1 && fx < x2 && fy > y1 && fy < y2); + let want = rect.map_or(clear, |&(_, id)| [fx, fy, id, id * 0.125]); + let got = px[y * n + x]; + if !got.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-5) { + assert!(!report, "{name}: pixel ({x},{y}) = {got:?}, expected {want:?}"); + wrong += 1; + } + } + } + wrong + }; + wrong(&run(true), true); + // the negative control: as a triangle list part of every rect is not drawn + let missing = wrong(&run(false), false); + assert!(missing >= 12 * rects.len(), "{name}: without the GS {missing} pixels differ"); + } +} + /// Console rect lists (DI_PT_RECTLIST) drawn through `emit::rect_list_gs`: three corners of a /// screen-aligned rectangle, the corner between the other two at v0 (Mesa radeonsi's blits), /// v1 (xf86-video-ati's r600 EXA) or v2. Each covers the whole rectangle and its attribute – the @@ -1760,7 +1806,7 @@ fn gpu_rect_list_corners() { assert!(vt.complete() && pt.complete(), "{:?} {:?}", vt.unsupported, pt.unsupported); let vs = super::dxc::compile(&vt.hlsl, "main", "vs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", vt.hlsl)); let ps = super::dxc::compile(&pt.hlsl, "main", "ps_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", pt.hlsl)); - let gs_hlsl = super::emit::rect_list_gs(&outputs).unwrap(); + let gs_hlsl = super::emit::rect_list_gs(&outputs); let gs = super::dxc::compile(&gs_hlsl, "main", "gs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{gs_hlsl}")); let layout = [ runner::VertexElement { semantic: "POSITION", index: 0, format: DXGI_FORMAT_R32G32B32A32_FLOAT, offset: 0 }, diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index bb8ae1dc4..65ef47f06 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -4180,16 +4180,11 @@ unsafe fn untranslated_stream_desc(desc: *const c_void, stream: bool) -> Option< } /// The GS that completes a rect list's rects behind the console VS `vs` and the PS `ps`; refused -/// for a PS that reads flat or is not a console one (its inputs' modes are not known). +/// for a PS that is not a console one (its inputs' modes are not known). fn rect_list_gs(vs: &[u8], ps: Option<&[u8]>) -> Result, String> { use crate::gpu::recomp::pso; - if let Some(p) = ps { - if !pso::is_console(p) { - return Err("a PC pixel shader".into()); - } - if pso::ps_reads_flat(p)? { - return Err("the PS reads a flat attribute".into()); - } + if ps.is_some_and(|p| !pso::is_console(p)) { + return Err("a PC pixel shader".into()); } pso::rect_list_gs(vs) }