mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-26 00:33:51 +00:00
get_with_usage helper
This commit is contained in:
parent
08cd75f38c
commit
bb7fee796d
@ -103,7 +103,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
|||||||
pool.available.pop().unwrap()
|
pool.available.pop().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submit(&self, cmd_buf: CommandBuffer<B>) {
|
pub fn after_submit(&self, cmd_buf: CommandBuffer<B>) {
|
||||||
self.inner.lock().pending.push(cmd_buf);
|
self.inner.lock().pending.push(cmd_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
|||||||
self.inner.lock().recycle(cmd_buf);
|
self.inner.lock().recycle(cmd_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maintain(&self, device: &B::Device, last_done: SubmissionIndex) {
|
pub fn maintain(&self, last_done: SubmissionIndex) {
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
for i in (0..inner.pending.len()).rev() {
|
for i in (0..inner.pending.len()).rev() {
|
||||||
let index = inner.pending[i].life_guard.submission_index.load(Ordering::Acquire);
|
let index = inner.pending[i].life_guard.submission_index.load(Ordering::Acquire);
|
||||||
|
@ -60,15 +60,15 @@ pub extern "C" fn wgpu_render_pass_set_index_buffer(
|
|||||||
let buffer_guard = HUB.buffers.read();
|
let buffer_guard = HUB.buffers.read();
|
||||||
|
|
||||||
let pass = pass_guard.get_mut(pass_id);
|
let pass = pass_guard.get_mut(pass_id);
|
||||||
let buffer = buffer_guard.get(buffer_id);
|
let (buffer, _) = pass.buffer_tracker
|
||||||
pass.buffer_tracker
|
.get_with_usage(
|
||||||
.transit(
|
&*buffer_guard,
|
||||||
buffer_id,
|
buffer_id,
|
||||||
&buffer.life_guard.ref_count,
|
|
||||||
BufferUsageFlags::INDEX,
|
BufferUsageFlags::INDEX,
|
||||||
TrackPermit::EXTEND,
|
TrackPermit::EXTEND,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
buffer_guard.get(buffer_id);
|
||||||
|
|
||||||
let view = hal::buffer::IndexBufferView {
|
let view = hal::buffer::IndexBufferView {
|
||||||
buffer: &buffer.raw,
|
buffer: &buffer.raw,
|
||||||
@ -90,11 +90,10 @@ pub extern "C" fn wgpu_render_pass_set_vertex_buffers(
|
|||||||
|
|
||||||
let pass = pass_guard.get_mut(pass_id);
|
let pass = pass_guard.get_mut(pass_id);
|
||||||
for &id in buffers {
|
for &id in buffers {
|
||||||
let buffer = buffer_guard.get(id);
|
|
||||||
pass.buffer_tracker
|
pass.buffer_tracker
|
||||||
.transit(
|
.get_with_usage(
|
||||||
|
&*buffer_guard,
|
||||||
id,
|
id,
|
||||||
&buffer.life_guard.ref_count,
|
|
||||||
BufferUsageFlags::VERTEX,
|
BufferUsageFlags::VERTEX,
|
||||||
TrackPermit::EXTEND,
|
TrackPermit::EXTEND,
|
||||||
)
|
)
|
||||||
|
@ -641,12 +641,12 @@ pub extern "C" fn wgpu_queue_submit(
|
|||||||
last_done
|
last_done
|
||||||
};
|
};
|
||||||
|
|
||||||
device.com_allocator.maintain(&device.raw, last_done);
|
device.com_allocator.maintain(last_done);
|
||||||
|
|
||||||
// finally, return the command buffers to the allocator
|
// finally, return the command buffers to the allocator
|
||||||
for &cmb_id in command_buffer_ids {
|
for &cmb_id in command_buffer_ids {
|
||||||
let cmd_buf = command_buffer_guard.take(cmb_id);
|
let cmd_buf = command_buffer_guard.take(cmb_id);
|
||||||
device.com_allocator.submit(cmd_buf);
|
device.com_allocator.after_submit(cmd_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Extent3d, LifeGuard, Stored,
|
Extent3d, LifeGuard, RefCount, Stored,
|
||||||
DeviceId, TextureId,
|
DeviceId, TextureId,
|
||||||
};
|
};
|
||||||
use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
|
use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
|
||||||
@ -8,6 +8,8 @@ use bitflags::bitflags;
|
|||||||
use hal;
|
use hal;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
@ -32,13 +34,18 @@ pub struct BufferDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Buffer<B: hal::Backend> {
|
pub(crate) struct Buffer<B: hal::Backend> {
|
||||||
//pub raw: B::UnboundBuffer,
|
|
||||||
pub raw: B::Buffer,
|
pub raw: B::Buffer,
|
||||||
pub memory_properties: hal::memory::Properties,
|
pub memory_properties: hal::memory::Properties,
|
||||||
pub life_guard: LifeGuard,
|
pub life_guard: LifeGuard,
|
||||||
// TODO: mapping, unmap()
|
// TODO: mapping, unmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B: hal::Backend> Borrow<RefCount> for Buffer<B> {
|
||||||
|
fn borrow(&self) -> &RefCount {
|
||||||
|
&self.life_guard.ref_count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
pub enum TextureDimension {
|
pub enum TextureDimension {
|
||||||
@ -89,6 +96,12 @@ pub(crate) struct Texture<B: hal::Backend> {
|
|||||||
pub life_guard: LifeGuard,
|
pub life_guard: LifeGuard,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B: hal::Backend> Borrow<RefCount> for Texture<B> {
|
||||||
|
fn borrow(&self) -> &RefCount {
|
||||||
|
&self.life_guard.ref_count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct TextureAspectFlags: u32 {
|
pub struct TextureAspectFlags: u32 {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
use crate::registry::{Id, Items};
|
||||||
use crate::resource::{BufferUsageFlags, TextureUsageFlags};
|
use crate::resource::{BufferUsageFlags, TextureUsageFlags};
|
||||||
use crate::{BufferId, RefCount, Stored, TextureId, WeaklyStored};
|
use crate::{BufferId, RefCount, Stored, TextureId, WeaklyStored};
|
||||||
|
|
||||||
|
use std::borrow::Borrow;
|
||||||
use std::collections::hash_map::{Entry, HashMap};
|
use std::collections::hash_map::{Entry, HashMap};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -154,3 +156,17 @@ impl<I: Clone + Hash + Eq, U: Copy + GenericUsage + BitOr<Output = U> + PartialE
|
|||||||
self.map.keys().map(|&WeaklyStored(ref id)| id.clone())
|
self.map.keys().map(|&WeaklyStored(ref id)| id.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<U: Copy + GenericUsage + BitOr<Output = U> + PartialEq> Tracker<Id, U> {
|
||||||
|
pub(crate) fn get_with_usage<'a, T: 'a + Borrow<RefCount>, V: Items<T>>(
|
||||||
|
&mut self,
|
||||||
|
items: &'a V,
|
||||||
|
id: Id,
|
||||||
|
usage: U,
|
||||||
|
permit: TrackPermit,
|
||||||
|
) -> Result<(&'a T, Tracktion<U>), U> {
|
||||||
|
let item = items.get(id);
|
||||||
|
self.transit(id, item.borrow(), usage, permit)
|
||||||
|
.map(|tracktion| (item, tracktion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user