Hello, new member reporting

Hi everyone! I’ve just joined SDL list, how are you people?

I’m learning SDL, and need some help :slight_smile: I’m trying to do a hardware scrolling (I think thats the name), but I can’t find a info on accessing the video memory the way SDL_Flip does. I searched the FAQs, wikiDoc, google…

Heres what I want to do: blit an image to the video memory, larger than the actual display, and then just change the pixel pointer of the SDL surface to scroll through the image, hence saving lots of blittings :slight_smile:
But it seems SDL doesn’t allow that, meaning any methods I use might not be as portable, maybe using openGL.
I can’t find info on how to get video memory limits so I don’t go over the edge… etc.

Could someone, please, point me to the right direction? I will be searching the list archives now :slight_smile: thanks!

Cheers,
AM

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

I could be wrong, but I don’t think modern graphics hardware supports
this. I can tell you OpenGL definitely doesn’t have this feature. I
doubt DirectX does either.

The optimization you’re trying to make has not been considered
important to video game graphics for quite a while.

The best you’ll probably be able to do is use a large surface, and
blit a subsection of that surface to the screen each frame, and move
your own X and Y values.On Sun, Jan 25, 2009 at 3:47 PM, Antonio Marcos wrote:

Heres what I want to do: blit an image to the video memory, larger than the actual display, and then just change the pixel pointer of the SDL surface to scroll through the image, hence saving lots of blittings :slight_smile:
But it seems SDL doesn’t allow that, meaning any methods I use might not be as portable, maybe using openGL.
I can’t find info on how to get video memory limits so I don’t go over the edge… etc.

Could someone, please, point me to the right direction? I will be searching the list archives now :slight_smile: thanks!


http://codebad.com/

[…hardware scrolling…]

I could be wrong, but I don’t think modern graphics hardware
supports this.

Actually, most hardware does support it, but it’s only used
for “virtual desktop” (desktop larger than the display) and things
like that… Probably not very portable or reliable stuff, if it’s at
all accessible to normal applications. (From what I’ve seen of this
stuff on Windows, it may as well be internal driver hacks.)

So, full screen redrawing it is!

If performance is an issue, you could implement it over OpenGL or
Direct3D, for hardware blitting and keeping it all in VRAM. With SDL
1.3/2.0, you don’t even have to touch those APIs directly to do this,
and it’ll still work with “software-only” displays as a fallback.

On the bright side, using blitting instead of hardware scrolling gives
you a lot more freedom when it comes to layering, screen layout,
blending effects etc.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 25 January 2009, Donny Viszneki wrote:

Cool, an active list :slight_smile: sorry if the subject changing messed things up. :frowning:

stuff on Windows, it may as well be internal driver hacks.)

lol… :frowning:

So, full screen redrawing it is!

dang!

If performance is an issue, you could implement it over
OpenGL or
Direct3D, for hardware blitting and keeping it all in VRAM.
With SDL
1.3/2.0, you don’t even have to touch those APIs
directly to do this,
and it’ll still work with "software-only"
displays as a fallback.

Nice… So I would have to set openGL surfaces, right? (didnt learned much about it yet)

On the bright side, using blitting instead of hardware
scrolling gives
you a lot more freedom when it comes to layering, screen
layout,
blending effects etc.

I was actually going to use both… hardware scrolling would allow to only pump updates from RAm to VRAM … and if I could have full access to the Video memory, I could even prevent ANY pumping at all! :slight_smile: as I would have most data there. Performance is probably an issue because Im planning on sync’n with vertical refresh. Oh look, just found an old thread about this! :slight_smile:

AM.— Em dom, 25/1/09, David Olofson escreveu:

Actually, most hardware does support it, but it’s only
used
for “virtual desktop” (desktop larger than the
display) and things
like that… Probably not very portable or reliable stuff,
if it’s at
all accessible to normal applications. (From what I’ve
seen of this
stuff on Windows, it may as well be internal driver hacks.)

So, full screen redrawing it is!

If performance is an issue, you could implement it over
OpenGL or
Direct3D, for hardware blitting and keeping it all in VRAM.
With SDL
1.3/2.0, you don’t even have to touch those APIs
directly to do this,
and it’ll still work with "software-only"
displays as a fallback.

On the bright side, using blitting instead of hardware
scrolling gives
you a lot more freedom when it comes to layering, screen
layout,
blending effects etc.

//David Olofson - Programmer, Composer, Open Source
Advocate

.------- http://olofson.net - Games, SDL examples
-------.
| http://zeespace.net - 2.5D rendering engine
|
| http://audiality.org - Music/audio engine
|
| http://eel.olofson.net - Real time scripting
|
’-- http://www.reologica.se - Rheology instrumentation
–’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

Oops, sorry Donny, it seems the reply function used your email instead of the list’s :frowning:

I could be wrong, but I don’t think modern graphics
hardware supports
this. I can tell you OpenGL definitely doesn’t
have
this feature. I
doubt DirectX does either.

:frowning: I guess I’ll have to wait for CUDA then? :frowning:

The optimization you’re trying to make has not
been
considered
important to video game graphics for quite a while.

really?! gee… I guess people just doesnt want as much
crazy sprites (read: visual polution :)) on the screen as I
do. :frowning:

The best you’ll probably be able to do is use a
large
surface, and
blit a subsection of that surface to the screen each
frame,
and move
your own X and Y values.

Hmm… I dont quite get what you mean, I would still have to
go from RAM to VRAM too much… What I could do though is…
blit the current display to the back buffer… then flip
back. But I would have to have access to it, as a separe
surface (or access to its pointer, which I guess would just
be a matter of reading it before and after a flip)…

…what happens if I blit from *screen to *screen? does SDL
gets that the source surface Im referring to is the current
display, or it considers all access to double buffered
screen as an access to the back buffer?

Im seeing some info on multi-buffer… (quad-buffer… wow
:)), so it seems possible :slight_smile:

thanks!
AM> — Em dom, 25/1/09, Donny Viszneki <donny.viszneki at gmail.com> escreveu:

De: Donny Viszneki <donny.viszneki at gmail.com>
Assunto: Re: [SDL] Hello, new member reporting
Para: @Antonio_Marcos, “A list for
developers using the SDL library. (includes
SDL-announce)”
Data: Domingo, 25 de Janeiro de 2009, 18:54
On Sun, Jan 25, 2009 at 3:47 PM, Antonio Marcos <@Antonio_Marcos> wrote:

Heres what I want to do: blit an image to the
video
memory, larger than the actual display, and then just
change
the pixel pointer of the SDL surface to scroll through
the
image, hence saving lots of blittings :slight_smile:

But it seems SDL doesn’t allow that, meaning
any
methods I use might not be as portable, maybe using
openGL.

I can’t find info on how to get video memory
limits so I don’t go over the edge… etc.

Could someone, please, point me to the right
direction? I will be searching the list archives now
:slight_smile:
thanks!

I could be wrong, but I don’t think modern
graphics
hardware supports
this. I can tell you OpenGL definitely doesn’t
have
this feature. I
doubt DirectX does either.

The optimization you’re trying to make has not
been
considered
important to video game graphics for quite a while.

The best you’ll probably be able to do is use a
large
surface, and
blit a subsection of that surface to the screen each
frame,
and move
your own X and Y values.


http://codebad.com/

  Veja quais s?o os assuntos do momento no Yahoo!

+Buscados
http://br.maisbuscados.yahoo.com

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

The optimization you’re trying to make has not
been
considered
important to video game graphics for quite a while.

really?! gee… I guess people just doesnt want as much
crazy sprites (read: visual polution :)) on the screen as I
do. :frowning:

1920x1200 in TrueColor (32 bit per pixel) is about 9 MB. A 1997-era
nVidia Riva 128 has 1.6 GB/s of memory bandwidth, giving you about 88
fps (assuming a read and a write). That’s quite the high resolution,
and that’s quite the old video card. On the video card in my iMac,
that’d give more than 3000 fps, and even a crappy Intel integrated
chip would still give you upward of 180 fps.

You’ve gotta have a lot of sprites to overload these guys. :slight_smile:

Note that to do any of this, you have to keep the CPU out of the loop,
otherwise that involves going over the busses. If your code has a
pointer to the video memory (such as what you get when using
SDL_LockSurface), you’re likely to be involving the CPU, and it all
shoots down the drain.

Wanting to wait for the vertical refresh is also a sign of trying to
micro-manage things. Some video hardware can take care of all that by
itself, where if a blit command is posted, the GPU can wait until the
retrace is past the destination area, instead of waiting for the
retrace to be at the bottom. After all, why wait until it’s at the
bottom if you’re blitting to the very top of the screen? Some clever
cards/drivers could even reorder blits to non-overlapping destinations
(for example, if you blit to the bottom and then the top, actually do
the top while the retrace goes down).

If you ask for DOS-style, down to the metal control, video hardware
and drivers have very little opportunity to improve things in ways you
might not have thought of, or might not be possible to you (with
standard VGA, you only know if the retrace is in the screen or if it
is blanked, not enough information to pull the previous trick).On Sun, Jan 25, 2009 at 4:58 PM, Antonio Marcos wrote:


http://pphaneuf.livejournal.com/

Hey, welcome to the community!
I don’t know how it would work in video memory, but it sounds like something
that can be done (in software, at least) by twiddling with void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch. I’ve never tried it, of
course, but I hope you can find a way to achieve your desired effect.

Jonny DOn Sun, Jan 25, 2009 at 4:22 PM, David Olofson wrote:

On Sunday 25 January 2009, Donny Viszneki wrote:
[…hardware scrolling…]

I could be wrong, but I don’t think modern graphics hardware
supports this.

Actually, most hardware does support it, but it’s only used
for “virtual desktop” (desktop larger than the display) and things
like that… Probably not very portable or reliable stuff, if it’s at
all accessible to normal applications. (From what I’ve seen of this
stuff on Windows, it may as well be internal driver hacks.)

So, full screen redrawing it is!

If performance is an issue, you could implement it over OpenGL or
Direct3D, for hardware blitting and keeping it all in VRAM. With SDL
1.3/2.0, you don’t even have to touch those APIs directly to do this,
and it’ll still work with “software-only” displays as a fallback.

On the bright side, using blitting instead of hardware scrolling gives
you a lot more freedom when it comes to layering, screen layout,
blending effects etc.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You’ve gotta have a lot of sprites to overload these guys. :slight_smile:

mwahaha… indeed! :slight_smile: Thanks Pierre, thats quite reassuring.
Just curious: whats the actual resolution and pixel depth
you use there?

(assuming a read and a write)

What you mean? why would I read from the video memory? I
would (probably) have the last frame on RAM already, unless
it was a composition of images… why read?

chip would still give you upward of 180 fps.

Just wondering: I still have plenty to do, like input
processing and actual game state calculations, BEFORE I can
send data to the card, so I guess I would have quite less
than 1 second to send those 1.6GB.
But again maybe it would be more a matter of breaking
things down in more steps, since more fps would require less
calculations per frame? Though not much… like if I have a
formula for movement, its still have to calculate the same
operations…

Note that to do any of this, you have to keep the CPU out
of the loop,
otherwise that involves going over the busses. If your code
has a
pointer to the video memory (such as what you get when
using
SDL_LockSurface), you’re likely to be involving the
CPU, and it all
shoots down the drain.

no no… the idea is to just change where the pointer points
to. Like SDL_Flip does. Also, I believe if i only call
operations on the card, the cpu would not be involved, would
it? :frowning: I mean, say you have a sprite on the vRAM, if you
just blit it to the display, the commands happened only on
the card, right? I mean, thats why hardware blitting is
feasible, so everything else dont get in the way… no?
I didnt get what you mean by ‘involving the cpu’,
when i lock the surface my objective is to just copy
something and unlock asap, i wouldn’t be calculating
stuff… what you mean?

Wanting to wait for the vertical refresh is also a sign of
trying to micro-manage things.

Yep :slight_smile: But your email was reassuring enough to take me
(mostly) out of this… The point was just to have as much
fps as possible, and the upper limit is the refresh
rate.(its pointless to have more) But still, its quite
useful to know whats the retrace rate of the monitor, do you
guys know how to get this info? SDL provides this?

is blanked, not enough information to pull the previous
trick).

you’re right. thanks :slight_smile: Also, this is the thing that
would probably involve too much CPU… though I believe CUDA
will change this :slight_smile: and allow me to get more crazy on the
vRAM :smiley: though not many users would be benefiting =/

cheers,
AM> — Em seg, 26/1/09, Pierre Phaneuf escreveu:

De: Pierre Phaneuf
Assunto: Re: [SDL] DirectAccess to Video Memory [was:
Hello, new member reporting]
Para: @Antonio_Marcos, “A list for
developers using the SDL library. (includes
SDL-announce)”
Data: Segunda-feira, 26 de Janeiro de 2009, 4:19
On Sun, Jan 25, 2009 at 4:58 PM, Antonio Marcos <@Antonio_Marcos> wrote:

The optimization you’re trying to make
has
not

been

considered
important to video game graphics for quite
a
while.

really?! gee… I guess people just doesnt want
as
much

crazy sprites (read: visual polution :)) on the
screen as I
do. :frowning:

1920x1200 in TrueColor (32 bit per pixel) is about 9
MB. A
1997-era
nVidia Riva 128 has 1.6 GB/s of memory bandwidth,
giving
you about 88
fps (assuming a read and a write). That’s quite
the
high resolution,
and that’s quite the old video card. On the video
card
in my iMac,
that’d give more than 3000 fps, and even a crappy
Intel
integrated
chip would still give you upward of 180 fps.

You’ve gotta have a lot of sprites to overload
these
guys. :slight_smile:

Note that to do any of this, you have to keep the CPU
out
of the loop,
otherwise that involves going over the busses. If your
code
has a
pointer to the video memory (such as what you get when
using
SDL_LockSurface), you’re likely to be involving
the
CPU, and it all
shoots down the drain.

Wanting to wait for the vertical refresh is also a
sign of
trying to
micro-manage things. Some video hardware can take care
of
all that by
itself, where if a blit command is posted, the GPU can
wait
until the
retrace is past the destination area, instead of
waiting
for the
retrace to be at the bottom. After all, why wait until
it’s at the
bottom if you’re blitting to the very top of the
screen? Some clever
cards/drivers could even reorder blits to
non-overlapping
destinations
(for example, if you blit to the bottom and then the
top,
actually do
the top while the retrace goes down).

If you ask for DOS-style, down to the metal control,
video
hardware
and drivers have very little opportunity to improve
things
in ways you
might not have thought of, or might not be possible to
you
(with
standard VGA, you only know if the retrace is in the
screen
or if it
is blanked, not enough information to pull the
previous
trick).


http://pphaneuf.livejournal.com/

  Veja quais s?o os assuntos do momento no Yahoo!

+Buscados
http://br.maisbuscados.yahoo.com

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

Hey, welcome to the community!

Hey, Thanks! :slight_smile:

I don’t know how it would work in video memory, but it
sounds like something
that can be done (in software, at least) by twiddling with
void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.

I was thinking about something like that, but I have no idea how the inner workings would proceed to know if its doing th actual thing. I was thinking about creating a bigger resolution surface with the SetVideoMode, get the pointer, and then reset to a lower resolution. The problem with this is that SDL have privileges to work with the hardware (at least on some OS’es i guess), and this would probably bypass it… also, I dont know if the ‘freed’ parts of the memory would be used by something else.

I’ve never tried it, of
course, but I hope you can find a way to achieve your
desired effect.

It would be nice because changing a “camera view” would just be a matter of incrementing/decrementing a pointer :slight_smile:

Jonny D

AM.— Em seg, 26/1/09, Jonathan Dearborn escreveu:

De: Jonathan Dearborn
Assunto: Re: [SDL] Hello, new member reporting
Para: “A list for developers using the SDL library. (includes SDL-announce)”
Data: Segunda-feira, 26 de Janeiro de 2009, 11:03
Hey, welcome to the community!
I don’t know how it would work in video memory, but it
sounds like something
that can be done (in software, at least) by twiddling with
void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.
I’ve never tried it, of
course, but I hope you can find a way to achieve your
desired effect.

Jonny D

On Sun, Jan 25, 2009 at 4:22 PM, David Olofson wrote:

On Sunday 25 January 2009, Donny Viszneki wrote:
[…hardware scrolling…]

I could be wrong, but I don’t think modern
graphics hardware

supports this.

Actually, most hardware does support it, but it’s
only used
for “virtual desktop” (desktop larger than
the display) and things
like that… Probably not very portable or reliable
stuff, if it’s at
all accessible to normal applications. (From what
I’ve seen of this
stuff on Windows, it may as well be internal driver
hacks.)

So, full screen redrawing it is!

If performance is an issue, you could implement it
over OpenGL or
Direct3D, for hardware blitting and keeping it all in
VRAM. With SDL
1.3/2.0, you don’t even have to touch those APIs
directly to do this,
and it’ll still work with
"software-only" displays as a fallback.

On the bright side, using blitting instead of hardware
scrolling gives
you a lot more freedom when it comes to layering,
screen layout,
blending effects etc.

//David Olofson - Programmer, Composer, Open Source
Advocate

.------- http://olofson.net - Games, SDL examples
-------.
| http://zeespace.net - 2.5D rendering engine
|
| http://audiality.org - Music/audio engine
|
| http://eel.olofson.net - Real time scripting
|
’-- http://www.reologica.se - Rheology
instrumentation --’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

You’ve gotta have a lot of sprites to overload these guys. :slight_smile:

mwahaha… indeed! :slight_smile: Thanks Pierre, thats quite reassuring.
Just curious: whats the actual resolution and pixel depth
you use there?

My “approximately 9 MB” was using 1920x1200, at 32 bit per pixels
(either padded RGB or RGBA).

(assuming a read and a write)

What you mean? why would I read from the video memory? I
would (probably) have the last frame on RAM already, unless
it was a composition of images… why read?

A blit from one place to the other involves reading, then writing, so
if the video card is capable of moving 3.2 GB/s between the GPU and
video memory, you need to halve it to figure out the theoretical
maximum frame rate. You’d be able to do a solid color fill (or some
other procedural fill) at the full speed, of course.

Note that those bandwidths I cited are GPU to video memory bandwidth.

chip would still give you upward of 180 fps.

Just wondering: I still have plenty to do, like input
processing and actual game state calculations, BEFORE I can
send data to the card, so I guess I would have quite less
than 1 second to send those 1.6GB.

Again, those were assuming the data was already on the video card, and
that you just played with the offset (trying to emulate
vga_setdisplaystart, for the Svgalib refugees reading this), so doing
this emulation by using a tall surface (say 1920x3600) and then
blitting the 1920x1200 “slice” that you want for this frame to the
framebuffer. Since I’m talking about the work being done by the GPU,
sending that command is actually very quick for your code, leaving it
plenty of time to do other stuff.

It is true that updating that 1920x3600 would eat into that memory
bandwidth, of course, but that’s why you should choose a maximum
resolution that would still give you 150 fps and up (considering many
video cards would be able to get you in the thousands of fps).

no no… the idea is to just change where the pointer points
to. Like SDL_Flip does. Also, I believe if i only call
operations on the card, the cpu would not be involved, would
it? :frowning: I mean, say you have a sprite on the vRAM, if you
just blit it to the display, the commands happened only on
the card, right? I mean, thats why hardware blitting is
feasible, so everything else dont get in the way… no?
I didnt get what you mean by ‘involving the cpu’,
when i lock the surface my objective is to just copy
something and unlock asap, i wouldn’t be calculating
stuff… what you mean?

You can verify the code for SDL_Flip yourself, but I’m afraid that 98%
of the time, it doesn’t actually “flip” (moving the framebuffer
starting offset), but actually blits from a backbuffer (it certainly
never does with Xlib, and I’d think it doesn’t with Mac OS X, it might
still be the case with the deprecated Direct2D driver in fullscreen
mode, but that’s about it). With SDL 1.3, it’s just a call to
SDL_UpdateRect the whole screen, all the time.

But I see you have the correct idea. I think the alarm was raised in
my head when you asked things like finding out how much video memory
there is, earlier on.

A key bit of information that a lot of people seem to miss out on is
that SDL is actually just an abstraction layer: there’s nothing it can
do that you cannot do using the platform APIs. I don’t know why, but I
often see people under the impression that (for example) “Xlib is
slow, so I’m using SDL instead” or something like that. No magic, if
Xlib can’t do it, then SDL can’t. It tries to be careful, using some
very optimized assembly pixel format conversion code, for example, but
no real magic.

Yep :slight_smile: But your email was reassuring enough to take me
(mostly) out of this… The point was just to have as much
fps as possible, and the upper limit is the refresh
rate.(its pointless to have more) But still, its quite
useful to know whats the retrace rate of the monitor, do you
guys know how to get this info? SDL provides this?

I don’t think SDL provides that information, as it’s too difficult to
get, but SDL_Flip and SDL_UpdateRect would most likely end up
throttling your application, much like when using glXSwapBuffers (when
vsync is enabled).On Mon, Jan 26, 2009 at 8:18 AM, Antonio Marcos wrote:


http://pphaneuf.livejournal.com/

Reminds me of some of the neat tricks used to make Super Mario Bros 3
possible (although if too many sprites occupy the same horizon, they
do start to flicker!)On Mon, Jan 26, 2009 at 1:19 AM, Pierre Phaneuf wrote:

Wanting to wait for the vertical refresh is also a sign of trying to
micro-manage things. Some video hardware can take care of all that by
itself, where if a blit command is posted, the GPU can wait until the
retrace is past the destination area, instead of waiting for the
retrace to be at the bottom. After all, why wait until it’s at the
bottom if you’re blitting to the very top of the screen? Some clever
cards/drivers could even reorder blits to non-overlapping destinations
(for example, if you blit to the bottom and then the top, actually do
the top while the retrace goes down).


http://codebad.com/

Reminds me of some of the neat tricks used to make Super
Mario Bros 3 possible

huahaha… I love those kind of tricks, but on newer machines you dont get this hacking opportunity very often :slight_smile:

(although if too many sprites occupy the same
horizon, they do start to flicker!)

wow, you noticed that only playing? or you helped on some nes emulator or something, I dont remember any flicker when I played mario 3.

Cheers,
AM— Em seg, 26/1/09, Donny Viszneki <donny.viszneki at gmail.com> escreveu:

De: Donny Viszneki <donny.viszneki at gmail.com>
Assunto: Re: [SDL] DirectAccess to Video Memory [was: Hello, new member reporting]
Para: “A list for developers using the SDL library. (includes SDL-announce)”
Data: Segunda-feira, 26 de Janeiro de 2009, 13:46
On Mon, Jan 26, 2009 at 1:19 AM, Pierre Phaneuf wrote:

Wanting to wait for the vertical refresh is also a
sign of trying to
micro-manage things. Some video hardware can take care
of all that by
itself, where if a blit command is posted, the GPU can
wait until the
retrace is past the destination area, instead of
waiting for the
retrace to be at the bottom. After all, why wait until
it’s at the
bottom if you’re blitting to the very top of the
screen? Some clever
cards/drivers could even reorder blits to
non-overlapping destinations
(for example, if you blit to the bottom and then the
top, actually do
the top while the retrace goes down).

Reminds me of some of the neat tricks used to make Super
Mario Bros 3
possible (although if too many sprites occupy the same
horizon, they
do start to flicker!)


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

My “approximately 9 MB” was using 1920x1200, at
32 bit per pixels
(either padded RGB or RGBA).

yes… i figured the math :slight_smile: but I was wondering what your actual config is like (sorry if I misunderstood again and you really meant your config)

A blit from one place to the other involves reading, then
writing, so if the video card is capable of moving 3.2 GB/s between the
GPU and video memory, you need to halve it to figure out the
theoretical maximum frame rate.

Hmm… maybe this is getting too low level for my understanding, but… when I ‘read’ something, “what” is reading it? I mean, its going somewhere, right? When you say you have to read, THEN write, you mean the reading goes, say, to the processor, and then to the right place? Are you sure it doesnt happen at the same time?

For example, as far as I understand it, when you read a memory position, it gets stored in the cpu and then goes to the other position? OR memory can copy from one place to another in the same chip? (that would save a lot of traffic in the bus!)…

… but in the case of vRAM, this cpu would be the gpu, and to copy to the right position would be on the board already, so no time spent there virtually… but this I’m just especulating, I dont know how exactly the interaction between RAM and VRAM happens… maybe it goes to the cpu, then to the gpu… but then the speed to use would be CPU<->RAM… hehe, i’m confused :slight_smile:

resolution that would still give you 150 fps and up

Hmm… Maybe I should test the system like many games do… btw, whats the maximum refresh rate recent monitors and lcd can achieve?

but actually blits from a backbuffer
With SDL 1.3, it’s just a call to
SDL_UpdateRect the whole screen, all the time.

dang… thats just for portability purposes?!

But I see you have the correct idea. I think the alarm was
raised in my head when you asked things like finding out how much
video memory there is, earlier on.

hehehehe…

that SDL is actually just an abstraction layer:
very optimized assembly pixel format conversion code, for
example, but no real magic.

Sure sure… but, in my opinion, SDL should allow you to send commands to the wrapped libraries IF you want to. For example, say linux allows me to access that pointer, but windows dont. Then if I used that functionality SDL should then translate for me to windows code, OR at least allow me to translate myself. Sort of providing an #ifdef WIN32 #else preprocessor-like functions. It would allow the users of that particular SO to benefit, but wouldnt change for the others (since SDL must comply to the weakest link in the chain)

get, but SDL_Flip and SDL_UpdateRect would most likely end
up throttling your application, much like when using
glXSwapBuffers (when vsync is enabled).

Sorry for misunderstanding again :slight_smile: but english is not my native language: when you say “throttling”, it would mean that would end up desync’n, OR eat up most of my cycles?
That info is essential for not wasting iterations calculating(maybe even actual game states) and blitting frames that would never be seen. That would free cycles for having a smarter game and even more stuff on the screen.

Cheers,
AM.— Em seg, 26/1/09, Pierre Phaneuf escreveu:

De: Pierre Phaneuf
Assunto: Re: [SDL] DirectAccess to Video Memory [was: Hello, new member reporting]
Para: sdl at lists.libsdl.org
Data: Segunda-feira, 26 de Janeiro de 2009, 13:29
On Mon, Jan 26, 2009 at 8:18 AM, Antonio Marcos <@Antonio_Marcos> wrote:

You’ve gotta have a lot of sprites to
overload these guys. :slight_smile:

mwahaha… indeed! :slight_smile: Thanks Pierre, thats quite
reassuring.
Just curious: whats the actual resolution and pixel
depth
you use there?

My “approximately 9 MB” was using 1920x1200, at
32 bit per pixels
(either padded RGB or RGBA).

(assuming a read and a write)

What you mean? why would I read from the video memory?
I
would (probably) have the last frame on RAM already,
unless
it was a composition of images… why read?

A blit from one place to the other involves reading, then
writing, so
if the video card is capable of moving 3.2 GB/s between the
GPU and
video memory, you need to halve it to figure out the
theoretical
maximum frame rate. You’d be able to do a solid color
fill (or some
other procedural fill) at the full speed, of course.

Note that those bandwidths I cited are GPU to video memory
bandwidth.

chip would still give you upward of 180 fps.

Just wondering: I still have plenty to do, like input
processing and actual game state calculations, BEFORE
I can
send data to the card, so I guess I would have quite
less
than 1 second to send those 1.6GB.

Again, those were assuming the data was already on the
video card, and
that you just played with the offset (trying to emulate
vga_setdisplaystart, for the Svgalib refugees reading
this), so doing
this emulation by using a tall surface (say 1920x3600) and
then
blitting the 1920x1200 “slice” that you want for
this frame to the
framebuffer. Since I’m talking about the work being
done by the GPU,
sending that command is actually very quick for your code,
leaving it
plenty of time to do other stuff.

It is true that updating that 1920x3600 would eat into
that memory
bandwidth, of course, but that’s why you should choose
a maximum
resolution that would still give you 150 fps and up
(considering many
video cards would be able to get you in the thousands of
fps).

no no… the idea is to just change where the pointer
points
to. Like SDL_Flip does. Also, I believe if i only call
operations on the card, the cpu would not be involved,
would
it? :frowning: I mean, say you have a sprite on the vRAM, if
you
just blit it to the display, the commands happened
only on
the card, right? I mean, thats why hardware blitting
is
feasible, so everything else dont get in the way… no?
I didnt get what you mean by ‘involving the
cpu’,
when i lock the surface my objective is to just copy
something and unlock asap, i wouldn’t be
calculating
stuff… what you mean?

You can verify the code for SDL_Flip yourself, but I’m
afraid that 98%
of the time, it doesn’t actually “flip”
(moving the framebuffer
starting offset), but actually blits from a backbuffer (it
certainly
never does with Xlib, and I’d think it doesn’t with
Mac OS X, it might
still be the case with the deprecated Direct2D driver in
fullscreen
mode, but that’s about it). With SDL 1.3, it’s just
a call to
SDL_UpdateRect the whole screen, all the time.

But I see you have the correct idea. I think the alarm was
raised in
my head when you asked things like finding out how much
video memory
there is, earlier on.

A key bit of information that a lot of people seem to miss
out on is
that SDL is actually just an abstraction layer: there’s
nothing it can
do that you cannot do using the platform APIs. I don’t
know why, but I
often see people under the impression that (for example)
“Xlib is
slow, so I’m using SDL instead” or something like
that. No magic, if
Xlib can’t do it, then SDL can’t. It tries to be
careful, using some
very optimized assembly pixel format conversion code, for
example, but
no real magic.

Yep :slight_smile: But your email was reassuring enough to take me
(mostly) out of this… The point was just to have as
much
fps as possible, and the upper limit is the refresh
rate.(its pointless to have more) But still, its quite
useful to know whats the retrace rate of the monitor,
do you
guys know how to get this info? SDL provides this?

I don’t think SDL provides that information, as
it’s too difficult to
get, but SDL_Flip and SDL_UpdateRect would most likely end
up
throttling your application, much like when using
glXSwapBuffers (when
vsync is enabled).


http://pphaneuf.livejournal.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

My “approximately 9 MB” was using 1920x1200, at
32 bit per pixels
(either padded RGB or RGBA).

yes… i figured the math :slight_smile: but I was wondering what your actual config is like (sorry if I misunderstood again and you really meant your config)

That’s indeed what my iMac desktop runs at, and I think is pretty
typical of 24" LCDs native resolution (but of course, I play many
games at lower resolutions). The laptop I’m writing this on is only
1024x768, though.

A blit from one place to the other involves reading, then
writing, so if the video card is capable of moving 3.2 GB/s between the
GPU and video memory, you need to halve it to figure out the
theoretical maximum frame rate.

Hmm… maybe this is getting too low level for my understanding, but… when I ‘read’ something, “what” is reading it? I mean, its going somewhere, right? When you say you have to read, THEN write, you mean the reading goes, say, to the processor, and then to the right place? Are you sure it doesnt happen at the same time?

For example, as far as I understand it, when you read a memory position, it gets stored in the cpu and then goes to the other position? OR memory can copy from one place to another in the same chip? (that would save a lot of traffic in the bus!)…

“What” is reading it can be either the CPU, the GPU, or a DMA
controller, from the point of view of the memory bus, it doesn’t
happen at the same time, so to move 9 MB of pixel data, you need 18 MB
of memory bus bandwidth. The advantage of using DMA or have the GPU do
it is that it leaves the CPU free to do other stuff (and in the case
of VRAM-to-VRAM, the GPU has a faster memory bus).

… but in the case of vRAM, this cpu would be the gpu, and to copy to the right position would be on the board already, so no time spent there virtually… but this I’m just especulating, I dont know how exactly the interaction between RAM and VRAM happens… maybe it goes to the cpu, then to the gpu… but then the speed to use would be CPU<->RAM… hehe, i’m confused :slight_smile:

You’ve got it pretty much right, when copying from VRAM to VRAM, the
GPU is the one reading and writing, playing the role of the CPU. But
they have to be programmed in special ways, specific to each cards.
This knowledge is put inside of the drivers. When you ask to get
direct access to the video memory, you basically giving up the GPU,
and doing everything over the (relatively slow) I/O bus, using the
main CPU. This made sense for old school DOS games, because there was
no GPU, but today, it’s just crazy. :slight_smile:

The interaction between RAM and VRAM is a bit more complicated,
because there are multiple ways to do it. You can either use
memory-mapped I/O to give the CPU access to the VRAM (which is what
happens when you get direct access to the VRAM), or you can use
programmed DMA transfers, which has the DMA controller copy the memory
without having it go through the CPU (it’s like a mini-CPU that just
does simple copies, really). Programming the DMA controller is the
kind of thing you have to ask the kernel to do, so it’s generally
managed by the DirectX drivers (and equivalents on other platforms).
Again, if you use direct video memory access, you’re missing out on
yet another performance boost. :slight_smile:

resolution that would still give you 150 fps and up

Hmm… Maybe I should test the system like many games do… btw, whats the maximum refresh rate recent monitors and lcd can achieve?

The best CRT monitors can probably do in the 120 Hz range, I’d guess?
I use to drive my ViewSonic P-series at about 100 Hz. LCD usually
behave as if they had a 60 Hz refresh rate.

but actually blits from a backbuffer
With SDL 1.3, it’s just a call to
SDL_UpdateRect the whole screen, all the time.

dang… thats just for portability purposes?!

Yeah, to provide compatibility for SDL 1.2 games. The new SDL 1.3 does
not have SDL_Flip, which is good, since it hasn’t been relevant since
about 1998. :slight_smile:

that SDL is actually just an abstraction layer:
very optimized assembly pixel format conversion code, for
example, but no real magic.

Sure sure… but, in my opinion, SDL should allow you to send commands to the wrapped libraries IF you want to. For example, say linux allows me to access that pointer, but windows dont. Then if I used that functionality SDL should then translate for me to windows code, OR at least allow me to translate myself. Sort of providing an #ifdef WIN32 #else preprocessor-like functions. It would allow the users of that particular SO to benefit, but wouldnt change for the others (since SDL must comply to the weakest link in the chain)

It does let you talk to the underlying libraries, actually! You have
to use the SDL_GetWMInfo call.

But to make a portable game, you have to avoid that. SDL tries to take
the subset of things that are either available everywhere, or are fast
to emulate on those platforms which don’t have it. If you use
something else, then there is almost certainly a platform where it
isn’t possible without some slow emulation.

That, or it was just forgotten, and you should submit a patch to add it. :slight_smile:

But generally, there’s a common model between platforms where you can
assume a few things, and worst case, it’s actually faster than you
thought. For example, you should assume that surfaces in video memory
should not be inaccessible directly, and that copying data to/from
main memory to video memory is slow. In the case of video cards with
shared memory (like the cheap Intels, and now the lower end nVidia and
ATI), accessing video memory is actually very cheap (it’s already in
the main memory!), but assuming that it’s slow is safer (you get a
"bonus" speed increase, rather than a “surprising” slowdown).

get, but SDL_Flip and SDL_UpdateRect would most likely end
up throttling your application, much like when using
glXSwapBuffers (when vsync is enabled).

Sorry for misunderstanding again :slight_smile: but english is not my native language: when you say “throttling”, it would mean that would end up desync’n, OR eat up most of my cycles?
That info is essential for not wasting iterations calculating(maybe even actual game states) and blitting frames that would never be seen. That would free cycles for having a smarter game and even more stuff on the screen.

By throttling, I mean that they would slow down your application if
you called them twice, because while the first one would be done in
the background, it wouldn’t be finished, and the second one would have
to wait for the first one to be done. So without doing anything, it
would “naturally” slow itself down there (which isn’t the best thing
ever, you might want to do other stuff than “wait”!).

Basically, what you want to do is avoid touching SDL surfaces for as
long as possible after doing an SDL_UpdateRects/SDL_Flip, because if
it’s not done, you’ll have a “stall”, where the first call will have
to wait until the surface is done being updated. So you should pack
all of your drawing in a single place, done as quickly as possible
(use pre-calculated stuff, instead of calculating stuff as you’re
drawing them, for example), do a single SDL_UpdateRect(s), then do
"other stuff" (handling input, network, game logic, physics, etc).
More info there (it says “Mac OS X FAQ”, but the recommendations more
or less generally apply to most modern platforms):

http://www.libsdl.org/faq.php?action=listentries&category=7#68On Tue, Jan 27, 2009 at 10:40 AM, Antonio Marcos wrote:


http://pphaneuf.livejournal.com/

You can do what you’re proposing if the pixels pointer is actually
editable, but I’m betting on most platforms it is not. That is, of
course, for the display surface, not for an ordinary surface. Why
would you want to do this with an ordinary surface?On Mon, Jan 26, 2009 at 8:39 AM, Antonio Marcos wrote:

Hey, welcome to the community!

Hey, Thanks! :slight_smile:

I don’t know how it would work in video memory, but it
sounds like something
that can be done (in software, at least) by twiddling with
void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.

I was thinking about something like that, but I have no idea how the inner workings would proceed to know if its doing th actual thing. I was thinking about creating a bigger resolution surface with the SetVideoMode, get the pointer, and then reset to a lower resolution. The problem with this is that SDL have privileges to work with the hardware (at least on some OS’es i guess), and this would probably bypass it… also, I dont know if the ‘freed’ parts of the memory would be used by something else.

I’ve never tried it, of
course, but I hope you can find a way to achieve your
desired effect.

It would be nice because changing a “camera view” would just be a matter of incrementing/decrementing a pointer :slight_smile:

Jonny D

AM.

— Em seg, 26/1/09, Jonathan Dearborn escreveu:

De: Jonathan Dearborn
Assunto: Re: [SDL] Hello, new member reporting
Para: “A list for developers using the SDL library. (includes SDL-announce)”
Data: Segunda-feira, 26 de Janeiro de 2009, 11:03
Hey, welcome to the community!
I don’t know how it would work in video memory, but it
sounds like something
that can be done (in software, at least) by twiddling with
void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.
I’ve never tried it, of
course, but I hope you can find a way to achieve your
desired effect.

Jonny D

On Sun, Jan 25, 2009 at 4:22 PM, David Olofson wrote:

On Sunday 25 January 2009, Donny Viszneki wrote:
[…hardware scrolling…]

I could be wrong, but I don’t think modern
graphics hardware

supports this.

Actually, most hardware does support it, but it’s
only used
for “virtual desktop” (desktop larger than
the display) and things
like that… Probably not very portable or reliable
stuff, if it’s at
all accessible to normal applications. (From what
I’ve seen of this
stuff on Windows, it may as well be internal driver
hacks.)

So, full screen redrawing it is!

If performance is an issue, you could implement it
over OpenGL or
Direct3D, for hardware blitting and keeping it all in
VRAM. With SDL
1.3/2.0, you don’t even have to touch those APIs
directly to do this,
and it’ll still work with
"software-only" displays as a fallback.

On the bright side, using blitting instead of hardware
scrolling gives
you a lot more freedom when it comes to layering,
screen layout,
blending effects etc.

//David Olofson - Programmer, Composer, Open Source
Advocate

.------- http://olofson.net - Games, SDL examples
-------.
| http://zeespace.net - 2.5D rendering engine
|
| http://audiality.org - Music/audio engine
|
| http://eel.olofson.net - Real time scripting
|
’-- http://www.reologica.se - Rheology
instrumentation --’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

 Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/

You can do what you’re proposing if the pixels pointer
is actually editable, but I’m betting on most platforms it is not.

Yep, thats what I meant. I should’ve been more clear when i said “this
would probably bypass it…”, I should’ve said: this would probably HAVE TO bypass it…"

That is, of
course, for the display surface, not for an ordinary
surface. Why
would you want to do this with an ordinary surface?

no, i said I would use the setvideomode function, it actually returns a SDL _Surface, thats why i said ‘surface’ :slight_smile: but it would be the display surface, yes…

another problem is that, even if it is editable, what guarantess i have that the memory I’ve allocated would not be used by something else if the video card/so thinks im using a less memory now?

[]
AM— Em qua, 28/1/09, Donny Viszneki <donny.viszneki at gmail.com> escreveu:

De: Donny Viszneki <donny.viszneki at gmail.com>
Assunto: Re: [SDL] Hello, new member reporting
Para: @Antonio_Marcos, “A list for developers using the SDL library. (includes SDL-announce)”
Data: Quarta-feira, 28 de Janeiro de 2009, 1:22
You can do what you’re proposing if the pixels pointer
is actually
editable, but I’m betting on most platforms it is not.
That is, of
course, for the display surface, not for an ordinary
surface. Why
would you want to do this with an ordinary surface?

On Mon, Jan 26, 2009 at 8:39 AM, Antonio Marcos <@Antonio_Marcos> wrote:

Hey, welcome to the community!

Hey, Thanks! :slight_smile:

I don’t know how it would work in video
memory, but it

sounds like something
that can be done (in software, at least) by
twiddling with

void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.

I was thinking about something like that, but I have
no idea how the inner workings would proceed to know if its
doing th actual thing. I was thinking about creating a
bigger resolution surface with the SetVideoMode, get the
pointer, and then reset to a lower resolution. The problem
with this is that SDL have privileges to work with the
hardware (at least on some OS’es i guess), and this
would probably bypass it… also, I dont know if the
’freed’ parts of the memory would be used by
something else.

I’ve never tried it, of
course, but I hope you can find a way to achieve
your

desired effect.

It would be nice because changing a “camera
view” would just be a matter of
incrementing/decrementing a pointer :slight_smile:

Jonny D

AM.

— Em seg, 26/1/09, Jonathan Dearborn escreveu:

De: Jonathan Dearborn
Assunto: Re: [SDL] Hello, new member reporting
Para: “A list for developers using the SDL
library. (includes SDL-announce)”

Data: Segunda-feira, 26 de Janeiro de 2009, 11:03
Hey, welcome to the community!
I don’t know how it would work in video
memory, but it

sounds like something
that can be done (in software, at least) by
twiddling with

void*
SDL_Surface::pixels and Uint16 SDL_Surface::pitch.
I’ve never tried it, of
course, but I hope you can find a way to achieve
your

desired effect.

Jonny D

On Sun, Jan 25, 2009 at 4:22 PM, David Olofson wrote:

On Sunday 25 January 2009, Donny Viszneki wrote:
[…hardware scrolling…]

I could be wrong, but I don’t think
modern

graphics hardware

supports this.

Actually, most hardware does support it, but
it’s

only used

for “virtual desktop” (desktop
larger than

the display) and things

like that… Probably not very portable or
reliable

stuff, if it’s at

all accessible to normal applications. (From
what

I’ve seen of this

stuff on Windows, it may as well be internal
driver

hacks.)

So, full screen redrawing it is!

If performance is an issue, you could
implement it

over OpenGL or

Direct3D, for hardware blitting and keeping
it all in

VRAM. With SDL

1.3/2.0, you don’t even have to touch
those APIs

directly to do this,

and it’ll still work with
"software-only" displays as a fallback.

On the bright side, using blitting instead of
hardware

scrolling gives

you a lot more freedom when it comes to
layering,

screen layout,

blending effects etc.

//David Olofson - Programmer, Composer, Open
Source

Advocate

.------- http://olofson.net - Games, SDL
examples

-------.

| http://zeespace.net - 2.5D rendering
engine

|

| http://audiality.org - Music/audio
engine

|

| http://eel.olofson.net - Real time
scripting

|

‘-- http://www.reologica.se - Rheology
instrumentation --’


SDL mailing list
SDL at lists.libsdl.org

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

 Veja quais s?o os assuntos do momento no Yahoo!

+Buscados

http://br.maisbuscados.yahoo.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

Thanks for all the info , Pierre :slight_smile: A few remaining points:

I still dont get why I need 18MB bandwidth for 9MB… :slight_smile:

The best CRT monitors can probably do in the 120 Hz range,
I’d guess? I use to drive my ViewSonic P-series at about 100 Hz. LCD
usually behave as if they had a 60 Hz refresh rate.

Anybody knows whats the capture rate of those cameras they use for certain tv shows which looks much faster than normal cinema camera? stuff like natural geographic and police cameras…

Basically, what you want to do is avoid touching SDL
surfaces for as
long as possible after doing an SDL_UpdateRects/SDL_Flip,
because if it’s not done, you’ll have a “stall”,

now that I know what SDL_Flip really does, I agree :slight_smile: But the idea was just to change the pointer, So what I would actually do is update the portion of the screen that would be seen next, and scroll the “camera” there. The changes could be very small actually.

I had a new idea considering dirty rectangles… When I have colorkeyed sprited (most of them), or even alpha-enabled (though not that much), I cant just copy and paste the sides of the rect(tipically 2 rects per sprite), I would like to use a “negative mask” to read from the background and then paste on the new position. Im sure it would be able to use RLE acceleration (though i dont know how it works). Any thoughts?

[]
AM.— Em ter, 27/1/09, Pierre Phaneuf escreveu:

De: Pierre Phaneuf
Assunto: Re: [SDL] DirectAccess to Video Memory [was: Hello, new member reporting]
Para: @Antonio_Marcos, “A list for developers using the SDL library. (includes SDL-announce)”
Data: Ter?a-feira, 27 de Janeiro de 2009, 17:25
On Tue, Jan 27, 2009 at 10:40 AM, Antonio Marcos <@Antonio_Marcos> wrote:

My “approximately 9 MB” was using
1920x1200, at

32 bit per pixels
(either padded RGB or RGBA).

yes… i figured the math :slight_smile: but I was wondering what
your actual config is like (sorry if I misunderstood again
and you really meant your config)

That’s indeed what my iMac desktop runs at, and I think
is pretty
typical of 24" LCDs native resolution (but of course,
I play many
games at lower resolutions). The laptop I’m writing
this on is only
1024x768, though.

A blit from one place to the other involves
reading, then

writing, so if the video card is capable of moving
3.2 GB/s between the

GPU and video memory, you need to halve it to
figure out the

theoretical maximum frame rate.

Hmm… maybe this is getting too low level for my
understanding, but… when I ‘read’ something,
“what” is reading it? I mean, its going somewhere,
right? When you say you have to read, THEN write, you mean
the reading goes, say, to the processor, and then to the
right place? Are you sure it doesnt happen at the same time?

For example, as far as I understand it, when you read
a memory position, it gets stored in the cpu and then goes
to the other position? OR memory can copy from one place to
another in the same chip? (that would save a lot of traffic
in the bus!)…

“What” is reading it can be either the CPU, the
GPU, or a DMA
controller, from the point of view of the memory bus, it
doesn’t
happen at the same time, so to move 9 MB of pixel data, you
need 18 MB
of memory bus bandwidth. The advantage of using DMA or have
the GPU do
it is that it leaves the CPU free to do other stuff (and in
the case
of VRAM-to-VRAM, the GPU has a faster memory bus).

… but in the case of vRAM, this cpu would be the
gpu, and to copy to the right position would be on the board
already, so no time spent there virtually… but this
I’m just especulating, I dont know how exactly the
interaction between RAM and VRAM happens… maybe it goes to
the cpu, then to the gpu… but then the speed to use would
be CPU<->RAM… hehe, i’m confused :slight_smile:

You’ve got it pretty much right, when copying from VRAM
to VRAM, the
GPU is the one reading and writing, playing the role of the
CPU. But
they have to be programmed in special ways, specific to
each cards.
This knowledge is put inside of the drivers. When you ask
to get
direct access to the video memory, you basically giving up
the GPU,
and doing everything over the (relatively slow) I/O bus,
using the
main CPU. This made sense for old school DOS games, because
there was
no GPU, but today, it’s just crazy. :slight_smile:

The interaction between RAM and VRAM is a bit more
complicated,
because there are multiple ways to do it. You can either
use
memory-mapped I/O to give the CPU access to the VRAM (which
is what
happens when you get direct access to the VRAM), or you can
use
programmed DMA transfers, which has the DMA controller copy
the memory
without having it go through the CPU (it’s like a
mini-CPU that just
does simple copies, really). Programming the DMA controller
is the
kind of thing you have to ask the kernel to do, so it’s
generally
managed by the DirectX drivers (and equivalents on other
platforms).
Again, if you use direct video memory access, you’re
missing out on
yet another performance boost. :slight_smile:

resolution that would still give you 150 fps and
up

Hmm… Maybe I should test the system like many games
do… btw, whats the maximum refresh rate recent monitors and
lcd can achieve?

The best CRT monitors can probably do in the 120 Hz range,
I’d guess?
I use to drive my ViewSonic P-series at about 100 Hz. LCD
usually
behave as if they had a 60 Hz refresh rate.

but actually blits from a backbuffer
With SDL 1.3, it’s just a call to
SDL_UpdateRect the whole screen, all the time.

dang… thats just for portability purposes?!

Yeah, to provide compatibility for SDL 1.2 games. The new
SDL 1.3 does
not have SDL_Flip, which is good, since it hasn’t been
relevant since
about 1998. :slight_smile:

that SDL is actually just an abstraction layer:
very optimized assembly pixel format conversion
code, for

example, but no real magic.

Sure sure… but, in my opinion, SDL should allow you
to send commands to the wrapped libraries IF you want to.
For example, say linux allows me to access that pointer, but
windows dont. Then if I used that functionality SDL should
then translate for me to windows code, OR at least allow me
to translate myself. Sort of providing an #ifdef WIN32 #else
preprocessor-like functions. It would allow the users of
that particular SO to benefit, but wouldnt change for the
others (since SDL must comply to the weakest link in the
chain)

It does let you talk to the underlying libraries, actually!
You have
to use the SDL_GetWMInfo call.

But to make a portable game, you have to avoid that. SDL
tries to take
the subset of things that are either available everywhere,
or are fast
to emulate on those platforms which don’t have it. If
you use
something else, then there is almost certainly a platform
where it
isn’t possible without some slow emulation.

That, or it was just forgotten, and you should submit a
patch to add it. :slight_smile:

But generally, there’s a common model between platforms
where you can
assume a few things, and worst case, it’s actually
faster than you
thought. For example, you should assume that surfaces in
video memory
should not be inaccessible directly, and that copying data
to/from
main memory to video memory is slow. In the case of video
cards with
shared memory (like the cheap Intels, and now the lower end
nVidia and
ATI), accessing video memory is actually very cheap
(it’s already in
the main memory!), but assuming that it’s slow is safer
(you get a
"bonus" speed increase, rather than a
"surprising" slowdown).

get, but SDL_Flip and SDL_UpdateRect would most
likely end

up throttling your application, much like when
using

glXSwapBuffers (when vsync is enabled).

Sorry for misunderstanding again :slight_smile: but english is not
my native language: when you say “throttling”, it
would mean that would end up desync’n, OR eat up most of
my cycles?
That info is essential for not wasting iterations
calculating(maybe even actual game states) and blitting
frames that would never be seen. That would free cycles for
having a smarter game and even more stuff on the screen.

By throttling, I mean that they would slow down your
application if
you called them twice, because while the first one would be
done in
the background, it wouldn’t be finished, and the second
one would have
to wait for the first one to be done. So without doing
anything, it
would “naturally” slow itself down there (which
isn’t the best thing
ever, you might want to do other stuff than
"wait"!).

Basically, what you want to do is avoid touching SDL
surfaces for as
long as possible after doing an SDL_UpdateRects/SDL_Flip,
because if
it’s not done, you’ll have a “stall”,
where the first call will have
to wait until the surface is done being updated. So you
should pack
all of your drawing in a single place, done as quickly as
possible
(use pre-calculated stuff, instead of calculating stuff as
you’re
drawing them, for example), do a single SDL_UpdateRect(s),
then do
"other stuff" (handling input, network, game
logic, physics, etc).
More info there (it says “Mac OS X FAQ”, but the
recommendations more
or less generally apply to most modern platforms):

http://www.libsdl.org/faq.php?action=listentries&category=7#68


http://pphaneuf.livejournal.com/

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com

I still dont get why I need 18MB bandwidth for 9MB… :slight_smile:
Because a blit is not a straight-up copy. It requires
processing. So the GPU has to load it, crunch some numbers,
and save the results. 9 MB each way.

Ok, but after it crunches its waaay faster to write than it was to read! no? I mean… to
read it has to go from RAM<->vRAM to write it goes GPU<->vRAM …(ok, so maybe
its 2x that last speed, but its still faster than the 1st one)… also, if its using a DMA
controller, does it really needs to go though gpu?

If you’re gonna be using the GPU you probably want the whole thing preloaded into
VRAM if you can. And yes, it still needs to go through the GPU. DMA is a very
fast way to copy, but that’s all it does is copy memory. It can’t do the number
crunching part.>----- Original Message ----

From: Antonio Marcos
Subject: Re: [SDL] DirectAccess to Video Memory [was: Hello, new member reporting]

I still dont get why I need 18MB bandwidth for 9MB… :slight_smile:

The GPU will read the 9 MB of pixel data from one location, then write
it to another location, therefore using 18 MB of bandwidth.

now that I know what SDL_Flip really does, I agree :slight_smile: But the idea was just to change the pointer, So what I would actually do is update the portion of the screen that would be seen next, and scroll the “camera” there. The changes could be very small actually.

Yeah, I remember some pinball games that did that for DOS, and I did
do some game development on DOS, back in the days. In fact, in my main
game project, Quadra, you can still see some “need_paint = 2” being
set in some Zone objects (an object that represent an area on the
screen, used for widgets and things like that) when they’re updated…
The reason is of course that we need to used to do double-buffering
with page-flipping, using DirectX and Svgalib at the time (we started
right about at the same time as SDL, so we made our own abstraction
library at the time, good times!), so when a button changed, we needed
to update it in both buffers.

I really need to clean that junk up. :slight_smile:

I had a new idea considering dirty rectangles… When I have colorkeyed sprited (most of them), or even alpha-enabled (though not that much), I cant just copy and paste the sides of the rect(tipically 2 rects per sprite), I would like to use a “negative mask” to read from the background and then paste on the new position. Im sure it would be able to use RLE acceleration (though i dont know how it works). Any thoughts?

I’m not sure I see what you mean… You want to minimize the amount
copied? If stuff is in video memory, using the hardware blitter to
copy everything without bothering to optimize might actually be
faster, as it is fewer commands than the detailed “instructions” that
would be necessary to optimize that. Even when doing it in main memory
with the CPU, your code being simpler and having fewer branches might
compensate for the speed gain of doing it optimally, too.

But, again, I’m not sure I understand what you meant.On Fri, Jan 30, 2009 at 4:38 PM, Antonio Marcos wrote:


http://pphaneuf.livejournal.com/

The GPU will read the 9 MB of pixel data from one location,
then write
it to another location, therefore using 18 MB of bandwidth.

Oh, so you were already assuming the surface was on video memory? Because I was thinking it was going from RAM to vRAM. hence much slower.

I really need to clean that junk up. :slight_smile:

huahahahaha

I’m not sure I see what you mean… You want to
minimize the amount
copied? If stuff is in video memory, using the hardware

yep.

blitter to
copy everything without bothering to optimize might
actually be
faster, as it is fewer commands than the detailed
"instructions" that
would be necessary to optimize that. Even when doing it in

i dont know… after all each blit, on the lower level, is actually repeating memory copies for each pixel(assuming a 32 bit depth on a 32bit machine). so the fewer pixels the better.

main memory
with the CPU, your code being simpler and having fewer
branches might
compensate for the speed gain of doing it optimally, too.

But, again, I’m not sure I understand what you meant.

actually it would have the same number of branches (if i understood correctly what you mean), when I do dirty rectangles i have to copy the BG, and then blit it on the previous position of the moving sprite. Then I blit the actual sprite at the new position. This last blit is already colorkeyed(otherwise I would blit only the sides that moved and exposed the BG, like I said previously), the idea is to do the same with the first blit. :slight_smile:

The catch though is that its a little trickier, because i would have to use a ‘negative mask’ of the sprite… and the way im seeing with SDL, i would need an actual blit of the whole BG rect to a new surface, then paste the mask to it, and only then pass it to the video card… and though this can save data going to the card, it could be done in a direct blit if I could ‘modify’ the colorkey code of SDL, and use the ‘negative mask’ at the AND phase… SDL could have a blit with a mask parameter :slight_smile:

Cheers,
AM.— Em fri, 30/1/09, Pierre Phaneuf escreveu:

De: Pierre Phaneuf
Assunto: Re: [SDL] DirectAccess to Video Memory [was: Hello, new member reporting]
Para: “A list for developers using the SDL library. (includes SDL-announce)”
Data: Sexta-feira, 30 de Janeiro de 2009, 22:33
On Fri, Jan 30, 2009 at 4:38 PM, Antonio Marcos <@Antonio_Marcos> wrote:

I still dont get why I need 18MB bandwidth for 9MB…
:slight_smile:

The GPU will read the 9 MB of pixel data from one location,
then write
it to another location, therefore using 18 MB of bandwidth.

now that I know what SDL_Flip really does, I agree :slight_smile:
But the idea was just to change the pointer, So what I would
actually do is update the portion of the screen that would
be seen next, and scroll the “camera” there. The
changes could be very small actually.

Yeah, I remember some pinball games that did that for DOS,
and I did
do some game development on DOS, back in the days. In fact,
in my main
game project, Quadra, you can still see some
"need_paint = 2" being
set in some Zone objects (an object that represent an area
on the
screen, used for widgets and things like that) when
they’re updated…
The reason is of course that we need to used to do
double-buffering
with page-flipping, using DirectX and Svgalib at the time
(we started
right about at the same time as SDL, so we made our own
abstraction
library at the time, good times!), so when a button
changed, we needed
to update it in both buffers.

I really need to clean that junk up. :slight_smile:

I had a new idea considering dirty rectangles… When I
have colorkeyed sprited (most of them), or even
alpha-enabled (though not that much), I cant just copy and
paste the sides of the rect(tipically 2 rects per sprite), I
would like to use a “negative mask” to read from
the background and then paste on the new position. Im sure
it would be able to use RLE acceleration (though i dont know
how it works). Any thoughts?

I’m not sure I see what you mean… You want to
minimize the amount
copied? If stuff is in video memory, using the hardware
blitter to
copy everything without bothering to optimize might
actually be
faster, as it is fewer commands than the detailed
"instructions" that
would be necessary to optimize that. Even when doing it in
main memory
with the CPU, your code being simpler and having fewer
branches might
compensate for the speed gain of doing it optimally, too.

But, again, I’m not sure I understand what you meant.


http://pphaneuf.livejournal.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Veja quais s?o os assuntos do momento no Yahoo! +Buscados

http://br.maisbuscados.yahoo.com