View Issue Details

IDProjectCategoryView StatusLast Update
0005459The Dark ModCodingpublic28.05.2023 23:51
Reporterstgatilov Assigned Tostgatilov  
Status closedResolutionunable to reproduce 
Product VersionTDM 2.09 
Target VersionTDM 2.12 
Summary0005459: Optimize idRenderWorldLocal::CreateLightDefInteractions for ambient_world light
DescriptionThe function idRenderWorldLocal::CreateLightDefInteractions searches for interactions of light like this:
    foreach area having light:
      foreach entity in area:
        if light is noshadows and entity not visible:
        ... # complicated code here

Ambient world light is noshadows and covers the whole map.
So all entities in the map are traversed every frame, just to see that they are not in the view and should be discarded.

I tried to profile game on Painter's Wife FM.
6.7% of time is spent on this function, most of which wasted on entity visibility check.
If I add this hack:
    volatile bool skipAmbientWorld = true;
    void idRenderWorldLocal::CreateLightDefInteractions( idRenderLightLocal *ldef ) {
      if (skipAmbientWorld && idStr::Icmp(gameLocal.entities[ldef->parms.entityNum]->spawnArgs.GetString("classname"), "atdm:ambient_world") == 0) {
        skipAmbientWorld = !!skipAmbientWorld;
Then only 1.4% is spent in this function. And all of it does into complicated logic of searching/adding interactions in the interaction table.

The idea of optimization is to extract light/entity processing into a separate function, then write second traversal.
The first traversal goes over all lights, then goes over their areas and entities.
The second traversal should go over visible entities, then go over lights in their areas.
The second approach should handle only specific class of lights, which are noshadows and large enough --- all the other lights should be handled with the first approach.
Additional InformationOriginally reported here, noticed during 100K entities experiment:
TagsNo tags attached.


related to 0006296 resolvedstgatilov CreateLightDefInteractions optimization 




15.11.2022 17:08

developer   ~0015432

A different approach might be planned for this. Tentatively moving to 2.12


28.05.2023 23:50

administrator   ~0016007

This is no longer an issue after 0006296.
Now CreateLightDefInteractions takes 1.15% of CPU time on Painter's Wife (according to profiler).

Note that ambient light is noshadows.
And for noshadows lights, we ignore areas which are not in the view.
This optimization means that for ambient world light we traverse all areas + contents of areas in the view.
And traversing areas is very fast, because number of areas is usually quite small.

Issue History

Date Modified Username Field Change
25.12.2020 16:31 stgatilov New Issue
27.02.2021 08:57 stgatilov Assigned To => stgatilov
27.02.2021 08:57 stgatilov Status new => assigned
27.02.2021 08:57 stgatilov Target Version TDM 2.10 =>
08.02.2022 14:54 nbohr1more Target Version => TDM 2.11
15.11.2022 17:08 nbohr1more Note Added: 0015432
15.11.2022 17:08 nbohr1more Target Version TDM 2.11 => TDM 2.12
28.05.2023 23:50 stgatilov Note Added: 0016007
28.05.2023 23:50 stgatilov Status assigned => closed
28.05.2023 23:50 stgatilov Resolution open => unable to reproduce
28.05.2023 23:51 stgatilov Relationship added related to 0006296