Results 1 to 3 of 3

Thread: Issue writing to constant buffer

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    4

    Issue writing to constant buffer

    Hi i have a constant buffer that contains a struct that has a few different params required for kernel execution which needs to be updated every frame, however the entire buffer doesn't seem to get written, some of the members do not get their values updated. The struct is 88 bytes in size, and only the first 84 bytes get written correctly. The cl code looks like this:

    Code :
    typedef struct 
    {	
    	float16 invWorldView;
    	int3 size;
    	float3 invSize;
    } Params;
     
    __kernel void VolRT(__write_only image2d_t bmp, __read_only image3d_t volTex, __constant Params* params)
    {
    ...
    The application code allocates and updates the buffer with the following calls:

    Code :
    ocl.paramBuffer = clCreateBuffer(ocl.context, CL_MEM_READ_ONLY, sizeof(RTParams), NULL, &resultCL);   //allocate
    clSetKernelArg(ocl.rtKernel, 2, sizeof(cl_mem), &ocl.paramBuffer);   //assign to third kernel arg
    clEnqueueWriteBuffer(ocl.queue, ocl.paramBuffer, true, 0, sizeof(RTParams), &RTParams, 0, NULL, NULL);   //update
    RTParams looks like this:

    Code :
    struct
    {		
    	float invWorldView[16];
    	int sizeX;
    	int sizeY; 
    	int sizeZ;
    	float invSize[3];
    } RTParams;
    Can anyone shed any light on this?

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    4

    Re: Issue writing to constant buffer

    Seems to be an alignment issue, changing the float3 and int3 to float4 and int4 respectively fixed the problem

  3. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Issue writing to constant buffer

    Quote Originally Posted by slicedpan
    Seems to be an alignment issue, changing the float3 and int3 to float4 and int4 respectively fixed the problem
    FWIW this is covered in the specification. type3's are aligned to type4 in memory.

Similar Threads

  1. constant memory issue
    By roger512 in forum OpenCL
    Replies: 4
    Last Post: 05-08-2013, 11:29 AM
  2. Replies: 4
    Last Post: 05-11-2010, 04:56 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
  •