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

Ray tracing compaction #6609

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

Conversation

Vecvec
Copy link
Contributor

@Vecvec Vecvec commented Nov 25, 2024

Connections
Follow up to #6291

Description
Adds the function compact_blas as specified in #1040. This needed two more functions in wgpu-hal. These are based on DX12 and the function call EmitRaytracingAccelerationStructurePostbuildInfo(). On Vulkan this call is emulated with query sets. Compaction does not need any additional featues. Depending on the GPU and BLAS contents compaction may not be possible. In that case the BLAS will be duplicated (logic done by GPU driver).

This change is shown by ray_cube_compute, which now compacts the BLAS before using it. This shows the requirements of the function.

Testing
Adds two more tests, testing valid and invalid compaction operations.

Checklist

  • Run cargo fmt.
  • Run taplo format. - done by CI
  • Run cargo clippy. If applicable, add:
    • N/A --target wasm32-unknown-unknown
    • N/A --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

daniel-keitel and others added 30 commits January 17, 2024 03:32
…mpaction

# Conflicts:
#	wgpu-core/src/resource.rs
# Conflicts:
#	.gitattributes
#	wgpu-core/src/command/compute.rs
#	wgpu-core/src/command/render.rs
#	wgpu-core/src/device/life.rs
#	wgpu-core/src/device/resource.rs
#	wgpu-core/src/track/mod.rs
# Conflicts:
#	examples/src/ray_cube_compute/mod.rs
#	wgpu-core/src/command/ray_tracing.rs
#	wgpu-core/src/device/ray_tracing.rs
#	wgpu-core/src/resource.rs
#	wgpu-hal/src/dx12/command.rs
#	wgpu-hal/src/dx12/device.rs
#	wgpu-hal/src/metal/command.rs
#	wgpu-hal/src/vulkan/command.rs
#	wgpu/src/context.rs
#	wgpu/src/ray_tracing.rs
…cing-compaction

# Conflicts:
#	examples/src/ray_cube_compute/mod.rs
#	player/src/lib.rs
#	wgpu-core/src/command/ray_tracing.rs
#	wgpu-core/src/device/ray_tracing.rs
#	wgpu-core/src/device/resource.rs
#	wgpu-core/src/device/trace.rs
#	wgpu-core/src/lock/rank.rs
#	wgpu-core/src/ray_tracing.rs
#	wgpu-core/src/resource.rs
#	wgpu-core/src/scratch.rs
#	wgpu-hal/src/empty.rs
#	wgpu-types/src/lib.rs
#	wgpu/src/api/command_encoder.rs
#	wgpu/src/backend/webgpu.rs
#	wgpu/src/backend/wgpu_core.rs
#	wgpu/src/context.rs
@Vecvec Vecvec requested a review from a team as a code owner November 25, 2024 03:21
@jimblandy
Copy link
Member

The synchronization around being_built looks wrong to me. There's no way that Relaxed could be adequate for this, because it means that even if the being_built check succeeds, modifications to other parts of the BLAS may not be visible to the thread.

I don't understand the big picture here, but I think these things need to either use the trackers, or there needs to be a Mutex somewhere.

@Vecvec
Copy link
Contributor Author

Vecvec commented Nov 25, 2024

Now that I think about it, I'm not sure that a mutex would be sufficient. I think that the synchronization may need to be redone. Here are the requirements I have thought up that should be implemented:

  • If a BLAS is being build, no compaction operation may happen between queue submit and the encoder being landed (although this is probably unneeded due to polling the device we should still enforce this).
  • If a BLAS is being compacted, no build operation may happen between command encoding and queue submit.

I'll get started on this.

@Vecvec
Copy link
Contributor Author

Vecvec commented Nov 25, 2024

The synchronisation between threads should now be improved, and I think this should be synchronised correctly.

@JMS55
Copy link
Contributor

JMS55 commented Nov 26, 2024

Nvidia has this neat diagram showing the state machine of the compaction process https://developer.nvidia.com/blog/tips-acceleration-structure-compaction/#how_does_compaction_work

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.

6 participants