mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 18:14:18 +01:00
Format code using 'cargo fmt'
This commit is contained in:
19 files changed
+311
-198
No files matched your search
@@ -1,23 +1,11 @@
|
||||
use super::CommandBuffer;
|
||||
use crate::{
|
||||
track::TrackerSet,
|
||||
DeviceId, LifeGuard, Stored, SubmissionIndex,
|
||||
};
|
||||
use crate::{track::TrackerSet, DeviceId, LifeGuard, Stored, SubmissionIndex};
|
||||
|
||||
use hal::{
|
||||
command::RawCommandBuffer,
|
||||
pool::RawCommandPool,
|
||||
Device,
|
||||
};
|
||||
use hal::{command::RawCommandBuffer, pool::RawCommandPool, Device};
|
||||
use log::trace;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::atomic::Ordering,
|
||||
thread,
|
||||
};
|
||||
|
||||
use std::{collections::HashMap, sync::atomic::Ordering, thread};
|
||||
|
||||
struct CommandPool<B: hal::Backend> {
|
||||
raw: B::CommandPool,
|
||||
@@ -112,7 +100,9 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
}
|
||||
|
||||
pub fn after_submit(&self, cmd_buf: CommandBuffer<B>, submit_index: SubmissionIndex) {
|
||||
cmd_buf.life_guard.submission_index
|
||||
cmd_buf
|
||||
.life_guard
|
||||
.submission_index
|
||||
.store(submit_index, Ordering::Release);
|
||||
self.inner.lock().pending.push(cmd_buf);
|
||||
}
|
||||
@@ -126,7 +116,11 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
.load(Ordering::Acquire);
|
||||
if index <= last_done {
|
||||
let cmd_buf = inner.pending.swap_remove(i);
|
||||
trace!("recycling comb submitted in {} when {} is done", index, last_done);
|
||||
trace!(
|
||||
"recycling comb submitted in {} when {} is done",
|
||||
index,
|
||||
last_done
|
||||
);
|
||||
inner.recycle(cmd_buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,9 @@ use log::trace;
|
||||
|
||||
use std::convert::identity;
|
||||
|
||||
|
||||
pub const MAX_BIND_GROUPS: usize = 4;
|
||||
type BindGroupMask = u8;
|
||||
|
||||
|
||||
pub struct BindGroupPair {
|
||||
layout_id: BindGroupLayoutId,
|
||||
group_id: Stored<BindGroupId>,
|
||||
@@ -28,7 +26,6 @@ pub enum Provision {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
struct TakeSome<I> {
|
||||
iter: I,
|
||||
}
|
||||
@@ -51,14 +48,17 @@ pub struct BindGroupEntry {
|
||||
impl BindGroupEntry {
|
||||
fn provide(&mut self, bind_group_id: BindGroupId, bind_group: &BindGroupHandle) -> Provision {
|
||||
let was_compatible = match self.provided {
|
||||
Some(BindGroupPair { layout_id, ref group_id }) => {
|
||||
Some(BindGroupPair {
|
||||
layout_id,
|
||||
ref group_id,
|
||||
}) => {
|
||||
if group_id.value == bind_group_id {
|
||||
assert_eq!(layout_id, bind_group.layout_id);
|
||||
return Provision::Unchanged;
|
||||
}
|
||||
self.expected_layout_id == Some(layout_id)
|
||||
}
|
||||
None => true
|
||||
None => true,
|
||||
};
|
||||
|
||||
self.provided = Some(BindGroupPair {
|
||||
@@ -75,10 +75,7 @@ impl BindGroupEntry {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_layout(
|
||||
&mut self,
|
||||
bind_group_layout_id: BindGroupLayoutId,
|
||||
) -> LayoutChange {
|
||||
pub fn expect_layout(&mut self, bind_group_layout_id: BindGroupLayoutId) -> LayoutChange {
|
||||
let some = Some(bind_group_layout_id);
|
||||
if self.expected_layout_id != some {
|
||||
self.expected_layout_id = some;
|
||||
@@ -103,14 +100,15 @@ impl BindGroupEntry {
|
||||
}
|
||||
|
||||
fn actual_value(&self) -> Option<BindGroupId> {
|
||||
self.expected_layout_id
|
||||
.and_then(|layout_id| self.provided.as_ref().and_then(|pair| {
|
||||
self.expected_layout_id.and_then(|layout_id| {
|
||||
self.provided.as_ref().and_then(|pair| {
|
||||
if pair.layout_id == layout_id {
|
||||
Some(pair.group_id.value)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +120,7 @@ pub struct Binder {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -140,15 +138,16 @@ impl Binder {
|
||||
) -> Option<(PipelineLayoutId, impl 'a + Iterator<Item = BindGroupId>)> {
|
||||
trace!("\tBinding [{}] = group {:?}", index, bind_group_id);
|
||||
match self.entries[index].provide(bind_group_id, bind_group) {
|
||||
Provision::Unchanged => {
|
||||
None
|
||||
}
|
||||
Provision::Changed { now_compatible: false, .. } => {
|
||||
Provision::Unchanged => None,
|
||||
Provision::Changed {
|
||||
now_compatible: false,
|
||||
..
|
||||
} => {
|
||||
trace!("\t\tnot compatible");
|
||||
None
|
||||
}
|
||||
Provision::Changed { was_compatible, .. } => {
|
||||
if self.entries[.. index].iter().all(|entry| entry.is_valid()) {
|
||||
if self.entries[..index].iter().all(|entry| entry.is_valid()) {
|
||||
self.pipeline_layout_id.map(move |pipeline_layout_id| {
|
||||
let end = if was_compatible {
|
||||
trace!("\t\tgenerating follow-up sequence");
|
||||
@@ -156,11 +155,14 @@ impl Binder {
|
||||
} else {
|
||||
index + 1
|
||||
};
|
||||
(pipeline_layout_id, TakeSome {
|
||||
iter: self.entries[index + 1 .. end]
|
||||
.iter()
|
||||
.map(|entry| entry.actual_value()),
|
||||
})
|
||||
(
|
||||
pipeline_layout_id,
|
||||
TakeSome {
|
||||
iter: self.entries[index + 1..end]
|
||||
.iter()
|
||||
.map(|entry| entry.actual_value()),
|
||||
},
|
||||
)
|
||||
})
|
||||
} else {
|
||||
trace!("\t\tbehind an incompatible");
|
||||
|
||||
@@ -2,17 +2,18 @@ use crate::{
|
||||
command::bind::{Binder, LayoutChange},
|
||||
hub::HUB,
|
||||
track::{Stitch, TrackerSet},
|
||||
BindGroupId, CommandBuffer, CommandBufferId, ComputePassId, ComputePipelineId, Stored,
|
||||
BindGroupId,
|
||||
CommandBuffer,
|
||||
CommandBufferId,
|
||||
ComputePassId,
|
||||
ComputePipelineId,
|
||||
Stored,
|
||||
};
|
||||
|
||||
use hal::{
|
||||
self,
|
||||
command::RawCommandBuffer,
|
||||
};
|
||||
use hal::{self, command::RawCommandBuffer};
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
||||
pub struct ComputePass<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
cmb_id: Stored<CommandBufferId>,
|
||||
@@ -78,8 +79,8 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(
|
||||
.provide_entry(index as usize, bind_group_id, bind_group)
|
||||
{
|
||||
let pipeline_layout_guard = HUB.pipeline_layouts.read();
|
||||
let bind_groups = iter::once(&bind_group.raw)
|
||||
.chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw));
|
||||
let bind_groups =
|
||||
iter::once(&bind_group.raw).chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw));
|
||||
unsafe {
|
||||
pass.raw.bind_compute_descriptor_sets(
|
||||
&pipeline_layout_guard[pipeline_layout_id].raw,
|
||||
@@ -114,7 +115,8 @@ pub extern "C" fn wgpu_compute_pass_set_pipeline(
|
||||
let bind_group_guard = HUB.bind_groups.read();
|
||||
|
||||
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
|
||||
pass.binder.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
pass.binder
|
||||
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
|
||||
for (index, (entry, &bgl_id)) in pass
|
||||
.binder
|
||||
|
||||
@@ -12,32 +12,37 @@ pub use self::transfer::*;
|
||||
use crate::{
|
||||
conv,
|
||||
device::{
|
||||
all_buffer_stages, all_image_stages, FramebufferKey, RenderPassContext, RenderPassKey,
|
||||
all_buffer_stages,
|
||||
all_image_stages,
|
||||
FramebufferKey,
|
||||
RenderPassContext,
|
||||
RenderPassKey,
|
||||
},
|
||||
hub::{Storage, HUB},
|
||||
pipeline::IndexFormat,
|
||||
resource::TexturePlacement,
|
||||
swap_chain::{SwapChainLink, SwapImageEpoch},
|
||||
track::{DummyUsage, Stitch, TrackerSet},
|
||||
BufferHandle, Color, CommandBufferHandle, CommandBufferId, CommandEncoderId, DeviceId,
|
||||
LifeGuard, Stored, TextureHandle, TextureUsageFlags, TextureViewId,
|
||||
BufferHandle,
|
||||
Color,
|
||||
CommandBufferHandle,
|
||||
CommandBufferId,
|
||||
CommandEncoderId,
|
||||
DeviceId,
|
||||
LifeGuard,
|
||||
Stored,
|
||||
TextureHandle,
|
||||
TextureUsageFlags,
|
||||
TextureViewId,
|
||||
};
|
||||
#[cfg(feature = "local")]
|
||||
use crate::{ComputePassId, RenderPassId};
|
||||
|
||||
use back::Backend;
|
||||
use hal::{
|
||||
Device as _,
|
||||
command::RawCommandBuffer,
|
||||
};
|
||||
use hal::{command::RawCommandBuffer, Device as _};
|
||||
use log::trace;
|
||||
|
||||
use std::{
|
||||
iter, slice,
|
||||
collections::hash_map::Entry,
|
||||
thread::ThreadId,
|
||||
};
|
||||
|
||||
use std::{collections::hash_map::Entry, iter, slice, thread::ThreadId};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
|
||||
@@ -6,14 +6,20 @@ use crate::{
|
||||
pipeline::{IndexFormat, PipelineFlags},
|
||||
resource::BufferUsageFlags,
|
||||
track::{Stitch, TrackerSet},
|
||||
BindGroupId, BufferId, Color, CommandBuffer, CommandBufferId, RenderPassId, RenderPipelineId, Stored,
|
||||
BindGroupId,
|
||||
BufferId,
|
||||
Color,
|
||||
CommandBuffer,
|
||||
CommandBufferId,
|
||||
RenderPassId,
|
||||
RenderPipelineId,
|
||||
Stored,
|
||||
};
|
||||
|
||||
use hal::command::RawCommandBuffer;
|
||||
|
||||
use std::{iter, slice};
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum BlendColorStatus {
|
||||
Unused,
|
||||
@@ -75,7 +81,7 @@ impl<B: hal::Backend> RenderPass<B> {
|
||||
});
|
||||
}
|
||||
if self.blend_color_status == BlendColorStatus::Required {
|
||||
return Err(DrawError::MissingBlendColor)
|
||||
return Err(DrawError::MissingBlendColor);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -231,8 +237,8 @@ pub extern "C" fn wgpu_render_pass_set_bind_group(
|
||||
.provide_entry(index as usize, bind_group_id, bind_group)
|
||||
{
|
||||
let pipeline_layout_guard = HUB.pipeline_layouts.read();
|
||||
let bind_groups = iter::once(&bind_group.raw)
|
||||
.chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw));
|
||||
let bind_groups =
|
||||
iter::once(&bind_group.raw).chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw));
|
||||
unsafe {
|
||||
pass.raw.bind_graphics_descriptor_sets(
|
||||
&&pipeline_layout_guard[pipeline_layout_id].raw,
|
||||
@@ -259,7 +265,9 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
"The render pipeline is not compatible with the pass!"
|
||||
);
|
||||
|
||||
if pipeline.flags.contains(PipelineFlags::BLEND_COLOR) && pass.blend_color_status == BlendColorStatus::Unused {
|
||||
if pipeline.flags.contains(PipelineFlags::BLEND_COLOR)
|
||||
&& pass.blend_color_status == BlendColorStatus::Unused
|
||||
{
|
||||
pass.blend_color_status = BlendColorStatus::Required;
|
||||
}
|
||||
|
||||
@@ -276,7 +284,8 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
let bind_group_guard = HUB.bind_groups.read();
|
||||
|
||||
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
|
||||
pass.binder.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
pass.binder
|
||||
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
|
||||
|
||||
for (index, (entry, &bgl_id)) in pass
|
||||
.binder
|
||||
@@ -324,10 +333,7 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_render_pass_set_blend_color(
|
||||
pass_id: RenderPassId,
|
||||
color: &Color,
|
||||
) {
|
||||
pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color: &Color) {
|
||||
let mut pass_guard = HUB.render_passes.write();
|
||||
let pass = &mut pass_guard[pass_id];
|
||||
|
||||
|
||||
@@ -4,7 +4,13 @@ use crate::{
|
||||
hub::HUB,
|
||||
resource::TexturePlacement,
|
||||
swap_chain::SwapChainLink,
|
||||
BufferId, BufferUsageFlags, CommandBufferId, Extent3d, Origin3d, TextureId, TextureUsageFlags,
|
||||
BufferId,
|
||||
BufferUsageFlags,
|
||||
CommandBufferId,
|
||||
Extent3d,
|
||||
Origin3d,
|
||||
TextureId,
|
||||
TextureUsageFlags,
|
||||
};
|
||||
|
||||
use copyless::VecHelper as _;
|
||||
@@ -12,7 +18,6 @@ use hal::command::RawCommandBuffer;
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
||||
const BITS_PER_BYTE: u32 = 8;
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
Reference in new issue
Block a user