From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 16040428F7 for ; Sun, 9 Jan 2022 23:12:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2DE5B68AE6D; Mon, 10 Jan 2022 01:12:52 +0200 (EET) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 79A526899A7 for ; Mon, 10 Jan 2022 01:12:46 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id s1so23510412wra.6 for ; Sun, 09 Jan 2022 15:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=VvRD/ZGXRdyIaaT27jWi07YN2FiNSShKi/G+04SX/Vo=; b=dNB/siHMeV/Ehy29Qvo60jwQH1Tu43R9/twmnNHKTIxSH0Uh0WfSb1pg4CcKuFF1Ht EkwSWS25fKmJ6Zz9616II82qIWrQKgCd04DHqUYQYkTARJrEM4plxlsbbOCtb+Jzyycw kFrlgrYCf0FjFHEMRgWATh0AGQGW43VBIA+Nibo9w88h5x05P57Nw3X1SxvoJP7z+xrA Fmr87BVT4T5Srp+KUgTUHTGoX8pDiUTeuxhdzcIPhhrwS3cRE/hEWl97JP1ZPKMW07SE oKkMJlVDrdHyntj2rk9Lrb6SXOSINDkvM/guAQsWrm6DpVf/ZB4zRdgV0Jd0liQyLcYN uvAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=VvRD/ZGXRdyIaaT27jWi07YN2FiNSShKi/G+04SX/Vo=; b=mX2KfRNvlfa6SOyLhr4BjB4UBJKD3u5aWb27aUvzPTckEYpC0LLjQMR430W+UA5x0g HqOKY6XzUEPPNnRaPau1xhwWCr7ALWcVSTjKZkiSYz+PY5jsruA+RDdSET0bmEYYVZYE VhPbMoR3rCYrM8WQpq6VnaySW2hnmGD1GI4qKVEU51FxAh3q/sx4MLsAU8TrU0ltwva4 2psKOWfhaEfdEPh+2ey9RBvGNCa3lviWIuSfM8GehReJZqjIiCpz2KxjFed6ExIzE/i9 ZjoXNUKgQGdUhwrvQAnnuptQTOYAGL46+0BODJqcEy1NPOVZ6ikUvvg+vmygR6wOTG99 ClPg== X-Gm-Message-State: AOAM530MGmPtFB7WCCP9Atoo/C88cBu83HDCxUrHQO/8OGYOpS8yxbI7 dAOAV0TPj/Ogr9iH1u/jL/7IdJX6sjjwiP5v X-Google-Smtp-Source: ABdhPJwhyRbJD2VOFaSHHVF6/tBSijS5j/Bcap0S2i3ZvSPaXSFkClBF8Ot4wM5YdEcZFQ7HoYIrgA== X-Received: by 2002:adf:d1cc:: with SMTP id b12mr66430940wrd.282.1641769965778; Sun, 09 Jan 2022 15:12:45 -0800 (PST) Received: from [192.168.0.11] (cpc91222-cmbg18-2-0-cust46.5-4.cable.virginm.net. [81.106.30.47]) by smtp.gmail.com with ESMTPSA id g5sm5400895wrd.100.2022.01.09.15.12.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Jan 2022 15:12:45 -0800 (PST) Message-ID: <97ce0944-17bc-6e89-160a-e103b77db861@jkqxz.net> Date: Sun, 9 Jan 2022 23:12:44 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <163785839519.25323.16303122737288435026@lain.red.khirnov.net> <163794332023.25323.7446601680884381987@lain.red.khirnov.net> <163795393240.7822.9483345286843818669@lain.red.khirnov.net> <50841f8a73c902d3fca896b1eda923d082b27383.camel@intel.com> <6c1f517dad96d2d6075cb69a30e1a50aefd3feb9.camel@intel.com> <1379ae9c-d8f9-7e32-260f-eff79ac1cfd7@gmail.com> <6cc00dffb915619af857283b9fb503e7aaeeb603.camel@intel.com> <595cea3f-43d1-e1fb-8541-c620cfd47090@jkqxz.net> From: Mark Thompson In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH v4 1/1] avutils/hwcontext: When deriving a hwdevice, search for existing device in both directions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 09/01/2022 21:15, Soft Works wrote: >> -----Original Message----- >> From: ffmpeg-devel On Behalf Of Mark >> Thompson >> Sent: Sunday, January 9, 2022 7:39 PM >> To: ffmpeg-devel@ffmpeg.org >> Subject: Re: [FFmpeg-devel] [PATCH v4 1/1] avutils/hwcontext: When deriving a >> hwdevice, search for existing device in both directions >> >> On 05/01/2022 03:38, Xiang, Haihao wrote: >>> ... this patch really fixed some issues for me and others. >> >> Can you explain this in more detail? >> >> I'd like to understand whether the issues you refer to are something which >> would be fixed by the ffmpeg utility allowing selection of devices for >> libavfilter, or whether they are something unrelated. >> >> (For library users the currently-supported way of getting the same device >> again is to keep a reference to the device and reuse it. If there is some >> case where you can't do that then it would be useful to hear about it.) > > Hi Mark, > > they have 3 workaround patches on their staging repo, but I'll let Haihao > answer in detail. > > I have another question. I've been searching high and low, yet I can't > find the message. Do you remember that patch discussion from (quite a > few) months ago, where it was about another QSV change (something about > device creation from the command line, IIRC). There was a command line > example with QSV and you correctly remarked something like: > "Do you even know that just for this command line, there are 5 device > creations happening in the background, implicit and explicit, and in > one case (or 2), it's not even creating the specified device but > a session for the default device instead" > (just roughly from memory) > > Do you remember - or was it Philip? > Anyway, this is something that the patch will improve. There has been one > other commit since that time regarding explicit device creation from > Haihao (iirc), which already reduced the device creation and fixed the > incorrect default session creation. Yes, the special ffmpeg utility code to work around the lack of AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX in the libmfx decoders caused confusion by working differently to everything else - implementing that and getting rid of the workarounds was definitely a good thing. > My patch tackles this from another side: at that time, you (or Philip) > explained that the secondary context that QSV requires (VAAPI, D3Dx) > and that is initially created when setting up the QSV device, does not > even get used when subsequently deriving to a context of that kind. > Instead, a new device is being created in this case. > > That's another scenario which is fixed by this patch. It does sound like you just always want a libmfx device to be derived from the thing which is really there sitting underneath it. Then it would be clear that derivation in the other direction would always have the retrieve-original-device meaning, rather than a fiction that you are deriving a new D3D device from a libmfx one which doesn't match what is actually happening. > It's a hybrid device context, that's the reason why QSV is more affected > than all other hwaccels as it consists of a QSV session already DERIVED > from a VAAPI or D3Dx device. > > Example (let's assume Windows with D3D9): You go into decoding with a > QSV decoder in a QSV context and then you want to use an OpenCL filter. > This requires an OpenCL context, and of course you want to share the > frames memory. For memory sharing, OpenCL requires the underlying context > of the QSV session - in this example D3D9. > > Before this patch - like you said - deriving devices was usually (except > reverse hwmap) forward-only. That means - you are stuck in this situation: > you could (forward-)derive to a D3D9 context, but that doesn't help: for > sharing the memory, you need to provide the original hw device to OpenCL, > you can't supply just another newly derived device of the same type. > And there is (was) no way to get the original hw context. If you are a library user then you get the original hw context by reusing the reference to it that you made when you created it. This includes libavfilter users, who can provide a hw device to each hwmap separately. If you are an ffmpeg utility user then I agree there isn't currently a way to do this for filter graphs, hence the solution of providing an a way in the ffmpeg utility to set hw devices per-filter. > Anyway I'm wondering whether it can even be logically valid to derive > from one device to another and then to another instance of the previous > device type. > From my understanding, "deriving" or "hw mapping" from one device to > another means to establish a different way or accessor to a common > resource/data, which means that you can access the data in one or the > other way. > > Now let's assume a forward device-derivation chain like this: > > D3D_1 >> OpenCL_1 >> D3D_2 You can't do this because device derivation is unidirectional (and acyclic) - you can only derive an OpenCL device from D3D (9 or 11), not the other way around. Similarly, you can only map frames from D3D to OpenCL. That's why the hwmap reverse option exists, because of cases where you actually want the other direction which doesn't really exist. (There are some cases like VAAPI <-> DRM which do offer frame mapping in both directions, but that's really because DRM does not itself have any frame management. Device derivation still only makes sense in one direction, as DRM sits beneath VAAPI.) > We have D3D surfaces, then we share them with OpenCL. Both *_1 > contexts provide access to the same data. > Then we derive again "forward only" and we get a new D3D_2 > context. It is derived from OpenCL_1, so it must provide > access to the same data as OpenCL_1 AND D3D_1. > > Now we have two different D3D contexts which are supposed to > provide access to the same data! > > > 1. This doesn't even work technically > - neither from D3D (iirc) > - nor from ffmpeg (not cleanly) > > 2. This doesn't make sense at all. There should always be > only a single device context of a device type for the same > resource > > 3. Why would somebody even want this - what kind of use case? The multiple derivation case is for when a single device doesn't work. Typically that involves multiple separate components which don't want to interact with the others, for example: * When something thread-unsafe might happen, so different threads need separate instances to work with. * When global options have to be set on a device, so a component which does that needs its own instance to avoid interfering with anyone else. * When some code (an external library, say) requires ownership of a device instance, so you need a new one to give to it. * When components are independent and your code is just simpler that way. Thanks, - Mark _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".