Set vertex and index buffers

This commit is contained in:
Dzmitry Malyshau 2019-01-18 09:48:49 -05:00
parent eff92d3427
commit 08cd75f38c
3 changed files with 74 additions and 5 deletions

6
Cargo.lock generated
View File

@ -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]]

View File

@ -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);
}
}

View File

@ -26,7 +26,12 @@ pub struct Query<T> {
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;
}
}