Skip to content

GPU: host pipelines with a geometry stage from the merged ES+GS pair (#314) - #400

Open
Revens2 wants to merge 12 commits into
fxceless:mainfrom
Revens2:fix/issue-314
Open

Revens2 wants to merge 12 commits into
fxceless:mainfrom
Revens2:fix/issue-314

Conversation

@Revens2

@Revens2 Revens2 commented Nov 25, 2026

Copy link
Copy Markdown

Step 5 of #138, for #314. Stacked on #381 (#313), itself on #373 (#312), #367 (#311) and #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

  • A title pipeline with a "vertex" and a "geometry" container is a merged ES+GS stage. pipeline::merged_pair translates the two containers together (emit::translate_merged_gs) into a vertex and a geometry shader, each a Shader with its translation made; the pair is kept by the two containers' hashes, so two pipelines sharing a GS container with different ES containers are two pairs (in memory only, translated again at each start).
  • HostPipeline::new takes geometry stages: vertex, geometry (root parameters with geometry visibility, same user-data / root-view handling as the other stages) and pixel; the GS bytecode goes in the PSO. Stages are found by visibility rather than by position. The library name of such a pipeline is its own (graphics geometry).
  • Topology: the title's own, used as it gives it; the emitted geometry shader takes triangles, so a geometry stage on any other topology type, or without its vertex container, or with a mesh shader, is refused (logged, the draws are dropped as for any pipeline that does not translate).
  • victory-shader gets a synthetic feature with the synthetic containers its tests use, for the victory-gpu test.

Tested

  • victory-shader (synthetic programs): the host device makes a PSO of the translated vertex shader, geometry shader and a pixel stage.
  • victory-gpu: HostPipeline::new on a synthetic ES+GS pair and a pixel container gives a three-stage host pipeline (vertex, geometry, pixel), the pair's translation is shared, a non-triangle topology and a missing vertex container are refused. Runs on the host GPU (skipped without one).
  • cargo build --workspace --locked, cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 536 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.

🤖 Generated with Claude Code

integ and others added 10 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>
…xceless#313)

The ES half becomes a DXIL vertex shader: each record dword written to
LDS is a channel of a synthetic TEXCOORD register (32-bit integers),
s_barrier a nop and the s_setpc_b64 handover an end. The GS half becomes
a geometry shader (triangles in, triangle strip out, stream 0): reads of
an input vertex record are loadInput, its own LDS writes go to a private
array, the k-th GS_EMIT copies record k to the output signature and
emits, GS_CUT cuts the strip, the runtime table load reads zero.

translate_merged_gs now returns both shaders. Tests use synthetic GCN
programs only; the DXIL validator accepts both modules.

Assumed, not verified on a title program: record dword 4*row+col is that
channel of the output register, emits are numbered in code order,
triangle strip topology, one instance, ES vertex id in v0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…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>
…xceless#314)

A title pipeline with a vertex and a geometry container is a merged ES+GS
stage: the two containers are translated together (translate_merged_gs,
kept by the pair of hashes) and the host pipeline gets a vertex shader, a
geometry shader (root parameters with geometry visibility) and the pixel
stage. Triangle topologies only; the library name of such a pipeline is
its own. victory-shader gets a synthetic feature with the synthetic
containers its tests use, for the victory-gpu test.

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:33:44.335969Z 5ccfea0 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: 5ccfea0e84

ℹ️ 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 on lines +4293 to +4294
let (name, value) = if e.comp == 9 {
("storeOutput.f32", self.as_float(bits))

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 Convert half-precision geometry outputs

When the geometry output signature marks an element as 16-bit (e.half), this path still reads a full record dword and forwards its raw bits through a 32-bit output operation. Unlike the regular export path, it never unpacks or widens the half value, so GS varyings or positions from such signatures are corrupted; reject these outputs or convert them before storing.

Useful? React with 👍 / 👎.

.op(self.cur, "barrier", Attr::NoDuplicate, void, 80, &[mode]);
Ok(())
}
Fields::Sopp { .. } if name == "s_sendmsg" && self.x.gs.is_some() => {

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 Handle halting geometry messages

When a GS uses s_sendmsghalt for GS_EMIT or GS_CUT, planning recognizes the message and assigns it an output record, but this dispatch handles only s_sendmsg. The halting instruction falls through as a no-op, so the translated shader omits the emission or cut while still declaring the vertex maximum; handle both opcodes or refuse the halting form.

Useful? React with 👍 / 👎.

unreachable!()
};
let name = inst.name();
if self.scalar.get(&site).is_some_and(|a| a.param == RUNTIME_TABLE) {

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 Preserve non-base runtime-table loads

Whenever a GS reads the runtime table, this branch replaces every scalar destination with zero without checking the load offset or proving that the value is used only as the relocatable LDS base. If a table field also feeds an output value, condition, or other computation, the pair is still accepted but silently produces results based on zero; limit this substitution to proven base-only uses or refuse other accesses.

Useful? React with 👍 / 👎.

(None, None) => return refuse("no vertex or mesh shader", shaders),
};
let mut stages = vec![first];
stages.extend(merged.as_ref().map(|m| (&m.1, D3D12_SHADER_VISIBILITY_GEOMETRY)));

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 Share the merged-stage user-data block

The ES and GS halves share one user-data layout, but adding the translated GS here sends it through the per-stage root-parameter construction, which allocates a second root-constants block for the same registers. If those duplicated constants plus the other parameters exceed D3D12's 64-DWORD root-signature limit, serialization fails and HostPipeline::new drops every draw for that pair; share the merged block or otherwise keep it within the limit.

Useful? React with 👍 / 👎.

@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown
Author

In-game run of the stacked head (release build, one session of about 9 minutes, the usual script to the lit cell scene): 0 ERROR, 0 device removed, 4 fps at ~4,900 draws a frame like the runs before it, and no pipeline with a geometry stage was created (no geometry stage translated nor does not translate line, no geometry shader seen), so the new path was not exercised in game. That matches #138: the title's GS_VoxelizeGeneric_* programs are not on a path this scene reaches.

The 195 failing programs: non verifie. victory translate reads the title's shader files, which I did not do, and it cannot pair an ES half with its GS half (the pair is only known from a title pipeline at run time), so it would not measure this path anyway.

integ and others added 2 commits November 25, 2026 01:42
…xceless#313)

Review fixes: s_sendmsghalt emits/cuts and half-precision outputs are
refused, the emitted output signature marks the components the emits store,
an input vertex offset must be scaled to bytes, a second runtime table field
is refused (the one read is taken as the output base), and the returned
vertex shader says it is a vertex shader.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/victory-shader/src/emit/gs.rs
@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Review findings: the three on the geometry emission (s_sendmsghalt, half-precision outputs, runtime table loads) are handled in #381 (1c4de71) and merged into this branch; see the comment there. The fourth, on the user-data block:

  • Shared merged-stage user-data block: not changed. Each translated shader numbers its user-data dwords itself (UserData::index), so the vertex and geometry halves of a pair do not necessarily use the same index for the same dword, and one shared block could have one stage overwrite the other's values. Each stage keeps its own block, as every other stage does. A pair whose two blocks and other root parameters exceed the 64 DWORD limit fails at root signature creation (logged as host root signature refused) and its draws are dropped; I did not measure how close a title's pairs get, as none was created in the run.

Workspace tests on the head (cargo test --workspace --locked --no-fail-fast -- --test-threads=4): 539 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