So, I'm trying to port this raytracer to CUDA, and I'm running into some trouble when trying to adapt the code to test for collision with a list of hittable objects.
More specifically, I have the following code to test for collisions:
__device__ bool hittable_list_hit(const ray& r, double t_min, double t_max, hit_record& rec, uint8_t* data, int& offset) {
hit_record temp_rec = { point3(0,0,0), point3(0,0,0), 0.0, false };
bool hit_anything = false;
auto closest_so_far = t_max;
//printf("%f", temp_rec.t); <-- UNCOMMENTING THIS LINE MAKES CUDA CRASH
uint8_t size = data[offset++];
for (uint8_t i = 0; i < size; i++) {
if (top_level_hit(r, t_min, closest_so_far, temp_rec, data, offset)) {
hit_anything = true;
//closest_so_far = temp_rec.t;
//rec = temp_rec;
}
}
return hit_anything;
}
If I keep the highlighted line commented, the output of the program is a nice sky background (as in the raytracing tutorial). But if I uncomment it, the output is a black screen, and I suspect it might be a CUDA crash. It seems like reading this variable makes CUDA crash for some reason.
I'm relatively new to CUDA, so I have no clue why this might be happening. Does anybody have any idea on why reading a normal variable can cause this?
If it helps, this function is 4 levels deep after the kernel launch. Perhaps this nesting can cause problems?