Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Is amf (amd GPU) supports hardware encoding in gpu paravirtualization (GPU-PV)? #509

Open
Zhenia-l opened this issue Oct 5, 2024 · 13 comments
Labels

Comments

@Zhenia-l
Copy link

Zhenia-l commented Oct 5, 2024

GPU: RX 6700XT
host/VM: windows 11 24h2
driver: 24.9.1
I created a VM using Hyper-V GPU Paravirtualization. The GPU is visible in the VM, I can run games and they work without problems, as on the host computer. But I ran into a problem trying to use hardware encoding in sunshine while trying to start stream. I get the following errors:

[2024-10-05 22:39:42.122]: Info: Creating encoder [h264_amf]
[2024-10-05 22:39:42.122]: Info: Color coding: SDR (Rec. 601)
[2024-10-05 22:39:42.122]: Info: Color depth: 8-bit
[2024-10-05 22:39:42.122]: Info: Color range: JPEG
[2024-10-05 22:39:42.281]: Verbose: [h264_amf @ 000001aa59f2ffc0] EncodeCoreHelper: 2024-10-05 22:39:42.281     19C8 [EncodeCoreHelper]    Info: ***Found regpath, but key not found using default=1
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] EncodeQueueWinImpl: 2024-10-05 22:39:42.282     19C8 [EncodeQueueWinImpl]   Error: c:\constructicon\builds\gfx\six\24.20\drivers\amf\stable\runtime\src\components\EncoderCore\EncodeQueueWinImpl.cpp(319):AMF_ERROR 1 : AMF_FAIL: EncodeQueueServiceWin::Initialize() Failed to Load EncodeCore binary.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] EncodeQueueService: 2024-10-05 22:39:42.282     19C8 [EncodeQueueService] Warning: Failed to create encode queue serivce.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreBaseImpl: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreBaseImpl] Warning: Failed to initialize EncodeQueueFactory.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreBaseImpl: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreBaseImpl] Warning: Failed to create encode queue serivce.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreH264: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreH264] Warning: Encode Core dll not found, fall back to UVE path
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreH264: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreH264] Warning: CreateServices failed.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreH264: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreH264] Warning: *****Failed to create H264 encoder component.
[2024-10-05 22:39:42.283]: Verbose: [h264_amf @ 000001aa59f2ffc0] AMFEncoderCoreH264: 2024-10-05 22:39:42.283     19C8 [AMFEncoderCoreH264]   Debug: AMFEncoderCoreH264Impl::Terminate()
[2024-10-05 22:39:42.283]: Error: [h264_amf @ 000001aa368a8cc0] CreateComponent(AMFVideoEncoderVCE_AVC) failed with error 11
[2024-10-05 22:39:42.284]: Info: Retrying with fallback configuration options for [h264_amf] after error: Encoder not found

When trying to use h265, the client reports that the computer (VM) does not support h265.
Hardware encoding (both h264 and h265) on the host works without issues. Software encoding on the VM also works.
Should hardware encoding work in the use case described above?

@Zhenia-l
Copy link
Author

Zhenia-l commented Oct 7, 2024

Sounds like a bug with newer AMD drivers jamesstringerparsec/Easy-GPU-PV#392

@MikhailAMD
Copy link
Collaborator

Based on conversation with virtualization team it looks like known and recently fixed issue. We will notify when the fix appears in the public driver.

@sikhness
Copy link

sikhness commented Jan 7, 2025

Hi @MikhailAMD,

I have a similar problem to what @Zhenia-l originally posted. I am using driver version 24.1.1 and using GPU-P I am able to use AMF correctly in a Guest Windows Server or even Windows client based VM as @Zhenia-l has been trying to do with a newer version of the driver.

However, I'm trying to get the same workflow to work in a Windows Server based Container with the GPU passed through from the host itself and even after I put the required DLLs in place, I am getting a similar error as above with CreateComponent(AMFVideoEncoderVCE_AVC) failed with error 10, and with AMF_FAIL: EncodeQueueServiceWin::Initialize() Failed to Load EncodeCore binary being the top most error.

Is there any reason why this wouldn't work on a Windows Container as opposed a GPU-P enabled VM?

@MikhailAMD
Copy link
Collaborator

Manually coping DLLs is unsupported situation. There are many things can go wrong. But based on the log you provided AMF failed to load another DLL it uses: amdenc64.dll.

@sikhness
Copy link

sikhness commented Jan 7, 2025

Thank you for the quick reply @MikhailAMD.
I completely understand manual copying is unsupported, but shouldn't Windows Containers also be supported out of the box?

Also I did try with amdenc64.dll but still seem to get the same issue. Here is a more detailed error log in case that helps:

[hevc_amf @ 000001b59ddf4ec0] Using device d3d11va0 (type d3d11va) with hevc_amf encoder.
[hevc @ 000001b59ddb0700] Decoded frame with POC 0/27.
[hevc @ 000001b59ddb0ac0] nal_unit_type: 1(TRAIL_R), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59ddb0ac0] Output frame with POC 0/18.
[hevc @ 000001b59ddb0ac0] Decoded frame with POC 0/23.
[hevc @ 000001b59de3a400] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59de3a400] Output frame with POC 0/19.
[hevc @ 000001b59de3a400] Decoded frame with POC 0/19.
[hevc @ 000001b59de3a7c0] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59de3a7c0] Output frame with POC 0/20.
[hevc @ 000001b59de3a7c0] Decoded frame with POC 0/20.
[hevc @ 000001b59de3ab80] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59de3ab80] Output frame with POC 0/21.
[hevc @ 000001b59de3ab80] Decoded frame with POC 0/21.
[hevc @ 000001b59de38e00] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59de38e00] Output frame with POC 0/22.
[hevc_amf @ 000001b59ddf4ec0] EncodeCoreHelper: 2025-01-07 16:12:03.837    177F0 [EncodeCoreHelper] Warning: ***Failed to find 
regpath, using default=1
[hevc_amf @ 000001b59ddf4ec0] EncodeQueueWinImpl: 2025-01-07 16:12:03.838    177F0 [EncodeQueueWinImpl]   Error: ..\..\..\..\..
\runtime\src\components\EncoderCore\EncodeQueueWinImpl.cpp(316):AMF_ERROR 1 : AMF_FAIL: EncodeQueueServiceWin::Initialize() Fai
led to Load EncodeCore binary.
[hevc_amf @ 000001b59ddf4ec0] EncodeQueueService: 2025-01-07 16:12:03.838    177F0 [EncodeQueueService] Warning: Failed to crea
te encode queue serivce.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreBaseImpl: 2025-01-07 16:12:03.838    177F0 [AMFEncoderCoreBaseImpl] Warning: Failed
 to initialize EncodeQueueFactory.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreBaseImpl: 2025-01-07 16:12:03.840    177F0 [AMFEncoderCoreBaseImpl] Warning: Failed
 to create encode queue serivce.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreHevc: 2025-01-07 16:12:03.840    177F0 [AMFEncoderCoreHevc] Warning: Encode Core dl
l not found, fall back to UVE path
[hevc @ 000001b59de38e00] Decoded frame with POC 0/22.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreHevc: 2025-01-07 16:12:03.840    177F0 [AMFEncoderCoreHevc] Warning: CreateServices
 failed.
[hevc @ 000001b59de38300] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreHevc: 2025-01-07 16:12:03.840    177F0 [AMFEncoderCoreHevc]    Info: *****Fallback 
to UVE path!
[hevc @ 000001b59de38300] Output frame with POC 0/23.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderCoreHevc: 2025-01-07 16:12:03.841    177F0 [AMFEncoderCoreHevc]   Debug: AMFEncoderCore
HevcImpl::Terminate()
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderHEVC: 2025-01-07 16:12:03.841    177F0 [AMFEncoderHEVC]   Error: ..\..\..\..\..\runtime
\src\components\EncoderUVE\EncoderUVEHEVCImpl.cpp(127):Failed to get UVEHEVC version.
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderHEVC: 2025-01-07 16:12:03.841    177F0 [AMFEncoderHEVC]   Error: ..\..\..\..\..\runtime
\src\components\EncoderUVE\EncoderUVEHEVCImpl.cpp(1007):Assertion failed:InitUVEHevc() UVEHEVC version mismatch
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderHEVC: 2025-01-07 16:12:03.841    177F0 [AMFEncoderHEVC]    Info: Prepare() - Failed to 
init uveHEVC service
[hevc_amf @ 000001b59ddf4ec0] AMFEncoderHEVC: 2025-01-07 16:12:03.841    177F0 [AMFEncoderHEVC]   Debug: AMFEncoderUVEHEVCImpl:
:Terminate()
[hevc_amf @ 000001b59e409a80] CreateComponent(AMFVideoEncoderHW_HEVC) failed with error 10
[hevc @ 000001b59de38300] Decoded frame with POC 0/24.
[hevc @ 000001b59de39540] nal_unit_type: 0(TRAIL_N), nuh_layer_id: 0, temporal_id: 0
[hevc @ 000001b59de39540] Output frame with POC 0/24.
[vost#0:0/hevc_amf @ 000001b59dd9fa80] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width o
r height.
[vf#0:0 @ 000001b59e21bcc0] Error sending frames to consumers: Encoder not found
[vf#0:0 @ 000001b59e21bcc0] Task finished with error code: -1129203192 (Encoder not found)
[vf#0:0 @ 000001b59e21bcc0] Terminating thread with return code -1129203192 (Encoder not found)
[vost#0:0/hevc_amf @ 000001b59dd9fa80] Encoder thread received EOF
[vost#0:0/hevc_amf @ 000001b59dd9fa80] Could not open encoder before EOF
[vost#0:0/hevc_amf @ 000001b59dd9fa80] Task finished with error code: -22 (Invalid argument)
[vost#0:0/hevc_amf @ 000001b59dd9fa80] Terminating thread with return code -22 (Invalid argument)
[vist#0:0/hevc @ 000001b59e2b2bc0] [dec:hevc @ 000001b59e258c40] Decoder returned EOF, finishing
[vist#0:0/hevc @ 000001b59e2b2bc0] [dec:hevc @ 000001b59e258c40] Terminating thread with return code 0 (success)
[vist#0:0/hevc @ 000001b59e2b2bc0] All consumers of this stream are done
[in#0/matroska,webm @ 000001b59dd6ecc0] Terminating thread with return code 0 (success)

@MikhailAMD
Copy link
Collaborator

I see. The DLL was loaded but AMF failed to initialize encoding with D3D11 driver. Could it be some mismatch between AMF DLL(s) and D3D11 driver versions? They can be only used from the same driver package.

@sikhness
Copy link

sikhness commented Jan 7, 2025

Hmm, I'm not sure myself. I am using the same driver package from the host, in fact in Containers it seems to copy the drivers automatically into the Containers HostDriverStore automatically, I just have to take care of the ones that should be in the root System32 folder.

When I follow almost the same exact method for GPU-P VM's that seems to work, I wonder if there's some limitations within Containers that are being set, because natively within Containers, DirectX graphics frameworks work out-of-the-box but external ones like AMF do not.

@MikhailAMD
Copy link
Collaborator

Hmmm... AMF runtime should be HostDriverStore (amfrtdrv64.dll). System32\amfrt64.dll is just a stub.
Can you attach debugger and log full paths and DLL versions in the process?
Can you start with SimpleEncoder sample?

@sikhness
Copy link

sikhness commented Jan 7, 2025

Yes, the Windows Container seems to automatically create a replica of the Host drivers and puts them in the HostDriverStore so within the u03*.inf_amd64* folder (folder for AMD drivers), I can see that amfrtdrv64.dll is there. I also did try to copy that directly into System32 but it made no difference.

Would you be able to guide me as to how I can attach a debugger and log full paths and versions from the Container?

@MikhailAMD
Copy link
Collaborator

If you can run the app in the container from Visual Studio for debugging, VS has Modules view with list of loaded DLLs, paths etc. But how to debug with VS inside container - I don't have experience.
Another thought: you use very old driver: 24.1.1. Can you try something fresh?

@sikhness
Copy link

sikhness commented Jan 7, 2025

Thank you I'll try to see if I can triage this a bit more tomorrow.

With respect to the driver version, I'm using an older driver because it works well with my Windows Server host. Traditionally, AMD drivers don't install on Windows Server for some reason, so I have to use a custom one from RDN-ID that is signed for it which hasn't been updated in some time. I understand that of course would not be supported, but my driver install is basically stock, just signed to install on Windows Server.

Additionally, as per the link that @Zhenia-l pasted, isn't there a bug with newer versions that causes encoding to fail?

@sikhness
Copy link

sikhness commented Jan 8, 2025

Hi @MikhailAMD,

I went down the path of trying to update my driver to 24.12.1 and noticed something really weird that I was hoping you could help with before I triage the AMF within a container issue. Since I'm running on Windows Server 2025, of course I can't normally install the driver without modifying the inf to support my version of Windows for the official drivers, so for all the installations I will mention below I had to use that method, followed by enabling testsigning mode in order to get it to install. My graphics are the Radeon 780M which is built in to Ryzen 7840HS processor.

So when I go about trying to install 24.12.1, it installs the driver but Windows disables it right away with a bunch of Code 31 or Code 43 errors. If I restart my computer, it will go into a boot loop. Ironically if I uninstall Hyper-V from my machine, then the driver loads properly, not sure why that is, but for me Hyper-V is required so I can't disable it. I had done this test with 24.10.1 as well as 24.9.1 and they both failed as well in the same way. If I look into the Event Viewer logs for the System right after installing it where Windows disables it I see the following:

The description of Event ID 1035 from source amduw23g cannot be found.  Either the component that raises this event is not installed on your local computer or the installation is corrupted.  You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:


The system cannot find the file specified

If I go back to either version 24.3.1 or 24.1.1 and install those, they work perfectly and survive reboots as well even with Hyper-V enabled.

Any idea why this might be happening and is there some problem with newer drivers and Hyper-V?

@sikhness
Copy link

sikhness commented Jan 9, 2025

Hi @MikhailAMD,

Did some more testing on this and found something definitely wrong with the latest drivers.

So I went ahead to dual boot a normal client Windows 11 Pro install on my machine to rule out any compatibility issues with Windows Server. Even on Windows 11, the latest 24.12.1 drivers fail to install with Code 31 or Code 43 errors IF you have Hyper-V installed, and if I restart my computer with them installed, the machine also enters a boot loop in the same way. So either I need to disable Hyper-V to use the latest drivers, or I need to downgrade them.

After some extensive testing, I noticed that the latest driver that DOES work with Hyper-V installed is 24.8.1. Anything above that exhibits the behaviour I mentioned above. The problem though with 24.8.1 is that it has the bug inside AMF which you had mentioned and that @Zhenia-l initially opened this issue for.

So I'm having to resort to using 24.3.1 which is the latest version that doesn't have the AMF bug and that works with Hyper-V installed. AMF however still doesn't work inside of Windows Containers, so I will need to begin triaging that further now that I have the driver versions set to something more stable.

Have you seen this behaviour on your end with the latest drivers as well? I'll get back to you about more testing with AMF in Windows Containers when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants