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

Author Topic: Speed test  (Read 9378 times)

0 Members and 1 Guest are viewing this topic.

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Speed test
« on: May 23, 2012, 06:05:22 am »
I have updated my own engine implementation to the new SFML2 RC, and I figured that runs a bit slow for me.  :(
I had a game prototype that was running at 150 fps, and now with the new implementation (without change the way) I have 60 ~ 70 fps.  :-\
If I turn on Vsync, my game looks very bad because cannot keep 60 fps. :-\

I see that the bottleneck is when I render my textures, so, there's not a logic problem.
Any suggestion?
« Last Edit: May 23, 2012, 06:38:25 am by NinjaFighter »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Speed test
« Reply #1 on: May 23, 2012, 08:05:48 am »
It's hard to suggest anything without knowing what you do in your code :)
Laurent Gomila - SFML developer

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #2 on: May 23, 2012, 09:06:18 am »
I'm trying to figure where's the bottleneck. I started a single project for each version, to trying focus on the problem, but drawing single sprites with shaders have the same results in fps. I'm a little confused  :P.. the old version works very fast with my game, but this new  does not, however, on the other hand... the two minimal testing project have very accuracy results  ???

I will continue trying, I hope to have something soon.

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #3 on: May 23, 2012, 07:21:34 pm »
I have a lot of questions about the new version:

1) What's the optimal way to do SetPixel and GetPixel from a Texture? (in the previous versions I only use "Images" (there's no Textures), and for create some basic images, I use SetPixel method)

2) How I must use Texture.Bind method? Why the old version doesn't have this method and draw faster anyway?

3) I notice that if I use "Texture.Bind" on every image that I load, these images may sometimes overrides my RenderTextures. Is it ok?
« Last Edit: May 23, 2012, 07:38:07 pm by NinjaFighter »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Speed test
« Reply #4 on: May 23, 2012, 08:17:18 pm »
1) What's the optimal way to do SetPixel and GetPixel from a Texture? (in the previous versions I only use "Images" (there's no Textures), and for create some basic images, I use SetPixel method)

setPixel is slow and shouldn't be used extensivly.
The fastest method would be, as Laurent has been writing all over the forum, using your own pixel array and call the update(...) function on a texture.

2) How I must use Texture.Bind method? Why the old version doesn't have this method and draw faster anyway?
3) I notice that if I use "Texture.Bind" on every image that I load, these images may sometimes overrides my RenderTextures. Is it ok?
Do you even know what this method does and why and when you should call it? Or do you just call it at random?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Speed test
« Reply #5 on: May 23, 2012, 08:20:58 pm »
1) If you're updating the texture continuously, then use the method described by eXpl0it3r. Otherwise, if it's only at load time, use whatever you want (like an Image instance) and load the texture from that.

2) and 3) Bind has always existed, you don't need it more now than you needed it before; read the documentation carefully :)
Laurent Gomila - SFML developer

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #6 on: May 23, 2012, 08:58:50 pm »
I know that SetPixel is slow, but I only use it at load time, to make some small basic default textures.
I'm testing a lot of things and I can not found the bottleneck  :-\, but I know that exists, because the same game runs slower with the new version.
I will no rest, until I find the answer!  >:(
I will keep you informed if I found something relevant.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Speed test
« Reply #7 on: May 23, 2012, 10:32:32 pm »
I'm testing a lot of things and I can not found the bottleneck  :-\

Just run a profiler and you'll have you're answer asap... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #8 on: May 23, 2012, 10:55:44 pm »
I don't have a profiler in my visual studio express  :'(
But I think I can found this... I keep trying... now I have some theories that can explain this, but I'm testing it.

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #9 on: May 24, 2012, 02:38:30 am »
There are any way to know the amount of texture memory that I have used?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Speed test
« Reply #10 on: May 24, 2012, 07:59:22 am »
Quote
There are any way to know the amount of texture memory that I have used?
Yes: counting the total number of pixels that you put in sf::Texture :)
Laurent Gomila - SFML developer

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #11 on: May 24, 2012, 09:02:15 am »
I think I found a strange behaviour here, when I was trying to find my bottleneck:

using System;
using SFML.Window;
using SFML.Graphics;
using System.Diagnostics;

namespace SFMLImplementation
{
    public static class SFMLSpeedTest
    {

        public static void Start() {

            RenderWindow app = new RenderWindow(VideoMode.DesktopMode, "");
            RenderTexture surface = new RenderTexture(640, 480);

            app.Closed += OnAppClosed;

            Stopwatch timer = new Stopwatch();
            timer.Start();

            int updateCount = 0;

            Texture img = new Texture("sprite.png");
            Texture img2 = new Texture("sprite2.png");
            Sprite spr = new Sprite(img);

            while(app.IsOpen()) {
                app.DispatchEvents();

                #region DRAWING IMAGES

                surface.Clear();

                for(int i = 0; i < 3000; i++) {
                    if(i % 2 == 0) {
                        spr.Texture = img;
                        spr.Rotation = 45f;
                        spr.Position = new Vector2f(100, 100);
                        spr.Scale = new Vector2f(2f, 2f);
                        surface.Draw(spr);
                    } else {
                        spr.Texture = img2;
                        spr.Rotation = 0f;
                        spr.Position = new Vector2f(0, 0);
                        spr.Scale = new Vector2f(1f, 1f);
                        surface.Draw(spr);
                    }
                   
                }

                surface.Display();

                spr.Position = new Vector2f();
                spr.Rotation = 0f;
                spr.Scale = new Vector2f(1f, 1f);
                spr.Texture = surface.Texture;
                app.Draw(spr);

                #endregion

                app.Display();

                updateCount++;
                if(timer.ElapsedMilliseconds > 1000) {
                    app.SetTitle("FPS: " + updateCount);
                    timer.Restart();
                    updateCount = 0;
                }
            }

            img.Dispose();
            img2.Dispose();

            app.Dispose();
            return;
        }

        static void OnAppClosed(object sender, EventArgs e) {
            Window app = sender as Window;
            app.Close();
        }

    }
}
 

I think the img2 must be visible, but in this case, does not?  ???

I don't know if I discovered something here or it was a fallen asleep... I think can be both things  :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Speed test
« Reply #12 on: May 24, 2012, 09:31:10 am »
I don't know if it has something to do with your problems, but... when you change the texture of a sprite, if the new texture has a different size than the previous one, you must adjust the TextureRect too.

And you shouldn't create non-fullscreen windows that have the same size as the desktop: with the decorations added, the window will be bigger than the screen, and some OSes (at least Windows) don't like that.
Laurent Gomila - SFML developer

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #13 on: May 24, 2012, 09:47:07 am »
Ok, I never use this manner, it's only because I'm testing.
Related to sprite, I must say that these two images ("sprite.png" and "sprite2.png") have the same exact size.

If you test this code... how many images do you see?

Edit: I must say too, that in an old version of SFML2, I can see the TWO images, and in the new version, only render one of them. This is not what I was searching for, but I think that is worthy of mention.
« Last Edit: May 24, 2012, 10:00:04 am by NinjaFighter »

NinjaFighter

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • http://www.sebagames.wordpress.com
Re: Speed test
« Reply #14 on: May 24, 2012, 10:08:27 am »
Ok, I figured what is the problem... it's because what you say about the rectangle. It's not a strange behaviour, it's a mine nonsense. Sorry  ;D
(the surface was drawing with the image source rectangle)

 

anything