mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-14 00:21:24 +00:00
Discard GPU trace tasks that are out of surface bounds
This commit is contained in:
parent
020b053398
commit
866d02fc4a
2 changed files with 54 additions and 26 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "framework/templates.h"
|
#include "framework/templates.h"
|
||||||
#include "framework/halffloat.h"
|
#include "framework/halffloat.h"
|
||||||
#include "vulkanbuilders.h"
|
#include "vulkanbuilders.h"
|
||||||
|
#include "surfaceclip.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -50,32 +51,7 @@ void GPURaytracer::Raytrace(LevelMesh* level)
|
||||||
CreateVulkanObjects();
|
CreateVulkanObjects();
|
||||||
|
|
||||||
std::vector<TraceTask> tasks;
|
std::vector<TraceTask> tasks;
|
||||||
for (size_t i = 0; i < mesh->lightProbes.size(); i++)
|
CreateTasks(tasks);
|
||||||
{
|
|
||||||
TraceTask task;
|
|
||||||
task.id = -(int)(i + 2);
|
|
||||||
task.x = 0;
|
|
||||||
task.y = 0;
|
|
||||||
tasks.push_back(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < mesh->surfaces.size(); i++)
|
|
||||||
{
|
|
||||||
Surface* surface = mesh->surfaces[i].get();
|
|
||||||
int sampleWidth = surface->lightmapDims[0];
|
|
||||||
int sampleHeight = surface->lightmapDims[1];
|
|
||||||
for (int y = 0; y < sampleHeight; y++)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < sampleWidth; x++)
|
|
||||||
{
|
|
||||||
TraceTask task;
|
|
||||||
task.id = (int)i;
|
|
||||||
task.x = x;
|
|
||||||
task.y = y;
|
|
||||||
tasks.push_back(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<vec3> HemisphereVectors;
|
std::vector<vec3> HemisphereVectors;
|
||||||
HemisphereVectors.reserve(bounceSampleCount);
|
HemisphereVectors.reserve(bounceSampleCount);
|
||||||
|
@ -152,6 +128,57 @@ void GPURaytracer::Raytrace(LevelMesh* level)
|
||||||
printf("Ray trace complete\n");
|
printf("Ray trace complete\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPURaytracer::CreateTasks(std::vector<TraceTask>& tasks)
|
||||||
|
{
|
||||||
|
tasks.resize(mesh->lightProbes.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mesh->lightProbes.size(); i++)
|
||||||
|
{
|
||||||
|
TraceTask task;
|
||||||
|
task.id = -(int)(i + 2);
|
||||||
|
task.x = 0;
|
||||||
|
task.y = 0;
|
||||||
|
tasks.push_back(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t fullTaskCount = mesh->lightProbes.size();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mesh->surfaces.size(); i++)
|
||||||
|
{
|
||||||
|
if (i % 4096 == 0)
|
||||||
|
printf("\rGathering surface trace tasks: %llu / %llu", i, mesh->surfaces.size());
|
||||||
|
|
||||||
|
Surface* surface = mesh->surfaces[i].get();
|
||||||
|
|
||||||
|
if (!surface->bSky)
|
||||||
|
{
|
||||||
|
int sampleWidth = surface->lightmapDims[0];
|
||||||
|
int sampleHeight = surface->lightmapDims[1];
|
||||||
|
|
||||||
|
fullTaskCount += size_t(sampleHeight) * size_t(sampleWidth);
|
||||||
|
|
||||||
|
SurfaceClip surfaceClip(surface);
|
||||||
|
|
||||||
|
for (int y = 0; y < sampleHeight; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < sampleWidth; x++)
|
||||||
|
{
|
||||||
|
if (surfaceClip.SampleIsInBounds(float(x), float(y)))
|
||||||
|
{
|
||||||
|
TraceTask task;
|
||||||
|
task.id = (int)i;
|
||||||
|
task.x = x;
|
||||||
|
task.y = y;
|
||||||
|
tasks.push_back(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\rGathering surface trace tasks: %llu / %llu\n", mesh->surfaces.size(), mesh->surfaces.size());
|
||||||
|
printf("\tDiscarded %.3f%% of all tasks\n", (1.0 - double(tasks.size()) / fullTaskCount) * 100.0);
|
||||||
|
}
|
||||||
|
|
||||||
void GPURaytracer::CreateVulkanObjects()
|
void GPURaytracer::CreateVulkanObjects()
|
||||||
{
|
{
|
||||||
cmdpool = std::make_unique<VulkanCommandPool>(device.get(), device->graphicsFamily);
|
cmdpool = std::make_unique<VulkanCommandPool>(device.get(), device->graphicsFamily);
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
void Raytrace(LevelMesh* level);
|
void Raytrace(LevelMesh* level);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CreateTasks(std::vector<TraceTask>& tasks);
|
||||||
void CreateVulkanObjects();
|
void CreateVulkanObjects();
|
||||||
void CreateVertexAndIndexBuffers();
|
void CreateVertexAndIndexBuffers();
|
||||||
void CreateBottomLevelAccelerationStructure();
|
void CreateBottomLevelAccelerationStructure();
|
||||||
|
|
Loading…
Reference in a new issue