Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: UpdatePixels VS LoadFromPixels  (Read 4560 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
UpdatePixels VS LoadFromPixels
« on: April 18, 2010, 09:17:04 pm »
I'm just curious how fast is UpdatePixels vs LoadFromPixels?

If I already have a full pixel array stored from GetPixelsPtr to operate on then..
 
LoadFromPixels slower than 2 UpdatePixels calls?
LoadFromPixels slower than 5 UpdatePixels calls?
LoadFromPixels slower than 100 UpdatePixels calls?

Is there a ratio Update per pixel vs Load per pixel?

Has anybody done any benchmarks?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
UpdatePixels VS LoadFromPixels
« Reply #1 on: April 18, 2010, 10:53:43 pm »
Why don't you measure the time yourself?

Since SFML provides a clock class, this is not much work at all. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UpdatePixels VS LoadFromPixels
« Reply #2 on: April 18, 2010, 11:25:26 pm »
UpdatePixels directly uploads the pixels to the video memory.
LoadFromPixels copies the pixels to the image's pixels cache, then it uploads them to the video memory. And that's in the best case, where the texture already exists and has the same size as before. If the size changes, LoadFromPixels will first create a new texture.

Now if you want to get numbers, measure it ;)
It depends on so many things that nobody can give a single global comparison factor, it will be different for every user.

But why do you want a ratio? Knowing which method is the best according to your usage isn't enough?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
UpdatePixels VS LoadFromPixels
« Reply #3 on: April 18, 2010, 11:59:49 pm »
Well of course I can just pick up a hammer and start trying to build a house.

But a wise carpenter knows everything he can about his tools.

This is for the most part just general discussion about this. Have any of you used both of these and noticed the trade-offs/gains? I'm not looking so much for global comparisons and specific ones.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UpdatePixels VS LoadFromPixels
« Reply #4 on: April 19, 2010, 08:19:04 am »
I don't understand why you keep on asking questions. UpdatePixels just uploads the new pixels to the video memory, it's made for fast updates of the texture. LoadFromPixels is made for creating the texture from scratch. What more do you need to know? Why do you want to compare these two functions?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
UpdatePixels VS LoadFromPixels
« Reply #5 on: April 19, 2010, 09:42:05 am »
Obviously LoadFromPixels is the more common use but UpdatePixels requires a strategy otherwise you would use LoadFromPixels instead.

I'm curious what strategies people may have tried and why.

BTW, you don't have to stress over every question. Forum activity builds site traffic and archives discussions on page cache. It's not so much the 'correct answer' as the 'informational answer' as most people learn through an amalgamation of content in their environment.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
UpdatePixels VS LoadFromPixels
« Reply #6 on: April 19, 2010, 01:06:10 pm »
I think Laurent is so much patient haha!

LoadFromPixels and UpdatePixels are both different functions with different results.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
UpdatePixels VS LoadFromPixels
« Reply #7 on: April 19, 2010, 05:58:17 pm »
Quote from: "panithadrum"
I think Laurent is so much patient haha!

LoadFromPixels and UpdatePixels are both different functions with different results.


If you're building a simple game you can just simply say, "Oh I need to only update a rect of this image so I used UpdatePixels."

But NOT if you're writing an image processor where max performance is important because the steps are repetitive and also the image source can span wide variables.

I need a strategy where I take in pixels_to_update and number_of_updates and decide whether to default to LoadFromPixels. I'm still working on it, but I was just curious what other people thought or if they had experience writing something similar.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UpdatePixels VS LoadFromPixels
« Reply #8 on: April 19, 2010, 06:16:18 pm »
But why do you think that LoadFromPixels could be faster/better/whatever than UpdatePixels? It does exactly the same thing as UpdatePixels, plus a lot more stuff (copying the pixels and creating the OpenGL texture). Unless you're creating an image of different size every time, or you need the pixels to be copied in the sf::Image cache, you shouldn't even consider using LoadFromPixels.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
UpdatePixels VS LoadFromPixels
« Reply #9 on: April 19, 2010, 07:35:22 pm »
Quote from: "Ashenwraith"
But NOT if you're writing an image processor where max performance is important because the steps are repetitive and also the image source can span wide variables.
Again, this is a case where a profiler must be considered. As I already stated here, you should really not base optimizations only on your assumptions or on statements of other people. It's important how your specific application works for your specific compiler. The second thing is that the actual bottlenecks are often completely elsewhere, and before they're not fixed, small optimizations are worthless.

Believe me, I just don't want you to make the same mistake as thousands of people before. Build up a working application with clean design first (use C++ features!), and optimize later, based on measurement. In most cases, the final result is better if your code is well-structured, since this allows much easier modifications and unnecessary operations are recognized faster.

I know this is a general discussion, regard my post as general advice. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
UpdatePixels VS LoadFromPixels
« Reply #10 on: April 19, 2010, 08:02:52 pm »
Quote from: "Nexus"
Again, this is a case where a profiler must be considered. As I already stated here, you should really not base optimizations only on your assumptions or on statements of other people. It's important how your specific application works for your specific compiler. The second thing is that the actual bottlenecks are often completely elsewhere, and before they're not fixed, small optimizations are worthless.

I do agree with this. Just adding an example of an experiment I did a few weeks ago. The optimisations also depends on the target hardware AND software. The target hardware may seem obvious (greate graphic card => can do lot of graphics effects, etc), but I noticed something weird with the software side (the OS) :
 - when launched from Mac OS X, my program was spending 80% of it's execution time on rendering the graphics, and 20% on my computing stuff (physical simulation) (50 FPS)
 - when launched from Ubuntu, my program was spending 50% of it's execution time on rendering, and 50% on the computing (don't remember the FPS)
 - and when launched from Window, my programe was spending 20% of it's execution time on rendering, et 80% on the computing (30 FPS)

The tests were done on the same computer, mine. And I know where is the bottleneck on Windows, and Mac OS X, and I can tell they are not the same.

Just to say that.. do you own tests!
Want to play movies in your SFML application? Check out sfeMovie!

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
UpdatePixels VS LoadFromPixels
« Reply #11 on: April 19, 2010, 10:08:45 pm »
Hey guys thanks for sharing your insights.

If you have any specific ones working with pixel data that would be great.


Quote from: "Laurent"
But why do you think that LoadFromPixels could be faster/better/whatever than UpdatePixels? It does exactly the same thing as UpdatePixels, plus a lot more stuff (copying the pixels and creating the OpenGL texture). Unless you're creating an image of different size every time, or you need the pixels to be copied in the sf::Image cache, you shouldn't even consider using LoadFromPixels.


This is some good info. Yes, a lot of my images are different sizes. I have to consider if it would be worth changing the size of them if it can give a benefit. Maybe I can have a static internal size for processing and then slice them up for saving.

The way I've been thinking of UpdatePixels is that it has the similar overhead of blitting.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UpdatePixels VS LoadFromPixels
« Reply #12 on: April 19, 2010, 10:36:54 pm »
The main problem with UpdatePixels, is that it doesn't store the pixels in the image (they go straight to the video memory). So if later you do a read call, the pixels will have to be downloaded from the video memory, which is a slow operation.
Laurent Gomila - SFML developer