mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Add ReferenceType trait for command structures
Use it to deduplicate some `Foo` / `ArcFoo` / `TraceFoo` definitions.
This commit is contained in:
parent
c0cce5973c
commit
5798a443d2
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -2360,6 +2360,22 @@ version = "0.1.4+2024.11.22-df583a3.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e3cd67e8ea2ba061339150970542cf1c60ba44c6d17e31279cbc133a4b018f8"
|
checksum = "0e3cd67e8ea2ba061339150970542cf1c60ba44c6d17e31279cbc133a4b018f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "macro_rules_attribute"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "65049d7923698040cd0b1ddcced9b0eb14dd22c5f86ae59c3740eab64a676520"
|
||||||
|
dependencies = [
|
||||||
|
"macro_rules_attribute-proc_macro",
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "macro_rules_attribute-proc_macro"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "670fdfda89751bc4a84ac13eaa63e205cf0fd22b4c9a5fbfa085b63c1f1d3a30"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "malloc_buf"
|
name = "malloc_buf"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
@ -4817,6 +4833,7 @@ dependencies = [
|
|||||||
"hashbrown 0.16.0",
|
"hashbrown 0.16.0",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"log",
|
"log",
|
||||||
|
"macro_rules_attribute",
|
||||||
"naga",
|
"naga",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|||||||
@ -142,6 +142,7 @@ libloading = "0.8"
|
|||||||
libm = { version = "0.2.6", default-features = false }
|
libm = { version = "0.2.6", default-features = false }
|
||||||
libtest-mimic = "0.8"
|
libtest-mimic = "0.8"
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
|
macro_rules_attribute = "0.2"
|
||||||
nanoserde = "0.2"
|
nanoserde = "0.2"
|
||||||
nanorand = { version = "0.8", default-features = false, features = ["wyrand"] }
|
nanorand = { version = "0.8", default-features = false, features = ["wyrand"] }
|
||||||
noise = "0.9"
|
noise = "0.9"
|
||||||
|
|||||||
@ -7,7 +7,7 @@ fn main() {
|
|||||||
|
|
||||||
use player::GlobalPlay as _;
|
use player::GlobalPlay as _;
|
||||||
use wgc::device::trace;
|
use wgc::device::trace;
|
||||||
use wgpu_core::identity::IdentityManager;
|
use wgpu_core::{command::IdReferences, identity::IdentityManager};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
@ -52,7 +52,7 @@ fn main() {
|
|||||||
|
|
||||||
log::info!("Loading trace '{trace:?}'");
|
log::info!("Loading trace '{trace:?}'");
|
||||||
let file = fs::File::open(trace).unwrap();
|
let file = fs::File::open(trace).unwrap();
|
||||||
let mut actions: Vec<trace::Action> = ron::de::from_reader(file).unwrap();
|
let mut actions: Vec<trace::Action<IdReferences>> = ron::de::from_reader(file).unwrap();
|
||||||
actions.reverse(); // allows us to pop from the top
|
actions.reverse(); // allows us to pop from the top
|
||||||
log::info!("Found {} actions", actions.len());
|
log::info!("Found {} actions", actions.len());
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,11 @@
|
|||||||
extern crate wgpu_core as wgc;
|
extern crate wgpu_core as wgc;
|
||||||
extern crate wgpu_types as wgt;
|
extern crate wgpu_types as wgt;
|
||||||
|
|
||||||
use wgc::{command::Command, device::trace, identity::IdentityManager};
|
use wgc::{
|
||||||
|
command::{Command, IdReferences},
|
||||||
|
device::trace,
|
||||||
|
identity::IdentityManager,
|
||||||
|
};
|
||||||
|
|
||||||
use std::{borrow::Cow, fs, path::Path};
|
use std::{borrow::Cow, fs, path::Path};
|
||||||
|
|
||||||
@ -21,7 +25,7 @@ pub trait GlobalPlay {
|
|||||||
&self,
|
&self,
|
||||||
device: wgc::id::DeviceId,
|
device: wgc::id::DeviceId,
|
||||||
queue: wgc::id::QueueId,
|
queue: wgc::id::QueueId,
|
||||||
action: trace::Action,
|
action: trace::Action<IdReferences>,
|
||||||
dir: &Path,
|
dir: &Path,
|
||||||
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
||||||
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
||||||
@ -143,7 +147,7 @@ impl GlobalPlay for wgc::global::Global {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
wgc::ray_tracing::BlasBuildEntry {
|
wgc::ray_tracing::BlasBuildEntry {
|
||||||
blas_id: x.blas_id,
|
blas_id: x.blas,
|
||||||
geometries,
|
geometries,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -153,14 +157,14 @@ impl GlobalPlay for wgc::global::Global {
|
|||||||
instance
|
instance
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|instance| wgc::ray_tracing::TlasInstance {
|
.map(|instance| wgc::ray_tracing::TlasInstance {
|
||||||
blas_id: instance.blas_id,
|
blas_id: instance.blas,
|
||||||
transform: &instance.transform,
|
transform: &instance.transform,
|
||||||
custom_data: instance.custom_data,
|
custom_data: instance.custom_data,
|
||||||
mask: instance.mask,
|
mask: instance.mask,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
wgc::ray_tracing::TlasPackage {
|
wgc::ray_tracing::TlasPackage {
|
||||||
tlas_id: x.tlas_id,
|
tlas_id: x.tlas,
|
||||||
instances: Box::new(instances),
|
instances: Box::new(instances),
|
||||||
lowest_unmodified: x.lowest_unmodified,
|
lowest_unmodified: x.lowest_unmodified,
|
||||||
}
|
}
|
||||||
@ -188,7 +192,7 @@ impl GlobalPlay for wgc::global::Global {
|
|||||||
&self,
|
&self,
|
||||||
device: wgc::id::DeviceId,
|
device: wgc::id::DeviceId,
|
||||||
queue: wgc::id::QueueId,
|
queue: wgc::id::QueueId,
|
||||||
action: trace::Action,
|
action: trace::Action<IdReferences>,
|
||||||
dir: &Path,
|
dir: &Path,
|
||||||
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
||||||
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
||||||
|
|||||||
@ -20,7 +20,7 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
slice,
|
slice,
|
||||||
};
|
};
|
||||||
use wgc::identity::IdentityManager;
|
use wgc::{command::IdReferences, identity::IdentityManager};
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct RawId {
|
struct RawId {
|
||||||
@ -57,7 +57,7 @@ struct Expectation {
|
|||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
features: wgt::Features,
|
features: wgt::Features,
|
||||||
expectations: Vec<Expectation>,
|
expectations: Vec<Expectation>,
|
||||||
actions: Vec<wgc::device::trace::Action<'a>>,
|
actions: Vec<wgc::device::trace::Action<'a, IdReferences>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_callback(status: Result<(), wgc::resource::BufferAccessError>) {
|
fn map_callback(status: Result<(), wgc::resource::BufferAccessError>) {
|
||||||
|
|||||||
@ -178,6 +178,7 @@ document-features.workspace = true
|
|||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
indexmap.workspace = true
|
indexmap.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
macro_rules_attribute.workspace = true
|
||||||
once_cell = { workspace = true, features = ["std"] }
|
once_cell = { workspace = true, features = ["std"] }
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
profiling = { workspace = true, default-features = false }
|
profiling = { workspace = true, default-features = false }
|
||||||
|
|||||||
@ -1,12 +1,77 @@
|
|||||||
use core::convert::Infallible;
|
use core::convert::Infallible;
|
||||||
|
|
||||||
use alloc::{string::String, sync::Arc, vec::Vec};
|
use alloc::{string::String, sync::Arc, vec::Vec};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use macro_rules_attribute::attribute_alias;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
id,
|
id,
|
||||||
resource::{Buffer, QuerySet, Texture},
|
resource::{Buffer, QuerySet, Texture},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub trait ReferenceType {
|
||||||
|
type Buffer: Clone + core::fmt::Debug;
|
||||||
|
type Texture: Clone + core::fmt::Debug;
|
||||||
|
type TextureView: Clone + core::fmt::Debug;
|
||||||
|
type QuerySet: Clone + core::fmt::Debug;
|
||||||
|
type BindGroup: Clone + core::fmt::Debug;
|
||||||
|
type RenderPipeline: Clone + core::fmt::Debug;
|
||||||
|
type RenderBundle: Clone + core::fmt::Debug;
|
||||||
|
type ComputePipeline: Clone + core::fmt::Debug;
|
||||||
|
type Blas: Clone + core::fmt::Debug;
|
||||||
|
type Tlas: Clone + core::fmt::Debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct IdReferences;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ArcReferences;
|
||||||
|
|
||||||
|
impl ReferenceType for IdReferences {
|
||||||
|
type Buffer = id::BufferId;
|
||||||
|
type Texture = id::TextureId;
|
||||||
|
type TextureView = id::TextureViewId;
|
||||||
|
type QuerySet = id::QuerySetId;
|
||||||
|
type BindGroup = id::BindGroupId;
|
||||||
|
type RenderPipeline = id::RenderPipelineId;
|
||||||
|
type RenderBundle = id::RenderBundleId;
|
||||||
|
type ComputePipeline = id::ComputePipelineId;
|
||||||
|
type Blas = id::BlasId;
|
||||||
|
type Tlas = id::TlasId;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReferenceType for ArcReferences {
|
||||||
|
type Buffer = Arc<Buffer>;
|
||||||
|
type Texture = Arc<Texture>;
|
||||||
|
type TextureView = Arc<crate::resource::TextureView>;
|
||||||
|
type QuerySet = Arc<QuerySet>;
|
||||||
|
type BindGroup = Arc<crate::binding_model::BindGroup>;
|
||||||
|
type RenderPipeline = Arc<crate::pipeline::RenderPipeline>;
|
||||||
|
type RenderBundle = Arc<crate::command::RenderBundle>;
|
||||||
|
type ComputePipeline = Arc<crate::pipeline::ComputePipeline>;
|
||||||
|
type Blas = Arc<crate::resource::Blas>;
|
||||||
|
type Tlas = Arc<crate::resource::Tlas>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
attribute_alias! {
|
||||||
|
#[apply(serde_object_reference_struct)] =
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(bound =
|
||||||
|
"R::Buffer: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::Texture: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::TextureView: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::QuerySet: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::BindGroup: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::RenderPipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::RenderBundle: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::ComputePipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::Blas: serde::Serialize + for<'d> serde::Deserialize<'d>,\
|
||||||
|
R::Tlas: serde::Serialize + for<'d> serde::Deserialize<'d>"
|
||||||
|
)];
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
|||||||
@ -34,13 +34,15 @@ use core::mem::{self, ManuallyDrop};
|
|||||||
use core::ops;
|
use core::ops;
|
||||||
|
|
||||||
pub(crate) use self::clear::clear_texture;
|
pub(crate) use self::clear::clear_texture;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
pub(crate) use self::encoder_command::serde_object_reference_struct;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
bundle::*,
|
bundle::*,
|
||||||
clear::ClearError,
|
clear::ClearError,
|
||||||
compute::*,
|
compute::*,
|
||||||
compute_command::{ArcComputeCommand, ComputeCommand},
|
compute_command::{ArcComputeCommand, ComputeCommand},
|
||||||
draw::*,
|
draw::*,
|
||||||
encoder_command::{ArcCommand, Command},
|
encoder_command::{ArcCommand, ArcReferences, Command, IdReferences, ReferenceType},
|
||||||
query::*,
|
query::*,
|
||||||
render::*,
|
render::*,
|
||||||
render_command::{ArcRenderCommand, RenderCommand},
|
render_command::{ArcRenderCommand, RenderCommand},
|
||||||
|
|||||||
@ -8,32 +8,29 @@ use core::{
|
|||||||
use wgt::{math::align_to, BufferUsages, BufferUses, Features};
|
use wgt::{math::align_to, BufferUsages, BufferUses, Features};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
command::CommandBufferMutable,
|
command::encoder::EncodingState,
|
||||||
|
ray_tracing::{AsAction, AsBuild, BlasTriangleGeometryInfo, TlasBuild, ValidateAsActionsError},
|
||||||
|
resource::InvalidResourceError,
|
||||||
|
track::Tracker,
|
||||||
|
};
|
||||||
|
use crate::{command::EncoderStateError, device::resource::CommandIndices};
|
||||||
|
use crate::{
|
||||||
|
command::{ArcCommand, ArcReferences, CommandBufferMutable},
|
||||||
device::queue::TempResource,
|
device::queue::TempResource,
|
||||||
global::Global,
|
global::Global,
|
||||||
id::CommandEncoderId,
|
id::CommandEncoderId,
|
||||||
init_tracker::MemoryInitKind,
|
init_tracker::MemoryInitKind,
|
||||||
ray_tracing::{
|
ray_tracing::{
|
||||||
BlasBuildEntry, BlasGeometries, BuildAccelerationStructureError, TlasPackage,
|
ArcBlasBuildEntry, ArcBlasGeometries, ArcBlasTriangleGeometry, ArcTlasInstance,
|
||||||
TraceBlasBuildEntry, TraceBlasGeometries, TraceBlasTriangleGeometry, TraceTlasInstance,
|
ArcTlasPackage, BlasBuildEntry, BlasGeometries, BuildAccelerationStructureError,
|
||||||
TraceTlasPackage,
|
OwnedBlasBuildEntry, OwnedTlasPackage, TlasPackage, TraceBlasBuildEntry,
|
||||||
|
TraceBlasGeometries, TraceBlasTriangleGeometry, TraceTlasInstance, TraceTlasPackage,
|
||||||
},
|
},
|
||||||
resource::{Blas, BlasCompactState, Buffer, Labeled, StagingBuffer, Tlas},
|
resource::{Blas, BlasCompactState, Buffer, Labeled, StagingBuffer, Tlas},
|
||||||
scratch::ScratchBuffer,
|
scratch::ScratchBuffer,
|
||||||
snatch::SnatchGuard,
|
snatch::SnatchGuard,
|
||||||
track::PendingTransition,
|
track::PendingTransition,
|
||||||
};
|
};
|
||||||
use crate::{command::EncoderStateError, device::resource::CommandIndices};
|
|
||||||
use crate::{
|
|
||||||
command::{encoder::EncodingState, ArcCommand},
|
|
||||||
ray_tracing::{
|
|
||||||
ArcBlasBuildEntry, ArcBlasGeometries, ArcBlasTriangleGeometry, ArcTlasInstance,
|
|
||||||
ArcTlasPackage, AsAction, AsBuild, BlasTriangleGeometryInfo, TlasBuild,
|
|
||||||
ValidateAsActionsError,
|
|
||||||
},
|
|
||||||
resource::InvalidResourceError,
|
|
||||||
track::Tracker,
|
|
||||||
};
|
|
||||||
use crate::{lock::RwLockWriteGuard, resource::RawResourceAccess};
|
use crate::{lock::RwLockWriteGuard, resource::RawResourceAccess};
|
||||||
|
|
||||||
use crate::id::{BlasId, TlasId};
|
use crate::id::{BlasId, TlasId};
|
||||||
@ -147,7 +144,7 @@ impl Global {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
TraceBlasBuildEntry {
|
TraceBlasBuildEntry {
|
||||||
blas_id: blas_entry.blas_id,
|
blas: blas_entry.blas_id,
|
||||||
geometries,
|
geometries,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -159,7 +156,7 @@ impl Global {
|
|||||||
.instances
|
.instances
|
||||||
.map(|instance| {
|
.map(|instance| {
|
||||||
instance.map(|instance| TraceTlasInstance {
|
instance.map(|instance| TraceTlasInstance {
|
||||||
blas_id: instance.blas_id,
|
blas: instance.blas_id,
|
||||||
transform: *instance.transform,
|
transform: *instance.transform,
|
||||||
custom_data: instance.custom_data,
|
custom_data: instance.custom_data,
|
||||||
mask: instance.mask,
|
mask: instance.mask,
|
||||||
@ -167,7 +164,7 @@ impl Global {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
TraceTlasPackage {
|
TraceTlasPackage {
|
||||||
tlas_id: package.tlas_id,
|
tlas: package.tlas_id,
|
||||||
instances,
|
instances,
|
||||||
lowest_unmodified: package.lowest_unmodified,
|
lowest_unmodified: package.lowest_unmodified,
|
||||||
}
|
}
|
||||||
@ -215,7 +212,7 @@ impl Global {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(ArcBlasBuildEntry {
|
Ok(ArcBlasBuildEntry {
|
||||||
blas: self.resolve_blas_id(blas_entry.blas_id)?,
|
blas: self.resolve_blas_id(blas_entry.blas)?,
|
||||||
geometries,
|
geometries,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -232,7 +229,7 @@ impl Global {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|instance| {
|
.map(|instance| {
|
||||||
Ok(ArcTlasInstance {
|
Ok(ArcTlasInstance {
|
||||||
blas: self.resolve_blas_id(instance.blas_id)?,
|
blas: self.resolve_blas_id(instance.blas)?,
|
||||||
transform: instance.transform,
|
transform: instance.transform,
|
||||||
custom_data: instance.custom_data,
|
custom_data: instance.custom_data,
|
||||||
mask: instance.mask,
|
mask: instance.mask,
|
||||||
@ -242,7 +239,7 @@ impl Global {
|
|||||||
})
|
})
|
||||||
.collect::<Result<_, BuildAccelerationStructureError>>()?;
|
.collect::<Result<_, BuildAccelerationStructureError>>()?;
|
||||||
Ok(ArcTlasPackage {
|
Ok(ArcTlasPackage {
|
||||||
tlas: self.resolve_tlas_id(tlas_package.tlas_id)?,
|
tlas: self.resolve_tlas_id(tlas_package.tlas)?,
|
||||||
instances,
|
instances,
|
||||||
lowest_unmodified: tlas_package.lowest_unmodified,
|
lowest_unmodified: tlas_package.lowest_unmodified,
|
||||||
})
|
})
|
||||||
@ -256,8 +253,8 @@ impl Global {
|
|||||||
|
|
||||||
pub(crate) fn build_acceleration_structures(
|
pub(crate) fn build_acceleration_structures(
|
||||||
state: &mut EncodingState,
|
state: &mut EncodingState,
|
||||||
blas: Vec<ArcBlasBuildEntry>,
|
blas: Vec<OwnedBlasBuildEntry<ArcReferences>>,
|
||||||
tlas: Vec<ArcTlasPackage>,
|
tlas: Vec<OwnedTlasPackage<ArcReferences>>,
|
||||||
) -> Result<(), BuildAccelerationStructureError> {
|
) -> Result<(), BuildAccelerationStructureError> {
|
||||||
state
|
state
|
||||||
.device
|
.device
|
||||||
@ -282,7 +279,7 @@ pub(crate) fn build_acceleration_structures(
|
|||||||
&mut scratch_buffer_blas_size,
|
&mut scratch_buffer_blas_size,
|
||||||
&mut blas_storage,
|
&mut blas_storage,
|
||||||
)?;
|
)?;
|
||||||
let mut tlas_lock_store = Vec::<(Option<ArcTlasPackage>, Arc<Tlas>)>::new();
|
let mut tlas_lock_store = Vec::<(Option<OwnedTlasPackage<ArcReferences>>, Arc<Tlas>)>::new();
|
||||||
|
|
||||||
for package in tlas.into_iter() {
|
for package in tlas.into_iter() {
|
||||||
let tlas = package.tlas.clone();
|
let tlas = package.tlas.clone();
|
||||||
@ -615,7 +612,7 @@ impl CommandBufferMutable {
|
|||||||
|
|
||||||
///iterates over the blas iterator, and it's geometry, pushing the buffers into a storage vector (and also some validation).
|
///iterates over the blas iterator, and it's geometry, pushing the buffers into a storage vector (and also some validation).
|
||||||
fn iter_blas(
|
fn iter_blas(
|
||||||
blas_iter: impl Iterator<Item = ArcBlasBuildEntry>,
|
blas_iter: impl Iterator<Item = OwnedBlasBuildEntry<ArcReferences>>,
|
||||||
tracker: &mut Tracker,
|
tracker: &mut Tracker,
|
||||||
build_command: &mut AsBuild,
|
build_command: &mut AsBuild,
|
||||||
buf_storage: &mut Vec<TriangleBufferStore>,
|
buf_storage: &mut Vec<TriangleBufferStore>,
|
||||||
|
|||||||
@ -1,12 +1,17 @@
|
|||||||
use alloc::{string::String, vec::Vec};
|
|
||||||
use core::{convert::Infallible, ops::Range};
|
use core::{convert::Infallible, ops::Range};
|
||||||
|
|
||||||
|
use alloc::{string::String, vec::Vec};
|
||||||
|
use macro_rules_attribute::apply;
|
||||||
|
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
use {alloc::borrow::Cow, std::io::Write as _};
|
use {alloc::borrow::Cow, std::io::Write as _};
|
||||||
|
|
||||||
use crate::{command::Command, id};
|
#[cfg(feature = "trace")]
|
||||||
|
use crate::command::IdReferences;
|
||||||
//TODO: consider a readable Id that doesn't include the backend
|
use crate::{
|
||||||
|
command::{serde_object_reference_struct, BasePass, Command, ReferenceType, RenderCommand},
|
||||||
|
id,
|
||||||
|
};
|
||||||
|
|
||||||
type FileName = String;
|
type FileName = String;
|
||||||
|
|
||||||
@ -36,8 +41,8 @@ pub(crate) fn new_render_bundle_encoder_descriptor<'a>(
|
|||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[apply(serde_object_reference_struct)]
|
||||||
pub enum Action<'a> {
|
pub enum Action<'a, R: ReferenceType> {
|
||||||
Init {
|
Init {
|
||||||
desc: crate::device::DeviceDescriptor<'a>,
|
desc: crate::device::DeviceDescriptor<'a>,
|
||||||
backend: wgt::Backend,
|
backend: wgt::Backend,
|
||||||
@ -46,18 +51,18 @@ pub enum Action<'a> {
|
|||||||
id::SurfaceId,
|
id::SurfaceId,
|
||||||
wgt::SurfaceConfiguration<Vec<wgt::TextureFormat>>,
|
wgt::SurfaceConfiguration<Vec<wgt::TextureFormat>>,
|
||||||
),
|
),
|
||||||
CreateBuffer(id::BufferId, crate::resource::BufferDescriptor<'a>),
|
CreateBuffer(R::Buffer, crate::resource::BufferDescriptor<'a>),
|
||||||
FreeBuffer(id::BufferId),
|
FreeBuffer(R::Buffer),
|
||||||
DestroyBuffer(id::BufferId),
|
DestroyBuffer(R::Buffer),
|
||||||
CreateTexture(id::TextureId, crate::resource::TextureDescriptor<'a>),
|
CreateTexture(R::Texture, crate::resource::TextureDescriptor<'a>),
|
||||||
FreeTexture(id::TextureId),
|
FreeTexture(R::Texture),
|
||||||
DestroyTexture(id::TextureId),
|
DestroyTexture(R::Texture),
|
||||||
CreateTextureView {
|
CreateTextureView {
|
||||||
id: id::TextureViewId,
|
id: R::TextureView,
|
||||||
parent_id: id::TextureId,
|
parent_id: R::Texture,
|
||||||
desc: crate::resource::TextureViewDescriptor<'a>,
|
desc: crate::resource::TextureViewDescriptor<'a>,
|
||||||
},
|
},
|
||||||
DestroyTextureView(id::TextureViewId),
|
DestroyTextureView(R::TextureView),
|
||||||
CreateExternalTexture {
|
CreateExternalTexture {
|
||||||
id: id::ExternalTextureId,
|
id: id::ExternalTextureId,
|
||||||
desc: crate::resource::ExternalTextureDescriptor<'a>,
|
desc: crate::resource::ExternalTextureDescriptor<'a>,
|
||||||
@ -68,7 +73,7 @@ pub enum Action<'a> {
|
|||||||
CreateSampler(id::SamplerId, crate::resource::SamplerDescriptor<'a>),
|
CreateSampler(id::SamplerId, crate::resource::SamplerDescriptor<'a>),
|
||||||
DestroySampler(id::SamplerId),
|
DestroySampler(id::SamplerId),
|
||||||
GetSurfaceTexture {
|
GetSurfaceTexture {
|
||||||
id: id::TextureId,
|
id: R::Texture,
|
||||||
parent_id: id::SurfaceId,
|
parent_id: id::SurfaceId,
|
||||||
},
|
},
|
||||||
Present(id::SurfaceId),
|
Present(id::SurfaceId),
|
||||||
@ -125,7 +130,7 @@ pub enum Action<'a> {
|
|||||||
CreateRenderBundle {
|
CreateRenderBundle {
|
||||||
id: id::RenderBundleId,
|
id: id::RenderBundleId,
|
||||||
desc: crate::command::RenderBundleEncoderDescriptor<'a>,
|
desc: crate::command::RenderBundleEncoderDescriptor<'a>,
|
||||||
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
|
base: BasePass<RenderCommand, Infallible>,
|
||||||
},
|
},
|
||||||
DestroyRenderBundle(id::RenderBundleId),
|
DestroyRenderBundle(id::RenderBundleId),
|
||||||
CreateQuerySet {
|
CreateQuerySet {
|
||||||
@ -134,13 +139,13 @@ pub enum Action<'a> {
|
|||||||
},
|
},
|
||||||
DestroyQuerySet(id::QuerySetId),
|
DestroyQuerySet(id::QuerySetId),
|
||||||
WriteBuffer {
|
WriteBuffer {
|
||||||
id: id::BufferId,
|
id: R::Buffer,
|
||||||
data: FileName,
|
data: FileName,
|
||||||
range: Range<wgt::BufferAddress>,
|
range: Range<wgt::BufferAddress>,
|
||||||
queued: bool,
|
queued: bool,
|
||||||
},
|
},
|
||||||
WriteTexture {
|
WriteTexture {
|
||||||
to: wgt::TexelCopyTextureInfo<id::TextureId>,
|
to: wgt::TexelCopyTextureInfo<R::Texture>,
|
||||||
data: FileName,
|
data: FileName,
|
||||||
layout: wgt::TexelCopyBufferLayout,
|
layout: wgt::TexelCopyBufferLayout,
|
||||||
size: wgt::Extent3d,
|
size: wgt::Extent3d,
|
||||||
@ -189,7 +194,10 @@ impl Trace {
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add(&mut self, action: Action) {
|
pub(crate) fn add(&mut self, action: Action<'_, IdReferences>)
|
||||||
|
where
|
||||||
|
for<'a> Action<'a, IdReferences>: serde::Serialize,
|
||||||
|
{
|
||||||
match ron::ser::to_string_pretty(&action, self.config.clone()) {
|
match ron::ser::to_string_pretty(&action, self.config.clone()) {
|
||||||
Ok(string) => {
|
Ok(string) => {
|
||||||
let _ = writeln!(self.file, "{string},");
|
let _ = writeln!(self.file, "{string},");
|
||||||
|
|||||||
@ -10,18 +10,21 @@
|
|||||||
|
|
||||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||||
|
|
||||||
|
use macro_rules_attribute::apply;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wgt::{
|
use wgt::{
|
||||||
error::{ErrorType, WebGpuError},
|
error::{ErrorType, WebGpuError},
|
||||||
AccelerationStructureGeometryFlags, BufferAddress, IndexFormat, VertexFormat,
|
AccelerationStructureGeometryFlags, BufferAddress, IndexFormat, VertexFormat,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::command::serde_object_reference_struct;
|
||||||
use crate::{
|
use crate::{
|
||||||
command::EncoderStateError,
|
command::{ArcReferences, EncoderStateError, IdReferences, ReferenceType},
|
||||||
device::{DeviceError, MissingFeatures},
|
device::{DeviceError, MissingFeatures},
|
||||||
id::{BlasId, BufferId, TlasId},
|
id::{BlasId, BufferId, TlasId},
|
||||||
resource::{
|
resource::{
|
||||||
Blas, BlasCompactCallback, BlasPrepareCompactResult, Buffer, DestroyedResourceError,
|
Blas, BlasCompactCallback, BlasPrepareCompactResult, DestroyedResourceError,
|
||||||
InvalidResourceError, MissingBufferUsageError, ResourceErrorIdent, Tlas,
|
InvalidResourceError, MissingBufferUsageError, ResourceErrorIdent, Tlas,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -306,60 +309,62 @@ pub(crate) enum AsAction {
|
|||||||
|
|
||||||
/// Like [`BlasTriangleGeometry`], but with owned data.
|
/// Like [`BlasTriangleGeometry`], but with owned data.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||||
pub struct TraceBlasTriangleGeometry {
|
pub struct OwnedBlasTriangleGeometry<R: ReferenceType> {
|
||||||
pub size: wgt::BlasTriangleGeometrySizeDescriptor,
|
pub size: wgt::BlasTriangleGeometrySizeDescriptor,
|
||||||
pub vertex_buffer: BufferId,
|
pub vertex_buffer: R::Buffer,
|
||||||
pub index_buffer: Option<BufferId>,
|
pub index_buffer: Option<R::Buffer>,
|
||||||
pub transform_buffer: Option<BufferId>,
|
pub transform_buffer: Option<R::Buffer>,
|
||||||
pub first_vertex: u32,
|
pub first_vertex: u32,
|
||||||
pub vertex_stride: BufferAddress,
|
pub vertex_stride: BufferAddress,
|
||||||
pub first_index: Option<u32>,
|
pub first_index: Option<u32>,
|
||||||
pub transform_buffer_offset: Option<BufferAddress>,
|
pub transform_buffer_offset: Option<BufferAddress>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
pub type ArcBlasTriangleGeometry = OwnedBlasTriangleGeometry<ArcReferences>;
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
pub type TraceBlasTriangleGeometry = OwnedBlasTriangleGeometry<IdReferences>;
|
||||||
pub enum TraceBlasGeometries {
|
|
||||||
TriangleGeometries(Vec<TraceBlasTriangleGeometry>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||||
pub struct TraceBlasBuildEntry {
|
pub enum OwnedBlasGeometries<R: ReferenceType> {
|
||||||
pub blas_id: BlasId,
|
TriangleGeometries(Vec<OwnedBlasTriangleGeometry<R>>),
|
||||||
pub geometries: TraceBlasGeometries,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type ArcBlasGeometries = OwnedBlasGeometries<ArcReferences>;
|
||||||
|
pub type TraceBlasGeometries = OwnedBlasGeometries<IdReferences>;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||||
pub struct TraceTlasInstance {
|
pub struct OwnedBlasBuildEntry<R: ReferenceType> {
|
||||||
pub blas_id: BlasId,
|
pub blas: R::Blas,
|
||||||
|
pub geometries: OwnedBlasGeometries<R>, // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type ArcBlasBuildEntry = OwnedBlasBuildEntry<ArcReferences>;
|
||||||
|
pub type TraceBlasBuildEntry = OwnedBlasBuildEntry<IdReferences>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||||
|
pub struct OwnedTlasInstance<R: ReferenceType> {
|
||||||
|
pub blas: R::Blas,
|
||||||
pub transform: [f32; 12],
|
pub transform: [f32; 12],
|
||||||
pub custom_data: u32,
|
pub custom_data: u32,
|
||||||
pub mask: u8,
|
pub mask: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type ArcTlasInstance = OwnedTlasInstance<ArcReferences>;
|
||||||
|
pub type TraceTlasInstance = OwnedTlasInstance<IdReferences>;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||||
pub struct TraceTlasPackage {
|
pub struct OwnedTlasPackage<R: ReferenceType> {
|
||||||
pub tlas_id: TlasId,
|
pub tlas: R::Tlas,
|
||||||
pub instances: Vec<Option<TraceTlasInstance>>,
|
pub instances: Vec<Option<OwnedTlasInstance<R>>>,
|
||||||
pub lowest_unmodified: u32,
|
pub lowest_unmodified: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [`BlasTriangleGeometry`], but with `Arc`s.
|
pub type TraceTlasPackage = OwnedTlasPackage<IdReferences>;
|
||||||
#[derive(Debug, Clone)]
|
pub type ArcTlasPackage = OwnedTlasPackage<ArcReferences>;
|
||||||
pub struct ArcBlasTriangleGeometry {
|
|
||||||
pub size: wgt::BlasTriangleGeometrySizeDescriptor,
|
|
||||||
pub vertex_buffer: Arc<Buffer>,
|
|
||||||
pub index_buffer: Option<Arc<Buffer>>,
|
|
||||||
pub transform_buffer: Option<Arc<Buffer>>,
|
|
||||||
pub first_vertex: u32,
|
|
||||||
pub vertex_stride: BufferAddress,
|
|
||||||
pub first_index: Option<u32>,
|
|
||||||
pub transform_buffer_offset: Option<BufferAddress>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [`BlasTriangleGeometry`], without the resources.
|
/// [`BlasTriangleGeometry`], without the resources.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -371,32 +376,6 @@ pub struct BlasTriangleGeometryInfo {
|
|||||||
pub transform_buffer_offset: Option<BufferAddress>,
|
pub transform_buffer_offset: Option<BufferAddress>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum ArcBlasGeometries {
|
|
||||||
TriangleGeometries(Vec<ArcBlasTriangleGeometry>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ArcBlasBuildEntry {
|
|
||||||
pub blas: Arc<Blas>,
|
|
||||||
pub geometries: ArcBlasGeometries,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ArcTlasInstance {
|
|
||||||
pub blas: Arc<Blas>,
|
|
||||||
pub transform: [f32; 12],
|
|
||||||
pub custom_data: u32,
|
|
||||||
pub mask: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ArcTlasPackage {
|
|
||||||
pub tlas: Arc<Tlas>,
|
|
||||||
pub instances: Vec<Option<ArcTlasInstance>>,
|
|
||||||
pub lowest_unmodified: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Error)]
|
#[derive(Clone, Debug, Error)]
|
||||||
pub enum BlasPrepareCompactError {
|
pub enum BlasPrepareCompactError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|||||||
@ -5357,6 +5357,8 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
/// Similar to `BufferUsages`, but used only for `CommandEncoder::transition_resources`.
|
/// Similar to `BufferUsages`, but used only for `CommandEncoder::transition_resources`.
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct BufferUses: u16 {
|
pub struct BufferUses: u16 {
|
||||||
/// The argument to a read-only mapping.
|
/// The argument to a read-only mapping.
|
||||||
@ -5408,6 +5410,7 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
/// A buffer transition for use with `CommandEncoder::transition_resources`.
|
/// A buffer transition for use with `CommandEncoder::transition_resources`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct BufferTransition<T> {
|
pub struct BufferTransition<T> {
|
||||||
/// The buffer to transition.
|
/// The buffer to transition.
|
||||||
pub buffer: T,
|
pub buffer: T,
|
||||||
@ -5669,6 +5672,8 @@ bitflags::bitflags! {
|
|||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
/// Similar to `TextureUsages`, but used only for `CommandEncoder::transition_resources`.
|
/// Similar to `TextureUsages`, but used only for `CommandEncoder::transition_resources`.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||||
pub struct TextureUses: u16 {
|
pub struct TextureUses: u16 {
|
||||||
/// The texture is in unknown state.
|
/// The texture is in unknown state.
|
||||||
const UNINITIALIZED = 1 << 0;
|
const UNINITIALIZED = 1 << 0;
|
||||||
@ -5724,6 +5729,7 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
/// A texture transition for use with `CommandEncoder::transition_resources`.
|
/// A texture transition for use with `CommandEncoder::transition_resources`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct TextureTransition<T> {
|
pub struct TextureTransition<T> {
|
||||||
/// The texture to transition.
|
/// The texture to transition.
|
||||||
pub texture: T,
|
pub texture: T,
|
||||||
@ -5737,6 +5743,7 @@ pub struct TextureTransition<T> {
|
|||||||
|
|
||||||
/// Specifies a particular set of subresources in a texture.
|
/// Specifies a particular set of subresources in a texture.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct TextureSelector {
|
pub struct TextureSelector {
|
||||||
/// Range of mips to use.
|
/// Range of mips to use.
|
||||||
pub mips: Range<u32>,
|
pub mips: Range<u32>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user