Skip to content

Shaders: model the ES to GS handoff, check the ES half too (#312) - #373

Open
Revens2 wants to merge 7 commits into
fxceless:mainfrom
Revens2:fix/issue-312
Open

Revens2 wants to merge 7 commits into
fxceless:mainfrom
Revens2:fix/issue-312

Conversation

@Revens2

@Revens2 Revens2 commented Nov 25, 2026

Copy link
Copy Markdown

Step 3 of #138, for #312. Stacked on #311 (#367), itself on #309: the diff here includes theirs until they merge; the commit of this step is the last one. Base is main because the stacked branches are not in this repository.

What is in it

  • handoff::es_record: from the ES program, the record it writes to LDS (ds_write_b32 .. b128 at one base address with constant offsets: dwords, VGPRs, highest dword), whether an s_barrier precedes the handover, and a refusal of an ES half that does not leave through s_setpc_b64, reads or does atomics on LDS, writes at two bases, off a dword, or writes nothing.
  • handoff::vertex_reads: from the GS program, its reads of input vertices: an address that is the low or high half of v0 or v1 (v_and_b32 0xffff, v_lshrrev_b32 16, v_bfe_u32, scaled and offset) is vertex 0, 1 or 2's record. A fourth vertex is refused; reads at other addresses are the GS half's own output memory and left to the output step.
  • handoff::handoff checks the GS half reads only dwords the ES half writes. emit::merged_halves is the pairing entry point: pair, ES half traced / raised / structured with the merged layout, then the handoff; translate_merged_gs goes through it before stopping at GS emit.
  • victory translate: ES programs get their own es line (traced, raised, writing a record, largest record) and no longer fall out of the batch silently.

What the LDS in a graphics stage comes to (reading emit/lower.rs, not tested): LDS exists in the lowering only where a stage declares groupshared memory (compute, mesh). The handoff does not need it: the ES records become vertex outputs, the GS reads become input loads, and the barrier is the stage boundary. That is the model the next step emits.

Tested

  • Synthetic GCN programs: an ES record of a 16-byte and a 4-byte write, refused ES halves (no handover, LDS read, two bases, no write), GS reads of vertices 0 and 1 through the halves of v0, reads at other addresses ignored, a fourth vertex refused, a read past the record refused, and containers going through merged_halves and translate_merged_gs.
  • cargo build --workspace --locked, cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 523 passed, 0 failed, 7 ignored (Windows).

Not tested / assumed

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 4 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>
)

handoff finds the record the ES half writes to LDS (whole-dword writes at
one base, then s_barrier and the s_setpc_b64 handover) and the GS half's
reads of its input vertices (the halves of the offsets in v0 and v1). The
GS half may only read dwords the ES half writes. emit::merged_halves
pairs two containers, traces and raises the ES half and checks the
handoff; victory translate counts the ES programs on their own line.

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

chatgpt-codex-connector Bot commented Nov 25, 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:08:41.262329Z e62e1c7 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: e62e1c740d

ℹ️ 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/handoff.rs Outdated
/// (`s_setpc_b64`), touches LDS in any way but whole-dword record writes,
/// writes at more than one base, or writes nothing.
pub fn es_record(p: &Program) -> Result<EsRecord, ShaderError> {
if !p.blocks.iter().any(|b| b.exit == Exit::Indirect) {

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 Require every reachable ES exit to hand off

If an ES CFG has one reachable s_setpc_b64 exit and another reachable s_endpgm exit, this check succeeds, so es_record and handoff accept a pair even though that branch never transfers the record to GS. Validate that every reachable terminal path hands off, rather than only requiring one indirect exit.

Useful? React with 👍 / 👎.

Comment thread crates/victory-shader/src/handoff.rs Outdated
Comment on lines +150 to +152
("v_bfe_u32", [x, off, width]) if c(width) == Some(16) && c(off).is_some_and(|o| o % 16 == 0) => {
match x.base {
Base::Input(reg) if plain(x) => Lin::of(Base::Half { reg, high: c(off) == Some(16) }),

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 Normalize BFE offsets before classifying halves

For a v_bfe_u32 with inline offset 48, this condition accepts the offset, but the branch below labels only exactly 16 as the high half. GFX10 masks BFE offsets to five bits (as emit/lower.rs::bfe does with off & 31), so 48 selects bit 16; vertex_reads then attributes a vertex-1 read to vertex 0, which can make the handoff check validate the wrong record. Classify the masked offset or reject values other than 0 and 16.

Useful? React with 👍 / 👎.

Comment thread crates/victory-shader/src/handoff.rs Outdated
let mut barrier = false;
for (b, block) in p.blocks.iter().enumerate() {
for (i, inst) in block.insts.iter().enumerate() {
barrier |= inst.name() == "s_barrier";

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 Track barriers along the handoff path

If an ES CFG has s_barrier only in an unreachable block or on a branch that does not reach s_setpc_b64, this assignment still marks EsRecord.barrier true. The returned record then incorrectly says the handoff path is preceded by a barrier; derive the flag from barriers that precede each reachable handoff instead of any barrier in the program.

Useful? React with 👍 / 👎.

Comment thread apps/victory/src/translate.rs Outdated
let es = p.stage == HwStage::Es;
t.gs_programs += usize::from(geometry);
t.es_programs += usize::from(es);
if es && let Ok(r) = victory_shader::handoff::es_record(&program) {

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 Report failed ES record analysis

When es_record rejects an ES program, this if let Ok discards the error. If resource, I/O, and structure checks pass, the later ES-only continue skips emission too, so victory translate leaves the invalid ES half out of t.failed and --list; record the error in the tally.

Useful? React with 👍 / 👎.

integ and others added 3 commits November 25, 2026 01:14
…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>
… bits (fxceless#312)

Review fixes: an ES half must hand over on every reachable path (a
reachable s_endpgm loses the record), the barrier flag holds only when a
barrier precedes every handover, v_bfe_u32 offsets are read in five bits,
and victory translate reports an ES half whose record analysis fails.

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

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown
Author

All four findings fixed in 9acd8f0 (with tests), on top of the #311 fixes (d8e53e1):

  • Every ES exit hands off: a reachable s_endpgm now refuses the ES half (an ES half that does not hand over to the GS half); an end nothing reaches is ignored.
  • BFE offsets: v_bfe_u32 offsets are read in five bits, so 48 is the high half like 16 and 32 the low half.
  • Barrier flag: EsRecord.barrier is true only when an s_barrier precedes every reachable handover (must-analysis over the CFG); a barrier on one arm or in unreachable code does not count.
  • victory translate: an ES half whose record analysis fails is now counted as a failure (ES record: ...) and listed with --list.

Workspace build and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 on the stacked head: 534 passed, 0 failed, 7 ignored.

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