Commit 00221e96 authored by Alexander Karsakov's avatar Alexander Karsakov

Fixed issue: Mat::copyTo(UMat) if device copy is obsolete. Added test.

parent d30729a8
...@@ -593,15 +593,16 @@ void* UMat::handle(int accessFlags) const ...@@ -593,15 +593,16 @@ void* UMat::handle(int accessFlags) const
if( !u ) if( !u )
return 0; return 0;
if ((accessFlags & ACCESS_WRITE) != 0)
u->markHostCopyObsolete(true);
// check flags: if CPU copy is newer, copy it back to GPU. // check flags: if CPU copy is newer, copy it back to GPU.
if( u->deviceCopyObsolete() ) if( u->deviceCopyObsolete() )
{ {
CV_Assert(u->refcount == 0); CV_Assert(u->refcount == 0);
u->currAllocator->unmap(u); u->currAllocator->unmap(u);
} }
if ((accessFlags & ACCESS_WRITE) != 0)
u->markHostCopyObsolete(true);
return u->handle; return u->handle;
} }
......
...@@ -745,6 +745,24 @@ TEST(UMat, Sync) ...@@ -745,6 +745,24 @@ TEST(UMat, Sync)
EXPECT_EQ(0, cvtest::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF)); EXPECT_EQ(0, cvtest::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF));
} }
TEST(UMat, CopyToIfDeviceCopyIsObsolete)
{
UMat um(7, 2, CV_8UC1);
Mat m(um.size(), um.type());
m.setTo(Scalar::all(0));
{
// make obsolete device copy of UMat
Mat temp = um.getMat(ACCESS_WRITE);
temp.setTo(Scalar::all(10));
}
m.copyTo(um);
um.setTo(Scalar::all(17));
EXPECT_EQ(0, cvtest::norm(um.getMat(ACCESS_READ), Mat(um.size(), um.type(), 17), NORM_INF));
}
TEST(UMat, setOpenCL) TEST(UMat, setOpenCL)
{ {
// save the current state // save the current state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment