Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-17 Thread SirVer
Thanks for testing everybody! Thanks for reviewing, Tibor.


@bunnybot merge
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-17 Thread noreply
The proposal to merge lp:~widelands-dev/widelands/use_image_cache into 
lp:widelands has been updated.

Status: Needs review => Merged

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
-- 
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread SirVer
The proposal to merge lp:~widelands-dev/widelands/use_image_cache into 
lp:widelands has been updated.

Commit Message changed to:

- Build a texture atlas with the most commonly used images on startup.
- Mild refactorings in the graphic initialization. 
- Add a caching mechanism to remember OpenGL state like bound textures, 
framebuffers, and so on. Use this to avoid unneeded calls into the driver.
- Combine all different blit programs into one and use a if in the fragment 
shader. This allows for more batching, taking load from the CPU and 
transferring it to the GPU.
- Apply suggestion by nha: Recreate buffers on the GPU on each frame instead of 
trying to reuse the memory.

These are the improvements that this buys: All benchmarks where run at 60 FPS, 
3440x1440 resolution & fullscreen, on a map with lots of buildings, lots of 
textures on the screen, lots of different map objects. The game was paused, so 
that no logic code ate CPU. Census & statistics were disabled since they do not 
benefit from the texture atlas at all.

pre renderqueue (revision 7691): ~90% CPU load, 41000 OpenGL calls per frame.
post renderqueue (revision 7695): ~65% CPU load, 18300 OpenGL calls per frame.
This commit: 28% CPU load, 3000 OpenGL calls per frame.

An experimental version that loaded every image in Widelands into one 16kx16k 
texture atlas (1 GB of GPU RAMs was needed): 18% CPU load, 209 OpenGL calls. 
This proved unsustainable for most GPUs so it was dropped again.

Worst to best rendering now only takes 32% CPU and 8% GL calls of what it used 
to. 

Possible improvements: The atlas creating could also compress the images by 
finding unchanging areas in animation. This would drastically reduce the size 
of the atlas and the use of GPU memory. This is described in bug 1121982. I am 
not motivated to work on this now though and I only consider it a nice to have.

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
-- 
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread SirVer
Review: Resubmit

Okay, I simplified the code as there is no need to cache the images anymore on 
disk - building the atlas is fast. I updated the commit message, merged trunk 
and removed codecheck warnings. Tibor, if you approve of the code, could you 
merge it in?
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread GunChleoc
I'm online today, so I can do some testing.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread SirVer
I think this is https://bugs.launchpad.net/widelands/+bug/1531114. I will look 
into that soonish. Can this branch go in?
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread TiborB
Review: Approve

I am all for merging it. 
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread GunChleoc
Looks like my bug is https://bugs.launchpad.net/widelands/+bug/1531114 indeed - 
seems more pronounced with small screen resolutions maybe?

I won't have time to look at the code until end of next week, but if everything 
has been checked, it can go in.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread kaputtnik
Is there a great difference between fullscreen and window mode? I used windowed 
mode to have the task manager open to see the CPU usage.

I just tested a little game on my laptop and this branch as current trunk uses 
about 12% CPU... So no difference?

-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread GunChleoc
I gave this a quick spin in my VM and it runs fine. There is a problem with 
drawing rectangles though - got probably introduced in one of the previous 
graphics branches.

https://launchpadlibrarian.net/234364565/rectangles.png
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread TiborB
I have the same problem as GunChleoc - though I did not notice it.

Otherwise, it works nicely
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-16 Thread SirVer
fullscreen and window will likely not make a huge difference. But the size of 
the widelands drawing area (i.e. resolution in game) and the amount of objects 
on it. The more different objects (terrains, roads, buildings, workers, 
critters and windows) the higher the difference in load. 

Also make sure to pause the game, otherwise the game logic will interfere with 
your benchmark. 

If your GPU is super quick at swapping textures, the difference to the 
renderqueue branch might be small. However, this branch should in no case be 
slower than trunk. 


-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-15 Thread TiborB
OK, I like it.
And I think there will be no more testers, unless GunChleoc shows up.
I am willing to approve it if you think my approval is sufficient.

Of course there is still some NOCOM in diff and you have to mute a logging 
about images as you mentioned.

BTW, windows builds were tested? 
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-14 Thread kaputtnik
Runs fine, the time to create the atlas and loading images is very short on my 
old AMD CPU. Tested editor and a save game. File sizes:

ls -lh
insgesamt 2,4M
-rw-r--r-- 1 kaputtnik users  79K 14. Jan 16:36 texture_atlas.lua
-rw-r--r-- 1 kaputtnik users 2,3M 14. Jan 16:36 texture_atlas_00.png

CPU usage after loading a 5hrs save game:
This branch: ~32%
Current trunk: ~54%

-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-14 Thread SirVer
I changed the code back to load an image from disk if it was not already 
loaded. That is the current behavior in trunk too. I just added logging to get 
a feeling how often that actually happens. I'll remove it before merging. 

nicolai, if you undo the last commit you have the originial behavior that 
creates a huge atlas if it can. I'll rework this branch to no longer cache the 
texture atlas and instead just regenerate the one with the most common images 
every time the game launches. We might revisit packing everything into an atlas 
once we go back to bug 1121982.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-14 Thread TiborB
So it will not built it at once on start, but instead it will expand it on the 
fly as new images are needed during the game? Correct?
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-14 Thread SirVer
no. sorry, that explanation was confusing.

It will immediately on start build a small one (~1024x1200 pixels) that 
contains frequently used images like the UI elements, buildhelp & the roads and 
world textures. Every other image will be loaded as needed from disk and put 
into a separate texture each, i.e. no texture atlas. 
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-14 Thread TiborB
Well, it compiled, building of that cache was fast, BUT I see a lot of output 
like this in console:

Image with hash tribes/workers/barbarians/lumberjack/walk_ne_08_pc.png not 
found. Loading from disk.
Image with hash tribes/workers/barbarians/lumberjack/walk_ne_09_pc.png not 
found. Loading from disk.

???
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-13 Thread SirVer
I need another round of testing, please. 

I modified the code to only pack terrains, roads and tribe borders and the 
pics/ subdirectory into a texture atlas and load all other graphics as needed 
from disk. This is what Nicolai requested - the code requires terrains and 
roads to be in the same texture, so we need this minimal atlas always.

In my tests, the performance for this is comparable to using one atlas with 
2048x2048 textures. It needs ~29% CPU and 3300 GL calls per frame. This is 
still less than half of what trunk currently needs (60% CU, 18300 GL calls), 
but not as good as one huge atlas (18% CPU, 210 GL calls).

Advantages of this are: building the atlas is very quick and there is no need 
to cache. Could I get some testing feedback? 
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-12 Thread TiborB
I can not start it in VirtualBox (Mint in Arch linux) - I am getting 
segmentation fault while building the texture. But virtualbox simply is not 
good enough virtualization tool for running such game inside a guest I think
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-11 Thread TiborB
AFAIK VirtualBox is bit worse in regard to 3D acceleration, but testing in 
VMWare is also very usefull
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-11 Thread SirVer
I will look into running with a minimal texture atlas through a commandline 
option and profile how much performance that cost on my system. 

Probably not before the weekend though. 

In the meantime, more testing with virtual machines would be great!
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread SirVer
> This is an impressive improvement! Out of curiosity, how large does the 
> texture atlas end up being?

All images fit into 16kx16k, but since most GPUs seem to support 8k we have 2 
textures. This could be improved by doing what we started once before, but 
never finished: compactifying the animations by finding common rectangles. This 
could be done when the atlas is constructed and would reduce memory foodprint a 
lot.

[Element Array]
I did experiment with an element array for a bit and it seems to buy some CPU 
too, but I had trouble keeping this indirection in my head during coding, so I 
cut it eventually. I agree that it would be better design.

[Buffer magic]
That sounds interesting, but would require some redesign in the current draw 
approach. I am very weary working on OpenGL related stuff, so I'll call it good 
enough for now. If you are interested in experimenting further, that would of 
course be greatly appreciated!
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/use_image_cache into lp:widelands.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread Tino
Review: Approve

Compiles and runs fine on windows. I would really like to see this land in 
trunk as soon as possible.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread kaputtnik
Review: Approve

Yes, great enhancement. No flickering anymore (which came up with the new font 
renderer):
- Fixes bug 1509791
- may this could help also fixing the bug related to some wrong colored 
shadows? See bug 1519361

A suggestion, if possible. After the image atlas is created a black "Loading 
images" screen appears. It would be nice if the splash screen (the one where 
one has to click) could be used as the background for "Loading images". And 
yes, of course, a progress bar when creating the texture atlas ... :-D

-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread kaputtnik
Thanks for adding the file :-) I just compile and want to test.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/use_image_cache into lp:widelands.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread Tino
Review: Needs Fixing

Currently the images in campaigns are not cached.
Starting any campaign mission fails.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread SirVer
Review: Resubmit

Images in campaigns are fixed now.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread Nicolai Hähnle
Review: Needs Fixing

I wanted to test this branch on my laptop right now, and I have to say it's a 
bit of a nightmare, all of which can be roughly summarized as "this is probably 
not a good idea when VRAM is small". Let me list a number of problems in no 
particular order:

1) Our driver correctly announces support for textures up to 16384 in size, but 
when you actually allocate such a texture, it is 1GB large, which is going to 
fail when VRAM is not that big. So that possibility is something that the code 
should account for.

2) It seems there are plenty of fun bugs in our driver when textures become 
gigantic, so on the plus side, this is a great test case for making our driver 
more robust...

3) When I force max_size to 4096, I no longer hit critical driver bugs (only 
ones leading to rendering errors, oh well). There is still a problem though 
because the atlas textures add up to something like 110 million texels, which 
means that the textures are going to take more than 400MB (okay, maybe slightly 
under since there are also mask textures), which means that on integrated GPUs, 
you get texture thrashing. (Mine has a 512MB VRAM reservation, and whether it 
starts thrashing or not seems to depend on what compiz is currently doing - if 
I only had a single monitor running Widelands fullscreen it would probably 
okay, but as is performance is occasionally killed completely.)

Even without texture atlases, an integrated GPU is going to swap textures 
occasionally, but it's going to happen much less because the working set is 
smaller. With texture atlases, your working set is going to be everything 
almost all of the time.

This sucks. Summary:

(1) Trying to reduce the atlas size is more important than you thought.

(2) Probably the best quick fix option you have is to check VRAM size (e.g. 
using GLX_MESA_query_renderer) and add some heuristic to disable texture 
atlases below a certain VRAM size. It should be possible to override the 
heuristic via the command line. It's kind of sad that you then have a 
performance optimization that doesn't help the hardware that needs it most...

(3) A longer term fix could be some kind of texture streaming. I actually don't 
know the best way to do this.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread SirVer
Nicolai, could you outline what VRAM means in this case? I did not understand a 
lot of your last post, it is full of things that I have no understanding of. 

So far the only feedback I got is that this change improves the performance - I 
tested it on old macs too which has only integrated graphics.


-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread TiborB
If there is such problem it must be discussed thoroughly.

I just tested it on my linux box, with integrated intel HD 4000 and 8 GB RAM 
(this probably matters much) and no visible problems and it seems to be running 
nicely.

I googled a bit how to find out VRAM or whatever it is and found two commands 
(for linux):

$ dmesg | grep Memory
..
[6.992863] [drm] Memory usable by graphics device = 2048M

$ LC_ALL=C lspci -v | grep -EA10 "3D|VGA" | grep 'prefetchable' 
Memory at f780 (64-bit, non-prefetchable) [size=4M]
Memory at e000 (64-bit, prefetchable) [size=256M]

It seems the first one shows maximum (2GB) and second one actual usage (256MB) 
- but I am not sure of interpretation...

But as I said - it runs OK here. Perhaps if more peoples tested it...


-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-10 Thread Nicolai Hähnle
VRAM is Video RAM, which in the case of integrated graphics is a part of the 
physical RAM which is reserved for the GPU. Run `free` to get an idea of how 
large it is approximately: the total memory shown will be less than the 
physical amount of RAM, reflecting how much is available to the CPU.

In addition, there's the GTT or GART, which is a virtual memory aperture 
through which the GPU can access system RAM. If not all data fits into VRAM, 
the GPU can still render from the GTT, but it tends to be slower. The 2048M 
shown in the dmesg log are probably VRAM + GTT.

It's possible that since Widelands doesn't use that much bandwidth, rendering 
from GTT (typically 1-2GB) would be fine.

Please do provide an option to disable the texture atlas, and I'll see what can 
be done about our driver.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/full_texture_atlas.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/use_image_cache into lp:widelands

2016-01-09 Thread Nicolai Hähnle
This is an impressive improvement! Out of curiosity, how large does the texture 
atlas end up being?

I have mostly looked at the actual drawing code (I did notice a merge conflict 
marker in world.cc though, and bunnybot probably did, too ;)). As I already 
said today on IRC, for desktop OpenGL you should really use instancing. You can 
copy the Arguments structure almost 1:1 into a buffer with per-instance data 
and use a simple vertex shader to reduce the CPU load. I'd understand if you 
don't want separate paths for OpenGL ES 2.0 though.

The next-best thing I noticed is using glMapBuffer to avoid an unnecessary 
copy. Right now you fill the vertices_ vector (first "copy"). Then glBufferData 
copies the vertex data into the buffer object (second copy). And finally the 
vertex data gets uploaded to/pulled by the GPU.

Since you know the number of vertices up-front, it would be better to use 
glBufferData(..., NULL, ...) to reserve the required amount of space, then use 
glMapBuffer and write the vertex data directly into the buffer object, thus 
avoiding the second copy. (This would also apply to 

(And now that I've written this, I notice that GLES 2.0 apparently doesn't have 
glMapBuffer... *sigh*)

Third, it would almost certainly be beneficial to use an element array. That 
would reduce the amount of vertex data you need to write by one third, and 
would also reduce the vertex shader load on the GPU by up to one third 
(Widelands almost certainly isn't shader bound, but hey... perhaps it saves 
some power). The element array can even be completely static - it just needs to 
grow as needed during application warm-up.

For the buffer handling, the following is actually best for the kind of 
streaming draw that Widelands is doing:
1. Determine a reasonably large buffer size N.
2. Use a single buffer object, initialized with glBufferData(..., N, NULL, 
GL_STREAM_DRAW);
3. As you go along drawing a frame, fill the buffer object from front to back. 
For all vertex data that you write, use glMapBufferRange to map _exactly_ the 
range that you want to write for the next draw call, then unmap, then do the 
draw call.
4. When the vertex data for the next draw call wouldn't fit in the remaining 
space of the buffer, start from the front, but (and this is VERY important, 
I've seen plenty of applications screw this up) add the 
GL_MAP_INVALIDATE_BUFFER_BIT.

What happens when you do this is that the driver magically maintains a pool of 
underlying buffers, all of size N. Whenever you start from 0 with the 
MAP_INVALIDATE_BUFFER_BIT, the driver switches the underlying buffer to one 
from the pool that is no longer in-flight. As far as I know, all desktop GL 
drivers do this.

Now you see that the patch I sent isn't actually optimal. It would be even 
better to do something like this:

GLsizeiptr bytes = items.size() * sizeof(T);

if (bytes > size_) {
  glBufferData(GL_ARRAY_BUFFER, bytes, items.data(), GL_STREAM_DRAW);
  size_ = bytes;
  filled_ = bytes;
} else {
  GLbitfield access = GL_MAP_WRITE_BIT;

  if (filled_ + bytes > size_) {
filled_ = 0;
access |= GL_MAP_INVALIDATE_BUFFER_BIT;
  }

  void *map = glMapBufferRange(GL_ARRAY_BUFFER, filled_, bytes, access);
  memcpy(map, items.data(), bytes);
  glUnmapBuffer(GL_ARRAY_BUFFER);

  filled_ = (filled_ + bytes + 3) & ~3; // for the memcpy a larger alignment 
might be better; the GPU doesn't really care that much as long as you're dword 
aligned
}

This is better because then the underlying buffer is always the same size and 
the re-use mechanism can work more efficiently. But then you need to check for 
support of GL_ARB_map_buffer_range, and apparently GLES 2.0 doesn't have it. 
Also, buffers don't have to be the exact same size to be re-used by the driver, 
so the impact is probably not too bad.

And of course, while all of the above should reduce CPU load, I have no idea by 
how much.
-- 
https://code.launchpad.net/~widelands-dev/widelands/use_image_cache/+merge/282106
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/use_image_cache into lp:widelands.

___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp