Use multiple threads to import HDR images
This commit is contained in:
parent
7e79aead99
commit
2cf5927920
|
@ -30,8 +30,8 @@
|
||||||
|
|
||||||
#include "image_compress_cvtt.h"
|
#include "image_compress_cvtt.h"
|
||||||
|
|
||||||
|
#include "core/object/worker_thread_pool.h"
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
#include "core/os/thread.h"
|
|
||||||
#include "core/string/print_string.h"
|
#include "core/string/print_string.h"
|
||||||
#include "core/templates/safe_refcount.h"
|
#include "core/templates/safe_refcount.h"
|
||||||
|
|
||||||
|
@ -129,6 +129,18 @@ static void _digest_row_task(const CVTTCompressionJobParams &p_job_params, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _digest_job_queue(void *p_job_queue, uint32_t p_index) {
|
||||||
|
CVTTCompressionJobQueue *job_queue = static_cast<CVTTCompressionJobQueue *>(p_job_queue);
|
||||||
|
uint32_t num_tasks = job_queue->num_tasks;
|
||||||
|
uint32_t total_threads = WorkerThreadPool::get_singleton()->get_thread_count();
|
||||||
|
uint32_t start = p_index * num_tasks / total_threads;
|
||||||
|
uint32_t end = (p_index + 1 == total_threads) ? num_tasks : ((p_index + 1) * num_tasks / total_threads);
|
||||||
|
|
||||||
|
for (uint32_t i = start; i < end; i++) {
|
||||||
|
_digest_row_task(job_queue->job_params, job_queue->job_tasks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void image_compress_cvtt(Image *p_image, Image::UsedChannels p_channels) {
|
void image_compress_cvtt(Image *p_image, Image::UsedChannels p_channels) {
|
||||||
if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) {
|
if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) {
|
||||||
return; //do not compress, already compressed
|
return; //do not compress, already compressed
|
||||||
|
@ -220,7 +232,7 @@ void image_compress_cvtt(Image *p_image, Image::UsedChannels p_channels) {
|
||||||
row_task.in_mm_bytes = in_bytes;
|
row_task.in_mm_bytes = in_bytes;
|
||||||
row_task.out_mm_bytes = out_bytes;
|
row_task.out_mm_bytes = out_bytes;
|
||||||
|
|
||||||
_digest_row_task(job_queue.job_params, row_task);
|
tasks.push_back(row_task);
|
||||||
|
|
||||||
out_bytes += 16 * (bw / 4);
|
out_bytes += 16 * (bw / 4);
|
||||||
}
|
}
|
||||||
|
@ -230,6 +242,13 @@ void image_compress_cvtt(Image *p_image, Image::UsedChannels p_channels) {
|
||||||
h = MAX(h / 2, 1);
|
h = MAX(h / 2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CVTTCompressionRowTask *tasks_rb = tasks.ptr();
|
||||||
|
|
||||||
|
job_queue.job_tasks = &tasks_rb[0];
|
||||||
|
job_queue.num_tasks = static_cast<uint32_t>(tasks.size());
|
||||||
|
WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_native_group_task(&_digest_job_queue, &job_queue, WorkerThreadPool::get_singleton()->get_thread_count(), -1, true, SNAME("CVTT Compress"));
|
||||||
|
WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group_task);
|
||||||
|
|
||||||
p_image->set_data(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
|
p_image->set_data(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue