mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Debug tracking derives and regular optimization
This commit is contained in:
@@ -57,6 +57,7 @@ before_install:
|
||||
|
||||
script:
|
||||
- cargo test
|
||||
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cargo check --release; fi
|
||||
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen; fi
|
||||
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME == "windows" ]]; then
|
||||
wget -nc -O glfw.zip https://github.com/glfw/glfw/archive/3.3.zip &&
|
||||
|
||||
@@ -176,6 +176,7 @@ pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) -> CommandBuf
|
||||
unsafe {
|
||||
pass.raw.end_render_pass();
|
||||
}
|
||||
pass.trackers.optimize();
|
||||
let cmb = &mut cmb_guard[pass.cmb_id.value];
|
||||
|
||||
match cmb.raw.last_mut() {
|
||||
|
||||
@@ -1283,6 +1283,9 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
}
|
||||
}
|
||||
|
||||
// optimize the tracked states
|
||||
comb.trackers.optimize();
|
||||
|
||||
// update submission IDs
|
||||
for id in comb.trackers.buffers.used() {
|
||||
let buffer = &buffer_guard[id];
|
||||
|
||||
@@ -78,6 +78,9 @@ impl ResourceState for BufferState {
|
||||
let usage = other.select(stitch);
|
||||
self.change(id, (), usage, output)
|
||||
}
|
||||
|
||||
fn optimize(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -17,6 +17,7 @@ use hal::backend::FastHashMap;
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::hash_map::Entry,
|
||||
fmt::Debug,
|
||||
marker::PhantomData,
|
||||
ops::Range,
|
||||
vec::Drain,
|
||||
@@ -70,11 +71,11 @@ pub enum Stitch {
|
||||
/// a particular resource type, like a buffer or a texture.
|
||||
pub trait ResourceState: Clone + Default {
|
||||
/// Corresponding `HUB` identifier.
|
||||
type Id: Copy + TypedId;
|
||||
type Id: Copy + Debug + TypedId;
|
||||
/// A type specifying the sub-resources.
|
||||
type Selector;
|
||||
type Selector: Debug;
|
||||
/// Usage type for a `Unit` of a sub-resource.
|
||||
type Usage;
|
||||
type Usage: Debug;
|
||||
|
||||
/// Check if all the selected sub-resources have the same
|
||||
/// usage, and return it.
|
||||
@@ -121,11 +122,15 @@ pub trait ResourceState: Clone + Default {
|
||||
stitch: Stitch,
|
||||
output: Option<&mut Vec<PendingTransition<Self>>>,
|
||||
) -> Result<(), PendingTransition<Self>>;
|
||||
|
||||
/// Try to optimize the internal representation.
|
||||
fn optimize(&mut self);
|
||||
}
|
||||
|
||||
/// Structure wrapping the abstract tracking state with the relevant resource
|
||||
/// data, such as the reference count and the epoch.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(debug_assertions, derive(Debug))]
|
||||
struct Resource<S> {
|
||||
ref_count: RefCount,
|
||||
state: S,
|
||||
@@ -143,6 +148,7 @@ pub struct PendingTransition<S: ResourceState> {
|
||||
}
|
||||
|
||||
/// A tracker for all resources of a given type.
|
||||
#[cfg_attr(debug_assertions, derive(Debug))]
|
||||
pub struct ResourceTracker<S: ResourceState> {
|
||||
/// An association of known resource indices with their tracked states.
|
||||
map: FastHashMap<Index, Resource<S>>,
|
||||
@@ -170,6 +176,13 @@ impl<S: ResourceState> ResourceTracker<S> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to optimize the internal representation.
|
||||
pub fn optimize(&mut self) {
|
||||
for resource in self.map.values_mut() {
|
||||
resource.state.optimize();
|
||||
}
|
||||
}
|
||||
|
||||
/// Return an iterator over used resources keys.
|
||||
pub fn used<'a>(&'a self) -> impl 'a + Iterator<Item = S::Id> {
|
||||
self.map
|
||||
@@ -352,7 +365,7 @@ impl<S: ResourceState> ResourceTracker<S> {
|
||||
}
|
||||
|
||||
|
||||
impl<I: Copy + TypedId> ResourceState for PhantomData<I> {
|
||||
impl<I: Copy + Debug + TypedId> ResourceState for PhantomData<I> {
|
||||
type Id = I;
|
||||
type Selector = ();
|
||||
type Usage = ();
|
||||
@@ -383,10 +396,14 @@ impl<I: Copy + TypedId> ResourceState for PhantomData<I> {
|
||||
) -> Result<(), PendingTransition<Self>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn optimize(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A set of trackers for all relevant resources.
|
||||
#[cfg_attr(debug_assertions, derive(Debug))]
|
||||
pub struct TrackerSet {
|
||||
pub buffers: ResourceTracker<BufferState>,
|
||||
pub textures: ResourceTracker<TextureState>,
|
||||
@@ -414,6 +431,14 @@ impl TrackerSet {
|
||||
self.bind_groups.clear();
|
||||
}
|
||||
|
||||
/// Try to optimize the tracking representation.
|
||||
pub fn optimize(&mut self) {
|
||||
self.buffers.optimize();
|
||||
self.textures.optimize();
|
||||
self.views.optimize();
|
||||
self.bind_groups.optimize();
|
||||
}
|
||||
|
||||
/// Merge all the trackers of another instance by extending
|
||||
/// the usage. Panics on a conflict.
|
||||
pub fn merge_extend(&mut self, other: &Self) {
|
||||
|
||||
@@ -62,8 +62,7 @@ impl<I: Copy + PartialOrd, T: Copy + PartialEq> RangedStates<I, T> {
|
||||
}
|
||||
|
||||
/// Merge the neighboring ranges together, where possible.
|
||||
#[cfg(test)]
|
||||
fn coalesce(&mut self) {
|
||||
pub fn coalesce(&mut self) {
|
||||
let mut num_removed = 0;
|
||||
let mut iter = self.ranges.iter_mut();
|
||||
let mut cur = match iter.next() {
|
||||
|
||||
@@ -195,6 +195,14 @@ impl ResourceState for TextureState {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn optimize(&mut self) {
|
||||
for mip in self.mips.iter_mut() {
|
||||
mip.color.coalesce();
|
||||
mip.depth.coalesce();
|
||||
mip.stencil.coalesce();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user