fix(video): balance Media Foundation buffer locks on rejected frames #2859
Open
github-sync
wants to merge 2 commits from
github/pr/2859 into main
pull from: github/pr/2859
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2859
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2859"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This hardens the Windows Media Foundation fallback against rare buffer-lock and attachment failures. A successfully locked but rejected output buffer could remain locked, and a failed input lock could reach an invalid copy. There is no observed gameplay symptom; the normal Windows movie path tries dav1d first, so this is not a change affecting every Windows player. Linux does not compile this file.
Fixes #2835. Draft: resource-lifetime regressions are reproduced, but this change has not been run in the game. No gameplay incidence, GPU-specific improvement, physical-RAM saving or FPS gain is claimed.
Technical changes
pullandmf_av1_decodebodies with controlled HRESULT failures and counted lock/reference lifetimes.The current open-PR file inventory found no other change to
host/mf_av1.c. Private investigation preceded the delivered team-room claim.Validation
Current head:
bc5078ac39828af4aa5271b4d4a450f27dd3142e. The review followup restoresdocs/worklist.mdbyte-for-byte to the base, removing the unmeasured reach/priority row and fixing the unrelated encoding change. Source and tests are unchanged from3cf32313b95a8ec96aaf69562ec23968742ec886, which was refreshed ontode8192345086c7c79c115fff260163508bb19c43. The source and focused tests are byte-identical to the previously tested commit5d8d0d167d453f18a6e2a2c57817fb88ae8ecc38; the upstream changes were reviewed before the refresh.3cf32313(identical source/test bytes):python -I -B tests/run_all.py --jobs 2finished 426 passed, 3 failed, 71 skipped, including the focused buffer-lifetime regression. The complete tracked tree and authored commit object were SHA-verified; the checkout was shallow at the exact head, without parent history. Failed checks:tests/test_bake_portability.py,tests/test_hookshot_ctl.py,tests/test_mem_gate_children.py. The unchanged-base controls at51da0464also failedtest_bake_portability.py(missing Python zstandard),test_hookshot_ctl.py(its runtime-directory prerequisite) andtest_mem_gate_children.py(child resident-memory accounting below its expected amount). These controls distinguish the observed local failures from a claim that the complete suite is green; skipped prerequisites were not suppressed.MFCreate2DMediaBuffersupplied through an authored one-output transform reproduced the unreleased output lock on the base; the fix left it unlocked. The deliberately unsupported bottom-up RGB picture exercises rejection cleanup, not a real AV1 decode, an observed GPU-driver incident or a gameplay corruption. Valid picture behavior is separately covered by the controlled regression.mf_av1.ctranslation units passed strict Windows syntax checks against the actual host interface and existing local generic runtime headers. No linked-game build or complete Windows suite is claimed for this PR.Current-head hosted checks: Game-free source regressions, Linux AppImage, PR title, Windows builder. Their live conclusions are separate from local tests. Independent code review was COMMENTED, not approval. The remaining runtime gate is a Windows build using Media Foundation, not dav1d: identify the decoder from HOS_VIDEO_LOG, play the intro and a movie through its end/drain, and report GPU, driver, OS, hardware/software decoding and any regressions. The authored native buffer test is not a decoder-owned D3D sample or a real AV1/movie run. Full linked-game compilation and this explicit fallback playback validation remain outstanding; no speed or memory measurement is claimed.
This line was re-encoded by mistake:
instalaçaobecameinstalaçao(UTF-8 read as Latin-1 and written back). Please restore it; the PR shouldn't touch this row.Two things about this row:
Thanks, this is a careful one. I read the change and the test against main; the code is right, and what's left is about evidence and the worklist row.
Locks and references. Every path through
pullnow pairs: Lock2D OK then Unlock2D; Lock2D failing (with the 2D interface held) falls back to a linear Lock that is unlocked on its own; both failing unlocks nothing; and a null pointer or a pitch <= 0 still unlocks before the release.b2andbare released once each, and the own-sample path drops the sample ifAddBufferfails. Inmf_av1_decodea failed or null Lock no longer reachesmemcpy, and theSetCurrentLength/AddBufferfailures releasebandsonce, with no double release (the sample owns nothing yet there). Good.What "rejected" means here. It's only a null pointer or a pitch <= 0 from a successful lock. A size change or a new output type mid-stream is the
MF_E_TRANSFORM_STREAM_CHANGEpath, which locks nothing and is untouched. With NV12 out of the AV1 decoder the pitch is positive, so the rejected path is close to unreachable with a real decoder, and the input lock only fails on a system-memory buffer when memory runs out. So this is hardening, with no symptom in the game today. That's fine as a change; I'd just like the PR and the row to say so (see the inline note).Reach. On Windows, Media Foundation is the fallback: Windows builds now ship dav1d (
HOOKSHOT_DAV1D, the "dav1d for Windows" job), andnn_video.ctries dav1d first. MF only runs when a build lacks dav1d or dav1d fails to open. Linux never compilesmf_av1.cand uses FFmpeg/libdav1d, so it is unaffected. #2682 (merged today) only touchesnn_video.c. Your base already has it, and the drain at the stream's end (mf_av1_decode(NULL)thenpull) goes through the same fixed unlock, so I see no interaction.The test extracts the real
pull/mf_av1_decodebodies and counts locks, unlocks and references through HRESULT-injected stand-ins. That models the pairing well. It can't model a decoder-owned D3D sample (where an unbalanced lock would really hurt), but your nativeMFCreate2DMediaBufferrun covers that side. It's declared throughRUN_ALL_ARGSand builds as C under the{cxx}driver with-x c, which is fine.To take it out of draft (our in-game rule): one Windows run on the Media Foundation path, i.e. a build without dav1d, so the log (
HOS_VIDEO_LOG=1) showsvideo: AV1 on Media Foundation: <decoder>. Play the intro movie and one movie to its end (that end is where #2682 changed things), and say whether the decoder was hardware or software and which GPU. A short note that the movies look and end the same as before is enough. No numbers are needed, since nothing claims a speed or memory change. Then fix the two worklist points below, and it's good to go from my side.CI on this head hasn't run yet: every job is still pending.
Restored docs/worklist.md byte-for-byte to the base in
bc5078ac, including the unrelated encoding damage. No MF source or test bytes changed in this followup.Removed the Windows-wide reach/priority row in
bc5078acand corrected #2835 and the PR summary: this is MF fallback hardening with no observed gameplay symptom, not a change to the normal dav1d path or Linux. The native MFCreate2DMediaBuffer control is an authored rejected RGB buffer, not a decoder-owned D3D sample or actual AV1 playback. The draft gate remains an explicitly MF-selected Windows build and decoder log, intro plus a movie through end/drain, with the actual decoding mode/GPU/driver/OS reported. That run has not been done.