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

Fix error in AABB calculation for particles with USERDATA #89046

Conversation

permelin
Copy link
Contributor

@permelin permelin commented Mar 1, 2024

Selecting Generate AABB on a 3D particle node in the editor would not work and printed an error about incorrect buffer size if the particle shader used one or more of the USERDATA build-ins.

@permelin permelin requested a review from a team as a code owner March 1, 2024 14:29
@akien-mga akien-mga added this to the 4.3 milestone Mar 1, 2024
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks good!

Did you test the compatibility renderer as well? I took a quick look and I think the compatibility renderer has the opposite problem where its reading from a buffer that only has Transform, color, and custom, but it uses the stride including userdata

@permelin
Copy link
Contributor Author

permelin commented Mar 1, 2024

Did you test the compatibility renderer as well?

No, it didn't even cross my mind that it would have separate code for this. I'm still very new to Godot (and C++, GLSL and gamedev in general) and I have much to learn about how the engine is structured.

I took a quick look and I think the compatibility renderer has the opposite problem where its reading from a buffer that only has Transform, color, and custom, but it uses the stride including userdata

I'm almost certainly misunderstanding you here but even while the userdata fields are not in the C++ struct, space is still reserved on the CPU side for userdata that will only exist on the GPU side. I've assumed it is done this way because the buffer seems to be memory mapped to the GPU. (I really have no idea how these pipelines works, I'm just guessing from the clues I've picked up in the code.)

But from a quick look at the particle code for GLES3 it seems like it sometimes includes userdata in the stride and sometimes not. The corresponding GLSL code expects space to be reserved in the buffer for userdata, but I don't think it actually is. And when I ran a quick test, the particle shader completely glitched out if there was any mention of userdata in it. Which seems to confirm that it is not correctly implemented for the compatibility renderer.

@clayjohn
Copy link
Member

clayjohn commented Mar 1, 2024

Did you test the compatibility renderer as well?

No, it didn't even cross my mind that it would have separate code for this. I'm still very new to Godot (and C++, GLSL and gamedev in general) and I have much to learn about how the engine is structured.

I took a quick look and I think the compatibility renderer has the opposite problem where its reading from a buffer that only has Transform, color, and custom, but it uses the stride including userdata

I'm almost certainly misunderstanding you here but even while the userdata fields are not in the C++ struct, space is still reserved on the CPU side for userdata that will only exist on the GPU side. I've assumed it is done this way because the buffer seems to be memory mapped to the GPU. (I really have no idea how these pipelines works, I'm just guessing from the clues I've picked up in the code.)

But from a quick look at the particle code for GLES3 it seems like it sometimes includes userdata in the stride and sometimes not. The corresponding GLSL code expects space to be reserved in the buffer for userdata, but I don't think it actually is. And when I ran a quick test, the particle shader completely glitched out if there was any mention of userdata in it. Which seems to confirm that it is not correctly implemented for the compatibility renderer.

In that case, perhaps it is best just to move forward with the fix for RD right now.

@permelin
Copy link
Contributor Author

permelin commented Mar 1, 2024

In that case, perhaps it is best just to move forward with the fix for RD right now.

Yes. GLES3 does seem to have a similar bug to the one that this PR fixes, but since the C++ and GLSL disagrees about userdata allocation for GLES3 as it stands, it's impossible to fix the AABB part on its own.

Selecting "Generate AABB" on a 3D particle node in the editor would not work
and printed an error about incorrect buffer size if the particle shader used
one or more of the USERDATA build-ins.
@permelin permelin force-pushed the fix-particle-aabb-recalc-with-userdata branch from 17538f1 to 853935a Compare March 2, 2024 13:27
@permelin
Copy link
Contributor Author

permelin commented Mar 2, 2024

I figured out why userdata in the compatibility particles caused different strides on the CPU and GPU. I'll do a separate PR for that.

@clayjohn You were of course right and I'm sorry that I mansplained things to you. The particular buffers that particles_get_current_aabb() reads from should never have space allocated for userdata. I've pushed an amend that also includes a fix for the compatibility renderer.

@akien-mga akien-mga merged commit 3be5d9b into godotengine:master Mar 4, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@permelin permelin deleted the fix-particle-aabb-recalc-with-userdata branch March 19, 2024 18:25
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.

3 participants