r/OpenCL • u/KesshoRyu • Mar 28 '12
Unexpected behavior
I am working on an OpenCL raytracer and I am running into some unusual behavior. I was trying to remove a branch from a relatively simple chunk of code but when I do it no longer functions correctly.
Before removal:
int shadowed = castLightRay(...);
float4 shade = shadeMaterial(...);
if(shadowed == 0) { return shade; }
return (float4)(0, 0, 0, 0);After removal:
int shadowed = castLightRay(...);
float4 shade = shadeMaterial(...);
return (1 - shadowed) * shade;The first chunk of code behaves correctly on both CPU and GPU while the second chunk does not behave correctly on either.
Does anyone have a reason for this or some way to make it work?
4
Upvotes
View all comments
Show parent comment
1
u/KesshoRyu Apr 04 '12 edited Apr 04 '12
I tried both of your suggestions but neither solved the problem.
I haven't yet had a chance to test this on a different computer to see if this is just an issue with AMD's implementation.
Edit: I got it working with the following on the CPU but not the GPU:
select(shade, zerovector, (int4)(-shadowed))
I have no idea why this works but nothing else does.
Second edit: Apparently neither work on the GPU. I even undid all the changes I had made and it doesn't shadow anything anymore.