将 SFML 图像发送到 OpenCL

Sending an SFML Image to OpenCL

我正在尝试将 SFML 图像发送到 OpenCL。但我只得到损坏的数据。我的猜测是我错误地处理了 pixelData,但我不知道如何正确处理:/

void ImageWindow::xBlend() 
{
    size_t size = sizeof(cl_uchar4) * textureSize.x * textureSize.y;

    cl::Buffer bufferIn(manager->context, CL_MEM_READ_ONLY, size);
    cl::Buffer bufferOut(manager->context, CL_MEM_WRITE_ONLY, size);

    auto pixelData = (cl_uchar4*)image.getPixelsPtr();

    manager->queue.enqueueWriteBuffer(bufferIn, CL_TRUE, 0, size, pixelData);
    functorXBlend(bufferIn, bufferOut);

    manager->queue.enqueueReadBuffer(bufferOut, CL_TRUE, 0, size, pixelData);
    newTexture.update(image);
}

我自己发现错误。有史以来最愚蠢的错误。上面的代码是正确的,问题是我弄乱了local worksize

functorXBlend = cl::KernelFunctor(
    cl::Kernel(manager->program, "xBlend"), 
    manager->queue, cl::NullRange, 
    cl::NDRange(textureSize.x, textureSize.y), 
    cl::NullRange);

相反,我有这个:

functorXBlend = cl::KernelFunctor(
    cl::Kernel(manager->program, "xBlend"), 
    manager->queue, cl::NullRange, 
    cl::NDRange(textureSize.x, textureSize.y), 
    cl::NDRange(textureSize.x, textureSize.y));