Skip to content

Small optimization to prepare_surface_texture_for_submit#9473

Open
andyleiserson wants to merge 1 commit intogfx-rs:trunkfrom
andyleiserson:jj-push-xrty
Open

Small optimization to prepare_surface_texture_for_submit#9473
andyleiserson wants to merge 1 commit intogfx-rs:trunkfrom
andyleiserson:jj-push-xrty

Conversation

@andyleiserson
Copy link
Copy Markdown
Contributor

@andyleiserson andyleiserson commented Apr 28, 2026

Small cleanup as discussed in #9307 (comment).

Also updates some comments and adds a debug assert.

Testing
Relying on existing tests

Squash or Rebase? Squash

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

@andyleiserson andyleiserson force-pushed the jj-push-xrty branch 2 times, most recently from 6e50167 to be0be2a Compare April 29, 2026 16:32
@andyleiserson andyleiserson marked this pull request as ready for review April 29, 2026 17:40
Copy link
Copy Markdown
Collaborator

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

Broadly LGTM. One maybe-suggestion

Comment thread wgpu-core/src/device/queue.rs Outdated
) -> Result<(), DeviceError> {
let snatch_guard = self.device.snatchable_lock.read();
let (mut submission, _index) = self.allocate_submission(snatch_guard);
let (submission, _index) = self.allocate_submission(snatch_guard);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could've sworn this exact line is modified by another recent PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd believe it has gone back and forth as the calls made on the submission have changed. This is a case where unused_mut is perhaps not that valuable, but easier just to remove the mut than to waive the lint.

// we haven't done anything yet to ensure it stays alive. If we
// cleared the texture, then we must have produced a barrier to put
// it in PRESENT state, so `pending` will not be empty.
debug_assert!(!needs_clear);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the reasoning for this being a debug_assert?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For me it's a borderline case. It does seem unlikely that the overhead of a release assertion here would be a problem. In favor of debug assert: it wasn't included with the code originally; it's more a defense against changes to the code in the future than against runtime conditions we don't expect; for non-web-content applications the annoyance of a false positive is probably worse than whatever consequences of this being wrong.

I am generally on the side of using release asserts unless there's concrete evidence they're too costly. If I wrote the entire function I'd probably make it a release assert.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@andyleiserson Ok, I trust your judgement here

Comment on lines -211 to -214
// Flush pending writes through the standard submission path.
submission
.surface_textures
.insert(Arc::as_ptr(texture), texture.clone());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume this was just unnecessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's discussed in the comment linked in the description -- it's redundant; putting the texture in pending_writes will result in it being added to surface_textures later anyways.

Copy link
Copy Markdown
Collaborator

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

Just ftr, lgtm, abcdef

@andyleiserson andyleiserson deleted the jj-push-xrty branch May 7, 2026 22:00
@inner-daemons
Copy link
Copy Markdown
Collaborator

Why was this closed?

@andyleiserson andyleiserson restored the jj-push-xrty branch May 8, 2026 01:55
@andyleiserson
Copy link
Copy Markdown
Contributor Author

andyleiserson commented May 8, 2026

Oops, that was an accident. (GitHub auto-closes PRs if you delete the branch.) Thank you for noticing!

@andyleiserson andyleiserson reopened this May 8, 2026
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.

3 participants