amplification shader: DispatchMesh hardcodes Y=1, Z=1 — ignores 2D/3D mesh dispatch #115

Closed
opened 2026-11-26 06:10:34 +00:00 by github-bot · 1 comment
Owner

@⁠Trwthh on GitHub · 2026-11-22 10:24 UTC · original

Bug

In crates/tombox-xshader/src/hlsl/amp.rs:269, the HLSL emitter always produces:

DispatchMesh(tb_args[0], 1, 1, tb_pl);

However, the amplification shader's args ring receives 4 dwords via global stores at the ARGS_HI virtual address (line 208-212), corresponding to:

  • tb_args[0] = X group count
  • tb_args[1] = Y group count
  • tb_args[2] = Z group count
  • tb_args[3] = reserved/flags

The Y and Z dispatch group counts are written by the console shader but silently discarded.

Impact

Medium. Any title using 2D or 3D mesh dispatch (Y > 1 or Z > 1) will only get the X dimension dispatched. This means fewer mesh shader groups are launched than intended, resulting in missing geometry. Most titles use 1D dispatch, but some advanced rendering techniques (tiled decal rendering, clustered lighting) use 2D dispatch.

Fix

Replace line 269 with:

let _ = writeln!(h, "    DispatchMesh(tb_args[0], tb_args[1] > 0u ? tb_args[1] : 1u, tb_args[2] > 0u ? tb_args[2] : 1u, tb_pl);");

The > 0u ? ... : 1u guards handle the case where the shader only writes arg[0] and the other slots remain at their initialized zero (which is invalid for DispatchMesh).

**@⁠Trwthh** on GitHub · 2026-11-22 10:24 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/115) ## Bug In `crates/tombox-xshader/src/hlsl/amp.rs:269`, the HLSL emitter always produces: ```hlsl DispatchMesh(tb_args[0], 1, 1, tb_pl); ``` However, the amplification shader's args ring receives 4 dwords via global stores at the `ARGS_HI` virtual address (line 208-212), corresponding to: - `tb_args[0]` = X group count - `tb_args[1]` = Y group count - `tb_args[2]` = Z group count - `tb_args[3]` = reserved/flags The Y and Z dispatch group counts are written by the console shader but silently discarded. ### Impact **Medium.** Any title using 2D or 3D mesh dispatch (Y > 1 or Z > 1) will only get the X dimension dispatched. This means fewer mesh shader groups are launched than intended, resulting in missing geometry. Most titles use 1D dispatch, but some advanced rendering techniques (tiled decal rendering, clustered lighting) use 2D dispatch. ### Fix Replace line 269 with: ```rust let _ = writeln!(h, " DispatchMesh(tb_args[0], tb_args[1] > 0u ? tb_args[1] : 1u, tb_args[2] > 0u ? tb_args[2] : 1u, tb_pl);"); ``` The `> 0u ? ... : 1u` guards handle the case where the shader only writes arg[0] and the other slots remain at their initialized zero (which is invalid for DispatchMesh).
github-bot 2026-11-26 06:10:34 +00:00
  • closed this issue
  • added the
    bug
    label
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:34 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 14:05 UTC · original

Not a bug, and the suggested change would break dispatch. The mesh-args entry is not X/Y/Z. The console fixture as3 (source DispatchMesh(g.x + 1, 1, 1)) writes the entry with one global_store_dwordx4: {X, 0, payload VA >> 4 high, payload VA >> 4 low}. tb_args[2] is therefore part of the payload pointer, and using it as Z would dispatch a pointer's worth of groups. The driver also launches AS work as DISPATCH_DIRECT start+count, 1, 1, and our translated mesh shaders read a flat group id (gid.x). The open part, how the console compiler encodes a 2D/3D DispatchMesh, is noted in docs/BLOCKERS.md (d585b945). No title we run has an amplification shader. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-22 14:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/115#issuecomment-7080278126) Not a bug, and the suggested change would break dispatch. The mesh-args entry is not X/Y/Z. The console fixture as3 (source DispatchMesh(g.x + 1, 1, 1)) writes the entry with one global_store_dwordx4: {X, 0, payload VA >> 4 high, payload VA >> 4 low}. tb_args[2] is therefore part of the payload pointer, and using it as Z would dispatch a pointer's worth of groups. The driver also launches AS work as DISPATCH_DIRECT start+count, 1, 1, and our translated mesh shaders read a flat group id (gid.x). The open part, how the console compiler encodes a 2D/3D DispatchMesh, is noted in docs/BLOCKERS.md (d585b945). No title we run has an amplification shader. Thanks.
This discussion has been locked. Commenting is limited to contributors.
No description provided.