directx – How to render AVFrames more efficiently?

I have currently got the frame on the GPU and can render it smoothly. I have a decoding thread and a rendering thread. The decoding thread puts the decoded pointer to the GPU into a List, and the rendering thread takes it from this List, creates a shared texture and copies it.

            textureLock_.lock();
            auto temp = decoders_[index]->frameDataList_.front();
            decoders_[index]->frameDataList_.pop_front();
            textureLock_.unlock();

            ID3D11Texture2D* t_frame = temp->texture;
            int t_index = temp->index;
            ComPtr device;
            t_frame->GetDevice(device.GetAddressOf());

            ComPtr deviceCtx;
            device->GetImmediateContext(&deviceCtx);

            ComPtr videoTexture;
            device->OpenSharedResource(d3ds_[index]->sharedHandle, __uuidof(ID3D11Texture2D), (void**)&videoTexture);
            deviceCtx->CopySubresourceRegion(videoTexture.Get(), 0, 0, 0, 0, t_frame, t_index, 0); //拷贝
            d3ds_[index]->RenderFrame(index);

But I found that CopySubresourceRegion consumes a lot of GPU in multi-threaded mode. At most 28 threads can be decoded and rendered at the same time. Is there any room for optimization?

I think the decoded frame is also a texture surface. Can I render this frame directly?

Read more here: Source link