Closed Bug 1952983 Opened 1 year ago Closed 1 year ago

Web render crash when using ffvpx hw with zero copy enabled

Categories

(Core :: Audio/Video: Playback, defect, P1)

Unspecified
Windows
defect

Tracking

()

VERIFIED FIXED
138 Branch
Tracking Status
firefox-esr128 --- unaffected
firefox138 --- verified

People

(Reporter: alwu, Assigned: alwu)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(1 file, 2 external files)

When debugging Bug 1952648, I noticed this crash on my debug build.

STR.

  1. set the pref media.ffvpx-hw.enabled, media.wmf.zero-copy-nv12-textures-force-enabled and gfx.direct3d11.reuse-decoder-device-force-enabledto true, then restart Firefox
  2. go to random Youtube Short video, this is the one I use https://www.youtube.com/shorts/SYJAZvxxais

Expected.
3. HW decoding video plays without crash

Actual
3. HW decoding video crash the GPU process and Firefox switches to the RDD process for using SW decoding

This issue happens on both my Intel and Nvidia card. The issue only happens when the zero copy is enabled.

#01: RustMozCrash (C:\mozilla-source\mozilla-unified\mozglue\static\rust\wrappers.cpp:18)
#02: mozglue_static::panic_hook (C:\mozilla-source\mozilla-unified\mozglue\static\rust\lib.rs:82)
#03: core::ops::function::Fn::call<void (*)(ref$<std::panic::PanicHookInfo>),tuple$<ref$<std::panic::PanicHookInfo> > > (C:\Users\alast\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:79)
#04: std::panicking::rust_panic_with_hook (/rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\std\src\panicking.rs:838)
#05: std::panicking::begin_panic_handler::closure$0 (/rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\std\src\panicking.rs:701)
#06: std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$> (/rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\std\src\sys\backtrace.rs:168)
#07: std::panicking::begin_panic_handler (/rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\std\src\panicking.rs:692)
#08: core::panicking::panic_fmt (/rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library\core\src\panicking.rs:75)
#09: gleam::gl::impl$11::draw_elements_instanced<webrender::device::gl::impl$32::new::closure_env$0> (C:\mozilla-source\mozilla-unified\third_party\rust\gleam\src\gl.rs:101)
#10: webrender::device::gl::Device::draw_indexed_triangles_instanced_u16 (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\device\gl.rs:3756)
#11: webrender::renderer::Renderer::draw_instanced_batch<webrender::gpu_types::PrimitiveInstanceData> (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\renderer\mod.rs:2092)
#12: webrender::renderer::Renderer::draw_alpha_batch_container (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\renderer\mod.rs:2999)
#13: webrender::renderer::Renderer::draw_frame (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\renderer\mod.rs:4927)
#14: webrender::renderer::Renderer::render_impl (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\renderer\mod.rs:1589)
#15: webrender::renderer::Renderer::render (C:\mozilla-source\mozilla-unified\gfx\wr\webrender\src\renderer\mod.rs:1268)
#16: webrender_bindings::bindings::wr_renderer_render (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\src\bindings.rs:649)
#17: mozilla::wr::RendererOGL::UpdateAndRender (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RendererOGL.cpp:191)
#18: mozilla::wr::RenderThread::UpdateAndRender (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RenderThread.cpp:851)
#19: mozilla::wr::RenderThread::HandleFrameOneDocInner (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RenderThread.cpp:666)
#20: mozilla::wr::RenderThread::HandleFrameOneDoc (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RenderThread.cpp:615)
#21: mozilla::wr::RenderThread::WrNotifierEvent_HandleNewFrameReady (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RenderThread.cpp:574)
#22: mozilla::wr::RenderThread::HandleWrNotifierEvents (C:\mozilla-source\mozilla-unified\gfx\webrender_bindings\RenderThread.cpp:536)
#24: nsThread::ProcessNextEvent (C:\mozilla-source\mozilla-unified\xpcom\threads\nsThread.cpp:1154)
#25: NS_ProcessNextEvent (C:\mozilla-source\mozilla-unified\xpcom\threads\nsThreadUtils.cpp:480)
#26: mozilla::ipc::MessagePumpForNonMainThreads::Run (C:\mozilla-source\mozilla-
#27: MessageLoop::RunHandler (C:\mozilla-source\mozilla-unified\ipc\chromium\src\base\message_loop.cc:363)
#28: MessageLoop::Run (C:\mozilla-source\mozilla-unified\ipc\chromium\src\base\message_loop.cc:345)
#29: nsThread::ThreadFunc (C:\mozilla-source\mozilla-unified\xpcom\threads\nsThread.cpp:368)
#30: _PR_NativeRunThread (C:\mozilla-source\mozilla-unified\nsprpub\pr\src\threads\combined\pruthr.c:391)
2025-03-10 18:45:45.388000 UTC - [GPU 36260: MediaSupervisor #1]: V/FFmpegVideo Unlocked D3D11 texture 2058f61f3a0 on index 17
#31: pr_root (C:\mozilla-source\mozilla-unified\nsprpub\pr\src\md\windows\w95thred.c:130)
#32: wcsrchr[C:\WINDOWS\System32\ucrtbase.dll +0x37b0]
#33: BaseThreadInitThunk[C:\WINDOWS\System32\KERNEL32.DLL +0x2e8d7]
#34: patched_BaseThreadInitThunk (C:\mozilla-source\mozilla-unified\toolkit\xre\dllservices\mozglue\WindowsDllBlocklist.cpp:562)
#35: RtlUserThreadStart[C:\WINDOWS\SYSTEM32\ntdll.dll +0xbbf2c]

Hi, Sotaro, is this something you could help with? If not, do you know who I should ask for help? Thanks!

Flags: needinfo?(sotaro.ikeda.g)
Severity: -- → S3

When I tried the STR with Win11 PC with NVIDIA card and latest m-c, I did not see the crash. Instead I saw Bug 1936717. I am going to try it with another Win PCs.

(In reply to Sotaro Ikeda [:sotaro] from comment #2)

When I tried the STR with Win11 PC with NVIDIA card and latest m-c, I did not see the crash. Instead I saw Bug 1936717. I am going to try it with another Win PCs.

With Attachment 9471286 [details] [diff], the video played without problems with the NVIDIA Win PC.

Flags: needinfo?(sotaro.ikeda.g)
See Also: → 1936717

:alwu, do you see the crash with Attachment 9471286 [details] [diff]?

Flags: needinfo?(alwu)

Yes, it works. I'm checking why the frame context we set doesn't take an effect... it seems FFmpeg creates another new one during the process. Thanks!

After doing some investigation, the current implementation of creating a frame context is useless, because this frame context won't be used by ffmpeg directly (even if setting hw_frames_ctx explicitly).

FFmpeg will create a real decoder when it first time receives a sample. The ff_get_format will be called to choose the correct format, which will clean the frame context we set before. If we want to use our own frame context, we have to set hw_frames_ctx inside our get_format callback.

However, simply doing it is not enough, we will also need to create a texture for ffmpeg and set it to AVD3D11VAFramesContext.texture. Otherwise, the initialization will fail.


I think it will be easier to let FFmpeg allocate its own texture pool, instead of creating a texture by us. In addition, I think the best way to do for this issue is to modify dxva2.c in order to always have D3D11_BIND_SHADER_RESOURCE flag on the frame context.

Assignee: nobody → alwu
Component: Graphics: WebRender → Audio/Video: Playback
Flags: needinfo?(alwu)
Priority: -- → P1
Duplicate of this bug: 1952648
Duplicate of this bug: 1945730

We don’t actually need to allocate a frame context, as FFmpeg handles
this automatically. Any frame context we allocate would even be cleaned
up before decoding starts. For more details, please refer to [1].

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1952983#c7

Since we’ll be using FFmpeg’s texture directly in the shader during
zero-copy playback, we need to add this flag to the frame context to
avoid crash.

Depends on D241677

Pushed by alwu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/6d49bcb47b9f part1 : no need to create a frame context for D3D11VA. r=media-playback-reviewers,padenot https://hg.mozilla.org/integration/autoland/rev/5796323ff511 part2 : add D3D11_BIND_SHADER_RESOURCE on dxva2.c. r=padenot
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 138 Branch
Duplicate of this bug: 1936717
Flags: qe-verify+

I was not able to reproduce the issue on Win11x64 using Firefox build 138.0a1(20250310205849) and the specs from description, I have an Intel processor.
Alastor Wu, is there any other way I can reproduce this? Or can you please confirm the fix on your side? Thank you.

Flags: needinfo?(alwu)

Yes, I can confirm this is fixed on my side, thanks!

Flags: needinfo?(alwu)

Marked as verified based in comment#16. Thank you.

Status: RESOLVED → VERIFIED
Regressed by: 1932772
Keywords: regression
See Also: 1952648, 1936717 →

Set release status flags based on info from the regressing bug 1932772

See Also: → 1942097
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: