为什么我不能映射映射的缓冲区:
void* map_ptr = clEnqueueMapImage(d->GetQueue(), DeviceMem, CL_TRUE, CL_MAP_WRITE, HostOrigin, Region, &HostRowPitch, &HostSlicePitch, 0, NULL, NULL, NULL);
memcpy(map_ptr, Data, HostWidth * HostHeight * sizeof(unsigned int)); ///ERROR ????????????
*Error = clEnqueueUnmapMemObject(d->GetQueue(), DeviceMem, map_ptr, 0, NULL, NULL);
CreateBuffer是:
cl_mem temp = clCreateBuffer(d->GetContext(), CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, Size, NULL, Error);
HostSlicePitch!= 0
size_t HostOrigin[3] = {0,0,0};
size_t Region[3] = {sizeof(unsigned int)*HostWidth, HostHeight, HostDepth};
答案 0 :(得分:0)
解决了! 在地图和UnMap之间需要clFlush。 https://github.com/CyberRSR/OpenCLV
void* map_ptr = clEnqueueMapBuffer(d->GetQueue(), DeviceMem, CL_TRUE, CL_MAP_WRITE, 0, HostWidth*HostHeight*HostDepth, NULL, NULL, d->GetEvent(), Error);
clFlush(d->GetQueue());
d->ThrowMemEvent(DeviceMem);
memcpy(map_ptr, Data, HostWidth*HostHeight*HostDepth*sizeof(unsigned int));
*Error = clEnqueueUnmapMemObject(d->GetQueue(), DeviceMem, map_ptr, 0, NULL, d->GetEvent());