@@ -2802,16 +2802,24 @@ struct Kernel::Impl
2802
2802
haveTempSrcUMats = true ; // UMat is created on RAW memory (without proper lifetime management, even from Mat)
2803
2803
}
2804
2804
2805
- void addImage (const Image2D& image)
2805
+ // / Preserve image lifetime (while it is specified as Kernel argument)
2806
+ void registerImageArgument (int arg, const Image2D& image)
2806
2807
{
2807
- images.push_back (image);
2808
+ CV_CheckGE (arg, 0 , " " );
2809
+ CV_CheckLT (arg, (int )MAX_ARRS, " " );
2810
+ if (arg < (int )shadow_images.size () && shadow_images[arg].ptr () != image.ptr ()) // TODO future: replace ptr => impl (more strong check)
2811
+ {
2812
+ CV_Check (arg, !isInProgress, " ocl::Kernel: clearing of pending Image2D arguments is not allowed" );
2813
+ }
2814
+ shadow_images.reserve (MAX_ARRS);
2815
+ shadow_images.resize (std::max (shadow_images.size (), (size_t )arg + 1 ));
2816
+ shadow_images[arg] = image;
2808
2817
}
2809
2818
2810
2819
void finit (cl_event e)
2811
2820
{
2812
2821
CV_UNUSED (e);
2813
2822
cleanupUMats ();
2814
- images.clear ();
2815
2823
isInProgress = false ;
2816
2824
release ();
2817
2825
}
@@ -2836,7 +2844,7 @@ struct Kernel::Impl
2836
2844
bool isInProgress;
2837
2845
bool isAsyncRun; // true if kernel was scheduled in async mode
2838
2846
int nu;
2839
- std::list <Image2D> images ;
2847
+ std::vector <Image2D> shadow_images ;
2840
2848
bool haveTempDstUMats;
2841
2849
bool haveTempSrcUMats;
2842
2850
};
@@ -2978,9 +2986,11 @@ int Kernel::set(int i, const void* value, size_t sz)
2978
2986
2979
2987
int Kernel::set (int i, const Image2D& image2D)
2980
2988
{
2981
- p->addImage (image2D);
2982
2989
cl_mem h = (cl_mem)image2D.ptr ();
2983
- return set (i, &h, sizeof (h));
2990
+ int res = set (i, &h, sizeof (h));
2991
+ if (res >= 0 )
2992
+ p->registerImageArgument (i, image2D);
2993
+ return res;
2984
2994
}
2985
2995
2986
2996
int Kernel::set (int i, const UMat& m)
0 commit comments