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

Forbid passing multiview sampler to the custom function in shaders #72300

Merged

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Jan 29, 2023

My attempt to fix #72290, if @BastiaanOlij has another idea of how to fix it that would be cool, and I will close this PR.

@Chaosus Chaosus requested a review from a team as a code owner January 29, 2023 09:16
@Chaosus Chaosus added this to the 4.0 milestone Jan 29, 2023
@clayjohn
Copy link
Member

My feeling is that this might be necessary until we figure out a better solution. It would be really nice to automatically detect XR and non-XR usage, but I have a feeling that it will be too complex for now

@BastiaanOlij
Copy link
Contributor

This does feel like a very ugly hack around the problem. One thing we could do is to check actions.check_multiview_samplers and only apply this restriction if that is true, and improve the code where we set actions.check_multiview_samplers to true to only do this if multiview shaders are actually used (right now a project setting).

Also could we change the check that if we detect a function being called using a parameter we've deemed needing multiview support, that we tell the user to create a sampler2Darray version of the function being called, if it doesn't exist?

@BastiaanOlij
Copy link
Contributor

My feeling is that this might be necessary until we figure out a better solution. It would be really nice to automatically detect XR and non-XR usage, but I have a feeling that it will be too complex for now

Keep in mind that in XR we're always dealing with a mixed environment. Plus someone adding a function like the OP did, that function might be used for both normal textures and for textures that require multiview access in the same shader.

@Chaosus
Copy link
Member Author

Chaosus commented Jan 30, 2023

It's not a hack - I would call it a plug until we found a way to handle it properly.

@BastiaanOlij
Copy link
Contributor

BastiaanOlij commented Jan 31, 2023

Just to repeat this here as it should be part of this fix, as i mentioned in the issue, we can make this smarter so that our restriction only applies if multiview is enabled. This requires a few small changes:

  1. We need to merge the fix Clay did months ago but which was closed because we wanted a better implementation that never eventuated and probably won't until much much later: Disable multiview shader versions when xr is disabled #63829

  2. We need to change the code in GLES3::MaterialStorage, SceneShaderForwardClustered and SceneShaderForwardMobile from actions.check_multiview_samplers = true; to actions.check_multiview_samplers = RendererCompositorRD::singleton->is_xr_enabled();

  3. We need to check actions.check_multiview_samplers in this fix and only apply this fix if it is true

With these changes our restriction will only be needed, and only apply, if we're compiling multiview shaders.

@YuriSizov
Copy link
Contributor

@clayjohn @BastiaanOlij You seem to have agreed in the issue that this is a good short-term solution (on top of Clay's own old PR, which has since been merged). What changes, if any, are expected from @Chaosus now? Or should we bump it?

@clayjohn
Copy link
Member

@Chaosus I agree with Bastiaan's proposed improvements to this PR. Together they will make this limitation only impact users who are working on XR.

For reference, these are the two changes needed:

We need to change the code in GLES3::MaterialStorage, SceneShaderForwardClustered and SceneShaderForwardMobile from actions.check_multiview_samplers = true; to actions.check_multiview_samplers = RendererCompositorRD::singleton->is_xr_enabled();

We need to check actions.check_multiview_samplers in this fix and only apply this fix if it is true

@BastiaanOlij
Copy link
Contributor

Sounds like clay covered it. If we can make those small changes, this should be ready to go.

@Chaosus Chaosus force-pushed the shader_forbid_pass_mv_textures branch from 20f455e to fc0a822 Compare February 18, 2023 07:47
@Chaosus
Copy link
Member Author

Chaosus commented Feb 18, 2023

@BastiaanOlij, @clayjohn OK, I think I've done it, please recheck.

@BastiaanOlij
Copy link
Contributor

Shader changes look good. Just a little nitpick on the singleton change, though this is my personal opinion on the subject, I don't know what the official stance on this is but I've always added separate singleton members to subclasses to ensure we're accessing a pointer that will remain null when a different subclass is instantiated.

@Chaosus Chaosus force-pushed the shader_forbid_pass_mv_textures branch from fc0a822 to 10b5c87 Compare February 20, 2023 06:31
@Chaosus
Copy link
Member Author

Chaosus commented Feb 20, 2023

@BastiaanOlij OK, I made some changes, check again.

Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

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

Seeing get_singleton is now on the base class we could replace RendererCompositorRD::get_singleton() and RendererCompositorGLES3::get_singleton() with RendererCompositor::get_singleton(). But I feel I'm really taking nitpicking to the next level now :)

@Chaosus Chaosus force-pushed the shader_forbid_pass_mv_textures branch 2 times, most recently from 32678d7 to c7558ef Compare February 21, 2023 08:19
@Chaosus Chaosus force-pushed the shader_forbid_pass_mv_textures branch from c7558ef to 94831c7 Compare February 21, 2023 08:23
@akien-mga

This comment was marked as resolved.

@BastiaanOlij
Copy link
Contributor

Weird, I thought this PR would only have impact on the 3D renderer, not on the 2D renderer, but I could be wrong

@akien-mga
Copy link
Member

I'll try to do more testing, it might have been an unrelated bug present in master too.

@akien-mga
Copy link
Member

Yeah my segfault was unrelated to this PR, sorry for the false alarm. It happens in the master branch too and is related to a simple plugin I got from an unrelated MRP.

So this should be good to go. But I already started the build for 4.0 RC 3, so please don't merge for now, we'll see in the production team how to time this.

@akien-mga akien-mga merged commit 547f8bc into godotengine:master Feb 21, 2023
@akien-mga
Copy link
Member

Thanks!

@Chaosus Chaosus deleted the shader_forbid_pass_mv_textures branch February 22, 2023 05:48
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.

Vulkan shader error when passing screen texture to function
5 participants