-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintegrator_scheduler.h
87 lines (66 loc) · 2 KB
/
integrator_scheduler.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef _MONTE_CARLO_INTEGRATOR_SCHEDULER_H_
#define _MONTE_CARLO_INTEGRATOR_SCHEDULER_H_
#include "common.h"
#include "size.h"
#include "image.h"
#include "observable.h"
#include "sensor.h"
#include <queue>
using namespace std;
namespace Renzoku {
const int MAX_THREADS = 16;
const int MAX_HUNGRY = 128;
class IParallelIntegrator {
public:
inline int get_num_threads() const;
inline void set_num_threads(int threads);
protected:
int num_threads;
};
inline int IParallelIntegrator::get_num_threads() const {
return num_threads;
}
inline void IParallelIntegrator::set_num_threads(int threads) {
num_threads = threads;
if (num_threads > MAX_THREADS) {
num_threads = MAX_THREADS;
Log::info() << "Max number of threads supported is " << MAX_THREADS << endn;
}
}
class MonteCarloIntegrator;
/**
* The scheduler determines which parts on the image plane should be integrated
* and schedule for the integration.
*
* The integrator should not know about the rendering schedule or the display process.
*/
class IntegratorScheduler : public IParallelIntegrator {
public:
IntegratorScheduler();
void initialize(Scene *scene);
void start();
protected:
/**
* Simply unpack each ray and trace it. No parallel.
*/
void sequential(PrimaryRayBundles *bundles);
/**
* Queue each ray bundle to a pool for each worker thread to process.
*/
void queue(PrimaryRayBundles *bundles);
private:
void on_primary_ray_bundle_start(int tid, PrimaryRayBundle &bundle);
void on_primary_ray_bundle_done(int tid, PrimaryRayBundle &bundle);
void sample_pack_to_primary_ray_bundle(const SensorSamplePacks &packs, PrimaryRayBundles &bundles);
private:
void worker(int thread_index);
private:
Scene *scene;
FrameBuffer *frame;
MonteCarloIntegrator *integrator;
bool is_threads_launched;
std::queue<PrimaryRayBundle> bundle_pool; // keep copy of ray bundles
int hungry[MAX_THREADS];
};
} // end namespace
#endif