diff --git a/src/lightmap/cpuraytracer.cpp b/src/lightmap/cpuraytracer.cpp index 78cd7aa..bfb6224 100644 --- a/src/lightmap/cpuraytracer.cpp +++ b/src/lightmap/cpuraytracer.cpp @@ -507,9 +507,21 @@ void CPURaytracer::RunJob(int count, std::function callback) { threads.push_back(std::thread([&, threadIndex]() { - for (int i = threadIndex; i < count; i += numThreads) + if (threadIndex == 0) { - callback(i); + for (int i = 0; i < count; i += numThreads) + { + if((i / numThreads) % 8192 == 0) + printf("\r%.1f%%\t%d/%d", double(i) / double(count) * 100, i, count); + callback(i); + } + } + else + { + for (int i = threadIndex; i < count; i += numThreads) + { + callback(i); + } } std::unique_lock lock(m); @@ -525,9 +537,8 @@ void CPURaytracer::RunJob(int count, std::function callback) while (threadsleft != 0) { condvar.wait_for(lock, std::chrono::milliseconds(500), [&]() { return threadsleft == 0; }); - printf("."); } - printf("\n"); + printf("\r%.1f%%\t%d/%d\n", 100.0, count, count); } for (int i = 0; i < numThreads; i++) diff --git a/src/lightmap/gpuraytracer.cpp b/src/lightmap/gpuraytracer.cpp index 0023b18..cdeec99 100644 --- a/src/lightmap/gpuraytracer.cpp +++ b/src/lightmap/gpuraytracer.cpp @@ -93,10 +93,11 @@ void GPURaytracer::Raytrace(LevelMesh* level) //printf("Ray tracing with %d bounce(s)\n", mesh->map->LightBounce); printf("Ray tracing in progress...\n"); - RunWithProgressDots([&]() { + RunAsync([&]() { size_t maxTasks = (size_t)rayTraceImageSize * rayTraceImageSize; for (size_t startTask = 0; startTask < tasks.size(); startTask += maxTasks) { + printf("\r%.1f%%\t%d/%d", double(startTask) / double(tasks.size()) * 100, startTask, tasks.size()); size_t numTasks = std::min(tasks.size() - startTask, maxTasks); UploadTasks(tasks.data() + startTask, numTasks); @@ -144,6 +145,7 @@ void GPURaytracer::Raytrace(LevelMesh* level) EndTracing(); DownloadTasks(tasks.data() + startTask, numTasks); } + printf("\r%.1f%%\t%d/%d\n", 100.0, tasks.size(), tasks.size()); }); if (device->renderdoc) @@ -971,7 +973,7 @@ float GPURaytracer::RadicalInverse_VdC(uint32_t bits) return float(bits) * 2.3283064365386963e-10f; // / 0x100000000 } -void GPURaytracer::RunWithProgressDots(std::function callback) +void GPURaytracer::RunAsync(std::function callback) { std::exception_ptr e; std::condition_variable condvar; @@ -1003,9 +1005,7 @@ void GPURaytracer::RunWithProgressDots(std::function callback) while (!stop) { condvar.wait_for(lock, std::chrono::milliseconds(500), [&]() { return stop; }); - printf("."); } - printf("\n"); } t.join(); diff --git a/src/lightmap/gpuraytracer.h b/src/lightmap/gpuraytracer.h index c71f0b8..1491f71 100644 --- a/src/lightmap/gpuraytracer.h +++ b/src/lightmap/gpuraytracer.h @@ -89,7 +89,7 @@ private: static float RadicalInverse_VdC(uint32_t bits); static vec2 Hammersley(uint32_t i, uint32_t N); - static void RunWithProgressDots(std::function callback); + static void RunAsync(std::function callback); const int coverageSampleCount = 256; const int bounceSampleCount = 2048;