From cd45aed0f079a6f6190a0acc34701c60b83bd743 Mon Sep 17 00:00:00 2001 From: Svenn-Arne Dragly Date: Tue, 30 Jul 2019 09:35:44 +0200 Subject: [PATCH] Add support for indirect dispatch --- wgpu-native/src/command/compute.rs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index 220e374f7..a2bf00ecf 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -1,9 +1,12 @@ use crate::{ command::bind::{Binder, LayoutChange}, + device::all_buffer_stages, hub::{HUB, Token}, track::{Stitch, TrackerSet}, BindGroupId, BufferAddress, + BufferId, + BufferUsage, CommandBuffer, CommandBufferId, ComputePassId, @@ -158,6 +161,39 @@ pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: } } +#[no_mangle] +pub extern "C" fn wgpu_compute_pass_dispatch_indirect( + pass_id: ComputePassId, + indirect_buffer_id: BufferId, + indirect_offset: BufferAddress, +) { + let mut token = Token::root(); + let (buffer_guard, _) = HUB.buffers.read(&mut token); + let (mut pass_guard, _) = HUB.compute_passes.write(&mut token); + let pass = &mut pass_guard[pass_id]; + + let (src_buffer, src_pending) = pass + .trackers + .buffers + .use_replace(&*buffer_guard, indirect_buffer_id, (), BufferUsage::INDIRECT); + + let barriers = src_pending.map(|pending| hal::memory::Barrier::Buffer { + states: pending.to_states(), + target: &src_buffer.raw, + families: None, + range: None .. None, + }); + + unsafe { + pass.raw.pipeline_barrier( + all_buffer_stages() .. all_buffer_stages(), + hal::memory::Dependencies::empty(), + barriers, + ); + pass.raw.dispatch_indirect(&src_buffer.raw, indirect_offset); + } +} + #[no_mangle] pub extern "C" fn wgpu_compute_pass_set_pipeline( pass_id: ComputePassId,