Skip to content

winegstreamer, mf, dxva2 and mfplat: the WM reader's compressed samples, a session that keeps its renderer, DXVA2 render targets, a discard copy - #78

Open
wenze-allen wants to merge 4 commits into
willfaust:madeira-lgplfrom
wenze-allen:video-cg-sabbat-senren
Open

wenze-allen wants to merge 4 commits into
willfaust:madeira-lgplfrom
wenze-allen:video-cg-sabbat-senren

Conversation

@wenze-allen

@wenze-allen wenze-allen commented Nov 21, 2026 •

Copy link
Copy Markdown

In short. Four commits on madeira-lgpl (ddf92ba), a fast-forward. They are the Wine side of willfaust/Madeira#631 (Windows Media and Media Foundation movies on iOS), which pins this head, 34765056b9e. One commit is on Sabbat of the Witch's path and was tested on a device. The other three are on Senren Banka's path, which has not been tested on a device yet.

Details

  • winegstreamer (b0d33cbd85a): the WM reader reads compressed samples per stream, and keeps its streams when a reinit fails. SetReadStreamSamples is per stream, but reinit_stream() used the last call's flag for every stream. When the parser refused to connect, the reader freed its stream array but kept stream_count, and SetReadStreamSamples() still returned S_OK. KiriKiri 2's movie plugin (krmovie.dll) reads a WMV as compressed samples. It then wrote through the NULL array and crashed, and Sabbat of the Witch stayed on a white screen. Now a failed reinit keeps the streams, goes back to the previous mode and parser, and returns the failure. A parser that exposes a different number of streams fails the reinit instead of hitting an assert.
  • mf/session (18689a08977): keep an output node whose sample allocator cannot be initialized. The failed InitializeSampleAllocator() HRESULT failed the whole node. session_collect_nodes() then stopped there, so the renderer's node and every node after it were missing. The session still sent MESessionStarted, but no sample was ever requested and playback never ended. Now the allocator is released and the node is kept; its upstream node gets system memory samples.
  • dxva2 (1f0f5075e94): video processor render targets are created as render targets, and a scaled blit is filtered. CreateSurface() made every surface an offscreen plain surface. The EVR mixer's targets are the size of the window, not of the video. Native d3d9 and DXMT do not StretchRect into a surface that is not a render target, so with DXMT, VideoProcessBlt() left only the background fill: Senren Banka's 1920x1080 WMV in a 2360x1328 window played as a black window. wined3d is lenient, so this did not show there. DXVA2_VideoProcessorRenderTarget surfaces are now lockable render targets. Native reports no usage for them, so the test's usage check is todo_wine. A scaling blit uses D3DTEXF_LINEAR; a 1:1 copy stays D3DTEXF_POINT.
  • mfplat (34765056b9e): ContiguousCopyFrom() on a D3D9 surface buffer locks with D3DLOCK_DISCARD. It locked with no flags, so the surface was read back before every byte was overwritten. With DXMT, that readback waits for the GPU: 9 to 12 ms per frame, on the session's work queue thread, which also feeds the audio renderer. The audio ran short every few seconds. A plain write-only Lock2DSize() keeps the contents, as the tests show native does.

willfaust/Madeira#631 depends on this one (it pins this head), so merge this one first.

Validation

  • Tested on a device (iPad Air M3, confirmed by me on IPA bef1e5d, built from my fork): Sabbat of the Witch's video CGs play. The path is KiriKiri 2's krmovie → WM sync reader with compressed samples → WMV/WMA decoder DMOs through the DMO wrapper → VMR9. Of these four commits, only the winegstreamer one is on that path. The tested build's wine (96d02552546) has the same tree as b0d33cbd85a here, and it also contains the mf/session commit.
  • Not tested on a device: Senren Banka's path (krkrz's Media Foundation session over the Madeira PR's ASF source → resampler to the SAR → decode-ahead → EVR mixer/presenter on DXMT). The mf/session, dxva2 and mfplat commits are verified only by the device logs that diagnosed the faults (the dropped topology nodes, the black mixer output, [d9-drain] ... avg-us=9300) and by Windows Media movies: ASF/WMV files, the WMV decoder and resampler transforms, decode-ahead (Sabbat of the Witch, Senren Banka) Madeira#631's host checks. check-mf-video-render.py checks this path from source against DXMT 3d62913. The dxva2 and mfplat commits were not in any build that ran on a device.
  • The four changed files and dlls/dxva2/tests/dxva2.c compile cleanly (x86_64 PE, -fsyntax-only). Wine's own conformance tests were not run; that needs Windows.

Written with Claude Code. Signed off (DCO), LGPL-2.1-or-later like the rest of the branch.

🤖 Generated with Claude Code

wenze-allen and others added 4 commits November 22, 2026 05:32
…ialized.

session_append_node() kept the HRESULT of
IMFVideoSampleAllocator_InitializeSampleAllocator(), so an allocator that
failed (the EVR's, when the device cannot create surfaces of the stream's
format) failed the whole output node. session_collect_nodes() then stopped at
that node, and the session ran with the renderer's node and every node after it
missing. It still sent MESessionStarted, but no sample was ever requested, the
remaining sinks never got the clock, and playback never ended.

Release the allocator instead and keep the node. The upstream node then gets
system memory samples, as it does for a renderer without an allocator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: allen <wenze532865208@gmail.com>
…streams when a reinit fails.

SetReadStreamSamples is per stream, but reinit_stream() created the parser for compressed
output from the last call's flag alone and enabled every stream with its compressed format
then. It now creates a compressed-output parser when any stream reads compressed samples, and
enables each stream with its own format: the compressed one, or the decoded one it has.

When reinit_stream() failed (the parser refused to connect), it freed the reader's stream array
but kept stream_count, and SetReadStreamSamples() returned S_OK anyway. The next call into the
reader wrote through the NULL array: a KiriKiri movie plugin (krmovie.dll) that reads WMV as
compressed samples crashed there, and the game stayed on a white screen. The streams belong to
the open file, so a failed reinit now keeps them and drops only the handles into the destroyed
parser. SetReadStreamSamples() goes back to the previous mode, rebuilds that parser and returns
the failure. reinit_stream() tolerates being called with no parser, read thread or semaphore
left, and returns an error rather than S_OK when it cannot wait for its read thread.
free_streams() clears stream_count with the array.

A parser that exposes a different number of streams with compressed output failed an assert,
which aborts the process; it now fails the reinit, and the caller goes back to the previous
parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: allen <wenze532865208@gmail.com>
…ilter a scaled blit.

IDirectXVideoProcessorService::CreateSurface() made every surface an offscreen plain surface,
whatever its DXVA2 type, and VideoProcessBlt() stretches the samples into the target with
StretchRect(). Native d3d9 does not stretch into a destination that is not a render target, and
a strict implementation refuses it. The EVR mixer's targets are the size of the video window,
not of the video: with DXMT's d3d9, VideoProcessBlt() left only its background fill, and a
Media Foundation movie played as a black window (Senren Banka, a 1920x1080 WMV in a 2360x1328
window). wined3d is lenient, so it did not show there.

DXVA2_VideoProcessorRenderTarget surfaces are now lockable render targets: the sample copier
still writes frames into them, and the presenter's GetCurrentImage() reads them back with
GetRenderTargetData(), which wants a render target. Native reports no usage for them, so the
test's usage check is todo_wine.

A blit that scales now uses D3DTEXF_LINEAR, as a video processor filters; a 1:1 copy stays
D3DTEXF_POINT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: allen <wenze532865208@gmail.com>
…rwrites.

ContiguousCopyFrom() on a D3D9 surface buffer locked the surface with no flags, so the surface
was read back first, though every byte is then overwritten. The sample copier delivers each
frame of a Media Foundation movie to the EVR this way. With DXMT's d3d9 the readback waits for
the GPU: 9 to 12 ms per frame, 30 times a second, on the session's work queue thread, which
also feeds the audio renderer; the audio ran short every few seconds (Senren Banka).

The surface buffer now has its own ContiguousCopyFrom(), which locks with D3DLOCK_DISCARD. A
plain write-only Lock2DSize() keeps the contents, as the tests show native does, and a buffer
that is already locked takes the generic path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: allen <wenze532865208@gmail.com>
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