-
-
Notifications
You must be signed in to change notification settings - Fork 55.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redesign of CL/VA interop initialization #22780
base: 4.x
Are you sure you want to change the base?
Redesign of CL/VA interop initialization #22780
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VideoCapture/VideoWriter
?
We should not have this in generic functions.
Why is CV_Error()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) VADisplay
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;
full example: https://github.com/kallaballa/OpenCV-Issues/blob/main/src/vaapi-decode-encode/vaapi-decode-encode.cpp
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. |
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.