From: Mark Thompson <sw@jkqxz.net> 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 Date: Wed, 29 Dec 2021 23:04:18 +0000 Message-ID: <0d168258-b2d3-f60e-87af-28b01e809038@jkqxz.net> (raw) In-Reply-To: <DM8P223MB036578CDD5AEA447DD2DE424BA629@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> On 25/11/2021 02:41, Soft Works wrote: > The test /libavutil/tests/hwdevice checks that when deriving a device > from a source device and then deriving back to the type of the source > device, the result is matching the original source device, i.e. the > derivation mechanism doesn't create a new device in this case. > > Previously, this test was usually passed, but only due to two different > kind of flaws: > > 1. The test covers only a single level of derivation (and back) > > It derives device Y from device X and then Y back to the type of X and > checks whether the result matches X. > > What it doesn't check for, are longer chains of derivation like: > > CUDA1 > OpenCL2 > CUDA3 and then back to OpenCL4 > > In that case, the second derivation returns the first device (CUDA3 == > CUDA1), but when deriving OpenCL4, hwcontext.c was creating a new > OpenCL4 context instead of returning OpenCL2, because there was no link > from CUDA1 to OpenCL2 (only backwards from OpenCL2 to CUDA1) Yes, this is exactly what I expect. Because of how these APIs work, device derivation is always one-way - you can make an OpenCL device from a D3D11 one, but not the other direction. I don't think there is any case which allows both directions (nor should there be, in general), so the possibilities form an acyclic graph. I do expect the user to know here what the possible-derivation graph looks like for the cases they want to use (since only a few cases are meaningful), though maybe it would be worth explicitly documenting it somewhere. There are then two non-overlapping operations combined in the device derivation function (when A -> B is the meaningful direction): * Given a context of type A, create a context of type B using the same physical device. * Given a context of type B, retrieve the original context of type A it was created from (if it exists). (Maybe they should have been separate functions to avoid this confusion, but it did fit rather nicely in how hwmap works. Saying that derivation from A should always return the same B is not intended, nor do I think it should be. The problem with doing that is that components can no longer tell whether the device they have is shared with someone else, whether they are in ffmpeg, in unrelated libraries, or in user code. What that actually means depends on the API, but in general it would ban doing anything which might affect another user of the same device, such as setting any global options or calling anything which might not be thread-safe. (Note that the global options argument in av_hwdevice_create_derived_opts() already violates this constraint, making the patch wrong as-is even if you do think it is reasonable to impose this constraint on all users.) > If the test would check for two levels of derivation, it would have > failed. > > This patch fixes those (yet untested) cases by introducing forward > references (derived_device) in addition to the existing back references > (source_device). > > 2. hwcontext_qsv didn't properly set the source_device > > In case of QSV, hwcontext_qsv creates a source context internally > (vaapi, dxva2 or d3d11va) without calling av_hwdevice_ctx_create_derived > and without setting source_device. What would go wrong if it did? > This way, the hwcontext test ran successful, but what practically > happened, was that - for example - deriving vaapi from qsv didn't return > the original underlying vaapi device and a new one was created instead: Er... how would it create a new device? The only type VAAPI can derive from is DRM. > Exactly what the test is intended to detect and prevent. It just > couldn't do so, because the original device was hidden (= not set as the > source_device of the QSV device). > > This patch properly makes these setting and fixes all derivation > scenarios. > > (at a later stage, /libavutil/tests/hwdevice should be extended to check > longer derivation chains as well) > > Signed-off-by: softworkz <softworkz@hotmail.com> > --- > v4: Fixed braces code style > > libavutil/hwcontext.c | 38 ++++++++++++++++++++++++++++++++++ > libavutil/hwcontext.h | 1 + > libavutil/hwcontext_internal.h | 6 ++++++ > libavutil/hwcontext_qsv.c | 13 +++++++++--- > 4 files changed, 55 insertions(+), 3 deletions(-) - 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".
next prev parent reply other threads:[~2021-12-29 23:04 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <cover.1637807570.git.softworkz@hotmail.com> [not found] ` <163785839519.25323.16303122737288435026@lain.red.khirnov.net> [not found] ` <163794332023.25323.7446601680884381987@lain.red.khirnov.net> [not found] ` <163795393240.7822.9483345286843818669@lain.red.khirnov.net> [not found] ` <DM8P223MB0365E3DFD61F63B305FC079BBA639@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> 2021-12-23 14:01 ` Xiang, Haihao 2021-12-27 3:08 ` Xiang, Haihao 2022-01-05 3:19 ` James Almer 2022-01-05 3:38 ` Xiang, Haihao 2022-01-09 18:39 ` Mark Thompson 2022-01-09 21:15 ` Soft Works 2022-01-09 23:12 ` Mark Thompson 2022-01-09 23:36 ` Soft Works 2022-01-10 0:56 ` Mark Thompson 2022-01-10 1:40 ` Soft Works 2022-01-10 6:47 ` Xiang, Haihao 2022-01-10 21:16 ` Mark Thompson 2022-01-11 7:01 ` Xiang, Haihao 2022-01-10 20:56 ` Mark Thompson 2022-01-12 5:15 ` Soft Works [not found] ` <DM8P223MB036578CDD5AEA447DD2DE424BA629@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> 2021-12-29 23:04 ` Mark Thompson [this message] 2021-12-30 0:29 ` Soft Works 2021-12-30 11:21 ` Mark Thompson 2021-12-30 19:20 ` Soft Works
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=0d168258-b2d3-f60e-87af-28b01e809038@jkqxz.net \ --to=sw@jkqxz.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git