How to estimate the memory-usage in jPCT-AE?

Started by kiffa, August 02, 2012, 06:20:15 AM

Previous topic - Next topic

kiffa

I have read this: http://www.jpct.net/wiki/index.php/Reducing_memory_usage

But i want to know more. Thanks!

How to estimate the memory-usage of an Object3D obj with some known attributes(such as  triangles、vertexs and so on )? For examble: How many memories will the jPCT-AE allocate when loading a 6000-triangles model? And what's the situation when invoke methods of this Object3D obj?

How to estimate  the memory-usage of a texture? Is that right: 
 
  1,   By default,  a 256*256 texture will need 256*256*4 bytes memory when "new texture(...)".
  2.a,  If enable "defaultToKeepPixels", there will need another 256*256*4 bytes when "World.draw(...)"(if enable4bpp then will be 256*256*2 bytes).
  2.b,  If disable "defaultToKeepPixels", there will need no extra memory when uploaded to gpu.

  How to estimate the memory-usage of both keyframe-animation and bones-animation?

  What's the situation when i use FrameBuffer.blit(...)?

EgonOlsen

Quote
How to estimate the memory-usage of an Object3D obj with some known attributes(such as  triangles?vertexs and so on )? For examble: How many memories will the jPCT-AE allocate when loading a 6000-triangles model? And what's the situation when invoke methods of this Object3D obj?
To be honest, i don't know. It also depends on the object itself, i.e. how many vertices can be shared, how many texture stages will be used, if you call strip() on it or not etc. I would say: Take your object and give it a try. Calling any methods on an Object3D usually has no effect on memory usage.

Quote1,   By default,  a 256*256 texture will need 256*256*4 bytes memory when "new texture(...)".
Yes, that's correct.

Quote
2.a,  If enable "defaultToKeepPixels", there will need another 256*256*4 bytes when "World.draw(...)"(if enable4bpp then will be 256*256*2 bytes).
Yes. Plus the memory needed for mip-maps, i.e. plus 128*128*4+64*64*4+32*32*4+16*16*4....you can rougly estimate the memory used on the GPU as x*y*4+(x*y*4)/2

Quote
2.b,  If disable "defaultToKeepPixels", there will need no extra memory when uploaded to gpu.
No quite. The additional memory will be used too, but it will be freed after the upload, i.e. you'll still see a peak in memory usage. However, i don't encourage you do disable that setting. Consider using the Virtualizer class instead.

Quote
How to estimate the memory-usage of both keyframe-animation and bones-animation?
Keyframe animations rougly need <number of keyframes>*<number of vertices>*12 bytes of memory. bones-animation should use much less, but i can't comment on that as i don't know much about Bones.

Quote
What's the situation when i use FrameBuffer.blit(...)?
When you want to paint 2d elements on top of your rendered scene.

kiffa

Thanks!

Another question: how  to estimate the memory-usage of native in jPCT-AE?

I am marred by OOM. So i tried the MAT(http://www.eclipse.org/mat/) to analyse the memory usage, but seems that it could only be used to analyse java-memory-usage.

I want to know: in jPCT-AE, when and how many native memories will be allocated by who(class.methods) for what?

A general(mainly) description about this is helpful for me, thanks!

EgonOlsen

I've answered to that question in the other thread: http://www.jpct.net/forum2/index.php/topic,2898.msg21335.html#msg21335. However, i don't understand what do you think that this will give you!? It's actually pretty simple: You are using too much memory for your VM. The solution is also simple: Don't to it.
The wiki has some information about how to save memory and if that doesn't help, reduce the size of your assets starting with texture sizes. What are your texture sizes? People sometimes tend to use insane texture sizes on mobile devices...we have multiple threads dealing with that.

kiffa

To avoid OOM, the dvm mem limit should >= java mem usage + native mem usage

So i need to know how to estimate both java mem usage and native mem usage.

There are some tools which can report the java mem usage clearly. But i don't know how to estimate the native mem usage. As you say,  "older" vm won't report that.

To resolve OOM, what i do first is to find the component(s) which consumed the most memory, then improve it. 

In short, for my app, the java mem usage is about 11.5M(5M for mesh, 1.5M for animation, 2M for textures, 500K for VisList...). But i have no idea about the native memory usage, so i don't know which one (of mesh、animation、textures) should i decrease first, because i want to get the most benefit of memory-improvement with the least modifying. Does the mesh(Object3D) use the native memory?  Does the animation(bones) use the native memory? Dose the textures use the native memory?

And i want to add some features in my app in future, so i need to know the left mem of vm = vm limit - "java mem used "- "native mem used ".

EgonOlsen

#5
Quote from: kiffa on August 07, 2012, 09:05:29 AM
In short, for my app, the java mem usage is about 11.5M(5M for mesh, 1.5M for animation, 2M for textures, 500K for VisList...). But i have no idea about the native memory usage, so i don't know which one (of mesh、animation、textures) should i decrease first, because i want to get the most benefit of memory-improvement with the least modifying. Does the mesh(Object3D) use the native memory?  Does the animation(bones) use the native memory? Dose the textures use the native memory?
I've posted here multiple times about the memory usage for textures and the information can be found in the wiki too. Sorry, if i sounded a bit harsh, but i really don't want to repeat myself over and over again albeit i know that this is a problem that most people will suffer from sooner or later.

I've also already said that decreasing the texture size first is reasonable, because they usually consume the most memory (both vm and native). Bones' animations don't use native memory as far as i know. Object3Ds use native memory. I've already explained that in the other thread.

Hope this helps.

kiffa

Thanks!

Before the previous posting, i have tried to search early threads about that in the form, but the result is not good enough for me.

I will try to search again, thanks for your patience!

EgonOlsen

#7
Quote from: kiffa on August 07, 2012, 12:22:52 PM
Before the previous posting, i have tried to search early threads about that in the form, but the result is not good enough for me.
But i posted a formular above:

Quote
You can rougly estimate the memory used on the GPU as x*y*4+(x*y*4)/2

That's the additional native memory requirement (Edit: For textures...). Maybe i didn't make this clear enough, but that is it.

kiffa

#8
Thanks! Now i got it!

I have read this formular, but i really don't know the memory usage of gpu for textures means "native memory usage" before.

And another question, i know it is not about jPCT, but i really want to get help:

Android 4.0, when my app-process spawned, there were some preload-system-resources(some drawables and other res which were loaded by Zygote, and spawned for each process),  they consumed about 4.1M of memory in my test. I don't use them at all in my app, so i want to free them, but i don't know how to do this.

I have referred the docs of google, and ask this in many forums, but seems not help.

EgonOlsen

Quote from: kiffa on August 09, 2012, 03:03:16 PM
Android 4.0, when my app-process spawned, there were some preload-system-resources(some drawables and other res which were loaded by Zygote, and spawned for each process),  they consumed about 4.1M of memory in my test. I don't use them at all in my app, so i want to free them, but i don't know how to do this.
What exactly do you mean? That creating an empty Activity already consumes 4mb of VM memory?

kiffa

#10
Quote from: EgonOlsen on August 09, 2012, 09:33:34 PM
What exactly do you mean? That creating an empty Activity already consumes 4mb of VM memory?

Yes, and the 4mb of memory was consumed by androd-system-preloaded-res. 



EgonOlsen

Strange. I've found people asking this or a similar question but no satisfying answer...