diff --git a/Cargo.lock b/Cargo.lock index 9f950e4a5..662d5200e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,7 +660,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -681,7 +681,7 @@ name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -719,7 +719,7 @@ name = "rand_xorshift" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 32b8e97a0..f00dfe4d4 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -1,6 +1,10 @@ +use crate::resource::BufferUsageFlags; use crate::registry::{Items, HUB}; -use crate::track::{BufferTracker, TextureTracker}; -use crate::{CommandBuffer, CommandBufferId, RenderPassId, Stored}; +use crate::track::{BufferTracker, TextureTracker, TrackPermit}; +use crate::{ + CommandBuffer, Stored, + BufferId, CommandBufferId, RenderPassId, +}; use hal::command::RawCommandBuffer; @@ -47,3 +51,63 @@ pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) -> CommandBuf cmb.raw.push(pass.raw); pass.cmb_id.value } + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_set_index_buffer( + pass_id: RenderPassId, buffer_id: BufferId, offset: u32 +) { + let mut pass_guard = HUB.render_passes.write(); + let buffer_guard = HUB.buffers.read(); + + let pass = pass_guard.get_mut(pass_id); + let buffer = buffer_guard.get(buffer_id); + pass.buffer_tracker + .transit( + buffer_id, + &buffer.life_guard.ref_count, + BufferUsageFlags::INDEX, + TrackPermit::EXTEND, + ) + .unwrap(); + + let view = hal::buffer::IndexBufferView { + buffer: &buffer.raw, + offset: offset as u64, + index_type: hal::IndexType::U16, //TODO? + }; + + unsafe { + pass.raw.bind_index_buffer(view); + } +} + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_set_vertex_buffers( + pass_id: RenderPassId, buffers: &[BufferId], offsets: &[u32] +) { + let mut pass_guard = HUB.render_passes.write(); + let buffer_guard = HUB.buffers.read(); + + let pass = pass_guard.get_mut(pass_id); + for &id in buffers { + let buffer = buffer_guard.get(id); + pass.buffer_tracker + .transit( + id, + &buffer.life_guard.ref_count, + BufferUsageFlags::VERTEX, + TrackPermit::EXTEND, + ) + .unwrap(); + } + + assert_eq!(buffers.len(), offsets.len()); + let buffers = buffers + .iter() + .map(|&id| &buffer_guard.get(id).raw) + .zip(offsets.iter().map(|&off| off as u64)); + + unsafe { + pass.raw.bind_vertex_buffers(0, buffers); + } +} diff --git a/wgpu-native/src/track.rs b/wgpu-native/src/track.rs index 767fa3978..087551641 100644 --- a/wgpu-native/src/track.rs +++ b/wgpu-native/src/track.rs @@ -26,7 +26,12 @@ pub struct Query { bitflags! { pub struct TrackPermit: u32 { + /// Allow extension of the current usage. This is useful during render pass + /// recording, where the usage has to stay constant, but we can defer the + /// decision on what it is until the end of the pass. const EXTEND = 1; + /// Allow replacing the current usage with the new one. This is useful when + /// recording a command buffer live, and the current usage is already been set. const REPLACE = 2; } }