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

Author Topic: Experimental internal-context-less branch  (Read 22155 times)

0 Members and 1 Guest are viewing this topic.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Experimental internal-context-less branch
« on: October 09, 2015, 04:10:26 am »
Hi guys, I recently came up with a way to completely get rid of the need for those infamous "internal contexts" that have plagued SFML for so long. This solves many problems/annoyances without actually changing the behaviour of the library for anybody who follows the official usage guidelines/documentation and doesn't rely on undocumented/undefined behaviour.

With internal contexts gone, you might have guessed, SFML has to deal with less contexts. Currently, even if you are working with a single window, SFML will create and hold on to at least 3 contexts although only one of them is really ever used. This branch gets rid of one of the unused contexts, the other one is another story. Less contexts means smaller memory footprint and less work for the OS/driver if that means anything.

The biggest change however, would be that people can actually start creating RenderTextures and other OpenGL resources in threads without having to worry about their system blowing up at some point. The only reason this was an issue previously was because of the whole internal context story.

For the time being I've pushed the branch to my own repository. After enough people have tested it and made sure I didn't utterly break too much stuff, I'll push it to the main repository and open a formal pull request. It might get merged one day.

Here it is for your testing pleasure: https://github.com/SFML/SFML/tree/feature/no_internal_context
« Last Edit: October 13, 2015, 03:50:58 pm by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Experimental internal-context-less branch
« Reply #1 on: October 09, 2015, 08:16:59 am »
Can you explain why these contexts are an issue?
A few more MB is no trouble for today's computers. So if it breaks usages (can you states which ones?) I'm not convinced it's a good idea.
Want to play movies in your SFML application? Check out sfeMovie!

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Experimental internal-context-less branch
« Reply #2 on: October 09, 2015, 10:45:40 am »
Can you explain why these contexts are an issue?
The biggest change however, would be that people can actually start creating RenderTextures and other OpenGL resources in threads without having to worry about their system blowing up at some point. The only reason this was an issue previously was because of the whole internal context story.
So if it breaks usages (can you states which ones?) I'm not convinced it's a good idea.
This solves many problems/annoyances without actually changing the behaviour of the library for anybody who follows the official usage guidelines/documentation and doesn't rely on undocumented/undefined behaviour.
I guess I wasn't clear enough in my original post.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Experimental internal-context-less branch
« Reply #3 on: October 09, 2015, 05:36:48 pm »
I believe this thread from last year may be relevant to give some background on how SFML uses contexts.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Experimental internal-context-less branch
« Reply #4 on: October 09, 2015, 07:27:16 pm »
Looks like it has potential. Nice work binary1248.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Experimental internal-context-less branch
« Reply #5 on: October 09, 2015, 07:58:36 pm »
Great work indeed! 8)

There are many threads about this limitation... I hope the feature branch gets enough exposure and is actually tested by some people!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Experimental internal-context-less branch
« Reply #6 on: October 10, 2015, 05:41:18 am »
I'd like to help with testing but I'm unsure how to actually test this. Can someone offer some suggestions like unit tests or something?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Experimental internal-context-less branch
« Reply #7 on: October 10, 2015, 10:44:21 am »
I think the most promising way is to download binary1248's repository, build it and use the installed SFML library in your projects. Especially if you're actively developing one, you'll see relatively quickly whether things function :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Satus

  • Guest
Re: Experimental internal-context-less branch
« Reply #8 on: October 10, 2015, 01:00:48 pm »
I want to test it, but I'm getting an error when building graphics module.

MinGW w64 5.0, Cmake 3.3, Windows 10, building from Clion IDE, all targets.

Full compiler output:

(click to show/hide)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Experimental internal-context-less branch
« Reply #9 on: October 10, 2015, 02:57:59 pm »
TransientContextLock should be declared as

class SFML_WINDOW_API TransientContextLock

(in GlResource.hpp)

Simple enough to add yourself, if you want to test before binary1248 fixes it ;)
Laurent Gomila - SFML developer

Satus

  • Guest
Re: Experimental internal-context-less branch
« Reply #10 on: October 10, 2015, 03:43:54 pm »
Yep, now it compiles and works with well for me  :)

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Experimental internal-context-less branch
« Reply #11 on: October 10, 2015, 04:30:25 pm »
Fixed. ;D
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Experimental internal-context-less branch
« Reply #12 on: October 11, 2015, 07:56:01 pm »
I guess I wasn't clear enough in my original post.
I guess I should really not post right after waking up ::)
Going to test your branch.

Edit: no trouble with sfeMovie. It only uses an OpenGL context on main thread though, so it doesn't test the annoying case.
« Last Edit: October 11, 2015, 08:09:26 pm by Ceylo »
Want to play movies in your SFML application? Check out sfeMovie!

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: Experimental internal-context-less branch
« Reply #13 on: October 11, 2015, 09:27:02 pm »
Cool.
I recall being bit once by some SFML context-related surprises.  Whether or not this change fixes that particular problem, I'm all for this change.  Especially if it makes the library more useful to advanced users, as suggested on this thread.  Even more impressive if it doesn't affect current users or the API at all.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Experimental internal-context-less branch
« Reply #14 on: October 13, 2015, 03:50:33 pm »
I just moved the branch to the main repository and updated/fixed a few things. The new version should minimize the number of temporary contexts created during the lifetime of an application as well. If you make sure to create an OpenGL resource (Texture, Shader, Window, etc.) before calling any of Shader's or Texture's static member functions, the total number of contexts created should be (number of RenderTargets or Windows) + 1. In a typical single window application that doesn't use RenderTextures, this means that only 2 contexts will ever be created.

As before, it would be nice if people could test this branch in their projects and report any behaviour that is different from the current master revision or release of SFML.

https://github.com/SFML/SFML/tree/feature/no_internal_context
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything