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

Author Topic: time variation when loading textures of different sizes?  (Read 2776 times)

0 Members and 1 Guest are viewing this topic.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
time variation when loading textures of different sizes?
« on: April 03, 2022, 01:38:21 pm »
hello! why does loading a big texture (16384x16384) takes so much more time than loading 16 textures of 4096x4096 (if the sum of the texture sizes is the same in the end)?

in this code:
#include <SFML/Graphics.hpp>
#include <iostream>

int main(){
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
    sf::Clock clock;

    sf::Image big_img, small_img;
    sf::Texture big_tex, small_tex[16];
    big_img.create(16384, 16384);
    small_img.create(4096, 4096);

    clock.restart();
   
    big_tex.loadFromImage(big_img);
    std::cout << "big_tex loading time: " << clock.restart().asMilliseconds() << " ms" << std::endl;

    for (int n=0; n<16; n++){
        small_tex[n].loadFromImage(small_img);
        std::cout << "small_tex[" << n << "] loading time: " << clock.restart().asMilliseconds() << " ms" << std::endl;
    }

    return 0;
}

in my computer (not a high-end) it took more than two minutes to load the big texture, and about 15 seconds to load all the small ones. I  suspect it could be something related to the video board needing a contiguous block of memory, but I'm not sure.
anyway, can we somehow take advantage of that to make loading times faster? i tried drawing all the small ones in a RenderTexture, but loading it to a sf::Texture ended up taking much more time (about 5min)  ::)
Visit my game site (and hopefully help funding it? )
Website | IndieDB

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: time variation when loading textures of different sizes?
« Reply #1 on: April 04, 2022, 04:27:21 pm »
This is with SFML 2.5.1 or something else?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: time variation when loading textures of different sizes?
« Reply #2 on: April 04, 2022, 06:41:32 pm »
yep, 2.5.1
I got these values in the last run

Quote
big_tex loading time: 179784 ms
small_tex[0] loading time: 8844 ms
small_tex[1] loading time: 43 ms
small_tex[2] loading time: 49 ms
small_tex[3] loading time: 61 ms
small_tex[4] loading time: 57 ms
small_tex[5] loading time: 60 ms
small_tex[6] loading time: 61 ms
small_tex[7] loading time: 63 ms
small_tex[8] loading time: 60 ms
small_tex[9] loading time: 59 ms
small_tex[10] loading time: 55 ms
small_tex[11] loading time: 57 ms
small_tex[12] loading time: 86 ms
small_tex[13] loading time: 1115 ms
small_tex[14] loading time: 2975 ms
small_tex[15] loading time: 1529 ms

small textures sum is only 15182 ms
Visit my game site (and hopefully help funding it? )
Website | IndieDB

kojack

  • Sr. Member
  • ****
  • Posts: 326
  • C++/C# game dev teacher.
    • View Profile
Re: time variation when loading textures of different sizes?
« Reply #3 on: April 05, 2022, 11:09:58 am »
The values I get:
big_tex loading time: 395 ms
small_tex[0] loading time: 25 ms
small_tex[1] loading time: 25 ms
small_tex[2] loading time: 25 ms
small_tex[3] loading time: 25 ms
small_tex[4] loading time: 25 ms
small_tex[5] loading time: 25 ms
small_tex[6] loading time: 26 ms
small_tex[7] loading time: 25 ms
small_tex[8] loading time: 25 ms
small_tex[9] loading time: 25 ms
small_tex[10] loading time: 25 ms
small_tex[11] loading time: 25 ms
small_tex[12] loading time: 25 ms
small_tex[13] loading time: 25 ms
small_tex[14] loading time: 25 ms
small_tex[15] loading time: 25 ms

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: time variation when loading textures of different sizes?
« Reply #4 on: April 05, 2022, 02:19:41 pm »
Same thing on my side (in debug mode)

big_tex loading time: 451 ms
small_tex[0] loading time: 27 ms
small_tex[1] loading time: 25 ms
small_tex[2] loading time: 27 ms
small_tex[3] loading time: 27 ms
small_tex[4] loading time: 28 ms
small_tex[5] loading time: 27 ms
small_tex[6] loading time: 29 ms
small_tex[7] loading time: 27 ms
small_tex[8] loading time: 28 ms
small_tex[9] loading time: 33 ms
small_tex[10] loading time: 34 ms
small_tex[11] loading time: 42 ms
small_tex[12] loading time: 52 ms
small_tex[13] loading time: 35 ms
small_tex[14] loading time: 36 ms
small_tex[15] loading time: 38 ms

I'd have guessed some odd AV interference, but since this code isn't even accessing the file system, that's not really possible.
As such I can only guess that your GPU might not be happy with the size of the textures.

What does sf::Texture::getMaximumSize() return and what GPU do you have?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: time variation when loading textures of different sizes?
« Reply #5 on: April 05, 2022, 03:35:14 pm »
nice. at least loading such texture won't be a real concern in most hardware, then.
I have an integrated graphics board, Intel HD Graphics 620. the maximum texture size is exactly 16384.

interestingly, if I cut textures sizes by half, the problem still persists (big_tex: 8192, 8192; small_tex: 2048, 2048):
Quote
big_tex loading time: 3089ms
small_tex[0] loading time: 41ms
small_tex[1] loading time: 13ms
small_tex[2] loading time: 27ms
small_tex[3] loading time: 13ms
small_tex[4] loading time: 10ms
small_tex[5] loading time: 12ms
small_tex[6] loading time: 10ms
small_tex[7] loading time: 11ms
small_tex[8] loading time: 12ms
small_tex[9] loading time: 12ms
small_tex[10] loading time: 12ms
small_tex[11] loading time: 12ms
small_tex[12] loading time: 11ms
small_tex[13] loading time: 11ms
small_tex[14] loading time: 12ms
small_tex[15] loading time: 42ms

total small_tex loading time: 268ms


but if I cut it down by half again, the values get very close (big_tex: 4096, 4096; small_tex: 1024, 1024):
Quote
big_tex loading time: 58ms
small_tex[0] loading time: 15ms
small_tex[1] loading time: 3ms
small_tex[2] loading time: 3ms
small_tex[3] loading time: 3ms
small_tex[4] loading time: 3ms
small_tex[5] loading time: 3ms
small_tex[6] loading time: 3ms
small_tex[7] loading time: 2ms
small_tex[8] loading time: 3ms
small_tex[9] loading time: 3ms
small_tex[10] loading time: 3ms
small_tex[11] loading time: 3ms
small_tex[12] loading time: 3ms
small_tex[13] loading time: 2ms
small_tex[14] loading time: 2ms
small_tex[15] loading time: 2ms

total small_tex loading time: 63ms

would you guys mind testing with your respective Texture::getMaximumSize()?

although its not a bug, preliminarly findings suggest that using the max and 2nd max texture sizes (considering powers of two) may be too unpractical
Visit my game site (and hopefully help funding it? )
Website | IndieDB

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: time variation when loading textures of different sizes?
« Reply #6 on: April 05, 2022, 05:08:55 pm »
Max: 32768

Make sure you're running the latest "GPU" driver by going directly to the Intel website.
Too often I've seen people with very outdated Intel graphics chip drivers.

Maybe someone with deep insight into OpenGL could find out more, but in the end, I guess it's just drivers doing drivers things and not much you can do about it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: time variation when loading textures of different sizes?
« Reply #7 on: April 07, 2022, 03:30:11 am »
then probably it is. thanks for the helo  :)
Visit my game site (and hopefully help funding it? )
Website | IndieDB

 

anything