Skip to content

[wgpu] Blas compaction#7285

Merged
cwfitzgerald merged 81 commits intogfx-rs:trunkfrom
Vecvec:compaction
Jun 12, 2025
Merged

[wgpu] Blas compaction#7285
cwfitzgerald merged 81 commits intogfx-rs:trunkfrom
Vecvec:compaction

Conversation

@Vecvec
Copy link
Copy Markdown
Contributor

@Vecvec Vecvec commented Mar 6, 2025

Waiting for #7740 which updates the validation layers to fix an issue.

Connections
Builds on #7101

Description
Adds BLAS compaction into wgpu (see wgpu-hal changes #7101)

Testing
Adds tests for the added API

Squash or Rebase?
Squash

Checklist

  • Run cargo fmt.
  • [n/a] Run taplo format.
  • Run cargo clippy. If applicable, add:
    • [n/a] --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

# Conflicts:
#	wgpu-core/src/device/ray_tracing.rs
Comment on lines +1303 to +1309
cmd_buf_raw.transition_buffers(&[hal::BufferBarrier {
buffer: buf,
usage: hal::StateTransition {
from: BufferUses::ACCELERATION_STRUCTURE_QUERY,
to: BufferUses::ACCELERATION_STRUCTURE_QUERY,
},
}])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this transition is not doing anything, IIUC we want to transition to BufferUses::ACCELERATION_STRUCTURE_QUERY but do we always know from what state we are transitioning?

[2025-04-24T06:53:16Z ERROR wgpu_test::expectations] Validation Error: vkCmdCopyQueryPoolResults(): WRITE_AFTER_READ hazard detected. vkCmdCopyQueryPoolResults writes to dstBuffer VkBuffer 0xcb1c7c000000001b[(wgpu internal) compaction read-back buffer], which was previously read by vkCmdBuildAccelerationStructuresKHR. 
    No sufficient synchronization is present to ensure that a write (VK_ACCESS_2_TRANSFER_WRITE_BIT) at VK_PIPELINE_STAGE_2_COPY_BIT does not conflict with a prior read (VK_ACCESS_2_SHADER_READ_BIT) at VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR.
    Vulkan insight: an execution dependency is sufficient to prevent this hazard.
    Buffer access region: {
      offset = 0
      size = 8
    }

The validation error wants us to transition from SHADER_READ in that case but is it guaranteed that we will always transition from SHADER_READ?

Copy link
Copy Markdown
Contributor Author

@Vecvec Vecvec Apr 25, 2025

Choose a reason for hiding this comment

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

I'm not sure, I'm not very good at synchronization. The bit that is most confusing about the error is not what we need to transition to (this can be quite easily done) but that the validation layers are claiming that this was passed to vkCmdBuildAccelerationStructuresKHR which this is never passed to. This buffer should only support BufferUses::ACCELERATION_STRUCTURE_QUERY which is equivelent (on Vulkan only) to COPY_DST and so the validation layers should be giving a validation error about invalid uses (I think) but aren't (it's also not passed to this call ever).

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.

do we always know from what state we are transitioning?

This buffer is blas.compaction_buffer which is only ever used here in a command buffer. The only other use it has is when it is mapped to be read, but that is always after all submissions have finished.

@Vecvec
Copy link
Copy Markdown
Contributor Author

Vecvec commented May 8, 2025

After upgrading my vulkan validation layers to 1.4.313.0 I can no longer reproduce the issue.

Copy link
Copy Markdown
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Looks like solid work through and through. Have some small comments, but lets land this and start testing it!

@cwfitzgerald
Copy link
Copy Markdown
Member

If you need to update the SDK, can you make a separate PR which does that?

@Vecvec
Copy link
Copy Markdown
Contributor Author

Vecvec commented May 30, 2025

If you need to update the SDK, can you make a separate PR which does that?

There are some issues caught by the new sdk that would need to be investigated (e.g: #7696).

@cwfitzgerald
Copy link
Copy Markdown
Member

Alright, I'll see if I can figure out the upgrade.

Vecvec and others added 4 commits May 30, 2025 14:36
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
@Vecvec Vecvec requested a review from cwfitzgerald May 30, 2025 20:41
@cwfitzgerald cwfitzgerald mentioned this pull request May 31, 2025
6 tasks
@teoxoy teoxoy removed their assignment Jun 4, 2025
Copy link
Copy Markdown
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Lets land this!

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) June 11, 2025 22:14
auto-merge was automatically disabled June 12, 2025 01:25

Head branch was pushed to by a user without write access

@cwfitzgerald cwfitzgerald merged commit 73eb83d into gfx-rs:trunk Jun 12, 2025
40 checks passed
@cwfitzgerald cwfitzgerald deleted the compaction branch June 12, 2025 01:40
sharmajai pushed a commit to sharmajai/wgpu that referenced this pull request Oct 12, 2025
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
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