Sergei Merekin
Sergei Merekin

Reputation: 45

OpenCL returns "OUT_OF_RESOURCES" error when loading an RGB texture-buffer and everything works fine with RGBA

OpenCL stubbornly refuses to load three-component textures, but if you add an empty fourth component, everything works fine. I suppose this is some kind of hardware limitation associated with the power of 2? Is it possible to solve it?

Doesn't work ("OUT_OF_RESOURCES"):

img = Image.open(path + "\color_" + str(n).zfill(4) + ".jpg")
temp_colors = np.asarray(img, dtype=np.uint8).tobytes();
clImageFormat = cl.ImageFormat(cl.channel_order.RGB,
                               cl.channel_type.UNSIGNED_INT8)
input_cols = cl.Image(context,
                       cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR,
                       clImageFormat,
                       imgSize,
                       None,
                       temp_colors)

Now works fine:

img = Image.open(path + "\color_" + str(n).zfill(4) + ".jpg")
temp_colors = np.asarray(img, dtype=np.uint8)
zeros=np.zeros((500,500,1), dtype=np.uint8)
temp_colors=np.concatenate((temp_colors,zeros), axis=2).tobytes();
clImageFormat = cl.ImageFormat(cl.channel_order.RGBA,
                               cl.channel_type.UNSIGNED_INT8)
input_cols = cl.Image(context,
                       cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR,
                       clImageFormat,
                       imgSize,
                       None,
                       temp_colors)

The kernel contains just an empty function accepting an image2d_t

Upvotes: 0

Views: 110

Answers (1)

doqtor
doqtor

Reputation: 8484

By OpenCL spec:

For 3-component vector data types, the size of the data type is 4 * sizeof(component). This means that a 3-component vector data type will be aligned to a 4 * sizeof(component) boundary.

Upvotes: 1

Related Questions