Delay creating the accel struct until frame start

This commit is contained in:
Magnus Norddahl 2023-09-11 14:55:31 +02:00 committed by Christoph Oelckers
parent 6a2135b315
commit 776b615e10
2 changed files with 30 additions and 26 deletions

View file

@ -466,6 +466,31 @@ TArray<uint8_t> VulkanRenderDevice::GetScreenshotBuffer(int &pitch, ESSType &col
void VulkanRenderDevice::BeginFrame()
{
if (levelMeshChanged)
{
levelMeshChanged = false;
mRaytrace->SetLevelMesh(levelMesh);
if (levelMesh && levelMesh->GetSurfaceCount() > 0)
{
levelMesh->UpdateLightLists();
GetTextureManager()->CreateLightmap(levelMesh->LMTextureSize, levelMesh->LMTextureCount);
#if 0 // full lightmap generation
TArray<LevelMeshSurface*> surfaces;
surfaces.Reserve(mesh->GetSurfaceCount());
for (unsigned i = 0, count = mesh->GetSurfaceCount(); i < count; ++i)
{
surfaces[i] = mesh->GetSurface(i);
}
GetLightmap()->Raytrace(mesh, surfaces);
#else
GetLightmap()->Raytrace(levelMesh, {});
#endif
}
}
SetViewportRects(nullptr);
mCommands->BeginFrame();
mTextureManager->BeginFrame();
@ -531,40 +556,16 @@ void VulkanRenderDevice::PrintStartupLog()
Printf("Min. uniform buffer offset alignment: %" PRIu64 "\n", limits.minUniformBufferOffsetAlignment);
}
LevelMesh* lastMesh = nullptr; // Temp hack; Since this function is called every frame we only want to do this once
void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh)
{
mRaytrace->SetLevelMesh(mesh);
if (mesh->GetSurfaceCount() > 0)
{
lastMesh = mesh;
mesh->UpdateLightLists();
GetTextureManager()->CreateLightmap(mesh->LMTextureSize, mesh->LMTextureCount);
#if 0 // full lightmap generation
TArray<LevelMeshSurface*> surfaces;
surfaces.Reserve(mesh->GetSurfaceCount());
for (unsigned i = 0, count = mesh->GetSurfaceCount(); i < count; ++i)
{
surfaces[i] = mesh->GetSurface(i);
}
GetLightmap()->Raytrace(mesh, surfaces);
#else
GetLightmap()->Raytrace(mesh, {});
#endif
}
levelMesh = mesh;
levelMeshChanged = true;
}
void VulkanRenderDevice::UpdateLightmaps(const TArray<LevelMeshSurface*>& surfaces)
{
if (surfaces.Size() > 0)
{
auto levelMesh = lastMesh; // There's nothing more permanent than a temporary solution
if (levelMesh)
{
GetLightmap()->Raytrace(levelMesh, surfaces);

View file

@ -115,6 +115,9 @@ private:
VkRenderBuffers *mActiveRenderBuffers = nullptr;
bool mVSync = false;
LevelMesh* levelMesh = nullptr;
bool levelMeshChanged = true;
};
class CVulkanError : public CEngineError