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

Ensure safety of indirect dispatch #5714

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

teoxoy
Copy link
Member

@teoxoy teoxoy commented May 17, 2024

Ensure safety of indirect dispatch by injecting a compute shader that validates the content of the indirect buffer.

Part of #2431.

@teoxoy teoxoy requested a review from a team as a code owner May 17, 2024 15:38
@teoxoy

This comment was marked as resolved.

@cwfitzgerald

This comment was marked as resolved.

@cwfitzgerald cwfitzgerald self-requested a review May 18, 2024 02:26
@teoxoy

This comment was marked as resolved.

jimblandy

This comment was marked as resolved.

@daxpedda

This comment was marked as resolved.

@teoxoy

This comment was marked as resolved.

@teoxoy teoxoy force-pushed the validate-indirect-compute branch from 018b23b to a5bebb0 Compare May 21, 2024 12:14
@teoxoy

This comment was marked as resolved.

@teoxoy teoxoy requested a review from jimblandy May 21, 2024 12:20
@teoxoy teoxoy force-pushed the validate-indirect-compute branch 4 times, most recently from ac3f089 to 36281af Compare May 21, 2024 14:35
@teoxoy

This comment was marked as resolved.

@teoxoy

This comment was marked as resolved.

@teoxoy

This comment was marked as resolved.

@teoxoy

This comment was marked as resolved.

@teoxoy teoxoy force-pushed the validate-indirect-compute branch from b57350e to e0bd41a Compare May 27, 2024 14:25
@teoxoy

This comment was marked as resolved.

@cwfitzgerald

This comment was marked as resolved.

jimblandy

This comment was marked as resolved.

@teoxoy

This comment was marked as resolved.

cwfitzgerald

This comment was marked as resolved.

@teoxoy teoxoy force-pushed the validate-indirect-compute branch 3 times, most recently from ab03bc6 to abeb863 Compare June 11, 2024 19:32
@teoxoy teoxoy requested a review from jimblandy June 11, 2024 20:47
@ErichDonGubler

This comment was marked as resolved.

@ErichDonGubler ErichDonGubler dismissed stale reviews from jimblandy and cwfitzgerald September 4, 2024 13:25

Seems to be satisfied, please review again!

@ErichDonGubler

This comment was marked as resolved.

Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

Rebased onto trunk to resolve conflicts.

Comment on lines 693 to 746
) -> Arc<Buffer> {
) -> Result<Arc<Buffer>, resource::CreateBufferError> {
#[cfg(feature = "indirect-validation")]
let raw_indirect_validation_bind_group =
self.create_indirect_validation_bind_group(hal_buffer.as_ref(), desc.size, desc.usage)?;

unsafe { self.raw().add_raw_buffer(&*hal_buffer) };
Copy link
Member

Choose a reason for hiding this comment

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

@nical, was it correct to resolve a conflict here by ordering the add_raw_buffer counter increment after creating raw_indirect_validation_bind_group?

Copy link
Member

Choose a reason for hiding this comment

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

Thinking out loud: I believe we shouldn't increment the counter after the only fallible operation that this PR introduces. If we fail, then we don't have a Buffer created.

Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

Review is still WIP for me, sadly. HOWEVER:

  • I did split some commits out, and I'm feeling confident that they're truly orthogonal (which means I feel like I'm understanding the scope of individual commits!).
  • I'm partway through the ensure safety of indirect dispatch commit. I've got the resource validation, creation, and destruction all confirmed in my head, and I'm not concerned about the correctness of those anymore. My next step is to finish reviewing the executed commands in the middle, to make sure they all make sense to me.

praise: This looks hecka complicated, esp. the size calculation for buffers. Kudos for persevering! Hopefully your eyes didn't glaze over too much with all the algebra; I know mine would have (and probably will during review 😅).

wgpu-core/src/pipeline.rs Show resolved Hide resolved
wgpu-core/src/present.rs Outdated Show resolved Hide resolved
wgpu-core/src/command/bind.rs Show resolved Hide resolved
wgpu/Cargo.toml Show resolved Hide resolved
wgpu-core/src/indirect_validation.rs Outdated Show resolved Hide resolved
wgpu-core/src/indirect_validation.rs Show resolved Hide resolved
buffer_size: u64,
buffer: &dyn hal::DynBuffer,
) -> Result<Box<dyn hal::DynBindGroup>, DeviceError> {
let binding_size = calculate_src_buffer_binding_size(buffer_size, limits);
Copy link
Member

@ErichDonGubler ErichDonGubler Sep 9, 2024

Choose a reason for hiding this comment

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

TODO: validate this in my head

wgpu-core/src/device/resource.rs Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@ErichDonGubler

This comment was marked as resolved.

@ErichDonGubler

This comment was marked as resolved.

@ErichDonGubler ErichDonGubler force-pushed the validate-indirect-compute branch 3 times, most recently from 64d03cf to 47c5116 Compare September 19, 2024 19:49
by injecting a compute shader that validates the content of the indirect buffer
This removes the required barrier prior to the validation dispatch.
Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

Mostly done with the ensure safety of indirect dispatch commit! 😭 🏁

wgpu-core/src/command/compute.rs Outdated Show resolved Hide resolved
state
.scope
.buffers
.merge_single(&buffer, hal::BufferUses::INDIRECT)?;
Copy link
Member

@ErichDonGubler ErichDonGubler Sep 19, 2024

Choose a reason for hiding this comment

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

question: Why do we not call merge_single in the version of code with indirect validation, as with the other? 🤔 Is that on purpose?

unsafe {
state.raw_encoder.transition_buffers(&[hal::BufferBarrier {
buffer: params.dst_buffer,
usage: hal::BufferUses::INDIRECT..hal::BufferUses::STORAGE_READ_WRITE,
Copy link
Member

Choose a reason for hiding this comment

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

issue: This range seems invalid; INDIRECT is an element that is after STORAGE_READ_WRITE. Was the intent to provide an empty range? If so, there's probably clearer way to do it. If not, theeeen oops!

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

Successfully merging this pull request may close these issues.

6 participants