[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: amf_frc: don't use a staging texture to pass the input texture

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 17 11:26:33 UTC 2024



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
fa203ea4 by Steve Lhomme at 2024-10-17T10:51:09+00:00
amf_frc: don't use a staging texture to pass the input texture

There is a trick to set the slice array number on the D3D resource before submission.

(cherry picked from commit b25d56b220c95a5f8003c3af0706e5e80478163e) (rebased)
rebased:
- in 3.0 we code around is slightly different

- - - - -
524bd5de by Steve Lhomme at 2024-10-17T10:51:09+00:00
amf_frc: lock D3D11 context on QueryOutput()

(cherry picked from commit bf7ce0156d8713b5b1cef5d398f7ee3576567430)

- - - - -


1 changed file:

- modules/video_filter/amf_frc.c


Changes:

=====================================
modules/video_filter/amf_frc.c
=====================================
@@ -25,6 +25,8 @@
 
 #include <assert.h>
 
+static GUID  AMFVLCTextureArrayIndexGUID = { 0x28115527, 0xe7c3, 0x4b66, {0x99, 0xd3, 0x4f, 0x2a, 0xe6, 0xb4, 0x7f, 0xaf} };
+
 static const char *const ppsz_filter_options[] = {
     "frc-indicator", NULL
 };
@@ -36,7 +38,6 @@ struct filter_sys_t
 
     struct vlc_amf_context         amf;
     AMFComponent                   *amf_frc;
-    AMFSurface                     *amfInput;
     const d3d_format_t             *cfg;
 
     enum AMF_FRC_MODE_TYPE         mode;
@@ -79,39 +80,23 @@ static picture_t * Filter(filter_t *filter, picture_t *p_pic)
     picture_sys_t *src_sys = ActivePictureSys(p_pic);
 
     AMF_RESULT res;
-    AMFSurface *submitSurface;
-
-    AMFPlane *packedStaging = sys->amfInput->pVtbl->GetPlane(sys->amfInput, AMF_PLANE_PACKED);
-    ID3D11Resource *amfStaging = packedStaging->pVtbl->GetNative(packedStaging);
-
-#ifndef NDEBUG
-    ID3D11Texture2D *staging = (ID3D11Texture2D *)amfStaging;
-    D3D11_TEXTURE2D_DESC stagingDesc, inputDesc;
-    ID3D11Texture2D_GetDesc(staging, &stagingDesc);
-    ID3D11Texture2D_GetDesc(src_sys->texture[KNOWN_DXGI_INDEX], &inputDesc);
-    assert(stagingDesc.Width == inputDesc.Width);
-    assert(stagingDesc.Height == inputDesc.Height);
-    assert(stagingDesc.Format == inputDesc.Format);
-#endif
+    AMFSurface *submitSurface = NULL;
 
     struct filter_sys_t *dev_sys = sys;
 
-#if 0
-    if (src_sys->slice_index == 0)
-    sys->amf.Context->pVtbl->CreateSurfaceFromDX11Native(sys->amf.Context, )
-#endif
-    // copy source into staging as it may not be shared and we can't select a slice
-    d3d11_device_lock( &dev_sys->d3d_dev );
-    ID3D11DeviceContext_CopySubresourceRegion(dev_sys->d3d_dev.d3dcontext, amfStaging,
-                                            0,
-                                            0, 0, 0,
-                                            src_sys->resource[KNOWN_DXGI_INDEX],
-                                            src_sys->slice_index,
-                                            NULL);
-    d3d11_device_unlock( &dev_sys->d3d_dev );
-    submitSurface = sys->amfInput;
+    res = sys->amf.Context->pVtbl->CreateSurfaceFromDX11Native(sys->amf.Context, (void*)src_sys->resource[KNOWN_DXGI_INDEX], &submitSurface, NULL);
+    if (res != AMF_OK)
+    {
+        msg_Err(filter, "filter surface allocation failed (err=%d)", res);
+        if (submitSurface)
+            submitSurface->pVtbl->Release(submitSurface);
+        return p_pic;
+    }
+    amf_int subResourceIndex = src_sys->slice_index;
+    ID3D11Resource_SetPrivateData(src_sys->resource[KNOWN_DXGI_INDEX], &AMFVLCTextureArrayIndexGUID, sizeof(subResourceIndex), &subResourceIndex);
 
     res = sys->amf_frc->pVtbl->SubmitInput(sys->amf_frc, (AMFData*)submitSurface);
+    submitSurface->pVtbl->Release(submitSurface);
     if (res == AMF_INPUT_FULL)
     {
         msg_Dbg(filter, "filter input full, skip this frame");
@@ -127,7 +112,9 @@ static picture_t * Filter(filter_t *filter, picture_t *p_pic)
     bool got_output = sys->mode != FRC_x2_PRESENT;
     do {
         AMFData *amfOutput = NULL;
+        d3d11_device_lock( &dev_sys->d3d_dev ); // may consider to connect with AMFContext::LockDX11()/UnlockDX11()
         res = sys->amf_frc->pVtbl->QueryOutput(sys->amf_frc, &amfOutput);
+        d3d11_device_unlock( &dev_sys->d3d_dev );
         if (res != AMF_OK && res != AMF_REPEAT)
         {
             msg_Err(filter, "filter gave no output (err=%d)", res);
@@ -177,7 +164,6 @@ void D3D11CloseAMFFRC(vlc_object_t *p_this)
 {
     filter_t *filter = container_of(p_this, filter_t, obj);
     struct filter_sys_t *sys = filter->p_sys;
-    sys->amfInput->pVtbl->Release(sys->amfInput);
     sys->amf_frc->pVtbl->Release(sys->amf_frc);
     if (sys->d3d_dev.d3dcontext)
         D3D11_FilterReleaseInstance(&sys->d3d_dev);
@@ -323,14 +309,6 @@ int D3D11CreateAMFFRC(vlc_object_t *p_this)
     if (res != AMF_OK)
         goto error;
 
-    res = sys->amf.Context->pVtbl->AllocSurface(sys->amf.Context, AMF_MEMORY_DX11,
-                                                amf_fmt,
-                                                filter->fmt_in.video.i_width,
-                                                filter->fmt_in.video.i_height,
-                                                &sys->amfInput);
-    if (res != AMF_OK)
-        goto error;
-
     sys->cfg = cfg;
     filter->pf_video_filter = Filter;
     filter->p_sys = sys;
@@ -354,8 +332,6 @@ int D3D11CreateAMFFRC(vlc_object_t *p_this)
 error:
     if (sys->d3d_dev.d3dcontext)
         D3D11_FilterReleaseInstance(&sys->d3d_dev);
-    if (sys->amfInput)
-        sys->amfInput->pVtbl->Release(sys->amfInput);
     if (sys->amf_frc != NULL)
         sys->amf_frc->pVtbl->Release(sys->amf_frc);
     vlc_AMFReleaseContext(&sys->amf);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/941a927de9fc8a24452430dff9f2b7aea849f4c2...524bd5debd3dd6e37154b774d18d5d25d640393d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/941a927de9fc8a24452430dff9f2b7aea849f4c2...524bd5debd3dd6e37154b774d18d5d25d640393d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list