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

Author Topic: Option to not save local image data/ use compressed textures  (Read 22506 times)

0 Members and 1 Guest are viewing this topic.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
I've been digging through some SFML code related to images and noticed 2 things...
First, I noticed that when you load an image it leaves a local (uncompressed) copy in the myPixels vector after passing the loaded texture off to OpenGL.  This is only useful if the user later calls resize, setPixel, or something similar.  But I'd be willing to bet that the vast majority of times, people load an image and then never modify it which makes the uncompressed local copy extremely wasteful of memory.
So what about adding an extra bool parameter to the loading functions (with a defualt value to preserve the pubic interface, if needed) bPreserveLocalCopy or something that if false would free the local copy after the first call the Update (to preserve the thread-safeness you added) and then cause the methods that would access it to just do nothing and/or return an error?

Secondly, there is no option to use compressed textures.  A big bottleneck in SFML is likely going to be re-binding textures on every draw call.  (Some simple tests I ran seem to support this.)  You already said that you were not planning to implement some sort of background texture-combining/atlasing to save texture binds, which is understandable.  But allowing compressed textures would be a much simpler way to still help this a good bit since at least there will be less stuff to move around on the GPU.  (Testing this with even only a couple dozen sprites produced measurable speed increases of about 1500->1725 FPS on my rig.)  Also, it will obviously allow more textures to be crammed on the GPU as well.
I know that compressed textures is technically an extension to OpenGL, but I think pretty much every video card supports it and it would be easy enough to do an auto fall-back to uncompressed if the GPU didn't support it.

Are these features you'd consider adding or do they violate your "simplicity" design philosophy too much?  I'll probably do them myself if something like this is not on your roadmap; but if it is, I'll just wait.

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Option to not save local image data/ use compressed textures
« Reply #1 on: June 24, 2008, 03:13:34 am »
You're right, I'm going to improve the storage system of images. Having a version of images not storing their pixels in system memory is going to be necessary, especially if I port SFML to portable devices like GBA, PSP or Pandora.

It would also help with some new features I'm planning.

Regarding compressed textures, I won't use them automatically because it would not allow perfect pixel rendering, which is what most people want. However I guess I can find a smart way to provide it ;)

Just one thing to finish :
Quote
Testing this with even only a couple dozen sprites produced measurable speed increases of about 1500->1725 FPS on my rig

1725 FPS - 1500 FPS = 0.00009 ms, which is the same difference as between 50 FPS and 50.23 FPS. Not really a big improvement ;)
Be careful when interpreting such results.
Laurent Gomila - SFML developer

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Option to not save local image data/ use compressed textures
« Reply #2 on: June 24, 2008, 03:23:24 am »
Quote from: "Laurent"

1725 FPS - 1500 FPS = 0.00009 ms, which is the same difference as between 50 FPS and 50.23 FPS. Not really a big improvement ;)


I'm no math magician, but wouldn't it be from 50 FPS to 57.5 FPS? I have no idea where you got those milliseconds from.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Option to not save local image data/ use compressed textures
« Reply #3 on: June 24, 2008, 05:03:46 am »
Frame time at 1725 FPS : 1 / 1725 = 0.00057 ms
Frame time at 1500 FPS : 1 / 1500 = 0.00067 ms
Time gained with optimization : 0.00067 - 0.00057 = 0.0001 ms (I previously found 0.00009 because I used 1750 instead of 1725, sorry)

Frame time at 50 FPS : 1 / 50 = 0.02 ms
Frame time with the same gain : 0.02 - 0.0001 = 0.0199 ms
Corresponding FPS : 1 / 0.0199 = 50.25 FPS

I don't know where you got those 7.5 FPS from. Even the obvious wrong formula (1 / (1725 - 1500)) doesn't give 7.5 FPS.
Laurent Gomila - SFML developer

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Option to not save local image data/ use compressed textures
« Reply #4 on: June 24, 2008, 06:00:47 am »
He did 1725 / 1500 = 1.15 = 115%
Then 50 * 115% = 57.5

That's also what I was thinking.  But, yeah, I think you're right.  That optimization is more likely to be closer to a constant time savings each frame over a percentage savings.

Edit:  As you said, I was suggesting compressed textures as an option, not a default.  I would be useful as a fallback on slower systems and/or GPUs with little texture memory.