(Optimization) Primitives and Surfaces

D

Diogo

Guest
Hello. :)

I was thinking about doing some optimization in my game, and found this: https://forums.tigsource.com/index.php?topic=3747.0

This is from 2008 so the question is: Is it still more efficient to use a surface to draw primitives (draw_circle, draw_line, draw_triangle, etc.) to, and only then drawing to the screen? Or has it been "automated" since then, on GM:S?

Thanks!
 
D

Diogo

Guest
Alright, thanks!

Although your wording on "re-drawing primitives on each frame" makes me think you may have misunderstood the question.
I'm not talking about saving the surface between frames and reusing it.

I mean about { n primitives -> surface -> screen } vs { n primitives -> screen }. (At least that's what I think the tigsource tip was about).


But either way, I appreciate the answer.
 
Z

Zaeith

Guest
It is far more efficient to draw 50,000 triangles than it is to draw a single surface (I know this from experience).
I agree with @Lonewolff but it depends on what you're doing. If the primitives are not changing or moving on screen, then drawing to a surface and redrawing that surface would be faster. That is, drawing 50,000 triangles once to a surface and then redrawing that surface to draw the triangles instead of drawing the triangles individually. This would be useful for a phone game where the screen size is small and doesn't change much or a game like the in the intermediate surfaces tutorial where the "decal" sprites are not moving.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It is far more efficient to draw 50,000 triangles than it is to draw a single surface (I know this from experience).
You really should caveat that comment... I mean, it will all depend on whether you are updating the surface every frame, what you are actually updating the surface with, and the target platform. As for prims, it will depend on how you are drawing them, whether it's all done in a single batch, and whether you are using a (frozen?) vertex buffer or not. Can you give us the details of what your test was? Would be interesting to test...
 
S

seanm

Guest
I'm still not sure what you are talking about with surfaces.

An empty room nets me ~2k fps.
A room with 17 1080p surfaces nets me ~1k fps.



All I have is an empty room and 17 surface objects with this as their draw code. (i just use a controller to add them to the room during runtime)
Code:
if !surface_exists(surf)
surf=surface_create(1920,1080)


surface_set_target(surf)

draw_clear_alpha(1,0)

draw_circle(random(room_width),random(room_height),10,false)

surface_reset_target()

draw_surface(surf,0,0)
A full screen surface (at least in an empty project) does not do anything close to halving my fps

EDIT: Seems I can get to ~150 of these surfaces before my FPS drops below 200, but at this point the fps immediately dips to 20 fps, which is strange.
 
Last edited:
S

seanm

Guest
Ah I think I see what you mean, copying a surface onto another surface will half the fps. I was saying that just drawing surfaces doesn't half fps.

I'll test that out, and test out your gmz.


e:
------------------
On your example I get ~1250 FPS


@Lonewolff Yeah ok drawing one surface onto another surface, 5 times, I get ~500 fps.
 
Last edited:
@Nocturne - Apologies for the double post. But I figured you may miss the update.

www.win32developer.com/downloads/geometry_example.gmz

I did a quick example of what I was on about. :)

Rendering 3 different square models (20K tri's each), 3 separate draw calls, each with its own shader (because I'm lazy), and individual transforms.

In total just over 60,000 triangles whilst still maintaining 1,000 FPS. Granted, in this scene I haven't mapped any textures. But gives an idea as to why I use surfaces as sparingly as possible.

If I chose to use a single full screen surface for this (say one or two of the squares were static and I combine them to a surface for 'efficiency'), then frame rate would be roughly halved to 500 FPS.

Surfaces are great and sometimes we have to use them through no other choice. But, they are not the 'optimisation' that they are cracked up to be.
I'd like to know more about that link that you posted. What kinds of things break a batch exactly? I'm specifically interested in whether changes to a shader uniform will break a batch.
 
Top