mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Refactor includes, collect swapchain links on RP begin
This commit is contained in:
parent
b67a0bee0d
commit
ba8828eb5b
@ -2,6 +2,7 @@ use crate::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId};
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
pub struct ShaderStageFlags: u32 {
|
||||
|
@ -5,6 +5,7 @@ use hal::command::RawCommandBuffer;
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
||||
pub struct ComputePass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
|
@ -6,12 +6,9 @@ pub(crate) use self::allocator::CommandAllocator;
|
||||
pub use self::compute::*;
|
||||
pub use self::render::*;
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
use hal::Device;
|
||||
|
||||
use crate::device::{FramebufferKey, RenderPassKey};
|
||||
use crate::registry::{Items, HUB};
|
||||
use crate::swap_chain::SwapChainLink;
|
||||
use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
|
||||
use crate::track::{BufferTracker, TextureTracker};
|
||||
use crate::{conv, resource};
|
||||
use crate::{
|
||||
@ -19,11 +16,14 @@ use crate::{
|
||||
Origin3d, RenderPassId, Stored, TextureId, TextureUsageFlags, TextureViewId, WeaklyStored, B,
|
||||
};
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
use hal::Device;
|
||||
use log::trace;
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::ops::Range;
|
||||
use std::thread::ThreadId;
|
||||
|
||||
use log::trace;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
@ -88,7 +88,7 @@ pub struct CommandBuffer<B: hal::Backend> {
|
||||
life_guard: LifeGuard,
|
||||
pub(crate) buffer_tracker: BufferTracker,
|
||||
pub(crate) texture_tracker: TextureTracker,
|
||||
swap_chain_links: Vec<SwapChainLink>,
|
||||
swap_chain_links: Vec<SwapChainLink<SwapImageEpoch>>,
|
||||
}
|
||||
|
||||
impl CommandBuffer<B> {
|
||||
@ -164,7 +164,7 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
|
||||
let rp_key = {
|
||||
let tracker = &mut cmb.texture_tracker;
|
||||
//let swap_chain_links = &mut cmb.swap_chain_links;
|
||||
let swap_chain_links = &mut cmb.swap_chain_links;
|
||||
|
||||
let depth_stencil_key = match desc.depth_stencil_attachment {
|
||||
Some(ref at) => {
|
||||
@ -192,6 +192,23 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
|
||||
let color_keys = desc.color_attachments.iter().map(|at| {
|
||||
let view = view_guard.get(at.attachment);
|
||||
|
||||
if view.is_owned_by_swap_chain {
|
||||
let link = match HUB.textures
|
||||
.read()
|
||||
.get(view.texture_id.value)
|
||||
.swap_chain_link
|
||||
{
|
||||
Some(ref link) => SwapChainLink {
|
||||
swap_chain_id: link.swap_chain_id.clone(),
|
||||
epoch: *link.epoch.lock(),
|
||||
image_index: link.image_index,
|
||||
},
|
||||
None => unreachable!()
|
||||
};
|
||||
swap_chain_links.push(link);
|
||||
}
|
||||
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent);
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ use crate::{CommandBuffer, CommandBufferId, RenderPassId, Stored};
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
|
||||
|
||||
pub struct RenderPass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
|
@ -20,6 +20,7 @@ use std::{ffi, slice};
|
||||
use std::collections::hash_map::{Entry, HashMap};
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
|
||||
#[derive(Hash, PartialEq)]
|
||||
pub(crate) struct RenderPassKey {
|
||||
pub attachments: Vec<hal::pass::Attachment>,
|
||||
@ -902,7 +903,6 @@ pub extern "C" fn wgpu_device_create_swap_chain(
|
||||
acquired: Vec::with_capacity(num_frames as usize),
|
||||
sem_available: device.raw.create_semaphore().unwrap(),
|
||||
command_pool,
|
||||
epoch: 1,
|
||||
});
|
||||
let swap_chain = swap_chain_guard.get_mut(swap_chain_id);
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
#[cfg(not(feature = "winit"))]
|
||||
extern crate winit;
|
||||
|
||||
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
||||
|
||||
use crate::registry::{HUB, Items};
|
||||
use crate::{WeaklyStored, Device, Surface,
|
||||
AdapterId, DeviceId, InstanceId, SurfaceId,
|
||||
};
|
||||
|
||||
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
|
@ -99,7 +99,7 @@ struct Stored<T> {
|
||||
unsafe impl<T> Send for Stored<T> {}
|
||||
unsafe impl<T> Sync for Stored<T> {}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
struct WeaklyStored<T>(T);
|
||||
|
||||
unsafe impl<T> Send for WeaklyStored<T> {}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::resource;
|
||||
|
||||
use crate::{BlendStateId, ByteArray, DepthStencilStateId, PipelineLayoutId, ShaderModuleId};
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum BlendFactor {
|
||||
|
@ -1,8 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::{
|
||||
AdapterHandle, BindGroupLayoutHandle, BindGroupHandle,
|
||||
BlendStateHandle, CommandBufferHandle, DepthStencilStateHandle, DeviceHandle, InstanceHandle,
|
||||
@ -12,6 +7,11 @@ use crate::{
|
||||
SurfaceHandle, SwapChainHandle,
|
||||
};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
||||
#[cfg(not(feature = "remote"))]
|
||||
mod local;
|
||||
|
@ -1,12 +1,12 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
use hal;
|
||||
|
||||
use crate::{
|
||||
Extent3d, LifeGuard, Stored,
|
||||
DeviceId, TextureId,
|
||||
};
|
||||
use crate::swap_chain::SwapChainLink;
|
||||
use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use hal;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
|
||||
bitflags! {
|
||||
@ -85,7 +85,7 @@ pub(crate) struct Texture<B: hal::Backend> {
|
||||
pub kind: hal::image::Kind,
|
||||
pub format: TextureFormat,
|
||||
pub full_range: hal::image::SubresourceRange,
|
||||
pub swap_chain_link: Option<SwapChainLink>,
|
||||
pub swap_chain_link: Option<SwapChainLink<Mutex<SwapImageEpoch>>>,
|
||||
pub life_guard: LifeGuard,
|
||||
}
|
||||
|
||||
|
@ -7,17 +7,16 @@ use crate::track::{Tracktion, TrackPermit};
|
||||
|
||||
use hal;
|
||||
use hal::{Device as _Device, Swapchain as _Swapchain};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use log::trace;
|
||||
|
||||
use std::{iter, mem};
|
||||
|
||||
|
||||
pub type Epoch = u16;
|
||||
pub type SwapImageEpoch = u16;
|
||||
|
||||
pub(crate) struct SwapChainLink {
|
||||
pub(crate) struct SwapChainLink<E> {
|
||||
pub swap_chain_id: WeaklyStored<SwapChainId>, //TODO: strongly
|
||||
pub epoch: Mutex<Epoch>,
|
||||
pub epoch: E,
|
||||
pub image_index: hal::SwapImageIndex,
|
||||
}
|
||||
|
||||
@ -41,7 +40,6 @@ pub(crate) struct SwapChain<B: hal::Backend> {
|
||||
pub acquired: Vec<hal::SwapImageIndex>,
|
||||
pub sem_available: B::Semaphore,
|
||||
pub command_pool: hal::CommandPool<B, hal::General>,
|
||||
pub epoch: Epoch,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -77,7 +75,7 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(
|
||||
let texture_guard = HUB.textures.read();
|
||||
let texture = texture_guard.get(frame.texture_id.value);
|
||||
match texture.swap_chain_link {
|
||||
Some(ref link) => *link.epoch.lock() = swap_chain.epoch,
|
||||
Some(ref link) => *link.epoch.lock() += 1,
|
||||
None => unreachable!(),
|
||||
}
|
||||
|
||||
@ -103,7 +101,7 @@ pub extern "C" fn wgpu_swap_chain_present(
|
||||
None => unreachable!(),
|
||||
}
|
||||
|
||||
//trace!("transit {:?} to present", frame.texture_id.value);
|
||||
trace!("transit {:?} to present", frame.texture_id.value);
|
||||
let tracktion = device.texture_tracker
|
||||
.lock()
|
||||
.transit(
|
||||
|
@ -8,6 +8,7 @@ use std::ops::{BitOr, Range};
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[allow(unused)]
|
||||
pub enum Tracktion<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user