Results 1 to 2 of 2

Thread: write_imagef only writes correct color if read_imagef is used (OpenCL/OpenGL)

  1. #1
    Join Date
    May 2013

    write_imagef only writes correct color if read_imagef is used (OpenCL/OpenGL)


    I am trying to write on to a texture using CL kernel.
    void simpleGL(unsigned int width, unsigned int height, write_only image2d_t img1, read_only image2d_t img2, __global float4* res)
    int x = get_global_id(0);
    int y = get_global_id(1);

    sampler_t my_sampler = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
    float4 clr = read_imagef(img2,my_sampler, (float2)(x, y));
    float4 clr2 = (float4)(1,0,0,1);
    res[x * 1024 + y] = clr * 0.0 + clr2;
    write_imagef(img1, (int2)( x, y), res[x * 1024 + y]);

    Simply by adding clr * 0.0 shows correct color (in this case RED) as the output.
    But if I remove read call or delete the statement clr * 0.0, color turns white, whatever color I try to update. I assume there is some assumption by the driver that texture must be brought in to memory only if read is called and then will write work.
    Also if I make only WRITE_ONLY driver, I can't see other than white.
    I do create textures after OpenCL context is created.

    Any clue why.
    I am running my program on NVIDIA:
    Vendor: NVIDIA Corporation
    Renderer: GeForce GT 525M/PCIe/SSE2
    Version: 4.3.0
    GLSL: 4.30 NVIDIA via Cg compiler
    Context Profile: Compatibility

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Are you sure that the image memory has been flushed after your kernel has been called but before you read it?
    Last edited by utnapishtim; 05-21-2013 at 07:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts