Maximum number of textures???

Started by
11 comments, last by GameDev.net 19 years, 6 months ago
Could it be that there is a maximum number of textures? I'm programming a little 2D-game in Direct3D and therefore I have to use many textures. I've made the experience that when I've loaded more than about 250-300 diffrent textures, the programm starts to run very slow.(before 100.0 fps, after 15-34 fps!!)
Advertisement
It is usually better to have one texture file with a lot of tiles in it, than having one separate file for each tile. This can (and it does) make things very, very slow. 250-300 different textures loaded at the same time is really a lot. You should group your tiles in textures like each texture has 16 tiles (4x4) inside or something like that.
So you'll create an MMORPG, uh? Well, what about reading THIS?
Using so many textures can cause video memory filling up, so D3D has to juggle the data back and forth across the graphics bus when the textures are used.

In D3D9, you can create managed textures, uploading of which the API takes care automatically. Furthermore, you can give managed resources a relative priority level, to hint the system about which resources should be moved first or last, if necessary. Of course, it is also possible to maker your own texture memory pager, if you want.

While texture paging described above can help greatly in your situation, in reality, there's only two complete solutions to your problem:
1. Buy a video card with more on-board memory, or
2. Use fewer/smaller textures.

Kind regards,
-Nik

PS. By the way, I presume that not all of the 250-300 textures are visible at the same time, are they?

Niko Suni

If it's 2D you might try only using the first mipmap level (pass 1 instead of 0 to the texture load function). They will use up a lot of memory with that many textures.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
I'm already using 1 as miplevel. I'm loading all 300 textures at the beginning of the programm and it only runs that slow after I've blit a certain number of them and not after I've loaded them. Is there a way to have only as many textures as I blit at a time??

And is the size of the textures or the number of them more important ?

What are managed textures?

( I think 2,4 Ghz, Geforce 5900 and 512 MB RAM should be enough ! )
Quote:Original post by Nod
What are managed textures?

Managed textures are stored in System memory and copied into video memory as needed. Only the textures currently used are kept in video memory.

Are you doing anything that allocated memory in your rendering loop? How are you drawing these textures? I'm inclined to think the problem lies there.
Stay Casual,KenDrunken Hyena
Quote:And is the size of the textures or the number of them more important ?

It sounds like you're over-committing video memory, so it's the total amount of memory that they're taking up. You've mentioned that there are about 300 textures. When you sum up width x height x bytes per texel, what do you get?
Quote:( I think 2,4 Ghz, Geforce 5900 and 512 MB RAM should be enough ! )

Are you sure you have 512 MB? I've never heard of a 5900 having more than 256 MB. Or maybe you mean system memory, which is not really relevant here.

At any rate, we can't say whether or not it's enough until we know how much space your textures are taking up.

Also, if you're using D3DPOOL_MANAGED, it's important that you first create all D3DPOOL_DEFAULT resources first, then create your managed resources. Default pool resources include render targets, depth-stencil buffers, and swap chains. Basically, once you start creating managed pool resources, the managed pool manager expects that it "owns" whatever video memory remains. So that's another possible explanation for what you're seeing.
Sorry, that was me making that last post. Gamedev and Firefox don't seem to get along so well.
Donavon KeithleyNo, Inky Death Vole!
I meant 512 MB system memory. My Geforce 5900 has only 128 MB!

I'm using this blit function :
( it's from http://www.mvps.org/directx/articles/blit3d.htm )

typedef struct _D3DTLVERTEX {
float sx; /* Screen coordinates */
float sy;
float sz;
float rhw; /* Reciprocal of homogeneous w */
D3DCOLOR color; /* Vertex color */
float tu; /* Texture coordinates */
float tv;
_D3DTLVERTEX() { }
_D3DTLVERTEX(const D3DVECTOR& v, float _rhw,
D3DCOLOR _color,
float _tu, float _tv)
{ sx = v.x; sy = v.y; sz = v.z; rhw = _rhw;
color = _color;
tu = _tu; tv = _tv;
}
} D3DTLVERTEX, *LPD3DTLVERTEX;

#define D3DFVF_TLVERTEX D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1

void BlitRect(LPDIRECT3DDEVICE8 lpDevice,
LPDIRECT3DTEXTURE8 lpSrc,
float left, float top,
float right, float bottom,
D3DCOLOR col,float z)
{
// calculate rhw

float rhw=1.0f/(z*990.0f+10.0f);

// set up rectangle

D3DTLVERTEX verts[4];
verts[0]=D3DTLVERTEX(D3DXVECTOR3(left-0.5f, top-0.5f, z),rhw,col,0.0f,0.0f);
verts[1]=D3DTLVERTEX(D3DXVECTOR3(right-0.5f, top-0.5f, z),rhw,col,1.0f,0.0f);
verts[2]=D3DTLVERTEX(D3DXVECTOR3(right-0.5f, bottom-0.5f, z),rhw,col,1.0f,1.0f);
verts[3]=D3DTLVERTEX(D3DXVECTOR3(left-0.5f, bottom-0.5f, z),rhw,col,0.0f,1.0f);

// set the texture

lpDevice->SetTexture(0,lpSrc);

// draw the rectangle

lpDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,verts,sizeof(D3DTLVERTEX));
}

And this load function:

typedef struct _CD3DImage
{
IDirect3DTexture9 *pTexture; // Pointer to image texture
int nImageWidth; // Original image size
int nImageHeight; // Original image height
D3DXIMAGE_INFO ImageInfo; // ImageInfo
}
CD3DImage;

CD3DImage D3DImages[MAXIMAGES];

for ( int nImage = 0; nImage < MAXIMAGES; nImage++ )
{
// Create a texture from the specified file
D3DXCreateTextureFromFileEx( pd3dDevice,
lpImageList[nImage], // list with file names
0,0,1,0,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DPOOL_MANAGED,
D3DCOLOR_XRGB(255,0,255),
&D3DImages[nImage].ImageInfo,
NULL,
&D3DImages[nImage].pTexture);

// Save image dimensions
D3DImages[nImage].nImageWidth = D3DImages[nImage].ImageInfo.Width;
D3DImages[nImage].nImageHeight = D3DImages[nImage].ImageInfo.Height;
}

When I sum up all the texutures' size, it's about 54 MB!
When I sum up x and y:

Width: 57230
Height: 56302

This topic is closed to new replies.

Advertisement