shocker-0x15 / GfxExp

Sandbox for graphics paper implementation
Other
222 stars 19 forks source link

Materials do not re-use textures leading to duplicate textures in memory. #1

Closed l2- closed 2 years ago

l2- commented 2 years ago

Hi,

When using a scene such as lost-empire I get the following error : Error: CUDA call (cuArray3DCreate(&m_array, &arrayDesc) ) failed with error: 'out of memory' (C:\Users\X\Documents\Shocker\GfxExp\utils\cuda_util.cpp:693). I think what is happening is that for every material in the mtl file the map_Ka and map_Kd attributes are loaded into memory even if those same textures have been loaded into memory already for another material. This is confirmed by the console output:


[ 4][  DISK CACHE]: Opened database: "C:\Users\X\AppData\Local\NVIDIA\OptixCache\optix7cache.db"
[ 4][  DISK CACHE]:     Cache data size: "1.8 MiB"
[ 4][   DISKCACHE]: Cache hit for key: ptx-538030-keyf4770f7ee17acca7955c0792d6c5b076-sm_61-rtc0-drv496.76
[ 4][COMPILE FEEDBACK]:
[ 4][   DISKCACHE]: Cache hit for key: ptx-40534-keyf6edc5a05105d08ef92e4c8cff25c7c6-sm_61-rtc0-drv496.76
[ 4][COMPILE FEEDBACK]:
[ 4][COMPILE FEEDBACK]: Info: Pipeline has 1 module(s), 35 entry function(s), 32 trace call(s), 0 continuation callable call(s), 54 direct callable call(s), 707 basic block(s) in entry functions, 19309 instruction(s) in entry functions, 0 non-entry function(s), 0 basic block(s) in non-entry functions, 0 instruction(s) in non-entry functions

Reading: ../scenes/lost-empire/lost_empire.obj ... done.
DefaultMaterial:
Stone:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Grass_Block:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Dirt:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Cobblestone:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Oak_Planks:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Stationary_Water:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Stationary_Lava:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Sand:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Gravel:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Iron_Ore:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Coal_Ore:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Oak_Log:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Oak_Leaves:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Bed:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Powered_Rail:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Detector_Rail:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Sticky_Piston:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Wool:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Dandelion:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Poppy:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Brown_Mushroom:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Double_Stone_Slab:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Stone_Slab:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Obsidian:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Torch:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... done.
Oak_Stairs:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Chest:
  Reading: ../scenes/lost-empire/lost_empire-RGB.png ... done.
Redstone_Wire:
  Reading: ../scenes/lost-empire/lost_empire-RGBA.png ... Error: CUDA call (cuArray3DCreate(&m_array, &arrayDesc) ) failed with error: 'out of memory' (C:\Users\X\Documents\Shocker\GfxExp\utils\cuda_util.cpp:693)

As you can see the same textures are loaded over and over.

shocker-0x15 commented 2 years ago

Thanks for the report. I haven't confirmed this scene and I'm not sure if my ReSTIR (ReGIR?) code can handle Minecraft scene well but I'll improve texture loading in spare time.

shocker-0x15 commented 2 years ago

Now texture loader reuses already loaded textures from caches. And I confirmed ReSTIR seems to work for the lost empire scene. Try the following options: -cam-pos -4.141 21.604 -37.123 -cam-roll 0 -cam-pitch 11 -cam-yaw 11 -name scene -obj ../../assets/lost-empire/lost_empire.obj 1.0 trad -brightness 3.0 -inst scene (modify the obj path) output_0 output_1

Note that the latest revision contains a commit which updated OptiX wrapper library internally used, so now the project requires you to install OptiX 7.4.0.

l2- commented 2 years ago

It works great. Thanks :)