Fix memory allocations #505
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
The Renderer was off in its GFX Memory allocation, most cases it would report 50 Mb GFX usage while the real usage was >150 Mb.
This was due to:
What changed?
Introduced
baselineMemoryAllocationmemory setting to set a baseline usage of your device. For example on my test device (RPI3b+ with WPEWebKit 2.46) an empty Canvas with a WebGL1 context uses 25 Mb. Every device you have will have a base allocation for just the WebGL context alone, adjust this setting to set that immutable baseline.All textures subsequently loaded will go on top of that baseline.
Removed mipmap's on Textures - we're using fixed scale textures and are not making use of Level-Of-Detail. Enabling mipmap's on textures generates a 33% extra memory allocation while we're never going to use that functionality. This PR thus reduces memory usage of textures allocated on the GPU that had a power of two for height & width.
Locked textures to 4 bytes, regardless of alpha channel. This was introduced in the assumption it would save memory, in tests on my device it didn't matter and all textures where aligned on a 4 byte anyway. So might as well use it, this allows the Renderer to more accurately estimate the memory usage. With 3 bytes in the non-alpha channel the calculation was always way off.
Added a default 10% texture padding, now this is a guesstimate sometimes its 5%, sometimes its more and very much depends on the texture that you're loading. With WebGL 1 there is no way to read the actual texture width/height or do any metrics on the allocation of the texture on the GPU. So this is an unfortunate side effect that we have to "guess" our allocations at all times and never 100% accurately know what the gfx memory usage is. If I missed something or you have a way, please let me know.
plus some random bits:
bla.svg?query=stringwhich I used for loading up unique SVGs and testTested on an RPI3b + with WPEWebKit and Thunder:
prior to these changes:

Renderer assumed we where using 76 Mb of GFX memory while in reality this was 109 Mb.
calculated memory by the renderer on the left and actual device GPU usage on the right with 500 textures.
Now it gets worse if we use textures with a power of two with mipmap's, prior to these changes:

with these changes:
