mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
core(ocl): fix lifetime handling of Image kernel args
This commit is contained in:
parent
68fb8dd873
commit
212815a10d
@ -2802,16 +2802,24 @@ struct Kernel::Impl
|
|||||||
haveTempSrcUMats = true; // UMat is created on RAW memory (without proper lifetime management, even from Mat)
|
haveTempSrcUMats = true; // UMat is created on RAW memory (without proper lifetime management, even from Mat)
|
||||||
}
|
}
|
||||||
|
|
||||||
void addImage(const Image2D& image)
|
/// Preserve image lifetime (while it is specified as Kernel argument)
|
||||||
|
void registerImageArgument(int arg, const Image2D& image)
|
||||||
{
|
{
|
||||||
images.push_back(image);
|
CV_CheckGE(arg, 0, "");
|
||||||
|
CV_CheckLT(arg, (int)MAX_ARRS, "");
|
||||||
|
if (arg < (int)shadow_images.size() && shadow_images[arg].ptr() != image.ptr()) // TODO future: replace ptr => impl (more strong check)
|
||||||
|
{
|
||||||
|
CV_Check(arg, !isInProgress, "ocl::Kernel: clearing of pending Image2D arguments is not allowed");
|
||||||
|
}
|
||||||
|
shadow_images.reserve(MAX_ARRS);
|
||||||
|
shadow_images.resize(std::max(shadow_images.size(), (size_t)arg + 1));
|
||||||
|
shadow_images[arg] = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void finit(cl_event e)
|
void finit(cl_event e)
|
||||||
{
|
{
|
||||||
CV_UNUSED(e);
|
CV_UNUSED(e);
|
||||||
cleanupUMats();
|
cleanupUMats();
|
||||||
images.clear();
|
|
||||||
isInProgress = false;
|
isInProgress = false;
|
||||||
release();
|
release();
|
||||||
}
|
}
|
||||||
@ -2836,7 +2844,7 @@ struct Kernel::Impl
|
|||||||
bool isInProgress;
|
bool isInProgress;
|
||||||
bool isAsyncRun; // true if kernel was scheduled in async mode
|
bool isAsyncRun; // true if kernel was scheduled in async mode
|
||||||
int nu;
|
int nu;
|
||||||
std::list<Image2D> images;
|
std::vector<Image2D> shadow_images;
|
||||||
bool haveTempDstUMats;
|
bool haveTempDstUMats;
|
||||||
bool haveTempSrcUMats;
|
bool haveTempSrcUMats;
|
||||||
};
|
};
|
||||||
@ -2978,9 +2986,11 @@ int Kernel::set(int i, const void* value, size_t sz)
|
|||||||
|
|
||||||
int Kernel::set(int i, const Image2D& image2D)
|
int Kernel::set(int i, const Image2D& image2D)
|
||||||
{
|
{
|
||||||
p->addImage(image2D);
|
|
||||||
cl_mem h = (cl_mem)image2D.ptr();
|
cl_mem h = (cl_mem)image2D.ptr();
|
||||||
return set(i, &h, sizeof(h));
|
int res = set(i, &h, sizeof(h));
|
||||||
|
if (res >= 0)
|
||||||
|
p->registerImageArgument(i, image2D);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Kernel::set(int i, const UMat& m)
|
int Kernel::set(int i, const UMat& m)
|
||||||
|
Loading…
Reference in New Issue
Block a user