yet another attempt to make Core_UMat.getUMat test work

pull/1901/head
Vadim Pisarevsky 11 years ago
parent 9be727b1ea
commit 82b852c13c
  1. 35
      modules/core/src/ocl.cpp

@ -2724,15 +2724,24 @@ public:
void sync(UMatData* u) const void sync(UMatData* u) const
{ {
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr(); cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
clFinish(q);
UMatDataAutoLock lock(u); UMatDataAutoLock lock(u);
if( u->hostCopyObsolete() && u->handle && if( u->hostCopyObsolete() && u->handle && u->refcount > 0 && u->origdata)
u->tempCopiedUMat() && u->refcount > 0 && u->origdata) {
if( u->tempCopiedUMat() )
{ {
clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0, clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0,
u->size, u->origdata, 0, 0, 0); u->size, u->origdata, 0, 0, 0);
}
else
{
cl_int retval = 0;
void* data = clEnqueueMapBuffer(q, (cl_mem)u->handle, CL_TRUE,
(CL_MAP_READ | CL_MAP_WRITE),
0, u->size, 0, 0, 0, &retval);
clEnqueueUnmapMemObject(q, (cl_mem)u->handle, data, 0, 0, 0);
clFinish(q);
}
u->markHostCopyObsolete(false); u->markHostCopyObsolete(false);
} }
else if( u->copyOnMap() && u->deviceCopyObsolete() && u->data ) else if( u->copyOnMap() && u->deviceCopyObsolete() && u->data )
@ -2753,12 +2762,24 @@ public:
CV_Assert(u->handle != 0 && u->urefcount == 0); CV_Assert(u->handle != 0 && u->urefcount == 0);
if(u->tempUMat()) if(u->tempUMat())
{ {
if( u->hostCopyObsolete() && u->refcount > 0 && u->tempCopiedUMat() ) if( u->hostCopyObsolete() && u->refcount > 0 )
{ {
clEnqueueReadBuffer((cl_command_queue)Queue::getDefault().ptr(), cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
(cl_mem)u->handle, CL_TRUE, 0, if( u->tempCopiedUMat() )
{
clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0,
u->size, u->origdata, 0, 0, 0); u->size, u->origdata, 0, 0, 0);
} }
else
{
cl_int retval = 0;
void* data = clEnqueueMapBuffer(q, (cl_mem)u->handle, CL_TRUE,
(CL_MAP_READ | CL_MAP_WRITE),
0, u->size, 0, 0, 0, &retval);
clEnqueueUnmapMemObject(q, (cl_mem)u->handle, data, 0, 0, 0);
clFinish(q);
}
}
u->markHostCopyObsolete(false); u->markHostCopyObsolete(false);
clReleaseMemObject((cl_mem)u->handle); clReleaseMemObject((cl_mem)u->handle);
u->handle = 0; u->handle = 0;

Loading…
Cancel
Save