rust: temporary vector of command buffers

This commit is contained in:
Dzmitry Malyshau 2019-02-21 08:15:39 -05:00
parent a60f3f13fa
commit a7476ee69a
2 changed files with 26 additions and 13 deletions

12
Cargo.lock generated
View File

@ -413,7 +413,7 @@ dependencies = [
[[package]]
name = "gfx-backend-metal"
version = "0.1.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -423,7 +423,7 @@ dependencies = [
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"metal 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"metal 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"range-alloc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -571,7 +571,7 @@ dependencies = [
[[package]]
name = "metal"
version = "0.13.1"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1277,7 +1277,7 @@ dependencies = [
"gfx-backend-dx11 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-backend-dx12 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-backend-empty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-backend-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-backend-metal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-backend-vulkan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx-hal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1438,7 +1438,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gfx-backend-dx11 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7751e630a3472d96b1a0ce9cd6742f2e17c0f71a6e833f822b914a11f89bd7db"
"checksum gfx-backend-dx12 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "635f526eb3110f47ab64145efce8510bb042df7eba147254ecd8a5d732700c11"
"checksum gfx-backend-empty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "590c15369f88b88e4ea748da52b27a521a758a947b4aee995539c9f0cc1beb4c"
"checksum gfx-backend-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "68fa011e32280f7566bddbb736734291b685c812087c99bc848d6ac7ae3e0b7f"
"checksum gfx-backend-metal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66a0fa897619ea7f05e8841fe6214cf1b4e3f52d6a88ed51c2fbc6635a2d5517"
"checksum gfx-backend-vulkan 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "982c618fd9ddeea7e68b2d872b9b6cf13024fc7d4033ba90f0e54ac0d33c798f"
"checksum gfx-hal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "84c470bce77fcaaea6854858682a99026ff796b880b0ca30511593a6b2bc77c0"
"checksum glsl-to-spirv 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "28caebc98746d507603a2d3df66dcbe04e41d4febad0320f3eec1ef72b6bbef1"
@ -1454,7 +1454,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
"checksum memchr 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1dd4eaac298c32ce07eb6ed9242eda7d82955b9170b7d6db59b2e02cc63fcb8"
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
"checksum metal 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7de9c2b83c946ab01c9942928388f911d93486b97636d9927541345905fea65d"
"checksum metal 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd3f21d259068945192293b7a98b1c6844af9eb7602e393c405198b229efc157"
"checksum nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "921f61dc817b379d0834e45d5ec45beaacfae97082090a49c2cf30dcbc30206f"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"

View File

@ -4,7 +4,6 @@ extern crate wgpu_native as wgn;
use arrayvec::ArrayVec;
use std::ffi::CString;
use std::marker::PhantomData;
use std::ops::Range;
use std::ptr;
@ -26,7 +25,14 @@ pub use wgn::{
};
//Note: we need some better guidelines on which structures receive by value, and which by pointer.
//TODO: avoid heap allocating vectors during resource creation.
#[derive(Default)]
struct Temp {
//bind_group_descriptors: Vec<wgn::BindGroupDescriptor>,
//vertex_buffers: Vec<wgn::VertexBufferDescriptor>,
command_buffers: Vec<wgn::CommandBufferId>,
}
pub struct Instance {
id: wgn::InstanceId,
@ -38,6 +44,7 @@ pub struct Adapter {
pub struct Device {
id: wgn::DeviceId,
temp: Temp,
}
pub struct Buffer {
@ -103,7 +110,7 @@ pub struct ComputePipeline {
}
pub struct CommandBuffer {
_id: wgn::CommandBufferId,
id: wgn::CommandBufferId,
}
pub struct CommandEncoder {
@ -122,7 +129,7 @@ pub struct ComputePass<'a> {
pub struct Queue<'a> {
id: wgn::QueueId,
_marker: PhantomData<&'a Self>,
temp: &'a mut Temp,
}
pub struct BindGroupLayoutDescriptor<'a> {
@ -239,6 +246,7 @@ impl Adapter {
pub fn create_device(&self, desc: &DeviceDescriptor) -> Device {
Device {
id: wgn::wgpu_adapter_create_device(self.id, desc),
temp: Temp::default(),
}
}
}
@ -259,7 +267,7 @@ impl Device {
pub fn get_queue(&mut self) -> Queue {
Queue {
id: wgn::wgpu_device_get_queue(self.id),
_marker: PhantomData,
temp: &mut self.temp,
}
}
@ -447,7 +455,7 @@ impl Texture {
impl CommandEncoder {
pub fn finish(self) -> CommandBuffer {
CommandBuffer {
_id: wgn::wgpu_command_encoder_finish(self.id),
id: wgn::wgpu_command_encoder_finish(self.id),
}
}
@ -633,9 +641,14 @@ impl<'a> ComputePass<'a> {
impl<'a> Queue<'a> {
pub fn submit(&mut self, command_buffers: &[CommandBuffer]) {
self.temp.command_buffers.clear();
self.temp.command_buffers.extend(
command_buffers.iter().map(|cb| cb.id)
);
wgn::wgpu_queue_submit(
self.id,
command_buffers.as_ptr() as *const _,
self.temp.command_buffers.as_ptr(),
command_buffers.len(),
);
}