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(limits): properly calculate max_bindings_per_bind_group #3940

Conversation

ErichDonGubler
Copy link
Member

@ErichDonGubler ErichDonGubler commented Jul 19, 2023

Depends on #3942.


Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
Link to the issues addressed by this PR, or dependent PRs in other repositories

Currently tracked in the Mozilla bug tracker at bug 1844230.

Description
Describe what problem this is solving, and how it's solved.

AdapterInfo::max_bindings_per_bind_group is incorrectly calculated, according to the WebGPU spec.:

max shader stages per pipeline is 2, because a GPURenderPipeline supports both a vertex and fragment shader.

Testing
Explain how this change is tested.

Tested by experimentally consuming this fix in Firefox, and demonstrating that the webgpu:api,operation,adapter,requestDevice:limit,worse_than_default:limit="maxBindingsPerBindGroup" case works correctly (TODO: link).

@ErichDonGubler ErichDonGubler self-assigned this Jul 19, 2023
@ErichDonGubler ErichDonGubler added type: bug Something isn't working area: correctness We're behaving incorrectly api: dx12 Issues with DX12 or DXGI api: metal Issues with Metal api: gles Issues with GLES or WebGL api: dx11 api: vulkan Issues with Vulkan area: cts Issues stemming from the WebGPU Conformance Test Suite labels Jul 19, 2023
@ErichDonGubler ErichDonGubler force-pushed the fix-max_bindings_per_bind_group branch 4 times, most recently from 3210f23 to d2fd46f Compare July 19, 2023 03:02
@ErichDonGubler
Copy link
Member Author

This PR is basically ready to go, minus a CHANGELOG entry and fixing the Clippy WebAssembly CI job that's failing because of an unused symbol error from rustc. Not sure what the right cfg for that is, yet, but this should otherwise be runnable and more-or-less the shape of code I was thinking of.

Comment on lines 505 to 515
let max_bindings_per_bind_group = (max_sampled_textures_per_shader_stage
+ max_samplers_per_shader_stage
+ max_storage_buffers_per_shader_stage
+ max_storage_textures_per_shader_stage
+ max_uniform_buffers_per_shader_stage)
* crate::auxil::MAX_SHADER_STAGES_PER_PIPELINE;

Copy link
Member Author

Choose a reason for hiding this comment

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

suggestion: This calculation is currently duplicated across all back ends. We should make this shared code, too.

@ErichDonGubler ErichDonGubler marked this pull request as ready for review July 19, 2023 12:38
+ max_storage_buffers_per_shader_stage
+ max_storage_textures_per_shader_stage
+ max_uniform_buffers_per_shader_stage)
* MAX_SHADER_STAGES_PER_PIPELINE;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is correct. maxBindingsPerBindGroup's purpose is to limit the maximum index used for bind group bindings, because in some implementations (wgpu with the vulkan backend for example) binding descriptors end up being allocated in a dense array, the size of which is the biggest index in the group, and with some vulkan drivers that was causing some stability/safety issues with large indices.

The limit was first introduced in the spec to be 640, and it has apparently been changed to 1000 since.

So the fix should involve updating the limit to 1000 and making it work consistently over the various backends.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm...sounds like we need to talk about it. @nical and I resolved in Firefox team chat to discuss with the WebGPU team. I'll set this PR back as draft for now.

@ErichDonGubler
Copy link
Member Author

Status: currently blocked on pending discussion with the WebGPU standards body (see #3940 (comment)).

@ErichDonGubler ErichDonGubler marked this pull request as draft July 19, 2023 16:30
@nical
Copy link
Contributor

nical commented Jul 19, 2023

Status: currently blocked on pending discussion with the WebGPU standards body (see #3940 (comment)).

No need to wait, this is superseded by #3942. There is a bit of confusion in the spec around that formula but it is the spec that needs change/clarification in this case, not wgpu.

@ErichDonGubler ErichDonGubler force-pushed the fix-max_bindings_per_bind_group branch 4 times, most recently from 224348c to 5a27bfd Compare July 19, 2023 18:24
@ErichDonGubler
Copy link
Member Author

Status: currently blocked on pending discussion with the WebGPU standards body (see #3940 (comment)).

No need to wait, this is superseded by #3942. There is a bit of confusion in the spec around that formula but it is the spec that needs change/clarification in this case, not wgpu.

I agree that this PR cannot progress for now. I don't agree that it should be closed right now, given that we still need to discuss your conclusion with the wider team and the standards committee first.

@ErichDonGubler ErichDonGubler force-pushed the fix-max_bindings_per_bind_group branch from 5a27bfd to a1db782 Compare July 19, 2023 20:23
@ErichDonGubler ErichDonGubler force-pushed the fix-max_bindings_per_bind_group branch from a1db782 to 1f7d343 Compare July 25, 2023 16:24
@cwfitzgerald
Copy link
Member

I'm going to close this for triage purposes as I don't really want unmergable PRs hanging out - please feel free to keep the branch alive, and re-open once a decision has been made upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dx12 Issues with DX12 or DXGI api: gles Issues with GLES or WebGL api: metal Issues with Metal api: vulkan Issues with Vulkan area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants