Skip to content

amfcodec: add support for GPU's with multiple hw instances

Some GPU's can have more than 1 hardware encoding instance per GPU which can be selected with the INSTANCE_INDEX property. A new device is registered for each combination of adapter luid and hardware instance.

  1. gst-launch-1.0.exe videotestsrc ! amfh264device3enc ! fakesink
  2. gst-launch-1.0.exe videotestsrc ! amfh264device4enc ! fakesink

image

Limitations:

When using 2 encoders from the same GPU but different instances in the same pipeline the creation of the second encoder fails with AMF_INVALID_POINTER:

  1. amfh264device3enc using adapter-luid=512792, instance-index=0
  2. amfh264device4enc using adapter-luid=512792, instance-index=1
PS C:\gstreamer-amf\builddir> C:\gstreamer-amf\x86_64\bin\gst-launch-1.0.exe videotestsrc ! amfh264device3enc ! fakesink videotestsrc ! amfh264device4enc ! fakesink

** (gst-launch-1.0:4988): CRITICAL **: 17:53:14.577: pygobject initialization failed
Use Windows high-resolution clock, precision: 1 ms
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Got context from element 'amfh264device4enc0': gst.d3d11.device.handle=context, device=(GstD3D11Device)"\(GstD3D11Device\)\ d3d11device3", adapter=(uint)2, adapter-luid=(gint64)512792, device-id=(uint)29631, vendor-id=(uint)4098, hardware=(boolean)true, description=(string)"AMD\ Radeon\ RX\ 6800\ XT";
Got context from element 'amfh264device4enc0': gst.d3d11.device.handle=context, device=(GstD3D11Device)"\(GstD3D11Device\)\ d3d11device3", adapter=(uint)2, adapter-luid=(gint64)512792, device-id=(uint)29631, vendor-id=(uint)4098, hardware=(boolean)true, description=(string)"AMD\ Radeon\ RX\ 6800\ XT";
Got context from element 'amfh264device3enc0': gst.d3d11.device.handle=context, device=(GstD3D11Device)"\(GstD3D11Device\)\ d3d11device3", adapter=(uint)2, adapter-luid=(gint64)512792, device-id=(uint)29631, vendor-id=(uint)4098, hardware=(boolean)true, description=(string)"AMD\ Radeon\ RX\ 6800\ XT";
0:00:00.221453000  4988 0000027BFB0D3AC0 ERROR             amfencoder gstamfencoder.cpp:878:gst_amf_encoder_submit_input:<amfh264device3enc0> SubmitInput returned AMF_INVALID_POINTER (7)
ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data stream error.
Redistribute latency...
Additional debug info:
../subprojects/gstreamer/libs/gst/base/gstbasesrc.c(3127): gst_base_src_loop (): /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0:
streaming stopped, reason error (-5)

I believe this is due to the fact that the 2 elements are sharing the GstD3D11Device from gst_d3d11_ensure_element_data_for_adapter_luid. If I force the creation of a new device for each encoder, than it's possible to use them in the same pipeline.

PS C:\gstreamer-amf\builddir> C:\gstreamer-amf\x86_64\bin\gst-launch-1.0.exe videotestsrc ! amfh264device3enc ! fakesink videotestsrc ! amfh264device4enc ! fakesink

** (gst-launch-1.0:11888): CRITICAL **: 17:55:41.086: pygobject initialization failed
Use Windows high-resolution clock, precision: 1 ms
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Got context from element 'amfh264device4enc0': gst.d3d11.device.handle=context, device=(GstD3D11Device)"\(GstD3D11Device\)\ d3d11device3", adapter=(uint)2, adapter-luid=(gint64)512792, device-id=(uint)29631, vendor-id=(uint)4098, hardware=(boolean)true, description=(string)"AMD\ Radeon\ RX\ 6800\ XT";
Got context from element 'amfh264device3enc0': gst.d3d11.device.handle=context, device=(GstD3D11Device)"\(GstD3D11Device\)\ d3d11device4", adapter=(uint)2, adapter-luid=(gint64)512792, device-id=(uint)29631, vendor-id=(uint)4098, hardware=(boolean)true, description=(string)"AMD\ Radeon\ RX\ 6800\ XT";
Redistribute latency...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
Redistribute latency...
New clock: GstSystemClock

Merge request reports