Texture Memory Usage

Started by aZen, February 09, 2014, 07:02:27 AM

Previous topic - Next topic

aZen

Is there an easy way to determine the texture memory usage in the software renderer? Trying to optimize textures and the would be quite helpful.

EgonOlsen

That's basically sizeX*sizeY*8+((sizeX/2)*(sizeY/2))*8+((sizeX/4)*(sizeY/4))*8...until either sizeX/a or sizeY/a are down to 16.

aZen

#2
Works ok if you're working with large textures. However very inaccurate if you're working with many small textures (<=16x16).

Just found this method. Will TextureManager.getInstance().getMemoryUsage(true) produce an accurate result in the software renderer?

        public long getMemoryUsage(boolean paramBoolean) {
            long l = 0L;
            for (int i = 0; i < this.textureCount; i++) {
                int[] arrayOfInt1 = this.textures[i].texels;
                int[] arrayOfInt2 = this.textures[i].alpha;
                if (arrayOfInt1 != null) {
                    l += (arrayOfInt1.length << 2);
                }
                if (arrayOfInt2 != null) {
                    l += (arrayOfInt2.length << 2);
                }
                if ((!paramBoolean) && (arrayOfInt1 == null)) {
                    l += (this.textures[i].width * this.textures[i].height << 2);
                }
            }
            return l;
        }


Edit: Mhmm, no that seems to consider removed textures as well. Would it be possible to add this functionality to the Texture object to determine how much memory it uses?

EgonOlsen

I will look into it, albeit i'm not sure what the actual purpose of such a method is...?

EgonOlsen

Try this jar: http://jpct.de/download/beta/jpct.jar. It adds a method getMemoryUsage() to Texture that should take everything into account.

aZen

Thank you! That finally works correctly with my testcase!

What I'm using this for:
Basically the voxel rendering works as following:
(1) A batch of voxel sides (that look into one direction on the same plane) are converted into a polygon.
(2) The polygon is converted into triangles. Each triangle can contain different colors (because it might span more than one voxel). Now we need to find or create a texture that can be used for this triangle.
(3) Complex algorithm determines whether there is an available triangle. If there is not, a new texture is created. It might be beneficial to reorganize textures (this is done with idle capacity). For this reorganization I was estimating the size of the texture by using the dimensions, but that wasn't very accurate. Much cleaner to get the real size (this will even be accurate if you ever update the internal structure of the Texture object).

Why do I even bother with this? Well, if voxel contain only a single color it's no problem at all. But they can also be textured and in that case you run out of memory faster than you can say "Texture".