From d3bd51d9172f3b61cbe2a5b2fd3871e946242830 Mon Sep 17 00:00:00 2001 From: ryosen0 Date: Tue, 24 Nov 2026 01:45:02 +0300 Subject: [PATCH 1/4] Recompiler: the mesh pass-through budget accounts DXC's vertex chunks A retail title's NGG transform programs (128 vertices / 128 primitives, 21 params + SV_ClipDistance0 = 352 B per vertex) all failed ms_6_6 with "vertex plus primitive output size is greater than 32768": the split budget divided 32768 by the stride, but DXC accounts whole chunks of 32 vertices even when fewer are declared - verts[78] at 352 B is accounted as 96 (33792 B) and refused. Measured with dxc 1.8.2502 on this machine: every boundary from 9 to 26 float4 rows agrees with the chunk model. passthrough_split now floors the vertex budget to a multiple of 32 (capped at 256); the wide records go out in 7 groups of 19 triangles instead of 5 groups of 26 that DXC refuses. Test: the wide record splits and compiles, a 96-vertex group at 320 B compiles, a narrow record stays whole; fails without the change (5 != 7). Assisted-by: DSH (GPT-6.2 Astra) --- crates/xcl/src/gpu/recomp/emit.rs | 13 +++++-- crates/xcl/src/gpu/recomp/tests.rs | 56 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 1d5ef0139..a6017fb32 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4713,15 +4713,24 @@ pub fn mesh_passthrough_for(ms: &MsInterface, ps_inputs: Option<&[SigElement]>) /// D3D12's limit on what one mesh shader group outputs (vertex + primitive attributes). const MESH_OUTPUT_BYTES: u32 = 32768; +/// Vertices the pass-through puts in one mesh group: the vertex output budget divided by the +/// stride, and DXC accounts whole chunks of 32 vertices even when fewer are declared (78 +/// vertices with 22 rows are accounted as 96). Measured with dxc 1.8.2502 (ms_6_6): every +/// boundary from 9 to 26 float4 rows agrees. +fn passthrough_max_vertices(vbytes: u32) -> u32 { + (MESH_OUTPUT_BYTES / vbytes).min(256) / 32 * 32 +} + /// Mesh groups the pass-through spends on one record: 1 when the record's vertices fit the /// mesh output limit as they are, else the triangles are split into runs whose own vertex /// copies (3 per triangle) fit. `elements`: output elements besides SV_Position. pub fn passthrough_split(ms: &MsInterface, elements: usize) -> u32 { let vbytes = 16 * (1 + elements as u32); - if vbytes * ms.max_vertices <= MESH_OUTPUT_BYTES { + let cap = passthrough_max_vertices(vbytes); + if ms.max_vertices <= cap { return 1; } - let ppg = (MESH_OUTPUT_BYTES / (3 * vbytes)).max(1); + let ppg = (cap / 3).max(1); ms.max_primitives.max(1).div_ceil(ppg) } diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 596a74198..eec2152c0 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2836,6 +2836,62 @@ fn gpu_mesh_mode_two_passes() { assert!(px16 == px, "split pass-through draws the same pixels"); } +/// The mesh output budget with wide vertices: DXC accounts whole chunks of 32 vertices even +/// when fewer are declared, so 78 vertices with 22 float4 rows are accounted as 96 (33792 B > +/// 32768) and the record must go out in split groups. A retail title's NGG transform programs +/// have this shape (128 vertices / 128 primitives, 21 params + SV_ClipDistance0); the previous +/// budget (32768 / stride) emitted verts[78] and DXC refused every one of them. +#[test] +fn mesh_split_accounts_vertex_chunks() { + use super::emit::{mesh_passthrough, passthrough_elements, passthrough_split}; + use super::MsInterface; + if super::dxc::location().is_err() { + println!("no DXC – skipping"); + runner::skip_test("no DXC"); + return; + } + let sig = |name: &str, sv: u32, reg: u32, index: u32| crate::gpu::dxbc::SigElement { + name: name.into(), + index, + system_value: sv, + component_type: 3, + register: reg, + mask: 0xF, + rw_mask: 0xF, + stream: 0, + }; + let mut outputs = vec![sig("SV_Position", 1, 0, 0)]; + for k in 0..20u32 { + outputs.push(sig("TEXCOORD", 0, k + 1, k)); + } + outputs.push(sig("SV_ClipDistance", 2, 21, 0)); + let ms = MsInterface { outputs, threads: 128, max_vertices: 128, max_primitives: 128 }; + let elems = passthrough_elements(&ms, None); + assert_eq!(elems, 21); + // 22 rows * 16 B = 352 B/vertex: 64 accounted vertices fit (96 would be 33792 B), so at + // most 21 triangles' worth of copies per group, ceil(128/21) = 7 groups of 19 + let split = passthrough_split(&ms, elems); + assert_eq!(split, 7, "chunks of 32: 78 verts are accounted as 96 and refused"); + let pass = mesh_passthrough(&ms); + assert!(pass.contains("verts[57]"), "19 triangles per group:\n{pass}"); + super::dxc::compile(&pass, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass}")); + // 20 rows * 16 B = 320 B/vertex: 96 accounted vertices fit (30720 B), but a whole record + // is 128 vertices (40960 B) – 4 groups of 32 triangles, 96 vertices each + let mut ms20 = ms.clone(); + ms20.outputs.pop(); + assert_eq!(passthrough_split(&ms20, passthrough_elements(&ms20, None)), 4); + let pass20 = mesh_passthrough(&ms20); + assert!(pass20.contains("verts[96]"), "96 vertices per group:\n{pass20}"); + super::dxc::compile(&pass20, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass20}")); + // 8 rows * 16 B = 128 B/vertex: 128 vertices are 16384 B – the record stays whole + let mut ms8 = ms.clone(); + ms8.outputs.truncate(8); + assert_eq!(passthrough_split(&ms8, passthrough_elements(&ms8, None)), 1); + let pass8 = mesh_passthrough(&ms8); + assert!(pass8.contains("verts[128]"), "whole record:\n{pass8}"); + super::dxc::compile(&pass8, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass8}")); +} + /// DXC optimisation levels on a saved HLSL file (`XCL_TIME_HLSL=path`, profile in `XCL_TIME_PROFILE`). #[test] #[ignore] From b884f3c001bec54273719539f2c3deef49676b78 Mon Sep 17 00:00:00 2001 From: ryosen0 Date: Tue, 24 Nov 2026 05:13:10 +0300 Subject: [PATCH 2/4] Recompiler: the pass-through layout is chosen by the vertex budget alone The emitter picked the whole-record layout from passthrough_split == 1, but that count is the dispatch's: a record of 80 vertices with 22 float4 rows does not fit the mesh output budget as a whole (DXC accounts 96 vertices, 33792 B > 32768) while its single triangle's compact copies fit one group, so the count is 1 and verts[80] was declared and refused. The declaration now follows the vertex budget independently of the group count; the compact form covers every record over the budget, including the one-group ones. mesh_layout_independent_of_group_count covers the asymmetric limits (80 vertices, 1 triangle, 22 rows): compact declaration, count 1, DXC accepts. Found in review by shdann (PR #304). Assisted-by: DSH (GPT-6.2 Astra) --- crates/xcl/src/gpu/recomp/emit.rs | 16 ++++++++--- crates/xcl/src/gpu/recomp/tests.rs | 43 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index a6017fb32..b43af52de 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4666,8 +4666,13 @@ pub fn mesh_passthrough_for(ms: &MsInterface, ps_inputs: Option<&[SigElement]>) let _ = writeln!(fill, " o.p{k} = {v};"); } let tri_base = MESH_HEADER + mv as usize * vd; + // The declaration is chosen by the vertex budget, the dispatch group count separately: + // a record over the budget in whole vertices can still fit one compact group (its few + // triangles' own copies fit) – declaring verts[mv] there is refused by DXC (80 vertices + // with 22 float4 rows are accounted as 96: 33792 B > 32768). + let cap = passthrough_max_vertices(16 * (1 + elems.len() as u32)); let split = passthrough_split(ms, elems.len()); - if split == 1 { + if mv <= cap { let _ = writeln!( h, "[outputtopology(\"triangle\")]\n[numthreads({t}, 1, 1)]\nvoid main(uint gi : SV_GroupIndex, uint3 gid : SV_GroupID, out vertices XclVert verts[{mv}], out indices uint3 tris[{mp}])\n{{" @@ -4721,9 +4726,12 @@ fn passthrough_max_vertices(vbytes: u32) -> u32 { (MESH_OUTPUT_BYTES / vbytes).min(256) / 32 * 32 } -/// Mesh groups the pass-through spends on one record: 1 when the record's vertices fit the -/// mesh output limit as they are, else the triangles are split into runs whose own vertex -/// copies (3 per triangle) fit. `elements`: output elements besides SV_Position. +/// Mesh groups the pass-through spends on one record: the record's vertices fit the mesh +/// output limit as they are, or the triangles go out in runs whose own vertex copies (3 per +/// triangle) fit – whichever costs fewer groups. The layout choice in `mesh_passthrough_for` +/// is by the vertex budget alone; this count is the dispatch's, and one compact group can +/// carry a record whose whole declaration would be refused. `elements`: output elements +/// besides SV_Position. pub fn passthrough_split(ms: &MsInterface, elements: usize) -> u32 { let vbytes = 16 * (1 + elements as u32); let cap = passthrough_max_vertices(vbytes); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index eec2152c0..13a4a628e 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2892,6 +2892,49 @@ fn mesh_split_accounts_vertex_chunks() { super::dxc::compile(&pass8, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass8}")); } +/// The layout and the dispatch count are chosen separately: a record of 80 vertices with 22 +/// float4 rows does not fit the mesh output budget as a whole (DXC accounts 96 vertices: +/// 33792 B > 32768 B), but its single triangle's copies fit one compact group. The pass- +/// through must then declare the compact layout while `passthrough_split` returns 1, and DXC +/// accepts it (the whole-record declaration is refused). +#[test] +fn mesh_layout_independent_of_group_count() { + use super::emit::{mesh_passthrough, passthrough_elements, passthrough_split}; + use super::MsInterface; + if super::dxc::location().is_err() { + println!("no DXC – skipping"); + runner::skip_test("no DXC"); + return; + } + let sig = |name: &str, sv: u32, reg: u32, index: u32| crate::gpu::dxbc::SigElement { + name: name.into(), + index, + system_value: sv, + component_type: 3, + register: reg, + mask: 0xF, + rw_mask: 0xF, + stream: 0, + }; + let mut outputs = vec![sig("SV_Position", 1, 0, 0)]; + for k in 0..20u32 { + outputs.push(sig("TEXCOORD", 0, k + 1, k)); + } + outputs.push(sig("SV_ClipDistance", 2, 21, 0)); + // 22 rows * 16 B = 352 B/vertex: 64 accounted vertices fit; 80 declared do not + let ms = MsInterface { outputs, threads: 128, max_vertices: 80, max_primitives: 1 }; + let elems = passthrough_elements(&ms, None); + assert_eq!(elems, 21); + // one triangle: its 3 copies fit one compact group, so the dispatch count is 1 + assert_eq!(passthrough_split(&ms, elems), 1, "one triangle fits one compact group"); + let pass = mesh_passthrough(&ms); + assert!(pass.contains("verts[3]"), "the compact layout is chosen, not verts[80]:\n{pass}"); + super::dxc::compile(&pass, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass}")); + // the whole-record form is what DXC refuses at this width (80 accounted as 96) + let refused = mesh_passthrough(&MsInterface { max_vertices: 80, max_primitives: 1, ..ms.clone() }); + assert!(refused.contains("verts[3]"), "the compact form stays:\n{refused}"); +} + /// DXC optimisation levels on a saved HLSL file (`XCL_TIME_HLSL=path`, profile in `XCL_TIME_PROFILE`). #[test] #[ignore] From 2a2cc6d11185d3b31f919bdbe10c62e127ac61ca Mon Sep 17 00:00:00 2001 From: ryosen0 Date: Tue, 24 Nov 2026 06:38:15 +0300 Subject: [PATCH 3/4] Recompiler: the layout test checks the whole-record refusal it names Review nits (Parakeet-Wheat): mesh_layout_independent_of_group_count ended with a block that rebuilt the same MsInterface and asserted verts[3] again; it now compiles the whole-record declaration (verts[80], accounted as 96: 33792 B) and asserts DXC refuses it. passthrough_split's doc claimed a comparison of the two forms it does not make; the doc now states what it does. Tests only plus a doc line; no behaviour change. Assisted-by: DSH (GPT-6.2 Astra) --- crates/xcl/src/gpu/recomp/emit.rs | 7 +++---- crates/xcl/src/gpu/recomp/tests.rs | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index b43af52de..2a3831511 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4728,10 +4728,9 @@ fn passthrough_max_vertices(vbytes: u32) -> u32 { /// Mesh groups the pass-through spends on one record: the record's vertices fit the mesh /// output limit as they are, or the triangles go out in runs whose own vertex copies (3 per -/// triangle) fit – whichever costs fewer groups. The layout choice in `mesh_passthrough_for` -/// is by the vertex budget alone; this count is the dispatch's, and one compact group can -/// carry a record whose whole declaration would be refused. `elements`: output elements -/// besides SV_Position. +/// triangle) fit. The layout choice in `mesh_passthrough_for` is by the vertex budget alone; +/// this count is the dispatch's, and one compact group can carry a record whose whole +/// declaration would be refused. `elements`: output elements besides SV_Position. pub fn passthrough_split(ms: &MsInterface, elements: usize) -> u32 { let vbytes = 16 * (1 + elements as u32); let cap = passthrough_max_vertices(vbytes); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 13a4a628e..b964636d5 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2930,9 +2930,11 @@ fn mesh_layout_independent_of_group_count() { let pass = mesh_passthrough(&ms); assert!(pass.contains("verts[3]"), "the compact layout is chosen, not verts[80]:\n{pass}"); super::dxc::compile(&pass, "main", "ms_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{pass}")); - // the whole-record form is what DXC refuses at this width (80 accounted as 96) - let refused = mesh_passthrough(&MsInterface { max_vertices: 80, max_primitives: 1, ..ms.clone() }); - assert!(refused.contains("verts[3]"), "the compact form stays:\n{refused}"); + // the whole-record form is what DXC refuses at this width: the same record declared whole + // (verts[80], accounted as 96: 33792 B) does not validate + let whole = pass.replace("verts[3]", "verts[80]"); + assert!(whole.contains("verts[80]"), "the whole-record declaration for the refusal check:\n{whole}"); + assert!(super::dxc::compile(&whole, "main", "ms_6_6", &[]).is_err(), "DXC refuses 96 accounted vertices of 352 B"); } /// DXC optimisation levels on a saved HLSL file (`XCL_TIME_HLSL=path`, profile in `XCL_TIME_PROFILE`). From 1ab9ba97620257bbeb54d307b8b98fc2f4943b3c Mon Sep 17 00:00:00 2001 From: ryosen0 Date: Tue, 24 Nov 2026 10:54:33 +0300 Subject: [PATCH 4/4] Recompiler: the vertex-budget doc names the whole measured range NathanTheophile bisected DXC's ms_6_6 acceptance boundary over 96 cases (1-32 float4 rows, up to 256 primitives): the formula matches exactly everywhere, not only rows 9-26. Doc-only; narrower clip/cull rows count as full rows (overestimate only). Assisted-by: DSH (GPT-6.2 Astra) --- crates/xcl/src/gpu/recomp/emit.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 2a3831511..df7c81361 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4720,8 +4720,10 @@ const MESH_OUTPUT_BYTES: u32 = 32768; /// Vertices the pass-through puts in one mesh group: the vertex output budget divided by the /// stride, and DXC accounts whole chunks of 32 vertices even when fewer are declared (78 -/// vertices with 22 rows are accounted as 96). Measured with dxc 1.8.2502 (ms_6_6): every -/// boundary from 9 to 26 float4 rows agrees. +/// vertices with 22 rows are accounted as 96). Measured with dxc 1.8.2502 (ms_6_6): the +/// formula gives DXC's exact boundary for 1 to 32 float4 rows, up to 256 primitives +/// (NathanTheophile's 96-case bisect in this PR); narrower clip/cull rows count as full rows +/// here, which can only overestimate. fn passthrough_max_vertices(vbytes: u32) -> u32 { (MESH_OUTPUT_BYTES / vbytes).min(256) / 32 * 32 }