mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-29 07:02:18 +00:00
Add progress dots for CPU tracer and streamline how they look
This commit is contained in:
parent
4cb0f59f66
commit
95232aedf4
3 changed files with 115 additions and 42 deletions
|
@ -10,6 +10,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
extern bool VKDebug;
|
extern bool VKDebug;
|
||||||
extern int NumThreads;
|
extern int NumThreads;
|
||||||
|
@ -491,19 +493,43 @@ void CPURaytracer::RunJob(int count, std::function<void(int)> callback)
|
||||||
|
|
||||||
numThreads = std::min(numThreads, count);
|
numThreads = std::min(numThreads, count);
|
||||||
|
|
||||||
|
std::condition_variable condvar;
|
||||||
|
std::mutex m;
|
||||||
|
int threadsleft = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
threadsleft = numThreads;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++)
|
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++)
|
||||||
{
|
{
|
||||||
threads.push_back(std::thread([=]() {
|
threads.push_back(std::thread([&]() {
|
||||||
|
|
||||||
for (int i = threadIndex; i < count; i += numThreads)
|
for (int i = threadIndex; i < count; i += numThreads)
|
||||||
{
|
{
|
||||||
callback(i);
|
callback(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
threadsleft--;
|
||||||
|
lock.unlock();
|
||||||
|
condvar.notify_all();
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
while (threadsleft != 0)
|
||||||
|
{
|
||||||
|
condvar.wait_for(lock, std::chrono::milliseconds(500), [&]() { return threadsleft == 0; });
|
||||||
|
printf(".");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++)
|
for (int i = 0; i < numThreads; i++)
|
||||||
threads[i].join();
|
threads[i].join();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
#include "glsl_rgen_bounce.h"
|
#include "glsl_rgen_bounce.h"
|
||||||
#include "glsl_rgen_light.h"
|
#include "glsl_rgen_light.h"
|
||||||
#include "glsl_rchit_bounce.h"
|
#include "glsl_rchit_bounce.h"
|
||||||
|
@ -86,6 +88,7 @@ void GPURaytracer::Raytrace(LevelMesh* level)
|
||||||
|
|
||||||
printf("Ray tracing with %d bounce(s)\n", mesh->map->LightBounce);
|
printf("Ray tracing with %d bounce(s)\n", mesh->map->LightBounce);
|
||||||
|
|
||||||
|
RunWithProgressDots([&]() {
|
||||||
size_t maxTasks = (size_t)rayTraceImageSize * rayTraceImageSize;
|
size_t maxTasks = (size_t)rayTraceImageSize * rayTraceImageSize;
|
||||||
for (size_t startTask = 0; startTask < tasks.size(); startTask += maxTasks)
|
for (size_t startTask = 0; startTask < tasks.size(); startTask += maxTasks)
|
||||||
{
|
{
|
||||||
|
@ -133,11 +136,12 @@ void GPURaytracer::Raytrace(LevelMesh* level)
|
||||||
EndTracing();
|
EndTracing();
|
||||||
DownloadTasks(tasks.data() + startTask, numTasks);
|
DownloadTasks(tasks.data() + startTask, numTasks);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (device->renderdoc)
|
if (device->renderdoc)
|
||||||
device->renderdoc->EndFrameCapture(0, 0);
|
device->renderdoc->EndFrameCapture(0, 0);
|
||||||
|
|
||||||
printf("\nRaytrace complete\n");
|
printf("Raytrace complete\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPURaytracer::CreateVulkanObjects()
|
void GPURaytracer::CreateVulkanObjects()
|
||||||
|
@ -264,7 +268,6 @@ void GPURaytracer::EndTracing()
|
||||||
cmdbuffer->end();
|
cmdbuffer->end();
|
||||||
|
|
||||||
SubmitCommands();
|
SubmitCommands();
|
||||||
printf(".");
|
|
||||||
|
|
||||||
cmdbuffer = cmdpool->createBuffer();
|
cmdbuffer = cmdpool->createBuffer();
|
||||||
cmdbuffer->begin();
|
cmdbuffer->begin();
|
||||||
|
@ -929,3 +932,46 @@ float GPURaytracer::RadicalInverse_VdC(uint32_t bits)
|
||||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||||
return float(bits) * 2.3283064365386963e-10f; // / 0x100000000
|
return float(bits) * 2.3283064365386963e-10f; // / 0x100000000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPURaytracer::RunWithProgressDots(std::function<void()> callback)
|
||||||
|
{
|
||||||
|
std::exception_ptr e;
|
||||||
|
std::condition_variable condvar;
|
||||||
|
std::mutex m;
|
||||||
|
bool stop;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
stop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::thread t([&]() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
e = std::current_exception();
|
||||||
|
}
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
stop = true;
|
||||||
|
lock.unlock();
|
||||||
|
condvar.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m);
|
||||||
|
while (!stop)
|
||||||
|
{
|
||||||
|
condvar.wait_for(lock, std::chrono::milliseconds(500), [&]() { return stop; });
|
||||||
|
printf(".");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
t.join();
|
||||||
|
|
||||||
|
if (e)
|
||||||
|
std::rethrow_exception(e);
|
||||||
|
}
|
||||||
|
|
|
@ -81,6 +81,8 @@ private:
|
||||||
static float RadicalInverse_VdC(uint32_t bits);
|
static float RadicalInverse_VdC(uint32_t bits);
|
||||||
static vec2 Hammersley(uint32_t i, uint32_t N);
|
static vec2 Hammersley(uint32_t i, uint32_t N);
|
||||||
|
|
||||||
|
static void RunWithProgressDots(std::function<void()> callback);
|
||||||
|
|
||||||
const int coverageSampleCount = 256;
|
const int coverageSampleCount = 256;
|
||||||
const int bounceSampleCount = 2048;
|
const int bounceSampleCount = 2048;
|
||||||
int rayTraceImageSize = 1024;
|
int rayTraceImageSize = 1024;
|
||||||
|
@ -139,5 +141,4 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<VulkanCommandPool> cmdpool;
|
std::unique_ptr<VulkanCommandPool> cmdpool;
|
||||||
std::unique_ptr<VulkanCommandBuffer> cmdbuffer;
|
std::unique_ptr<VulkanCommandBuffer> cmdbuffer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue