Giter Site home page Giter Site logo

Revert change to `sf::Drawable::draw` signature which made `sf::RenderStates` a const reference, and make it a copy again about sfml HOT 10 CLOSED

Bambo-Borris avatar Bambo-Borris commented on May 26, 2024 3
Revert change to `sf::Drawable::draw` signature which made `sf::RenderStates` a const reference, and make it a copy again

from sfml.

Comments (10)

danieljpetersen avatar danieljpetersen commented on May 26, 2024 2

For whatever it's worth, I agree with Bambo. The cost of a draw call is enormous, I don't think that the gains are going to meaningfully offset the still enormous cost of a draw call. You'd have to have A LOT of draw calls I imagine, at which point you've already lost.

from sfml.

vittorioromeo avatar vittorioromeo commented on May 26, 2024 1

sf::RenderStates is quite big as it contains a sf::Transform, plus other 5 members of integer size. We'd be copying sizeof(float) * 16 + sizeof(int) * 5 every time we invoke draw. This could be significant if users are drawing many drawables in a loop.

Is the explicit copy really that annoying? If anything, it shows that quite a bit of data is being copied explicitly.

This API is kinda weird though, maybe this is a symptom of a larger problem? Can RenderStates be taken by non-const reference?

from sfml.

Bambo-Borris avatar Bambo-Borris commented on May 26, 2024 1

For whatever it's worth, I agree with Bambo. The cost of a draw call is enormous, I don't think that the gains are going to meaningfully offset the still enormous cost of a draw call. You'd have to have A LOT of draw calls I imagine, at which point you've already lost.

That is fair, and you are right.

Still, I'd take this as an opportunity to figure out why the API is so awkward in the first place before jumping on a revert. Maybe we can do something even better, but not opposed to a revert.

While I feel there is merit in deeper interrogation of the drawing API, I think it's largely out of the scope of the issue raised here. I think realigning the API to work as it did in 2.0 via a revert so that the ergonomics are kept the same presently is worth it. And revisiting the API discussion when the move away from legacy GL is an option is likely the best time. We're better off bringing this back to how it was before prior to a release of 3.0.

from sfml.

eXpl0it3r avatar eXpl0it3r commented on May 26, 2024 1

What hasn't been mentioned is that the fix was original done because it popped up in static code analysis tools, see the original PR #2008
Unfortunately, due to Coverity having the worst UI ever, I don't know if we can still see what it complained about exactly. Maybe @binary1248 still remembers or can dig up the original report.

Performance is in my view a non-issue. We've been living with this in SFML 2 for the past ten years or so and I don't remember having people run into a bottleneck with this part ever.

For me it's generally fine to revert the change.

Yes, maybe there's a more ergonomic API and since it probably would be breaking, it would be the "right time". On the other hand, it might also not be the right time, as we may come up with quite a different rendering API for SFML 4 and having SFML 3 be a quality of life release for C++17 support, I believe we don't need a major API revamp for this.

from sfml.

binary1248 avatar binary1248 commented on May 26, 2024 1

It was SonarCloud and yes... they truly have one of the most unusable user interfaces in recent memory.

from sfml.

ChrisThrasher avatar ChrisThrasher commented on May 26, 2024

While I'm all for some theoretically performance gains, we're not sure if those performance gains are meaningful compared to the very real ergonomic issues this change has introduced. If we're going to make the library more annoying to use, we need a bit more evidence that the performance gains are worth it. I'm open to reverting this.

from sfml.

Bambo-Borris avatar Bambo-Borris commented on May 26, 2024

sf::RenderStates is quite big as it contains a sf::Transform, plus other 5 members of integer size. We'd be copying sizeof(float) * 16 + sizeof(int) * 5 every time we invoke draw. This could be significant if users are drawing many drawables in a loop.

Is the explicit copy really that annoying? If anything, it shows that quite a bit of data is being copied explicitly.

This API is kinda weird though, maybe this is a symptom of a larger problem? Can RenderStates be taken by non-const reference?

I would suppose there are implications in it being non-const in effecting draw calls subsequent to your custom drawable. I think the API is rather strange but has previously made for nice ergonomics. Anyone making custom drawables is likely to be manipulating the RenderStates object and thus they will have to eat the cost of the copy anyway. And honestly the draw itself is more costly (also more problematic in immediate mode rather than the model favoured by later GL versions and other rendering APIs. I also think it's likely that powerusers who make use of sf::Drawable likely have some scheme of batching which means the cost of the copy is not so bad but the removal of the explicit copy is favourable for readability. And in general the issue with the copy on lots of drawables would be better sorted with batching (considering that the GL draw call itself is the largest overhead).

I may be speaking largely for myself in this issue, which is why I raised it, maybe I should merely avoid the sf::Drawable base but I've utilised it in many projects for the smooth ergonomics it offers when performing a draw on my own custom types (as it was intended for). Would be nice to see some other heavy SFML users chime in with their viewpoint.

from sfml.

vittorioromeo avatar vittorioromeo commented on May 26, 2024

For whatever it's worth, I agree with Bambo. The cost of a draw call is enormous, I don't think that the gains are going to meaningfully offset the still enormous cost of a draw call. You'd have to have A LOT of draw calls I imagine, at which point you've already lost.

That is fair, and you are right.

Still, I'd take this as an opportunity to figure out why the API is so awkward in the first place before jumping on a revert. Maybe we can do something even better, but not opposed to a revert.

from sfml.

vittorioromeo avatar vittorioromeo commented on May 26, 2024

For whatever it's worth, I agree with Bambo. The cost of a draw call is enormous, I don't think that the gains are going to meaningfully offset the still enormous cost of a draw call. You'd have to have A LOT of draw calls I imagine, at which point you've already lost.

That is fair, and you are right.
Still, I'd take this as an opportunity to figure out why the API is so awkward in the first place before jumping on a revert. Maybe we can do something even better, but not opposed to a revert.

While I feel there is merit in deeper interrogation of the drawing API, I think it's largely out of the scope of the issue raised here. I think realigning the API to work as it did in 2.0 via a revert so that the ergonomics are kept the same presently is worth it. And revisiting the API discussion when the move away from legacy GL is an option is likely the best time. We're better off bringing this back to how it was before prior to a release of 3.0.

I'm not talking about a major change to the API. I'm saying that if -- for instance -- it makes more sense to pass sf::RenderStates as a non-const reference, this is the right time to make the change (prior to 3.0 release).

from sfml.

ChrisThrasher avatar ChrisThrasher commented on May 26, 2024

See #2949

from sfml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.