mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
Extract IDs, Registries and Global into wgpu-core-remote (#10053)
This commit is contained in:
41 files changed
+3123
-3162
No files matched your search
Generated
+12
@@ -4850,6 +4850,18 @@ dependencies = [
|
||||
"wgpu-hal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wgpu-core-remote"
|
||||
version = "30.0.0"
|
||||
dependencies = [
|
||||
"parking_lot",
|
||||
"raw-window-handle",
|
||||
"serde",
|
||||
"wgpu-core",
|
||||
"wgpu-hal",
|
||||
"wgpu-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wgpu-example-01-hello-compute"
|
||||
version = "0.0.0"
|
||||
|
||||
@@ -21,6 +21,7 @@ members = [
|
||||
"tests",
|
||||
"wgpu-core",
|
||||
"wgpu-core/platform-deps/*",
|
||||
"wgpu-core-remote",
|
||||
"wgpu-hal",
|
||||
"wgpu-info",
|
||||
"wgpu-naga-bridge",
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
[package]
|
||||
name = "wgpu-core-remote"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
description = "Remoting version of wgpu-core"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
keywords.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
# Override the workspace's `rust-version` key. `wgpu-core-remote` and its dependencies
|
||||
# have a less strict MSRV, to allow firefox more leeway in updating their Rust toolchain.
|
||||
#
|
||||
# See the repo README for more information on MSRV policy.
|
||||
rust-version = "1.87"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
targets = [
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-apple-darwin",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"wasm32-unknown-unknown",
|
||||
]
|
||||
|
||||
[features]
|
||||
## Enables serialization via `serde` on common wgpu types.
|
||||
serde = ["dep:serde", "wgpu-types/serde", "wgpu-core/serde"]
|
||||
|
||||
[dependencies]
|
||||
wgpu-core = { workspace = true, default-features = false }
|
||||
wgpu-hal = { workspace = true, default-features = false }
|
||||
wgpu-types.workspace = true
|
||||
parking_lot.workspace = true
|
||||
raw-window-handle.workspace = true
|
||||
serde = { workspace = true, optional = true }
|
||||
@@ -0,0 +1,161 @@
|
||||
use core::ops::Deref;
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id::*;
|
||||
|
||||
impl Global {
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw buffer handle must not be manually destroyed
|
||||
pub unsafe fn buffer_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: BufferId,
|
||||
) -> Option<impl Deref<Target = A::Buffer>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let buffer = hub.buffers.get(id);
|
||||
|
||||
unsafe { buffer.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw texture handle must not be manually destroyed
|
||||
pub unsafe fn texture_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TextureId,
|
||||
) -> Option<impl Deref<Target = A::Texture>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let texture = hub.textures.get(id);
|
||||
|
||||
unsafe { texture.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw texture view handle must not be manually destroyed
|
||||
pub unsafe fn texture_view_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TextureViewId,
|
||||
) -> Option<impl Deref<Target = A::TextureView>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let view = hub.texture_views.get(id);
|
||||
|
||||
unsafe { view.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw adapter handle must not be manually destroyed
|
||||
pub unsafe fn adapter_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: AdapterId,
|
||||
) -> Option<impl Deref<Target = A::Adapter>> {
|
||||
let hub = &self.hub;
|
||||
let adapter = hub.adapters.get(id);
|
||||
|
||||
unsafe { adapter.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw device handle must not be manually destroyed
|
||||
pub unsafe fn device_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: DeviceId,
|
||||
) -> Option<impl Deref<Target = A::Device>> {
|
||||
let device = self.hub.devices.get(id);
|
||||
|
||||
unsafe { device.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw fence handle must not be manually destroyed
|
||||
pub unsafe fn device_fence_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: DeviceId,
|
||||
) -> Option<impl Deref<Target = A::Fence>> {
|
||||
let device = self.hub.devices.get(id);
|
||||
|
||||
unsafe { device.fence_as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw surface handle must not be manually destroyed
|
||||
pub unsafe fn surface_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: SurfaceId,
|
||||
) -> Option<impl Deref<Target = A::Surface>> {
|
||||
let surface = self.surfaces.get(id);
|
||||
|
||||
unsafe { surface.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// Encode commands using the raw HAL command encoder.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If the command encoder has already been used with the wgpu encoding API.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw command encoder handle must not be manually destroyed
|
||||
pub unsafe fn command_encoder_as_hal_mut<
|
||||
A: hal::Api,
|
||||
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
||||
R,
|
||||
>(
|
||||
&self,
|
||||
id: CommandEncoderId,
|
||||
hal_command_encoder_callback: F,
|
||||
) -> R {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(id);
|
||||
unsafe { cmd_enc.as_hal_mut::<A, F, R>(hal_command_encoder_callback) }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw queue handle must not be manually destroyed
|
||||
pub unsafe fn queue_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: QueueId,
|
||||
) -> Option<impl Deref<Target = A::Queue>> {
|
||||
let queue = self.hub.queues.get(id);
|
||||
|
||||
unsafe { queue.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw blas handle must not be manually destroyed
|
||||
pub unsafe fn blas_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: BlasId,
|
||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(id);
|
||||
|
||||
unsafe { blas.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw tlas handle must not be manually destroyed
|
||||
pub unsafe fn tlas_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TlasId,
|
||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let tlas = hub.tlas_s.get(id);
|
||||
|
||||
unsafe { tlas.as_hal::<A>() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
use crate::id;
|
||||
use wgpu_core::command::{PassStateError, RenderBundleEncoder};
|
||||
|
||||
impl crate::global::Global {
|
||||
pub fn render_bundle_encoder_set_bind_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[wgt::DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_bind_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[wgt::DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_pipeline(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_pipeline(self.hub.render_pipelines.get(pipeline_id))
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_pipeline_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_pipeline(self.hub.render_pipelines.get(pipeline_id))
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_vertex_buffer(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.hub.buffers.get(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_vertex_buffer_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.hub.buffers.get(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_index_buffer(
|
||||
&self,
|
||||
encoder: &mut RenderBundleEncoder,
|
||||
buffer: id::BufferId,
|
||||
index_format: wgt::IndexFormat,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
encoder.set_index_buffer(self.hub.buffers.get(buffer), index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_index_buffer_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer: id::BufferId,
|
||||
index_format: wgt::IndexFormat,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_index_buffer(self.hub.buffers.get(buffer), index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_immediates(
|
||||
&self,
|
||||
pass: &mut RenderBundleEncoder,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_immediates_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indirect(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indirect_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_indirect(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indexed_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_indirect_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indexed_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_push_debug_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_push_debug_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_pop_debug_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_pop_debug_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_insert_debug_marker(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.insert_debug_marker(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_insert_debug_marker_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.insert_debug_marker(label)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
use wgpu_core::command::{CommandEncoderError, EncoderStateError};
|
||||
use wgpu_core::ray_tracing::{
|
||||
BlasAabbGeometry, BlasBuildEntry, BlasGeometries, BlasTriangleGeometry, TlasInstance,
|
||||
TlasPackage,
|
||||
};
|
||||
use wgpu_core::Label;
|
||||
use wgt::{BufferAddress, Extent3d, ImageSubresourceRange};
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id::{BlasId, BufferId, CommandEncoderId, TextureId, TlasId};
|
||||
use crate::{id, TexelCopyBufferInfo};
|
||||
|
||||
impl Global {
|
||||
/// Finishes a command encoder, creating a command buffer and returning errors that were
|
||||
/// deferred until now.
|
||||
///
|
||||
/// The returned `String` is the label of the command encoder, supplied so that `wgpu` can
|
||||
/// include the label when printing deferred errors without having its own copy of the label.
|
||||
/// This is a kludge and should be replaced if we think of a better solution to propagating
|
||||
/// labels.
|
||||
pub fn command_encoder_finish(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
desc: &wgt::CommandBufferDescriptor<Label>,
|
||||
id_in: Option<id::CommandBufferId>,
|
||||
) -> (id::CommandBufferId, Option<(String, CommandEncoderError)>) {
|
||||
let hub = &self.hub;
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let (cmd_buf, opt_error) = cmd_enc.finish(desc);
|
||||
let cmd_buf_id = hub.command_buffers.prepare(id_in).assign(cmd_buf);
|
||||
|
||||
(cmd_buf_id, opt_error)
|
||||
}
|
||||
|
||||
pub fn command_encoder_push_debug_group(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn command_encoder_insert_debug_marker(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.insert_debug_marker(label)
|
||||
}
|
||||
|
||||
pub fn command_encoder_pop_debug_group(
|
||||
&self,
|
||||
encoder_id: CommandEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.pop_debug_group()
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_clear_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
dst: BufferId,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
cmd_enc.clear_buffer(hub.buffers.get(dst), offset, size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_clear_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
dst: TextureId,
|
||||
subresource_range: &ImageSubresourceRange,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
cmd_enc.clear_texture(hub.textures.get(dst), subresource_range)
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_write_timestamp(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
cmd_enc.write_timestamp(hub.query_sets.get(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn command_encoder_resolve_query_set(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
start_query: u32,
|
||||
query_count: u32,
|
||||
destination: BufferId,
|
||||
destination_offset: BufferAddress,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
cmd_enc.resolve_query_set(
|
||||
hub.query_sets.get(query_set_id),
|
||||
start_query,
|
||||
query_count,
|
||||
hub.buffers.get(destination),
|
||||
destination_offset,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_mark_acceleration_structures_built(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
blas_ids: &[BlasId],
|
||||
tlas_ids: &[TlasId],
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let blases = blas_ids
|
||||
.iter()
|
||||
.map(|&id| hub.blas_s.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
let tlases = tlas_ids
|
||||
.iter()
|
||||
.map(|&id| hub.tlas_s.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
cmd_enc.mark_acceleration_structures_built(&blases, &tlases)
|
||||
}
|
||||
|
||||
pub fn command_encoder_build_acceleration_structures<'a>(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
blas_iter: impl Iterator<Item = BlasBuildEntry<'a, BlasId, BufferId>>,
|
||||
tlas_iter: impl Iterator<Item = TlasPackage<'a, TlasId, BlasId>>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let blases = blas_iter.map(|e| BlasBuildEntry {
|
||||
blas: hub.blas_s.get(e.blas),
|
||||
geometries: match e.geometries {
|
||||
BlasGeometries::TriangleGeometries(triangle_geometries) => {
|
||||
let triangle_geometries = triangle_geometries.map(|tg| BlasTriangleGeometry {
|
||||
size: tg.size,
|
||||
vertex_buffer: hub.buffers.get(tg.vertex_buffer),
|
||||
index_buffer: tg
|
||||
.index_buffer
|
||||
.map(|index_buffer| hub.buffers.get(index_buffer)),
|
||||
transform_buffer: tg
|
||||
.transform_buffer
|
||||
.map(|transform_buffer| hub.buffers.get(transform_buffer)),
|
||||
first_vertex: tg.first_vertex,
|
||||
vertex_stride: tg.vertex_stride,
|
||||
first_index: tg.first_index,
|
||||
transform_buffer_offset: tg.transform_buffer_offset,
|
||||
});
|
||||
BlasGeometries::TriangleGeometries(Box::new(triangle_geometries.into_iter()))
|
||||
}
|
||||
BlasGeometries::AabbGeometries(aabb_geometries) => {
|
||||
let aabb_geometries = aabb_geometries.map(|ag| BlasAabbGeometry {
|
||||
size: ag.size,
|
||||
stride: ag.stride,
|
||||
aabb_buffer: hub.buffers.get(ag.aabb_buffer),
|
||||
primitive_offset: ag.primitive_offset,
|
||||
});
|
||||
BlasGeometries::AabbGeometries(Box::new(aabb_geometries.into_iter()))
|
||||
}
|
||||
},
|
||||
});
|
||||
let tlases = tlas_iter.map(|e| TlasPackage {
|
||||
tlas: hub.tlas_s.get(e.tlas),
|
||||
instances: Box::new(e.instances.map(|instance| {
|
||||
instance.as_ref().map(|instance| TlasInstance {
|
||||
blas: hub.blas_s.get(instance.blas),
|
||||
transform: instance.transform,
|
||||
custom_data: instance.custom_data,
|
||||
mask: instance.mask,
|
||||
})
|
||||
})),
|
||||
lowest_unmodified: e.lowest_unmodified,
|
||||
});
|
||||
cmd_enc.build_acceleration_structures(blases.into_iter(), tlases.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_copy_buffer_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: BufferId,
|
||||
source_offset: BufferAddress,
|
||||
destination: BufferId,
|
||||
destination_offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let source = self.resolve_buffer_id(source);
|
||||
let destination = self.resolve_buffer_id(destination);
|
||||
cmd_enc.copy_buffer_to_buffer(source, source_offset, destination, destination_offset, size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_buffer_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &TexelCopyBufferInfo,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
let source = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(source.buffer),
|
||||
layout: source.layout,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_buffer_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &TexelCopyBufferInfo,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(destination.buffer),
|
||||
layout: destination.layout,
|
||||
};
|
||||
cmd_enc.copy_texture_to_buffer(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_texture_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_transition_resources(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
buffer_transitions: impl Iterator<Item = wgt::BufferTransition<BufferId>>,
|
||||
texture_transitions: impl Iterator<Item = wgt::TextureTransition<TextureId>>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let buffer_transitions = buffer_transitions
|
||||
.map(|t| {
|
||||
let buffer = hub.buffers.get(t.buffer);
|
||||
wgt::BufferTransition {
|
||||
buffer,
|
||||
state: t.state,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let texture_transitions = texture_transitions
|
||||
.map(|t| {
|
||||
let texture = hub.textures.get(t.texture);
|
||||
wgt::TextureTransition {
|
||||
texture,
|
||||
selector: t.selector,
|
||||
state: t.state,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
cmd_enc.transition_resources(
|
||||
buffer_transitions.into_iter(),
|
||||
texture_transitions.into_iter(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use alloc::borrow::Cow;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use wgpu_core::command::{
|
||||
CommandEncoderError, ComputePass, ComputePassDescriptor, EncoderStateError, PassStateError,
|
||||
PassTimestampWrites,
|
||||
};
|
||||
use wgt::{BufferAddress, DynamicOffset};
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id;
|
||||
|
||||
impl Global {
|
||||
/// Creates a compute pass.
|
||||
///
|
||||
/// If creation fails, an invalid pass is returned. Attempting to record
|
||||
/// commands into an invalid pass is permitted, but a validation error will
|
||||
/// ultimately be generated when the parent encoder is finished, and it is
|
||||
/// not possible to run any commands from the invalid pass.
|
||||
///
|
||||
/// If successful, puts the encoder into the [`Locked`] state.
|
||||
///
|
||||
/// [`Locked`]: crate::command::CommandEncoderStatus::Locked
|
||||
pub fn command_encoder_begin_compute_pass(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &ComputePassDescriptor<'_, PassTimestampWrites<id::QuerySetId>>,
|
||||
) -> (ComputePass, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let desc = ComputePassDescriptor {
|
||||
label: desc.label.as_deref().map(Cow::Borrowed),
|
||||
timestamp_writes: desc
|
||||
.timestamp_writes
|
||||
.as_ref()
|
||||
.map(|tw| PassTimestampWrites {
|
||||
query_set: hub.query_sets.get(tw.query_set),
|
||||
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,
|
||||
end_of_pass_write_index: tw.end_of_pass_write_index,
|
||||
}),
|
||||
};
|
||||
|
||||
cmd_enc.begin_compute_pass(&desc)
|
||||
}
|
||||
|
||||
pub fn command_encoder_begin_compute_pass_with_id(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &ComputePassDescriptor<'_, PassTimestampWrites<id::QuerySetId>>,
|
||||
id_in: Option<id::ComputePassEncoderId>,
|
||||
) -> (id::ComputePassEncoderId, Option<CommandEncoderError>) {
|
||||
let fid = self.hub.compute_passes.prepare(id_in);
|
||||
|
||||
let (pass, err) = self.command_encoder_begin_compute_pass(encoder_id, desc);
|
||||
|
||||
// no lock rank here because only one thread should be using compute pass
|
||||
// and it's only used by id variants of compute pass methods on global
|
||||
// so no deadlock (or concurrent lock) should happen in practise
|
||||
let id = fid.assign(Arc::new(Mutex::new(pass)));
|
||||
|
||||
(id, err)
|
||||
}
|
||||
|
||||
pub fn compute_pass_end(&self, pass: &mut ComputePass) -> Result<(), EncoderStateError> {
|
||||
pass.end()
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_end(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_drop(&self, pass_id: id::ComputePassEncoderId) {
|
||||
self.hub.compute_passes.remove(pass_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Recording a compute pass.
|
||||
//
|
||||
// The only error that should be returned from these methods is
|
||||
// `EncoderStateError::Ended`, when the pass has already ended and an immediate
|
||||
// validation error is raised.
|
||||
//
|
||||
// All other errors should be stored in the pass for later reporting when
|
||||
// `CommandEncoder.finish()` is called.
|
||||
impl Global {
|
||||
pub fn compute_pass_set_bind_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|bind_group_id| self.hub.bind_groups.get(bind_group_id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_bind_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_bind_group(&mut pass, index, bind_group_id, offsets)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_pipeline(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pipeline = self.hub.compute_pipelines.get(pipeline_id);
|
||||
pass.set_pipeline(pipeline)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_pipeline_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_pipeline(&mut pass, pipeline_id)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_immediates(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_immediates_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_immediates(&mut pass, offset, data)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
groups_x: u32,
|
||||
groups_y: u32,
|
||||
groups_z: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.dispatch_workgroups(groups_x, groups_y, groups_z)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
groups_x: u32,
|
||||
groups_y: u32,
|
||||
groups_z: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_dispatch_workgroups(&mut pass, groups_x, groups_y, groups_z)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_indirect(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.dispatch_workgroups_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_indirect_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_dispatch_workgroups_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn compute_pass_push_debug_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.push_debug_group(label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_push_debug_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_push_debug_group(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_pop_debug_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn compute_pass_pop_debug_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_pop_debug_group(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_insert_debug_marker(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.insert_debug_marker(label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_insert_debug_marker_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_insert_debug_marker(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_write_timestamp(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let query_set = self.hub.query_sets.get(query_set_id);
|
||||
pass.write_timestamp(query_set, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_write_timestamp_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_write_timestamp(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_begin_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let query_set = self.hub.query_sets.get(query_set_id);
|
||||
pass.begin_pipeline_statistics_query(query_set, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_begin_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_begin_pipeline_statistics_query(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_pipeline_statistics_query()
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_end_pipeline_statistics_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_transition_resources(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
buffer_transitions: impl Iterator<Item = wgt::BufferTransition<id::BufferId>>,
|
||||
texture_transitions: impl Iterator<Item = wgt::TextureTransition<id::TextureViewId>>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.transition_resources(
|
||||
buffer_transitions.map(|bt| wgt::BufferTransition {
|
||||
buffer: self.hub.buffers.get(bt.buffer),
|
||||
state: bt.state,
|
||||
}),
|
||||
texture_transitions.map(|tt| wgt::TextureTransition {
|
||||
texture: self.hub.texture_views.get(tt.texture),
|
||||
selector: tt.selector,
|
||||
state: tt.state,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,10 @@
|
||||
use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec};
|
||||
use core::ptr::NonNull;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
use crate::device::trace;
|
||||
use crate::{
|
||||
use wgpu_core::{
|
||||
binding_model::{self},
|
||||
command,
|
||||
device::{life::WaitIdleError, DeviceError, DeviceLostClosure},
|
||||
global::Global,
|
||||
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||
device::{Device, DeviceError, DeviceLostClosure, WaitIdleError},
|
||||
instance::{self, Adapter, Surface},
|
||||
pipeline::{
|
||||
self, MeshState, ProgrammableStageDescriptor, RenderPipelineVertexProcessor,
|
||||
@@ -18,8 +14,13 @@ use crate::{
|
||||
resource::{
|
||||
self, BufferAccessError, BufferAccessResult, BufferMapOperation, CreateBufferError,
|
||||
},
|
||||
Label, LabelHelpers, SubmissionIndex,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
global::Global,
|
||||
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||
storage::Storage,
|
||||
Label, LabelHelpers,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, TextureFormat};
|
||||
@@ -61,8 +62,6 @@ pub type ComputePipelineDescriptor<'a> = pipeline::ComputePipelineDescriptor<
|
||||
id::PipelineCacheId,
|
||||
>;
|
||||
|
||||
pub type VertexState<'a> = pipeline::VertexState<'a, id::ShaderModuleId>;
|
||||
|
||||
pub type MeshPipelineDescriptor<'a> = pipeline::MeshPipelineDescriptor<
|
||||
'a,
|
||||
id::PipelineLayoutId,
|
||||
@@ -147,7 +146,7 @@ impl Global {
|
||||
|
||||
pub fn device_adapter_info(&self, device_id: DeviceId) -> wgt::AdapterInfo {
|
||||
let device = self.hub.devices.get(device_id);
|
||||
device.adapter.get_info()
|
||||
device.adapter_info()
|
||||
}
|
||||
|
||||
pub fn device_downlevel_properties(&self, device_id: DeviceId) -> wgt::DownlevelCapabilities {
|
||||
@@ -906,7 +905,7 @@ impl Global {
|
||||
fn device_create_general_render_pipeline(
|
||||
&self,
|
||||
desc: GeneralRenderPipelineDescriptor,
|
||||
device: Arc<crate::device::resource::Device>,
|
||||
device: Arc<Device>,
|
||||
fid: crate::registry::FutureId<Arc<pipeline::RenderPipeline>>,
|
||||
) -> (
|
||||
id::RenderPipelineId,
|
||||
@@ -1145,7 +1144,7 @@ impl Global {
|
||||
pub fn device_poll(
|
||||
&self,
|
||||
device_id: DeviceId,
|
||||
poll_type: wgt::PollType<crate::SubmissionIndex>,
|
||||
poll_type: wgt::PollType<SubmissionIndex>,
|
||||
) -> Result<wgt::PollStatus, WaitIdleError> {
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
@@ -1229,15 +1228,6 @@ impl Global {
|
||||
device.generate_allocator_report()
|
||||
}
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
pub fn device_take_trace(
|
||||
&self,
|
||||
device_id: DeviceId,
|
||||
) -> Option<Box<dyn trace::Trace + Send + Sync + 'static>> {
|
||||
let device = self.hub.devices.get(device_id);
|
||||
device.take_trace()
|
||||
}
|
||||
|
||||
pub fn queue_drop(&self, queue_id: QueueId) {
|
||||
self.hub.queues.remove(queue_id);
|
||||
}
|
||||
@@ -1249,7 +1239,7 @@ impl Global {
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
op: BufferMapOperation,
|
||||
) -> Result<crate::SubmissionIndex, BufferAccessError> {
|
||||
) -> Result<SubmissionIndex, BufferAccessError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let buffer = hub.buffers.get(buffer_id);
|
||||
@@ -0,0 +1,206 @@
|
||||
use wgpu_core::device::DeviceDescriptor;
|
||||
use wgpu_core::instance::{CreateSurfaceError, RequestDeviceError};
|
||||
use wgt::Backends;
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id::{AdapterId, DeviceId, QueueId, SurfaceId};
|
||||
|
||||
pub type RequestAdapterOptions = wgt::RequestAdapterOptions<SurfaceId>;
|
||||
|
||||
impl Global {
|
||||
/// Creates a new surface targeting the given display/window handles.
|
||||
///
|
||||
/// Internally attempts to create hal surfaces for all enabled backends.
|
||||
///
|
||||
/// Fails only if creation for surfaces for all enabled backends fails in which case
|
||||
/// the error for each enabled backend is listed.
|
||||
/// Vice versa, if creation for any backend succeeds, success is returned.
|
||||
/// Surface creation errors are logged to the debug log in any case.
|
||||
///
|
||||
/// id_in:
|
||||
/// - If `Some`, the id to assign to the surface. A new one will be generated otherwise.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - `display_handle` must be a valid object to create a surface upon,
|
||||
/// falls back to the instance display handle otherwise.
|
||||
/// - `window_handle` must remain valid as long as the returned
|
||||
/// [`SurfaceId`] is being used.
|
||||
pub unsafe fn instance_create_surface(
|
||||
&self,
|
||||
display_handle: Option<raw_window_handle::RawDisplayHandle>,
|
||||
window_handle: raw_window_handle::RawWindowHandle,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe { self.instance.create_surface(display_handle, window_handle) }?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
pub fn surface_drop(&self, id: SurfaceId) {
|
||||
self.surfaces.remove(id);
|
||||
}
|
||||
|
||||
pub fn enumerate_adapters(
|
||||
&self,
|
||||
backends: Backends,
|
||||
apply_limit_buckets: bool,
|
||||
) -> Vec<AdapterId> {
|
||||
let adapters = self
|
||||
.instance
|
||||
.enumerate_adapters(backends, apply_limit_buckets);
|
||||
adapters
|
||||
.into_iter()
|
||||
.map(|adapter| self.hub.adapters.prepare(None).assign(adapter))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn request_adapter(
|
||||
&self,
|
||||
desc: &RequestAdapterOptions,
|
||||
backends: Backends,
|
||||
id_in: Option<AdapterId>,
|
||||
) -> Result<AdapterId, wgt::RequestAdapterError> {
|
||||
let compatible_surface = desc.compatible_surface.map(|id| self.surfaces.get(id));
|
||||
let desc = wgt::RequestAdapterOptions {
|
||||
power_preference: desc.power_preference,
|
||||
force_fallback_adapter: desc.force_fallback_adapter,
|
||||
compatible_surface: compatible_surface.as_deref(),
|
||||
apply_limit_buckets: desc.apply_limit_buckets,
|
||||
};
|
||||
let adapter = self.instance.request_adapter(&desc, backends)?;
|
||||
let id = self.hub.adapters.prepare(id_in).assign(adapter);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Create an adapter from a HAL adapter.
|
||||
///
|
||||
/// The HAL adapter may be obtained e.g. by calling `enumerate_adapters` on
|
||||
/// the HAL directly.
|
||||
///
|
||||
/// If [limit bucketing][lt] is desired, [`crate::limits::apply_limit_buckets`]
|
||||
/// should be called with the HAL adapter before calling this function.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `hal_adapter` must be created from this global internal instance handle.
|
||||
///
|
||||
/// [lt]: crate::limits#Limit-bucketing
|
||||
pub unsafe fn create_adapter_from_hal(
|
||||
&self,
|
||||
hal_adapter: hal::DynExposedAdapter,
|
||||
input: Option<AdapterId>,
|
||||
) -> AdapterId {
|
||||
let fid = self.hub.adapters.prepare(input);
|
||||
fid.assign(unsafe { self.instance.create_adapter_from_hal(hal_adapter) })
|
||||
}
|
||||
|
||||
pub fn adapter_get_info(&self, adapter_id: AdapterId) -> wgt::AdapterInfo {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_info()
|
||||
}
|
||||
|
||||
pub fn adapter_get_texture_format_features(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
format: wgt::TextureFormat,
|
||||
) -> wgt::TextureFormatFeatures {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_texture_format_features(format)
|
||||
}
|
||||
|
||||
pub fn adapter_features(&self, adapter_id: AdapterId) -> wgt::Features {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.features()
|
||||
}
|
||||
|
||||
pub fn adapter_limits(&self, adapter_id: AdapterId) -> wgt::Limits {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.limits()
|
||||
}
|
||||
|
||||
pub fn adapter_downlevel_capabilities(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> wgt::DownlevelCapabilities {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.downlevel_capabilities()
|
||||
}
|
||||
|
||||
pub fn adapter_get_presentation_timestamp(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> wgt::PresentationTimestamp {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_presentation_timestamp()
|
||||
}
|
||||
|
||||
pub fn adapter_cooperative_matrix_properties(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> Vec<wgt::CooperativeMatrixProperties> {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.cooperative_matrix_properties()
|
||||
}
|
||||
|
||||
pub fn adapter_drop(&self, adapter_id: AdapterId) {
|
||||
self.hub.adapters.remove(adapter_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn adapter_request_device(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &DeviceDescriptor,
|
||||
device_id_in: Option<DeviceId>,
|
||||
queue_id_in: Option<QueueId>,
|
||||
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
|
||||
let device_fid = self.hub.devices.prepare(device_id_in);
|
||||
let queue_fid = self.hub.queues.prepare(queue_id_in);
|
||||
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
let (device, queue) = adapter.request_device(desc)?;
|
||||
|
||||
let device_id = device_fid.assign(device);
|
||||
|
||||
let queue_id = queue_fid.assign(queue);
|
||||
|
||||
Ok((device_id, queue_id))
|
||||
}
|
||||
|
||||
pub fn adapter_validate_device_descriptor(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &mut DeviceDescriptor,
|
||||
) -> Result<(), RequestDeviceError> {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.validate_device_descriptor(desc)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - `hal_device` must be created from `adapter_id` or its internal handle.
|
||||
/// - `desc` must be a subset of `hal_device` features and limits.
|
||||
pub unsafe fn create_device_from_hal(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
hal_device: hal::DynOpenDevice,
|
||||
desc: &DeviceDescriptor,
|
||||
device_id_in: Option<DeviceId>,
|
||||
queue_id_in: Option<QueueId>,
|
||||
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
|
||||
let devices_fid = self.hub.devices.prepare(device_id_in);
|
||||
let queues_fid = self.hub.queues.prepare(queue_id_in);
|
||||
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
let (device, queue) =
|
||||
unsafe { adapter.create_device_and_queue_from_hal(hal_device, desc) }?;
|
||||
|
||||
let device_id = devices_fid.assign(device);
|
||||
|
||||
let queue_id = queues_fid.assign(queue);
|
||||
|
||||
Ok((device_id, queue_id))
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,30 @@
|
||||
use alloc::{borrow::ToOwned as _, sync::Arc};
|
||||
use core::fmt;
|
||||
use wgpu_core::binding_model::{BindGroupLayout, PipelineLayout};
|
||||
use wgpu_core::command::{CommandBuffer, CommandEncoder};
|
||||
use wgpu_core::device::queue::Queue;
|
||||
use wgpu_core::device::Device;
|
||||
use wgpu_core::instance::{Adapter, Instance, Surface};
|
||||
use wgpu_core::pipeline::{ComputePipeline, RenderPipeline};
|
||||
use wgpu_core::resource::{Buffer, QuerySet, Texture};
|
||||
|
||||
use crate::{
|
||||
binding_model::{BindGroupLayout, PipelineLayout},
|
||||
command::{CommandBuffer, CommandEncoder},
|
||||
device::{queue::Queue, Device},
|
||||
hub::{Hub, HubReport},
|
||||
id::{
|
||||
AdapterId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
|
||||
ComputePipelineId, DeviceId, PipelineLayoutId, QuerySetId, QueueId, RenderPipelineId,
|
||||
TextureId,
|
||||
},
|
||||
instance::{Adapter, Instance, Surface},
|
||||
pipeline::{ComputePipeline, RenderPipeline},
|
||||
registry::{Registry, RegistryReport},
|
||||
resource::{Buffer, QuerySet, Texture},
|
||||
resource_log,
|
||||
use crate::hub::{Hub, HubReport};
|
||||
use crate::id::{
|
||||
AdapterId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId, ComputePipelineId,
|
||||
DeviceId, PipelineLayoutId, QuerySetId, QueueId, RenderPipelineId, TextureId,
|
||||
};
|
||||
use crate::registry::{Registry, RegistryReport};
|
||||
|
||||
mod as_hal;
|
||||
mod bundle;
|
||||
mod command_encoder;
|
||||
mod compute_pass;
|
||||
mod device;
|
||||
mod instance;
|
||||
mod present;
|
||||
mod queue;
|
||||
mod ray_tracing;
|
||||
mod render_pass;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct GlobalReport {
|
||||
@@ -46,7 +54,6 @@ impl Global {
|
||||
instance_desc: wgt::InstanceDescriptor,
|
||||
telemetry: Option<hal::Telemetry>,
|
||||
) -> Self {
|
||||
profiling::scope!("Global::new");
|
||||
Self {
|
||||
instance: Instance::new(name, instance_desc, telemetry),
|
||||
surfaces: Registry::new(),
|
||||
@@ -58,8 +65,6 @@ impl Global {
|
||||
///
|
||||
/// Refer to the creation of wgpu-hal Instance for every backend.
|
||||
pub unsafe fn from_hal_instance<A: hal::Api>(name: &str, hal_instance: A::Instance) -> Self {
|
||||
profiling::scope!("Global::new");
|
||||
|
||||
Self {
|
||||
instance: Instance::from_hal_instance::<A>(name.to_owned(), hal_instance),
|
||||
surfaces: Registry::new(),
|
||||
@@ -78,7 +83,6 @@ impl Global {
|
||||
///
|
||||
/// - The raw handles obtained from the Instance must not be manually destroyed
|
||||
pub unsafe fn from_instance(instance: Arc<Instance>) -> Self {
|
||||
profiling::scope!("Global::new");
|
||||
Self {
|
||||
instance,
|
||||
surfaces: Registry::new(),
|
||||
@@ -293,14 +297,6 @@ impl fmt::Debug for Global {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Global {
|
||||
fn drop(&mut self) {
|
||||
profiling::scope!("Global::drop");
|
||||
resource_log!("Global::drop");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(send_sync)]
|
||||
fn _test_send_sync(global: &Global) {
|
||||
fn test_internal<T: Send + Sync>(_: T) {}
|
||||
test_internal(global)
|
||||
@@ -0,0 +1,48 @@
|
||||
use wgpu_core::present::{SurfaceError, SurfaceOutput};
|
||||
use wgt::SurfaceStatus;
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id;
|
||||
|
||||
impl Global {
|
||||
pub fn surface_get_current_texture(
|
||||
&self,
|
||||
surface_id: id::SurfaceId,
|
||||
texture_id_in: Option<id::TextureId>,
|
||||
) -> Result<SurfaceOutput<id::TextureId>, SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
let fid = self.hub.textures.prepare(texture_id_in);
|
||||
|
||||
let output = surface.get_current_texture()?;
|
||||
|
||||
let status = output.status;
|
||||
let texture_id = output.texture.map(|texture| fid.assign(texture));
|
||||
|
||||
Ok(SurfaceOutput {
|
||||
status,
|
||||
texture: texture_id,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn surface_present(
|
||||
&self,
|
||||
surface_id: id::SurfaceId,
|
||||
) -> Result<SurfaceStatus, SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.present()
|
||||
}
|
||||
|
||||
pub fn surface_texture_discard(&self, surface_id: id::SurfaceId) -> Result<(), SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.discard()
|
||||
}
|
||||
|
||||
pub fn surface_texture_release(&self, surface_id: id::SurfaceId) -> Result<(), SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.release()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
use core::ptr::NonNull;
|
||||
|
||||
use wgpu_core::device::queue::{QueueSubmitError, QueueWriteError, SubmittedWorkDoneClosure};
|
||||
use wgpu_core::ray_tracing::CompactBlasError;
|
||||
use wgpu_core::SubmissionIndex;
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id::{BlasId, BufferId, CommandBufferId, QueueId, StagingBufferId, TextureId};
|
||||
|
||||
impl Global {
|
||||
pub fn queue_write_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: BufferId,
|
||||
buffer_offset: wgt::BufferAddress,
|
||||
data: &[u8],
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
|
||||
queue.write_buffer(buffer, buffer_offset, data)
|
||||
}
|
||||
|
||||
pub fn queue_create_staging_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_size: wgt::BufferSize,
|
||||
id_in: Option<StagingBufferId>,
|
||||
) -> Result<(StagingBufferId, NonNull<u8>), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let (staging_buffer, ptr) = queue.create_staging_buffer(buffer_size)?;
|
||||
|
||||
let fid = self.hub.staging_buffers.prepare(id_in);
|
||||
let id = fid.assign(staging_buffer);
|
||||
|
||||
Ok((id, ptr))
|
||||
}
|
||||
|
||||
pub fn queue_write_staging_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: BufferId,
|
||||
buffer_offset: wgt::BufferAddress,
|
||||
staging_buffer_id: StagingBufferId,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
let staging_buffer = self.hub.staging_buffers.remove(staging_buffer_id);
|
||||
queue.write_staging_buffer(buffer, buffer_offset, staging_buffer)
|
||||
}
|
||||
|
||||
pub fn queue_validate_write_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: BufferId,
|
||||
buffer_offset: u64,
|
||||
buffer_size: wgt::BufferSize,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
queue.validate_write_buffer(buffer, buffer_offset, buffer_size)
|
||||
}
|
||||
|
||||
pub fn queue_write_texture(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
data: &[u8],
|
||||
data_layout: &wgt::TexelCopyBufferLayout,
|
||||
size: &wgt::Extent3d,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let texture = self.hub.textures.get(destination.texture);
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture,
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
|
||||
queue.write_texture(destination, data, data_layout, size)
|
||||
}
|
||||
|
||||
pub fn queue_submit(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
command_buffer_ids: &[CommandBufferId],
|
||||
) -> Result<SubmissionIndex, (SubmissionIndex, QueueSubmitError)> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let command_buffer_guard = self.hub.command_buffers.read();
|
||||
let command_buffers = command_buffer_ids
|
||||
.iter()
|
||||
.map(|id| command_buffer_guard.get(*id))
|
||||
.collect::<Vec<_>>();
|
||||
drop(command_buffer_guard);
|
||||
queue.submit(&command_buffers)
|
||||
}
|
||||
|
||||
pub fn queue_get_timestamp_period(&self, queue_id: QueueId) -> f32 {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
|
||||
queue.get_timestamp_period()
|
||||
}
|
||||
|
||||
pub fn queue_on_submitted_work_done(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
closure: SubmittedWorkDoneClosure,
|
||||
) -> SubmissionIndex {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let result = queue.on_submitted_work_done(closure);
|
||||
result.unwrap_or(0) // '0' means no wait is necessary
|
||||
}
|
||||
|
||||
pub fn queue_compact_blas(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
blas_id: BlasId,
|
||||
id_in: Option<BlasId>,
|
||||
) -> (BlasId, Option<u64>, Option<CompactBlasError>) {
|
||||
let fid = self.hub.blas_s.prepare(id_in);
|
||||
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let blas = self.hub.blas_s.get(blas_id);
|
||||
|
||||
let (blas, error) = queue.compact_blas(&blas);
|
||||
|
||||
let handle = blas.handle();
|
||||
let id = fid.assign(blas);
|
||||
|
||||
(id, handle, error)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
use wgpu_core::ray_tracing::{BlasPrepareCompactError, CreateBlasError, CreateTlasError};
|
||||
use wgpu_core::resource::{self, BlasCompactCallback, InvalidResourceError};
|
||||
use wgpu_core::SubmissionIndex;
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id::{self, BlasId, TlasId};
|
||||
|
||||
impl Global {
|
||||
pub fn device_create_blas(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &resource::BlasDescriptor,
|
||||
sizes: wgt::BlasGeometrySizeDescriptors,
|
||||
id_in: Option<BlasId>,
|
||||
) -> (BlasId, Option<u64>, Option<CreateBlasError>) {
|
||||
let fid = self.hub.blas_s.prepare(id_in);
|
||||
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
let (blas, error) = device.create_blas(desc, sizes);
|
||||
|
||||
let handle = blas.handle();
|
||||
|
||||
let id = fid.assign(blas);
|
||||
|
||||
(id, handle, error)
|
||||
}
|
||||
|
||||
pub fn device_create_tlas(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &resource::TlasDescriptor,
|
||||
id_in: Option<TlasId>,
|
||||
) -> (TlasId, Option<CreateTlasError>) {
|
||||
let fid = self.hub.tlas_s.prepare(id_in);
|
||||
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
let (tlas, error) = device.create_tlas(desc);
|
||||
|
||||
let id = fid.assign(tlas);
|
||||
|
||||
(id, error)
|
||||
}
|
||||
|
||||
pub fn blas_drop(&self, blas_id: BlasId) {
|
||||
let _blas = self.hub.blas_s.remove(blas_id);
|
||||
}
|
||||
|
||||
pub fn tlas_drop(&self, tlas_id: TlasId) {
|
||||
let _tlas = self.hub.tlas_s.remove(tlas_id);
|
||||
}
|
||||
|
||||
pub fn blas_prepare_compact_async(
|
||||
&self,
|
||||
blas_id: BlasId,
|
||||
callback: Option<BlasCompactCallback>,
|
||||
) -> Result<SubmissionIndex, BlasPrepareCompactError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(blas_id);
|
||||
|
||||
blas.prepare_compact_async(callback)
|
||||
}
|
||||
|
||||
pub fn ready_for_compaction(&self, blas_id: BlasId) -> Result<bool, InvalidResourceError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(blas_id);
|
||||
|
||||
blas.ready_for_compaction()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,783 @@
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::sync::Arc;
|
||||
use core::num::NonZeroU32;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use wgpu_core::command::{
|
||||
CommandEncoderError, EncoderStateError, PassStateError, PassTimestampWrites, RenderPass,
|
||||
RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassError,
|
||||
ResolvedRenderPassDescriptor,
|
||||
};
|
||||
use wgpu_core::Label;
|
||||
use wgt::{BufferAddress, BufferSize, Color, DynamicOffset, IndexFormat};
|
||||
|
||||
use crate::global::Global;
|
||||
use crate::id;
|
||||
|
||||
/// Describes the attachments of a render pass.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct RenderPassDescriptor<'a> {
|
||||
pub label: Label<'a>,
|
||||
/// The color attachments of the render pass.
|
||||
pub color_attachments: Cow<'a, [Option<RenderPassColorAttachment<id::TextureViewId>>]>,
|
||||
/// The depth and stencil attachment of the render pass, if any.
|
||||
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachment<id::TextureViewId>>,
|
||||
/// Defines where and when timestamp values will be written for this pass.
|
||||
pub timestamp_writes: Option<PassTimestampWrites<id::QuerySetId>>,
|
||||
/// Defines where the occlusion query results will be stored for this pass.
|
||||
pub occlusion_query_set: Option<id::QuerySetId>,
|
||||
/// The multiview array layers that will be used
|
||||
pub multiview_mask: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// Creates a render pass.
|
||||
///
|
||||
/// If creation fails, an invalid pass is returned. Attempting to record
|
||||
/// commands into an invalid pass is permitted, but a validation error will
|
||||
/// ultimately be generated when the parent encoder is finished, and it is
|
||||
/// not possible to run any commands from the invalid pass.
|
||||
///
|
||||
/// If successful, puts the encoder into the [`Locked`] state.
|
||||
///
|
||||
/// [`Locked`]: crate::command::CommandEncoderStatus::Locked
|
||||
pub fn command_encoder_begin_render_pass(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor<'_>,
|
||||
) -> (RenderPass, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let texture_views = hub.texture_views.read();
|
||||
let query_sets = hub.query_sets.read();
|
||||
|
||||
let desc = ResolvedRenderPassDescriptor {
|
||||
label: desc.label.as_deref().map(Cow::Borrowed),
|
||||
color_attachments: Cow::Owned(
|
||||
desc.color_attachments
|
||||
.iter()
|
||||
.map(|at| {
|
||||
at.as_ref().map(|at| RenderPassColorAttachment {
|
||||
view: texture_views.get(at.view),
|
||||
depth_slice: at.depth_slice,
|
||||
resolve_target: at
|
||||
.resolve_target
|
||||
.as_ref()
|
||||
.map(|rt| texture_views.get(*rt)),
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
depth_stencil_attachment: desc.depth_stencil_attachment.as_ref().map(|at| {
|
||||
RenderPassDepthStencilAttachment {
|
||||
view: texture_views.get(at.view),
|
||||
depth: at.depth.clone(),
|
||||
stencil: at.stencil.clone(),
|
||||
}
|
||||
}),
|
||||
timestamp_writes: desc
|
||||
.timestamp_writes
|
||||
.as_ref()
|
||||
.map(|tw| PassTimestampWrites {
|
||||
query_set: query_sets.get(tw.query_set),
|
||||
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,
|
||||
end_of_pass_write_index: tw.end_of_pass_write_index,
|
||||
}),
|
||||
occlusion_query_set: desc
|
||||
.occlusion_query_set
|
||||
.as_ref()
|
||||
.map(|query_set| query_sets.get(*query_set)),
|
||||
multiview_mask: desc.multiview_mask,
|
||||
};
|
||||
|
||||
drop(texture_views);
|
||||
drop(query_sets);
|
||||
|
||||
cmd_enc.begin_render_pass(desc)
|
||||
}
|
||||
|
||||
pub fn command_encoder_begin_render_pass_with_id(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor<'_>,
|
||||
id_in: Option<id::RenderPassEncoderId>,
|
||||
) -> (id::RenderPassEncoderId, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
let fid = hub.render_passes.prepare(id_in);
|
||||
let (render_pass, error) = self.command_encoder_begin_render_pass(encoder_id, desc);
|
||||
// no lock rank here because only one thread should be using renderpass
|
||||
// and it's only used by id variants of render pass methods on global
|
||||
// so no deadlock (or concurrent lock) should happen in practise
|
||||
let id = fid.assign(Arc::new(Mutex::new(render_pass)));
|
||||
(id, error)
|
||||
}
|
||||
|
||||
pub fn render_pass_end(&self, pass: &mut RenderPass) -> Result<(), EncoderStateError> {
|
||||
pass.end()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be accessed concurrently");
|
||||
self.render_pass_end(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_drop(&self, pass: id::RenderPassEncoderId) {
|
||||
self.hub.render_passes.remove(pass);
|
||||
}
|
||||
}
|
||||
|
||||
// Recording a render pass.
|
||||
//
|
||||
// The only error that should be returned from these methods is
|
||||
// `EncoderStateError::Ended`, when the pass has already ended and an immediate
|
||||
// validation error is raised.
|
||||
//
|
||||
// All other errors should be stored in the pass for later reporting when
|
||||
// `CommandEncoder.finish()` is called.
|
||||
impl Global {
|
||||
pub fn render_pass_set_bind_group(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_bind_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_bind_group(&mut pass, index, bind_group_id, offsets)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_pipeline(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pipeline = self.resolve_render_pipeline_id(pipeline_id);
|
||||
pass.set_pipeline(pipeline)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_pipeline_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_pipeline(&mut pass, pipeline_id)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_index_buffer(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
index_format: IndexFormat,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_index_buffer(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
index_format,
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_index_buffer_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
index_format: IndexFormat,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_index_buffer(&mut pass, buffer_id, index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_vertex_buffer(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.resolve_buffer_id(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_vertex_buffer_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_vertex_buffer(&mut pass, slot, buffer_id, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_blend_constant(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
color: Color,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_blend_constant(color)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_blend_constant_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
color: Color,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_blend_constant(&mut pass, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_stencil_reference(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
value: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_stencil_reference(value)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_stencil_reference_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
value: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_stencil_reference(&mut pass, value)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_viewport(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
depth_min: f32,
|
||||
depth_max: f32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_viewport(x, y, w, h, depth_min, depth_max)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_viewport_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
depth_min: f32,
|
||||
depth_max: f32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_viewport(&mut pass, x, y, w, h, depth_min, depth_max)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_scissor_rect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_scissor_rect(x, y, w, h)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_scissor_rect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_scissor_rect(&mut pass, x, y, w, h)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_immediates(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_immediates_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_immediates(&mut pass, offset, data)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw(
|
||||
&mut pass,
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indexed(
|
||||
&mut pass,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_mesh_tasks(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
group_count_x: u32,
|
||||
group_count_y: u32,
|
||||
group_count_z: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.draw_mesh_tasks(group_count_x, group_count_y, group_count_z)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indirect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indexed_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_indirect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indexed_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_mesh_tasks_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.draw_mesh_tasks_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indexed_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indexed_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_mesh_tasks_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.multi_draw_mesh_tasks_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indexed_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indexed_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_mesh_tasks_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.multi_draw_mesh_tasks_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_push_debug_group(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.push_debug_group(label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_push_debug_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_push_debug_group(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_pop_debug_group(&self, pass: &mut RenderPass) -> Result<(), PassStateError> {
|
||||
pass.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_pass_pop_debug_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_pop_debug_group(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_insert_debug_marker(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.insert_debug_marker(label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_insert_debug_marker_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_insert_debug_marker(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_write_timestamp(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.write_timestamp(self.resolve_query_set_id(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_write_timestamp_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_write_timestamp(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_occlusion_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.begin_occlusion_query(query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_occlusion_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_begin_occlusion_query(&mut pass, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_end_occlusion_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_occlusion_query()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_occlusion_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_end_occlusion_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.begin_pipeline_statistics_query(self.resolve_query_set_id(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_begin_pipeline_statistics_query(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_end_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_pipeline_statistics_query()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_end_pipeline_statistics_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_execute_bundles(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
render_bundle_ids: &[id::RenderBundleId],
|
||||
) -> Result<(), PassStateError> {
|
||||
let hub = &self.hub;
|
||||
let bundles = hub.render_bundles.read();
|
||||
let render_bundles = render_bundle_ids
|
||||
.iter()
|
||||
.map(|&id| bundles.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
pass.execute_bundles(&render_bundles)
|
||||
}
|
||||
|
||||
pub fn render_pass_execute_bundles_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
render_bundle_ids: &[id::RenderBundleId],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_execute_bundles(&mut pass, render_bundle_ids)
|
||||
}
|
||||
}
|
||||
@@ -101,34 +101,20 @@ flagged as errors as well.
|
||||
[wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E
|
||||
[WebGPU]: https://www.w3.org/TR/webgpu/
|
||||
|
||||
## IDs and tracing
|
||||
|
||||
As of `wgpu` v27, commands are encoded all at once when
|
||||
`CommandEncoder::finish` is called, not when the encoding methods are
|
||||
called for each command. This implies storing a representation of the
|
||||
commands in memory until `finish` is called. `Arc`s are more suitable
|
||||
for this purpose than numeric ids. Rather than redundantly store both
|
||||
`Id`s and `Arc`s, tracing has been changed to work with `Arc`s. The
|
||||
serialized trace identifies resources by the integer value of
|
||||
`Arc::as_ptr`. These IDs have the type [`crate::id::PointerId`]. The
|
||||
trace player uses hash maps to go from `PointerId`s to `Arc`s
|
||||
when replaying a trace.
|
||||
|
||||
*/
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use core::fmt::Debug;
|
||||
|
||||
use crate::{
|
||||
use crate::registry::{Registry, RegistryReport};
|
||||
use wgpu_core::{
|
||||
binding_model::{BindGroup, BindGroupLayout, PipelineLayout},
|
||||
command::{
|
||||
CommandBuffer, CommandEncoder, ComputePass, RenderBundle, RenderBundleEncoder, RenderPass,
|
||||
},
|
||||
device::{queue::Queue, Device},
|
||||
instance::Adapter,
|
||||
lock::rank,
|
||||
pipeline::{ComputePipeline, PipelineCache, RenderPipeline, ShaderModule},
|
||||
registry::{Registry, RegistryReport},
|
||||
resource::{
|
||||
Blas, Buffer, ExternalTexture, QuerySet, Sampler, StagingBuffer, Texture, TextureView, Tlas,
|
||||
},
|
||||
@@ -233,22 +219,22 @@ impl Hub {
|
||||
pipeline_layouts: Registry::new(),
|
||||
shader_modules: Registry::new(),
|
||||
bind_group_layouts: Registry::new(),
|
||||
bind_groups: Registry::with_rank(rank::HUB_BIND_GROUPS),
|
||||
bind_groups: Registry::new(),
|
||||
command_encoders: Registry::new(),
|
||||
command_buffers: Registry::new(),
|
||||
render_bundles: Registry::new(),
|
||||
render_pipelines: Registry::with_rank(rank::HUB_RENDER_PIPELINES),
|
||||
render_pipelines: Registry::new(),
|
||||
compute_pipelines: Registry::new(),
|
||||
pipeline_caches: Registry::new(),
|
||||
query_sets: Registry::new(),
|
||||
buffers: Registry::new(),
|
||||
staging_buffers: Registry::new(),
|
||||
textures: Registry::new(),
|
||||
texture_views: Registry::with_rank(rank::HUB_TEXTURE_VIEWS),
|
||||
external_textures: Registry::with_rank(rank::HUB_EXTERNAL_TEXTURES),
|
||||
samplers: Registry::with_rank(rank::HUB_SAMPLERS),
|
||||
texture_views: Registry::new(),
|
||||
external_textures: Registry::new(),
|
||||
samplers: Registry::new(),
|
||||
blas_s: Registry::new(),
|
||||
tlas_s: Registry::with_rank(rank::HUB_TLAS),
|
||||
tlas_s: Registry::new(),
|
||||
render_passes: Registry::new(),
|
||||
compute_passes: Registry::new(),
|
||||
render_bundle_encoders: Registry::new(),
|
||||
@@ -0,0 +1,278 @@
|
||||
use crate::{Epoch, Index};
|
||||
use core::{
|
||||
cmp::Ordering,
|
||||
fmt::{self, Debug},
|
||||
hash::Hash,
|
||||
marker::PhantomData,
|
||||
num::NonZeroU64,
|
||||
};
|
||||
pub use wgpu_core::id::markers;
|
||||
pub use wgpu_core::id::Marker;
|
||||
|
||||
const _: () = {
|
||||
if size_of::<Index>() != 4 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
const _: () = {
|
||||
if size_of::<Epoch>() != 4 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
const _: () = {
|
||||
if size_of::<RawId>() != 8 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
|
||||
/// The raw underlying representation of an identifier.
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(into = "SerialId"))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(serde::Deserialize),
|
||||
serde(try_from = "SerialId")
|
||||
)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct RawId(NonZeroU64);
|
||||
|
||||
impl RawId {
|
||||
/// Zip together an identifier and return its raw underlying representation.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If both ID components are zero.
|
||||
pub fn zip(index: Index, epoch: Epoch) -> RawId {
|
||||
let v = (index as u64) | ((epoch as u64) << 32);
|
||||
Self(NonZeroU64::new(v).expect("IDs may not be zero"))
|
||||
}
|
||||
|
||||
/// Unzip a raw identifier into its components.
|
||||
pub fn unzip(self) -> (Index, Epoch) {
|
||||
(self.0.get() as Index, (self.0.get() >> 32) as Epoch)
|
||||
}
|
||||
}
|
||||
|
||||
/// An identifier for a wgpu object.
|
||||
///
|
||||
/// An `Id<T>` value identifies a value stored in a [`Global`]'s [`Hub`].
|
||||
///
|
||||
/// [`Global`]: crate::global::Global
|
||||
/// [`Hub`]: crate::hub::Hub
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
pub struct Id<T: Marker>(RawId, PhantomData<T>);
|
||||
|
||||
// This type represents Id in a more readable (and editable) way.
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SerialId {
|
||||
// The only variant forces RON to not ignore "Id"
|
||||
Id(Index, Epoch),
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl From<RawId> for SerialId {
|
||||
fn from(id: RawId) -> Self {
|
||||
let (index, epoch) = id.unzip();
|
||||
Self::Id(index, epoch)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
pub struct ZeroIdError;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl fmt::Display for ZeroIdError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "IDs may not be zero")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl TryFrom<SerialId> for RawId {
|
||||
type Error = ZeroIdError;
|
||||
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
|
||||
let SerialId::Id(index, epoch) = id;
|
||||
if index == 0 && epoch == 0 {
|
||||
Err(ZeroIdError)
|
||||
} else {
|
||||
Ok(RawId::zip(index, epoch))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
/// # Safety
|
||||
///
|
||||
/// The raw id must be valid for the type.
|
||||
pub unsafe fn from_raw(raw: RawId) -> Self {
|
||||
Self(raw, PhantomData)
|
||||
}
|
||||
|
||||
/// Coerce the identifiers into its raw underlying representation.
|
||||
pub fn into_raw(self) -> RawId {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn zip(index: Index, epoch: Epoch) -> Self {
|
||||
Id(RawId::zip(index, epoch), PhantomData)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unzip(self) -> (Index, Epoch) {
|
||||
self.0.unzip()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Copy for Id<T> where T: Marker {}
|
||||
|
||||
impl<T> Clone for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let (index, epoch) = self.unzip();
|
||||
write!(formatter, "{}Id({index},{epoch})", T::TYPE)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Id<T> where T: Marker {}
|
||||
|
||||
impl<T> PartialOrd for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Ord for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.cmp(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Define identifiers for each resource.
|
||||
macro_rules! ids {
|
||||
($(
|
||||
$(#[$($meta:meta)*])*
|
||||
pub type $name:ident $marker:ident;
|
||||
)*) => {
|
||||
$(
|
||||
$(#[$($meta)*])*
|
||||
pub type $name = Id<wgpu_core::id::markers::$marker>;
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
ids! {
|
||||
pub type AdapterId Adapter;
|
||||
pub type SurfaceId Surface;
|
||||
pub type DeviceId Device;
|
||||
pub type QueueId Queue;
|
||||
pub type BufferId Buffer;
|
||||
pub type StagingBufferId StagingBuffer;
|
||||
pub type TextureViewId TextureView;
|
||||
pub type TextureId Texture;
|
||||
pub type ExternalTextureId ExternalTexture;
|
||||
pub type SamplerId Sampler;
|
||||
pub type BindGroupLayoutId BindGroupLayout;
|
||||
pub type PipelineLayoutId PipelineLayout;
|
||||
pub type BindGroupId BindGroup;
|
||||
pub type ShaderModuleId ShaderModule;
|
||||
pub type RenderPipelineId RenderPipeline;
|
||||
pub type ComputePipelineId ComputePipeline;
|
||||
pub type PipelineCacheId PipelineCache;
|
||||
pub type CommandEncoderId CommandEncoder;
|
||||
pub type CommandBufferId CommandBuffer;
|
||||
pub type RenderPassEncoderId RenderPassEncoder;
|
||||
pub type ComputePassEncoderId ComputePassEncoder;
|
||||
pub type RenderBundleEncoderId RenderBundleEncoder;
|
||||
pub type RenderBundleId RenderBundle;
|
||||
pub type QuerySetId QuerySet;
|
||||
pub type BlasId Blas;
|
||||
pub type TlasId Tlas;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_id() {
|
||||
struct TestMarker;
|
||||
|
||||
impl Marker for TestMarker {
|
||||
const TYPE: &'static str = "TestMarker";
|
||||
}
|
||||
|
||||
let indexes = [0, Index::MAX / 2 - 1, Index::MAX / 2 + 1, Index::MAX];
|
||||
let epochs = [1, Epoch::MAX / 2 - 1, Epoch::MAX / 2 + 1, Epoch::MAX];
|
||||
for &i in &indexes {
|
||||
for &e in &epochs {
|
||||
let id = Id::<TestMarker>::zip(i, e);
|
||||
let (index, epoch) = id.unzip();
|
||||
assert_eq!(index, i);
|
||||
assert_eq!(epoch, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Reference wgpu objects via numeric IDs assigned by [`crate::identity::IdentityManager`].
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IdReferences;
|
||||
|
||||
impl wgpu_core::command::ReferenceType for IdReferences {
|
||||
type Buffer = BufferId;
|
||||
type Surface = SurfaceId;
|
||||
type Texture = TextureId;
|
||||
type TextureView = TextureViewId;
|
||||
type ExternalTexture = ExternalTextureId;
|
||||
type QuerySet = QuerySetId;
|
||||
type BindGroup = BindGroupId;
|
||||
type RenderPipeline = RenderPipelineId;
|
||||
type RenderBundle = RenderBundleId;
|
||||
type ComputePipeline = ComputePipelineId;
|
||||
type Blas = BlasId;
|
||||
type Tlas = TlasId;
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::{fmt::Debug, marker::PhantomData};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{
|
||||
id::{Id, Marker},
|
||||
lock::{rank, Mutex},
|
||||
Epoch, Index,
|
||||
};
|
||||
use crate::{id::Id, id::Marker, Epoch, Index};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
enum IdSource {
|
||||
@@ -135,20 +132,23 @@ impl<T: Marker> IdentityManager<T> {
|
||||
impl<T: Marker> IdentityManager<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
values: Mutex::new(
|
||||
rank::IDENTITY_MANAGER_VALUES,
|
||||
IdentityValues {
|
||||
free: Vec::new(),
|
||||
next_index: 0,
|
||||
count: 0,
|
||||
id_source: IdSource::None,
|
||||
},
|
||||
),
|
||||
values: Mutex::new(IdentityValues {
|
||||
free: Vec::new(),
|
||||
next_index: 0,
|
||||
count: 0,
|
||||
id_source: IdSource::None,
|
||||
}),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Marker> Default for IdentityManager<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_epoch_end_of_life() {
|
||||
use crate::id;
|
||||
@@ -0,0 +1,35 @@
|
||||
#![allow(
|
||||
// Need many arguments for some core functions to be able to re-use code in many situations.
|
||||
clippy::too_many_arguments,
|
||||
)]
|
||||
#![warn(
|
||||
clippy::alloc_instead_of_core,
|
||||
clippy::ptr_as_ptr,
|
||||
clippy::std_instead_of_alloc,
|
||||
clippy::std_instead_of_core,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unsafe_op_in_unsafe_fn,
|
||||
unused_extern_crates,
|
||||
unused_qualifications
|
||||
)]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate wgpu_hal as hal;
|
||||
extern crate wgpu_types as wgt;
|
||||
|
||||
pub type TexelCopyBufferInfo = wgt::TexelCopyBufferInfo<id::BufferId>;
|
||||
pub type TexelCopyTextureInfo = wgt::TexelCopyTextureInfo<id::TextureId>;
|
||||
pub type CopyExternalImageDestInfo = wgt::CopyExternalImageDestInfo<id::TextureId>;
|
||||
|
||||
pub type Command = wgpu_core::command::Command<id::IdReferences>;
|
||||
|
||||
pub mod global;
|
||||
pub mod hub;
|
||||
pub mod id;
|
||||
pub mod identity;
|
||||
pub mod registry;
|
||||
pub mod storage;
|
||||
|
||||
type Index = u32;
|
||||
type Epoch = u32;
|
||||
@@ -1,12 +1,9 @@
|
||||
use alloc::sync::Arc;
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
|
||||
use crate::{
|
||||
id::Id,
|
||||
identity::IdentityManager,
|
||||
lock::{
|
||||
rank::{self, LockRank},
|
||||
RwLock, RwLockReadGuard,
|
||||
},
|
||||
storage::{Element, Storage, StorageItem},
|
||||
};
|
||||
|
||||
@@ -49,13 +46,9 @@ pub(crate) struct Registry<T: StorageItem> {
|
||||
|
||||
impl<T: StorageItem> Registry<T> {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self::with_rank(rank::HUB_OTHER)
|
||||
}
|
||||
|
||||
pub(crate) fn with_rank(rank: LockRank) -> Self {
|
||||
Self {
|
||||
identity: Arc::new(IdentityManager::new()),
|
||||
storage: RwLock::new(rank, Storage::new()),
|
||||
storage: RwLock::new(Storage::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +130,9 @@ impl<T: StorageItem + Clone> Registry<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Registry;
|
||||
use crate::{id::Marker, resource::ResourceType, storage::StorageItem};
|
||||
use crate::{id::Marker, storage::StorageItem};
|
||||
use alloc::sync::Arc;
|
||||
use wgpu_core::resource::ResourceType;
|
||||
|
||||
struct TestData;
|
||||
struct TestDataId;
|
||||
@@ -0,0 +1,201 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
|
||||
use crate::id::Id;
|
||||
use crate::{Epoch, Index};
|
||||
pub use wgpu_core::storage::StorageItem;
|
||||
|
||||
/// An entry in a `Storage::map` table.
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Element<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
/// There are no live ids with this index.
|
||||
Vacant,
|
||||
|
||||
/// There is one live id with this index, allocated at the given
|
||||
/// epoch.
|
||||
Occupied(T, Epoch),
|
||||
}
|
||||
|
||||
/// A table of `T` values indexed by the id type `I`.
|
||||
///
|
||||
/// `Storage` implements [`core::ops::Index`], accepting `Id` values as
|
||||
/// indices.
|
||||
///
|
||||
/// The table is represented as a vector indexed by the ids' index
|
||||
/// values, so you should use an id allocator like `IdentityManager`
|
||||
/// that keeps the index values dense and close to zero.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) map: Vec<Element<T>>,
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) fn new() -> Self {
|
||||
Self { map: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) fn insert(&mut self, id: Id<T::Marker>, value: T) {
|
||||
let (index, epoch) = id.unzip();
|
||||
let index = index as usize;
|
||||
if index >= self.map.len() {
|
||||
self.map.resize_with(index + 1, || Element::Vacant);
|
||||
}
|
||||
match mem::replace(&mut self.map[index], Element::Occupied(value, epoch)) {
|
||||
Element::Vacant => {}
|
||||
Element::Occupied(_, storage_epoch) => {
|
||||
panic!(
|
||||
"Cannot insert {id:?}, found existing resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index as Index, storage_epoch),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn remove(&mut self, id: Id<T::Marker>) -> T {
|
||||
let (index, epoch) = id.unzip();
|
||||
let stored = self.map.get_mut(index as usize);
|
||||
match stored.map(|stored| mem::replace(stored, Element::Vacant)) {
|
||||
Some(Element::Occupied(value, storage_epoch)) => {
|
||||
assert_eq!(
|
||||
epoch,
|
||||
storage_epoch,
|
||||
"Cannot remove {id:?}, found other resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index, storage_epoch),
|
||||
);
|
||||
value
|
||||
}
|
||||
None | Some(Element::Vacant) => {
|
||||
panic!("Cannot remove non-existent resource {id:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = (Id<T::Marker>, &T)> {
|
||||
self.map
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(move |(index, x)| match *x {
|
||||
Element::Occupied(ref value, storage_epoch) => {
|
||||
Some((Id::zip(index as Index, storage_epoch), value))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem + Clone,
|
||||
{
|
||||
/// Get an owned reference to an item.
|
||||
/// Panics if there is an epoch mismatch, the entry is empty or in error.
|
||||
pub(crate) fn get(&self, id: Id<T::Marker>) -> T {
|
||||
let (index, epoch) = id.unzip();
|
||||
let (result, storage_epoch) = match self.map.get(index as usize) {
|
||||
Some(&Element::Occupied(ref v, epoch)) => (v.clone(), epoch),
|
||||
None | Some(&Element::Vacant) => {
|
||||
panic!("Cannot get non-existent resource {id:?}");
|
||||
}
|
||||
};
|
||||
assert_eq!(
|
||||
epoch,
|
||||
storage_epoch,
|
||||
"Cannot get {id:?}, found other resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index, storage_epoch),
|
||||
);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::id::Marker;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct TestItem;
|
||||
|
||||
impl wgpu_core::resource::ResourceType for TestItem {
|
||||
const TYPE: &'static str = "TestItem";
|
||||
}
|
||||
|
||||
struct TestMarker;
|
||||
|
||||
impl Marker for TestMarker {
|
||||
const TYPE: &'static str = "TestMarker";
|
||||
}
|
||||
|
||||
impl StorageItem for TestItem {
|
||||
type Marker = TestMarker;
|
||||
}
|
||||
|
||||
fn id(index: Index, epoch: Epoch) -> Id<TestMarker> {
|
||||
Id::zip(index, epoch)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Cannot insert UntypedId(0,1), found existing resource UntypedId(0,1)"
|
||||
)]
|
||||
fn insert_occupied_same_epoch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Cannot insert UntypedId(0,2), found existing resource UntypedId(0,1)"
|
||||
)]
|
||||
fn insert_occupied_different_epoch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.insert(id(0, 2), TestItem);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot remove UntypedId(0,2), found other resource UntypedId(0,1)")]
|
||||
fn remove_epoch_mismatch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.remove(id(0, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot remove non-existent resource UntypedId(0,1)")]
|
||||
fn remove_vacant() {
|
||||
let mut storage = Storage::<TestItem>::new();
|
||||
storage.remove(id(0, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot get non-existent resource UntypedId(0,1)")]
|
||||
fn get_vacant() {
|
||||
let storage = Storage::<TestItem>::new();
|
||||
storage.get(id(0, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot get UntypedId(0,2), found other resource UntypedId(0,1)")]
|
||||
fn get_epoch_mismatch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.get(id(0, 2));
|
||||
}
|
||||
}
|
||||
+1
-171
@@ -3,16 +3,7 @@ use core::{mem::ManuallyDrop, ops::Deref};
|
||||
use alloc::sync::Arc;
|
||||
use hal::DynResource;
|
||||
|
||||
use crate::{
|
||||
global::Global,
|
||||
id::{
|
||||
AdapterId, BlasId, BufferId, CommandEncoderId, DeviceId, QueueId, SurfaceId, TextureId,
|
||||
TextureViewId, TlasId,
|
||||
},
|
||||
lock::RankData,
|
||||
resource::RawResourceAccess,
|
||||
snatch::SnatchGuard,
|
||||
};
|
||||
use crate::{lock::RankData, resource::RawResourceAccess, snatch::SnatchGuard};
|
||||
|
||||
/// A guard which holds alive a wgpu-core resource and dereferences to the Hal type.
|
||||
struct SimpleResourceGuard<Resource, HalType> {
|
||||
@@ -301,164 +292,3 @@ impl crate::resource::Tlas {
|
||||
SnatchableResourceGuard::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw buffer handle must not be manually destroyed
|
||||
pub unsafe fn buffer_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: BufferId,
|
||||
) -> Option<impl Deref<Target = A::Buffer>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let buffer = hub.buffers.get(id);
|
||||
|
||||
unsafe { buffer.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw texture handle must not be manually destroyed
|
||||
pub unsafe fn texture_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TextureId,
|
||||
) -> Option<impl Deref<Target = A::Texture>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let texture = hub.textures.get(id);
|
||||
|
||||
unsafe { texture.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw texture view handle must not be manually destroyed
|
||||
pub unsafe fn texture_view_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TextureViewId,
|
||||
) -> Option<impl Deref<Target = A::TextureView>> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let view = hub.texture_views.get(id);
|
||||
|
||||
unsafe { view.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw adapter handle must not be manually destroyed
|
||||
pub unsafe fn adapter_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: AdapterId,
|
||||
) -> Option<impl Deref<Target = A::Adapter>> {
|
||||
let hub = &self.hub;
|
||||
let adapter = hub.adapters.get(id);
|
||||
|
||||
unsafe { adapter.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw device handle must not be manually destroyed
|
||||
pub unsafe fn device_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: DeviceId,
|
||||
) -> Option<impl Deref<Target = A::Device>> {
|
||||
let device = self.hub.devices.get(id);
|
||||
|
||||
unsafe { device.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw fence handle must not be manually destroyed
|
||||
pub unsafe fn device_fence_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: DeviceId,
|
||||
) -> Option<impl Deref<Target = A::Fence>> {
|
||||
let device = self.hub.devices.get(id);
|
||||
|
||||
unsafe { device.fence_as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw surface handle must not be manually destroyed
|
||||
pub unsafe fn surface_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: SurfaceId,
|
||||
) -> Option<impl Deref<Target = A::Surface>> {
|
||||
let surface = self.surfaces.get(id);
|
||||
|
||||
unsafe { surface.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// Encode commands using the raw HAL command encoder.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If the command encoder has already been used with the wgpu encoding API.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw command encoder handle must not be manually destroyed
|
||||
pub unsafe fn command_encoder_as_hal_mut<
|
||||
A: hal::Api,
|
||||
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
||||
R,
|
||||
>(
|
||||
&self,
|
||||
id: CommandEncoderId,
|
||||
hal_command_encoder_callback: F,
|
||||
) -> R {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(id);
|
||||
unsafe { cmd_enc.as_hal_mut::<A, F, R>(hal_command_encoder_callback) }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw queue handle must not be manually destroyed
|
||||
pub unsafe fn queue_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: QueueId,
|
||||
) -> Option<impl Deref<Target = A::Queue>> {
|
||||
let queue = self.hub.queues.get(id);
|
||||
|
||||
unsafe { queue.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw blas handle must not be manually destroyed
|
||||
pub unsafe fn blas_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: BlasId,
|
||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||
profiling::scope!("Blas::as_hal");
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(id);
|
||||
|
||||
unsafe { blas.as_hal::<A>() }
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw tlas handle must not be manually destroyed
|
||||
pub unsafe fn tlas_as_hal<A: hal::Api>(
|
||||
&self,
|
||||
id: TlasId,
|
||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||
profiling::scope!("Tlas::as_hal");
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
let tlas = hub.tlas_s.get(id);
|
||||
|
||||
unsafe { tlas.as_hal::<A>() }
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ use crate::{
|
||||
AttachmentData, Device, DeviceError, MissingDownlevelFlags, MissingFeatures,
|
||||
RenderPassContext,
|
||||
},
|
||||
id, impl_resource_type, impl_storage_item,
|
||||
impl_resource_type, impl_storage_item,
|
||||
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
|
||||
pipeline::{PipelineFlags, RenderPipeline},
|
||||
resource::{
|
||||
@@ -1833,333 +1833,3 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::global::Global {
|
||||
pub fn render_bundle_encoder_set_bind_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[wgt::DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_bind_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[wgt::DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_pipeline(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_pipeline(self.hub.render_pipelines.get(pipeline_id))
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_pipeline_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_pipeline(self.hub.render_pipelines.get(pipeline_id))
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_vertex_buffer(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.hub.buffers.get(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_vertex_buffer_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.hub.buffers.get(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_index_buffer(
|
||||
&self,
|
||||
encoder: &mut RenderBundleEncoder,
|
||||
buffer: id::BufferId,
|
||||
index_format: wgt::IndexFormat,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
encoder.set_index_buffer(self.hub.buffers.get(buffer), index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_index_buffer_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer: id::BufferId,
|
||||
index_format: wgt::IndexFormat,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_index_buffer(self.hub.buffers.get(buffer), index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_immediates(
|
||||
&self,
|
||||
pass: &mut RenderBundleEncoder,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_set_immediates_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indirect(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indirect_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_indirect(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.draw_indexed_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_draw_indexed_indirect_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.draw_indexed_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_push_debug_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_push_debug_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_pop_debug_group(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_pop_debug_group_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_insert_debug_marker(
|
||||
&self,
|
||||
bundle: &mut RenderBundleEncoder,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
bundle.insert_debug_marker(label)
|
||||
}
|
||||
|
||||
pub fn render_bundle_encoder_insert_debug_marker_with_id(
|
||||
&self,
|
||||
bundle_encoder: id::RenderBundleEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), PassStateError> {
|
||||
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);
|
||||
|
||||
let mut bundle_encoder = bundle_encoder
|
||||
.try_lock()
|
||||
.expect("RenderBundleEncoders should not be accessed concurrently");
|
||||
|
||||
bundle_encoder.insert_debug_marker(label)
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,7 @@ use crate::{
|
||||
api_log,
|
||||
command::{encoder::EncodingState, ArcCommand, EncoderStateError},
|
||||
device::{DeviceError, MissingFeatures},
|
||||
get_lowest_common_denom,
|
||||
global::Global,
|
||||
hal_label,
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
get_lowest_common_denom, hal_label,
|
||||
init_tracker::{MemoryInitKind, TextureInitRange},
|
||||
resource::{
|
||||
Buffer, DestroyedResourceError, InvalidOrDestroyedResourceError, InvalidResourceError,
|
||||
@@ -148,34 +145,6 @@ impl super::CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_clear_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
dst: BufferId,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
cmd_enc.clear_buffer(hub.buffers.get(dst), offset, size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_clear_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
dst: TextureId,
|
||||
subresource_range: &ImageSubresourceRange,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
cmd_enc.clear_texture(hub.textures.get(dst), subresource_range)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn clear_buffer(
|
||||
state: &mut EncodingState,
|
||||
dst_buffer: Arc<Buffer>,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use parking_lot::Mutex;
|
||||
use thiserror::Error;
|
||||
use wgt::{
|
||||
error::{ErrorType, WebGpuError},
|
||||
@@ -28,7 +27,6 @@ use crate::{
|
||||
TransitionResourcesError,
|
||||
},
|
||||
device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures},
|
||||
global::Global,
|
||||
hal_label, id, impl_resource_type,
|
||||
init_tracker::MemoryInitKind,
|
||||
pipeline::ComputePipeline,
|
||||
@@ -594,79 +592,6 @@ impl ComputePass {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// Creates a compute pass.
|
||||
///
|
||||
/// If creation fails, an invalid pass is returned. Attempting to record
|
||||
/// commands into an invalid pass is permitted, but a validation error will
|
||||
/// ultimately be generated when the parent encoder is finished, and it is
|
||||
/// not possible to run any commands from the invalid pass.
|
||||
///
|
||||
/// If successful, puts the encoder into the [`Locked`] state.
|
||||
///
|
||||
/// [`Locked`]: crate::command::CommandEncoderStatus::Locked
|
||||
pub fn command_encoder_begin_compute_pass(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &ComputePassDescriptor<'_, PassTimestampWrites<id::QuerySetId>>,
|
||||
) -> (ComputePass, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let desc = ComputePassDescriptor {
|
||||
label: desc.label.as_deref().map(Cow::Borrowed),
|
||||
timestamp_writes: desc
|
||||
.timestamp_writes
|
||||
.as_ref()
|
||||
.map(|tw| PassTimestampWrites {
|
||||
query_set: hub.query_sets.get(tw.query_set),
|
||||
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,
|
||||
end_of_pass_write_index: tw.end_of_pass_write_index,
|
||||
}),
|
||||
};
|
||||
|
||||
cmd_enc.begin_compute_pass(&desc)
|
||||
}
|
||||
|
||||
pub fn command_encoder_begin_compute_pass_with_id(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &ComputePassDescriptor<'_, PassTimestampWrites<id::QuerySetId>>,
|
||||
id_in: Option<id::ComputePassEncoderId>,
|
||||
) -> (id::ComputePassEncoderId, Option<CommandEncoderError>) {
|
||||
let fid = self.hub.compute_passes.prepare(id_in);
|
||||
|
||||
let (pass, err) = self.command_encoder_begin_compute_pass(encoder_id, desc);
|
||||
|
||||
// no lock rank here because only one thread should be using compute pass
|
||||
// and it's only used by id variants of compute pass methods on global
|
||||
// so no deadlock (or concurrent lock) should happen in practise
|
||||
let id = fid.assign(Arc::new(Mutex::new(pass)));
|
||||
|
||||
(id, err)
|
||||
}
|
||||
|
||||
pub fn compute_pass_end(&self, pass: &mut ComputePass) -> Result<(), EncoderStateError> {
|
||||
pass.end()
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_end(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_drop(&self, pass_id: id::ComputePassEncoderId) {
|
||||
self.hub.compute_passes.remove(pass_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn encode_compute_pass(
|
||||
parent_state: &mut EncodingState<InnerCommandEncoder>,
|
||||
mut base: BasePass<ArcComputeCommand, Infallible>,
|
||||
@@ -1466,279 +1391,3 @@ impl ComputePass {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Recording a compute pass.
|
||||
//
|
||||
// The only error that should be returned from these methods is
|
||||
// `EncoderStateError::Ended`, when the pass has already ended and an immediate
|
||||
// validation error is raised.
|
||||
//
|
||||
// All other errors should be stored in the pass for later reporting when
|
||||
// `CommandEncoder.finish()` is called.
|
||||
//
|
||||
// The `pass_try!` macro should be used to handle errors appropriately. Note
|
||||
// that the `pass_try!` and `pass_base!` macros may return early from the
|
||||
// function that invokes them, like the `?` operator.
|
||||
impl Global {
|
||||
pub fn compute_pass_set_bind_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|bind_group_id| self.hub.bind_groups.get(bind_group_id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_bind_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_bind_group(&mut pass, index, bind_group_id, offsets)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_pipeline(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pipeline = self.hub.compute_pipelines.get(pipeline_id);
|
||||
pass.set_pipeline(pipeline)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_pipeline_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
pipeline_id: id::ComputePipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_pipeline(&mut pass, pipeline_id)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_immediates(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn compute_pass_set_immediates_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_set_immediates(&mut pass, offset, data)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
groups_x: u32,
|
||||
groups_y: u32,
|
||||
groups_z: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.dispatch_workgroups(groups_x, groups_y, groups_z)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
groups_x: u32,
|
||||
groups_y: u32,
|
||||
groups_z: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_dispatch_workgroups(&mut pass, groups_x, groups_y, groups_z)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_indirect(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.dispatch_workgroups_indirect(self.hub.buffers.get(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn compute_pass_dispatch_workgroups_indirect_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_dispatch_workgroups_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn compute_pass_push_debug_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.push_debug_group(label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_push_debug_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_push_debug_group(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_pop_debug_group(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn compute_pass_pop_debug_group_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_pop_debug_group(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_insert_debug_marker(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.insert_debug_marker(label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_insert_debug_marker_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_insert_debug_marker(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn compute_pass_write_timestamp(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let query_set = self.hub.query_sets.get(query_set_id);
|
||||
pass.write_timestamp(query_set, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_write_timestamp_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_write_timestamp(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_begin_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let query_set = self.hub.query_sets.get(query_set_id);
|
||||
pass.begin_pipeline_statistics_query(query_set, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_begin_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_begin_pipeline_statistics_query(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_pipeline_statistics_query()
|
||||
}
|
||||
|
||||
pub fn compute_pass_end_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass_id: id::ComputePassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.compute_passes.get(pass_id);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("ComputePasses should not be accessed concurrently");
|
||||
self.compute_pass_end_pipeline_statistics_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn compute_pass_transition_resources(
|
||||
&self,
|
||||
pass: &mut ComputePass,
|
||||
buffer_transitions: impl Iterator<Item = wgt::BufferTransition<id::BufferId>>,
|
||||
texture_transitions: impl Iterator<Item = wgt::TextureTransition<id::TextureViewId>>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.transition_resources(
|
||||
buffer_transitions.map(|bt| wgt::BufferTransition {
|
||||
buffer: self.hub.buffers.get(bt.buffer),
|
||||
state: bt.state,
|
||||
}),
|
||||
texture_transitions.map(|tt| wgt::TextureTransition {
|
||||
texture: self.hub.texture_views.get(tt.texture),
|
||||
selector: tt.selector,
|
||||
state: tt.state,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ use macro_rules_attribute::{apply, attribute_alias};
|
||||
|
||||
use crate::{
|
||||
command::ColorAttachments,
|
||||
id,
|
||||
instance::Surface,
|
||||
resource::{Buffer, QuerySet, Texture},
|
||||
};
|
||||
@@ -26,10 +25,6 @@ pub trait ReferenceType {
|
||||
type Tlas: Clone + core::fmt::Debug;
|
||||
}
|
||||
|
||||
/// Reference wgpu objects via numeric IDs assigned by [`crate::identity::IdentityManager`].
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IdReferences;
|
||||
|
||||
/// Reference wgpu objects via the integer value of pointers.
|
||||
///
|
||||
/// This is used for trace recording and playback. Recording stores the pointer
|
||||
@@ -44,35 +39,20 @@ pub struct PointerReferences;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ArcReferences;
|
||||
|
||||
impl ReferenceType for IdReferences {
|
||||
type Buffer = id::BufferId;
|
||||
type Surface = id::SurfaceId;
|
||||
type Texture = id::TextureId;
|
||||
type TextureView = id::TextureViewId;
|
||||
type ExternalTexture = id::ExternalTextureId;
|
||||
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;
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "trace", feature = "replay"))]
|
||||
impl ReferenceType for PointerReferences {
|
||||
type Buffer = id::PointerId<id::markers::Buffer>;
|
||||
type Surface = id::PointerId<id::markers::Surface>;
|
||||
type Texture = id::PointerId<id::markers::Texture>;
|
||||
type TextureView = id::PointerId<id::markers::TextureView>;
|
||||
type ExternalTexture = id::PointerId<id::markers::ExternalTexture>;
|
||||
type QuerySet = id::PointerId<id::markers::QuerySet>;
|
||||
type BindGroup = id::PointerId<id::markers::BindGroup>;
|
||||
type RenderPipeline = id::PointerId<id::markers::RenderPipeline>;
|
||||
type RenderBundle = id::PointerId<id::markers::RenderBundle>;
|
||||
type ComputePipeline = id::PointerId<id::markers::ComputePipeline>;
|
||||
type Blas = id::PointerId<id::markers::Blas>;
|
||||
type Tlas = id::PointerId<id::markers::Tlas>;
|
||||
type Buffer = crate::id::PointerId<crate::id::markers::Buffer>;
|
||||
type Surface = crate::id::PointerId<crate::id::markers::Surface>;
|
||||
type Texture = crate::id::PointerId<crate::id::markers::Texture>;
|
||||
type TextureView = crate::id::PointerId<crate::id::markers::TextureView>;
|
||||
type ExternalTexture = crate::id::PointerId<crate::id::markers::ExternalTexture>;
|
||||
type QuerySet = crate::id::PointerId<crate::id::markers::QuerySet>;
|
||||
type BindGroup = crate::id::PointerId<crate::id::markers::BindGroup>;
|
||||
type RenderPipeline = crate::id::PointerId<crate::id::markers::RenderPipeline>;
|
||||
type RenderBundle = crate::id::PointerId<crate::id::markers::RenderBundle>;
|
||||
type ComputePipeline = crate::id::PointerId<crate::id::markers::ComputePipeline>;
|
||||
type Blas = crate::id::PointerId<crate::id::markers::Blas>;
|
||||
type Tlas = crate::id::PointerId<crate::id::markers::Tlas>;
|
||||
}
|
||||
|
||||
impl ReferenceType for ArcReferences {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
//! Types that are useful for FFI bindings to `wgpu`.
|
||||
|
||||
use crate::{command::IdReferences, id};
|
||||
|
||||
pub type TexelCopyBufferInfo = wgt::TexelCopyBufferInfo<id::BufferId>;
|
||||
pub type TexelCopyTextureInfo = wgt::TexelCopyTextureInfo<id::TextureId>;
|
||||
pub type CopyExternalImageDestInfo = wgt::CopyExternalImageDestInfo<id::TextureId>;
|
||||
|
||||
pub type Command = super::Command<IdReferences>;
|
||||
@@ -17,7 +17,6 @@ mod compute_command;
|
||||
mod draw;
|
||||
mod encoder;
|
||||
mod encoder_command;
|
||||
pub mod ffi;
|
||||
mod memory_init;
|
||||
mod pass;
|
||||
mod query;
|
||||
@@ -54,13 +53,13 @@ pub use self::{
|
||||
},
|
||||
compute_command::ArcComputeCommand,
|
||||
draw::{DrawError, Rect, RenderCommandError},
|
||||
encoder_command::{ArcCommand, ArcReferences, Command, IdReferences, ReferenceType},
|
||||
encoder_command::{ArcCommand, ArcReferences, Command, ReferenceType},
|
||||
query::{QueryError, QueryUseError, ResolveError, SimplifiedQueryType},
|
||||
render::{
|
||||
AttachmentError, AttachmentErrorLocation, ColorAttachmentError, ColorAttachments, LoadOp,
|
||||
PassChannel, RenderBasePass, RenderPass, RenderPassColorAttachment,
|
||||
RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPassError,
|
||||
RenderPassErrorInner, ResolvedPassChannel, ResolvedRenderPassDepthStencilAttachment,
|
||||
RenderPassDepthStencilAttachment, RenderPassError, RenderPassErrorInner,
|
||||
ResolvedPassChannel, ResolvedRenderPassDepthStencilAttachment,
|
||||
ResolvedRenderPassDescriptor, StoreOp,
|
||||
},
|
||||
render_command::ArcRenderCommand,
|
||||
@@ -98,20 +97,13 @@ use crate::resource::{
|
||||
ParentDevice as _, QuerySet,
|
||||
};
|
||||
use crate::track::{DeviceTracker, ResourceUsageCompatibilityError, Tracker, UsageScope};
|
||||
use crate::{api_log, global::Global, id, resource_log, Label};
|
||||
use crate::{api_log, resource_log, Label};
|
||||
use crate::{hal_label, LabelHelpers};
|
||||
|
||||
use wgt::error::{ErrorType, WebGpuError};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
/// cbindgen:ignore
|
||||
pub type TexelCopyBufferInfo = ffi::TexelCopyBufferInfo;
|
||||
/// cbindgen:ignore
|
||||
pub type TexelCopyTextureInfo = ffi::TexelCopyTextureInfo;
|
||||
/// cbindgen:ignore
|
||||
pub type CopyExternalImageDestInfo = ffi::CopyExternalImageDestInfo;
|
||||
|
||||
pub(crate) struct EncoderErrorState {
|
||||
error: CommandEncoderError,
|
||||
|
||||
@@ -1794,62 +1786,6 @@ impl CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// Finishes a command encoder, creating a command buffer and returning errors that were
|
||||
/// deferred until now.
|
||||
///
|
||||
/// The returned `String` is the label of the command encoder, supplied so that `wgpu` can
|
||||
/// include the label when printing deferred errors without having its own copy of the label.
|
||||
/// This is a kludge and should be replaced if we think of a better solution to propagating
|
||||
/// labels.
|
||||
pub fn command_encoder_finish(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &wgt::CommandBufferDescriptor<Label>,
|
||||
id_in: Option<id::CommandBufferId>,
|
||||
) -> (id::CommandBufferId, Option<(String, CommandEncoderError)>) {
|
||||
let hub = &self.hub;
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let (cmd_buf, opt_error) = cmd_enc.finish(desc);
|
||||
let cmd_buf_id = hub.command_buffers.prepare(id_in).assign(cmd_buf);
|
||||
|
||||
(cmd_buf_id, opt_error)
|
||||
}
|
||||
|
||||
pub fn command_encoder_push_debug_group(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.push_debug_group(label)
|
||||
}
|
||||
|
||||
pub fn command_encoder_insert_debug_marker(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
label: &str,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.insert_debug_marker(label)
|
||||
}
|
||||
|
||||
pub fn command_encoder_pop_debug_group(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
cmd_enc.pop_debug_group()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn push_debug_group(
|
||||
state: &mut EncodingState,
|
||||
label: &str,
|
||||
@@ -1932,12 +1868,6 @@ trait PartialEq_ {
|
||||
fn eq(&self, other: &Self) -> bool;
|
||||
}
|
||||
|
||||
impl<T: id::Marker> PartialEq_ for id::Id<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self == other
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq_ for Arc<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Arc::ptr_eq(self, other)
|
||||
|
||||
@@ -5,8 +5,6 @@ use core::{iter, mem};
|
||||
use crate::{
|
||||
command::{encoder::EncodingState, ArcCommand, EncoderStateError, InnerCommandEncoder},
|
||||
device::{Device, DeviceError, MissingFeatures},
|
||||
global::Global,
|
||||
id,
|
||||
init_tracker::MemoryInitKind,
|
||||
resource::{
|
||||
Buffer, DestroyedResourceError, InvalidResourceError, MissingBufferUsageError,
|
||||
@@ -468,42 +466,6 @@ impl super::CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_write_timestamp(
|
||||
&self,
|
||||
command_encoder_id: id::CommandEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
cmd_enc.write_timestamp(hub.query_sets.get(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn command_encoder_resolve_query_set(
|
||||
&self,
|
||||
command_encoder_id: id::CommandEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
start_query: u32,
|
||||
query_count: u32,
|
||||
destination: id::BufferId,
|
||||
destination_offset: BufferAddress,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
cmd_enc.resolve_query_set(
|
||||
hub.query_sets.get(query_set_id),
|
||||
start_query,
|
||||
query_count,
|
||||
hub.buffers.get(destination),
|
||||
destination_offset,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn write_timestamp(
|
||||
state: &mut EncodingState,
|
||||
query_set: Arc<QuerySet>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use core::{
|
||||
cmp::max,
|
||||
num::NonZeroU64,
|
||||
@@ -9,18 +9,13 @@ use wgt::{math::align_to, BufferUsages, BufferUses, Features};
|
||||
|
||||
use crate::{
|
||||
command::encoder::EncodingState,
|
||||
ray_tracing::{
|
||||
AsAction, AsBuild, BlasAabbGeometry, BlasTriangleGeometry, TlasBuild, TlasInstance,
|
||||
ValidateAsActionsError,
|
||||
},
|
||||
ray_tracing::{AsAction, AsBuild, TlasBuild, ValidateAsActionsError},
|
||||
resource::{Buffer, InvalidResourceError},
|
||||
};
|
||||
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::{
|
||||
ArcBlasAabbGeometry, ArcBlasBuildEntry, ArcBlasGeometries, ArcBlasTriangleGeometry,
|
||||
@@ -35,8 +30,6 @@ use crate::{
|
||||
};
|
||||
use crate::{lock::RwLockWriteGuard, resource::RawResourceAccess};
|
||||
|
||||
use crate::id::{BlasId, BufferId, TlasId};
|
||||
|
||||
struct BlasStore<'a> {
|
||||
blas: Arc<Blas>,
|
||||
entries: hal::AccelerationStructureEntries<'a, dyn hal::DynBuffer>,
|
||||
@@ -193,84 +186,6 @@ impl super::CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_mark_acceleration_structures_built(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
blas_ids: &[BlasId],
|
||||
tlas_ids: &[TlasId],
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let blases = blas_ids
|
||||
.iter()
|
||||
.map(|&id| hub.blas_s.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
let tlases = tlas_ids
|
||||
.iter()
|
||||
.map(|&id| hub.tlas_s.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
cmd_enc.mark_acceleration_structures_built(&blases, &tlases)
|
||||
}
|
||||
|
||||
pub fn command_encoder_build_acceleration_structures<'a>(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
blas_iter: impl Iterator<Item = BlasBuildEntry<'a, BlasId, BufferId>>,
|
||||
tlas_iter: impl Iterator<Item = TlasPackage<'a, TlasId, BlasId>>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let blases = blas_iter.map(|e| BlasBuildEntry {
|
||||
blas: hub.blas_s.get(e.blas),
|
||||
geometries: match e.geometries {
|
||||
BlasGeometries::TriangleGeometries(triangle_geometries) => {
|
||||
let triangle_geometries = triangle_geometries.map(|tg| BlasTriangleGeometry {
|
||||
size: tg.size,
|
||||
vertex_buffer: hub.buffers.get(tg.vertex_buffer),
|
||||
index_buffer: tg
|
||||
.index_buffer
|
||||
.map(|index_buffer| hub.buffers.get(index_buffer)),
|
||||
transform_buffer: tg
|
||||
.transform_buffer
|
||||
.map(|transform_buffer| hub.buffers.get(transform_buffer)),
|
||||
first_vertex: tg.first_vertex,
|
||||
vertex_stride: tg.vertex_stride,
|
||||
first_index: tg.first_index,
|
||||
transform_buffer_offset: tg.transform_buffer_offset,
|
||||
});
|
||||
BlasGeometries::TriangleGeometries(Box::new(triangle_geometries.into_iter()))
|
||||
}
|
||||
BlasGeometries::AabbGeometries(aabb_geometries) => {
|
||||
let aabb_geometries = aabb_geometries.map(|ag| BlasAabbGeometry {
|
||||
size: ag.size,
|
||||
stride: ag.stride,
|
||||
aabb_buffer: hub.buffers.get(ag.aabb_buffer),
|
||||
primitive_offset: ag.primitive_offset,
|
||||
});
|
||||
BlasGeometries::AabbGeometries(Box::new(aabb_geometries.into_iter()))
|
||||
}
|
||||
},
|
||||
});
|
||||
let tlases = tlas_iter.map(|e| TlasPackage {
|
||||
tlas: hub.tlas_s.get(e.tlas),
|
||||
instances: Box::new(e.instances.map(|instance| {
|
||||
instance.as_ref().map(|instance| TlasInstance {
|
||||
blas: hub.blas_s.get(instance.blas),
|
||||
transform: instance.transform,
|
||||
custom_data: instance.custom_data,
|
||||
mask: instance.mask,
|
||||
})
|
||||
})),
|
||||
lowest_unmodified: e.lowest_unmodified,
|
||||
});
|
||||
cmd_enc.build_acceleration_structures(blases.into_iter(), tlases.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn build_acceleration_structures(
|
||||
state: &mut EncodingState,
|
||||
blas: Vec<OwnedBlasBuildEntry<ArcReferences>>,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec};
|
||||
use core::{convert::Infallible, fmt, num::NonZeroU32, ops::Range, str};
|
||||
use parking_lot::Mutex;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@@ -35,7 +34,6 @@ use crate::{
|
||||
AttachmentData, Device, DeviceError, MissingDownlevelFlags, MissingFeatures,
|
||||
RenderPassCompatibilityError, RenderPassContext,
|
||||
},
|
||||
global::Global,
|
||||
hal_label, id, impl_resource_type,
|
||||
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
|
||||
pipeline::{PipelineFlags, RenderPipeline, VertexStep},
|
||||
@@ -254,23 +252,6 @@ pub struct ResolvedRenderPassDepthStencilAttachment<TV> {
|
||||
pub stencil: ResolvedPassChannel<u32>,
|
||||
}
|
||||
|
||||
/// Describes the attachments of a render pass.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct RenderPassDescriptor<'a> {
|
||||
pub label: Label<'a>,
|
||||
/// The color attachments of the render pass.
|
||||
pub color_attachments: Cow<'a, [Option<RenderPassColorAttachment<id::TextureViewId>>]>,
|
||||
/// The depth and stencil attachment of the render pass, if any.
|
||||
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachment<id::TextureViewId>>,
|
||||
/// Defines where and when timestamp values will be written for this pass.
|
||||
pub timestamp_writes: Option<PassTimestampWrites<id::QuerySetId>>,
|
||||
/// Defines where the occlusion query results will be stored for this pass.
|
||||
pub occlusion_query_set: Option<id::QuerySetId>,
|
||||
/// The multiview array layers that will be used
|
||||
pub multiview_mask: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
/// Describes the attachments of a render pass.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ResolvedRenderPassDescriptor<'a> {
|
||||
@@ -2184,112 +2165,6 @@ impl RenderPass {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// Creates a render pass.
|
||||
///
|
||||
/// If creation fails, an invalid pass is returned. Attempting to record
|
||||
/// commands into an invalid pass is permitted, but a validation error will
|
||||
/// ultimately be generated when the parent encoder is finished, and it is
|
||||
/// not possible to run any commands from the invalid pass.
|
||||
///
|
||||
/// If successful, puts the encoder into the [`Locked`] state.
|
||||
///
|
||||
/// [`Locked`]: crate::command::CommandEncoderStatus::Locked
|
||||
pub fn command_encoder_begin_render_pass(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor<'_>,
|
||||
) -> (RenderPass, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(encoder_id);
|
||||
|
||||
let texture_views = hub.texture_views.read();
|
||||
let query_sets = hub.query_sets.read();
|
||||
|
||||
let desc = ResolvedRenderPassDescriptor {
|
||||
label: desc.label.as_deref().map(Cow::Borrowed),
|
||||
color_attachments: Cow::Owned(
|
||||
desc.color_attachments
|
||||
.iter()
|
||||
.map(|at| {
|
||||
at.as_ref().map(|at| RenderPassColorAttachment {
|
||||
view: texture_views.get(at.view),
|
||||
depth_slice: at.depth_slice,
|
||||
resolve_target: at
|
||||
.resolve_target
|
||||
.as_ref()
|
||||
.map(|rt| texture_views.get(*rt)),
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
depth_stencil_attachment: desc.depth_stencil_attachment.as_ref().map(|at| {
|
||||
RenderPassDepthStencilAttachment {
|
||||
view: texture_views.get(at.view),
|
||||
depth: at.depth.clone(),
|
||||
stencil: at.stencil.clone(),
|
||||
}
|
||||
}),
|
||||
timestamp_writes: desc
|
||||
.timestamp_writes
|
||||
.as_ref()
|
||||
.map(|tw| PassTimestampWrites {
|
||||
query_set: query_sets.get(tw.query_set),
|
||||
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,
|
||||
end_of_pass_write_index: tw.end_of_pass_write_index,
|
||||
}),
|
||||
occlusion_query_set: desc
|
||||
.occlusion_query_set
|
||||
.as_ref()
|
||||
.map(|query_set| query_sets.get(*query_set)),
|
||||
multiview_mask: desc.multiview_mask,
|
||||
};
|
||||
|
||||
drop(texture_views);
|
||||
drop(query_sets);
|
||||
|
||||
cmd_enc.begin_render_pass(desc)
|
||||
}
|
||||
|
||||
pub fn command_encoder_begin_render_pass_with_id(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor<'_>,
|
||||
id_in: Option<id::RenderPassEncoderId>,
|
||||
) -> (id::RenderPassEncoderId, Option<CommandEncoderError>) {
|
||||
let hub = &self.hub;
|
||||
let fid = hub.render_passes.prepare(id_in);
|
||||
let (render_pass, error) = self.command_encoder_begin_render_pass(encoder_id, desc);
|
||||
// no lock rank here because only one thread should be using renderpass
|
||||
// and it's only used by id variants of render pass methods on global
|
||||
// so no deadlock (or concurrent lock) should happen in practise
|
||||
let id = fid.assign(Arc::new(Mutex::new(render_pass)));
|
||||
(id, error)
|
||||
}
|
||||
|
||||
pub fn render_pass_end(&self, pass: &mut RenderPass) -> Result<(), EncoderStateError> {
|
||||
pass.end()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be accessed concurrently");
|
||||
self.render_pass_end(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_drop(&self, pass: id::RenderPassEncoderId) {
|
||||
self.hub.render_passes.remove(pass);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn encode_render_pass(
|
||||
parent_state: &mut EncodingState<InnerCommandEncoder>,
|
||||
mut base: BasePass<ArcRenderCommand, Infallible>,
|
||||
@@ -4298,652 +4173,3 @@ pub(crate) const fn get_dst_stride_of_indirect_args(
|
||||
};
|
||||
extra + get_src_stride_of_indirect_args(family)
|
||||
}
|
||||
|
||||
// Recording a render pass.
|
||||
//
|
||||
// The only error that should be returned from these methods is
|
||||
// `EncoderStateError::Ended`, when the pass has already ended and an immediate
|
||||
// validation error is raised.
|
||||
//
|
||||
// All other errors should be stored in the pass for later reporting when
|
||||
// `CommandEncoder.finish()` is called.
|
||||
//
|
||||
// The `pass_try!` macro should be used to handle errors appropriately. Note
|
||||
// that the `pass_try!` and `pass_base!` macros may return early from the
|
||||
// function that invokes them, like the `?` operator.
|
||||
impl Global {
|
||||
pub fn render_pass_set_bind_group(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_bind_group(
|
||||
index,
|
||||
bind_group_id.map(|id| self.hub.bind_groups.get(id)),
|
||||
offsets,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_bind_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
index: u32,
|
||||
bind_group_id: Option<id::BindGroupId>,
|
||||
offsets: &[DynamicOffset],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_bind_group(&mut pass, index, bind_group_id, offsets)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_pipeline(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pipeline = self.resolve_render_pipeline_id(pipeline_id);
|
||||
pass.set_pipeline(pipeline)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_pipeline_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
pipeline_id: id::RenderPipelineId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_pipeline(&mut pass, pipeline_id)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_index_buffer(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
index_format: IndexFormat,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_index_buffer(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
index_format,
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_index_buffer_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
index_format: IndexFormat,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_index_buffer(&mut pass, buffer_id, index_format, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_vertex_buffer(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_vertex_buffer(
|
||||
slot,
|
||||
buffer_id.map(|id| self.resolve_buffer_id(id)),
|
||||
offset,
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_vertex_buffer_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
slot: u32,
|
||||
buffer_id: Option<id::BufferId>,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_vertex_buffer(&mut pass, slot, buffer_id, offset, size)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_blend_constant(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
color: Color,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_blend_constant(color)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_blend_constant_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
color: Color,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_blend_constant(&mut pass, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_stencil_reference(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
value: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_stencil_reference(value)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_stencil_reference_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
value: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_stencil_reference(&mut pass, value)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_viewport(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
depth_min: f32,
|
||||
depth_max: f32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_viewport(x, y, w, h, depth_min, depth_max)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_viewport_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
h: f32,
|
||||
depth_min: f32,
|
||||
depth_max: f32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_viewport(&mut pass, x, y, w, h, depth_min, depth_max)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_scissor_rect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_scissor_rect(x, y, w, h)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_scissor_rect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
x: u32,
|
||||
y: u32,
|
||||
w: u32,
|
||||
h: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_scissor_rect(&mut pass, x, y, w, h)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_immediates(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.set_immediates(offset, data)
|
||||
}
|
||||
|
||||
pub fn render_pass_set_immediates_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
offset: u32,
|
||||
data: &[u8],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_set_immediates(&mut pass, offset, data)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw(vertex_count, instance_count, first_vertex, first_instance)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
vertex_count: u32,
|
||||
instance_count: u32,
|
||||
first_vertex: u32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw(
|
||||
&mut pass,
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indexed(
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
index_count: u32,
|
||||
instance_count: u32,
|
||||
first_index: u32,
|
||||
base_vertex: i32,
|
||||
first_instance: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indexed(
|
||||
&mut pass,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
base_vertex,
|
||||
first_instance,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_mesh_tasks(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
group_count_x: u32,
|
||||
group_count_y: u32,
|
||||
group_count_z: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.draw_mesh_tasks(group_count_x, group_count_y, group_count_z)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indirect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.draw_indexed_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_indexed_indirect_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_draw_indexed_indirect(&mut pass, buffer_id, offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_draw_mesh_tasks_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.draw_mesh_tasks_indirect(self.resolve_buffer_id(buffer_id), offset)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indexed_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indexed_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_mesh_tasks_indirect(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.multi_draw_mesh_tasks_indirect(self.resolve_buffer_id(buffer_id), offset, count)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_indexed_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.multi_draw_indexed_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_multi_draw_mesh_tasks_indirect_count(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
count_buffer_id: id::BufferId,
|
||||
count_buffer_offset: BufferAddress,
|
||||
max_count: u32,
|
||||
) -> Result<(), RenderPassError> {
|
||||
pass.multi_draw_mesh_tasks_indirect_count(
|
||||
self.resolve_buffer_id(buffer_id),
|
||||
offset,
|
||||
self.resolve_buffer_id(count_buffer_id),
|
||||
count_buffer_offset,
|
||||
max_count,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn render_pass_push_debug_group(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.push_debug_group(label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_push_debug_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_push_debug_group(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_pop_debug_group(&self, pass: &mut RenderPass) -> Result<(), PassStateError> {
|
||||
pass.pop_debug_group()
|
||||
}
|
||||
|
||||
pub fn render_pass_pop_debug_group_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_pop_debug_group(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_insert_debug_marker(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.insert_debug_marker(label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_insert_debug_marker_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
label: &str,
|
||||
color: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_insert_debug_marker(&mut pass, label, color)
|
||||
}
|
||||
|
||||
pub fn render_pass_write_timestamp(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.write_timestamp(self.resolve_query_set_id(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_write_timestamp_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_write_timestamp(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_occlusion_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.begin_occlusion_query(query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_occlusion_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_begin_occlusion_query(&mut pass, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_end_occlusion_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_occlusion_query()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_occlusion_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_end_occlusion_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.begin_pipeline_statistics_query(self.resolve_query_set_id(query_set_id), query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_begin_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
query_set_id: id::QuerySetId,
|
||||
query_index: u32,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_begin_pipeline_statistics_query(&mut pass, query_set_id, query_index)
|
||||
}
|
||||
|
||||
pub fn render_pass_end_pipeline_statistics_query(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
) -> Result<(), PassStateError> {
|
||||
pass.end_pipeline_statistics_query()
|
||||
}
|
||||
|
||||
pub fn render_pass_end_pipeline_statistics_query_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_end_pipeline_statistics_query(&mut pass)
|
||||
}
|
||||
|
||||
pub fn render_pass_execute_bundles(
|
||||
&self,
|
||||
pass: &mut RenderPass,
|
||||
render_bundle_ids: &[id::RenderBundleId],
|
||||
) -> Result<(), PassStateError> {
|
||||
let hub = &self.hub;
|
||||
let bundles = hub.render_bundles.read();
|
||||
let render_bundles = render_bundle_ids
|
||||
.iter()
|
||||
.map(|&id| bundles.get(id))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
pass.execute_bundles(&render_bundles)
|
||||
}
|
||||
|
||||
pub fn render_pass_execute_bundles_with_id(
|
||||
&self,
|
||||
pass: id::RenderPassEncoderId,
|
||||
render_bundle_ids: &[id::RenderBundleId],
|
||||
) -> Result<(), PassStateError> {
|
||||
let pass = self.hub.render_passes.get(pass);
|
||||
let mut pass = pass
|
||||
.try_lock()
|
||||
.expect("RenderPasses should not be used concurrently");
|
||||
self.render_pass_execute_bundles(&mut pass, render_bundle_ids)
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,6 @@ use crate::{
|
||||
clear_texture, encoder::EncodingState, ArcCommand, CommandEncoderError, EncoderStateError,
|
||||
},
|
||||
device::MissingDownlevelFlags,
|
||||
global::Global,
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
init_tracker::{
|
||||
has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange,
|
||||
TextureInitTrackerAction,
|
||||
@@ -28,7 +26,6 @@ use crate::{
|
||||
|
||||
use super::ClearError;
|
||||
|
||||
type TexelCopyBufferInfo = wgt::TexelCopyBufferInfo<BufferId>;
|
||||
type TexelCopyTextureInfo = wgt::TexelCopyTextureInfo<Arc<Texture>>;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -967,92 +964,6 @@ impl super::CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_copy_buffer_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: BufferId,
|
||||
source_offset: BufferAddress,
|
||||
destination: BufferId,
|
||||
destination_offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let source = self.resolve_buffer_id(source);
|
||||
let destination = self.resolve_buffer_id(destination);
|
||||
cmd_enc.copy_buffer_to_buffer(source, source_offset, destination, destination_offset, size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_buffer_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &TexelCopyBufferInfo,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
let source = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(source.buffer),
|
||||
layout: source.layout,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_buffer_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &TexelCopyBufferInfo,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(destination.buffer),
|
||||
layout: destination.layout,
|
||||
};
|
||||
cmd_enc.copy_texture_to_buffer(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_texture_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn copy_buffer_to_buffer(
|
||||
state: &mut EncodingState,
|
||||
src_buffer: &Arc<Buffer>,
|
||||
|
||||
@@ -6,8 +6,6 @@ use wgt::error::{ErrorType, WebGpuError};
|
||||
use crate::{
|
||||
command::{encoder::EncodingState, ArcCommand, CommandEncoder, EncoderStateError},
|
||||
device::DeviceError,
|
||||
global::Global,
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
resource::{Buffer, InvalidResourceError, ParentDevice, Texture},
|
||||
track::ResourceUsageCompatibilityError,
|
||||
};
|
||||
@@ -48,42 +46,6 @@ impl CommandEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_transition_resources(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
buffer_transitions: impl Iterator<Item = wgt::BufferTransition<BufferId>>,
|
||||
texture_transitions: impl Iterator<Item = wgt::TextureTransition<TextureId>>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let buffer_transitions = buffer_transitions
|
||||
.map(|t| {
|
||||
let buffer = hub.buffers.get(t.buffer);
|
||||
wgt::BufferTransition {
|
||||
buffer,
|
||||
state: t.state,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let texture_transitions = texture_transitions
|
||||
.map(|t| {
|
||||
let texture = hub.textures.get(t.texture);
|
||||
wgt::TextureTransition {
|
||||
texture,
|
||||
selector: t.selector,
|
||||
state: t.state,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
cmd_enc.transition_resources(
|
||||
buffer_transitions.into_iter(),
|
||||
texture_transitions.into_iter(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn transition_resources(
|
||||
state: &mut EncodingState,
|
||||
buffer_transitions: Vec<wgt::BufferTransition<Arc<Buffer>>>,
|
||||
|
||||
@@ -21,7 +21,6 @@ use wgt::{
|
||||
};
|
||||
|
||||
pub(crate) mod bgl;
|
||||
pub mod global;
|
||||
mod life;
|
||||
pub mod queue;
|
||||
pub mod ray_tracing;
|
||||
|
||||
@@ -27,10 +27,7 @@ use crate::{
|
||||
TransferError,
|
||||
},
|
||||
device::{DeviceError, WaitIdleError},
|
||||
get_lowest_common_denom,
|
||||
global::Global,
|
||||
hal_label,
|
||||
id::{self, BlasId, QueueId},
|
||||
get_lowest_common_denom, hal_label,
|
||||
init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange},
|
||||
lock::{rank, Mutex, MutexGuard, RwLock, RwLockWriteGuard},
|
||||
ray_tracing::{BlasCompactReadyPendingClosure, CompactBlasError},
|
||||
@@ -1997,153 +1994,6 @@ impl Queue {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn queue_write_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: id::BufferId,
|
||||
buffer_offset: wgt::BufferAddress,
|
||||
data: &[u8],
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
|
||||
queue.write_buffer(buffer, buffer_offset, data)
|
||||
}
|
||||
|
||||
pub fn queue_create_staging_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_size: wgt::BufferSize,
|
||||
id_in: Option<id::StagingBufferId>,
|
||||
) -> Result<(id::StagingBufferId, NonNull<u8>), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let (staging_buffer, ptr) = queue.create_staging_buffer(buffer_size)?;
|
||||
|
||||
let fid = self.hub.staging_buffers.prepare(id_in);
|
||||
let id = fid.assign(staging_buffer);
|
||||
|
||||
Ok((id, ptr))
|
||||
}
|
||||
|
||||
pub fn queue_write_staging_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: id::BufferId,
|
||||
buffer_offset: wgt::BufferAddress,
|
||||
staging_buffer_id: id::StagingBufferId,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
let staging_buffer = self.hub.staging_buffers.remove(staging_buffer_id);
|
||||
queue.write_staging_buffer(buffer, buffer_offset, staging_buffer)
|
||||
}
|
||||
|
||||
pub fn queue_validate_write_buffer(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
buffer_id: id::BufferId,
|
||||
buffer_offset: u64,
|
||||
buffer_size: wgt::BufferSize,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let buffer = self.hub.buffers.get(buffer_id);
|
||||
queue.validate_write_buffer(buffer, buffer_offset, buffer_size)
|
||||
}
|
||||
|
||||
pub fn queue_write_texture(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
destination: &wgt::TexelCopyTextureInfo<id::TextureId>,
|
||||
data: &[u8],
|
||||
data_layout: &wgt::TexelCopyBufferLayout,
|
||||
size: &wgt::Extent3d,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let texture = self.hub.textures.get(destination.texture);
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture,
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
|
||||
queue.write_texture(destination, data, data_layout, size)
|
||||
}
|
||||
|
||||
#[cfg(webgl)]
|
||||
pub fn queue_copy_external_image_to_texture(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
source: &wgt::CopyExternalImageSourceInfo,
|
||||
destination: crate::command::CopyExternalImageDestInfo,
|
||||
size: wgt::Extent3d,
|
||||
) -> Result<(), QueueWriteError> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let destination = wgt::CopyExternalImageDestInfo {
|
||||
texture: self.hub.textures.get(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
color_space: destination.color_space,
|
||||
premultiplied_alpha: destination.premultiplied_alpha,
|
||||
};
|
||||
queue.copy_external_image_to_texture(source, destination, size)
|
||||
}
|
||||
|
||||
pub fn queue_submit(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
command_buffer_ids: &[id::CommandBufferId],
|
||||
) -> Result<SubmissionIndex, (SubmissionIndex, QueueSubmitError)> {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let command_buffer_guard = self.hub.command_buffers.read();
|
||||
let command_buffers = command_buffer_ids
|
||||
.iter()
|
||||
.map(|id| command_buffer_guard.get(*id))
|
||||
.collect::<Vec<_>>();
|
||||
drop(command_buffer_guard);
|
||||
queue.submit(&command_buffers)
|
||||
}
|
||||
|
||||
pub fn queue_get_timestamp_period(&self, queue_id: QueueId) -> f32 {
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
|
||||
queue.get_timestamp_period()
|
||||
}
|
||||
|
||||
pub fn queue_on_submitted_work_done(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
closure: SubmittedWorkDoneClosure,
|
||||
) -> SubmissionIndex {
|
||||
api_log!("Queue::on_submitted_work_done {queue_id:?}");
|
||||
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let result = queue.on_submitted_work_done(closure);
|
||||
result.unwrap_or(0) // '0' means no wait is necessary
|
||||
}
|
||||
|
||||
pub fn queue_compact_blas(
|
||||
&self,
|
||||
queue_id: QueueId,
|
||||
blas_id: BlasId,
|
||||
id_in: Option<BlasId>,
|
||||
) -> (BlasId, Option<u64>, Option<CompactBlasError>) {
|
||||
let fid = self.hub.blas_s.prepare(id_in);
|
||||
|
||||
let queue = self.hub.queues.get(queue_id);
|
||||
let blas = self.hub.blas_s.get(blas_id);
|
||||
|
||||
let (blas, error) = queue.compact_blas(&blas);
|
||||
|
||||
let handle = blas.handle();
|
||||
let id = fid.assign(blas);
|
||||
|
||||
(id, handle, error)
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_command_buffer(
|
||||
command_buffer: &CommandBuffer,
|
||||
queue: &Queue,
|
||||
|
||||
@@ -8,15 +8,12 @@ use crate::resource::ResourceState;
|
||||
use crate::{
|
||||
api_log,
|
||||
device::Device,
|
||||
global::Global,
|
||||
hal_label,
|
||||
id::{self, BlasId, TlasId},
|
||||
lock::RwLock,
|
||||
lock::{rank, Mutex},
|
||||
ray_tracing::BlasPrepareCompactError,
|
||||
ray_tracing::{CreateBlasError, CreateTlasError},
|
||||
resource,
|
||||
resource::{BlasCompactCallback, BlasCompactState, InvalidResourceError, TrackingData},
|
||||
resource::{BlasCompactState, TrackingData},
|
||||
snatch::Snatchable,
|
||||
LabelHelpers,
|
||||
};
|
||||
@@ -345,74 +342,3 @@ impl Device {
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn device_create_blas(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &resource::BlasDescriptor,
|
||||
sizes: wgt::BlasGeometrySizeDescriptors,
|
||||
id_in: Option<BlasId>,
|
||||
) -> (BlasId, Option<u64>, Option<CreateBlasError>) {
|
||||
profiling::scope!("Device::create_blas");
|
||||
|
||||
let fid = self.hub.blas_s.prepare(id_in);
|
||||
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
let (blas, error) = device.create_blas(desc, sizes);
|
||||
|
||||
let handle = blas.handle();
|
||||
|
||||
let id = fid.assign(blas);
|
||||
|
||||
(id, handle, error)
|
||||
}
|
||||
|
||||
pub fn device_create_tlas(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &resource::TlasDescriptor,
|
||||
id_in: Option<TlasId>,
|
||||
) -> (TlasId, Option<CreateTlasError>) {
|
||||
profiling::scope!("Device::create_tlas");
|
||||
|
||||
let fid = self.hub.tlas_s.prepare(id_in);
|
||||
|
||||
let device = self.hub.devices.get(device_id);
|
||||
|
||||
let (tlas, error) = device.create_tlas(desc);
|
||||
|
||||
let id = fid.assign(tlas);
|
||||
|
||||
(id, error)
|
||||
}
|
||||
|
||||
pub fn blas_drop(&self, blas_id: BlasId) {
|
||||
let _blas = self.hub.blas_s.remove(blas_id);
|
||||
}
|
||||
|
||||
pub fn tlas_drop(&self, tlas_id: TlasId) {
|
||||
let _tlas = self.hub.tlas_s.remove(tlas_id);
|
||||
}
|
||||
|
||||
pub fn blas_prepare_compact_async(
|
||||
&self,
|
||||
blas_id: BlasId,
|
||||
callback: Option<BlasCompactCallback>,
|
||||
) -> Result<crate::SubmissionIndex, BlasPrepareCompactError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(blas_id);
|
||||
|
||||
blas.prepare_compact_async(callback)
|
||||
}
|
||||
|
||||
pub fn ready_for_compaction(&self, blas_id: BlasId) -> Result<bool, InvalidResourceError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let blas = hub.blas_s.get(blas_id);
|
||||
|
||||
blas.ready_for_compaction()
|
||||
}
|
||||
}
|
||||
+44
-250
@@ -1,121 +1,26 @@
|
||||
use crate::{Epoch, Index};
|
||||
use core::{
|
||||
cmp::Ordering,
|
||||
fmt::{self, Debug},
|
||||
hash::Hash,
|
||||
marker::PhantomData,
|
||||
num::NonZeroU64,
|
||||
};
|
||||
use wgt::WasmNotSendSync;
|
||||
|
||||
const _: () = {
|
||||
if size_of::<Index>() != 4 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
const _: () = {
|
||||
if size_of::<Epoch>() != 4 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
const _: () = {
|
||||
if size_of::<RawId>() != 8 {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
|
||||
/// The raw underlying representation of an identifier.
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(
|
||||
any(feature = "serde", feature = "trace"),
|
||||
derive(serde::Serialize),
|
||||
serde(into = "SerialId")
|
||||
)]
|
||||
#[cfg_attr(
|
||||
any(feature = "serde", feature = "replay"),
|
||||
derive(serde::Deserialize),
|
||||
serde(try_from = "SerialId")
|
||||
)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct RawId(NonZeroU64);
|
||||
|
||||
impl RawId {
|
||||
/// Zip together an identifier and return its raw underlying representation.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If both ID components are zero.
|
||||
pub fn zip(index: Index, epoch: Epoch) -> RawId {
|
||||
let v = (index as u64) | ((epoch as u64) << 32);
|
||||
Self(NonZeroU64::new(v).expect("IDs may not be zero"))
|
||||
}
|
||||
|
||||
/// Unzip a raw identifier into its components.
|
||||
pub fn unzip(self) -> (Index, Epoch) {
|
||||
(self.0.get() as Index, (self.0.get() >> 32) as Epoch)
|
||||
}
|
||||
}
|
||||
|
||||
/// An identifier for a wgpu object.
|
||||
///
|
||||
/// An `Id<T>` value identifies a value stored in a [`Global`]'s [`Hub`].
|
||||
///
|
||||
/// [`Global`]: crate::global::Global
|
||||
/// [`Hub`]: crate::hub::Hub
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(transparent))]
|
||||
pub struct Id<T: Marker>(RawId, PhantomData<T>);
|
||||
|
||||
// This type represents Id in a more readable (and editable) way.
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum SerialId {
|
||||
// The only variant forces RON to not ignore "Id"
|
||||
Id(Index, Epoch),
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl From<RawId> for SerialId {
|
||||
fn from(id: RawId) -> Self {
|
||||
let (index, epoch) = id.unzip();
|
||||
Self::Id(index, epoch)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
pub struct ZeroIdError;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl fmt::Display for ZeroIdError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "IDs may not be zero")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl TryFrom<SerialId> for RawId {
|
||||
type Error = ZeroIdError;
|
||||
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
|
||||
let SerialId::Id(index, epoch) = id;
|
||||
if index == 0 && epoch == 0 {
|
||||
Err(ZeroIdError)
|
||||
} else {
|
||||
Ok(RawId::zip(index, epoch))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Identify an object by the pointer returned by `Arc::as_ptr`.
|
||||
///
|
||||
/// This is used for tracing. See [IDs and tracing](crate::hub#ids-and-tracing).
|
||||
/// This is used for tracing.
|
||||
///
|
||||
/// As of `wgpu` v27, commands are encoded all at once when
|
||||
/// `CommandEncoder::finish` is called, not when the encoding methods are
|
||||
/// called for each command. This implies storing a representation of the
|
||||
/// commands in memory until `finish` is called. The
|
||||
/// serialized trace identifies resources by the integer value of
|
||||
/// `Arc::as_ptr`. These IDs have the type [`crate::id::PointerId`]. The
|
||||
/// trace player uses hash maps to go from `PointerId`s to `Arc`s
|
||||
/// when replaying a trace.
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "serde")]
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum PointerId<T: Marker> {
|
||||
// The only variant forces RON to not ignore "Id"
|
||||
PointerId(core::num::NonZeroUsize, #[serde(skip)] PhantomData<T>),
|
||||
PointerId(
|
||||
core::num::NonZeroUsize,
|
||||
#[serde(skip)] core::marker::PhantomData<T>,
|
||||
),
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@@ -141,7 +46,7 @@ impl<T: Marker> PartialEq for PointerId<T> {
|
||||
impl<T: Marker> Eq for PointerId<T> {}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<T: Marker> Hash for PointerId<T> {
|
||||
impl<T: Marker> core::hash::Hash for PointerId<T> {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
let PointerId::PointerId(this, _) = self;
|
||||
this.hash(state);
|
||||
@@ -160,103 +65,11 @@ impl<T: crate::storage::StorageItem> From<&alloc::sync::Arc<T>> for PointerId<T:
|
||||
// to add an offset to the pointer.
|
||||
PointerId::PointerId(
|
||||
core::num::NonZeroUsize::new(alloc::sync::Arc::as_ptr(arc) as usize).unwrap(),
|
||||
PhantomData,
|
||||
core::marker::PhantomData,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
/// # Safety
|
||||
///
|
||||
/// The raw id must be valid for the type.
|
||||
pub unsafe fn from_raw(raw: RawId) -> Self {
|
||||
Self(raw, PhantomData)
|
||||
}
|
||||
|
||||
/// Coerce the identifiers into its raw underlying representation.
|
||||
pub fn into_raw(self) -> RawId {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn zip(index: Index, epoch: Epoch) -> Self {
|
||||
Id(RawId::zip(index, epoch), PhantomData)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unzip(self) -> (Index, Epoch) {
|
||||
self.0.unzip()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Copy for Id<T> where T: Marker {}
|
||||
|
||||
impl<T> Clone for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
let (index, epoch) = self.unzip();
|
||||
write!(formatter, "{}Id({index},{epoch})", T::TYPE)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for Id<T> where T: Marker {}
|
||||
|
||||
impl<T> PartialOrd for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Ord for Id<T>
|
||||
where
|
||||
T: Marker,
|
||||
{
|
||||
#[inline]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.cmp(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Marker trait used to determine which types uniquely identify a resource.
|
||||
///
|
||||
/// For example, `Device<A>` will have the same type of identifier as
|
||||
@@ -274,11 +87,11 @@ impl Marker for () {
|
||||
const TYPE: &'static str = "Untyped";
|
||||
}
|
||||
|
||||
/// Define identifiers for each resource.
|
||||
/// Define markers for each resource.
|
||||
macro_rules! ids {
|
||||
($(
|
||||
$(#[$($meta:meta)*])*
|
||||
pub type $name:ident $marker:ident;
|
||||
pub type $marker:ident;
|
||||
)*) => {
|
||||
/// Marker types for each resource.
|
||||
pub mod markers {
|
||||
@@ -290,53 +103,34 @@ macro_rules! ids {
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
$(
|
||||
$(#[$($meta)*])*
|
||||
pub type $name = Id<self::markers::$marker>;
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
ids! {
|
||||
pub type AdapterId Adapter;
|
||||
pub type SurfaceId Surface;
|
||||
pub type DeviceId Device;
|
||||
pub type QueueId Queue;
|
||||
pub type BufferId Buffer;
|
||||
pub type StagingBufferId StagingBuffer;
|
||||
pub type TextureViewId TextureView;
|
||||
pub type TextureId Texture;
|
||||
pub type ExternalTextureId ExternalTexture;
|
||||
pub type SamplerId Sampler;
|
||||
pub type BindGroupLayoutId BindGroupLayout;
|
||||
pub type PipelineLayoutId PipelineLayout;
|
||||
pub type BindGroupId BindGroup;
|
||||
pub type ShaderModuleId ShaderModule;
|
||||
pub type RenderPipelineId RenderPipeline;
|
||||
pub type ComputePipelineId ComputePipeline;
|
||||
pub type PipelineCacheId PipelineCache;
|
||||
pub type CommandEncoderId CommandEncoder;
|
||||
pub type CommandBufferId CommandBuffer;
|
||||
pub type RenderPassEncoderId RenderPassEncoder;
|
||||
pub type ComputePassEncoderId ComputePassEncoder;
|
||||
pub type RenderBundleEncoderId RenderBundleEncoder;
|
||||
pub type RenderBundleId RenderBundle;
|
||||
pub type QuerySetId QuerySet;
|
||||
pub type BlasId Blas;
|
||||
pub type TlasId Tlas;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_id() {
|
||||
let indexes = [0, Index::MAX / 2 - 1, Index::MAX / 2 + 1, Index::MAX];
|
||||
let epochs = [1, Epoch::MAX / 2 - 1, Epoch::MAX / 2 + 1, Epoch::MAX];
|
||||
for &i in &indexes {
|
||||
for &e in &epochs {
|
||||
let id = Id::<()>::zip(i, e);
|
||||
let (index, epoch) = id.unzip();
|
||||
assert_eq!(index, i);
|
||||
assert_eq!(epoch, e);
|
||||
}
|
||||
}
|
||||
pub type Adapter;
|
||||
pub type Surface;
|
||||
pub type Device;
|
||||
pub type Queue;
|
||||
pub type Buffer;
|
||||
pub type StagingBuffer;
|
||||
pub type TextureView;
|
||||
pub type Texture;
|
||||
pub type ExternalTexture;
|
||||
pub type Sampler;
|
||||
pub type BindGroupLayout;
|
||||
pub type PipelineLayout;
|
||||
pub type BindGroup;
|
||||
pub type ShaderModule;
|
||||
pub type RenderPipeline;
|
||||
pub type ComputePipeline;
|
||||
pub type PipelineCache;
|
||||
pub type CommandEncoder;
|
||||
pub type CommandBuffer;
|
||||
pub type RenderPassEncoder;
|
||||
pub type ComputePassEncoder;
|
||||
pub type RenderBundleEncoder;
|
||||
pub type RenderBundle;
|
||||
pub type QuerySet;
|
||||
pub type Blas;
|
||||
pub type Tlas;
|
||||
}
|
||||
+2
-304
@@ -9,8 +9,7 @@ use crate::{
|
||||
device::{
|
||||
queue::Queue, resource::Device, DeviceDescriptor, DeviceError, UserClosures, WaitIdleError,
|
||||
},
|
||||
global::Global,
|
||||
id::{markers, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||
id::markers,
|
||||
limits::{self, check_limits, FailedLimit},
|
||||
lock::{rank, Mutex},
|
||||
present::{ConfigureSurfaceError, Presentation},
|
||||
@@ -23,8 +22,6 @@ use crate::{
|
||||
|
||||
use wgt::{Backend, Backends, InstanceFlags, PowerPreference};
|
||||
|
||||
pub type RequestAdapterOptions = wgt::RequestAdapterOptions<SurfaceId>;
|
||||
|
||||
#[test]
|
||||
fn downlevel_default_limits_less_than_default_limits() {
|
||||
let res = check_limits(&wgt::Limits::downlevel_defaults(), &wgt::Limits::default());
|
||||
@@ -257,7 +254,7 @@ impl Instance {
|
||||
/// - `display_handle` must be a valid object to create a surface upon,
|
||||
/// falls back to the instance display handle otherwise.
|
||||
/// - `window_handle` must remain valid as long as the returned
|
||||
/// [`SurfaceId`] is being used.
|
||||
/// [`Surface`] is being used.
|
||||
pub unsafe fn create_surface(
|
||||
&self,
|
||||
display_handle: Option<raw_window_handle::RawDisplayHandle>,
|
||||
@@ -1352,305 +1349,6 @@ pub enum CreateSurfaceError {
|
||||
MissingDisplayHandle,
|
||||
}
|
||||
|
||||
impl Global {
|
||||
/// Creates a new surface targeting the given display/window handles.
|
||||
///
|
||||
/// Internally attempts to create hal surfaces for all enabled backends.
|
||||
///
|
||||
/// Fails only if creation for surfaces for all enabled backends fails in which case
|
||||
/// the error for each enabled backend is listed.
|
||||
/// Vice versa, if creation for any backend succeeds, success is returned.
|
||||
/// Surface creation errors are logged to the debug log in any case.
|
||||
///
|
||||
/// id_in:
|
||||
/// - If `Some`, the id to assign to the surface. A new one will be generated otherwise.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - `display_handle` must be a valid object to create a surface upon,
|
||||
/// falls back to the instance display handle otherwise.
|
||||
/// - `window_handle` must remain valid as long as the returned
|
||||
/// [`SurfaceId`] is being used.
|
||||
pub unsafe fn instance_create_surface(
|
||||
&self,
|
||||
display_handle: Option<raw_window_handle::RawDisplayHandle>,
|
||||
window_handle: raw_window_handle::RawWindowHandle,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe { self.instance.create_surface(display_handle, window_handle) }?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Creates a new surface from the given drm configuration.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - All parameters must point to valid DRM values.
|
||||
///
|
||||
/// # Platform Support
|
||||
///
|
||||
/// This function requires the `"drm"` feature, and is only available on
|
||||
/// non-apple Unix-like platforms (Linux, FreeBSD) and currently only works
|
||||
/// with the Vulkan backend.
|
||||
#[cfg(drm)]
|
||||
pub unsafe fn instance_create_surface_from_drm(
|
||||
&self,
|
||||
fd: i32,
|
||||
plane: u32,
|
||||
connector_id: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
refresh_rate: u32,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe {
|
||||
self.instance.create_surface_from_drm(
|
||||
fd,
|
||||
plane,
|
||||
connector_id,
|
||||
width,
|
||||
height,
|
||||
refresh_rate,
|
||||
)
|
||||
}?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// `layer` must be a valid pointer.
|
||||
#[cfg(metal)]
|
||||
pub unsafe fn instance_create_surface_metal(
|
||||
&self,
|
||||
layer: *mut core::ffi::c_void,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe { self.instance.create_surface_metal(layer) }?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
#[cfg(dx12)]
|
||||
/// # Safety
|
||||
///
|
||||
/// The visual must be valid and able to be used to make a swapchain with.
|
||||
pub unsafe fn instance_create_surface_from_visual(
|
||||
&self,
|
||||
visual: *mut core::ffi::c_void,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe { self.instance.create_surface_from_visual(visual) }?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
#[cfg(dx12)]
|
||||
/// # Safety
|
||||
///
|
||||
/// The surface_handle must be valid and able to be used to make a swapchain with.
|
||||
pub unsafe fn instance_create_surface_from_surface_handle(
|
||||
&self,
|
||||
surface_handle: *mut core::ffi::c_void,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe {
|
||||
self.instance
|
||||
.create_surface_from_surface_handle(surface_handle)
|
||||
}?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
#[cfg(dx12)]
|
||||
/// # Safety
|
||||
///
|
||||
/// The swap_chain_panel must be valid and able to be used to make a swapchain with.
|
||||
pub unsafe fn instance_create_surface_from_swap_chain_panel(
|
||||
&self,
|
||||
swap_chain_panel: *mut core::ffi::c_void,
|
||||
id_in: Option<SurfaceId>,
|
||||
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||
let surface = unsafe {
|
||||
self.instance
|
||||
.create_surface_from_swap_chain_panel(swap_chain_panel)
|
||||
}?;
|
||||
let id = self.surfaces.prepare(id_in).assign(surface);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
pub fn surface_drop(&self, id: SurfaceId) {
|
||||
self.surfaces.remove(id);
|
||||
}
|
||||
|
||||
pub fn enumerate_adapters(
|
||||
&self,
|
||||
backends: Backends,
|
||||
apply_limit_buckets: bool,
|
||||
) -> Vec<AdapterId> {
|
||||
let adapters = self
|
||||
.instance
|
||||
.enumerate_adapters(backends, apply_limit_buckets);
|
||||
adapters
|
||||
.into_iter()
|
||||
.map(|adapter| self.hub.adapters.prepare(None).assign(adapter))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn request_adapter(
|
||||
&self,
|
||||
desc: &RequestAdapterOptions,
|
||||
backends: Backends,
|
||||
id_in: Option<AdapterId>,
|
||||
) -> Result<AdapterId, wgt::RequestAdapterError> {
|
||||
let compatible_surface = desc.compatible_surface.map(|id| self.surfaces.get(id));
|
||||
let desc = wgt::RequestAdapterOptions {
|
||||
power_preference: desc.power_preference,
|
||||
force_fallback_adapter: desc.force_fallback_adapter,
|
||||
compatible_surface: compatible_surface.as_deref(),
|
||||
apply_limit_buckets: desc.apply_limit_buckets,
|
||||
};
|
||||
let adapter = self.instance.request_adapter(&desc, backends)?;
|
||||
let id = self.hub.adapters.prepare(id_in).assign(adapter);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Create an adapter from a HAL adapter.
|
||||
///
|
||||
/// The HAL adapter may be obtained e.g. by calling `enumerate_adapters` on
|
||||
/// the HAL directly.
|
||||
///
|
||||
/// If [limit bucketing][lt] is desired, [`crate::limits::apply_limit_buckets`]
|
||||
/// should be called with the HAL adapter before calling this function.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `hal_adapter` must be created from this global internal instance handle.
|
||||
///
|
||||
/// [lt]: crate::limits#Limit-bucketing
|
||||
pub unsafe fn create_adapter_from_hal(
|
||||
&self,
|
||||
hal_adapter: hal::DynExposedAdapter,
|
||||
input: Option<AdapterId>,
|
||||
) -> AdapterId {
|
||||
let fid = self.hub.adapters.prepare(input);
|
||||
fid.assign(unsafe { self.instance.create_adapter_from_hal(hal_adapter) })
|
||||
}
|
||||
|
||||
pub fn adapter_get_info(&self, adapter_id: AdapterId) -> wgt::AdapterInfo {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_info()
|
||||
}
|
||||
|
||||
pub fn adapter_get_texture_format_features(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
format: wgt::TextureFormat,
|
||||
) -> wgt::TextureFormatFeatures {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_texture_format_features(format)
|
||||
}
|
||||
|
||||
pub fn adapter_features(&self, adapter_id: AdapterId) -> wgt::Features {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.features()
|
||||
}
|
||||
|
||||
pub fn adapter_limits(&self, adapter_id: AdapterId) -> wgt::Limits {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.limits()
|
||||
}
|
||||
|
||||
pub fn adapter_downlevel_capabilities(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> wgt::DownlevelCapabilities {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.downlevel_capabilities()
|
||||
}
|
||||
|
||||
pub fn adapter_get_presentation_timestamp(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> wgt::PresentationTimestamp {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.get_presentation_timestamp()
|
||||
}
|
||||
|
||||
pub fn adapter_cooperative_matrix_properties(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
) -> Vec<wgt::CooperativeMatrixProperties> {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.cooperative_matrix_properties()
|
||||
}
|
||||
|
||||
pub fn adapter_drop(&self, adapter_id: AdapterId) {
|
||||
self.hub.adapters.remove(adapter_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn adapter_request_device(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &DeviceDescriptor,
|
||||
device_id_in: Option<DeviceId>,
|
||||
queue_id_in: Option<QueueId>,
|
||||
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
|
||||
let device_fid = self.hub.devices.prepare(device_id_in);
|
||||
let queue_fid = self.hub.queues.prepare(queue_id_in);
|
||||
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
let (device, queue) = adapter.request_device(desc)?;
|
||||
|
||||
let device_id = device_fid.assign(device);
|
||||
resource_log!("Created Device {:?}", device_id);
|
||||
|
||||
let queue_id = queue_fid.assign(queue);
|
||||
resource_log!("Created Queue {:?}", queue_id);
|
||||
|
||||
Ok((device_id, queue_id))
|
||||
}
|
||||
|
||||
pub fn adapter_validate_device_descriptor(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &mut DeviceDescriptor,
|
||||
) -> Result<(), RequestDeviceError> {
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
adapter.validate_device_descriptor(desc)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// - `hal_device` must be created from `adapter_id` or its internal handle.
|
||||
/// - `desc` must be a subset of `hal_device` features and limits.
|
||||
pub unsafe fn create_device_from_hal(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
hal_device: hal::DynOpenDevice,
|
||||
desc: &DeviceDescriptor,
|
||||
device_id_in: Option<DeviceId>,
|
||||
queue_id_in: Option<QueueId>,
|
||||
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
|
||||
let devices_fid = self.hub.devices.prepare(device_id_in);
|
||||
let queues_fid = self.hub.queues.prepare(queue_id_in);
|
||||
|
||||
let adapter = self.hub.adapters.get(adapter_id);
|
||||
let (device, queue) =
|
||||
unsafe { adapter.create_device_and_queue_from_hal(hal_device, desc) }?;
|
||||
|
||||
let device_id = devices_fid.assign(device);
|
||||
|
||||
let queue_id = queues_fid.assign(queue);
|
||||
|
||||
Ok((device_id, queue_id))
|
||||
}
|
||||
}
|
||||
|
||||
/// This function checks that the adapter obeys WebGPU's adapter capability
|
||||
/// guarantees. Most of the limits are adjusted in wgpu-hal's
|
||||
/// `adjust_raw_limits` fn. So we only check the remaining properties here.
|
||||
|
||||
@@ -75,10 +75,7 @@ pub mod command;
|
||||
mod conv;
|
||||
pub mod device;
|
||||
pub mod error;
|
||||
pub mod global;
|
||||
pub mod hub;
|
||||
pub mod id;
|
||||
pub mod identity;
|
||||
mod indirect_validation;
|
||||
mod init_tracker;
|
||||
pub mod instance;
|
||||
@@ -89,7 +86,6 @@ mod pipeline_cache;
|
||||
mod pool;
|
||||
pub mod present;
|
||||
pub mod ray_tracing;
|
||||
pub mod registry;
|
||||
pub mod resource;
|
||||
mod snatch;
|
||||
pub mod storage;
|
||||
@@ -120,13 +116,10 @@ pub(crate) use nt::{FastHashMap, FastHashSet, FastIndexMap};
|
||||
/// These are the values stored in `Device::fence`.
|
||||
pub type SubmissionIndex = hal::FenceValue;
|
||||
|
||||
type Index = u32;
|
||||
type Epoch = u32;
|
||||
|
||||
pub type RawString = *const core::ffi::c_char;
|
||||
pub type Label<'a> = Option<Cow<'a, str>>;
|
||||
|
||||
trait LabelHelpers<'a> {
|
||||
pub trait LabelHelpers<'a> {
|
||||
fn to_hal(&'a self, flags: wgt::InstanceFlags) -> Option<&'a str>;
|
||||
fn to_string(&self) -> String;
|
||||
}
|
||||
|
||||
@@ -176,23 +176,6 @@ define_lock_ranks! {
|
||||
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
|
||||
}
|
||||
rank HUB_OTHER "Hub (general)" followed by {
|
||||
HUB_TEXTURE_VIEWS,
|
||||
HUB_BIND_GROUPS,
|
||||
}
|
||||
rank HUB_BIND_GROUPS "Hub::bind_groups" followed by {
|
||||
HUB_RENDER_PIPELINES,
|
||||
}
|
||||
rank HUB_RENDER_PIPELINES "Hub::render_pipelines" followed by {
|
||||
SHARED_TRACKER_INDEX_ALLOCATOR_INNER,
|
||||
}
|
||||
rank HUB_TEXTURE_VIEWS "Hub::texture_views" followed by {
|
||||
HUB_SAMPLERS,
|
||||
}
|
||||
rank HUB_SAMPLERS "Hub::samplers" followed by {
|
||||
HUB_TLAS,
|
||||
}
|
||||
rank HUB_TLAS "Hub::tlas" followed by {
|
||||
HUB_EXTERNAL_TEXTURES,
|
||||
}
|
||||
|
||||
// Leaf ranks reachable from the graph above, alphabetical.
|
||||
@@ -203,7 +186,6 @@ define_lock_ranks! {
|
||||
rank DEVICE_DEFERRED_DESTROY "Device::deferred_destroy" followed by { }
|
||||
rank DEVICE_TRACE "Device::trace" followed by { }
|
||||
rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { }
|
||||
rank HUB_EXTERNAL_TEXTURES "Hub::external_textures" followed by { }
|
||||
rank SHARED_TRACKER_INDEX_ALLOCATOR_INNER "SharedTrackerIndexAllocator::inner" followed by { }
|
||||
rank QUERY_SET_INITIALIZED_SLOTS "QuerySet::initialized_slots" followed by { }
|
||||
rank TEXTURE_BIND_GROUPS "Texture::bind_groups" followed by { }
|
||||
@@ -213,7 +195,6 @@ define_lock_ranks! {
|
||||
// Ranks not connected to the graph, alphabetical.
|
||||
rank BLAS_BUILT_INDEX "Blas::built_index" followed by { }
|
||||
rank DEVICE_LOST_CLOSURE "Device::device_lost_closure" followed by { }
|
||||
rank IDENTITY_MANAGER_VALUES "IdentityManager::values" followed by { }
|
||||
rank RESOURCE_POOL_INNER "ResourcePool::inner" followed by { }
|
||||
rank SURFACE_PRESENTATION "Surface::presentation" followed by { }
|
||||
rank TLAS_BUILT_INDEX "Tlas::built_index" followed by { }
|
||||
|
||||
@@ -17,8 +17,7 @@ use crate::device::trace::{Action, IntoTrace};
|
||||
use crate::{
|
||||
conv,
|
||||
device::{queue::Queue, Device, DeviceError, MissingDownlevelFlags, WaitIdleError},
|
||||
global::Global,
|
||||
hal_label, id,
|
||||
hal_label,
|
||||
instance::Surface,
|
||||
resource::{self, Labeled},
|
||||
};
|
||||
@@ -481,43 +480,3 @@ impl Surface {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn surface_get_current_texture(
|
||||
&self,
|
||||
surface_id: id::SurfaceId,
|
||||
texture_id_in: Option<id::TextureId>,
|
||||
) -> Result<SurfaceOutput<id::TextureId>, SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
let fid = self.hub.textures.prepare(texture_id_in);
|
||||
|
||||
let output = surface.get_current_texture()?;
|
||||
|
||||
let status = output.status;
|
||||
let texture_id = output.texture.map(|texture| fid.assign(texture));
|
||||
|
||||
Ok(SurfaceOutput {
|
||||
status,
|
||||
texture: texture_id,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn surface_present(&self, surface_id: id::SurfaceId) -> Result<Status, SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.present()
|
||||
}
|
||||
|
||||
pub fn surface_texture_discard(&self, surface_id: id::SurfaceId) -> Result<(), SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.discard()
|
||||
}
|
||||
|
||||
pub fn surface_texture_release(&self, surface_id: id::SurfaceId) -> Result<(), SurfaceError> {
|
||||
let surface = self.surfaces.get(surface_id);
|
||||
|
||||
surface.release()
|
||||
}
|
||||
}
|
||||
+2
-191
@@ -1,25 +1,9 @@
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use core::mem;
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use crate::id::{Id, Marker};
|
||||
use crate::id::Marker;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::{Epoch, Index};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
/// An entry in a `Storage::map` table.
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Element<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
/// There are no live ids with this index.
|
||||
Vacant,
|
||||
|
||||
/// There is one live id with this index, allocated at the given
|
||||
/// epoch.
|
||||
Occupied(T, Epoch),
|
||||
}
|
||||
|
||||
/// Not a public API. For use only by `player`.
|
||||
#[doc(hidden)]
|
||||
pub trait StorageItem: ResourceType {
|
||||
@@ -50,176 +34,3 @@ macro_rules! impl_storage_item {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// A table of `T` values indexed by the id type `I`.
|
||||
///
|
||||
/// `Storage` implements [`core::ops::Index`], accepting `Id` values as
|
||||
/// indices.
|
||||
///
|
||||
/// The table is represented as a vector indexed by the ids' index
|
||||
/// values, so you should use an id allocator like `IdentityManager`
|
||||
/// that keeps the index values dense and close to zero.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) map: Vec<Element<T>>,
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) fn new() -> Self {
|
||||
Self { map: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem,
|
||||
{
|
||||
pub(crate) fn insert(&mut self, id: Id<T::Marker>, value: T) {
|
||||
let (index, epoch) = id.unzip();
|
||||
let index = index as usize;
|
||||
if index >= self.map.len() {
|
||||
self.map.resize_with(index + 1, || Element::Vacant);
|
||||
}
|
||||
match mem::replace(&mut self.map[index], Element::Occupied(value, epoch)) {
|
||||
Element::Vacant => {}
|
||||
Element::Occupied(_, storage_epoch) => {
|
||||
panic!(
|
||||
"Cannot insert {id:?}, found existing resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index as Index, storage_epoch),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn remove(&mut self, id: Id<T::Marker>) -> T {
|
||||
let (index, epoch) = id.unzip();
|
||||
let stored = self.map.get_mut(index as usize);
|
||||
match stored.map(|stored| mem::replace(stored, Element::Vacant)) {
|
||||
Some(Element::Occupied(value, storage_epoch)) => {
|
||||
assert_eq!(
|
||||
epoch,
|
||||
storage_epoch,
|
||||
"Cannot remove {id:?}, found other resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index, storage_epoch),
|
||||
);
|
||||
value
|
||||
}
|
||||
None | Some(Element::Vacant) => {
|
||||
panic!("Cannot remove non-existent resource {id:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = (Id<T::Marker>, &T)> {
|
||||
self.map
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(move |(index, x)| match *x {
|
||||
Element::Occupied(ref value, storage_epoch) => {
|
||||
Some((Id::zip(index as Index, storage_epoch), value))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Storage<T>
|
||||
where
|
||||
T: StorageItem + Clone,
|
||||
{
|
||||
/// Get an owned reference to an item.
|
||||
/// Panics if there is an epoch mismatch, the entry is empty or in error.
|
||||
pub(crate) fn get(&self, id: Id<T::Marker>) -> T {
|
||||
let (index, epoch) = id.unzip();
|
||||
let (result, storage_epoch) = match self.map.get(index as usize) {
|
||||
Some(&Element::Occupied(ref v, epoch)) => (v.clone(), epoch),
|
||||
None | Some(&Element::Vacant) => {
|
||||
panic!("Cannot get non-existent resource {id:?}");
|
||||
}
|
||||
};
|
||||
assert_eq!(
|
||||
epoch,
|
||||
storage_epoch,
|
||||
"Cannot get {id:?}, found other resource {other:?}",
|
||||
other = Id::<T::Marker>::zip(index, storage_epoch),
|
||||
);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct TestItem;
|
||||
|
||||
impl ResourceType for TestItem {
|
||||
const TYPE: &'static str = "TestItem";
|
||||
}
|
||||
|
||||
impl StorageItem for TestItem {
|
||||
type Marker = ();
|
||||
}
|
||||
|
||||
fn id(index: Index, epoch: Epoch) -> Id<()> {
|
||||
Id::zip(index, epoch)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Cannot insert UntypedId(0,1), found existing resource UntypedId(0,1)"
|
||||
)]
|
||||
fn insert_occupied_same_epoch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Cannot insert UntypedId(0,2), found existing resource UntypedId(0,1)"
|
||||
)]
|
||||
fn insert_occupied_different_epoch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.insert(id(0, 2), TestItem);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot remove UntypedId(0,2), found other resource UntypedId(0,1)")]
|
||||
fn remove_epoch_mismatch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.remove(id(0, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot remove non-existent resource UntypedId(0,1)")]
|
||||
fn remove_vacant() {
|
||||
let mut storage = Storage::<TestItem>::new();
|
||||
storage.remove(id(0, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot get non-existent resource UntypedId(0,1)")]
|
||||
fn get_vacant() {
|
||||
let storage = Storage::<TestItem>::new();
|
||||
storage.get(id(0, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Cannot get UntypedId(0,2), found other resource UntypedId(0,1)")]
|
||||
fn get_epoch_mismatch() {
|
||||
let mut storage = Storage::new();
|
||||
storage.insert(id(0, 1), TestItem);
|
||||
storage.get(id(0, 2));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user