-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Replace sampler arrays with constant sampler elements, simplify and reuse code for all shaders #77740
Conversation
f4fd310
to
bac628e
Compare
I'm quite concerned about this change. I'm not sure if it is safe to arbitrarily set a binding index so high (will we run into binding slot limits on some devices? Will we create a future headache for other APIs)). Further, I'm not even sure that this is solving a problem. There are no linked bug reports, so it looks like the old way of using a sampler array wasn't causing any issues. You mention that sampler arrays aren't supported on all devices, could you elaborate on that? Have you tested on a device where master doesn't work, but this PR does? Alternatively, is this a limitation mentioned in the spec, or one we can look at in the GPUInfo database? |
Hey @clayjohn according to the API documentation (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDescriptorSetLayoutBinding.html#_description) Alternative options I thought of:
Im trying to run Godot4 vulkan on low end iPhone (iPhone 6 and iPhone simulator). This changes resolves the limitation under "Array of samplers" With this change and removing a single line in "vulkan_context.cpp"
Running 2D projects works on both devices with the vulkan renderer. I would like to have even simple 3D projects working on the iPhone simulator if possible I did not open a bug about this but I would gladly open one if necessary. Regarding other devices which does not support "Array of samplers", I could not find any information, and I suspect that there are no issues with vulkan-native devices. |
The last update replaces the high binding index with a separate binding set. So at the cost of some additional management in every shader that requires the samplers
I removed the high index values. I think that in general, using the defines to align the shader binding sets and the code values is a good practice. |
That is a neat idea. Unfortunately, most android devices only support binding up to 4 sets at once https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxBoundDescriptorSets This is why we have kept the number of sets so low in all of our shaders. It looks like iOS supports at least 8, so this approach would work there. But it will break on Android |
Ohh wow, I did not know theres a limit on that. |
59d1c8a
to
1a137c3
Compare
Updated the code to not use an additional binding set, instead using a dynamic index assigned by each shader via a define. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now! I just left a small nitpick on one comment. but other than that, everything looks good. I am very happy with this approach now.
I tested locally on a few test scenes I have and on GDQuests TPS demo and I didn't encounter any errors.
This should be good to merge right after we release 4.1 so that it can get lots of testing before 4.2
1a137c3
to
35715e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is missing an empty new line at the end.
Oh, I merged this a bit too early by accident. It was still good, aside from a small formatting issue. But more importantly, I forgot to thank you for your contribution because of that. So thanks :) |
This changes simplifies the material_samplers arrays with constant elements and a single shared definition for all shaders.
Benefits:
reduces code duplication
removes sampler arrays in shaders (which are not supported by all devices)
bugsquad edit: fixes: #70013