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

Adapt WGPU limits to ggez Backend configuration #1249

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

TimerErTim
Copy link

@TimerErTim TimerErTim commented Sep 12, 2023

Problem

I want to be able to write and use compute shaders in ggez projects, as long as the configured backend allows their usage. Currently this is impossible, because the device limits are always set to downlevel_webgl2_defaults which disallows compute shaders.

Solution

This PR dynamically changes these device limits based on the configured backends. It does this in a way, that is consistent across all possible backends according to configuration. (Backend:All disallows compute shaders because it may target WebGL2, Backend::OnlyPrimary on the other hand always enables them).

@a1phyr
Copy link
Member

a1phyr commented Sep 18, 2023

As I understand wgpu::Limits, not requesting compute shaders in the device will prevent using them even if they are actually supported, is that right ?

@TimerErTim
Copy link
Author

TimerErTim commented Sep 18, 2023

Yes, that's right. It limits the wgpu device to the requested limits so that you can't accidentally use the compute shader feature on devices that may not support it.

I used the same philosophy in this PR.

Copy link
Member

@a1phyr a1phyr left a comment

Choose a reason for hiding this comment

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

An alternative strategy would be to test compute shaders availability in new_from_instance from Adapter::limits, and enable them when requesting a device.

This is more complex but more robust.

src/graphics/context.rs Outdated Show resolved Hide resolved
src/graphics/context.rs Outdated Show resolved Hide resolved
src/graphics/context.rs Outdated Show resolved Hide resolved
This allows the usage of more complex and advanced
features like compute shaders on backend platforms
that allow it.
@TimerErTim
Copy link
Author

An alternative strategy would be to test compute shaders availability in new_from_instance from Adapter::limits, and enable them when requesting a device.

This is more complex but more robust.

That approach would be dynamic, right? With that I mean dependent on the current hardware environment and its GPU capabilities.

If so, I'd avoid that, because any feature (which compute shaders are) usable has to be guaranteed to work under all possible environments, in order to align with wgpu's own philosophy. So either the configuration (in this case Backend::<whatever>) can guarantee that under all circumstances the specific feature (compute shaders) is available, in which case that feature is activated, or it can't guarantee it, in which case the feature is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants