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

Author Topic: Saving memory bandwidth by not calling glTexCoordPointer()  (Read 4158 times)

0 Members and 1 Guest are viewing this topic.

hobby

  • Newbie
  • *
  • Posts: 43
    • View Profile
Saving memory bandwidth by not calling glTexCoordPointer()
« on: December 01, 2015, 08:10:27 pm »
For an application that makes heavy use of vector graphics that is rendered in batches with sf::VertexArray, using textures only infrequently for drawing text, performance might be improved by having RenderTarget::draw() not call glTexCoordPointer() in case that no texture nor shader is active, disabling the texture coords client state if needed.

Could you consider such an option for SFML?
Alternatively, how would you suggest to get a similar behavior with SFML without modifying its source code?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #1 on: December 01, 2015, 09:24:43 pm »
So it would be
if (!states.texture && !states.shader)
    glTexCoords(...);
else
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
?

We just need to make sure that GL_TEXTURE_COORD_ARRAY is managed properly, and of course check that it is indeed more optimized in the general case, but that seems doable.
« Last Edit: December 01, 2015, 09:26:50 pm by Laurent »
Laurent Gomila - SFML developer

hobby

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #2 on: December 02, 2015, 06:45:16 am »
Yes, that would be great!

Is it safe to assume that glDisableClientState() will be no slower than glTexCoordPointer()?

A potential worst-case scenario may be to perform a sequence of drawing calls with a small number of vertices, alternating between using and not using texture/shader. In that case, glTexCoordPointer() will be replaced by two calls (glEnable/DisableClientState), though. I guess that scenarios of this sort are not too common among performance-aware users of SFML anyway.

hobby

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #3 on: December 04, 2015, 11:20:44 am »
This optimization has indeed increased performance in my case.

The implementation (including state management) can be seen in https://github.com/hobby8/SFML/commit/4c68bf1bb62bd5d6210b60f341fa827e9d7c7ec3

Should I open a pull request?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #4 on: December 04, 2015, 11:57:25 am »
Quote
Should I open a pull request?
I'd say yes. Thanks for working on it :)
Laurent Gomila - SFML developer

hobby

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #5 on: December 04, 2015, 02:12:30 pm »
You're welcome, you've made it very easy to contribute. Created #1015.

Do you have benchmark programs for testing performance-related features?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Saving memory bandwidth by not calling glTexCoordPointer()
« Reply #6 on: December 04, 2015, 02:23:41 pm »
Quote
Do you have benchmark programs for testing performance-related features?
No. In a perfect world we would have ready-to-run programs that test the most common cases, as well as unit tests, but we still have nothing ;)
Laurent Gomila - SFML developer

 

anything