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"
|
||||
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]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
@ -4817,6 +4833,7 @@ dependencies = [
|
||||
"hashbrown 0.16.0",
|
||||
"indexmap",
|
||||
"log",
|
||||
"macro_rules_attribute",
|
||||
"naga",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
|
||||
@ -142,6 +142,7 @@ libloading = "0.8"
|
||||
libm = { version = "0.2.6", default-features = false }
|
||||
libtest-mimic = "0.8"
|
||||
log = "0.4.21"
|
||||
macro_rules_attribute = "0.2"
|
||||
nanoserde = "0.2"
|
||||
nanorand = { version = "0.8", default-features = false, features = ["wyrand"] }
|
||||
noise = "0.9"
|
||||
|
||||
@ -7,7 +7,7 @@ fn main() {
|
||||
|
||||
use player::GlobalPlay as _;
|
||||
use wgc::device::trace;
|
||||
use wgpu_core::identity::IdentityManager;
|
||||
use wgpu_core::{command::IdReferences, identity::IdentityManager};
|
||||
|
||||
use std::{
|
||||
fs,
|
||||
@ -52,7 +52,7 @@ fn main() {
|
||||
|
||||
log::info!("Loading trace '{trace:?}'");
|
||||
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
|
||||
log::info!("Found {} actions", actions.len());
|
||||
|
||||
|
||||
@ -6,7 +6,11 @@
|
||||
extern crate wgpu_core as wgc;
|
||||
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};
|
||||
|
||||
@ -21,7 +25,7 @@ pub trait GlobalPlay {
|
||||
&self,
|
||||
device: wgc::id::DeviceId,
|
||||
queue: wgc::id::QueueId,
|
||||
action: trace::Action,
|
||||
action: trace::Action<IdReferences>,
|
||||
dir: &Path,
|
||||
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
||||
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
||||
@ -143,7 +147,7 @@ impl GlobalPlay for wgc::global::Global {
|
||||
}
|
||||
};
|
||||
wgc::ray_tracing::BlasBuildEntry {
|
||||
blas_id: x.blas_id,
|
||||
blas_id: x.blas,
|
||||
geometries,
|
||||
}
|
||||
});
|
||||
@ -153,14 +157,14 @@ impl GlobalPlay for wgc::global::Global {
|
||||
instance
|
||||
.as_ref()
|
||||
.map(|instance| wgc::ray_tracing::TlasInstance {
|
||||
blas_id: instance.blas_id,
|
||||
blas_id: instance.blas,
|
||||
transform: &instance.transform,
|
||||
custom_data: instance.custom_data,
|
||||
mask: instance.mask,
|
||||
})
|
||||
});
|
||||
wgc::ray_tracing::TlasPackage {
|
||||
tlas_id: x.tlas_id,
|
||||
tlas_id: x.tlas,
|
||||
instances: Box::new(instances),
|
||||
lowest_unmodified: x.lowest_unmodified,
|
||||
}
|
||||
@ -188,7 +192,7 @@ impl GlobalPlay for wgc::global::Global {
|
||||
&self,
|
||||
device: wgc::id::DeviceId,
|
||||
queue: wgc::id::QueueId,
|
||||
action: trace::Action,
|
||||
action: trace::Action<IdReferences>,
|
||||
dir: &Path,
|
||||
command_encoder_id_manager: &mut IdentityManager<wgc::id::markers::CommandEncoder>,
|
||||
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
|
||||
|
||||
@ -20,7 +20,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
slice,
|
||||
};
|
||||
use wgc::identity::IdentityManager;
|
||||
use wgc::{command::IdReferences, identity::IdentityManager};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct RawId {
|
||||
@ -57,7 +57,7 @@ struct Expectation {
|
||||
struct Test<'a> {
|
||||
features: wgt::Features,
|
||||
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>) {
|
||||
|
||||
@ -178,6 +178,7 @@ document-features.workspace = true
|
||||
hashbrown.workspace = true
|
||||
indexmap.workspace = true
|
||||
log.workspace = true
|
||||
macro_rules_attribute.workspace = true
|
||||
once_cell = { workspace = true, features = ["std"] }
|
||||
parking_lot.workspace = true
|
||||
profiling = { workspace = true, default-features = false }
|
||||
|
||||
@ -1,12 +1,77 @@
|
||||
use core::convert::Infallible;
|
||||
|
||||
use alloc::{string::String, sync::Arc, vec::Vec};
|
||||
#[cfg(feature = "serde")]
|
||||
use macro_rules_attribute::attribute_alias;
|
||||
|
||||
use crate::{
|
||||
id,
|
||||
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)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Command {
|
||||
|
||||
@ -34,13 +34,15 @@ use core::mem::{self, ManuallyDrop};
|
||||
use core::ops;
|
||||
|
||||
pub(crate) use self::clear::clear_texture;
|
||||
#[cfg(feature = "serde")]
|
||||
pub(crate) use self::encoder_command::serde_object_reference_struct;
|
||||
pub use self::{
|
||||
bundle::*,
|
||||
clear::ClearError,
|
||||
compute::*,
|
||||
compute_command::{ArcComputeCommand, ComputeCommand},
|
||||
draw::*,
|
||||
encoder_command::{ArcCommand, Command},
|
||||
encoder_command::{ArcCommand, ArcReferences, Command, IdReferences, ReferenceType},
|
||||
query::*,
|
||||
render::*,
|
||||
render_command::{ArcRenderCommand, RenderCommand},
|
||||
|
||||
@ -8,32 +8,29 @@ use core::{
|
||||
use wgt::{math::align_to, BufferUsages, BufferUses, Features};
|
||||
|
||||
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,
|
||||
global::Global,
|
||||
id::CommandEncoderId,
|
||||
init_tracker::MemoryInitKind,
|
||||
ray_tracing::{
|
||||
BlasBuildEntry, BlasGeometries, BuildAccelerationStructureError, TlasPackage,
|
||||
TraceBlasBuildEntry, TraceBlasGeometries, TraceBlasTriangleGeometry, TraceTlasInstance,
|
||||
TraceTlasPackage,
|
||||
ArcBlasBuildEntry, ArcBlasGeometries, ArcBlasTriangleGeometry, ArcTlasInstance,
|
||||
ArcTlasPackage, BlasBuildEntry, BlasGeometries, BuildAccelerationStructureError,
|
||||
OwnedBlasBuildEntry, OwnedTlasPackage, TlasPackage, TraceBlasBuildEntry,
|
||||
TraceBlasGeometries, TraceBlasTriangleGeometry, TraceTlasInstance, TraceTlasPackage,
|
||||
},
|
||||
resource::{Blas, BlasCompactState, Buffer, Labeled, StagingBuffer, Tlas},
|
||||
scratch::ScratchBuffer,
|
||||
snatch::SnatchGuard,
|
||||
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::id::{BlasId, TlasId};
|
||||
@ -147,7 +144,7 @@ impl Global {
|
||||
}
|
||||
};
|
||||
TraceBlasBuildEntry {
|
||||
blas_id: blas_entry.blas_id,
|
||||
blas: blas_entry.blas_id,
|
||||
geometries,
|
||||
}
|
||||
})
|
||||
@ -159,7 +156,7 @@ impl Global {
|
||||
.instances
|
||||
.map(|instance| {
|
||||
instance.map(|instance| TraceTlasInstance {
|
||||
blas_id: instance.blas_id,
|
||||
blas: instance.blas_id,
|
||||
transform: *instance.transform,
|
||||
custom_data: instance.custom_data,
|
||||
mask: instance.mask,
|
||||
@ -167,7 +164,7 @@ impl Global {
|
||||
})
|
||||
.collect();
|
||||
TraceTlasPackage {
|
||||
tlas_id: package.tlas_id,
|
||||
tlas: package.tlas_id,
|
||||
instances,
|
||||
lowest_unmodified: package.lowest_unmodified,
|
||||
}
|
||||
@ -215,7 +212,7 @@ impl Global {
|
||||
}
|
||||
};
|
||||
Ok(ArcBlasBuildEntry {
|
||||
blas: self.resolve_blas_id(blas_entry.blas_id)?,
|
||||
blas: self.resolve_blas_id(blas_entry.blas)?,
|
||||
geometries,
|
||||
})
|
||||
})
|
||||
@ -232,7 +229,7 @@ impl Global {
|
||||
.as_ref()
|
||||
.map(|instance| {
|
||||
Ok(ArcTlasInstance {
|
||||
blas: self.resolve_blas_id(instance.blas_id)?,
|
||||
blas: self.resolve_blas_id(instance.blas)?,
|
||||
transform: instance.transform,
|
||||
custom_data: instance.custom_data,
|
||||
mask: instance.mask,
|
||||
@ -242,7 +239,7 @@ impl Global {
|
||||
})
|
||||
.collect::<Result<_, BuildAccelerationStructureError>>()?;
|
||||
Ok(ArcTlasPackage {
|
||||
tlas: self.resolve_tlas_id(tlas_package.tlas_id)?,
|
||||
tlas: self.resolve_tlas_id(tlas_package.tlas)?,
|
||||
instances,
|
||||
lowest_unmodified: tlas_package.lowest_unmodified,
|
||||
})
|
||||
@ -256,8 +253,8 @@ impl Global {
|
||||
|
||||
pub(crate) fn build_acceleration_structures(
|
||||
state: &mut EncodingState,
|
||||
blas: Vec<ArcBlasBuildEntry>,
|
||||
tlas: Vec<ArcTlasPackage>,
|
||||
blas: Vec<OwnedBlasBuildEntry<ArcReferences>>,
|
||||
tlas: Vec<OwnedTlasPackage<ArcReferences>>,
|
||||
) -> Result<(), BuildAccelerationStructureError> {
|
||||
state
|
||||
.device
|
||||
@ -282,7 +279,7 @@ pub(crate) fn build_acceleration_structures(
|
||||
&mut scratch_buffer_blas_size,
|
||||
&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() {
|
||||
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).
|
||||
fn iter_blas(
|
||||
blas_iter: impl Iterator<Item = ArcBlasBuildEntry>,
|
||||
blas_iter: impl Iterator<Item = OwnedBlasBuildEntry<ArcReferences>>,
|
||||
tracker: &mut Tracker,
|
||||
build_command: &mut AsBuild,
|
||||
buf_storage: &mut Vec<TriangleBufferStore>,
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::{convert::Infallible, ops::Range};
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use macro_rules_attribute::apply;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
use {alloc::borrow::Cow, std::io::Write as _};
|
||||
|
||||
use crate::{command::Command, id};
|
||||
|
||||
//TODO: consider a readable Id that doesn't include the backend
|
||||
#[cfg(feature = "trace")]
|
||||
use crate::command::IdReferences;
|
||||
use crate::{
|
||||
command::{serde_object_reference_struct, BasePass, Command, ReferenceType, RenderCommand},
|
||||
id,
|
||||
};
|
||||
|
||||
type FileName = String;
|
||||
|
||||
@ -36,8 +41,8 @@ pub(crate) fn new_render_bundle_encoder_descriptor<'a>(
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum Action<'a> {
|
||||
#[apply(serde_object_reference_struct)]
|
||||
pub enum Action<'a, R: ReferenceType> {
|
||||
Init {
|
||||
desc: crate::device::DeviceDescriptor<'a>,
|
||||
backend: wgt::Backend,
|
||||
@ -46,18 +51,18 @@ pub enum Action<'a> {
|
||||
id::SurfaceId,
|
||||
wgt::SurfaceConfiguration<Vec<wgt::TextureFormat>>,
|
||||
),
|
||||
CreateBuffer(id::BufferId, crate::resource::BufferDescriptor<'a>),
|
||||
FreeBuffer(id::BufferId),
|
||||
DestroyBuffer(id::BufferId),
|
||||
CreateTexture(id::TextureId, crate::resource::TextureDescriptor<'a>),
|
||||
FreeTexture(id::TextureId),
|
||||
DestroyTexture(id::TextureId),
|
||||
CreateBuffer(R::Buffer, crate::resource::BufferDescriptor<'a>),
|
||||
FreeBuffer(R::Buffer),
|
||||
DestroyBuffer(R::Buffer),
|
||||
CreateTexture(R::Texture, crate::resource::TextureDescriptor<'a>),
|
||||
FreeTexture(R::Texture),
|
||||
DestroyTexture(R::Texture),
|
||||
CreateTextureView {
|
||||
id: id::TextureViewId,
|
||||
parent_id: id::TextureId,
|
||||
id: R::TextureView,
|
||||
parent_id: R::Texture,
|
||||
desc: crate::resource::TextureViewDescriptor<'a>,
|
||||
},
|
||||
DestroyTextureView(id::TextureViewId),
|
||||
DestroyTextureView(R::TextureView),
|
||||
CreateExternalTexture {
|
||||
id: id::ExternalTextureId,
|
||||
desc: crate::resource::ExternalTextureDescriptor<'a>,
|
||||
@ -68,7 +73,7 @@ pub enum Action<'a> {
|
||||
CreateSampler(id::SamplerId, crate::resource::SamplerDescriptor<'a>),
|
||||
DestroySampler(id::SamplerId),
|
||||
GetSurfaceTexture {
|
||||
id: id::TextureId,
|
||||
id: R::Texture,
|
||||
parent_id: id::SurfaceId,
|
||||
},
|
||||
Present(id::SurfaceId),
|
||||
@ -125,7 +130,7 @@ pub enum Action<'a> {
|
||||
CreateRenderBundle {
|
||||
id: id::RenderBundleId,
|
||||
desc: crate::command::RenderBundleEncoderDescriptor<'a>,
|
||||
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
|
||||
base: BasePass<RenderCommand, Infallible>,
|
||||
},
|
||||
DestroyRenderBundle(id::RenderBundleId),
|
||||
CreateQuerySet {
|
||||
@ -134,13 +139,13 @@ pub enum Action<'a> {
|
||||
},
|
||||
DestroyQuerySet(id::QuerySetId),
|
||||
WriteBuffer {
|
||||
id: id::BufferId,
|
||||
id: R::Buffer,
|
||||
data: FileName,
|
||||
range: Range<wgt::BufferAddress>,
|
||||
queued: bool,
|
||||
},
|
||||
WriteTexture {
|
||||
to: wgt::TexelCopyTextureInfo<id::TextureId>,
|
||||
to: wgt::TexelCopyTextureInfo<R::Texture>,
|
||||
data: FileName,
|
||||
layout: wgt::TexelCopyBufferLayout,
|
||||
size: wgt::Extent3d,
|
||||
@ -189,7 +194,10 @@ impl Trace {
|
||||
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()) {
|
||||
Ok(string) => {
|
||||
let _ = writeln!(self.file, "{string},");
|
||||
|
||||
@ -10,18 +10,21 @@
|
||||
|
||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
|
||||
use macro_rules_attribute::apply;
|
||||
use thiserror::Error;
|
||||
use wgt::{
|
||||
error::{ErrorType, WebGpuError},
|
||||
AccelerationStructureGeometryFlags, BufferAddress, IndexFormat, VertexFormat,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use crate::command::serde_object_reference_struct;
|
||||
use crate::{
|
||||
command::EncoderStateError,
|
||||
command::{ArcReferences, EncoderStateError, IdReferences, ReferenceType},
|
||||
device::{DeviceError, MissingFeatures},
|
||||
id::{BlasId, BufferId, TlasId},
|
||||
resource::{
|
||||
Blas, BlasCompactCallback, BlasPrepareCompactResult, Buffer, DestroyedResourceError,
|
||||
Blas, BlasCompactCallback, BlasPrepareCompactResult, DestroyedResourceError,
|
||||
InvalidResourceError, MissingBufferUsageError, ResourceErrorIdent, Tlas,
|
||||
},
|
||||
};
|
||||
@ -306,60 +309,62 @@ pub(crate) enum AsAction {
|
||||
|
||||
/// Like [`BlasTriangleGeometry`], but with owned data.
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct TraceBlasTriangleGeometry {
|
||||
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||
pub struct OwnedBlasTriangleGeometry<R: ReferenceType> {
|
||||
pub size: wgt::BlasTriangleGeometrySizeDescriptor,
|
||||
pub vertex_buffer: BufferId,
|
||||
pub index_buffer: Option<BufferId>,
|
||||
pub transform_buffer: Option<BufferId>,
|
||||
pub vertex_buffer: R::Buffer,
|
||||
pub index_buffer: Option<R::Buffer>,
|
||||
pub transform_buffer: Option<R::Buffer>,
|
||||
pub first_vertex: u32,
|
||||
pub vertex_stride: BufferAddress,
|
||||
pub first_index: Option<u32>,
|
||||
pub transform_buffer_offset: Option<BufferAddress>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum TraceBlasGeometries {
|
||||
TriangleGeometries(Vec<TraceBlasTriangleGeometry>),
|
||||
}
|
||||
pub type ArcBlasTriangleGeometry = OwnedBlasTriangleGeometry<ArcReferences>;
|
||||
pub type TraceBlasTriangleGeometry = OwnedBlasTriangleGeometry<IdReferences>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct TraceBlasBuildEntry {
|
||||
pub blas_id: BlasId,
|
||||
pub geometries: TraceBlasGeometries,
|
||||
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||
pub enum OwnedBlasGeometries<R: ReferenceType> {
|
||||
TriangleGeometries(Vec<OwnedBlasTriangleGeometry<R>>),
|
||||
}
|
||||
|
||||
pub type ArcBlasGeometries = OwnedBlasGeometries<ArcReferences>;
|
||||
pub type TraceBlasGeometries = OwnedBlasGeometries<IdReferences>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct TraceTlasInstance {
|
||||
pub blas_id: BlasId,
|
||||
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||
pub struct OwnedBlasBuildEntry<R: ReferenceType> {
|
||||
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 custom_data: u32,
|
||||
pub mask: u8,
|
||||
}
|
||||
|
||||
pub type ArcTlasInstance = OwnedTlasInstance<ArcReferences>;
|
||||
pub type TraceTlasInstance = OwnedTlasInstance<IdReferences>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct TraceTlasPackage {
|
||||
pub tlas_id: TlasId,
|
||||
pub instances: Vec<Option<TraceTlasInstance>>,
|
||||
#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
|
||||
pub struct OwnedTlasPackage<R: ReferenceType> {
|
||||
pub tlas: R::Tlas,
|
||||
pub instances: Vec<Option<OwnedTlasInstance<R>>>,
|
||||
pub lowest_unmodified: u32,
|
||||
}
|
||||
|
||||
/// Like [`BlasTriangleGeometry`], but with `Arc`s.
|
||||
#[derive(Debug, Clone)]
|
||||
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>,
|
||||
}
|
||||
pub type TraceTlasPackage = OwnedTlasPackage<IdReferences>;
|
||||
pub type ArcTlasPackage = OwnedTlasPackage<ArcReferences>;
|
||||
|
||||
/// [`BlasTriangleGeometry`], without the resources.
|
||||
#[derive(Debug, Clone)]
|
||||
@ -371,32 +376,6 @@ pub struct BlasTriangleGeometryInfo {
|
||||
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)]
|
||||
pub enum BlasPrepareCompactError {
|
||||
#[error(transparent)]
|
||||
|
||||
@ -5357,6 +5357,8 @@ bitflags::bitflags! {
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// 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)]
|
||||
pub struct BufferUses: u16 {
|
||||
/// The argument to a read-only mapping.
|
||||
@ -5408,6 +5410,7 @@ bitflags::bitflags! {
|
||||
|
||||
/// A buffer transition for use with `CommandEncoder::transition_resources`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct BufferTransition<T> {
|
||||
/// The buffer to transition.
|
||||
pub buffer: T,
|
||||
@ -5669,6 +5672,8 @@ bitflags::bitflags! {
|
||||
bitflags::bitflags! {
|
||||
/// Similar to `TextureUsages`, but used only for `CommandEncoder::transition_resources`.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
pub struct TextureUses: u16 {
|
||||
/// The texture is in unknown state.
|
||||
const UNINITIALIZED = 1 << 0;
|
||||
@ -5724,6 +5729,7 @@ bitflags::bitflags! {
|
||||
|
||||
/// A texture transition for use with `CommandEncoder::transition_resources`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct TextureTransition<T> {
|
||||
/// The texture to transition.
|
||||
pub texture: T,
|
||||
@ -5737,6 +5743,7 @@ pub struct TextureTransition<T> {
|
||||
|
||||
/// Specifies a particular set of subresources in a texture.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct TextureSelector {
|
||||
/// Range of mips to use.
|
||||
pub mips: Range<u32>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user