Skip to content

Shaders: a thread-id count field of 3 still means three components - #339

Closed
SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/shader-tidig-count
Closed

SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/shader-tidig-count

Conversation

@SkippySteve

Copy link
Copy Markdown

What

`ComputeIo::thread_id_vgprs` (crates/victory-shader/src/native.rs) read `COMPUTE_PGM_RSRC2.TIDIG_COMP_CNT` (bits 11-12) and added one, so a field value of 3 gave 4 thread-id VGPRs. `io::raise` then mapped v3 to `Input::ThreadIdInGroup(3)`, and `emit/lower.rs` passes that component straight to DXIL's `threadIdInGroup.i32` — a component that doesn't exist (only 0-2 are valid). On the console-lanes path, component 3 fell into the `_` arm and was silently computed as z.

Fix

A thread id has only x, y and z, so the field is clamped to 2 before adding one: 3 now means v0-v2 like 2 does, and v3 stays an ordinary VGPR. One line plus a doc comment.

Tests

  • New unit test `native::tests::thread_id_count_three_is_still_three_components` (synthetic `rsrc2`, no game data).
  • `cargo test -p victory-shader`: 57 passed, 0 failed (Linux).
  • `cargo clippy -p victory-shader -- -D warnings`: clean. (`--all-targets` hits the existing dead-code warning on `emit::mod::tests::constant_color` off Windows, which this PR doesn't touch.)
  • `cargo fmt --check`: clean.

COMPUTE_PGM_RSRC2.TIDIG_COMP_CNT is a 2-bit field, and
ComputeIo::thread_id_vgprs returned it plus one: 4 for a value of 3.
io::raise then labelled v3 as Input::ThreadIdInGroup(3), and lowering
asks DXIL's threadIdInGroup for component 3, which does not exist (the
console-lanes path quietly treats it as z instead).

A thread id has only x, y and z, so clamp the field to 2 before adding
one: v0-v2 are the thread id and v3 stays an ordinary VGPR. A unit test
covers the field at 3.
@SkippySteve

Copy link
Copy Markdown
Author

superseded by #333 (combined native.rs: SGPR bound + refusal tests + TIDIG_COMP_CNT clamp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant