Scene texture maps resize policy: MINMEM

Discussion related to the LuxCore functionality, implementations and API.
Post Reply
User avatar
Dade
Developer
Posts: 5324
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Scene texture maps resize policy: MINMEM

Post by Dade » Thu May 20, 2021 2:13 pm

Continuing from: https://forums.luxcorerender.org/viewto ... 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.
Support LuxCoreRender project with salts and bounties

zuljin3d
Posts: 68
Joined: Sun Apr 08, 2018 12:13 pm

Re: Scene texture maps resize policy: MINMEM

Post by zuljin3d » Thu May 20, 2021 2:36 pm

:shock: wow
Actualy sorry for my google translate english :)

User avatar
Sharlybg
Donor
Posts: 2779
Joined: Mon Dec 04, 2017 10:11 pm
Location: Ivory Coast

Re: Scene texture maps resize policy: MINMEM

Post by Sharlybg » Thu May 20, 2021 3:42 pm

Now we are talking seriously :twisted:

Good Job Dade ;)
Support LuxCoreRender project with salts and bounties

Portfolio : https://www.behance.net/DRAVIA

juangea
Donor
Posts: 297
Joined: Thu Jan 02, 2020 6:23 pm

Re: Scene texture maps resize policy: MINMEM

Post by juangea » Fri May 21, 2021 10:32 am

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 :)

User avatar
Dade
Developer
Posts: 5324
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Scene texture maps resize policy: MINMEM

Post by Dade » Fri May 21, 2021 11:34 am

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).
Support LuxCoreRender project with salts and bounties

juangea
Donor
Posts: 297
Joined: Thu Jan 02, 2020 6:23 pm

Re: Scene texture maps resize policy: MINMEM

Post by juangea » Fri May 21, 2021 11:52 am

Oh, awesome!

Harvester
Donor
Posts: 41
Joined: Thu Jan 25, 2018 8:06 pm

Re: Scene texture maps resize policy: MINMEM

Post by Harvester » Sun May 23, 2021 12:35 pm

This is very promising, well done, Davide!

Post Reply