mirror of
https://github.com/encounter/wgpu.git
synced 2026-03-30 11:42:28 -07:00
Rustfmt stable pass
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
newline_style = "Native"
|
||||
blank_lines_upper_bound = 2
|
||||
spaces_around_ranges = true
|
||||
imports_layout = "HorizontalVertical"
|
||||
|
||||
@@ -4,16 +4,13 @@
|
||||
|
||||
use crate::{
|
||||
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId},
|
||||
track::{DUMMY_SELECTOR, TrackerSet},
|
||||
FastHashMap,
|
||||
LifeGuard,
|
||||
RefCount,
|
||||
Stored,
|
||||
track::{TrackerSet, DUMMY_SELECTOR},
|
||||
FastHashMap, LifeGuard, RefCount, Stored,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, TextureComponentType};
|
||||
use arrayvec::ArrayVec;
|
||||
use gfx_descriptor::{DescriptorCounts, DescriptorSet};
|
||||
use wgt::{BufferAddress, TextureComponentType};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde_crate::{Deserialize, Serialize};
|
||||
@@ -21,7 +18,11 @@ use std::borrow::Borrow;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub enum BindingType {
|
||||
UniformBuffer = 0,
|
||||
StorageBuffer = 1,
|
||||
@@ -35,7 +36,11 @@ pub enum BindingType {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct BindGroupLayoutEntry {
|
||||
pub binding: u32,
|
||||
pub visibility: wgt::ShaderStage,
|
||||
@@ -80,7 +85,11 @@ pub struct PipelineLayout<B: hal::Backend> {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct BufferBinding {
|
||||
pub buffer: BufferId,
|
||||
pub offset: BufferAddress,
|
||||
@@ -89,7 +98,11 @@ pub struct BufferBinding {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub enum BindingResource {
|
||||
Buffer(BufferBinding),
|
||||
Sampler(SamplerId),
|
||||
@@ -98,7 +111,11 @@ pub enum BindingResource {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct BindGroupEntry {
|
||||
pub binding: u32,
|
||||
pub resource: BindingResource,
|
||||
|
||||
@@ -4,13 +4,7 @@
|
||||
|
||||
use super::CommandBuffer;
|
||||
use crate::{
|
||||
hub::GfxBackend,
|
||||
id::DeviceId,
|
||||
track::TrackerSet,
|
||||
Features,
|
||||
LifeGuard,
|
||||
Stored,
|
||||
SubmissionIndex,
|
||||
hub::GfxBackend, id::DeviceId, track::TrackerSet, Features, LifeGuard, Stored, SubmissionIndex,
|
||||
};
|
||||
|
||||
use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _};
|
||||
@@ -27,7 +21,7 @@ struct CommandPool<B: hal::Backend> {
|
||||
|
||||
impl<B: hal::Backend> CommandPool<B> {
|
||||
fn maintain(&mut self, lowest_active_index: SubmissionIndex) {
|
||||
for i in (0 .. self.pending.len()).rev() {
|
||||
for i in (0..self.pending.len()).rev() {
|
||||
let index = self.pending[i]
|
||||
.life_guard
|
||||
.submission_index
|
||||
@@ -55,7 +49,10 @@ impl<B: hal::Backend> CommandPool<B> {
|
||||
|
||||
fn allocate(&mut self) -> B::CommandBuffer {
|
||||
if self.available.is_empty() {
|
||||
unsafe { self.raw.allocate(20, hal::command::Level::Primary, &mut self.available) };
|
||||
unsafe {
|
||||
self.raw
|
||||
.allocate(20, hal::command::Level::Primary, &mut self.available)
|
||||
};
|
||||
}
|
||||
self.available.pop().unwrap()
|
||||
}
|
||||
@@ -131,7 +128,10 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
let pool = inner.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();
|
||||
|
||||
if pool.available.is_empty() {
|
||||
unsafe { pool.raw.allocate(20, hal::command::Level::Primary, &mut pool.available) };
|
||||
unsafe {
|
||||
pool.raw
|
||||
.allocate(20, hal::command::Level::Primary, &mut pool.available)
|
||||
};
|
||||
}
|
||||
|
||||
pool.available.pop().unwrap()
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::{
|
||||
};
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use wgt::DynamicOffset;
|
||||
use std::slice;
|
||||
use wgt::DynamicOffset;
|
||||
|
||||
pub const DEFAULT_BIND_GROUPS: usize = 4;
|
||||
type BindGroupMask = u8;
|
||||
@@ -44,12 +44,7 @@ impl<'a> Iterator for FollowUpIter<'a> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter
|
||||
.next()
|
||||
.and_then(|entry| {
|
||||
Some((
|
||||
entry.actual_value()?,
|
||||
entry.dynamic_offsets.as_slice(),
|
||||
))
|
||||
})
|
||||
.and_then(|entry| Some((entry.actual_value()?, entry.dynamic_offsets.as_slice())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +146,7 @@ impl Binder {
|
||||
}
|
||||
|
||||
pub(crate) fn reset_expectations(&mut self, length: usize) {
|
||||
for entry in self.entries[length ..].iter_mut() {
|
||||
for entry in self.entries[length..].iter_mut() {
|
||||
entry.expected_layout_id = None;
|
||||
}
|
||||
}
|
||||
@@ -185,8 +180,8 @@ impl Binder {
|
||||
Some((
|
||||
self.pipeline_layout_id?,
|
||||
FollowUpIter {
|
||||
iter: self.entries[index + 1 .. end].iter(),
|
||||
}
|
||||
iter: self.entries[index + 1..end].iter(),
|
||||
},
|
||||
))
|
||||
} else {
|
||||
log::trace!("\t\tskipping above compatible {}", compatible_count);
|
||||
|
||||
@@ -5,17 +5,16 @@
|
||||
use crate::{
|
||||
command::{
|
||||
bind::{Binder, LayoutChange},
|
||||
CommandBuffer,
|
||||
PhantomSlice,
|
||||
CommandBuffer, PhantomSlice,
|
||||
},
|
||||
device::all_buffer_stages,
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage, DynamicOffset, BIND_BUFFER_ALIGNMENT};
|
||||
use hal::command::CommandBuffer as _;
|
||||
use peek_poke::{Peek, PeekPoke, Poke};
|
||||
use wgt::{BufferAddress, BufferUsage, DynamicOffset, BIND_BUFFER_ALIGNMENT};
|
||||
|
||||
use std::iter;
|
||||
|
||||
@@ -90,17 +89,24 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut pipeline_state = PipelineState::Required;
|
||||
|
||||
let mut peeker = raw_data.as_ptr();
|
||||
let raw_data_end = unsafe {
|
||||
raw_data.as_ptr().add(raw_data.len())
|
||||
};
|
||||
let raw_data_end = unsafe { raw_data.as_ptr().add(raw_data.len()) };
|
||||
let mut command = ComputeCommand::Dispatch([0; 3]); // dummy
|
||||
loop {
|
||||
assert!(unsafe { peeker.add(ComputeCommand::max_size()) } <= raw_data_end);
|
||||
peeker = unsafe { ComputeCommand::peek_from(peeker, &mut command) };
|
||||
match command {
|
||||
ComputeCommand::SetBindGroup { index, num_dynamic_offsets, bind_group_id, phantom_offsets } => {
|
||||
ComputeCommand::SetBindGroup {
|
||||
index,
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
phantom_offsets,
|
||||
} => {
|
||||
let (new_peeker, offsets) = unsafe {
|
||||
phantom_offsets.decode_unaligned(peeker, num_dynamic_offsets as usize, raw_data_end)
|
||||
phantom_offsets.decode_unaligned(
|
||||
peeker,
|
||||
num_dynamic_offsets as usize,
|
||||
raw_data_end,
|
||||
)
|
||||
};
|
||||
peeker = new_peeker;
|
||||
|
||||
@@ -136,11 +142,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&*texture_guard,
|
||||
);
|
||||
|
||||
if let Some((pipeline_layout_id, follow_ups)) = binder
|
||||
.provide_entry(index as usize, bind_group_id, bind_group, offsets)
|
||||
if let Some((pipeline_layout_id, follow_ups)) =
|
||||
binder.provide_entry(index as usize, bind_group_id, bind_group, offsets)
|
||||
{
|
||||
let bind_groups = iter::once(bind_group.raw.raw())
|
||||
.chain(follow_ups.clone().map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()));
|
||||
let bind_groups = iter::once(bind_group.raw.raw()).chain(
|
||||
follow_ups
|
||||
.clone()
|
||||
.map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()),
|
||||
);
|
||||
unsafe {
|
||||
raw.bind_compute_descriptor_sets(
|
||||
&pipeline_layout_guard[pipeline_layout_id].raw,
|
||||
@@ -156,7 +165,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
ComputeCommand::SetPipeline(pipeline_id) => {
|
||||
pipeline_state = PipelineState::Set;
|
||||
let pipeline = cmb.trackers
|
||||
let pipeline = cmb
|
||||
.trackers
|
||||
.compute_pipes
|
||||
.use_extend(&*pipeline_guard, pipeline_id, (), ())
|
||||
.unwrap();
|
||||
@@ -169,8 +179,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
if binder.pipeline_layout_id != Some(pipeline.layout_id) {
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline.layout_id];
|
||||
binder.pipeline_layout_id = Some(pipeline.layout_id);
|
||||
binder
|
||||
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
binder.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
let mut is_compatible = true;
|
||||
|
||||
for (index, (entry, &bgl_id)) in binder
|
||||
@@ -200,13 +209,21 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
}
|
||||
ComputeCommand::Dispatch(groups) => {
|
||||
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
|
||||
assert_eq!(
|
||||
pipeline_state,
|
||||
PipelineState::Set,
|
||||
"Dispatch error: Pipeline is missing"
|
||||
);
|
||||
unsafe {
|
||||
raw.dispatch(groups);
|
||||
}
|
||||
}
|
||||
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
|
||||
assert_eq!(pipeline_state, PipelineState::Set, "Dispatch error: Pipeline is missing");
|
||||
assert_eq!(
|
||||
pipeline_state,
|
||||
PipelineState::Set,
|
||||
"Dispatch error: Pipeline is missing"
|
||||
);
|
||||
let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
|
||||
&*buffer_guard,
|
||||
buffer_id,
|
||||
@@ -219,7 +236,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
unsafe {
|
||||
raw.pipeline_barrier(
|
||||
all_buffer_stages() .. all_buffer_stages(),
|
||||
all_buffer_stages()..all_buffer_stages(),
|
||||
hal::memory::Dependencies::empty(),
|
||||
barriers,
|
||||
);
|
||||
@@ -234,15 +251,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
pub mod compute_ffi {
|
||||
use super::{
|
||||
ComputeCommand,
|
||||
super::{PhantomSlice, RawPass},
|
||||
ComputeCommand,
|
||||
};
|
||||
use crate::{
|
||||
id,
|
||||
RawString,
|
||||
};
|
||||
use wgt::{BufferAddress, DynamicOffset};
|
||||
use crate::{id, RawString};
|
||||
use std::{convert::TryInto, slice};
|
||||
use wgt::{BufferAddress, DynamicOffset};
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
@@ -264,9 +278,7 @@ use wgt::{BufferAddress, DynamicOffset};
|
||||
bind_group_id,
|
||||
phantom_offsets: PhantomSlice::default(),
|
||||
});
|
||||
pass.encode_slice(
|
||||
slice::from_raw_parts(offsets, offset_length),
|
||||
);
|
||||
pass.encode_slice(slice::from_raw_parts(offsets, offset_length));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -293,24 +305,16 @@ use wgt::{BufferAddress, DynamicOffset};
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) {
|
||||
pass.encode(&ComputeCommand::DispatchIndirect {
|
||||
buffer_id,
|
||||
offset,
|
||||
});
|
||||
pass.encode(&ComputeCommand::DispatchIndirect { buffer_id, offset });
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_push_debug_group(
|
||||
_pass: &mut RawPass,
|
||||
_label: RawString,
|
||||
) {
|
||||
pub extern "C" fn wgpu_compute_pass_push_debug_group(_pass: &mut RawPass, _label: RawString) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_compute_pass_pop_debug_group(
|
||||
_pass: &mut RawPass,
|
||||
) {
|
||||
pub extern "C" fn wgpu_compute_pass_pop_debug_group(_pass: &mut RawPass) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
@@ -14,30 +14,17 @@ pub use self::render::*;
|
||||
pub use self::transfer::*;
|
||||
|
||||
use crate::{
|
||||
device::{
|
||||
MAX_COLOR_TARGETS,
|
||||
all_buffer_stages,
|
||||
all_image_stages,
|
||||
},
|
||||
device::{all_buffer_stages, all_image_stages, MAX_COLOR_TARGETS},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Storage, Token},
|
||||
id,
|
||||
resource::{Buffer, Texture},
|
||||
track::TrackerSet,
|
||||
Features,
|
||||
LifeGuard,
|
||||
Stored,
|
||||
Features, LifeGuard, Stored,
|
||||
};
|
||||
|
||||
use peek_poke::PeekPoke;
|
||||
|
||||
use std::{
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ptr,
|
||||
slice,
|
||||
thread::ThreadId,
|
||||
};
|
||||
|
||||
use std::{marker::PhantomData, mem, ptr, slice, thread::ThreadId};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PeekPoke)]
|
||||
struct PhantomSlice<T>(PhantomData<T>);
|
||||
@@ -50,7 +37,10 @@ impl<T> Default for PhantomSlice<T> {
|
||||
|
||||
impl<T> PhantomSlice<T> {
|
||||
unsafe fn decode_unaligned<'a>(
|
||||
self, pointer: *const u8, count: usize, bound: *const u8
|
||||
self,
|
||||
pointer: *const u8,
|
||||
count: usize,
|
||||
bound: *const u8,
|
||||
) -> (*const u8, &'a [T]) {
|
||||
let align_offset = pointer.align_offset(mem::align_of::<T>());
|
||||
let aligned = pointer.add(align_offset);
|
||||
@@ -70,10 +60,7 @@ pub struct RawPass {
|
||||
}
|
||||
|
||||
impl RawPass {
|
||||
fn from_vec<T>(
|
||||
mut vec: Vec<T>,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
) -> Self {
|
||||
fn from_vec<T>(mut vec: Vec<T>, encoder_id: id::CommandEncoderId) -> Self {
|
||||
let ptr = vec.as_mut_ptr() as *mut u8;
|
||||
let capacity = vec.capacity() * mem::size_of::<T>();
|
||||
mem::forget(vec);
|
||||
@@ -89,9 +76,7 @@ impl RawPass {
|
||||
///
|
||||
/// The last command is provided, yet the encoder
|
||||
/// is guaranteed to have exactly `C::max_size()` space for it.
|
||||
unsafe fn finish<C: peek_poke::Poke>(
|
||||
&mut self, command: C
|
||||
) {
|
||||
unsafe fn finish<C: peek_poke::Poke>(&mut self, command: C) {
|
||||
self.ensure_extra_size(C::max_size());
|
||||
let extended_end = self.data.add(C::max_size());
|
||||
let end = command.poke_into(self.data);
|
||||
@@ -169,30 +154,26 @@ impl<B: GfxBackend> CommandBuffer<B> {
|
||||
debug_assert_eq!(B::VARIANT, base.backend());
|
||||
debug_assert_eq!(B::VARIANT, head.backend());
|
||||
|
||||
let buffer_barriers = base
|
||||
.buffers
|
||||
.merge_replace(&head.buffers)
|
||||
.map(|pending| {
|
||||
let buf = &buffer_guard[pending.id];
|
||||
pending.into_hal(buf)
|
||||
});
|
||||
let texture_barriers = base
|
||||
.textures
|
||||
.merge_replace(&head.textures)
|
||||
.map(|pending| {
|
||||
let tex = &texture_guard[pending.id];
|
||||
pending.into_hal(tex)
|
||||
});
|
||||
let buffer_barriers = base.buffers.merge_replace(&head.buffers).map(|pending| {
|
||||
let buf = &buffer_guard[pending.id];
|
||||
pending.into_hal(buf)
|
||||
});
|
||||
let texture_barriers = base.textures.merge_replace(&head.textures).map(|pending| {
|
||||
let tex = &texture_guard[pending.id];
|
||||
pending.into_hal(tex)
|
||||
});
|
||||
base.views.merge_extend(&head.views).unwrap();
|
||||
base.bind_groups.merge_extend(&head.bind_groups).unwrap();
|
||||
base.samplers.merge_extend(&head.samplers).unwrap();
|
||||
base.compute_pipes.merge_extend(&head.compute_pipes).unwrap();
|
||||
base.compute_pipes
|
||||
.merge_extend(&head.compute_pipes)
|
||||
.unwrap();
|
||||
base.render_pipes.merge_extend(&head.render_pipes).unwrap();
|
||||
|
||||
let stages = all_buffer_stages() | all_image_stages();
|
||||
unsafe {
|
||||
raw.pipeline_barrier(
|
||||
stages .. stages,
|
||||
stages..stages,
|
||||
hal::memory::Dependencies::empty(),
|
||||
buffer_barriers.chain(texture_barriers),
|
||||
);
|
||||
@@ -258,7 +239,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
comb.is_recording = false;
|
||||
// stop tracking the swapchain image, if used
|
||||
if let Some((ref sc_id, _)) = comb.used_swap_chain {
|
||||
let view_id = swap_chain_guard[sc_id.value].acquired_view_id
|
||||
let view_id = swap_chain_guard[sc_id.value]
|
||||
.acquired_view_id
|
||||
.as_ref()
|
||||
.expect("Used swap chain frame has already presented");
|
||||
comb.trackers.views.remove(view_id.value);
|
||||
|
||||
+147
-163
File diff suppressed because it is too large
Load Diff
@@ -9,8 +9,8 @@ use crate::{
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage, Extent3d, Origin3d, TextureUsage};
|
||||
use hal::command::CommandBuffer as _;
|
||||
use wgt::{BufferAddress, BufferUsage, Extent3d, Origin3d, TextureUsage};
|
||||
|
||||
use std::iter;
|
||||
|
||||
@@ -47,8 +47,8 @@ impl TextureCopyView {
|
||||
{
|
||||
hal::image::SubresourceRange {
|
||||
aspects,
|
||||
levels: level .. level + 1,
|
||||
layers: layer .. layer + 1,
|
||||
levels: level..level + 1,
|
||||
layers: layer..layer + 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ impl TextureCopyView {
|
||||
hal::image::SubresourceLayers {
|
||||
aspects,
|
||||
level: self.mip_level as hal::image::Level,
|
||||
layers: layer .. layer + 1,
|
||||
layers: layer..layer + 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let cmb_raw = cmb.raw.last_mut().unwrap();
|
||||
unsafe {
|
||||
cmb_raw.pipeline_barrier(
|
||||
all_buffer_stages() .. all_buffer_stages(),
|
||||
all_buffer_stages()..all_buffer_stages(),
|
||||
hal::memory::Dependencies::empty(),
|
||||
barriers,
|
||||
);
|
||||
@@ -172,7 +172,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let stages = all_buffer_stages() | all_image_stages();
|
||||
unsafe {
|
||||
cmb_raw.pipeline_barrier(
|
||||
stages .. stages,
|
||||
stages..stages,
|
||||
hal::memory::Dependencies::empty(),
|
||||
src_barriers.chain(dst_barriers),
|
||||
);
|
||||
@@ -236,7 +236,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let stages = all_buffer_stages() | all_image_stages();
|
||||
unsafe {
|
||||
cmb_raw.pipeline_barrier(
|
||||
stages .. stages,
|
||||
stages..stages,
|
||||
hal::memory::Dependencies::empty(),
|
||||
src_barriers.chain(dst_barrier),
|
||||
);
|
||||
@@ -297,7 +297,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let cmb_raw = cmb.raw.last_mut().unwrap();
|
||||
unsafe {
|
||||
cmb_raw.pipeline_barrier(
|
||||
all_image_stages() .. all_image_stages(),
|
||||
all_image_stages()..all_image_stages(),
|
||||
hal::memory::Dependencies::empty(),
|
||||
barriers,
|
||||
);
|
||||
|
||||
+63
-117
@@ -4,32 +4,16 @@
|
||||
|
||||
use crate::{binding_model, Features};
|
||||
use wgt::{
|
||||
BlendDescriptor,
|
||||
BlendFactor,
|
||||
Color,
|
||||
ColorStateDescriptor,
|
||||
ColorWrite,
|
||||
CompareFunction,
|
||||
CullMode,
|
||||
DepthStencilStateDescriptor,
|
||||
Extent3d,
|
||||
FrontFace,
|
||||
IndexFormat,
|
||||
Origin3d,
|
||||
PrimitiveTopology,
|
||||
RasterizationStateDescriptor,
|
||||
StencilOperation,
|
||||
StencilStateFaceDescriptor,
|
||||
TextureFormat,
|
||||
VertexFormat,
|
||||
BlendDescriptor, BlendFactor, Color, ColorStateDescriptor, ColorWrite, CompareFunction,
|
||||
CullMode, DepthStencilStateDescriptor, Extent3d, FrontFace, IndexFormat, Origin3d,
|
||||
PrimitiveTopology, RasterizationStateDescriptor, StencilOperation, StencilStateFaceDescriptor,
|
||||
TextureFormat, VertexFormat,
|
||||
};
|
||||
|
||||
pub fn map_buffer_usage(
|
||||
usage: wgt::BufferUsage,
|
||||
) -> (hal::buffer::Usage, hal::memory::Properties) {
|
||||
use wgt::BufferUsage as W;
|
||||
pub fn map_buffer_usage(usage: wgt::BufferUsage) -> (hal::buffer::Usage, hal::memory::Properties) {
|
||||
use hal::buffer::Usage as U;
|
||||
use hal::memory::Properties as P;
|
||||
use wgt::BufferUsage as W;
|
||||
|
||||
let mut hal_memory = P::empty();
|
||||
if usage.contains(W::MAP_READ) {
|
||||
@@ -69,8 +53,8 @@ pub fn map_texture_usage(
|
||||
usage: wgt::TextureUsage,
|
||||
aspects: hal::format::Aspects,
|
||||
) -> hal::image::Usage {
|
||||
use wgt::TextureUsage as W;
|
||||
use hal::image::Usage as U;
|
||||
use wgt::TextureUsage as W;
|
||||
|
||||
let mut value = U::empty();
|
||||
if usage.contains(W::COPY_SRC) {
|
||||
@@ -97,73 +81,46 @@ pub fn map_texture_usage(
|
||||
value
|
||||
}
|
||||
|
||||
pub fn map_binding_type(
|
||||
binding: &binding_model::BindGroupLayoutEntry,
|
||||
) -> hal::pso::DescriptorType {
|
||||
pub fn map_binding_type(binding: &binding_model::BindGroupLayoutEntry) -> hal::pso::DescriptorType {
|
||||
use crate::binding_model::BindingType as Bt;
|
||||
use hal::pso;
|
||||
match binding.ty {
|
||||
Bt::UniformBuffer => {
|
||||
pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Uniform,
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::StorageBuffer => {
|
||||
pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Storage {
|
||||
read_only: false,
|
||||
},
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::ReadonlyStorageBuffer => {
|
||||
pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Storage {
|
||||
read_only: false,
|
||||
},
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::Sampler |
|
||||
Bt::ComparisonSampler => {
|
||||
pso::DescriptorType::Sampler
|
||||
}
|
||||
Bt::SampledTexture => {
|
||||
pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Sampled {
|
||||
with_sampler: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::ReadonlyStorageTexture => {
|
||||
pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Storage {
|
||||
read_only: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::WriteonlyStorageTexture => {
|
||||
pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Storage {
|
||||
read_only: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
Bt::UniformBuffer => pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Uniform,
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
},
|
||||
Bt::StorageBuffer => pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Storage { read_only: false },
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
},
|
||||
Bt::ReadonlyStorageBuffer => pso::DescriptorType::Buffer {
|
||||
ty: pso::BufferDescriptorType::Storage { read_only: false },
|
||||
format: pso::BufferDescriptorFormat::Structured {
|
||||
dynamic_offset: binding.has_dynamic_offset,
|
||||
},
|
||||
},
|
||||
Bt::Sampler | Bt::ComparisonSampler => pso::DescriptorType::Sampler,
|
||||
Bt::SampledTexture => pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Sampled {
|
||||
with_sampler: false,
|
||||
},
|
||||
},
|
||||
Bt::ReadonlyStorageTexture => pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Storage { read_only: false },
|
||||
},
|
||||
Bt::WriteonlyStorageTexture => pso::DescriptorType::Image {
|
||||
ty: pso::ImageDescriptorType::Storage { read_only: true },
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_shader_stage_flags(
|
||||
shader_stage_flags: wgt::ShaderStage,
|
||||
) -> hal::pso::ShaderStageFlags {
|
||||
use wgt::ShaderStage as Ss;
|
||||
pub fn map_shader_stage_flags(shader_stage_flags: wgt::ShaderStage) -> hal::pso::ShaderStageFlags {
|
||||
use hal::pso::ShaderStageFlags as H;
|
||||
use wgt::ShaderStage as Ss;
|
||||
|
||||
let mut value = H::empty();
|
||||
if shader_stage_flags.contains(Ss::VERTEX) {
|
||||
@@ -194,11 +151,9 @@ pub fn map_extent(extent: Extent3d) -> hal::image::Extent {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_primitive_topology(
|
||||
primitive_topology: PrimitiveTopology,
|
||||
) -> hal::pso::Primitive {
|
||||
use wgt::PrimitiveTopology as Pt;
|
||||
pub fn map_primitive_topology(primitive_topology: PrimitiveTopology) -> hal::pso::Primitive {
|
||||
use hal::pso::Primitive as H;
|
||||
use wgt::PrimitiveTopology as Pt;
|
||||
match primitive_topology {
|
||||
Pt::PointList => H::PointList,
|
||||
Pt::LineList => H::LineList,
|
||||
@@ -208,9 +163,7 @@ pub fn map_primitive_topology(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_color_state_descriptor(
|
||||
desc: &ColorStateDescriptor,
|
||||
) -> hal::pso::ColorBlendDesc {
|
||||
pub fn map_color_state_descriptor(desc: &ColorStateDescriptor) -> hal::pso::ColorBlendDesc {
|
||||
let color_mask = desc.write_mask;
|
||||
let blend_state = if desc.color_blend != BlendDescriptor::REPLACE
|
||||
|| desc.alpha_blend != BlendDescriptor::REPLACE
|
||||
@@ -229,8 +182,8 @@ pub fn map_color_state_descriptor(
|
||||
}
|
||||
|
||||
fn map_color_write_flags(flags: ColorWrite) -> hal::pso::ColorMask {
|
||||
use wgt::ColorWrite as Cw;
|
||||
use hal::pso::ColorMask as H;
|
||||
use wgt::ColorWrite as Cw;
|
||||
|
||||
let mut value = H::empty();
|
||||
if flags.contains(Cw::RED) {
|
||||
@@ -249,8 +202,8 @@ fn map_color_write_flags(flags: ColorWrite) -> hal::pso::ColorMask {
|
||||
}
|
||||
|
||||
fn map_blend_descriptor(blend_desc: &BlendDescriptor) -> hal::pso::BlendOp {
|
||||
use wgt::BlendOperation as Bo;
|
||||
use hal::pso::BlendOp as H;
|
||||
use wgt::BlendOperation as Bo;
|
||||
match blend_desc.operation {
|
||||
Bo::Add => H::Add {
|
||||
src: map_blend_factor(blend_desc.src_factor),
|
||||
@@ -270,8 +223,8 @@ fn map_blend_descriptor(blend_desc: &BlendDescriptor) -> hal::pso::BlendOp {
|
||||
}
|
||||
|
||||
fn map_blend_factor(blend_factor: BlendFactor) -> hal::pso::Factor {
|
||||
use wgt::BlendFactor as Bf;
|
||||
use hal::pso::Factor as H;
|
||||
use wgt::BlendFactor as Bf;
|
||||
match blend_factor {
|
||||
Bf::Zero => H::Zero,
|
||||
Bf::One => H::One,
|
||||
@@ -293,11 +246,10 @@ pub fn map_depth_stencil_state_descriptor(
|
||||
desc: &DepthStencilStateDescriptor,
|
||||
) -> hal::pso::DepthStencilDesc {
|
||||
hal::pso::DepthStencilDesc {
|
||||
depth: if desc.depth_write_enabled
|
||||
|| desc.depth_compare != CompareFunction::Always
|
||||
{
|
||||
depth: if desc.depth_write_enabled || desc.depth_compare != CompareFunction::Always {
|
||||
Some(hal::pso::DepthTest {
|
||||
fun: map_compare_function(desc.depth_compare).expect("DepthStencilStateDescriptor has undefined compare function"),
|
||||
fun: map_compare_function(desc.depth_compare)
|
||||
.expect("DepthStencilStateDescriptor has undefined compare function"),
|
||||
write: desc.depth_write_enabled,
|
||||
})
|
||||
} else {
|
||||
@@ -328,11 +280,10 @@ pub fn map_depth_stencil_state_descriptor(
|
||||
}
|
||||
}
|
||||
|
||||
fn map_stencil_face(
|
||||
stencil_state_face_desc: &StencilStateFaceDescriptor,
|
||||
) -> hal::pso::StencilFace {
|
||||
fn map_stencil_face(stencil_state_face_desc: &StencilStateFaceDescriptor) -> hal::pso::StencilFace {
|
||||
hal::pso::StencilFace {
|
||||
fun: map_compare_function(stencil_state_face_desc.compare).expect("StencilStateFaceDescriptor has undefined compare function"),
|
||||
fun: map_compare_function(stencil_state_face_desc.compare)
|
||||
.expect("StencilStateFaceDescriptor has undefined compare function"),
|
||||
op_fail: map_stencil_operation(stencil_state_face_desc.fail_op),
|
||||
op_depth_fail: map_stencil_operation(stencil_state_face_desc.depth_fail_op),
|
||||
op_pass: map_stencil_operation(stencil_state_face_desc.pass_op),
|
||||
@@ -340,8 +291,8 @@ fn map_stencil_face(
|
||||
}
|
||||
|
||||
pub fn map_compare_function(compare_function: CompareFunction) -> Option<hal::pso::Comparison> {
|
||||
use wgt::CompareFunction as Cf;
|
||||
use hal::pso::Comparison as H;
|
||||
use wgt::CompareFunction as Cf;
|
||||
match compare_function {
|
||||
Cf::Undefined => None,
|
||||
Cf::Never => Some(H::Never),
|
||||
@@ -356,8 +307,8 @@ pub fn map_compare_function(compare_function: CompareFunction) -> Option<hal::ps
|
||||
}
|
||||
|
||||
fn map_stencil_operation(stencil_operation: StencilOperation) -> hal::pso::StencilOp {
|
||||
use wgt::StencilOperation as So;
|
||||
use hal::pso::StencilOp as H;
|
||||
use wgt::StencilOperation as So;
|
||||
match stencil_operation {
|
||||
So::Keep => H::Keep,
|
||||
So::Zero => H::Zero,
|
||||
@@ -374,8 +325,8 @@ pub(crate) fn map_texture_format(
|
||||
texture_format: TextureFormat,
|
||||
features: Features,
|
||||
) -> hal::format::Format {
|
||||
use wgt::TextureFormat as Tf;
|
||||
use hal::format::Format as H;
|
||||
use wgt::TextureFormat as Tf;
|
||||
match texture_format {
|
||||
// Normal 8 bit formats
|
||||
Tf::R8Unorm => H::R8Unorm,
|
||||
@@ -444,8 +395,8 @@ pub(crate) fn map_texture_format(
|
||||
}
|
||||
|
||||
pub fn map_vertex_format(vertex_format: VertexFormat) -> hal::format::Format {
|
||||
use wgt::VertexFormat as Vf;
|
||||
use hal::format::Format as H;
|
||||
use wgt::VertexFormat as Vf;
|
||||
match vertex_format {
|
||||
Vf::Uchar2 => H::Rg8Uint,
|
||||
Vf::Uchar4 => H::Rgba8Uint,
|
||||
@@ -495,8 +446,8 @@ pub fn map_texture_dimension_size(
|
||||
array_size: u32,
|
||||
sample_size: u32,
|
||||
) -> hal::image::Kind {
|
||||
use wgt::TextureDimension::*;
|
||||
use hal::image::Kind as H;
|
||||
use wgt::TextureDimension::*;
|
||||
match dimension {
|
||||
D1 => {
|
||||
assert_eq!(height, 1);
|
||||
@@ -531,11 +482,9 @@ pub fn map_texture_dimension_size(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_texture_view_dimension(
|
||||
dimension: wgt::TextureViewDimension,
|
||||
) -> hal::image::ViewKind {
|
||||
use wgt::TextureViewDimension::*;
|
||||
pub fn map_texture_view_dimension(dimension: wgt::TextureViewDimension) -> hal::image::ViewKind {
|
||||
use hal::image::ViewKind as H;
|
||||
use wgt::TextureViewDimension::*;
|
||||
match dimension {
|
||||
D1 => H::D1,
|
||||
D2 => H::D2,
|
||||
@@ -547,8 +496,8 @@ pub fn map_texture_view_dimension(
|
||||
}
|
||||
|
||||
pub fn map_buffer_state(usage: wgt::BufferUsage) -> hal::buffer::State {
|
||||
use wgt::BufferUsage as W;
|
||||
use hal::buffer::Access as A;
|
||||
use wgt::BufferUsage as W;
|
||||
|
||||
let mut access = A::empty();
|
||||
if usage.contains(W::COPY_SRC) {
|
||||
@@ -580,8 +529,8 @@ pub fn map_texture_state(
|
||||
usage: wgt::TextureUsage,
|
||||
aspects: hal::format::Aspects,
|
||||
) -> hal::image::State {
|
||||
use wgt::TextureUsage as W;
|
||||
use hal::image::{Access as A, Layout as L};
|
||||
use wgt::TextureUsage as W;
|
||||
|
||||
let is_color = aspects.contains(hal::format::Aspects::COLOR);
|
||||
let layout = match usage {
|
||||
@@ -619,10 +568,7 @@ pub fn map_texture_state(
|
||||
(access, layout)
|
||||
}
|
||||
|
||||
pub fn map_load_store_ops(
|
||||
load: wgt::LoadOp,
|
||||
store: wgt::StoreOp,
|
||||
) -> hal::pass::AttachmentOps {
|
||||
pub fn map_load_store_ops(load: wgt::LoadOp, store: wgt::StoreOp) -> hal::pass::AttachmentOps {
|
||||
hal::pass::AttachmentOps {
|
||||
load: match load {
|
||||
wgt::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
||||
@@ -668,8 +614,8 @@ pub fn map_filter(filter: wgt::FilterMode) -> hal::image::Filter {
|
||||
}
|
||||
|
||||
pub fn map_wrap(address: wgt::AddressMode) -> hal::image::WrapMode {
|
||||
use wgt::AddressMode as Am;
|
||||
use hal::image::WrapMode as W;
|
||||
use wgt::AddressMode as Am;
|
||||
match address {
|
||||
Am::ClampToEdge => W::Clamp,
|
||||
Am::Repeat => W::Tile,
|
||||
|
||||
@@ -4,25 +4,18 @@
|
||||
|
||||
use crate::{
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id,
|
||||
resource,
|
||||
id, resource,
|
||||
track::TrackerSet,
|
||||
FastHashMap,
|
||||
Stored,
|
||||
RefCount,
|
||||
SubmissionIndex,
|
||||
FastHashMap, RefCount, Stored, SubmissionIndex,
|
||||
};
|
||||
|
||||
use copyless::VecHelper as _;
|
||||
use hal::device::Device as _;
|
||||
use parking_lot::Mutex;
|
||||
use gfx_descriptor::{DescriptorAllocator, DescriptorSet};
|
||||
use gfx_memory::{Heaps, MemoryBlock};
|
||||
use hal::device::Device as _;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use std::{
|
||||
sync::atomic::Ordering,
|
||||
};
|
||||
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
const CLEANUP_WAIT_MS: u64 = 5000;
|
||||
|
||||
@@ -55,8 +48,10 @@ impl SuspectedResources {
|
||||
self.texture_views.extend_from_slice(&other.texture_views);
|
||||
self.samplers.extend_from_slice(&other.samplers);
|
||||
self.bind_groups.extend_from_slice(&other.bind_groups);
|
||||
self.compute_pipelines.extend_from_slice(&other.compute_pipelines);
|
||||
self.render_pipelines.extend_from_slice(&other.render_pipelines);
|
||||
self.compute_pipelines
|
||||
.extend_from_slice(&other.compute_pipelines);
|
||||
self.render_pipelines
|
||||
.extend_from_slice(&other.render_pipelines);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,14 +192,12 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
new_suspects: &SuspectedResources,
|
||||
) {
|
||||
self.suspected_resources.extend(new_suspects);
|
||||
self.active
|
||||
.alloc()
|
||||
.init(ActiveSubmission {
|
||||
index,
|
||||
fence,
|
||||
last_resources: NonReferencedResources::new(),
|
||||
mapped: Vec::new(),
|
||||
});
|
||||
self.active.alloc().init(ActiveSubmission {
|
||||
index,
|
||||
fence,
|
||||
last_resources: NonReferencedResources::new(),
|
||||
mapped: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn map(&mut self, buffer: id::BufferId, ref_count: RefCount) {
|
||||
@@ -238,11 +231,7 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
}
|
||||
|
||||
/// Returns the last submission index that is done.
|
||||
pub fn triage_submissions(
|
||||
&mut self,
|
||||
device: &B::Device,
|
||||
force_wait: bool,
|
||||
) -> SubmissionIndex {
|
||||
pub fn triage_submissions(&mut self, device: &B::Device, force_wait: bool) -> SubmissionIndex {
|
||||
if force_wait {
|
||||
self.wait_idle(device);
|
||||
}
|
||||
@@ -259,7 +248,7 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
return 0;
|
||||
};
|
||||
|
||||
for a in self.active.drain(.. done_count) {
|
||||
for a in self.active.drain(..done_count) {
|
||||
log::trace!("Active submission {} is done", a.index);
|
||||
self.free_resources.extend(a.last_resources);
|
||||
self.ready_to_map.extend(a.mapped);
|
||||
@@ -278,14 +267,9 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
descriptor_allocator_mutex: &Mutex<DescriptorAllocator<B>>,
|
||||
) {
|
||||
unsafe {
|
||||
self.free_resources.clean(
|
||||
device,
|
||||
heaps_mutex,
|
||||
descriptor_allocator_mutex,
|
||||
);
|
||||
descriptor_allocator_mutex
|
||||
.lock()
|
||||
.cleanup(device);
|
||||
self.free_resources
|
||||
.clean(device, heaps_mutex, descriptor_allocator_mutex);
|
||||
descriptor_allocator_mutex.lock().cleanup(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,17 +293,26 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
assert!(res.used.bind_groups.is_empty());
|
||||
self.suspected_resources.buffers.extend(res.used.buffers.used());
|
||||
self.suspected_resources.textures.extend(res.used.textures.used());
|
||||
self.suspected_resources.texture_views.extend(res.used.views.used());
|
||||
self.suspected_resources.samplers.extend(res.used.samplers.used());
|
||||
self.suspected_resources
|
||||
.buffers
|
||||
.extend(res.used.buffers.used());
|
||||
self.suspected_resources
|
||||
.textures
|
||||
.extend(res.used.textures.used());
|
||||
self.suspected_resources
|
||||
.texture_views
|
||||
.extend(res.used.views.used());
|
||||
self.suspected_resources
|
||||
.samplers
|
||||
.extend(res.used.samplers.used());
|
||||
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
self.active
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.desc_sets.push(res.raw);
|
||||
.desc_sets
|
||||
.push(res.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,7 +339,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.image_views.push((id, raw));
|
||||
.image_views
|
||||
.push((id, raw));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,7 +359,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.images.push((res.raw, res.memory));
|
||||
.images
|
||||
.push((res.raw, res.memory));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,7 +379,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.samplers.push(res.raw);
|
||||
.samplers
|
||||
.push(res.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,7 +400,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.buffers.push((res.raw, res.memory));
|
||||
.buffers
|
||||
.push((res.raw, res.memory));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,7 +420,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.compute_pipes.push(res.raw);
|
||||
.compute_pipes
|
||||
.push(res.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,7 +440,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.graphics_pipes.push(res.raw);
|
||||
.graphics_pipes
|
||||
.push(res.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -517,7 +516,9 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
// Between all attachments, we need the smallest index, because that's the last
|
||||
// time this framebuffer is still valid
|
||||
if let Some(attachment_last_submit) = attachment_last_submit {
|
||||
let min = last_submit.unwrap_or(std::usize::MAX).min(attachment_last_submit);
|
||||
let min = last_submit
|
||||
.unwrap_or(std::usize::MAX)
|
||||
.min(attachment_last_submit);
|
||||
last_submit = Some(min);
|
||||
}
|
||||
}
|
||||
@@ -537,7 +538,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
.iter_mut()
|
||||
.find(|a| a.index == submit_index)
|
||||
.map_or(&mut self.free_resources, |a| &mut a.last_resources)
|
||||
.framebuffers.push(framebuffer);
|
||||
.framebuffers
|
||||
.push(framebuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,18 +555,25 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
}
|
||||
let hub = B::hub(global);
|
||||
let (mut buffer_guard, _) = B::hub(global).buffers.write(token);
|
||||
let mut pending_callbacks: Vec<super::BufferMapPendingCallback> = Vec::with_capacity(self.ready_to_map.len());
|
||||
let mut pending_callbacks: Vec<super::BufferMapPendingCallback> =
|
||||
Vec::with_capacity(self.ready_to_map.len());
|
||||
let mut trackers = trackers.lock();
|
||||
for buffer_id in self.ready_to_map.drain(..) {
|
||||
let buffer = &mut buffer_guard[buffer_id];
|
||||
if buffer.life_guard.ref_count.is_none() && trackers.buffers.remove_abandoned(buffer_id) {
|
||||
if buffer.life_guard.ref_count.is_none() && trackers.buffers.remove_abandoned(buffer_id)
|
||||
{
|
||||
buffer.map_state = resource::BufferMapState::Idle;
|
||||
log::debug!("Mapping request is dropped because the buffer is destroyed.");
|
||||
hub.buffers.free_id(buffer_id);
|
||||
let buffer = buffer_guard.remove(buffer_id).unwrap();
|
||||
self.free_resources.buffers.push((buffer.raw, buffer.memory));
|
||||
self.free_resources
|
||||
.buffers
|
||||
.push((buffer.raw, buffer.memory));
|
||||
} else {
|
||||
let mapping = match std::mem::replace(&mut buffer.map_state, resource::BufferMapState::Active) {
|
||||
let mapping = match std::mem::replace(
|
||||
&mut buffer.map_state,
|
||||
resource::BufferMapState::Active,
|
||||
) {
|
||||
resource::BufferMapState::Waiting(pending_mapping) => pending_mapping,
|
||||
_ => panic!("No pending mapping."),
|
||||
};
|
||||
|
||||
+191
-182
File diff suppressed because it is too large
Load Diff
+26
-44
@@ -8,40 +8,25 @@ use crate::{
|
||||
command::CommandBuffer,
|
||||
device::Device,
|
||||
id::{
|
||||
AdapterId,
|
||||
BindGroupId,
|
||||
BindGroupLayoutId,
|
||||
BufferId,
|
||||
CommandBufferId,
|
||||
ComputePipelineId,
|
||||
DeviceId,
|
||||
PipelineLayoutId,
|
||||
RenderPipelineId,
|
||||
SamplerId,
|
||||
ShaderModuleId,
|
||||
SurfaceId,
|
||||
SwapChainId,
|
||||
TextureId,
|
||||
TextureViewId,
|
||||
TypedId,
|
||||
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePipelineId,
|
||||
DeviceId, PipelineLayoutId, RenderPipelineId, SamplerId, ShaderModuleId, SurfaceId,
|
||||
SwapChainId, TextureId, TextureViewId, TypedId,
|
||||
},
|
||||
instance::{Adapter, Instance, Surface},
|
||||
pipeline::{ComputePipeline, RenderPipeline, ShaderModule},
|
||||
resource::{Buffer, Sampler, Texture, TextureView},
|
||||
swap_chain::SwapChain,
|
||||
Epoch,
|
||||
Index,
|
||||
Epoch, Index,
|
||||
};
|
||||
|
||||
use wgt::Backend;
|
||||
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use vec_map::VecMap;
|
||||
use wgt::Backend;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use std::cell::Cell;
|
||||
use std::{fmt::Debug, iter, marker::PhantomData, ops};
|
||||
|
||||
|
||||
/// A simple structure to manage identities of objects.
|
||||
#[derive(Debug)]
|
||||
pub struct IdentityManager {
|
||||
@@ -136,11 +121,9 @@ impl<T, I: TypedId> Storage<T, I> {
|
||||
}
|
||||
|
||||
pub fn iter(&self, backend: Backend) -> impl Iterator<Item = (I, &T)> {
|
||||
self.map
|
||||
.iter()
|
||||
.map(move |(index, (value, storage_epoch))| {
|
||||
(I::zip(index as Index, *storage_epoch, backend), value)
|
||||
})
|
||||
self.map.iter().map(move |(index, (value, storage_epoch))| {
|
||||
(I::zip(index as Index, *storage_epoch, backend), value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +235,6 @@ impl<'a, T> Drop for Token<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait IdentityHandler<I>: Debug {
|
||||
type Input: Clone + Debug;
|
||||
fn process(&self, id: Self::Input, backend: Backend) -> I;
|
||||
@@ -281,35 +263,35 @@ impl<I: TypedId + Debug> IdentityHandlerFactory<I> for IdentityManagerFactory {
|
||||
type Filter = Mutex<IdentityManager>;
|
||||
fn spawn(&self, min_index: Index) -> Self::Filter {
|
||||
let mut man = IdentityManager::default();
|
||||
man.free.extend(0 .. min_index);
|
||||
man.free.extend(0..min_index);
|
||||
man.epochs.extend(iter::repeat(1).take(min_index as usize));
|
||||
Mutex::new(man)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GlobalIdentityHandlerFactory:
|
||||
IdentityHandlerFactory<AdapterId> +
|
||||
IdentityHandlerFactory<DeviceId> +
|
||||
IdentityHandlerFactory<SwapChainId> +
|
||||
IdentityHandlerFactory<PipelineLayoutId> +
|
||||
IdentityHandlerFactory<ShaderModuleId> +
|
||||
IdentityHandlerFactory<BindGroupLayoutId> +
|
||||
IdentityHandlerFactory<BindGroupId> +
|
||||
IdentityHandlerFactory<CommandBufferId> +
|
||||
IdentityHandlerFactory<RenderPipelineId> +
|
||||
IdentityHandlerFactory<ComputePipelineId> +
|
||||
IdentityHandlerFactory<BufferId> +
|
||||
IdentityHandlerFactory<TextureId> +
|
||||
IdentityHandlerFactory<TextureViewId> +
|
||||
IdentityHandlerFactory<SamplerId> +
|
||||
IdentityHandlerFactory<SurfaceId>
|
||||
{}
|
||||
IdentityHandlerFactory<AdapterId>
|
||||
+ IdentityHandlerFactory<DeviceId>
|
||||
+ IdentityHandlerFactory<SwapChainId>
|
||||
+ IdentityHandlerFactory<PipelineLayoutId>
|
||||
+ IdentityHandlerFactory<ShaderModuleId>
|
||||
+ IdentityHandlerFactory<BindGroupLayoutId>
|
||||
+ IdentityHandlerFactory<BindGroupId>
|
||||
+ IdentityHandlerFactory<CommandBufferId>
|
||||
+ IdentityHandlerFactory<RenderPipelineId>
|
||||
+ IdentityHandlerFactory<ComputePipelineId>
|
||||
+ IdentityHandlerFactory<BufferId>
|
||||
+ IdentityHandlerFactory<TextureId>
|
||||
+ IdentityHandlerFactory<TextureViewId>
|
||||
+ IdentityHandlerFactory<SamplerId>
|
||||
+ IdentityHandlerFactory<SurfaceId>
|
||||
{
|
||||
}
|
||||
|
||||
impl GlobalIdentityHandlerFactory for IdentityManagerFactory {}
|
||||
|
||||
pub type Input<G, I> = <<G as IdentityHandlerFactory<I>>::Filter as IdentityHandler<I>>::Input;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Registry<T, I: TypedId, F: IdentityHandlerFactory<I>> {
|
||||
identity: F::Filter,
|
||||
|
||||
+7
-4
@@ -5,15 +5,19 @@
|
||||
use crate::{Epoch, Index};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde_crate::{Deserialize, Serialize};
|
||||
use wgt::Backend;
|
||||
use std::{fmt, marker::PhantomData, mem, num::NonZeroU64};
|
||||
use wgt::Backend;
|
||||
|
||||
const BACKEND_BITS: usize = 3;
|
||||
const EPOCH_MASK: u32 = (1 << (32 - BACKEND_BITS)) - 1;
|
||||
type Dummy = crate::backend::Empty;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct Id<T>(NonZeroU64, PhantomData<T>);
|
||||
|
||||
// required for PeekPoke
|
||||
@@ -75,7 +79,7 @@ impl<T> Eq for Id<T> {}
|
||||
|
||||
unsafe impl<T> peek_poke::Poke for Id<T> {
|
||||
fn max_size() -> usize {
|
||||
mem::size_of::<u64>()
|
||||
mem::size_of::<u64>()
|
||||
}
|
||||
unsafe fn poke_into(&self, data: *mut u8) -> *mut u8 {
|
||||
self.0.get().poke_into(data)
|
||||
@@ -112,7 +116,6 @@ impl<T> TypedId for Id<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub type AdapterId = Id<crate::instance::Adapter<Dummy>>;
|
||||
pub type SurfaceId = Id<crate::instance::Surface>;
|
||||
// Device
|
||||
|
||||
+50
-32
@@ -17,20 +17,19 @@ use serde_crate::{Deserialize, Serialize};
|
||||
|
||||
use hal::{
|
||||
self,
|
||||
adapter::{
|
||||
AdapterInfo as HalAdapterInfo,
|
||||
DeviceType as HalDeviceType,
|
||||
PhysicalDevice as _,
|
||||
},
|
||||
adapter::{AdapterInfo as HalAdapterInfo, DeviceType as HalDeviceType, PhysicalDevice as _},
|
||||
queue::QueueFamily as _,
|
||||
window::Surface as _,
|
||||
Instance as _,
|
||||
};
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct RequestAdapterOptions {
|
||||
pub power_preference: PowerPreference,
|
||||
pub compatible_surface: Option<SurfaceId>,
|
||||
@@ -125,7 +124,11 @@ pub struct Adapter<B: hal::Backend> {
|
||||
|
||||
/// Metadata about a backend adapter.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub struct AdapterInfo {
|
||||
/// Adapter name
|
||||
pub name: String,
|
||||
@@ -160,7 +163,11 @@ impl AdapterInfo {
|
||||
|
||||
/// Supported physical device types
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(Serialize, Deserialize),
|
||||
serde(crate = "serde_crate")
|
||||
)]
|
||||
pub enum DeviceType {
|
||||
/// Other
|
||||
Other,
|
||||
@@ -300,13 +307,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut adapters_vk = match instance.vulkan {
|
||||
Some(ref inst) if id_vulkan.is_some() => {
|
||||
let mut adapters = inst.enumerate_adapters();
|
||||
if let Some(&Surface { vulkan: Some(ref surface), .. }) = compatible_surface {
|
||||
adapters.retain(|a|
|
||||
if let Some(&Surface {
|
||||
vulkan: Some(ref surface),
|
||||
..
|
||||
}) = compatible_surface
|
||||
{
|
||||
adapters.retain(|a| {
|
||||
a.queue_families
|
||||
.iter()
|
||||
.find(|qf| qf.queue_type().supports_graphics())
|
||||
.map_or(false, |qf| surface.supports_queue_family(qf))
|
||||
);
|
||||
});
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type.clone()));
|
||||
adapters
|
||||
@@ -317,12 +328,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut adapters_mtl = if id_metal.is_some() {
|
||||
let mut adapters = instance.metal.enumerate_adapters();
|
||||
if let Some(surface) = compatible_surface {
|
||||
adapters.retain(|a|
|
||||
adapters.retain(|a| {
|
||||
a.queue_families
|
||||
.iter()
|
||||
.find(|qf| qf.queue_type().supports_graphics())
|
||||
.map_or(false, |qf| surface.metal.supports_queue_family(qf))
|
||||
);
|
||||
});
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type.clone()));
|
||||
adapters
|
||||
@@ -333,13 +344,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut adapters_dx12 = match instance.dx12 {
|
||||
Some(ref inst) if id_dx12.is_some() => {
|
||||
let mut adapters = inst.enumerate_adapters();
|
||||
if let Some(&Surface { dx12: Some(ref surface), .. }) = compatible_surface {
|
||||
adapters.retain(|a|
|
||||
if let Some(&Surface {
|
||||
dx12: Some(ref surface),
|
||||
..
|
||||
}) = compatible_surface
|
||||
{
|
||||
adapters.retain(|a| {
|
||||
a.queue_families
|
||||
.iter()
|
||||
.find(|qf| qf.queue_type().supports_graphics())
|
||||
.map_or(false, |qf| surface.supports_queue_family(qf))
|
||||
);
|
||||
});
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type.clone()));
|
||||
adapters
|
||||
@@ -350,12 +365,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut adapters_dx11 = if id_dx11.is_some() {
|
||||
let mut adapters = instance.dx11.enumerate_adapters();
|
||||
if let Some(surface) = compatible_surface {
|
||||
adapters.retain(|a|
|
||||
adapters.retain(|a| {
|
||||
a.queue_families
|
||||
.iter()
|
||||
.find(|qf| qf.queue_type().supports_graphics())
|
||||
.map_or(false, |qf| surface.dx11.supports_queue_family(qf))
|
||||
);
|
||||
});
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type.clone()));
|
||||
adapters
|
||||
@@ -388,14 +403,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
|
||||
let preferred_gpu = match desc.power_preference {
|
||||
PowerPreference::Default => {
|
||||
match power::is_battery_discharging() {
|
||||
Ok(false) => discrete.or(integrated).or(other).or(virt),
|
||||
Ok(true) => integrated.or(discrete).or(other).or(virt),
|
||||
Err(err) => {
|
||||
log::debug!("Power info unavailable, preferring integrated gpu ({})", err);
|
||||
integrated.or(discrete).or(other).or(virt)
|
||||
}
|
||||
PowerPreference::Default => match power::is_battery_discharging() {
|
||||
Ok(false) => discrete.or(integrated).or(other).or(virt),
|
||||
Ok(true) => integrated.or(discrete).or(other).or(virt),
|
||||
Err(err) => {
|
||||
log::debug!(
|
||||
"Power info unavailable, preferring integrated gpu ({})",
|
||||
err
|
||||
);
|
||||
integrated.or(discrete).or(other).or(virt)
|
||||
}
|
||||
},
|
||||
PowerPreference::LowPower => integrated.or(other).or(discrete).or(virt),
|
||||
@@ -500,13 +516,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let device = {
|
||||
let (adapter_guard, _) = hub.adapters.read(&mut token);
|
||||
let adapter = &adapter_guard[adapter_id].raw;
|
||||
let wishful_features =
|
||||
hal::Features::VERTEX_STORES_AND_ATOMICS |
|
||||
hal::Features::FRAGMENT_STORES_AND_ATOMICS |
|
||||
hal::Features::NDC_Y_UP;
|
||||
let wishful_features = hal::Features::VERTEX_STORES_AND_ATOMICS
|
||||
| hal::Features::FRAGMENT_STORES_AND_ATOMICS
|
||||
| hal::Features::NDC_Y_UP;
|
||||
let enabled_features = adapter.physical_device.features() & wishful_features;
|
||||
if enabled_features != wishful_features {
|
||||
log::warn!("Missing features: {:?}", wishful_features - enabled_features);
|
||||
log::warn!(
|
||||
"Missing features: {:?}",
|
||||
wishful_features - enabled_features
|
||||
);
|
||||
}
|
||||
|
||||
let family = adapter
|
||||
|
||||
@@ -103,8 +103,7 @@ impl LifeGuard {
|
||||
|
||||
/// Returns `true` if the resource is still needed by the user.
|
||||
fn use_at(&self, submit_index: SubmissionIndex) -> bool {
|
||||
self.submission_index
|
||||
.store(submit_index, Ordering::Release);
|
||||
self.submission_index.store(submit_index, Ordering::Release);
|
||||
self.ref_count.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
use crate::{
|
||||
device::RenderPassContext,
|
||||
id::{DeviceId, PipelineLayoutId, ShaderModuleId},
|
||||
LifeGuard,
|
||||
RawString,
|
||||
RefCount,
|
||||
Stored,
|
||||
U32Array
|
||||
LifeGuard, RawString, RefCount, Stored, U32Array,
|
||||
};
|
||||
use wgt::{BufferAddress, ColorStateDescriptor, DepthStencilStateDescriptor, IndexFormat, InputStepMode, PrimitiveTopology, RasterizationStateDescriptor, VertexAttributeDescriptor};
|
||||
use std::borrow::Borrow;
|
||||
use wgt::{
|
||||
BufferAddress, ColorStateDescriptor, DepthStencilStateDescriptor, IndexFormat, InputStepMode,
|
||||
PrimitiveTopology, RasterizationStateDescriptor, VertexAttributeDescriptor,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
@@ -40,7 +39,7 @@ pub struct ShaderModuleDescriptor {
|
||||
#[derive(Debug)]
|
||||
pub struct ShaderModule<B: hal::Backend> {
|
||||
pub(crate) raw: B::ShaderModule,
|
||||
pub(crate) device_id: Stored<DeviceId>
|
||||
pub(crate) device_id: Stored<DeviceId>,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
+20
-14
@@ -19,13 +19,16 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "battery", any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
)))]
|
||||
#[cfg(all(
|
||||
feature = "battery",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
)
|
||||
))]
|
||||
mod platform {
|
||||
use super::Error;
|
||||
use battery::{self, Manager, State};
|
||||
@@ -49,13 +52,16 @@ mod platform {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(feature = "battery"), not(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
))))]
|
||||
#[cfg(any(
|
||||
not(feature = "battery"),
|
||||
not(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "windows",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd"
|
||||
))
|
||||
))]
|
||||
mod platform {
|
||||
use super::Error;
|
||||
|
||||
|
||||
@@ -5,18 +5,11 @@
|
||||
use crate::{
|
||||
id::{DeviceId, SwapChainId, TextureId},
|
||||
track::DUMMY_SELECTOR,
|
||||
LifeGuard,
|
||||
RefCount,
|
||||
Stored,
|
||||
LifeGuard, RefCount, Stored,
|
||||
};
|
||||
|
||||
use wgt::{
|
||||
BufferAddress,
|
||||
BufferUsage,
|
||||
TextureFormat,
|
||||
TextureUsage,
|
||||
};
|
||||
use gfx_memory::MemoryBlock;
|
||||
use wgt::{BufferAddress, BufferUsage, TextureFormat, TextureUsage};
|
||||
|
||||
use std::{borrow::Borrow, fmt};
|
||||
|
||||
@@ -47,7 +40,7 @@ pub enum BufferMapOperation {
|
||||
Write {
|
||||
callback: crate::device::BufferMapWriteCallback,
|
||||
userdata: *mut u8,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
//TODO: clarify if/why this is needed here
|
||||
@@ -69,11 +62,15 @@ impl BufferMapOperation {
|
||||
match self {
|
||||
BufferMapOperation::Read { callback, userdata } => {
|
||||
log::error!("wgpu_buffer_map_read_async failed: buffer mapping is pending");
|
||||
unsafe { callback(BufferMapAsyncStatus::Error, std::ptr::null(), userdata); }
|
||||
unsafe {
|
||||
callback(BufferMapAsyncStatus::Error, std::ptr::null(), userdata);
|
||||
}
|
||||
}
|
||||
BufferMapOperation::Write { callback, userdata } => {
|
||||
log::error!("wgpu_buffer_map_write_async failed: buffer mapping is pending");
|
||||
unsafe { callback(BufferMapAsyncStatus::Error, std::ptr::null_mut(), userdata); }
|
||||
unsafe {
|
||||
callback(BufferMapAsyncStatus::Error, std::ptr::null_mut(), userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,11 @@ use crate::{
|
||||
conv,
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
id::{DeviceId, SwapChainId, TextureViewId},
|
||||
resource,
|
||||
Features,
|
||||
LifeGuard,
|
||||
Stored,
|
||||
resource, Features, LifeGuard, Stored,
|
||||
};
|
||||
|
||||
use wgt::SwapChainDescriptor;
|
||||
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
|
||||
|
||||
use wgt::SwapChainDescriptor;
|
||||
|
||||
const FRAME_TIMEOUT_MS: u64 = 1000;
|
||||
pub const DESIRED_NUM_FRAMES: u32 = 3;
|
||||
@@ -118,7 +114,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
|
||||
let desc = swap_chain_descriptor_to_hal(&sc.desc, sc.num_frames, device.features);
|
||||
let desc =
|
||||
swap_chain_descriptor_to_hal(&sc.desc, sc.num_frames, device.features);
|
||||
unsafe {
|
||||
suf.configure_swapchain(&device.raw, desc).unwrap();
|
||||
suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap()
|
||||
@@ -144,8 +141,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
samples: 1,
|
||||
range: hal::image::SubresourceRange {
|
||||
aspects: hal::format::Aspects::COLOR,
|
||||
layers: 0 .. 1,
|
||||
levels: 0 .. 1,
|
||||
layers: 0..1,
|
||||
levels: 0..1,
|
||||
},
|
||||
life_guard: LifeGuard::new(),
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ impl ResourceState for BufferState {
|
||||
let pending = PendingTransition {
|
||||
id,
|
||||
selector: (),
|
||||
usage: old .. usage,
|
||||
usage: old..usage,
|
||||
};
|
||||
self.last = match output {
|
||||
None => pending.collapse()?,
|
||||
@@ -92,7 +92,7 @@ impl ResourceState for BufferState {
|
||||
let pending = PendingTransition {
|
||||
id,
|
||||
selector: (),
|
||||
usage: old .. new,
|
||||
usage: old..new,
|
||||
};
|
||||
match output {
|
||||
None => pending.collapse()?,
|
||||
@@ -114,7 +114,7 @@ impl ResourceState for BufferState {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{id::TypedId};
|
||||
use crate::id::TypedId;
|
||||
|
||||
#[test]
|
||||
fn change() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user