Make LevelMeshUpdater responsible for updating the tiles (playsim tells the mesh updater, the level mesh tells the tiles)

This commit is contained in:
Magnus Norddahl 2025-05-11 20:11:18 +02:00
commit 6cf3cdb871
11 changed files with 45 additions and 117 deletions

View file

@ -77,8 +77,8 @@ ADD_STAT(lightmap)
int indexBufferUsed = levelMesh->FreeLists.Index.GetUsedSize();
out.Format(
"Surfaces: %u (awaiting updates: %u static, %u dynamic)\n"
"Surface pixel area to update: %u static, %u dynamic\n"
"Surfaces: %u (awaiting updates: %u)\n"
"Surface pixel area to update: %u\n"
"Surface pixel area: %u\nAtlas pixel area: %u\n"
"Atlas efficiency: %.4f%%\n"
"Dynamic BLAS time: %2.3f ms\n"
@ -86,8 +86,8 @@ ADD_STAT(lightmap)
"Level mesh index buffer: %d K used (%d%%)\n"
"Lightmap tiles in use: %d\n"
"Lightmap texture count: %d",
stats.tiles.total, stats.tiles.dirty, stats.tiles.dirtyDynamic,
stats.pixels.dirty, stats.pixels.dirtyDynamic,
stats.tiles.total, stats.tiles.dirty,
stats.pixels.dirty,
stats.pixels.total,
atlasPixelCount,
float(stats.pixels.total) / float(atlasPixelCount) * 100.0f,
@ -159,7 +159,6 @@ void DoomLevelMesh::PrintSurfaceInfo(const LevelMeshSurface* surface)
Printf(" Pixels: %dx%d (area: %d)\n", tile->AtlasLocation.Width, tile->AtlasLocation.Height, tile->AtlasLocation.Area());
Printf(" Sample dimension: %d\n", tile->SampleDimension);
Printf(" Needs update?: %d\n", tile->NeedsUpdate);
Printf(" Always update?: %d\n", tile->AlwaysUpdate);
}
Printf(" Sector group: %d\n", surface->SectorGroup);
Printf(" Texture: '%s'\n", gameTexture ? gameTexture->GetName().GetChars() : "<nullptr>");
@ -1239,7 +1238,6 @@ int DoomLevelMesh::AddSurfaceToTile(const DoomSurfaceInfo& info, const LevelMesh
tile.Bounds.max.X = std::max(tile.Bounds.max.X, surf.Bounds.max.X);
tile.Bounds.max.Y = std::max(tile.Bounds.max.Y, surf.Bounds.max.Y);
tile.Bounds.max.Z = std::max(tile.Bounds.max.Z, surf.Bounds.max.Z);
tile.AlwaysUpdate = max<uint8_t>(tile.AlwaysUpdate, alwaysUpdate);
tile.UseCount++;
return index;
@ -1251,7 +1249,6 @@ int DoomLevelMesh::AddSurfaceToTile(const DoomSurfaceInfo& info, const LevelMesh
tile.Bounds = surf.Bounds;
tile.Plane = surf.Plane;
tile.SampleDimension = GetSampleDimension(sampleDimension);
tile.AlwaysUpdate = alwaysUpdate;
tile.UseCount = 1;
int index = AllocTile(tile);

View file

@ -140,9 +140,11 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
hudsprites.Clear();
Fogballs.Clear();
VisibleTiles.Clear();
visibleDyn = 0;
vpIndex = 0;
static int counter = 1;
TileSeenCounter = ++counter;
// Fullbright information needs to be propagated from the main view.
if (outer != nullptr) FullbrightFlags = outer->FullbrightFlags;
else FullbrightFlags = 0;
@ -714,34 +716,26 @@ void HWDrawInfo::PutWallPortal(HWWall wall, FRenderState& state)
void HWDrawInfo::UpdateLightmaps()
{
if (!outer && VisibleTiles.Size() < unsigned(lm_background_updates))
{
int unbaked = 0;
int dynamic = 0;
if (outer)
return;
/*
if (VisibleTiles.size() > (size_t)lm_max_updates)
VisibleTiles.resize(lm_max_updates);
if (VisibleTiles.size() < (size_t)lm_background_updates)
{
for (auto& e : level.levelMesh->Lightmap.Tiles)
{
if (e.NeedsUpdate)
if (e.NeedsUpdate && e.LastSeen != TileSeenCounter)
{
if(e.AlwaysUpdate == 0) unbaked++;
if(e.AlwaysUpdate != 0) dynamic++;
VisibleTiles.Push(&e);
if((!dynamic && (VisibleTiles.Size() >= unsigned(lm_background_updates))) || unbaked >= unsigned(lm_background_updates)) break;
if (VisibleTiles.size() >= (size_t)lm_background_updates)
break;
}
}
if(unbaked && dynamic)
{
std::sort(VisibleTiles.begin(), VisibleTiles.end(), [](LightmapTile *a, LightmapTile *b){return (!!a->AlwaysUpdate) < (!!b->AlwaysUpdate);});
}
if(VisibleTiles.Size() > unsigned(lm_background_updates))
{
VisibleTiles.Resize(lm_background_updates);
}
}
*/
screen->UpdateLightmaps(VisibleTiles);
}

View file

@ -158,7 +158,7 @@ struct HWDrawInfo
TArray<HUDSprite> hudsprites; // These may just be stored by value.
TArray<Fogball> Fogballs;
TArray<LightmapTile*> VisibleTiles;
unsigned visibleDyn;
int TileSeenCounter = 0;
uint64_t LastFrameTime = 0;
TArray<MissingTextureInfo> MissingUpperTextures;
@ -241,24 +241,9 @@ public:
}
LightmapTile* tile = &Level->levelMesh->Lightmap.Tiles[tileIndex];
if (lm_always_update || tile->AlwaysUpdate == 2 || (tile->AlwaysUpdate == 1 && lm_dynamic))
{
tile->NeedsUpdate = true;
visibleDyn++;
}
else if(tile->AlwaysUpdate == 3 && lm_dynamic)
{
tile->AlwaysUpdate = 0;
tile->NeedsUpdate = true;
visibleDyn++;
}
else if ((VisibleTiles.Size() - visibleDyn) >= unsigned(lm_max_updates))
{
return;
}
if (tile->NeedsUpdate)
if (tile->LastSeen != TileSeenCounter)
{
tile->LastSeen = TileSeenCounter;
VisibleTiles.Push(tile);
}
}

View file

@ -553,7 +553,8 @@ void HWFlat::ProcessSector(HWFlatDispatcher *di, FRenderState& state, sector_t *
unsigned int count = sector->e->XFloor.ffloors.Size() + 1;
for (unsigned int j = 0; j < count; j++)
{
if (int tile = sector->subsectors[i]->LightmapTiles[plane].Size() > j ? sector->subsectors[i]->LightmapTiles[plane][j] : -1)
int tile = sector->subsectors[i]->LightmapTiles[plane].Size() > j ? sector->subsectors[i]->LightmapTiles[plane][j] : -1;
if (tile >= 0)
{
di->di->PushVisibleTile(tile);
}

View file

@ -1149,7 +1149,7 @@ void HWWall::DoTexture(HWWallDispatcher *di, FRenderState& state, int _type,seg_
if (seg->sidedef->LightmapTiles.Size() >= 4 && type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM)
{
lightmaptile = seg->sidedef->LightmapTiles[type - RENDERWALL_TOP];
if (lightmaptile && di->di)
if (lightmaptile >= 0 && di->di)
{
di->di->PushVisibleTile(lightmaptile);
}
@ -1582,7 +1582,7 @@ void HWWall::BuildFFBlock(HWWallDispatcher *di, FRenderState& state, seg_t * seg
else
lightmaptile = seg->linedef->sidedef[0]->LightmapTiles.Size() > 4 + roverIndex ? seg->linedef->sidedef[0]->LightmapTiles[4 + roverIndex] : -1;
if (lightmaptile > 0)
if (lightmaptile >= 0)
{
di->di->PushVisibleTile(lightmaptile);
}