diff options
author | Keuin <[email protected]> | 2022-04-17 18:21:41 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-17 18:21:41 +0800 |
commit | 23b2d8939528bd44a40702482ef50d7b8c063254 (patch) | |
tree | dd6bf823193cc074a31eddee2b1d1cbe7d9651be | |
parent | 82c24472a4bf9463d39cbb2db0d06cbbf151fe2f (diff) |
Configurable thread count.
-rw-r--r-- | aa.h | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -18,9 +18,11 @@ template<typename T> class aa_viewport : public viewport<T> { unsigned samples; std::vector<basic_viewport<T>> *subviews; + int threads; public: - aa_viewport(double width, double height, vec3d viewport_center, unsigned samples) : samples(samples) { + aa_viewport(double width, double height, vec3d viewport_center, unsigned samples, int threads = -1) + : samples(samples), threads{(threads > 0) ? threads : (int)std::thread::hardware_concurrency()} { assert(samples >= 1); subviews = new std::vector<basic_viewport<T>>{samples, {width, height, viewport_center}}; } @@ -31,9 +33,9 @@ public: virtual bitmap<T> render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) { static constexpr auto seed = 123456789012345678ULL; - const unsigned thread_count = std::min(std::thread::hardware_concurrency(), samples); + const unsigned thread_count = std::min((unsigned)threads, samples); std::cerr << "Preparing tasks..." << std::endl; - std::vector<bitmap<T>> images{samples, {0,0}}; + std::vector<bitmap<T>> images{samples, {0, 0}}; std::mt19937_64 seedgen{seed}; // generates seeds for workers const struct s_render_shared { |