Performance: an efficiency-first frame budget - governor on the frame clock, read-only redundant-pass profiler on replay #2249

Open
opened 2026-11-26 05:24:34 +00:00 by github-bot · 0 comments
Owner

@⁠itsonewi on GitHub · 2026-11-25 11:18 UTC · original

What I am proposing (the two-line version, as CONTRIBUTING asks): measure where frames are wasted before anyone optimises. A read-only profiler that logs, per frame, the present interval and how much of the replayed command stream is identical to the previous frame's - then, only if the numbers justify it, a frame-budget governor that spends the surplus on idle time instead of frames, and shading-rate on the main scene pass.

This is a design question first: is efficiency/perf policy in scope for XCL at all, now or later? If the answer is "not now", the rest of this issue is still useful as a record of where the hooks are.

Why it fits XCL in particular

XCL is in an unusual position: it owns the three things an efficiency controller needs, which a Vulkan-based layer (DXVK, VKD3D-Proton) does not all own.

  1. The frame clock is the layer's, not a swap chain's. crates/xcl/src/hle/d3d12x/frame.rs runs the console frame clock on its own high-resolution timer thread, releases the origin semaphore per interval, hands out tokens and tracks flips for GetFrameStatisticsX, and already clamps the interval through XCL_FRAME_INTERVAL_US (including 0/uncapped). A title blocks in WaitFrameEventX, so when the layer releases that token is a frame-pacing decision the layer can make without a latency SDK. Most layers cannot pace a title this way; this one can.
  2. Replay is explicit, so a "pass" is already a decoded segment. Command lists arrive in the console format, are decoded and re-recorded for D3D12 (hle/d3d12x/list_x.rs; README "graphics"; design §5.7). Skipping redundant work therefore means not recording it, not intercepting already-compiled commands. That is the cheapest possible place to drop a pass - provided the pass really is pure.
  3. Shader text is produced by the layer. Precision/quality choices at translation time are possible in a way they are not for a layer that only forwards DXIL.

What already exists and would be reused rather than rebuilt: the timer thread and its 0.6 ms spin, frame tokens with origin and flip timestamps, d3d12.presents in report.json, the XCL_ACTIVITY counters in frame.rs, the translated-shader disk cache and the --precompile --pipelines blobs. The gap is not measurement plumbing; it is a policy on top, and the evidence to justify one.

Step 1 - the only thing I would ask to build: a read-only profiler

No behaviour change, no quality change, no skipped work. A diagnostic behind an environment variable, in the shape report.json already uses:

  • per-frame present interval from the existing origin/flip timestamps: p50, p95, p99, 1 % and 0.1 % low, so stutter is visible and not averaged away;
  • per decoded replay segment: a fingerprint (shaders, pipeline state, viewport/scissor, resource versions, and only the constant-buffer bytes the shaders read) plus the GPU milliseconds it cost, so the log says "this much GPU time would have been skipped" rather than "passes look redundant";
  • explicit counters for segments that can never be skipped (UAV writes or counters, predication, read-back, frame-index/random-dependent shaders), because in a real title that list decides whether the idea is alive at all.

The kill criterion, stated before the work so it cannot be moved afterwards: if the median across a representative set of titles is under ~10 % savable GPU time, stop and do not build the skipping logic. The one piece of hard evidence I have found for this class of idea is mobile (Arnau et al., ISCA 2014: 38 % of fragment shader executions redundant across frames on Android games, ~60 % of those removed). Mobile titles are often 2D or mostly static; that number will not transfer to a third-person 3D title with a moving camera, and menus will flatter it badly.

Step 2 - only if step 1 passes: the governor

A target p95 frame time with a PID-style budget, rate-limited (small change per frame), hysteresis (cut fast, restore slowly after N stable frames), and the surplus converted into idle time rather than more frames - that is where watts actually fall; an uncapped frame rate saves nothing per frame. Two XCL-specific cautions:

  • the clock grid is already an implicit cap, so the governor only matters when the title is GPU-bound and the clock is not the limiter. That has to be measured, not assumed;
  • it must not fight the cold-PSO work (#2088, #1035, #1598): a budget that reacts to a compile stall would degrade quality for a problem the precompile path is meant to remove.

Step 3 - quality knobs, safe class only

Applying detail where it is not visible is the part of this idea I trust least in a blind layer, because a title often reads its render size from constants and resizing render targets from outside breaks it. The one pixel-cost knob that does not need those constants is variable-rate shading on the main scene pass, driven by the previous frame's local contrast, applied only where the pass can be recognised (render-target size/format, shader hashes) and excluded from UI, text, alpha-tested foliage and anything with MSAA or depth-writing pixels. I found no SetShadingRate/shading-rate-image path in the tree today (code search; the only "shading rate" match is in gpu/dxil/graphics.rs), so this would be new. Render-scale injection outside the title's own upscaler is off the table for me; XCL already runs the title's FSR 4 pass, which is the cooperative version of that knob.

Honest limits of the source brief

The document I am condensing was written for Vulkan translation layers, and most of its vendor half does not survive the translation to a native-D3D12 layer on Windows: NVML gives device-level energy, not per-process, so "joules per frame" is not attributable to one title; Reflex and VK_NV_low_latency2 have no role because there is no swap chain to pace - the frame clock replaces them; optical-flow interpolation and DLSS need inputs a blind layer cannot supply; NTC needs re-encoded assets. NVIDIA-specific fast paths are also premature here: on 32-lane-wave hardware console wave64 programs run as two halves with mask exchange (docs/wave64-on-wave32.md, #42), which is the bigger NVIDIA cost.

Where it probably does not pay yet

README puts the retail title at "steady 30 fps, menus, gameplay not reached". A redundancy profiler run on menus would show a wonderful hit rate and say nothing about gameplay. That is the strongest argument against doing this now, and the reason I am asking rather than opening a PR.

Questions

  1. Is "efficiency policy" in scope for XCL - now, later, or not at all?
  2. If it is, is a read-only profiler behind an env var acceptable in the runtime, or is that too much measurement code for this tree? I would scope it to one PR, crates/xcl/src/hle/d3d12x/frame.rs + the replay path, no behaviour change.
  3. Which title should be the reference: the retail one (menus only today), or a playable one (Minecraft, Fortnite, Unicorn Overlord), where the hit rate would actually mean something?
  • #103 - presentation and frame-pacing correctness; this would be policy on top, not a duplicate.
  • #1269 - the thread collecting shader-optimisation PRs.
  • #459 - CPU-side perf; independent of this.
  • #2088, #1035, #1598 - cold-PSO stalls the governor must not react to.
  • #1855 - smoke artifacts/manifest, which is where these numbers would live.
  • #1566 - budget reported but not enforced; #717 - a single number is not the picture.

I searched for memoization, redundant pass, shading rate, frame pacing, energy, telemetry, Reflex, NVML, dynamic resolution and found no existing issue for this, so I am not duplicating one; tell me if it should live inside #103 or #1269 instead and I will move it.

Scope: read through the GitHub API on 2026-11-25 (main as of 11:04Z); frame.rs read in full,

list_x.rs and graphics.rs only by search and size. Nothing was cloned, built or run, so no number here is a measurement.

**@⁠itsonewi** on GitHub · 2026-11-25 11:18 UTC · [original](https://github.com/xcl-dev/xcl/issues/2249) **What I am proposing** (the two-line version, as CONTRIBUTING asks): measure where frames are wasted before anyone optimises. A read-only profiler that logs, per frame, the present interval and how much of the replayed command stream is identical to the previous frame's - then, only if the numbers justify it, a frame-budget governor that spends the surplus on idle time instead of frames, and shading-rate on the main scene pass. This is a design question first: **is efficiency/perf policy in scope for XCL at all, now or later?** If the answer is "not now", the rest of this issue is still useful as a record of where the hooks are. ## Why it fits XCL in particular XCL is in an unusual position: it owns the three things an efficiency controller needs, which a Vulkan-based layer (DXVK, VKD3D-Proton) does not all own. 1. **The frame clock is the layer's, not a swap chain's.** `crates/xcl/src/hle/d3d12x/frame.rs` runs the console frame clock on its own high-resolution timer thread, releases the origin semaphore per interval, hands out tokens and tracks flips for `GetFrameStatisticsX`, and already clamps the interval through `XCL_FRAME_INTERVAL_US` (including `0`/`uncapped`). A title blocks in `WaitFrameEventX`, so *when the layer releases that token* is a frame-pacing decision the layer can make without a latency SDK. Most layers cannot pace a title this way; this one can. 2. **Replay is explicit, so a "pass" is already a decoded segment.** Command lists arrive in the console format, are decoded and re-recorded for D3D12 (`hle/d3d12x/list_x.rs`; README "graphics"; design §5.7). Skipping redundant work therefore means *not recording* it, not intercepting already-compiled commands. That is the cheapest possible place to drop a pass - provided the pass really is pure. 3. **Shader text is produced by the layer.** Precision/quality choices at translation time are possible in a way they are not for a layer that only forwards DXIL. What already exists and would be reused rather than rebuilt: the timer thread and its 0.6 ms spin, frame tokens with origin and flip timestamps, `d3d12.presents` in `report.json`, the `XCL_ACTIVITY` counters in `frame.rs`, the translated-shader disk cache and the `--precompile --pipelines` blobs. The gap is not measurement plumbing; it is a *policy* on top, and the evidence to justify one. ## Step 1 - the only thing I would ask to build: a read-only profiler No behaviour change, no quality change, no skipped work. A diagnostic behind an environment variable, in the shape `report.json` already uses: - per-frame present interval from the existing origin/flip timestamps: p50, p95, p99, 1 % and 0.1 % low, so stutter is visible and not averaged away; - per decoded replay segment: a fingerprint (shaders, pipeline state, viewport/scissor, resource versions, and only the constant-buffer bytes the shaders read) plus the GPU milliseconds it cost, so the log says *"this much GPU time would have been skipped"* rather than *"passes look redundant"*; - explicit counters for segments that can never be skipped (UAV writes or counters, predication, read-back, frame-index/random-dependent shaders), because in a real title that list decides whether the idea is alive at all. The kill criterion, stated before the work so it cannot be moved afterwards: **if the median across a representative set of titles is under ~10 % savable GPU time, stop and do not build the skipping logic.** The one piece of hard evidence I have found for this class of idea is mobile (Arnau et al., ISCA 2014: 38 % of fragment shader executions redundant across frames on Android games, ~60 % of those removed). Mobile titles are often 2D or mostly static; that number will not transfer to a third-person 3D title with a moving camera, and menus will flatter it badly. ## Step 2 - only if step 1 passes: the governor A target p95 frame time with a PID-style budget, rate-limited (small change per frame), hysteresis (cut fast, restore slowly after N stable frames), and the surplus converted into *idle time* rather than more frames - that is where watts actually fall; an uncapped frame rate saves nothing per frame. Two XCL-specific cautions: - the clock grid is already an implicit cap, so the governor only matters when the title is GPU-bound and the clock is not the limiter. That has to be measured, not assumed; - it must not fight the cold-PSO work (#2088, #1035, #1598): a budget that reacts to a compile stall would degrade quality for a problem the precompile path is meant to remove. ## Step 3 - quality knobs, safe class only Applying detail where it is not visible is the part of this idea I trust least in a blind layer, because a title often reads its render size from constants and resizing render targets from outside breaks it. The one pixel-cost knob that does not need those constants is **variable-rate shading on the main scene pass**, driven by the previous frame's local contrast, applied only where the pass can be recognised (render-target size/format, shader hashes) and excluded from UI, text, alpha-tested foliage and anything with MSAA or depth-writing pixels. I found no `SetShadingRate`/shading-rate-image path in the tree today (code search; the only "shading rate" match is in `gpu/dxil/graphics.rs`), so this would be new. Render-scale injection outside the title's own upscaler is off the table for me; XCL already runs the title's FSR 4 pass, which is the cooperative version of that knob. ## Honest limits of the source brief The document I am condensing was written for Vulkan translation layers, and most of its vendor half does not survive the translation to a native-D3D12 layer on Windows: NVML gives device-level energy, not per-process, so "joules per frame" is not attributable to one title; Reflex and `VK_NV_low_latency2` have no role because there is no swap chain to pace - the frame clock replaces them; optical-flow interpolation and DLSS need inputs a blind layer cannot supply; NTC needs re-encoded assets. NVIDIA-specific fast paths are also premature here: on 32-lane-wave hardware console wave64 programs run as two halves with mask exchange (docs/wave64-on-wave32.md, #42), which is the bigger NVIDIA cost. ## Where it probably does not pay yet README puts the retail title at "steady 30 fps, menus, gameplay not reached". A redundancy profiler run on menus would show a wonderful hit rate and say nothing about gameplay. That is the strongest argument *against* doing this now, and the reason I am asking rather than opening a PR. ## Questions 1. Is "efficiency policy" in scope for XCL - now, later, or not at all? 2. If it is, is a read-only profiler behind an env var acceptable in the runtime, or is that too much measurement code for this tree? I would scope it to one PR, `crates/xcl/src/hle/d3d12x/frame.rs` + the replay path, no behaviour change. 3. Which title should be the reference: the retail one (menus only today), or a playable one (Minecraft, Fortnite, Unicorn Overlord), where the hit rate would actually mean something? ## Related - #103 - presentation and frame-pacing *correctness*; this would be policy on top, not a duplicate. - #1269 - the thread collecting shader-optimisation PRs. - #459 - CPU-side perf; independent of this. - #2088, #1035, #1598 - cold-PSO stalls the governor must not react to. - #1855 - smoke artifacts/manifest, which is where these numbers would live. - #1566 - budget reported but not enforced; #717 - a single number is not the picture. I searched for `memoization`, `redundant pass`, `shading rate`, `frame pacing`, `energy`, `telemetry`, `Reflex`, `NVML`, `dynamic resolution` and found no existing issue for this, so I am not duplicating one; tell me if it should live inside #103 or #1269 instead and I will move it. **Scope:** read through the GitHub API on 2026-11-25 (main as of 11:04Z); `frame.rs` read in full, `list_x.rs` and `graphics.rs` only by search and size. Nothing was cloned, built or run, so no number here is a measurement.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.