No I can not. When I try to strip away all unnecessary code I get a “unspecified launch error”. Supposedly that happens when you’re writing uninitialized variable to memory (should that be an error?) so I’ve made sure all variables are initialized before use. Unce I get that error the driver seems to be in an incorrect state and every graphics application will get a flickering noise in the screen.
Here is the function causing all the trouble.
device bool Trace(float3 pos, float3 dir, float3& normal, float3& color, float3& hitPoint)
bool hitAnything = false;
float dist = 50.0;
float3 hitCenter = make_float3(0.0f, 0.0f, 0.0f);
const int sphereCount = 4;
spheres = make_float4(0.0f, 0.0f, -10.0f, 10.0f);
colors = make_float3(1.0f, 0.0f, 1.0f);
spheres = make_float4(-2.0f, -2.0f, 1.0f, 1.0f);
colors = make_float3(1.0f, 0.0f, 0.0f);
spheres = make_float4(2.0f, -2.0f, 1.0f, 1.0f);
colors = make_float3(0.0f, 1.0f, 0.0f);
spheres = make_float4(-2.0f, 2.0f, 1.0f, 1.0f);
colors = make_float3(0.0f, 0.0f, 1.0f);
color = make_float3(0.5f, 0.5f, 1.0f);
for(int i=0; i<sphereCount; i++)
float4 sphere = spheres[i];
if( RaySphere( pos, dir, make_float3(sphere.x, sphere.y, sphere.z), sphere.w, dist) )
hitCenter = make_float3(sphere.x, sphere.y, sphere.z);
color = colors[i];
hitAnything = true;
hitPoint = pos + dir*dist;
normal = normalize( hitPoint - hitCenter );
The calling code should be ok. I’ve used it to call a much more complex trace function without any problem. I just needed a simple and fast Trace function so I could experiment with different MLT strategies when I ran into these problems.
By just adding float3 newColor = colors[i]; before the branch and exchange colors[i] against newColor both problems disapear. Doesn’t feel very stable to me.