Skip to content

Shaders: read the merged stage's LDS size, bound GS vertices (#311) - #367

Open
Revens2 wants to merge 4 commits into
fxceless:mainfrom
Revens2:fix/issue-311
Open

Revens2 wants to merge 4 commits into
fxceless:mainfrom
Revens2:fix/issue-311

Conversation

@Revens2

@Revens2 Revens2 commented Nov 24, 2026

Copy link
Copy Markdown

Step 2 of #138, for #311. Stacked on #309: this branch starts from #309's, so until #309 merges the diff here includes its commits (and the review fix on it); the commit of this step is the last one. The base is main because the stacked branch is not in this repository.

What is in it

  • StageIo::Es(MergedIo) and StageIo::Gs(MergedIo): the record of either half of a merged stage now gives its LDS bytes (the common record field, as mesh programs already read it). The other stage data after the record (output signature rows, limits) is in a layout nothing in the tree has a fixture for, so it is not read.
  • merged::limits(program): from the code, the vertices a GS program emits along its longest path (s_sendmsg GS_EMIT / GS_EMIT_CUT), the streams used, whether it cuts; a message inside a loop or a program that emits nothing is refused. merged::GsMessage decodes the geometry messages (message, operation and stream bits of simm16).
  • MergedGs::lds_bytes(): the larger of the two records' LDS size.
  • The ES half resolves the runtime table pointer too (same SGPRs as the GS half) when tracked with the merged layout, and io::raise accepts an ES program (no exports, runtime table input only).
  • victory translate: the geometry section gains a line with how many GS programs have a bounded vertex count in their code and the largest bound.

Tested

  • New unit tests on synthetic GCN programs and containers: message decoding, straight-line and branching emit counts, a cut, a message in a loop, no emit, LDS size read from synthetic records (ES and GS, and a record that allocates none), the merged LDS size, the ES half and the runtime table.
  • cargo build --workspace --locked, cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 517 passed, 0 failed, 7 ignored (Windows). One unrelated victory-gpu in-place WARP test failed in a first run and passed in the rerun of that crate and in the full run.

Not tested

  • victory translate over the title: not run, so the new bounded-count line is unmeasured.
  • That the real records' LDS field holds what the synthetic fixtures put there, and that the limits the code gives are what the title's geometry shaders declare: the output topology and instance count are not read at all (no source for them in the tree).
  • No run in game; the host still has no geometry path beyond the rectangle one.

Still to do: #312 (ES half, LDS handoff), #313 (GS output as DXIL stream emits), #314 (pipeline path); #138 stays open.

AI use
Written with Claude Code (Claude Sonnet 5.5). The tests are synthetic programs; no title shaders or game files were read.

integ and others added 3 commits November 25, 2026 00:28
The 195 "an address in an SGPR that is no root parameter" failures are the
GS half of one merged ES+GS stage (fxceless#138). Step 1 of its support, without
emitting anything:

- StageIo::Gs and io::raise for a geometry program. User data 0 and 1 of
  the merged stage (s8, s9) are the console runtime's table pointer when the
  root layout puts nothing there; resource tracking traces a load through it
  to resource::RUNTIME_TABLE instead of failing. Other stages and other
  unbound SGPRs fail as before.
- merged::pair_es_gs pairs the ES program (vertex container) with the GS
  program (geometry container): same wave size, one meaning per user-data
  dword, merged root layout. emit::translate_merged_gs runs the pair as far
  as emission.
- emit refuses a geometry program with GS_EMIT ("GS emit"). `translate`
  counts those on their own "geometry" line, not among the failures.

Not done: DXIL geometry emission, the ES to GS handoff through LDS, the
output records, GS_EMIT/GS_CUT, the host pipeline. The runtime table's
contents and the GS stage data are not read.

Refs fxceless#138

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fxceless#138)

pair_es_gs keeps both halves' ranges of one descriptor table pointer
instead of calling them a user-data conflict. The runtime table pointer
is only inferred through resource::track_merged, i.e. for the merged
layout of a pair (translate_merged_gs) or, in victory translate, as a
stated assumption for an unpaired geometry program: a geometry program
traced alone no longer takes user data 0 and 1 as free.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s#311)

StageIo::Es and StageIo::Gs now carry MergedIo (LDS bytes from the common
record). merged::limits counts the vertices a GS program emits along its
longest path from its s_sendmsg GS_EMIT / GS_CUT / GS_EMIT_CUT messages,
refusing a message in a loop. The runtime table pointer is also resolved
for the ES half, which shares the SGPRs. victory translate counts the GS
programs with a bounded vertex count.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:07:04.045790Z b622e17 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b622e17409

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/victory-shader/src/merged.rs Outdated
}
on.push(b);
let after = match p.blocks[b].exit {
Exit::End | Exit::Indirect => 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject unresolved GS control flow when claiming a vertex bound

If a GS has an unresolved s_setpc_b64 whose target reaches another GS block, the IR marks the exit Indirect, but this branch treats it like End. limits then counts only pre-jump emits, so max_vertices can be lower than the shader's actual maximum; reject such paths or resolve their targets before reporting a bound.

Useful? React with 👍 / 👎.

Comment thread crates/victory-shader/src/io.rs Outdated
let first = native.stage.user_sgpr(crate::merged::RUNTIME_TABLE);
let taken = native.layout.iter().any(|p| {
let at = u32::from(native.stage.user_sgpr(p.user_data));
at < u32::from(first) + 2 && u32::from(first) < at + p.sgprs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the SGPR range before adding its untrusted length

For ES/GS containers, RootParam.sgprs is deserialized from the layout without a range check, so a malformed entry with a large count can overflow at + p.sgprs: checked builds panic, while release builds can wrap and incorrectly treat s8/s9 as free. Use checked or widened interval arithmetic here and in pair_es_gs.

Useful? React with 👍 / 👎.

…unts (fxceless#311)

Review fixes: a GS program with an indirect jump has no vertex bound, and
the user-data overlap tests saturate the container-supplied SGPR count.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Both review findings fixed in d8e53e1 (with tests):

  • Unresolved GS control flow (merged.rs): limits now refuses a GS program with an indirect jump (an unresolved jump in a geometry program) instead of counting only the emits before it.
  • SGPR range overflow (io.rs, merged.rs): the overlap tests saturate the container-supplied SGPR count; a test pairs two halves with a u32::MAX count and gets a refusal rather than a wrap.

cargo test -p victory-shader --locked: 233 passed, 0 failed.

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