Skip to content

perf(windows-screen-capture): scale resized frames on D3D11 - #3300

Open
kyzer1023 wants to merge 8 commits into
CapSoftware:mainfrom
kyzer1023:perf/windows-screen-d3d11-scale
Open

kyzer1023 wants to merge 8 commits into
CapSoftware:mainfrom
kyzer1023:perf/windows-screen-d3d11-scale

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Use D3D11 VideoProcessorBlt to scale resized WGC frames into pooled GPU targets. The software encoder reads back only the output-sized texture, and initialization or blit failures retain the existing CPU scaling fallback.

Synthetic texture benchmark medians (3 runs × 12 frames), Ryzen 7 8745HS / Radeon 780M, Windows:

Resize CPU scale call before GPU scale submission after Software output path before Software output path after
1920×1080 → 1280×720 14.468 ms 0.263 ms 15.411 ms 3.568 ms
3840×2160 → 1920×1080 49.872 ms 0.300 ms 52.077 ms 9.836 ms

Synthetic output matched the CPU scaler within 1 channel value maximum error in both cases.

Validation: cargo fmt --all --check, cargo check -p cap-recording, and cargo clippy -p cap-recording -- -D warnings passed. The D3D11 benchmark/pixel test passed. cargo test -p cap-recording had three existing AMF instant-mode scenario failures; the 50+ segment case also fails identically on upstream main at 60ef63232.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issues were found.

Summary

This PR moves resized Windows capture frames onto D3D11 and keeps CPU scaling as a fallback.

  • Windows scales resized capture frames on the GPU.
  • Windows encoders keep frames alive while using their textures.
  • Wayland display discovery waits longer for compositor replies.
  • Linux screenshot checks use the active Hyprland display size.
  • The Linux reliability job prepares the video device only when needed.

No new actionable issues were found. This review checked source code; it did not run Windows tests or benchmarks.

Reviews (7) · Last reviewed commit: "fix: lease pooled D3D11 screen scaling t..." · Reviewed by Greptile

@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai review

@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

@richiemcilroy

Copy link
Copy Markdown
Member

Thanks, nice win. The GPU path has no CI coverage (its parity test is ignored) and was only checked on AMD, and driver colour differences wouldn't trigger the fallback. Can you run the pixel-parity test on NVIDIA or Intel and share the result? Also it creates a new texture every frame, so the 3-target pool isn't doing anything yet.

Retain scaled-frame leases through native encoder copies and paced repeats, and allocate overflow targets only when every pool slot is in flight. Add adapter-selectable pixel parity, allocation and lifetime tests, and explicit WARP capability and CPU-scaling coverage.
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai review

@kyzer1023

Copy link
Copy Markdown
Contributor Author

@richiemcilroy thanks, both points addressed in 39a47f5.

Pool reuse: the scaler now renders straight into the three pooled targets instead of creating and copying into a fresh texture each frame. Each ScaledScreenFrame holds an Arc lease on its target, and a slot is only reused once nothing downstream still holds it. Both native encoder loops (win.rs paced repeats, win_segmented.rs) keep the frame alive until its copy is queued. If all three are busy, it allocates a one-off overflow target rather than overwriting an in-flight frame. New tests: 120 promptly dropped frames create exactly 3 textures total, in-flight frames are left untouched across 12 overflow renders, and slots are reused after release.

Pixel parity: this machine only has AMD hardware, so I couldn't run NVIDIA or Intel here and don't want to make up numbers. The parity test can now target a specific adapter (CAP_D3D11_SCALE_ADAPTER=hardware|warp|<index>) and prints the adapter name, vendor id and per-channel max and mean deltas, so it's a one-liner on any box:

CAP_D3D11_SCALE_ADAPTER=hardware cargo test -p cap-recording --lib windows_screen_scale_tests -- --ignored --nocapture --test-threads=1

AMD Radeon 780M (vendor 0x1002), RGBA and BGRA identical:

Scenario Max delta Mean delta
1920x1080 -> 1280x720 1 0.0043
3840x2160 -> 1920x1080 1 0.0386
638x358 -> 318x178 1 0.1977
Solid R/G/B/gray 64x48 -> 32x24 0 0

I also tried WARP as a vendor-neutral reference, but it doesn't expose ID3D11VideoDevice (E_NOINTERFACE), so it can't run the video-processor path. That case is covered by a non-ignored test that checks we report it as unsupported and fall back to CPU. If you or anyone with an NVIDIA or Intel Windows machine can run the command above, I'd love to see the output. Otherwise I'm happy to keep the GPU path behind the existing fallback until someone does.

This branch has not been deployed

No deployments
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.

2 participants