foxostro / GutsyStorm

Game with voxel graphics similar to Minecraft. (Restart GutsyStorm with Objective-C/Cocoa)
Other
12 stars 4 forks source link

Investigate potential memory improvements, file new issues #46

Closed foxostro closed 12 years ago

foxostro commented 12 years ago

Investigate potential improvements to the game's memory consumption and file new issues for anything that comes up.

foxostro commented 12 years ago

I could free ambient occlusion data after the chunk VBO has been generated. It won't be used again. Potential complication: are there any instances where I would need it again to regenerate the VBO?

foxostro commented 12 years ago

Chunk light values could be packed into fewer than 8-bits, for a significant memory win. Bit twiddling to pack the values into memory will have a cost, but lower memory consumption means that more of the world can be in memory at once and there will be fewer zero-fill faults. I already know that zero-fill faults are a big hit on performance right now.

a) When ambient occlusion is calculated, each visible vertex has 0 - 4 neighbors. So, only 3 bits are necessary. The final ambient occlusion light value can be calculated when the mesh is generated for a chunk.

b) Sunlight is stored as discrete values per block and only assumes a value between 0 and CHUNK_LIGHTING_MAX, which is 7. So, only 3 bits are necessary.

foxostro commented 12 years ago

cb8e85b0ef7a4bf7af10a3b31548f5e07a7efc01: Free geometry buffers after it has been submitted to the GPU. 4000a357085e5b88cd863b2342733d0e0bdfdb46: Each per-vertex AO lighting value only takes up 4-bits. ef15e8bf565af4aadf2e1e308b626b0cb363b7a8: Free ambient occlusion data after the mesh is generated. c76ce8e52189d69cd38ff6e2340a49c64a5d3002: Each sunlight value takes up only 8-bits.

Next steps: a) A large amount of memory is consumed by GSBoxedVector objects created as chunk IDs. Find a way to use less memory here. b) Store each sunlight in 4-bits instead of 8-bits. This will halve the size of the sunlight buffer at the cost of some CPU to pack and unpack sunlight values.

foxostro commented 12 years ago

Another idea: Do not allocate a buffer for ambient occlusion values at all. Generate them as needed during the mesh generation process, which already iterates over all the visible vertices in the chunk.

In any case, looking deeply into what memory is being allocated and used during the "warm up" period will tell me more about where the high ROI improvements will be.

foxostro commented 12 years ago

Another idea: do not allocate / de-allocate GSVertex and GSBoxedVector repeatedly when meshing a chunk. Do not use NSMutableArray here. Instead, allocate only the final buffer and work inside of that.

foxostro commented 12 years ago

fb8200ccc5c75d0cf2bfd74993de9468c2e882df: Do not store ambient occlusion data in a buffer at all. 035b0e2913f215a18f0675dee6120525c5ec1d83: Do not allocate so many GSBoxedVector during chunk meshing.

Memory footprint (RPRVT) was 900MB and is now 50MB. I call that a win, and I think I'm done here. Closing.