From ba97aeb0a6ff52b79f43f883c639a55c8e3cf78d Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 20 Apr 2022 00:48:44 +0800 Subject: Reserve vector thread_pool::tasks to speed up task initializing. --- aa.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'aa.h') diff --git a/aa.h b/aa.h index 3a4def4..9622696 100644 --- a/aa.h +++ b/aa.h @@ -50,6 +50,26 @@ public: assert(samples >= 1); } + aa_viewport(const vec3 &cxyz, + const vec3 &screen_center, + uint16_t image_width, + uint16_t image_height, + double fov_h, + hitlist &world, + unsigned samples, + int threads = -1) : + cxyz(cxyz), + screen_center(screen_center), + image_width(image_width), + image_height(image_height), + screen_hw{(cxyz - screen_center).norm() * tan((double) fov_h / 2.0)}, + screen_hh{screen_hw * ((double) image_height / image_width)}, + world(world), + samples(samples), + threads((threads > 0) ? threads : (int) std::thread::hardware_concurrency()) { + assert(samples >= 1); + } + bitmap render() { static constexpr auto seed = 123456789012345678ULL; const unsigned thread_count = std::min((unsigned) threads, samples); @@ -62,7 +82,7 @@ public: uint64_t diffuse_seed; }; - thread_pool pool{thread_count, *this, images}; + thread_pool pool{thread_count, *this, images, samples}; timer tim{true}; std::cerr << "Seeding tasks..." << std::endl; -- cgit v1.2.3