draw an image ?

Started by drfloyd, May 10, 2019, 16:49:41

Previous topic - Next topic

Qube

Quote from: Pingus on May 17, 2019, 01:48:27
Does anyone know if drawing several instance of a sprite with DrawSprite count for one draw call overall, or a draw call for each sprite ?
Drawing the same sprite multiple times doesn't really count as a draw call. Drawing different sprites from different textures does. This is the reason that using a sprite atlas for your sprites helps a whole heap as then you can draw hundreds of sprites from the same image rather than the GPU having to swap textures increasing draw calls. In a very basic nutshell drawing a sprite from a different texture is classed as a draw call.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Derron

I would have assumed that a draw stays to be a draw call (a polygon/quad with a texture[part] on it). Changing textures is a texture switch.

Both are "expensive" and the texture switch can get minimized by batching.


Bye
Ron

Steve Elliott

Quote
I would have assumed

You know what they say about assume, you make an ASS-out-of-U-and-ME.   Well make an ass out of Pingus in this case because he's the one asking and Derron is assuming ;D
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Derron

I needed to assume as I did not like to guarantee - Let's hope it is not an "End of the road" (prefer the "Gimme Gimmes" variant) ;-)

A draw call means (in my limited POV) to setup states, shaders, ... for an material thing. Dunno if AGK somehow merges together multiple images of one texture by arranging UVs on a bigger object (polygon instead of quad) or so.
I assume GaborD or other gfx gurus might be able to tell us more about it.


bye
Ron


GaborD

#35
You have it right, Derron. New texture means new batch.
AGK doesn't combine sprite textures or such as far as I know. It does try to batch sprites if they have the same texture, so that's good.
Batch counts should be fairly low unless using tons of individual textures. Even lower if (as you guys already suggested) an atlas is used.

Generally, for a sprite based 2D game I wouldn't see batch count to be an issue, would be hard to not comfortably stay under the max amount the system can handle (usually in the thousands).
In almost every case the game will be fillrate limited, as usual. The stock sprite shader is extremely simple and fast though (one tex lookup and one multiplication in the ps).

The issues start when having thousands of batches, in this case severe CPU bottlenecking can happen, especially when each batch is tiny and can be executed superfast by the GPU.
The CPU will not be able to pack and send all the tiny geometry packets quickly enough to keep the GPU happy and the GPU will start idling inbetween, waiting for data. Thus you lose performance and your app becomes CPU bound instead of using the full power of the GPU.
But this should never be the case in a simple 2D game. That said, if someone exports to a 17 year old toaster, anything can happen :)

Qube

#36
QuoteYou have it right, Derron. New texture means new batch.
Yes a texture switch is a new draw call. At least that's the version I'm more familiar with. No doubt these days with whizzy whizzy techniques it's not as straight forward as that anymore.

QuoteAGK doesn't combine sprite textures or such as far as I know. It does try to batch sprites if they have the same texture, so that's good.
AGK does try and batch sprites and does a great job when all your game sprites are part of the same texture. It has great throughput grunt on it's 2D engine.

QuoteThe issues start when having thousands of batches, in this case severe CPU bottlenecking can happen
You are bang on with that. When dealing with 10'000's of sprites the only realistic option is for the GPU to handle that directly. Sending all that info into the GPU per frame is a real frame rate killer. From my own tests Tier 1 of AGK on a fairly decent setup can comfortably handle around 5000 sprites per frame + a good chunk of game logic.

QuoteYou know what they say about assume
To quote Under Siege 2 - "Assumption is the mother of all fuck ups" ;D

QuoteDunno if AGK somehow merges together multiple images of one texture by arranging UVs on a bigger object (polygon instead of quad) or so.
As mentioned above AGK does attempt to batch sprites together based on their texture. As AGK has atlas support built in it's a no brainier not to use it. It's much faster to use a texture atlas over individually loaded sprites.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

blinkok

When you assume you make an ASS out of U and ME

GaborD

Quote from: Qube on May 18, 2019, 03:26:14
QuoteYou have it right, Derron. New texture means new batch.
Yes a texture switch is a new draw call. At least that's the version I'm more familiar with. No doubt these days with whizzy whizzy techniques it's not as straight forward as that anymore.
Yep, "draw call" fits too, for a discussion about drawing sprites in AGK we can indeed ignore the whizzy whizzy and just see drawcalls and batches as referring to the function call or the data being sent.

Quote from: Qube on May 18, 2019, 03:26:14From my own tests Tier 1 of AGK on a fairly decent setup can comfortably handle around 5000 sprites per frame + a good chunk of game logic.
That's the craziness of modern hardware.  :)
The GPU can comfortably handle a million moving sprites/particles (well, if they are big then you'll get tons of overdraw and fillrate will kill you ofcourse), but there is no way to control them on the CPU and push all the data over. Some trickery is needed.

Quote from: Qube on May 18, 2019, 03:26:14It has great throughput grunt on it's 2D engine.
Agreed. AGK is so underrated.
People vastly underestimate how much power is available under the hood. Both in 2D and 3D. Learned that the hard way with the "fake!" complainers lol.

Agree on atlas usage for sprites. Always a good idea.

drfloyd

#39
Hello
I come back...
I want to give a chance to AGK :)

If I unterstand, if i create 100 tiles, all the tiles will be on screen on the same time !!!!!

Does it mean that on each loop i should start by hide all the tiles (sprites) ?

for i=1 to 100
setspritevisible(i,0)
next

(instead of CLS or Clearscreen in other classic basic languages)

and then I decide which tiles I active + its position with :

setspritevisible(7,1)
setspriteposition(7,123,234)
sync()

is that correct ????

Derron

Qube wrote that it depends on the way you set the sprite up - relative positions or absolute positions.
Absolute positions: you need to draw them manually
Relative positions (percentage): automatic rendering except they are hidden


bye
Ron

drfloyd

#41
Yes, i used Pqube method but it doesnt work. Each sprite iI load is visible
Exemple with a empty loop :


SetVirtualResolution( 320, 240 )

temp=loadimage("cache.png")
cache=createsprite(temp)

// want to draw Nothing but it draw :/
do
//setspriteposition(cache,50,50)
       //drawsprite (cache)

    Sync()
loop



even without drawing the sprite, it display it at 0,0... It is for that reason i ask if I should do a setspritevisible(cache,0) at each loop ?

so i try another solution :


SetVirtualResolution( 320, 240 ) // doesn't have to match the window
cache=loadimage("cache.png")

do

setspriteposition(cache,50,50)
drawsprite (cache)

    Sync()
loop



the sprite does not appear, but when i activate drawsprite, it say that the sprite does not exist...


Qube

QuoteYes, i used Pqube method but it doesnt work. Each sprite iI load is visible
All you keep saying is "Doesn't work"  ::) - READ THE MANUAL :P

If you read the manual you'll see that your code should be :

SetVirtualResolution( 320, 240 )

temp=loadimage("cache.png")
cache=createsprite(temp)

// want to draw Nothing but it draw :/
do
       setspriteposition(cache,50,50)
       drawsprite (cache)

    Swap() // THIS IS WHAT YOU USE IF YOU ONLY WANT SPRITES TO SHOW WHEN DRAWN WITH THE DRAWSPRITE COMMAND
loop


Sync() will draw all sprites unless hidden.
Swap() with ONLY draw sprites that you've drawn with the DrawSprite command and does not require you to hide sprites.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

GaborD

#43
@drfloyd
Keep in mind Swap() will not auto draw anything, no 3D, no sprites, no print commands (text is also in Render2DFront(), just like sprites.)
Just adding this so you don't eventually wonder why your print commands suddenly don't work. :)

Just to clarify:
Sync() is a shortcut for
Update(), Render(), Swap()

Render() is a shortcut for
Render2DBack(), ClearDepthBuffer(), Render3D(), ClearDepthBuffer(), Render2DFront()


Qube

Quote from: GaborD on May 19, 2019, 15:59:52
@drfloyd
Keep in mind Swap() will not auto draw anything, no 3D, no sprites, no print commands (text is also in Render2DFront(), just like sprites.)
Just adding this so you don't eventually wonder why your print commands suddenly don't work. :)

Just to clarify:
Sync() is a shortcut for
Update(), Render(), Swap()

Render() is a shortcut for
Render2DBack(), ClearDepthBuffer(), Render3D(), ClearDepthBuffer(), Render2DFront()
One step at a time, he's not got the hang of drawing sprites yet :P
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.