Page 1 of 1

Scene texture maps resize policy: MINMEM

Posted: Thu May 20, 2021 2:13 pm
by Dade
Continuing from: viewtopic.php?f=5&t=3573

Policy: MINMEM

The "MINMEM" policy is the weapon of last resort. The nuke: the one you want to use when you want to save any possible bit of memory (at cost of a longer pre-processing).

It is defined by:

Code: Select all

scene.images.resizepolicy.type = MINMEM
scene.images.resizepolicy.scale = 1.0
scene.images.resizepolicy.minsize = 64
"MINMEM" works in 3 steps:

1) load all image maps at "scene.images.resizepolicy.minsize";
2) compute each optimal image map resolution (i.e. the optimal is when an image map pixel cover one screen pixel);
3) reload each image map and scale to the optimal resolution (where optimal resolution can be forced up and down by "scene.images.resizepolicy.minsize").

This is reference rendering (all the image maps are 512x512):

none.jpg

Using:

Code: Select all

[LuxRays][0.524] [Device GeForce RTX 2070 SUPER CUDAIntersect] ImageMaps buffer size: 5376Kbytes
And this is the MINMEM rendering:

minmem1.jpg

Using:

Code: Select all

[LuxRays][1.160] [Device GeForce RTX 2070 SUPER CUDAIntersect] ImageMaps buffer size: 4099Kbytes
The quality is the same but I have saved ~25% of the GPU ram.

The log show what MINMEM does:

Code: Select all

[LuxCore][0.593] Resize policy preprocess thread count: 24
[SDL][0.855] Image maps "scenes/randomizedtiling/pattern-3.jpg" optimal resize: 512x512 => 533x533
[SDL][0.855] Image maps "scenes/randomizedtiling/pattern-7.jpg" optimal resize: 512x512 => 266x266
[SDL][0.855] Image maps "scenes/randomizedtiling/pattern-9.jpg" optimal resize: 512x512 => 133x133
[SDL][0.855] WARNING: image maps "scenes/randomizedtiling/pattern-3.jpg" too small !
[SDL][0.855] Reading texture map: scenes/randomizedtiling/pattern-3.jpg
[SDL][0.880] Image maps "scenes/randomizedtiling/pattern-3.jpg" scaled: 512x512 => 512x512
[SDL][0.880] Reading texture map: scenes/randomizedtiling/pattern-7.jpg
[SDL][0.942] Image maps "scenes/randomizedtiling/pattern-7.jpg" scaled: 512x512 => 266x266
[SDL][0.942] Reading texture map: scenes/randomizedtiling/pattern-9.jpg
[SDL][0.998] Image maps "scenes/randomizedtiling/pattern-9.jpg" scaled: 512x512 => 133x133
[SDL][0.998] Applying resize policy MINMEM time: 0.4secs
It shows the optimal resolution for each image maps. It even tells me that 512x512 is not enough for the larger quad (533x533 is the optimal resolution).

Now let's render with the same scene at a lower resolution (960x540 instead of 1920x1080):

minmem2.jpg

MINMEM uses even less ram thanks to the lower rendering resolution:

Code: Select all

[LuxRays][0.923] [Device GeForce RTX 2070 SUPER CUDAIntersect] ImageMaps buffer size: 3343Kbytes
Because the optimal resolutions are even smaller:

Code: Select all

[LuxCore][0.652] Resize policy preprocess thread count: 24
[SDL][0.726] Image maps "scenes/randomizedtiling/pattern-3.jpg" optimal resize: 512x512 => 266x266
[SDL][0.726] Image maps "scenes/randomizedtiling/pattern-7.jpg" optimal resize: 512x512 => 133x133
[SDL][0.726] Image maps "scenes/randomizedtiling/pattern-9.jpg" optimal resize: 512x512 => 66x66
[SDL][0.726] Reading texture map: scenes/randomizedtiling/pattern-3.jpg
[SDL][0.793] Image maps "scenes/randomizedtiling/pattern-3.jpg" scaled: 512x512 => 266x266
[SDL][0.793] Reading texture map: scenes/randomizedtiling/pattern-7.jpg
[SDL][0.852] Image maps "scenes/randomizedtiling/pattern-7.jpg" scaled: 512x512 => 133x133
[SDL][0.852] Reading texture map: scenes/randomizedtiling/pattern-9.jpg
[SDL][0.907] Image maps "scenes/randomizedtiling/pattern-9.jpg" scaled: 512x512 => 66x66
[SDL][0.907] Applying resize policy MINMEM time: 0.3secs
Let's make the scene more complex with a glass sphere:

minmem3.jpg

It uses even less ram because the optimal size of the middle quad is even smaller:

Code: Select all

[LuxCore][0.625] Resize policy preprocess thread count: 24
[SDL][0.702] Image maps "scenes/randomizedtiling/pattern-3.jpg" optimal resize: 512x512 => 266x266
[SDL][0.702] Image maps "scenes/randomizedtiling/pattern-7.jpg" optimal resize: 512x512 => 71x71
[SDL][0.702] Image maps "scenes/randomizedtiling/pattern-9.jpg" optimal resize: 512x512 => 66x66
[SDL][0.702] Reading texture map: scenes/randomizedtiling/pattern-3.jpg
[SDL][0.776] Image maps "scenes/randomizedtiling/pattern-3.jpg" scaled: 512x512 => 266x266
[SDL][0.776] Reading texture map: scenes/randomizedtiling/pattern-7.jpg
[SDL][0.843] Image maps "scenes/randomizedtiling/pattern-7.jpg" scaled: 512x512 => 71x71
[SDL][0.843] Reading texture map: scenes/randomizedtiling/pattern-9.jpg
[SDL][0.901] Image maps "scenes/randomizedtiling/pattern-9.jpg" scaled: 512x512 => 66x66
[SDL][0.901] Applying resize policy MINMEM time: 0.3secs
From original 512x512 (and 133x133 optimal without glass lens) to 71x71.

A real world test

This is a rendering of HallBench scene:

hallbench0.jpg

And this is the same rendering with MINMEM:

hallbench1.jpg

The saved memory is:

Code: Select all

[SDL][34.015] Memory required for original Image maps: 272710Kbytes
[SDL][34.015] Memory required for MINMEM Image maps: 46985Kbytes
It requires 5.8 times less memory ! 46MB Vs 272MB.

More to come

The next strategy will use Arnold .tx files as cache and mip map levels (instead of 100% optimal size) to have about the same memory saving but at no pre-processing cost.

Re: Scene texture maps resize policy: MINMEM

Posted: Thu May 20, 2021 2:36 pm
by zuljin3d
:shock: wow

Re: Scene texture maps resize policy: MINMEM

Posted: Thu May 20, 2021 3:42 pm
by Sharlybg
Now we are talking seriously :twisted:

Good Job Dade ;)

Re: Scene texture maps resize policy: MINMEM

Posted: Fri May 21, 2021 10:32 am
by juangea
AMAZING!

This is fully compatible with GPU, right?

I ask this because of the Arnold .tx files strategy, that could be awesome, but I'm not sure if it was compatible with GPU too :)

Re: Scene texture maps resize policy: MINMEM

Posted: Fri May 21, 2021 11:34 am
by Dade
juangea wrote: Fri May 21, 2021 10:32 am This is fully compatible with GPU, right?

I ask this because of the Arnold .tx files strategy, that could be awesome, but I'm not sure if it was compatible with GPU too :)
Yes, it is done only as scene pre-processing on the CPU to estimate the optimal sizes, after that it render as usual on the GPU. The .tx file will be used as cache (you pre-compute all mip map levels so all possible used sizes are there).

Re: Scene texture maps resize policy: MINMEM

Posted: Fri May 21, 2021 11:52 am
by juangea
Oh, awesome!

Re: Scene texture maps resize policy: MINMEM

Posted: Sun May 23, 2021 12:35 pm
by Harvester
This is very promising, well done, Davide!