Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.
3075 Discussions

What's the correct usage of a shared handle of video surfaces in different d3d device with intel MSDK?

____2
Beginner
710 Views

In Intel media SDK samples6.0.0.36,  when create a  d3d9 surface, I should use a d3dallocator. It calls D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) to fulfill this task.

Innerly, AllocImpl() callsIDirectXVideoAccelerationService::CreateSurface(
  [in]      UINT              Width,
  [in]      UINT              Height, [in]      UINT              BackBuffers,
  [in]      D3DFORMAT         Format,
  [in]      D3DPOOL           Pool,
  [in]      DWORD             Usage,
  [in]      DWORD             DxvaType,
  [out]     IDirect3DSurface9 **ppSurface,
  [in, out] HANDLE            *pSharedHandle)

to create d3d9 surfaces. use it like:

if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
        for (int i = 0; i < request->NumFrameSuggested; i++) {
            hr = videoService->CreateSurface(request->Info.Width, request->Info.Height, 0,  format,
                                                D3DPOOL_DEFAULT, m_surfaceUsage, target, &dxMids.m_surface, &dxMids.m_handle);

            if (FAILED(hr)) {
                ReleaseResponse(response);
                MSDK_SAFE_FREE(dxMids);
                return MFX_ERR_MEMORY_ALLOC;
            }
            dxMidPtrs = &dxMids;
        }

It pass a handle to the parameter pSharedHandle to get a handle out. But It didn't specify how to use this handle.

I searched MSDN, it says:

pSharedHandle [in, out]

A pointer to a handle that is used to share the surfaces between Direct3D devices. Set this parameter to NULL.

Then I searched another sample Interoperability with Intel® Media SDK. It use this pSharedHandle as the input of clCreateFromDX9MediasurfaceKHR aims to create a memory object shared by opencl and d3d9. Besides of this, I havn't seen a sample shows how to use this pSharedHandle.

In my application, I need a method with which I can share surfaces between different devices. It seems that this pSharedHandle  give by CreateSurface could make a contribution. But I don't know how.

0 Kudos
1 Reply
Harshdeep_B_Intel
710 Views

Hello there, 

Apologies in  delay on response. So, let first start with updating to latest MSDK and samples. Latest MSDK ver.  6.0.0.49 and samples ver. 6.0.0.68. Now in regard to pSharedHandle parameter is used in Direct3d9 to share between resources (devices and processes). In this case resource included the render target surface also. pSharedHandle is a HANDLE that points to shared resource and to open or access any previously created shared resources you just have to set pSharedHandle to the address of that previous handle. There is a blog on MSDN with explains APIs which include this handle and how handle can be used to share surfaces between different devices: https://msdn.microsoft.com/en-us/library/windows/desktop/bb219800 . Please take a look at Sharing Resources section. Hope this is the information you are looking for!

Thanks, 

0 Kudos
Reply