6 Replies Latest reply on Feb 24, 2010 2:00 PM by twiig

    opencl function problems

    twiig

      So, I have a chunk of code that generates a ray for ray tracing purposes, but when I move the ray creation to its own function, it no longer works.  Literally, I can move the exact same chunk of code to a function that returns the created ray, and it no longer works.

      Any ideas?

      ie, //works fine <create ray code>; <use ray code>; //doesnt work Ray CreateRay() { <create ray code>; return ray; } ... Ray ray = CreateRay(); <use ray code>

        • opencl function problems
          nou

          IIRC there was some issue if function return struct.

          • opencl function problems
            MicahVillmow
            We should not have any trouble with structs. If you can't post your code publicly, please send a test case to streamdeveloper@amd.com Re: Micah Villmow and i'll see what is wrong with your kernel.
              • opencl function problems
                twiig

                no problem posting the code ... nothing too new here.  Thanks for the help!

                ps. I left out some code, because if you were going to run the whole project it would be very difficult as I use a custom 3D API to setup the project.

                typedef struct { float length; float4 origin; float4 direction; } clRay; float4 GenerateRay(float width, float height, float near, float far, float rx, float ry, float rz, float16 mat) { rx = rx * 2.0f / width - 1.0f; ry = ry * 2.0f / height - 1.0f; rz = rz * 2.0f - 1.0f; float rw = mat.sc*rx + mat.sd*ry + mat.se*rz + mat.sf; rw = (rw == 0.0f ? 1.0f : rw); float4 v; v.x = (mat.s0*rx + mat.s1*ry + mat.s2*rz + mat.s3) / rw; v.y = (mat.s4*rx + mat.s5*ry + mat.s6*rz + mat.s7) / rw; v.z = (mat.s8*rx + mat.s9*ry + mat.sa*rz + mat.sb) / rw; v.w = 1.0f; return v; } clRay GenerateReverseOrthographicRay(const float width, const float height, const float near, const float far, const float4 eye_or_dir, const float16 inverseViewProjection, float x, float y, float depth) { float rz = (depth - near) / (far - near); float4 point = GenerateRay(width, height, near, far, x, y, rz, inverseViewProjection); clRay ray; ray.origin = point; ray.direction = eye_or_dir; ray.length = depth - near; return ray; } //this works __kernel void TraceRay0(const int width, const int height, const float near, const float far, const float4 eye_or_dir, const float16 inverseViewProjection, , const float4 nvoxels, const float vsize, const __global float *depths, __global clVoxel *voxels) { ... float rz = (depth - near) / (far - near); float4 point = GenerateRay(width, height, near, far, x, y, rz, inverseViewProjection); clRay ray; ray.origin = point; ray.direction = eye_or_dir; ray.length = depth - near; ... } //this does not work __kernel void TraceRay1(const int width, const int height, const float near, const float far, const float4 eye_or_dir, const float16 inverseViewProjection, , const float4 nvoxels, const float vsize, const __global float *depths, __global clVoxel *voxels) { ... clRay ray = GenerateReverseOrthographicRay(width, height, near, far, eye_or_dir, inverseViewProjection, x, y, depth); ... }

              • opencl function problems
                MicahVillmow
                twiig,
                Can you make a CL kernel that is all inclusive and compiles? That way I don't have to guess about your intentions and can more accurately reproduce your issue.

                Thanks,
                Micah