Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix glGet overflows by using 64 bit versions #83031

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Oct 9, 2023

Certain glGet operations require 64 bit versions according to the GLES spec. The previous code was susceptible to overflow bugs, especially running under ANGLE.

May fix #75913

Notes

@lawnjelly lawnjelly added this to the 3.6 milestone Oct 9, 2023
@lawnjelly lawnjelly force-pushed the fix_64bit_glgets branch 3 times, most recently from 5ee0b24 to 015fa5a Compare October 9, 2023 09:42
@lawnjelly lawnjelly marked this pull request as ready for review October 9, 2023 09:43
@lawnjelly lawnjelly requested a review from a team as a code owner October 9, 2023 09:43
@lawnjelly
Copy link
Member Author

lawnjelly commented Oct 9, 2023

Let me know if there are any more than get spotted that should be 64 bit from the spec, I've tried to catch the ones from #80909 .

For the shaders, instead of reading max_image_units directly I've exposed the maximum desired so the calculations will be the same. We could alternatively e.g. make max_image_units static, or make storage readable from the shader file, or copy this value in the shader setup(), but it looks like more code for something that only needs a simple solution.

UBO Size

The UBO size seems to be the primary bug, and I have expanded some comments to discuss this. The problems seem to occur under ANGLE.

  • This needs to be retrieved as 64 bit.
  • Angle may report INT32_MAX + 1, a very high value suggesting that system memory is being used, but the hardware supported size may be lower, and we have no way of querying what it will be (afaik).

There is thus no ideal way to deal with this situation, and we have to compromise. We could e.g.:

  1. Use the large value reported. This should not crash, but may end up being slower.
  2. Detect the situation and revert to a value we know will work in hardware (the minimum), but may not be as fast as using the actual hardware max (which we don't know).

I've gone for (2) here, which still allowing for using larger sizes up to a megabyte, which we seem unlikely to use over in Godot 3.x.

Certain glGet operations require 64 bit versions according to the GLES spec.
The previous code was susceptible to overflow bugs,  especially running under ANGLE.
@akien-mga akien-mga changed the title Fix glGet overflows by using 64 bit versions [3.x] Fix glGet overflows by using 64 bit versions Oct 17, 2023
@akien-mga akien-mga merged commit 00b99bd into godotengine:3.x Nov 14, 2023
13 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga added the cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release label Nov 14, 2023
@lawnjelly lawnjelly deleted the fix_64bit_glgets branch November 14, 2023 13:54
@akien-mga akien-mga changed the title [3.x] Fix glGet overflows by using 64 bit versions [3.x] Fix glGet overflows by using 64 bit versions Jan 25, 2024
@akien-mga akien-mga removed the cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants