Repository navigation
Redesign of CL/VA interop initialization - #22780
kallaballa wants to merge 13 commits into
Conversation
d57a32a to
1ba0984
Compare
|
I don't know what exactly happened. I force pushed to my own branch.. and then this |
|
I pushed an empty branch which made it auto close. now things should be back to fine |
|
I drafted a fallback-less version of VA initialization that does not work with my reproducer. 2875b0b |
|
It after all still boils down to opencv/modules/videoio/src/cap_ffmpeg_hw.hpp Line 478 in 64aad34 being called twice and failing. |
|
Apart from fixing an error in my system setup, I think i have the behavior like you wanted. That also required changes to my reproducer which now works (but is code-wise a little cumbersome). This needs a better design, especially in cases where different interop-systems are used at the same time. Reproducer before (fails) : vaapi-decode-encode.cpp Reproducer now (succeeds) : vaapi-decode-encode.cpp Anyway as I mentioned above i have a proposal for how this could work, based on my 4.x fork: https://github.com/kallaballa/GCV/blob/main/src/video/video-demo.cpp I isolated the dirty hack that made my demo work in a separate branch Now... how to do it properly? |
…ze the context automatically if it isn't already
Reproducer works now as initially proposed, except now there isn't an interop fallback anymore: vaapi-decode-encode.cpp
Also the demo would now work like that (except it requires #22704)
I moved On the other hand if the user decides to manually call What do you think? |
|
Simplified the reproducer |
|
Updated the proposal/demo which demonstrates how CL/GL and CL/VA interop could be used together by copying and binding ocl_contexts as needed. |
7b723c5 to
f161534
Compare
Ensured by throwing an error on VADisplay mismatch: 497a536 |
f161534 to
497a536
Compare
alalek
left a comment
There was a problem hiding this comment.
Thank you for the updates!
Sorry for delay. I'm a busy till the end of this week.
| { | ||
| VAAPIInterop* interop = ocl_context.getContext().getUserContext<VAAPIInterop>().get(); | ||
| if(!context_display || context_display != display) | ||
| CV_Error_(cv::Error::StsBadArg, ("Can't interop with current OpenCL context - VA display mismatch: %p (context) vs %p (surface).\ndid you call initializeContextFromVA before using VideoCapture/VideoWriter?", context_display, (void*)display)); |
There was a problem hiding this comment.
VideoCapture/VideoWriter
?
We should not have this in generic functions.
Why is CV_Error()?
There was a problem hiding this comment.
I think you are right about this. Should be debug? I'll test.
| va_intel::ocl::initializeContextFromVA(va_display); | ||
| } | ||
| } else { | ||
| CV_LOG_DEBUG(NULL, "OpenCL/VA_INTEL: CL/VA interop already initialized. ") |
There was a problem hiding this comment.
If there is HW_ACCELERATION_USE_OPENCL=1 then we should initialize context anyway (as this is explicitly requested by user through dedicated property).
Is there a way to check if OpenCL context could serve for compatible (but different) VADisplays?
There was a problem hiding this comment.
I try to find one but initializing anyway would lead to the situation we had with different VADisplays and no VA-capability
There was a problem hiding this comment.
Also, when the user sets HW_ACCELERATION_USE_OPENCL=1 on both VideoCapture and VideoWriter in the same program tha would lead again to the situation with two different VADisplays.
There was a problem hiding this comment.
So this wouldn't benefit from VA:
cv::VideoCapture capture("in.mkv", cv::CAP_FFMPEG, {
cv::CAP_PROP_HW_DEVICE, VA_HW_DEVICE_INDEX,
cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI,
cv::CAP_PROP_HW_ACCELERATION_USE_OPENCL, 1
});
cv::VideoWriter writer("out.mkv", cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, cv::Size(width, height), {
cv::VIDEOWRITER_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI,
cv::VIDEOWRITER_PROP_HW_ACCELERATION_USE_OPENCL, 1
});
cv::UMat frame;
capture >> frame;
writer << frame;There was a problem hiding this comment.
Can we come up with a way that will provide proper context handling (and therefore actual acceleration) while not introducing breaking changes? I value this PR a lot and I am willing to put considerably more effort into it.
|
I've experimented with partly parallel implementations of the WASM versions of my demos and the current VA initialization pattern is really in the way because the native implementation differs greatly from the WASM implementation and suffers from the above mentioned defects. It would be great if we could outline requirements on an initialization pattern so i can create a proper pull request and resolve this issue. |
|
Please checkout https://github.com/opencv/opencv/pull/22780/files#r1031421488 for why this stalled. I'd love some direction on this one. |
There was a problem hiding this comment.
Status: 🔴 Red
Verdict: Refactor before merge.
Retain slow-copy and backend-probing fallbacks when VA contexts differ; context mismatch should not turn previously supported operations into hard failures.
Please address this in the current PR and add focused regression coverage where applicable.
The pertaining issue: #22779
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.