Commit e30875bc authored by Ilya Lavrenov's avatar Ilya Lavrenov

fixed UMat sync problems

parent b43d6b68
...@@ -580,7 +580,6 @@ Mat UMat::getMat(int accessFlags) const ...@@ -580,7 +580,6 @@ Mat UMat::getMat(int accessFlags) const
Mat hdr(dims, size.p, type(), u->data + offset, step.p); Mat hdr(dims, size.p, type(), u->data + offset, step.p);
hdr.flags = flags; hdr.flags = flags;
hdr.u = u; hdr.u = u;
hdr.flags = flags;
hdr.datastart = u->data; hdr.datastart = u->data;
hdr.data = hdr.datastart + offset; hdr.data = hdr.datastart + offset;
hdr.datalimit = hdr.dataend = u->data + u->size; hdr.datalimit = hdr.dataend = u->data + u->size;
...@@ -588,11 +587,14 @@ Mat UMat::getMat(int accessFlags) const ...@@ -588,11 +587,14 @@ Mat UMat::getMat(int accessFlags) const
return hdr; return hdr;
} }
void* UMat::handle(int /*accessFlags*/) const 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() )
{ {
......
...@@ -237,3 +237,17 @@ TEST(Core_UMat, getUMat) ...@@ -237,3 +237,17 @@ TEST(Core_UMat, getUMat)
EXPECT_EQ(err, 0.); EXPECT_EQ(err, 0.);
} }
} }
TEST(UMat, Sync)
{
UMat um(10, 10, CV_8UC1);
{
Mat m = um.getMat(ACCESS_WRITE);
m.setTo(cv::Scalar::all(17));
}
um.setTo(cv::Scalar::all(19));
EXPECT_EQ(0, cv::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF));
}
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