Skip to content

GPU: use one warm-up key for reordered graphics shader stages - #2986

Open
andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/graphics-stream-stage-order-key
Open

andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/graphics-stream-stage-order-key

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

The graphics pre-build writes the vertex or mesh shader before the pixel shader. A guest stream can describe the same pipeline with those two subobjects reversed. The host already uses the same stage order to build the pipeline, but the warm-up key came from the stream order. This can miss the prebuilt entry and split usage across two early keys.

Normalize the two supported graphics stages when reading the stream. Pre-build and guest creation then name that pipeline the same way.

On main 63bcca43c6a00a758510398fa43096ce7e4f7df0, the synthetic Prebuild::graphics and guest CreatePipelineState test found a different key for each reversed vertex/pixel and mesh/pixel pair. Both orders agree after this change. A different pixel shader still changes the key. Six paired runs. Full Windows/WARP GPU diagnostics passed (247 passed, 1 ignored), along with strict GPU Clippy in both feature configurations and asset policy.

AI-assisted.

@kotekompotek kotekompotek 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.

Verified: canonicalizing [pixel, vertex|mesh] to producer-first order at read_stream makes the runtime key equal the prebuild key regardless of subobject order in the stream — the swap is a no-op for forward order and other stage mixes. The test is the right shape: same pipeline through runtime create in both orders plus a control pixel proving keys still differ when content does.

@kotekompotek kotekompotek 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.

Verified: the swap normalizes [pixel, vertex|mesh] streams inside read_stream, so runtime creation and the pre-build produce the same key regardless of subobject order. The test covers both orderings for vertex and mesh, asserts reversed==canonical, and keeps distinct stages/distinct pixel code keyed apart.

@steven-seagull27

Copy link
Copy Markdown

Verified across process restarts with a real D3D12 pipeline library on an RTX 5080 and Microsoft WARP, with #2952 (2cdb5e3) present in both builds. I prebuilt canonical VS+PS and MS+PS streams, exercised them once through guest creation / first use, saved the cache, then reopened it in a fresh process. The table shows the four guest creations per adapter (both stream orders for each stage pair).

Build Recognized as prebuilt Started early at creation Loaded from the host library Newly compiled
Before stage normalization 2/4 2/4 4/4 0
With 7ce9941 4/4 4/4 4/4 0

The old reversed streams could already load the canonical host PSO on first use. The change lets those streams also find the guest prebuild and prior-use records at creation. Both adapters showed the same counts.

The color-only PSOs stayed distinct from two D32_FLOAT variants: omitted depth state (enabled by the DSV) and explicitly disabled depth at the same DSV format. For both VS+PS and MS+PS, each new variant compiled once, then its opposite stage order loaded it. That gave four distinct PSO creations and four loads per adapter.

I also carried an old cache whose early list had only reversed-order uses into the updated build. On the first updated run, both streams found their prebuilt entries and loaded their PSOs at first use. On the next process start, both started early too. This was a synthetic stream/cache test using SDK-compiled shaders seeded at the translation boundary, guest CreatePipelineState, and the production prebuild, worker and library paths.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review on 7ce9941a (static source inspection):

  • crates/victory-gpu/src/pipeline.rs:564-572 canonicalizes reversed vertex–pixel and mesh–pixel stage pairs in the parser shared by runtime pipeline creation and prebuild (:512, :641).
  • The key continues to include every stage, shader hash, and graphics state (pipeline/make.rs:111-118), and host pipeline construction selects shaders by stage (pipeline/host.rs:401-428), preserving behavior without introducing shared-state mutation.
  • Non-blocking note: pre-existing early-list entries stored under a reversed key will miss once after upgrade and then be recorded under the canonical key (pipeline/library.rs:473-480).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. The change in read_stream (victory-gpu/src/pipeline.rs) swaps a two-shader stream that lists the pixel shader before the vertex or mesh shader, so the guest pipeline's warm-up key matches the pre-build's. The code is small and the test shows the keys now agree. A commenter confirms the effect on a synthetic cache.

What is missing is evidence that the title ever produces such a stream. All the tests here are synthetic; if the title always writes the producer stage first, this changes nothing at run time. Please add a log line or count from a real run showing pixel-first streams (stage order and count only, no game data). If they do occur, consider normalizing by stage rank instead of special-casing a two-element [pixel, vertex|mesh] slice, so amplification + mesh + pixel streams are covered too.

CI: passing.


Generated by Claude Code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants