mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
Move MapMode into wgpu-types and use it instead of HostMap in wgpu-core (#10474)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
10 files changed
+39
-48
No files matched your search
@@ -12,8 +12,8 @@ use deno_core::webidl::WebIdlInterfaceConverter;
|
||||
use deno_core::GarbageCollected;
|
||||
use deno_core::WebIDL;
|
||||
use deno_error::JsErrorBox;
|
||||
use wgpu_core::device::HostMap as MapMode;
|
||||
use wgpu_core::resource::Labeled as _;
|
||||
use wgpu_types::MapMode;
|
||||
|
||||
use crate::error::GPUGenericError;
|
||||
|
||||
@@ -158,7 +158,7 @@ impl GPUBuffer {
|
||||
offset,
|
||||
size,
|
||||
wgpu_core::resource::BufferMapOperation {
|
||||
host: mode,
|
||||
mode,
|
||||
callback: Some(callback),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -196,7 +196,7 @@ impl GPUDevice {
|
||||
"unmapped"
|
||||
}),
|
||||
map_mode: RefCell::new(if descriptor.mapped_at_creation {
|
||||
Some(wgpu_core::device::HostMap::Write)
|
||||
Some(wgpu_types::MapMode::Write)
|
||||
} else {
|
||||
None
|
||||
}),
|
||||
|
||||
@@ -101,7 +101,7 @@ impl Test<'_> {
|
||||
expect.offset,
|
||||
Some(expect.data.len() as u64),
|
||||
wgc::resource::BufferMapOperation {
|
||||
host: wgc::device::HostMap::Read,
|
||||
mode: wgt::MapMode::Read,
|
||||
callback: Some(Box::new(map_callback)),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ use smallvec::SmallVec;
|
||||
use thiserror::Error;
|
||||
use wgt::{
|
||||
error::{ErrorType, WebGpuError},
|
||||
BufferAddress, DeviceLostReason, TextureFormat,
|
||||
BufferAddress, DeviceLostReason, MapMode, TextureFormat,
|
||||
};
|
||||
|
||||
pub(crate) mod bgl;
|
||||
@@ -40,14 +40,6 @@ pub(crate) const ENTRYPOINT_FAILURE_ERROR: &str = "The given EntryPoint is Inval
|
||||
pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor<Label<'a>>;
|
||||
pub type QueueDescriptor<'a> = wgt::QueueDescriptor<Label<'a>>;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum HostMap {
|
||||
Read,
|
||||
Write,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub(crate) struct AttachmentData<T> {
|
||||
@@ -231,7 +223,7 @@ pub(crate) fn map_buffer(
|
||||
buffer: &Buffer,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
kind: HostMap,
|
||||
kind: MapMode,
|
||||
snatch_guard: &SnatchGuard,
|
||||
) -> Result<hal::BufferMapping, BufferAccessError> {
|
||||
let raw_device = buffer.device.raw();
|
||||
@@ -242,7 +234,7 @@ pub(crate) fn map_buffer(
|
||||
.map_err(|e| buffer.device.handle_hal_error(e))?
|
||||
};
|
||||
|
||||
if !mapping.is_coherent && kind == HostMap::Read {
|
||||
if !mapping.is_coherent && kind == MapMode::Read {
|
||||
#[allow(clippy::single_range_in_vec_init)]
|
||||
unsafe {
|
||||
raw_device.invalidate_mapped_ranges(raw_buffer, &[offset..offset + size]);
|
||||
@@ -269,7 +261,7 @@ pub(crate) fn map_buffer(
|
||||
|
||||
// We can't call flush_mapped_ranges in this case, so we can't drain the uninitialized ranges either
|
||||
if !mapping.is_coherent
|
||||
&& kind == HostMap::Read
|
||||
&& kind == MapMode::Read
|
||||
&& !buffer.usage.contains(wgt::BufferUsages::MAP_WRITE)
|
||||
{
|
||||
for uninitialized in buffer
|
||||
@@ -297,7 +289,7 @@ pub(crate) fn map_buffer(
|
||||
|
||||
// NOTE: This is only possible when MAPPABLE_PRIMARY_BUFFERS is enabled.
|
||||
if !mapping.is_coherent
|
||||
&& kind == HostMap::Read
|
||||
&& kind == MapMode::Read
|
||||
&& buffer.usage.contains(wgt::BufferUsages::MAP_WRITE)
|
||||
{
|
||||
unsafe { raw_device.flush_mapped_ranges(raw_buffer, &[uninitialized]) };
|
||||
|
||||
@@ -34,7 +34,7 @@ use crate::{
|
||||
command, conv,
|
||||
device::{
|
||||
bgl, create_validator, life::WaitIdleError, map_buffer, AttachmentData,
|
||||
BufferMapPendingClosure, DeviceLostInvocation, HostMap, MissingDownlevelFlags,
|
||||
BufferMapPendingClosure, DeviceLostInvocation, MapMode, MissingDownlevelFlags,
|
||||
MissingFeatures, RenderPassContext,
|
||||
},
|
||||
error::ErrorSink,
|
||||
@@ -1311,7 +1311,7 @@ impl Device {
|
||||
buffer,
|
||||
tail_start,
|
||||
final_size - tail_start,
|
||||
HostMap::Write,
|
||||
MapMode::Write,
|
||||
snatch_guard,
|
||||
)?;
|
||||
let raw = buffer
|
||||
@@ -1373,13 +1373,13 @@ impl Device {
|
||||
is_coherent: true,
|
||||
}
|
||||
} else {
|
||||
map_buffer(&buffer, 0, map_size, HostMap::Write, &snatch_guard)?
|
||||
map_buffer(&buffer, 0, map_size, MapMode::Write, &snatch_guard)?
|
||||
};
|
||||
drop(snatch_guard);
|
||||
*buffer.map_state.lock() = resource::BufferMapState::Active {
|
||||
mapping,
|
||||
range: 0..map_size,
|
||||
host: HostMap::Write,
|
||||
host: MapMode::Write,
|
||||
};
|
||||
wgt::BufferUses::MAP_WRITE
|
||||
} else {
|
||||
|
||||
+11
-11
@@ -12,7 +12,7 @@ use thiserror::Error;
|
||||
use wgt::{
|
||||
error::{ErrorType, WebGpuError},
|
||||
math::align_to,
|
||||
TextureSelector,
|
||||
MapMode, TextureSelector,
|
||||
};
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
binding_model::{BindGroup, BindingError},
|
||||
device::{
|
||||
queue, resource::DeferredDestroy, BufferMapPendingClosure, Device, DeviceError,
|
||||
DeviceMismatch, HostMap, MissingDownlevelFlags, MissingFeatures,
|
||||
DeviceMismatch, MissingDownlevelFlags, MissingFeatures,
|
||||
},
|
||||
hal_label,
|
||||
init_tracker::{BufferInitTracker, TextureInitTracker},
|
||||
@@ -256,7 +256,7 @@ pub(crate) enum BufferMapState {
|
||||
Active {
|
||||
mapping: hal::BufferMapping,
|
||||
range: hal::MemoryRange,
|
||||
host: HostMap,
|
||||
host: MapMode,
|
||||
},
|
||||
/// Not mapped
|
||||
Idle,
|
||||
@@ -273,14 +273,14 @@ pub type BufferMapCallback = Box<dyn FnOnce(BufferAccessResult) + Send + 'static
|
||||
pub type BufferMapCallback = Box<dyn FnOnce(BufferAccessResult) + 'static>;
|
||||
|
||||
pub struct BufferMapOperation {
|
||||
pub host: HostMap,
|
||||
pub mode: MapMode,
|
||||
pub callback: Option<BufferMapCallback>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for BufferMapOperation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("BufferMapOperation")
|
||||
.field("host", &self.host)
|
||||
.field("mode", &self.mode)
|
||||
.field("callback", &self.callback.as_ref().map(|_| "?"))
|
||||
.finish()
|
||||
}
|
||||
@@ -795,9 +795,9 @@ impl Buffer {
|
||||
return Err((op, BufferAccessError::UnalignedRange));
|
||||
}
|
||||
|
||||
let (pub_usage, internal_use) = match op.host {
|
||||
HostMap::Read => (wgt::BufferUsages::MAP_READ, wgt::BufferUses::MAP_READ),
|
||||
HostMap::Write => (wgt::BufferUsages::MAP_WRITE, wgt::BufferUses::MAP_WRITE),
|
||||
let (pub_usage, internal_use) = match op.mode {
|
||||
MapMode::Read => (wgt::BufferUsages::MAP_READ, wgt::BufferUses::MAP_READ),
|
||||
MapMode::Write => (wgt::BufferUsages::MAP_WRITE, wgt::BufferUses::MAP_WRITE),
|
||||
};
|
||||
|
||||
if let Err(e) = self.check_usage(pub_usage) {
|
||||
@@ -999,7 +999,7 @@ impl Buffer {
|
||||
let status = if let Err(error) = self.device.check_is_valid() {
|
||||
Err(error.into())
|
||||
} else if pending_mapping.range.start != pending_mapping.range.end {
|
||||
let host = pending_mapping.op.host;
|
||||
let host = pending_mapping.op.mode;
|
||||
let size = pending_mapping.range.end - pending_mapping.range.start;
|
||||
match crate::device::map_buffer(
|
||||
self,
|
||||
@@ -1025,7 +1025,7 @@ impl Buffer {
|
||||
is_coherent: true,
|
||||
},
|
||||
range: pending_mapping.range,
|
||||
host: pending_mapping.op.host,
|
||||
host: pending_mapping.op.mode,
|
||||
};
|
||||
Ok(())
|
||||
};
|
||||
@@ -1130,7 +1130,7 @@ impl Buffer {
|
||||
range,
|
||||
host,
|
||||
} => {
|
||||
if host == HostMap::Write {
|
||||
if host == MapMode::Write {
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut trace) = *device.trace.lock() {
|
||||
use crate::device::trace::{DataKind, IntoTrace};
|
||||
|
||||
@@ -176,3 +176,15 @@ pub struct BufferTransition<T> {
|
||||
/// The new state to transition to.
|
||||
pub state: BufferUses,
|
||||
}
|
||||
|
||||
/// Type of buffer mapping.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum MapMode {
|
||||
/// Map only for reading
|
||||
Read,
|
||||
/// Map only for writing
|
||||
Write,
|
||||
}
|
||||
static_assertions::assert_impl_all!(MapMode: Send, Sync);
|
||||
@@ -932,16 +932,6 @@ impl fmt::Display for MapRangeError {
|
||||
|
||||
impl error::Error for MapRangeError {}
|
||||
|
||||
/// Type of buffer mapping.
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum MapMode {
|
||||
/// Map only for reading
|
||||
Read,
|
||||
/// Map only for writing
|
||||
Write,
|
||||
}
|
||||
static_assertions::assert_impl_all!(MapMode: Send, Sync);
|
||||
|
||||
/// A read-only view of a mapped buffer's bytes.
|
||||
///
|
||||
/// To get a `BufferView`, first [map] the buffer, and then
|
||||
|
||||
@@ -26,7 +26,7 @@ use wgt::WasmNotSendSync;
|
||||
use crate::{
|
||||
api,
|
||||
dispatch::{self, BlasCompactCallback, BufferMappedRangeInterface},
|
||||
BindingResource, Blas, BufferBinding, BufferDescriptor, Features, LoadOp, MapMode, Operations,
|
||||
BindingResource, Blas, BufferBinding, BufferDescriptor, Features, LoadOp, Operations,
|
||||
ShaderSource, SurfaceTargetUnsafe, TextureDescriptor, Tlas, WriteOnly,
|
||||
};
|
||||
use crate::{dispatch::DispatchAdapter, util::Mutex};
|
||||
@@ -1807,10 +1807,7 @@ impl dispatch::BufferInterface for CoreBuffer {
|
||||
callback: dispatch::BufferMapCallback,
|
||||
) {
|
||||
let operation = wgc::resource::BufferMapOperation {
|
||||
host: match mode {
|
||||
MapMode::Read => wgc::device::HostMap::Read,
|
||||
MapMode::Write => wgc::device::HostMap::Write,
|
||||
},
|
||||
mode,
|
||||
callback: Some(Box::new(|status| {
|
||||
let res = status.map_err(|_| crate::BufferAsyncError);
|
||||
callback(res);
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ pub use wgt::{
|
||||
Features, FeaturesWGPU, FeaturesWebGPU, FilterMode, ForceShaderModelToken, FrontFace,
|
||||
GlBackendOptions, GlDebugFns, GlFenceBehavior, Gles3MinorVersion, HalCounters,
|
||||
ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters,
|
||||
Limits, LoadOpDontCare, MemoryBudgetThresholds, MemoryHints, MipmapFilterMode,
|
||||
Limits, LoadOpDontCare, MapMode, MemoryBudgetThresholds, MemoryHints, MipmapFilterMode,
|
||||
MultisampleState, NoopBackendOptions, Origin2d, Origin3d, PassthroughShaderEntryPoint,
|
||||
PipelineStatisticsTypes, PollError, PollStatus, PolygonMode, PowerPreference,
|
||||
PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
|
||||
|
||||
Reference in new issue
Block a user