AMF icon indicating copy to clipboard operation
AMF copied to clipboard

[Bug]: Encoding crashes when Unigine Superposition starts and/or stops rendering, using H265 w/"obs-amf" branch of OBS Studio

Open cs9kc opened this issue 3 years ago • 6 comments

Describe the bug The GPU drivers crash when recording Unigine Superposition while encoding with H265 in the "obs-amf" branch of OBS Studio (https://github.com/obsproject/obs-studio/pull/6508). The crash happens when one starts recording before Superposition begins properly rendering (start before or on the loading screen, crashes when one crosses over into the start of the render), or if one starts during the render, and is recording when Superposition ends (going from render back to menu, crash happens when rendering ends).

Just before the crash happens, encoder usage will depart from the normal 50-60% and spike up to 100%, at which point the GPU driver crashes and the render crashes to desktop. OBS Studio and Superposition are both still running after the crash.

Both crashes throw the same error in OBS Studio. This has only occurred while using Superposition, and has not occurred with any other games. I have tested with a DX11 and DX12 game; both behave as expected.

To Reproduce Steps to reproduce the behavior:

  • On a Windows machine, using , clone the "obs-amf" branch to you your machine (using git for Windows)
  • Run Visual Studio 19 and ensure it has the following components installed:
    • MSVC v142 - VS 2019 C++ x64/x86 build tools (latest)
    • C++ ATL for latest v142 build tools (x86 & x64)
    • C++ MFC for latest v142 build tools (x86 & x64)
    • Windows 10 SDK (10.0.20348.0)
  • In Powershell, navigate to the main folder location
  • in "obs-studio\CI\windows", open the file "02_build_obs.ps1"
  • Under "$CmakeCommand = @(", add ""-DENABLE_HEVC=ON"," (minus outer-most quotes)
  • Run "CI/build-windows.ps1 -BuildArch x64 -BuildConfiguration Release -Choco" ("-Choco" may only need to be run once the first time, and then any time the dependencies are updated) (More information on building OBS Studio here: https://obsproject.com/wiki/build-instructions-for-windows)
  • Run the program as administrator (do this every time), close the configuration wizard pop-up, and go into settings
  • On the Video tab: Change Output Resolution to 1920x1080, set framerate to 60fps, hit apply
  • On the output tab, change Output Mode to "Advanced"
  • On the recording tab, in the Encoder drop-down, select "AMD HW H.264"
  • Add the following configuration in to the AMF/FFmpeg Options field:

HevcRateControlMethod=2 HevcProfile=1 HevcTier=1 HevcProfileLevel=150 HevcQualityPreset=0 HevcGOPSize=240 HevcGOPSPerIDR=1 HevcTargetBitrate=14000000 HevcPeakBitrate=20000000 HevcVBVBufferSize=80000000 HevcInitialVBVBufferFullness=64 HevcMaxOfLTRFrames=0 HevcMaxNumRefFrames=8 HevcFillerDataEnable=false HevcEnforceHRD=false HevcHalfPixel=true HevcQuarterPixel=true HevcDeBlockingFilter=false HevcRateControlPreAnalysisEnable=false HevcEnablePreAnalysis=false HevcRateControlSkipFrameEnable=false HevcHighMotionQualityBoostEnable=false HevcEnableVBAQ=false

  • Click apply, then OK
  • Download and install Unigine Superposition: https://benchmark.unigine.com/superposition
  • Set Superposition to "4K Optimized"
  • Star recording with H265 using the settings above, before the render starts (Or start it after it starts, and let it record past the end of the render)
  • Click ok on the driver crash notification, and go check the logs of OBS Studio

Setup (please complete the following information):

  • OS version: Windows 11 21H2 22000.708
  • Adrenalin driver version: WHQL 22.5.2
  • GPU: AMD Reference RX 6900 XT LC
  • Which component has the issue: H265 Encoder

Debug Log (please upload or paste): There have been two distinct errors thrown when the GPU driver crashes. The first is the most common:

19:56:51.425: [texture-amf-h265: 'advanced_video_recording'] amf_encode_tex: SubmitInput timed out: AMF_INPUT_FULL

This has only occurred once, on the previous build of the "obs-amf" branch:

22:21:33.864: [AMF] 2022-06-12 22:21:33.864 3ED0 [AMFEncoderCoreHevc] Error: ..........\runtime\src\components\EncoderCore\EncoderCoreHevcImpl.cpp(2074):Assertion failed:CopyOutputBuffer():Invalid taskID

22:21:33.865: [AMF] 2022-06-12 22:21:33.864 3ED0 [AMFEncoderCoreHevc] Error: ..........\runtime\src\components\EncoderCore\EncoderCoreHevcImpl.cpp(2252):AMF_ERROR 1 : AMF_FAIL: QueryOutput() Failed to copy output buffer

22:21:33.865: [texture-amf-h265: 'advanced_video_recording'] amf_encode_tex: QueryOutput failed: AMF_FAIL 22:21:33.865: Error encoding with encoder 'advanced_video_recording'

Expected behavior This issue only occurs with Superposition, and only occurs when using the H265 encoder. It does not occur with the H264 encoder with Superposition, and does not occur at all with either encoder in other games that I have tried

Additional context I appreciate that this is a pretty obscure issue, in what amounts to an alpha or early-beta build of OBS Studio, but I did run this by jp0000 (Jim at OBS Studio) and it is not believed that this is an OBS Studio issue, instead it is an AMF issue. Thank you all for your time!

cs9kc avatar Jun 14 '22 01:06 cs9kc

To start with, could you please share full log? Also could you please check free video memory situation in task manager?

MikhailAMD avatar Jun 14 '22 13:06 MikhailAMD

Attached are the log output from OBS and a screenshot of Task manager during the crash.

  • The green arrow is when Superpositon begins rendering the benchmark (from loading screen to benchmark begin)
  • The red arrow is when the encoder overloads and crashes the GPU driver

Of note: When I went to try to recreate the crash this morning to get data for you... it didn't crash. I realize that I left it in CQP mode from last night's testing. When I input the VBR_Peak settings back in to OBS Studio, it began crashing as it did a few days prior. I've got no problem admitting it is my own fault, if the settings I fed OBS Studio/AMF were the cause of the crash.

I also did submit a bug report through the BRT in the Adrenalin control panel, for the crash pictured below. I'm not at liberty to put my email address here, but all the text of the bug report contains is "refer to AMD AMF Github issue 325". I copy/pasted the wrong issue # in the bug report; that's what I get for githubbing before lunch.

OBS Log: 2022-06-14 09-35-30-1.txt

task manager

cs9kc avatar Jun 14 '22 15:06 cs9kc

Thanks for the logs. It seems that AMF_INPUT_FULL handling needs to be improved in OBS. I have conversation about this with jp0000 on the side.

MikhailAMD avatar Jun 14 '22 15:06 MikhailAMD

Rock on! If you think that this particular issue is indeed an OBS problem, please feel free to close it if you wish.

cs9kc avatar Jun 14 '22 15:06 cs9kc

Let's keep this open for some time.

MikhailAMD avatar Jun 14 '22 15:06 MikhailAMD

I'm making this post on both Issue 325 and 326.

It has come to light that many people are having issues with encoding, starting with driver 21.50.xx, and AMF 1.4.24. Poor H264 performance, H265 performance, and driver crashes with H265, are occurring across various driver versions since release driver 22.3.1.

I rolled back to release driver 22.2.3, and have no experienced any of the issues thus far; encoding performance is fine, no encoding overloads, no crashes.

I believe all of these issues to be related to AMF 1.4.24, and possibly to all driver versions since 21.50.xx, too. Jim/jp9000 over at OBS Studio has been notified of my findings.

cs9kc avatar Jun 18 '22 18:06 cs9kc

Oh shoot, forgot to close this D:

cs9kc avatar Feb 13 '23 20:02 cs9kc