GameMaker Question about texture page optimization

S

SayBaconOneMoreTime

Guest
Hi there,

So regarding texture pages: my current set up has everything separated by room/theme, and every room change flushes texture memory during the transition so there aren't any visible stutters. Is this a good set up? Since my room backgrounds are hand drawn, I have one texture page per room for the background, and then a texture page for a set of enemies that belong to one theme; i.e., all the enemies belonging to a forest region would be on one texture page, all the ones for a cave area would be in another one, etc., then another texture page for things always on screen, i.e. player character, HUD elements, that sort of thing. Am I doing it wrong, or is this about right?
 

obscene

Member
Sounds good, but with regards to changing enemies and things from level to level.... that can be helpful to reduce your game's RAM usage but you can have a negative effect on performance if you have texture pages sharing the same depths.

What I mean is that since objects are drawn according to their depth, if you have a lot of objects with the same depths pulling sprites from different texture pages you will end up with lots of swaps. So you want to have a system that considers that. So I'd make sure when you load in your enemy sprites in a certain level that those objects aren't intermingling in the draw-order with stuff from other texture pages or you will see performance drop.
 
S

SayBaconOneMoreTime

Guest
Sounds good, but with regards to changing enemies and things from level to level.... that can be helpful to reduce your game's RAM usage but you can have a negative effect on performance if you have texture pages sharing the same depths.

What I mean is that since objects are drawn according to their depth, if you have a lot of objects with the same depths pulling sprites from different texture pages you will end up with lots of swaps. So you want to have a system that considers that. So I'd make sure when you load in your enemy sprites in a certain level that those objects aren't intermingling in the draw-order with stuff from other texture pages or you will see performance drop.
Well, since I have a top-down game, things are being drawn from one object in a sequence from two different texture pages. Is that ok?
 

obscene

Member
You should probably turn on the debug overlay ( show_debug_overlay(true) ).

Two texture pages or 20, you could get the same bad results if you do it wrong.

What you want to do is this..
draw sprites from texture page 1
draw sprites from texture page 2

Instead of this..
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2

With the overlay on, you'll see the number of swaps. There are 4 built-in swaps and the rest are caused by your draw order, so if it's 6 or 8 you are doing good and if its 20 you should re-organize.
 
S

SayBaconOneMoreTime

Guest
You should probably turn on the debug overlay ( show_debug_overlay(true) ).

Two texture pages or 20, you could get the same bad results if you do it wrong.

What you want to do is this..
draw sprites from texture page 1
draw sprites from texture page 2

Instead of this..
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2
draw sprite from texture page 1
draw sprite from texture page 2

With the overlay on, you'll see the number of swaps. There are 4 built-in swaps and the rest are caused by your draw order, so if it's 6 or 8 you are doing good and if its 20 you should re-organize.
Hey, sorry for the necro post, but I finally got around to looking at this with the debug overlay on, and we are sitting at 33 texture swaps. The thing is, I can't exactly do it the way you are saying, because, since I'm making a Zelda-ish game which runs top down, I have to draw them in that order, so that depth perception works out. I have my sleep margin set at like 17 (worked out the math for the max sleep margin for the game to run at 60 fps, that's what I came up with), and it runs fine, and I'm not trying to develop for mobile or anything, but I don't know. I have a fairly high-end machine, which could mean it is really bad but the game just works because beefy computer. How does one fix that problem in that context? I really don't know how one could even start to handle that.

EDIT: Looked through all my rooms, 33 is the cap. It's typically around 20, which I realize isn't much better, but still, need to give all the info I got. Even when it is that high, the debug overlay thing is spitting out 200 FPS, and that number only goes up in different rooms. Typically it sticks around 300. However, I know that what the debug overlay displays isn't necessarily how many FPS I actually have, so once again, I don't know. Has anyone else run into this same problem and has a fix? I'm kinda stuck. Don't want high system reqs for a pixel art game. Looks bad.
 
Last edited by a moderator:

obscene

Member
I've never done top-down but often thought about how I'd approach it because of texture swaps. Some assumptions...

Use large texture page size.

Try to fit all normal props / characters onto one texture page.

Separate background tiles / floor textures etc into a group. All that stuff should be drawn before the props / characters right?

Separate group for treetops and things that are drawn overtop the characters. All that stuff should be drawn by a controller object after the normal prop drawing is done.

Large sprites or groups of sprites drawn together (bosses etc) should be separated too but only IF it helps get the normal stuff squeezed onto one page.

Separate group for post effects and GUI elements.

Again, no practical experience with it but I'm sure there are optimizations that can be made. If it's pixel art I would assume the sprites aren't big anyway, so surely a 4096x4096 pages could fit all your props/characters?

I'd be curious to open up Link to the Past in ZSNES and disable the individual layers and see how they do it. That could be helpful.
 
Last edited:
S

SayBaconOneMoreTime

Guest
I've never done top-down but often thought about how I'd approach it because of texture swaps. Some assumptions...

Use large texture page size.

Try to fit all normal props / characters onto one texture page.

Separate background tiles / floor textures etc into a group. All that stuff should be drawn before the props / characters right?

Separate group for treetops and things that are drawn overtop the characters. All that stuff should be drawn by a controller object after the normal prop drawing is done.

Large sprites or groups of sprites drawn together (bosses etc) should be separated too but only IF it helps get the normal stuff squeezed onto one page.

Separate group for post effects and GUI elements.

Again, no practical experience with it but I'm sure there are optimizations that can be made. If it's pixel art I would assume the sprites aren't big anyway, so surely a 4096x4096 pages could fit all your props/characters?

I'd be curious to open up Link to the Past in ZSNES and disable the individual layers and see how they do it. That could be helpful.
I'm currently using 2048x2048, thanks for the recommendation. You're right, I can definitely fit most if not all characters onto one sheet at that resolution. I can definitely do GUI stuff on one page and draw all of it in one go, but as far as the over-top stuff goes... it doesn't really exist. I'm using a priority queue for drawing things, which in terms of draw order is basically the old depth = -y trick. I have a few things that I know will be drawn at the end; you're saying they should go in their own texture page? And yeah, I'm thinking bosses should get their own page as well, since you know, big sprites and stuff. What is ZSNES? I'm curious.

EDIT: Yeah, all my player animations plus a few other characters will go onto one 512x512, so feasibly all my characters that will need to appear in multiple rooms will fit into one texture page. I see no point in not just including the sprites for a character specific to one room in that room's texture page (for its backgrounds and stuff). Is my logic bad and I should feel bad, or am I right there?
 
Last edited by a moderator:

obscene

Member
It's really hard to give sound advice as to what to do because I know little about your game... I can only give you the general idea.

In theory, the best possible solution is to fit every single graphic onto one texture page. Every time you add a page you are doing a bad thing. :p So the only reason you want to add pages is when you HAVE to in order to avoid letting GM do it automatically.

You have to analyze your draw order, considering the depths of your objects, draw events (begin, normal, end), backgrounds, foregrounds etc as well as your draw controller objects. Knowing what draws first / last is the key. Then, split off some grouping of your graphics that you know are all drawn together. The GUI is a good example of that. All GUI graphics on one sheet and you know that it will only take one texture swap to draw your entire GUI. When those graphics are off your main texture group, hopefully the rest of your game will fit on it. If not, repeat the process trying to find any group of sprites you know will be drawn together (backgrounds for instance). Now you know it will only take one texture swap to draw your background, one for GUI and one for all the rest.

Just whatever you do, don't let GM automatically make multiple pages for any one group.

If you want me to take a look at your project sometime I may be able to tell you more.
 

Mr Errorz

Member
It's really hard to give sound advice as to what to do because I know little about your game... I can only give you the general idea.

In theory, the best possible solution is to fit every single graphic onto one texture page. Every time you add a page you are doing a bad thing. :p So the only reason you want to add pages is when you HAVE to in order to avoid letting GM do it automatically.

You have to analyze your draw order, considering the depths of your objects, draw events (begin, normal, end), backgrounds, foregrounds etc as well as your draw controller objects. Knowing what draws first / last is the key. Then, split off some grouping of your graphics that you know are all drawn together. The GUI is a good example of that. All GUI graphics on one sheet and you know that it will only take one texture swap to draw your entire GUI. When those graphics are off your main texture group, hopefully the rest of your game will fit on it. If not, repeat the process trying to find any group of sprites you know will be drawn together (backgrounds for instance). Now you know it will only take one texture swap to draw your background, one for GUI and one for all the rest.

Just whatever you do, don't let GM automatically make multiple pages for any one group.

If you want me to take a look at your project sometime I may be able to tell you more.
What do you mean by: Just whatever you do, don't let GM automatically make multiple pages for any one group.
How can one control that? I thought the only control you have is assigning assets to diff texture groups, not creating the actual pages..
Or have I got it wrong?
 

obscene

Member
Just meaning that if you put more graphics in one group than will fit on one page, GM will make two pages out of it and there won't be any rhyme or reason which could cause a lot of swaps.

So at that point you would want to find the most efficient way to split it into two groups.
 

Mr Errorz

Member
Just meaning that if you put more graphics in one group than will fit on one page, GM will make two pages out of it and there won't be any rhyme or reason which could cause a lot of swaps.

So at that point you would want to find the most efficient way to split it into two groups.
oh okay, got it.
 
Top