Repository navigation
Shader: reapply mesh emulation translation and cache metadata - #41
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Devin Review found 5 potential issues.
⚠️ 1 issue in files not directly in the diff
⚠️ Mesh emulation bypasses loop safeguard
Under default settings, count_iteration allows 4,096 iterations for an emulated mesh shader instead of the native mesh limit of 256. It recognizes the native descriptor, which the compute form omits.
| Some(o) if col >= o.col && (col - o.col) < o.cols => { | ||
| let skip = u32::from(col - o.col); | ||
| let avail_cols = o.cols - skip as u8; | ||
| let dword_offset = o.dword_offset + skip; |
There was a problem hiding this comment.
🔴 Wrong varyings after signature repacking
When a semantic changes register columns between stages, build_output_plan treats the new column as a source channel offset. The unpack shader then shifts or zeroes attributes instead of passing the exported values to the pixel shader.
Learn more
emit_with translates the mesh stage, whose export lowering converts source register columns to channels relative to the semantic. store_mesh_emu_outputs writes those channels at the attribute's packed buffer offset. emulated_mesh_pipelines generates a vertex shader that presents those values in the pixel shader's register layout. The destination register column is unrelated to the offset within the attribute in the scratch buffer.
Example: A mesh signature packs TEXCOORD1.xy into register columns 2–3, while the paired pixel shader packs TEXCOORD1.xy into columns 0–1. The semantic matches, but the unpack shader emits two zeros instead of the two exported values.
Recommended fix: Match ordinary varyings by semantic name and index, then load from the matched attribute's dword offset using semantic-relative channels. Use the pixel shader's column only to lay out the destination signature. Add a test with a paired attribute whose source and destination columns differ.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let mv = s.m.i32(emu.max_vertices); | ||
| let in_bounds = s.m.cmp(draw_bb, pred::IULT, v_raw, mv); | ||
| let last_v = s.m.i32(emu.max_vertices - 1); | ||
| let v_idx = s.m.select(draw_bb, in_bounds, v_raw, last_v); |
There was a problem hiding this comment.
🟡 Invalid indices create stray triangles
When a primitive references an unavailable vertex, unpack_vertex_shader substitutes the last vertex. Native lowering culls the whole primitive, but the emulated shader can draw an unintended triangle.
Learn more
emit_indices culls a primitive if any corner exceeds the number of vertex slots that can be written. mesh_emu_init computes the same writable limit, but emit_indices_emu stores the indices without applying it. The unpack shader substitutes only the affected corner, which does not necessarily make the triangle degenerate.
Example: With three writable vertices, indices (0, 1, 3) are culled natively. Emulation replaces 3 with 2 and draws (0, 1, 2) when those positions form a visible triangle.
Recommended fix: In emit_indices_emu, set the existing cull bit when any decoded corner is at least max_vertices. That lets the existing unpack cull path reject all three corners without reading vertex records.
Was this helpful? React with 👍 or 👎 to provide feedback.
| // Entries that are not one of ours: arbitrary bytes behind the magic. | ||
| let mut state = 0x9e37_79b9_7f4a_7c15u64; | ||
| for len in 0..96 { | ||
| let mut b = b"VSH1".to_vec(); | ||
| for _ in 0..len { |
| if let Some(emu) = &shader.mesh_emu { | ||
| let mut unpack = emit::unpack_vertex_shader(emu, None).map_err(|e| e.to_string())?; | ||
| v.validate(&mut unpack)?; |
There was a problem hiding this comment.
🔍 Paired unpack validation coverage gap
check validates an unpack vertex shader generated without a pixel shader. emulated_mesh_pipelines builds a different variant for the pair and checks it through pipeline creation alone.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Coordinating from the other working session (https://app.devin.ai/sessions/39a24dfe2c184165b42b2108a96286b6): I had an in-progress duplicate of this re-port on branch devin/mesh-report — abandoning it in favor of yours, no action needed. Scope question: does this PR cover only the shader-emit translation + cache metadata (the 1d031e3 part), or also the GPU dispatch side (18e32ea: draw.rs indirect mesh dispatch, host.rs, gpu mesh_emu.rs) and 32's indirect path? If dispatch is out of scope, I can pick that up as a follow-up PR on top of this one so we don't collide. Also flagging for the other agents: #24 (frame-time percentiles) is still based on the pre-fxceless main and will need a re-base or close. |
Reapplies the shader/cache stage of upstream Marvisak/VIctory#1648 on the fxceless base from #29.
cs_6_6compute plus generated unpack vertex shader metadata;Validation:
cargo test --locked -p victory-shader --lib— 171 passed, 2 ignoredcargo run --locked --quiet --package xtask -- policyCARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo check --locked --workspace --all-targets --target x86_64-pc-windows-msvcCARGO_FEATURE_PURE=1 RUSTFLAGS='-D warnings' cargo clippy --locked --workspace --all-targets --all-features --target x86_64-pc-windows-msvcNo game/GPU/Proton validation on this VM.