mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #411
411: Fix tracking of render pass attachments r=grovesNL a=kvark Sibling of #410 for master Fixes #407 Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
@@ -56,6 +56,7 @@ impl<F: IdentityFilter<ComputePassId>> Global<F> {
|
||||
|
||||
// There are no transitions to be made: we've already been inserting barriers
|
||||
// into the parent command buffer while recording this compute pass.
|
||||
log::debug!("Compute pass {:?} tracker: {:#?}", pass_id, pass.trackers);
|
||||
cmb.trackers = pass.trackers;
|
||||
cmb.raw.push(pass.raw);
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ impl<F> Global<F> {
|
||||
if let Some((ref view_id, _)) = comb.used_swap_chain {
|
||||
comb.trackers.views.remove(view_id.value);
|
||||
}
|
||||
log::debug!("Command buffer {:?} tracker: {:#?}", encoder_id, comb.trackers);
|
||||
encoder_id
|
||||
}
|
||||
}
|
||||
@@ -280,8 +281,18 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let texture = &texture_guard[texture_id];
|
||||
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));
|
||||
|
||||
let old_layout = match trackers.textures.query(texture_id, view.range.clone()) {
|
||||
let consistent_usage = trackers.textures.query(texture_id, view.range.clone());
|
||||
let pending = trackers.textures.change_replace(
|
||||
texture_id,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
|
||||
let old_layout = match consistent_usage {
|
||||
Some(usage) => {
|
||||
// Using render pass for transition.
|
||||
conv::map_texture_state(
|
||||
usage,
|
||||
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
|
||||
@@ -291,14 +302,6 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
None => {
|
||||
// Required sub-resources have inconsistent states, we need to
|
||||
// issue individual barriers instead of relying on the render pass.
|
||||
let pending = trackers.textures.change_replace(
|
||||
texture_id,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
|
||||
barriers.extend(pending.map(|pending| {
|
||||
log::trace!("\tdepth-stencil {:?}", pending);
|
||||
hal::memory::Barrier::Image {
|
||||
@@ -349,23 +352,26 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let texture = &texture_guard[source_id.value];
|
||||
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));
|
||||
|
||||
let old_layout = match trackers
|
||||
.textures
|
||||
.query(source_id.value, view.range.clone())
|
||||
{
|
||||
let consistent_usage = trackers.textures.query(
|
||||
source_id.value,
|
||||
view.range.clone(),
|
||||
);
|
||||
let pending = trackers.textures.change_replace(
|
||||
source_id.value,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
|
||||
let old_layout = match consistent_usage {
|
||||
Some(usage) => {
|
||||
// Using render pass for transition.
|
||||
conv::map_texture_state(usage, hal::format::Aspects::COLOR).1
|
||||
}
|
||||
None => {
|
||||
// Required sub-resources have inconsistent states, we need to
|
||||
// issue individual barriers instead of relying on the render pass.
|
||||
let pending = trackers.textures.change_replace(
|
||||
source_id.value,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
barriers.extend(pending.map(|pending| {
|
||||
log::trace!("\tcolor {:?}", pending);
|
||||
hal::memory::Barrier::Image {
|
||||
@@ -432,23 +438,26 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let texture = &texture_guard[source_id.value];
|
||||
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));
|
||||
|
||||
let old_layout = match trackers
|
||||
.textures
|
||||
.query(source_id.value, view.range.clone())
|
||||
{
|
||||
let consistent_usage = trackers.textures.query(
|
||||
source_id.value,
|
||||
view.range.clone(),
|
||||
);
|
||||
let pending = trackers.textures.change_replace(
|
||||
source_id.value,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
|
||||
let old_layout = match consistent_usage {
|
||||
Some(usage) => {
|
||||
// Using render pass for transition.
|
||||
conv::map_texture_state(usage, hal::format::Aspects::COLOR).1
|
||||
}
|
||||
None => {
|
||||
// Required sub-resources have inconsistent states, we need to
|
||||
// issue individual barriers instead of relying on the render pass.
|
||||
let pending = trackers.textures.change_replace(
|
||||
source_id.value,
|
||||
&texture.life_guard.ref_count,
|
||||
view.range.clone(),
|
||||
TextureUsage::OUTPUT_ATTACHMENT,
|
||||
&texture.full_range,
|
||||
);
|
||||
barriers.extend(pending.map(|pending| {
|
||||
log::trace!("\tresolve {:?}", pending);
|
||||
hal::memory::Barrier::Image {
|
||||
|
||||
@@ -185,6 +185,8 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
pass.raw.end_render_pass();
|
||||
}
|
||||
pass.trackers.optimize();
|
||||
log::debug!("Render pass {:?} tracker: {:#?}", pass_id, pass.trackers);
|
||||
|
||||
let cmb = &mut cmb_guard[pass.cmb_id.value];
|
||||
let (buffer_guard, mut token) = hub.buffers.read(&mut token);
|
||||
let (texture_guard, _) = hub.textures.read(&mut token);
|
||||
|
||||
@@ -1427,6 +1427,9 @@ impl<F: IdentityFilter<BindGroupId>> Global<F> {
|
||||
let id = hub
|
||||
.bind_groups
|
||||
.register_identity(id_in, bind_group, &mut token);
|
||||
log::debug!("Bind group {:?} tracker : {:#?}",
|
||||
id, hub.bind_groups.read(&mut token).0[id].used);
|
||||
|
||||
let ok = device
|
||||
.trackers
|
||||
.lock()
|
||||
@@ -1628,6 +1631,8 @@ impl<F: AllIdentityFilter + IdentityFilter<CommandBufferId>> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("Device tracker after submission: {:#?}", trackers);
|
||||
|
||||
// now prepare the GPU submission
|
||||
let fence = device.raw.create_fence(false).unwrap();
|
||||
let submission = hal::queue::Submission::<_, _, Vec<&B::Semaphore>> {
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::{
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::hash_map::Entry,
|
||||
fmt::Debug,
|
||||
fmt,
|
||||
marker::PhantomData,
|
||||
ops::Range,
|
||||
vec::Drain,
|
||||
@@ -75,11 +75,11 @@ pub enum Stitch {
|
||||
/// a particular resource type, like a buffer or a texture.
|
||||
pub trait ResourceState: Clone {
|
||||
/// Corresponding `HUB` identifier.
|
||||
type Id: Copy + Debug + TypedId;
|
||||
type Id: Copy + fmt::Debug + TypedId;
|
||||
/// A type specifying the sub-resources.
|
||||
type Selector: Debug;
|
||||
type Selector: fmt::Debug;
|
||||
/// Usage type for a `Unit` of a sub-resource.
|
||||
type Usage: Debug;
|
||||
type Usage: fmt::Debug;
|
||||
|
||||
/// Create a new resource state to track the specified subresources.
|
||||
fn new(full_selector: &Self::Selector) -> Self;
|
||||
@@ -137,7 +137,7 @@ pub trait ResourceState: Clone {
|
||||
|
||||
/// Structure wrapping the abstract tracking state with the relevant resource
|
||||
/// data, such as the reference count and the epoch.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone)]
|
||||
struct Resource<S> {
|
||||
ref_count: RefCount,
|
||||
state: S,
|
||||
@@ -155,7 +155,6 @@ pub struct PendingTransition<S: ResourceState> {
|
||||
}
|
||||
|
||||
/// A tracker for all resources of a given type.
|
||||
#[derive(Debug)]
|
||||
pub struct ResourceTracker<S: ResourceState> {
|
||||
/// An association of known resource indices with their tracked states.
|
||||
map: FastHashMap<Index, Resource<S>>,
|
||||
@@ -165,6 +164,18 @@ pub struct ResourceTracker<S: ResourceState> {
|
||||
backend: Backend,
|
||||
}
|
||||
|
||||
impl<S: ResourceState + fmt::Debug> fmt::Debug for ResourceTracker<S> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.map
|
||||
.iter()
|
||||
.map(|(&index, res)| {
|
||||
((index, res.epoch), &res.state)
|
||||
})
|
||||
.collect::<FastHashMap<_, _>>()
|
||||
.fmt(formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: ResourceState> ResourceTracker<S> {
|
||||
/// Create a new empty tracker.
|
||||
pub fn new(backend: Backend) -> Self {
|
||||
@@ -388,7 +399,7 @@ impl<S: ResourceState> ResourceTracker<S> {
|
||||
}
|
||||
|
||||
|
||||
impl<I: Copy + Debug + TypedId> ResourceState for PhantomData<I> {
|
||||
impl<I: Copy + fmt::Debug + TypedId> ResourceState for PhantomData<I> {
|
||||
type Id = I;
|
||||
type Selector = ();
|
||||
type Usage = ();
|
||||
|
||||
Reference in New Issue
Block a user