Skip to content

Do explicit uint casting in GLSL operations #1613

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

Merged
merged 3 commits into from
Mar 24, 2025
Merged

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Mar 19, 2025

Do explicit uint casting in GLSL operations.

Fixes #1611:

@illwieckz
Copy link
Member Author

I confirm it fixes #1611:

@illwieckz
Copy link
Member Author

Curiously the last commit (wip: set u_numLights and u_lightLayer as uint from the start) is generating a bunch of:

OpenGL error GL_INVALID_OPERATION detected

When running with this environment:

export MESA_GL_VERSION_OVERRIDE='3.1'
export MESA_GLSL_VERSION_OVERRIDE='140'
export MESA_EXTENSION_OVERRIDE='-GL_ARB_gpu_shader5'

And this breaks dynamic lighting.

But the last too commits (this one and the one before it) are totally optional. So without those commits making things cleaner, it would work anyway.

@illwieckz illwieckz changed the title WIP: properly type uint GLSL operations Do explicit uint typing in GLSL operations Mar 19, 2025
@illwieckz illwieckz changed the title Do explicit uint typing in GLSL operations Do explicit uint casting in GLSL operations Mar 19, 2025
@illwieckz illwieckz changed the title Do explicit uint casting in GLSL operations Do explicit uint casting in GLSL operations Mar 19, 2025
@illwieckz
Copy link
Member Author

illwieckz commented Mar 19, 2025

I removed all commits that were not meant to fix the #1611 bug.

Fixes for other bugs found when debugging this are now tracked there:

Further improvements (like passing some variables as uint directly instead of casting them) can be done later.

@VReaperV
Copy link
Contributor

This could potentially fix #1491.

@@ -213,7 +213,7 @@ idxs_t fetchIdxs( in vec3 coords, in usampler3D u_LightTiles ) {

// 8 bits per light ID
uint nextIdx( in uint count, in idxs_t idxs ) {
return ( idxs[count / 4] >> ( 8 * ( count % 4 ) ) ) & 0xFFu;
return idxs[count / 4u] >> 8u * ( count % 4u ) & 0xFFu;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should keep at least the outer parentheses so it's clear immediately what the intended order of operations is.

Copy link
Member Author

@illwieckz illwieckz Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is because I first added explicit cast everywhere to get something working, so I ended transforming ( ... ) into uint( ... ). But then when I tracked down the useless casts, I mistakenly deleted the parentheses that were there before…

Now fixed.

@illwieckz
Copy link
Member Author

illwieckz commented Mar 24, 2025

This could potentially fix #1491.

Yes #1491 is very likely the same bug as #1611, they're both running OpenGL 3.1 with GLSL 1.40, and I can reproduce the bug (which is now fixed) with other Mesa drivers (radeonsi…) when I force GL 3.1 and GLSL 1.40.

Copy link
Contributor

@VReaperV VReaperV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@illwieckz
Copy link
Member Author

LGTM

Thank you very much!

@illwieckz illwieckz merged commit 4038c9e into master Mar 24, 2025
9 checks passed
@illwieckz illwieckz deleted the illwieckz/unpack branch March 24, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Renderer T-Improvement Improvement for an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some bitwise errors on Mali G52 r1
2 participants