-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScene.hpp
56 lines (46 loc) · 1.19 KB
/
Scene.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef GPU_RAY_TRACING_SCENE_HPP_
#define GPU_RAY_TRACING_SCENE_HPP_
#include "Hittable.hpp"
#include "Material.hpp"
#include "Preprocessor.hpp"
#include "types.hpp"
class scene {
public:
hittable *hittables;
int hittables_size;
int object_count;
material *materials;
int material_count;
public:
void free_host() {
delete hittables;
delete materials;
}
#ifdef USE_GPU
void free_device() {
cudaFree(hittables);
cudaFree(materials);
}
scene *copy_to_device() {
scene gpu_scene(*this);
{
const int size = sizeof(hittable) * hittables_size;
CUDA_CALL(cudaMalloc(&gpu_scene.hittables, size));
CUDA_CALL(
cudaMemcpy(gpu_scene.hittables, hittables, size, cudaMemcpyHostToDevice));
}
{
const int size = sizeof(material) * material_count;
CUDA_CALL(cudaMalloc(&gpu_scene.materials, size));
CUDA_CALL(cudaMemcpy(gpu_scene.materials, materials, size,
cudaMemcpyHostToDevice));
}
scene *d_scene;
CUDA_CALL(cudaMalloc(&d_scene, sizeof(scene)));
CUDA_CALL(
cudaMemcpy(d_scene, &gpu_scene, sizeof(scene), cudaMemcpyHostToDevice));
return d_scene;
}
#endif
};
#endif