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: don't depend on BG{,L} layout entry order in HAL #5421

Conversation

ErichDonGubler
Copy link
Member

@ErichDonGubler ErichDonGubler commented Mar 21, 2024

Connections

Description

Multiple backends for wgpu-hal currently make assumptions about the ordering of descriptor entries provided for bind groups and bind group layouts that are invalid. In particular, it was assumed that the element order of resource entries stored in Vecs in bind group layouts were the same for bind group resources entries stored in Vecs. This caused binding slot order to become out-of-sync when actually creating bind groups from descriptors and bind group layouts with code like desc.entries.iter().zip(desc.layout.entries.iter()), bypassing essential validation for, i.e., type matching in resource entries, and usage masks for buffers and textures. At best, this caused crashes because of different numbers of types of resources being used (as observed in Firefox's bug 1877461, comment 3). At worst, this caused resources of (of the same and different) types to be bound in the wrong places. We in Firefox noticed because of crashes and putting graphics drivers into invalid states. I'm sure there are other potential types of damage that are even worse. 😬

Testing

The test wgpu_test::different_bgl_order_bw_shader_and_api has been added, which exercises the previously crashing case where more than one resource type was being used in a bind group layout. This doesn't cover cases of resources of the same type having their order mixed up, but it should be sufficient to prevent a significant regression.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@ErichDonGubler ErichDonGubler self-assigned this Mar 29, 2024
@ErichDonGubler ErichDonGubler added area: correctness We're behaving incorrectly api: dx12 Issues with DX12 or DXGI api: gles Issues with GLES or WebGL api: metal Issues with Metal type: bug Something isn't working labels Mar 29, 2024
@ErichDonGubler ErichDonGubler force-pushed the create-bgl-resource-ordering branch 2 times, most recently from 0adbd36 to a709356 Compare March 29, 2024 14:36
@ErichDonGubler ErichDonGubler changed the title WIP: fix: don't depend on BGL layout entry order in HAL fix: don't depend on BG{,L} layout entry order in HAL Mar 29, 2024
This isn't guaranteed by `wgpu-core`; we should try to match by binding
slot index instead.
This isn't guaranteed by `wgpu-core`; we should try to match by binding
slot index instead.
This isn't guaranteed by `wgpu-core`; we should try to match by binding
slot index instead.
@ErichDonGubler ErichDonGubler marked this pull request as ready for review March 29, 2024 16:06
@ErichDonGubler ErichDonGubler requested a review from a team as a code owner March 29, 2024 16:06
@ErichDonGubler ErichDonGubler added the PR: needs back-porting PR with a fix that needs to land on crates label Mar 29, 2024
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

We need a followup bug for the quadratic behavior, but other than that, this looks fantastic. Thank you so much for writing a test.

Edit from @ErichDonGubler: Added in #5473.

@ErichDonGubler ErichDonGubler merged commit 1144b06 into gfx-rs:trunk Apr 1, 2024
27 checks passed
@ErichDonGubler ErichDonGubler deleted the create-bgl-resource-ordering branch April 1, 2024 21:51
cwfitzgerald pushed a commit that referenced this pull request Apr 17, 2024
#5421 (#5455)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@cwfitzgerald cwfitzgerald removed the PR: needs back-porting PR with a fix that needs to land on crates label Apr 17, 2024
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 area: correctness We're behaving incorrectly type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants