mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
* WIP * Fix typo * WIP: Implement structure of command_encoder_transition_resources * WIP * More work * Clippy * Fix web build * Use new types for API, more docs * Add very basic test * Try to fix test cfg * Fix merge * Missed commit * Use wgt types instead of hal types * Implement `Clone` for `ShaderModule` (#6939) * Move to dispatch trait, move more things to wgt * Move existing code to use new wgt types * Fixes * Format import * Format another file * Fixes * Make module private * Fix imports * Fix test imports * Rexport types * Fix imports * Fix import --------- Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use crate::device::{Device, DeviceError};
|
|
use crate::resource_log;
|
|
use std::mem::ManuallyDrop;
|
|
use std::sync::Arc;
|
|
use wgt::BufferUses;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ScratchBuffer {
|
|
raw: ManuallyDrop<Box<dyn hal::DynBuffer>>,
|
|
device: Arc<Device>,
|
|
}
|
|
|
|
impl ScratchBuffer {
|
|
pub(crate) fn new(device: &Arc<Device>, size: wgt::BufferSize) -> Result<Self, DeviceError> {
|
|
let raw = unsafe {
|
|
device
|
|
.raw()
|
|
.create_buffer(&hal::BufferDescriptor {
|
|
label: Some("(wgpu) scratch buffer"),
|
|
size: size.get(),
|
|
usage: BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
|
|
memory_flags: hal::MemoryFlags::empty(),
|
|
})
|
|
.map_err(DeviceError::from_hal)?
|
|
};
|
|
Ok(Self {
|
|
raw: ManuallyDrop::new(raw),
|
|
device: device.clone(),
|
|
})
|
|
}
|
|
pub(crate) fn raw(&self) -> &dyn hal::DynBuffer {
|
|
self.raw.as_ref()
|
|
}
|
|
}
|
|
|
|
impl Drop for ScratchBuffer {
|
|
fn drop(&mut self) {
|
|
resource_log!("Destroy raw ScratchBuffer");
|
|
// SAFETY: We are in the Drop impl and we don't use self.raw anymore after this point.
|
|
let raw = unsafe { ManuallyDrop::take(&mut self.raw) };
|
|
unsafe { self.device.raw().destroy_buffer(raw) };
|
|
}
|
|
}
|