Repository navigation
display: take the screenshot the title asks for - #106
Open
xiaotu030202 wants to merge 1 commit into
Open
xiaotu030202 wants to merge 1 commit into
xiaotu030202 wants to merge 1 commit into
Conversation
`take_screenshot` answered `NOT_SUPPORTED` with `tracing::info!("screenshot not
taken")`, so the title's own screenshot path could never take one. The
comment beside it described what was missing: "the last presented frame read
back as BGRA8 (size, row pitch, bytes) on request … copied from the back
buffer after `PresentX`".
That is now there. `victory-gpu/src/screenshot.rs` holds the ask queue and the
read-back; `host::present` notices an ask and reads the frame on the copy list
it already runs, before the swap chain's `Present`; `display.rs` writes the
bytes where the title asked.
## Why a module of its own
`capture.rs` already reads a texture back for its frame saves, but it is
`#[cfg(all(windows, feature = "diagnostics"))]` and its job is writing PNGs
into a folder. The title asks for a screenshot in **every** build, and what it
needs is the bytes in its own buffer, not a file. Sharing `capture` would
mean compiling it without its switches and splitting what is left; the
read-back is about forty lines, so it lives beside it instead of inside it.
The queue it needs is small and worth its own comment: an ask is a placeholder
with no rows, a present fills the oldest one in, and `take` hands back the
oldest filled one. A third ask before any frame is presented drops the oldest,
so a title asking in a loop cannot grow it.
## The shape the title sees
`CAPTURE_VTABLE`'s `0x28`, `(this, user, result)`:
```rust
#[repr(C)]
struct Shot {
width: u32, height: u32, pitch: u32, pad: u32,
bytes: *mut u8, capacity: usize,
}
```
The call fills in `width`, `height` and `pitch` before returning and copies
the frame into `bytes`, which the title sized by `capacity`. A null result,
null buffer, or a capacity below `pitch * height` is refused rather than
written past — `E_INVALIDARG` and `E_NOT_SUFFICIENT_BUFFER`.
Formats other than 8-bit colour cannot be read back as a screenshot: the ask
is dropped rather than left waiting for every later frame, and the call
reports `NOT_SUPPORTED` after its timeout, which is what it did before.
## Waiting
`take_blocking` polls for up to two seconds. A condition variable would need
the presenting thread to take the same mutex while it holds the swap chain's,
which is a lock order I did not want to introduce for this; the poll is every
2 ms and only runs while a title is waiting for a screenshot.
## Verification
Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK
10.0.26100.0. **No game files**, so this is not evidence that the title's
screenshot now works end to end — it is evidence that nothing else broke and
that the queue behaves.
```
$ cargo test --workspace -- --test-threads=1
... every suite ok; victory-shader 210 passed, victory-gpu 110 passed ...
test result: ok. N passed; 0 failed (0 failures anywhere)
$ cargo clippy -p victory-gpu -p victory-hle --all-targets
clean
$ cargo xtask policy
asset policy: 172 files ok
```
One new test, `screenshot::tests::asks_queue_and_are_taken_oldest_first`,
covers what does not need a device: an ask is wanted until a frame fills it,
an unfilled ask is not a frame, `take` gives the oldest filled one, and a
third ask drops the oldest. The read-back and the mapping need a real device
and are left to the title's own calls.
## Not done
`0x18` (`diagnostic screenshot`) and `0x20` (`diagnostic clip`) are still
`missing`. Those are the developer-capture interfaces, not what the title
calls for a user screenshot, and they write files rather than take a frame —
a different shape, and `capture.rs` already has most of it behind its
switches.
If this is not the layout the title actually passes at `0x28`, the refusal is
immediate (`E_NOT_SUFFICIENT_BUFFER` or `E_INVALIDARG`) rather than a bad
write, so a wrong guess here fails safely and the log says which.
xiaotu030202
force-pushed
the
screenshot-from-the-title
branch
from
November 25, 2026 11:56
e3a0ac7 to
888d818
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
take_screenshotansweredNOT_SUPPORTEDwithtracing::info!("screenshot not taken"), so the title's own screenshot path could never take one. The comment beside it described exactly what was missing:That is now there.
What is in it
victory-gpu/src/screenshot.rs(new) — the ask queue, the read-back, and the fill:ask()queues a placeholder;wanted()says one is outstanding; a third ask before any frame is presented drops the oldest, so a title asking in a loop cannot grow the queue.read_back()copies the frame into a readback buffer on the copy list the present already runs.fill()maps it after the submission has run and converts RGBA to BGRA when the swap format is RGBA.host.rs—presenttreats an outstanding ask like a saved frame: it runs on its own list rather than being sent ahead, and fills the ask before the swap chain'sPresent.display.rs— writes the bytes where the title asked, and fills inwidth/height/pitch.Why not share
capture.rsIt already reads a texture back for its frame saves, but it is
#[cfg(all(windows, feature = "diagnostics"))]and its job is writing PNGs into a folder. The title asks for a screenshot in every build, and what it needs is the bytes in its own buffer, not a file. Sharing it would mean compilingcapturewithout its switches and splitting what remains; the read-back is about forty lines, so it lives beside it rather than inside it. Nothing incapture.rschanged.The shape the title sees
CAPTURE_VTABLE's0x28,(this, user, result):The call fills
width,heightandpitchbefore returning and copies the frame intobytes, which the title sized bycapacity. A null result, null buffer, or a capacity belowpitch * heightis refused —E_INVALIDARG,E_NOT_SUFFICIENT_BUFFER— rather than written past.If that layout is not what the title passes, the failure is an immediate refusal, not a bad write, and the log names which check failed. A wrong guess here is safe to be wrong about.
Formats other than 8-bit colour drop the ask rather than leaving it outstanding (so later frames are not read back for nothing) and report
NOT_SUPPORTEDafter the timeout, which is the old behaviour.Waiting
take_blockingpolls every 2 ms for up to two seconds. A condition variable would need the presenting thread to take the same mutex while it holds the swap chain's — a lock order I did not want to introduce for one feature. The poll only runs while a title is waiting.Verification
Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK 10.0.26100.0. No game files — so this is not evidence that the title's screenshot works end to end; it is evidence that nothing else broke and the queue behaves.
One new test,
screenshot::tests::asks_queue_and_are_taken_oldest_first, covers what needs no device: an ask is wanted until a frame fills it, an unfilled ask is not a frame,takegives the oldest filled one, and a third ask drops the oldest. The read-back and the mapping need a real device and are left to the title's calls.Not done
0x18(diagnostic screenshot) and0x20(diagnostic clip) are stillmissing. Those are the developer-capture interfaces — they write files rather than take a frame, andcapture.rsalready has most of what they need behind its switches. A different change.If someone can run the title and report what the log says at a screenshot (
screenshot takenwith the size, ornot taken: no frame presented, or a refusal), that would settle the layout question above without needing to guess.Added after the first push: the conversion is tested on its own
380 lines of new module for one call is a lot to review, so the part that can be held without a device is now a pure function with tests beside it. ill maps the readback and hands the rows to o_bgra, which either copies (the swap chain already presents BGRA) or swaps red and blue four bytes at a time.
screenshot::tests::rgba_rows_arrive_as_bgra pins:
cargo test -p victory-gpu --lib is 112 passed, 0 failed; cargo clippy -p victory-gpu -p victory-hle --all-targets is clean; cargo xtask policy is 172 files ok.