Transition resources (#6678)

* 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>
This commit is contained in:
authored and GitHub committed 2025-01-24 00:54:19 -05:00
1 parent d8e7ab1ad1
commit 0fc0b35899
58 files changed
+807 -551

No files matched your search

+1
View File
@@ -284,6 +284,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
- Image atomic support in shaders. By @atlv24 in [#6706](https://github.com/gfx-rs/wgpu/pull/6706)
- 64 bit image atomic support in shaders. By @atlv24 in [#5537](https://github.com/gfx-rs/wgpu/pull/5537)
- Add `no_std` support to `wgpu-types`. By @bushrat011899 in [#6892](https://github.com/gfx-rs/wgpu/pull/6892).
- Added `CommandEncoder::transition_resources()` for native API interop, and allowing users to slightly optimize barriers. By @JMS55 in [6678](https://github.com/gfx-rs/wgpu/pull/6678).
##### Vulkan
+1
View File
@@ -54,6 +54,7 @@ mod texture_blit;
mod texture_bounds;
mod texture_view_creation;
mod transfer;
mod transition_resources;
mod vertex_formats;
mod vertex_indices;
mod write_texture;
+35
View File
@@ -0,0 +1,35 @@
use wgpu_test::{gpu_test, GpuTestConfiguration};
#[gpu_test]
static TRANSITION_RESOURCES: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| {
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
width: 32,
height: 32,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
});
let mut encoder = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.transition_resources(
std::iter::empty(),
[wgpu::TextureTransition {
texture: &texture,
selector: None,
state: wgpu::TextureUses::COLOR_TARGET,
}]
.into_iter(),
);
ctx.queue.submit([encoder.finish()]);
});
+3 -3
View File
@@ -683,7 +683,7 @@ fn set_index_buffer(
state
.trackers
.buffers
.merge_single(&buffer, hal::BufferUses::INDEX)?;
.merge_single(&buffer, wgt::BufferUses::INDEX)?;
buffer.same_device(&state.device)?;
buffer.check_usage(wgt::BufferUsages::INDEX)?;
@@ -725,7 +725,7 @@ fn set_vertex_buffer(
state
.trackers
.buffers
.merge_single(&buffer, hal::BufferUses::VERTEX)?;
.merge_single(&buffer, wgt::BufferUses::VERTEX)?;
buffer.same_device(&state.device)?;
buffer.check_usage(wgt::BufferUsages::VERTEX)?;
@@ -864,7 +864,7 @@ fn multi_draw_indirect(
state
.trackers
.buffers
.merge_single(&buffer, hal::BufferUses::INDIRECT)?;
.merge_single(&buffer, wgt::BufferUses::INDIRECT)?;
buffer.same_device(&state.device)?;
buffer.check_usage(wgt::BufferUsages::INDIRECT)?;
+11 -8
View File
@@ -15,11 +15,14 @@ use crate::{
ParentDevice, ResourceErrorIdent, Texture, TextureClearMode,
},
snatch::SnatchGuard,
track::{TextureSelector, TextureTrackerSetSingle},
track::TextureTrackerSetSingle,
};
use thiserror::Error;
use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect};
use wgt::{
math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect,
TextureSelector,
};
/// Error encountered while attempting a clear.
#[derive(Clone, Debug, Error)]
@@ -107,7 +110,7 @@ impl Global {
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
.set_single(&dst_buffer, wgt::BufferUses::COPY_DST);
let snatch_guard = dst_buffer.device.snatchable_lock.read();
let dst_raw = dst_buffer.try_raw(&snatch_guard)?;
@@ -269,12 +272,12 @@ pub(crate) fn clear_texture<T: TextureTrackerSetSingle>(
// Issue the right barrier.
let clear_usage = match dst_texture.clear_mode {
TextureClearMode::BufferCopy => hal::TextureUses::COPY_DST,
TextureClearMode::BufferCopy => wgt::TextureUses::COPY_DST,
TextureClearMode::RenderPass {
is_color: false, ..
} => hal::TextureUses::DEPTH_STENCIL_WRITE,
} => wgt::TextureUses::DEPTH_STENCIL_WRITE,
TextureClearMode::Surface { .. } | TextureClearMode::RenderPass { is_color: true, .. } => {
hal::TextureUses::COLOR_TARGET
wgt::TextureUses::COLOR_TARGET
}
TextureClearMode::None => {
return Err(ClearError::NoValidTextureClearMode(
@@ -455,7 +458,7 @@ fn clear_texture_via_render_passes(
mip_level,
depth_or_layer,
),
usage: hal::TextureUses::COLOR_TARGET,
usage: wgt::TextureUses::COLOR_TARGET,
},
resolve_target: None,
ops: hal::AttachmentOps::STORE,
@@ -473,7 +476,7 @@ fn clear_texture_via_render_passes(
mip_level,
depth_or_layer,
),
usage: hal::TextureUses::DEPTH_STENCIL_WRITE,
usage: wgt::TextureUses::DEPTH_STENCIL_WRITE,
},
depth_ops: hal::AttachmentOps::STORE,
stencil_ops: hal::AttachmentOps::STORE,
+6 -6
View File
@@ -938,7 +938,7 @@ fn dispatch_indirect(
let src_transition = state
.intermediate_trackers
.buffers
.set_single(&buffer, hal::BufferUses::STORAGE_READ_ONLY);
.set_single(&buffer, wgt::BufferUses::STORAGE_READ_ONLY);
let src_barrier =
src_transition.map(|transition| transition.into_hal(&buffer, &state.snatch_guard));
unsafe {
@@ -949,8 +949,8 @@ fn dispatch_indirect(
state.raw_encoder.transition_buffers(&[hal::BufferBarrier {
buffer: params.dst_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::INDIRECT,
to: hal::BufferUses::STORAGE_READ_WRITE,
from: wgt::BufferUses::INDIRECT,
to: wgt::BufferUses::STORAGE_READ_WRITE,
},
}]);
}
@@ -996,8 +996,8 @@ fn dispatch_indirect(
state.raw_encoder.transition_buffers(&[hal::BufferBarrier {
buffer: params.dst_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::STORAGE_READ_WRITE,
to: hal::BufferUses::INDIRECT,
from: wgt::BufferUses::STORAGE_READ_WRITE,
to: wgt::BufferUses::INDIRECT,
},
}]);
}
@@ -1012,7 +1012,7 @@ fn dispatch_indirect(
state
.scope
.buffers
.merge_single(&buffer, hal::BufferUses::INDIRECT)?;
.merge_single(&buffer, wgt::BufferUses::INDIRECT)?;
use crate::resource::Trackable;
state.flush_states(Some(buffer.tracker_index()))?;
+1 -1
View File
@@ -213,7 +213,7 @@ impl BakedCommands {
// must already know about it.
let transition = device_tracker
.buffers
.set_single(&buffer, hal::BufferUses::COPY_DST);
.set_single(&buffer, wgt::BufferUses::COPY_DST);
let raw_buf = buffer.try_raw(snatch_guard)?;
+1
View File
@@ -12,6 +12,7 @@ mod render;
mod render_command;
mod timestamp_writes;
mod transfer;
mod transition_resources;
use std::mem::{self, ManuallyDrop};
use std::sync::Arc;
+1 -1
View File
@@ -396,7 +396,7 @@ impl Global {
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
.set_single(&dst_buffer, wgt::BufferUses::COPY_DST);
let dst_barrier = dst_pending.map(|pending| pending.into_hal(&dst_buffer, &snatch_guard));
+1 -2
View File
@@ -17,10 +17,9 @@ use crate::{
FastHashSet,
};
use wgt::{math::align_to, BufferUsages, Features};
use wgt::{math::align_to, BufferUsages, BufferUses, Features};
use super::CommandBufferMutable;
use hal::BufferUses;
use std::{
cmp::max,
num::NonZeroU64,
+16 -16
View File
@@ -29,7 +29,7 @@ use crate::{
DestroyedResourceError, Labeled, MissingBufferUsageError, MissingTextureUsageError,
ParentDevice, QuerySet, Texture, TextureView, TextureViewNotRenderableReason,
},
track::{ResourceUsageCompatibilityError, TextureSelector, Tracker, UsageScope},
track::{ResourceUsageCompatibilityError, Tracker, UsageScope},
Label,
};
@@ -37,7 +37,7 @@ use arrayvec::ArrayVec;
use thiserror::Error;
use wgt::{
BufferAddress, BufferSize, BufferUsages, Color, DynamicOffset, IndexFormat, ShaderStages,
TextureUsages, TextureViewDimension, VertexStepMode,
TextureSelector, TextureUsages, TextureViewDimension, VertexStepMode,
};
#[cfg(feature = "serde")]
@@ -779,11 +779,11 @@ where
struct RenderAttachment {
texture: Arc<Texture>,
selector: TextureSelector,
usage: hal::TextureUses,
usage: wgt::TextureUses,
}
impl TextureView {
fn to_render_attachment(&self, usage: hal::TextureUses) -> RenderAttachment {
fn to_render_attachment(&self, usage: wgt::TextureUses) -> RenderAttachment {
RenderAttachment {
texture: self.parent.clone(),
selector: self.selector.clone(),
@@ -1049,9 +1049,9 @@ impl<'d> RenderPassInfo<'d> {
.flags
.contains(wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL)
{
hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::RESOURCE
wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::RESOURCE
} else {
hal::TextureUses::DEPTH_STENCIL_WRITE
wgt::TextureUses::DEPTH_STENCIL_WRITE
};
render_attachments.push(view.to_render_attachment(usage));
@@ -1104,7 +1104,7 @@ impl<'d> RenderPassInfo<'d> {
&mut pending_discard_init_fixups,
);
render_attachments
.push(color_view.to_render_attachment(hal::TextureUses::COLOR_TARGET));
.push(color_view.to_render_attachment(wgt::TextureUses::COLOR_TARGET));
let mut hal_resolve_target = None;
if let Some(resolve_view) = &at.resolve_target {
@@ -1160,18 +1160,18 @@ impl<'d> RenderPassInfo<'d> {
TextureInitRange::from(resolve_view.selector.clone()),
);
render_attachments
.push(resolve_view.to_render_attachment(hal::TextureUses::COLOR_TARGET));
.push(resolve_view.to_render_attachment(wgt::TextureUses::COLOR_TARGET));
hal_resolve_target = Some(hal::Attachment {
view: resolve_view.try_raw(snatch_guard)?,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgt::TextureUses::COLOR_TARGET,
});
}
color_attachments_hal.push(Some(hal::ColorAttachment {
target: hal::Attachment {
view: color_view.try_raw(snatch_guard)?,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgt::TextureUses::COLOR_TARGET,
},
resolve_target: hal_resolve_target,
ops: at.hal_ops(),
@@ -1333,7 +1333,7 @@ impl<'d> RenderPassInfo<'d> {
depth_stencil_attachment: Some(hal::DepthStencilAttachment {
target: hal::Attachment {
view: view.try_raw(snatch_guard)?,
usage: hal::TextureUses::DEPTH_STENCIL_WRITE,
usage: wgt::TextureUses::DEPTH_STENCIL_WRITE,
},
depth_ops,
stencil_ops,
@@ -2167,7 +2167,7 @@ fn set_index_buffer(
.info
.usage_scope
.buffers
.merge_single(&buffer, hal::BufferUses::INDEX)?;
.merge_single(&buffer, wgt::BufferUses::INDEX)?;
buffer.same_device_as(cmd_buf.as_ref())?;
@@ -2216,7 +2216,7 @@ fn set_vertex_buffer(
.info
.usage_scope
.buffers
.merge_single(&buffer, hal::BufferUses::VERTEX)?;
.merge_single(&buffer, wgt::BufferUses::VERTEX)?;
buffer.same_device_as(cmd_buf.as_ref())?;
@@ -2496,7 +2496,7 @@ fn multi_draw_indirect(
.info
.usage_scope
.buffers
.merge_single(&indirect_buffer, hal::BufferUses::INDIRECT)?;
.merge_single(&indirect_buffer, wgt::BufferUses::INDIRECT)?;
indirect_buffer.check_usage(BufferUsages::INDIRECT)?;
let indirect_raw = indirect_buffer.try_raw(state.snatch_guard)?;
@@ -2573,7 +2573,7 @@ fn multi_draw_indirect_count(
.info
.usage_scope
.buffers
.merge_single(&indirect_buffer, hal::BufferUses::INDIRECT)?;
.merge_single(&indirect_buffer, wgt::BufferUses::INDIRECT)?;
indirect_buffer.check_usage(BufferUsages::INDIRECT)?;
let indirect_raw = indirect_buffer.try_raw(state.snatch_guard)?;
@@ -2582,7 +2582,7 @@ fn multi_draw_indirect_count(
.info
.usage_scope
.buffers
.merge_single(&count_buffer, hal::BufferUses::INDIRECT)?;
.merge_single(&count_buffer, wgt::BufferUses::INDIRECT)?;
count_buffer.check_usage(BufferUsages::INDIRECT)?;
let count_raw = count_buffer.try_raw(state.snatch_guard)?;
+11 -12
View File
@@ -16,12 +16,11 @@ use crate::{
MissingTextureUsageError, ParentDevice, Texture, TextureErrorDimension,
},
snatch::SnatchGuard,
track::TextureSelector,
};
use arrayvec::ArrayVec;
use thiserror::Error;
use wgt::{BufferAddress, BufferUsages, Extent3d, TextureUsages};
use wgt::{BufferAddress, BufferUsages, Extent3d, TextureSelector, TextureUsages};
use std::sync::Arc;
@@ -576,7 +575,7 @@ impl Global {
let src_pending = cmd_buf_data
.trackers
.buffers
.set_single(&src_buffer, hal::BufferUses::COPY_SRC);
.set_single(&src_buffer, wgt::BufferUses::COPY_SRC);
let src_raw = src_buffer.try_raw(&snatch_guard)?;
src_buffer
@@ -592,7 +591,7 @@ impl Global {
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
.set_single(&dst_buffer, wgt::BufferUses::COPY_DST);
let dst_raw = dst_buffer.try_raw(&snatch_guard)?;
dst_buffer
@@ -767,7 +766,7 @@ impl Global {
let src_pending = cmd_buf_data
.trackers
.buffers
.set_single(&src_buffer, hal::BufferUses::COPY_SRC);
.set_single(&src_buffer, wgt::BufferUses::COPY_SRC);
let src_raw = src_buffer.try_raw(&snatch_guard)?;
src_buffer
@@ -778,7 +777,7 @@ impl Global {
let dst_pending = cmd_buf_data.trackers.textures.set_single(
&dst_texture,
dst_range,
hal::TextureUses::COPY_DST,
wgt::TextureUses::COPY_DST,
);
let dst_raw = dst_texture.try_raw(&snatch_guard)?;
dst_texture
@@ -916,7 +915,7 @@ impl Global {
let src_pending = cmd_buf_data.trackers.textures.set_single(
&src_texture,
src_range,
hal::TextureUses::COPY_SRC,
wgt::TextureUses::COPY_SRC,
);
let src_raw = src_texture.try_raw(&snatch_guard)?;
src_texture
@@ -946,7 +945,7 @@ impl Global {
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
.set_single(&dst_buffer, wgt::BufferUses::COPY_DST);
let dst_raw = dst_buffer.try_raw(&snatch_guard)?;
dst_buffer
@@ -1010,7 +1009,7 @@ impl Global {
cmd_buf_raw.transition_textures(&src_barrier);
cmd_buf_raw.copy_texture_to_buffer(
src_raw,
hal::TextureUses::COPY_SRC,
wgt::TextureUses::COPY_SRC,
dst_raw,
&regions,
);
@@ -1125,7 +1124,7 @@ impl Global {
let src_pending = cmd_buf_data.trackers.textures.set_single(
&src_texture,
src_range,
hal::TextureUses::COPY_SRC,
wgt::TextureUses::COPY_SRC,
);
let src_raw = src_texture.try_raw(&snatch_guard)?;
src_texture
@@ -1141,7 +1140,7 @@ impl Global {
let dst_pending = cmd_buf_data.trackers.textures.set_single(
&dst_texture,
dst_range,
hal::TextureUses::COPY_DST,
wgt::TextureUses::COPY_DST,
);
let dst_raw = dst_texture.try_raw(&snatch_guard)?;
dst_texture
@@ -1173,7 +1172,7 @@ impl Global {
cmd_buf_raw.transition_textures(&barriers);
cmd_buf_raw.copy_texture_to_texture(
src_raw,
hal::TextureUses::COPY_SRC,
wgt::TextureUses::COPY_SRC,
dst_raw,
&regions,
);
@@ -0,0 +1,93 @@
use thiserror::Error;
use crate::{
command::CommandBuffer,
device::DeviceError,
global::Global,
id::{BufferId, CommandEncoderId, TextureId},
resource::{InvalidResourceError, ParentDevice},
track::ResourceUsageCompatibilityError,
};
use super::CommandEncoderError;
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<(), TransitionResourcesError> {
profiling::scope!("CommandEncoder::transition_resources");
let hub = &self.hub;
// Lock command encoder for recording
let cmd_buf = hub
.command_buffers
.get(command_encoder_id.into_command_buffer_id());
let mut cmd_buf_data = cmd_buf.data.lock();
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
let cmd_buf_data = &mut *cmd_buf_data_guard;
// Get and lock device
let device = &cmd_buf.device;
device.check_is_valid()?;
let snatch_guard = &device.snatchable_lock.read();
let mut usage_scope = device.new_usage_scope();
let indices = &device.tracker_indices;
usage_scope.buffers.set_size(indices.buffers.size());
usage_scope.textures.set_size(indices.textures.size());
// Process buffer transitions
for buffer_transition in buffer_transitions {
let buffer = hub.buffers.get(buffer_transition.buffer).get()?;
buffer.same_device_as(cmd_buf.as_ref())?;
usage_scope
.buffers
.merge_single(&buffer, buffer_transition.state)?;
}
// Process texture transitions
for texture_transition in texture_transitions {
let texture = hub.textures.get(texture_transition.texture).get()?;
texture.same_device_as(cmd_buf.as_ref())?;
unsafe {
usage_scope.textures.merge_single(
&texture,
texture_transition.selector,
texture_transition.state,
)
}?;
}
// Record any needed barriers based on tracker data
let cmd_buf_raw = cmd_buf_data.encoder.open()?;
CommandBuffer::insert_barriers_from_scope(
cmd_buf_raw,
&mut cmd_buf_data.trackers,
&usage_scope,
snatch_guard,
);
cmd_buf_data_guard.mark_successful();
Ok(())
}
}
/// Error encountered while attempting to perform [`Global::command_encoder_transition_resources`].
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum TransitionResourcesError {
#[error(transparent)]
Device(#[from] DeviceError),
#[error(transparent)]
Encoder(#[from] CommandEncoderError),
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
#[error(transparent)]
ResourceUsage(#[from] ResourceUsageCompatibilityError),
}
+39 -39
View File
@@ -51,54 +51,54 @@ pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureForma
}
}
pub fn map_buffer_usage(usage: wgt::BufferUsages) -> hal::BufferUses {
let mut u = hal::BufferUses::empty();
pub fn map_buffer_usage(usage: wgt::BufferUsages) -> wgt::BufferUses {
let mut u = wgt::BufferUses::empty();
u.set(
hal::BufferUses::MAP_READ,
wgt::BufferUses::MAP_READ,
usage.contains(wgt::BufferUsages::MAP_READ),
);
u.set(
hal::BufferUses::MAP_WRITE,
wgt::BufferUses::MAP_WRITE,
usage.contains(wgt::BufferUsages::MAP_WRITE),
);
u.set(
hal::BufferUses::COPY_SRC,
wgt::BufferUses::COPY_SRC,
usage.contains(wgt::BufferUsages::COPY_SRC),
);
u.set(
hal::BufferUses::COPY_DST,
wgt::BufferUses::COPY_DST,
usage.contains(wgt::BufferUsages::COPY_DST),
);
u.set(
hal::BufferUses::INDEX,
wgt::BufferUses::INDEX,
usage.contains(wgt::BufferUsages::INDEX),
);
u.set(
hal::BufferUses::VERTEX,
wgt::BufferUses::VERTEX,
usage.contains(wgt::BufferUsages::VERTEX),
);
u.set(
hal::BufferUses::UNIFORM,
wgt::BufferUses::UNIFORM,
usage.contains(wgt::BufferUsages::UNIFORM),
);
u.set(
hal::BufferUses::STORAGE_READ_ONLY | hal::BufferUses::STORAGE_READ_WRITE,
wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE,
usage.contains(wgt::BufferUsages::STORAGE),
);
u.set(
hal::BufferUses::INDIRECT,
wgt::BufferUses::INDIRECT,
usage.contains(wgt::BufferUsages::INDIRECT),
);
u.set(
hal::BufferUses::QUERY_RESOLVE,
wgt::BufferUses::QUERY_RESOLVE,
usage.contains(wgt::BufferUsages::QUERY_RESOLVE),
);
u.set(
hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage.contains(wgt::BufferUsages::BLAS_INPUT),
);
u.set(
hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage.contains(wgt::BufferUsages::TLAS_INPUT),
);
u
@@ -108,45 +108,45 @@ pub fn map_texture_usage(
usage: wgt::TextureUsages,
aspect: hal::FormatAspects,
flags: wgt::TextureFormatFeatureFlags,
) -> hal::TextureUses {
let mut u = hal::TextureUses::empty();
) -> wgt::TextureUses {
let mut u = wgt::TextureUses::empty();
u.set(
hal::TextureUses::COPY_SRC,
wgt::TextureUses::COPY_SRC,
usage.contains(wgt::TextureUsages::COPY_SRC),
);
u.set(
hal::TextureUses::COPY_DST,
wgt::TextureUses::COPY_DST,
usage.contains(wgt::TextureUsages::COPY_DST),
);
u.set(
hal::TextureUses::RESOURCE,
wgt::TextureUses::RESOURCE,
usage.contains(wgt::TextureUsages::TEXTURE_BINDING),
);
if usage.contains(wgt::TextureUsages::STORAGE_BINDING) {
u.set(
hal::TextureUses::STORAGE_READ_ONLY,
wgt::TextureUses::STORAGE_READ_ONLY,
flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_READ_ONLY),
);
u.set(
hal::TextureUses::STORAGE_WRITE_ONLY,
wgt::TextureUses::STORAGE_WRITE_ONLY,
flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_WRITE_ONLY),
);
u.set(
hal::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::STORAGE_READ_WRITE,
flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_READ_WRITE),
);
}
let is_color = aspect.contains(hal::FormatAspects::COLOR);
u.set(
hal::TextureUses::COLOR_TARGET,
wgt::TextureUses::COLOR_TARGET,
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && is_color,
);
u.set(
hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::DEPTH_STENCIL_WRITE,
wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE,
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && !is_color,
);
u.set(
hal::TextureUses::STORAGE_ATOMIC,
wgt::TextureUses::STORAGE_ATOMIC,
usage.contains(wgt::TextureUsages::STORAGE_ATOMIC),
);
u
@@ -155,14 +155,14 @@ pub fn map_texture_usage(
pub fn map_texture_usage_for_texture(
desc: &TextureDescriptor,
format_features: &TextureFormatFeatures,
) -> hal::TextureUses {
) -> wgt::TextureUses {
// Enforce having COPY_DST/DEPTH_STENCIL_WRITE/COLOR_TARGET otherwise we
// wouldn't be able to initialize the texture.
map_texture_usage(desc.usage, desc.format.into(), format_features.flags)
| if desc.format.is_depth_stencil_format() {
hal::TextureUses::DEPTH_STENCIL_WRITE
wgt::TextureUses::DEPTH_STENCIL_WRITE
} else if desc.usage.contains(wgt::TextureUsages::COPY_DST) {
hal::TextureUses::COPY_DST // (set already)
wgt::TextureUses::COPY_DST // (set already)
} else {
// Use COPY_DST only if we can't use COLOR_TARGET
if format_features
@@ -171,42 +171,42 @@ pub fn map_texture_usage_for_texture(
&& desc.dimension == wgt::TextureDimension::D2
// Render targets dimension must be 2d
{
hal::TextureUses::COLOR_TARGET
wgt::TextureUses::COLOR_TARGET
} else {
hal::TextureUses::COPY_DST
wgt::TextureUses::COPY_DST
}
}
}
pub fn map_texture_usage_from_hal(uses: hal::TextureUses) -> wgt::TextureUsages {
pub fn map_texture_usage_from_hal(uses: wgt::TextureUses) -> wgt::TextureUsages {
let mut u = wgt::TextureUsages::empty();
u.set(
wgt::TextureUsages::COPY_SRC,
uses.contains(hal::TextureUses::COPY_SRC),
uses.contains(wgt::TextureUses::COPY_SRC),
);
u.set(
wgt::TextureUsages::COPY_DST,
uses.contains(hal::TextureUses::COPY_DST),
uses.contains(wgt::TextureUses::COPY_DST),
);
u.set(
wgt::TextureUsages::TEXTURE_BINDING,
uses.contains(hal::TextureUses::RESOURCE),
uses.contains(wgt::TextureUses::RESOURCE),
);
u.set(
wgt::TextureUsages::STORAGE_BINDING,
uses.intersects(
hal::TextureUses::STORAGE_READ_ONLY
| hal::TextureUses::STORAGE_WRITE_ONLY
| hal::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
),
);
u.set(
wgt::TextureUsages::RENDER_ATTACHMENT,
uses.contains(hal::TextureUses::COLOR_TARGET),
uses.contains(wgt::TextureUses::COLOR_TARGET),
);
u.set(
wgt::TextureUsages::STORAGE_ATOMIC,
uses.contains(hal::TextureUses::STORAGE_ATOMIC),
uses.contains(wgt::TextureUses::STORAGE_ATOMIC),
);
u
}
+13 -13
View File
@@ -73,8 +73,8 @@ impl Queue {
.transition_buffers(&[hal::BufferBarrier {
buffer: zero_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::empty(),
to: hal::BufferUses::COPY_DST,
from: wgt::BufferUses::empty(),
to: wgt::BufferUses::COPY_DST,
},
}]);
pending_writes
@@ -85,8 +85,8 @@ impl Queue {
.transition_buffers(&[hal::BufferBarrier {
buffer: zero_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::COPY_DST,
to: hal::BufferUses::COPY_SRC,
from: wgt::BufferUses::COPY_DST,
to: wgt::BufferUses::COPY_SRC,
},
}]);
}
@@ -588,7 +588,7 @@ impl Queue {
let mut trackers = self.device.trackers.lock();
trackers
.buffers
.set_single(&buffer, hal::BufferUses::COPY_DST)
.set_single(&buffer, wgt::BufferUses::COPY_DST)
};
let snatch_guard = self.device.snatchable_lock.read();
@@ -606,8 +606,8 @@ impl Queue {
let barriers = iter::once(hal::BufferBarrier {
buffer: staging_buffer.raw(),
usage: hal::StateTransition {
from: hal::BufferUses::MAP_WRITE,
to: hal::BufferUses::COPY_SRC,
from: wgt::BufferUses::MAP_WRITE,
to: wgt::BufferUses::COPY_SRC,
},
})
.chain(transition.map(|pending| pending.into_hal(&buffer, &snatch_guard)))
@@ -828,8 +828,8 @@ impl Queue {
let buffer_barrier = hal::BufferBarrier {
buffer: staging_buffer.raw(),
usage: hal::StateTransition {
from: hal::BufferUses::MAP_WRITE,
to: hal::BufferUses::COPY_SRC,
from: wgt::BufferUses::MAP_WRITE,
to: wgt::BufferUses::COPY_SRC,
},
};
@@ -837,7 +837,7 @@ impl Queue {
let transition =
trackers
.textures
.set_single(&dst, selector, hal::TextureUses::COPY_DST);
.set_single(&dst, selector, wgt::TextureUses::COPY_DST);
let texture_barriers = transition
.map(|pending| pending.into_hal(dst_raw))
.collect::<Vec<_>>();
@@ -1014,7 +1014,7 @@ impl Queue {
let mut trackers = self.device.trackers.lock();
let transitions = trackers
.textures
.set_single(&dst, selector, hal::TextureUses::COPY_DST);
.set_single(&dst, selector, wgt::TextureUses::COPY_DST);
// `copy_external_image_to_texture` is exclusive to the WebGL backend.
// Don't go through the `DynCommandEncoder` abstraction and directly to the WebGL backend.
@@ -1221,7 +1221,7 @@ impl Queue {
unsafe {
used_surface_textures
.merge_single(texture, None, hal::TextureUses::PRESENT)
.merge_single(texture, None, wgt::TextureUses::PRESENT)
.unwrap()
};
}
@@ -1532,7 +1532,7 @@ fn validate_command_buffer(
if should_extend {
unsafe {
used_surface_textures
.merge_single(texture, None, hal::TextureUses::PRESENT)
.merge_single(texture, None, wgt::TextureUses::PRESENT)
.unwrap();
};
}
+2 -2
View File
@@ -146,8 +146,8 @@ impl Device {
self.raw().create_buffer(&hal::BufferDescriptor {
label: Some("(wgpu-core) instances_buffer"),
size: instance_buffer_size as u64,
usage: hal::BufferUses::COPY_DST
| hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage: wgt::BufferUses::COPY_DST
| wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
})
}
+34 -36
View File
@@ -23,10 +23,7 @@ use crate::{
},
resource_log,
snatch::{SnatchGuard, SnatchLock, Snatchable},
track::{
BindGroupStates, DeviceTracker, TextureSelector, TrackerIndexAllocators, UsageScope,
UsageScopePool,
},
track::{BindGroupStates, DeviceTracker, TrackerIndexAllocators, UsageScope, UsageScopePool},
validation::{self, validate_color_attachment_bytes_per_sample},
weak_vec::WeakVec,
FastHashMap, LabelHelpers,
@@ -36,7 +33,8 @@ use arrayvec::ArrayVec;
use bitflags::Flags;
use smallvec::SmallVec;
use wgt::{
math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureViewDimension,
math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureSelector,
TextureViewDimension,
};
use crate::resource::{AccelerationStructure, Tlas};
@@ -210,7 +208,7 @@ impl Device {
raw_device.create_buffer(&hal::BufferDescriptor {
label: hal_label(Some("(wgpu internal) zero init buffer"), instance_flags),
size: ZERO_BUFFER_SIZE,
usage: hal::BufferUses::COPY_SRC | hal::BufferUses::COPY_DST,
usage: wgt::BufferUses::COPY_SRC | wgt::BufferUses::COPY_DST,
memory_flags: hal::MemoryFlags::empty(),
})
}
@@ -520,7 +518,7 @@ impl Device {
self.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)?;
// We are going to be reading from it, internally;
// when validating the content of the buffer
usage |= hal::BufferUses::STORAGE_READ_ONLY | hal::BufferUses::STORAGE_READ_WRITE;
usage |= wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE;
}
if desc.mapped_at_creation {
@@ -529,12 +527,12 @@ impl Device {
}
if !desc.usage.contains(wgt::BufferUsages::MAP_WRITE) {
// we are going to be copying into it, internally
usage |= hal::BufferUses::COPY_DST;
usage |= wgt::BufferUses::COPY_DST;
}
} else {
// We are required to zero out (initialize) all memory. This is done
// on demand using clear_buffer which requires write transfer usage!
usage |= hal::BufferUses::COPY_DST;
usage |= wgt::BufferUses::COPY_DST;
}
let actual_size = if desc.size == 0 {
@@ -586,7 +584,7 @@ impl Device {
let buffer = Arc::new(buffer);
let buffer_use = if !desc.mapped_at_creation {
hal::BufferUses::empty()
wgt::BufferUses::empty()
} else if desc.usage.contains(wgt::BufferUsages::MAP_WRITE) {
// buffer is mappable, so we are just doing that at start
let map_size = buffer.size;
@@ -604,7 +602,7 @@ impl Device {
range: 0..map_size,
host: HostMap::Write,
};
hal::BufferUses::MAP_WRITE
wgt::BufferUses::MAP_WRITE
} else {
let mut staging_buffer =
StagingBuffer::new(self, wgt::BufferSize::new(aligned_size).unwrap())?;
@@ -615,7 +613,7 @@ impl Device {
buffer.initialization_status.write().drain(0..aligned_size);
*buffer.map_state.lock() = resource::BufferMapState::Init { staging_buffer };
hal::BufferUses::COPY_DST
wgt::BufferUses::COPY_DST
};
self.trackers
@@ -652,7 +650,7 @@ impl Device {
self.trackers
.lock()
.textures
.insert_single(&texture, hal::TextureUses::UNINITIALIZED);
.insert_single(&texture, wgt::TextureUses::UNINITIALIZED);
Ok(texture)
}
@@ -696,7 +694,7 @@ impl Device {
self.trackers
.lock()
.buffers
.insert_single(&buffer, hal::BufferUses::empty());
.insert_single(&buffer, wgt::BufferUses::empty());
(Fallible::Valid(buffer), None)
}
@@ -943,12 +941,12 @@ impl Device {
.map_err(|e| self.handle_hal_error(e))?;
let clear_mode = if hal_usage
.intersects(hal::TextureUses::DEPTH_STENCIL_WRITE | hal::TextureUses::COLOR_TARGET)
.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE | wgt::TextureUses::COLOR_TARGET)
{
let (is_color, usage) = if desc.format.is_depth_stencil_format() {
(false, hal::TextureUses::DEPTH_STENCIL_WRITE)
(false, wgt::TextureUses::DEPTH_STENCIL_WRITE)
} else {
(true, hal::TextureUses::COLOR_TARGET)
(true, wgt::TextureUses::COLOR_TARGET)
};
let dimension = match desc.dimension {
wgt::TextureDimension::D1 => TextureViewDimension::D1,
@@ -1022,7 +1020,7 @@ impl Device {
self.trackers
.lock()
.textures
.insert_single(&texture, hal::TextureUses::UNINITIALIZED);
.insert_single(&texture, wgt::TextureUses::UNINITIALIZED);
Ok(texture)
}
@@ -1275,23 +1273,23 @@ impl Device {
// filter the usages based on the other criteria
let usage = {
let mask_copy = !(hal::TextureUses::COPY_SRC | hal::TextureUses::COPY_DST);
let mask_copy = !(wgt::TextureUses::COPY_SRC | wgt::TextureUses::COPY_DST);
let mask_dimension = match resolved_dimension {
TextureViewDimension::Cube | TextureViewDimension::CubeArray => {
hal::TextureUses::RESOURCE
wgt::TextureUses::RESOURCE
}
TextureViewDimension::D3 => {
hal::TextureUses::RESOURCE
| hal::TextureUses::STORAGE_READ_ONLY
| hal::TextureUses::STORAGE_WRITE_ONLY
| hal::TextureUses::STORAGE_READ_WRITE
wgt::TextureUses::RESOURCE
| wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE
}
_ => hal::TextureUses::all(),
_ => wgt::TextureUses::all(),
};
let mask_mip_level = if resolved_mip_level_count == 1 {
hal::TextureUses::all()
wgt::TextureUses::all()
} else {
hal::TextureUses::RESOURCE
wgt::TextureUses::RESOURCE
};
texture.hal_usage & mask_copy & mask_dimension & mask_mip_level
};
@@ -1955,15 +1953,15 @@ impl Device {
let (pub_usage, internal_use, range_limit) = match binding_ty {
wgt::BufferBindingType::Uniform => (
wgt::BufferUsages::UNIFORM,
hal::BufferUses::UNIFORM,
wgt::BufferUses::UNIFORM,
self.limits.max_uniform_buffer_binding_size,
),
wgt::BufferBindingType::Storage { read_only } => (
wgt::BufferUsages::STORAGE,
if read_only {
hal::BufferUses::STORAGE_READ_ONLY
wgt::BufferUses::STORAGE_READ_ONLY
} else {
hal::BufferUses::STORAGE_READ_WRITE
wgt::BufferUses::STORAGE_READ_WRITE
},
self.limits.max_storage_buffer_binding_size,
),
@@ -2438,7 +2436,7 @@ impl Device {
decl: &wgt::BindGroupLayoutEntry,
view: &TextureView,
expected: &'static str,
) -> Result<hal::TextureUses, binding_model::CreateBindGroupError> {
) -> Result<wgt::TextureUses, binding_model::CreateBindGroupError> {
use crate::binding_model::CreateBindGroupError as Error;
if view
.desc
@@ -2498,7 +2496,7 @@ impl Device {
});
}
view.check_usage(wgt::TextureUsages::TEXTURE_BINDING)?;
Ok(hal::TextureUses::RESOURCE)
Ok(wgt::TextureUses::RESOURCE)
}
wgt::BindingType::StorageTexture {
access,
@@ -2537,7 +2535,7 @@ impl Device {
{
return Err(Error::StorageWriteNotSupported(view.desc.format));
}
hal::TextureUses::STORAGE_WRITE_ONLY
wgt::TextureUses::STORAGE_WRITE_ONLY
}
wgt::StorageTextureAccess::ReadOnly => {
if !view
@@ -2547,7 +2545,7 @@ impl Device {
{
return Err(Error::StorageReadNotSupported(view.desc.format));
}
hal::TextureUses::STORAGE_READ_ONLY
wgt::TextureUses::STORAGE_READ_ONLY
}
wgt::StorageTextureAccess::ReadWrite => {
if !view
@@ -2558,7 +2556,7 @@ impl Device {
return Err(Error::StorageReadWriteNotSupported(view.desc.format));
}
hal::TextureUses::STORAGE_READ_WRITE
wgt::TextureUses::STORAGE_READ_WRITE
}
wgt::StorageTextureAccess::Atomic => {
if !view
@@ -2569,7 +2567,7 @@ impl Device {
return Err(Error::StorageAtomicNotSupported(view.desc.format));
}
hal::TextureUses::STORAGE_ATOMIC
wgt::TextureUses::STORAGE_ATOMIC
}
};
view.check_usage(wgt::TextureUsages::STORAGE_BINDING)?;
+1 -1
View File
@@ -226,7 +226,7 @@ impl IndirectValidation {
let dst_buffer_desc = hal::BufferDescriptor {
label: None,
size: DST_BUFFER_SIZE.get(),
usage: hal::BufferUses::INDIRECT | hal::BufferUses::STORAGE_READ_WRITE,
usage: wgt::BufferUses::INDIRECT | wgt::BufferUses::STORAGE_READ_WRITE,
memory_flags: hal::MemoryFlags::empty(),
};
let dst_buffer =
+2 -1
View File
@@ -1,7 +1,8 @@
use super::{InitTracker, MemoryInitKind};
use crate::{resource::Texture, track::TextureSelector};
use crate::resource::Texture;
use arrayvec::ArrayVec;
use std::{ops::Range, sync::Arc};
use wgt::TextureSelector;
#[derive(Debug, Clone)]
pub(crate) struct TextureInitRange {
+4 -4
View File
@@ -89,8 +89,8 @@ pub enum ConfigureSurfaceError {
},
#[error("Requested usage {requested:?} is not in the list of supported usages: {available:?}")]
UnsupportedUsage {
requested: hal::TextureUses,
available: hal::TextureUses,
requested: wgt::TextureUses,
available: wgt::TextureUses,
},
}
@@ -170,7 +170,7 @@ impl Surface {
),
format: config.format,
dimension: wgt::TextureViewDimension::D2,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgt::TextureUses::COLOR_TARGET,
range: wgt::ImageSubresourceRange::default(),
};
let clear_view = unsafe {
@@ -200,7 +200,7 @@ impl Surface {
.trackers
.lock()
.textures
.insert_single(&texture, hal::TextureUses::UNINITIALIZED);
.insert_single(&texture, wgt::TextureUses::UNINITIALIZED);
if present.acquired_texture.is_some() {
return Err(SurfaceError::AlreadyAcquired);
+12 -10
View File
@@ -16,11 +16,13 @@ use crate::{
lock::{rank, Mutex, RwLock},
resource_log,
snatch::{SnatchGuard, Snatchable},
track::{SharedTrackerIndexAllocator, TextureSelector, TrackerIndex},
track::{SharedTrackerIndexAllocator, TrackerIndex},
weak_vec::WeakVec,
Label, LabelHelpers, SubmissionIndex,
};
use wgt::TextureSelector;
use smallvec::SmallVec;
use thiserror::Error;
@@ -458,8 +460,8 @@ impl Buffer {
}
let (pub_usage, internal_use) = match op.host {
HostMap::Read => (wgt::BufferUsages::MAP_READ, hal::BufferUses::MAP_READ),
HostMap::Write => (wgt::BufferUsages::MAP_WRITE, hal::BufferUses::MAP_WRITE),
HostMap::Read => (wgt::BufferUsages::MAP_READ, wgt::BufferUses::MAP_READ),
HostMap::Write => (wgt::BufferUsages::MAP_WRITE, wgt::BufferUses::MAP_WRITE),
};
if let Err(e) = self.check_usage(pub_usage) {
@@ -637,15 +639,15 @@ impl Buffer {
let transition_src = hal::BufferBarrier {
buffer: staging_buffer.raw(),
usage: hal::StateTransition {
from: hal::BufferUses::MAP_WRITE,
to: hal::BufferUses::COPY_SRC,
from: wgt::BufferUses::MAP_WRITE,
to: wgt::BufferUses::COPY_SRC,
},
};
let transition_dst = hal::BufferBarrier::<dyn hal::DynBuffer> {
buffer: raw_buf,
usage: hal::StateTransition {
from: hal::BufferUses::empty(),
to: hal::BufferUses::COPY_DST,
from: wgt::BufferUses::empty(),
to: wgt::BufferUses::COPY_DST,
},
};
let mut pending_writes = queue.pending_writes.lock();
@@ -859,7 +861,7 @@ impl StagingBuffer {
let stage_desc = hal::BufferDescriptor {
label: crate::hal_label(Some("(wgpu internal) Staging"), device.instance_flags),
size: size.get(),
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::COPY_SRC,
usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::COPY_SRC,
memory_flags: hal::MemoryFlags::TRANSIENT,
};
@@ -1013,7 +1015,7 @@ pub struct Texture {
pub(crate) inner: Snatchable<TextureInner>,
pub(crate) device: Arc<Device>,
pub(crate) desc: wgt::TextureDescriptor<(), Vec<wgt::TextureFormat>>,
pub(crate) hal_usage: hal::TextureUses,
pub(crate) hal_usage: wgt::TextureUses,
pub(crate) format_features: wgt::TextureFormatFeatures,
pub(crate) initialization_status: RwLock<TextureInitTracker>,
pub(crate) full_range: TextureSelector,
@@ -1029,7 +1031,7 @@ impl Texture {
pub(crate) fn new(
device: &Arc<Device>,
inner: TextureInner,
hal_usage: hal::TextureUses,
hal_usage: wgt::TextureUses,
desc: &TextureDescriptor,
format_features: wgt::TextureFormatFeatures,
clear_mode: TextureClearMode,
+1 -1
View File
@@ -1,8 +1,8 @@
use crate::device::{Device, DeviceError};
use crate::resource_log;
use hal::BufferUses;
use std::mem::ManuallyDrop;
use std::sync::Arc;
use wgt::BufferUses;
#[derive(Debug)]
pub struct ScratchBuffer {
+2 -2
View File
@@ -15,8 +15,8 @@ use crate::{
ResourceUsageCompatibilityError, ResourceUses,
},
};
use hal::{BufferBarrier, BufferUses};
use wgt::{strict_assert, strict_assert_eq};
use hal::BufferBarrier;
use wgt::{strict_assert, strict_assert_eq, BufferUses};
impl ResourceUses for BufferUses {
const EXCLUSIVE: Self = Self::EXCLUSIVE;
+15 -15
View File
@@ -118,8 +118,8 @@ pub(crate) use buffer::{
use metadata::{ResourceMetadata, ResourceMetadataProvider};
pub(crate) use stateless::StatelessTracker;
pub(crate) use texture::{
DeviceTextureTracker, TextureSelector, TextureTracker, TextureTrackerSetSingle,
TextureUsageScope, TextureViewBindGroupState,
DeviceTextureTracker, TextureTracker, TextureTrackerSetSingle, TextureUsageScope,
TextureViewBindGroupState,
};
use wgt::strict_assert_ne;
@@ -256,9 +256,9 @@ pub(crate) struct PendingTransition<S: ResourceUses> {
pub usage: hal::StateTransition<S>,
}
pub(crate) type PendingTransitionList = Vec<PendingTransition<hal::TextureUses>>;
pub(crate) type PendingTransitionList = Vec<PendingTransition<wgt::TextureUses>>;
impl PendingTransition<hal::BufferUses> {
impl PendingTransition<wgt::BufferUses> {
/// Produce the hal barrier corresponding to the transition.
pub fn into_hal<'a>(
self,
@@ -273,15 +273,15 @@ impl PendingTransition<hal::BufferUses> {
}
}
impl PendingTransition<hal::TextureUses> {
impl PendingTransition<wgt::TextureUses> {
/// Produce the hal barrier corresponding to the transition.
pub fn into_hal(
self,
texture: &dyn hal::DynTexture,
) -> hal::TextureBarrier<'_, dyn hal::DynTexture> {
// These showing up in a barrier is always a bug
strict_assert_ne!(self.usage.from, hal::TextureUses::UNKNOWN);
strict_assert_ne!(self.usage.to, hal::TextureUses::UNKNOWN);
strict_assert_ne!(self.usage.from, wgt::TextureUses::UNKNOWN);
strict_assert_ne!(self.usage.to, wgt::TextureUses::UNKNOWN);
let mip_count = self.selector.mips.end - self.selector.mips.start;
strict_assert_ne!(mip_count, 0);
@@ -341,7 +341,7 @@ pub enum ResourceUsageCompatibilityError {
#[error("Attempted to use {res} with {invalid_use}.")]
Buffer {
res: ResourceErrorIdent,
invalid_use: InvalidUse<hal::BufferUses>,
invalid_use: InvalidUse<wgt::BufferUses>,
},
#[error(
"Attempted to use {res} (mips {mip_levels:?} layers {array_layers:?}) with {invalid_use}."
@@ -350,15 +350,15 @@ pub enum ResourceUsageCompatibilityError {
res: ResourceErrorIdent,
mip_levels: ops::Range<u32>,
array_layers: ops::Range<u32>,
invalid_use: InvalidUse<hal::TextureUses>,
invalid_use: InvalidUse<wgt::TextureUses>,
},
}
impl ResourceUsageCompatibilityError {
fn from_buffer(
buffer: &resource::Buffer,
current_state: hal::BufferUses,
new_state: hal::BufferUses,
current_state: wgt::BufferUses,
new_state: wgt::BufferUses,
) -> Self {
Self::Buffer {
res: buffer.error_ident(),
@@ -371,9 +371,9 @@ impl ResourceUsageCompatibilityError {
fn from_texture(
texture: &resource::Texture,
selector: TextureSelector,
current_state: hal::TextureUses,
new_state: hal::TextureUses,
selector: wgt::TextureSelector,
current_state: wgt::TextureUses,
new_state: wgt::TextureUses,
) -> Self {
Self::Texture {
res: texture.error_ident(),
@@ -641,7 +641,7 @@ impl Tracker {
/// bind group as a source of which IDs to look at. The bind groups
/// must have first been added to the usage scope.
///
/// Only stateful things are merged in herell other resources are owned
/// Only stateful things are merged in here, all other resources are owned
/// indirectly by the bind group.
///
/// # Safety
+2 -10
View File
@@ -27,27 +27,19 @@ use crate::{
ResourceUsageCompatibilityError, ResourceUses,
},
};
use hal::{TextureBarrier, TextureUses};
use hal::TextureBarrier;
use arrayvec::ArrayVec;
use naga::FastHashMap;
use wgt::{strict_assert, strict_assert_eq};
use wgt::{strict_assert, strict_assert_eq, TextureSelector, TextureUses};
use std::{
iter,
ops::Range,
sync::{Arc, Weak},
vec::Drain,
};
/// Specifies a particular set of subresources in a texture.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TextureSelector {
pub mips: Range<u32>,
pub layers: Range<u32>,
}
impl ResourceUses for TextureUses {
const EXCLUSIVE: Self = Self::EXCLUSIVE;
+19 -19
View File
@@ -148,7 +148,7 @@ impl<A: hal::Api> Example<A> {
height: window_size.1,
depth_or_array_layers: 1,
},
usage: hal::TextureUses::COLOR_TARGET,
usage: wgpu_types::TextureUses::COLOR_TARGET,
view_formats: vec![],
};
unsafe {
@@ -287,7 +287,7 @@ impl<A: hal::Api> Example<A> {
let staging_buffer_desc = hal::BufferDescriptor {
label: Some("stage"),
size: texture_data.len() as wgpu_types::BufferAddress,
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::COPY_SRC,
usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::COPY_SRC,
memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT,
};
let staging_buffer = unsafe { device.create_buffer(&staging_buffer_desc).unwrap() };
@@ -315,7 +315,7 @@ impl<A: hal::Api> Example<A> {
sample_count: 1,
dimension: wgpu_types::TextureDimension::D2,
format: wgpu_types::TextureFormat::Rgba8UnormSrgb,
usage: hal::TextureUses::COPY_DST | hal::TextureUses::RESOURCE,
usage: wgpu_types::TextureUses::COPY_DST | wgpu_types::TextureUses::RESOURCE,
memory_flags: hal::MemoryFlags::empty(),
view_formats: vec![],
};
@@ -331,24 +331,24 @@ impl<A: hal::Api> Example<A> {
let buffer_barrier = hal::BufferBarrier {
buffer: &staging_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::empty(),
to: hal::BufferUses::COPY_SRC,
from: wgpu_types::BufferUses::empty(),
to: wgpu_types::BufferUses::COPY_SRC,
},
};
let texture_barrier1 = hal::TextureBarrier {
texture: &texture,
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::UNINITIALIZED,
to: hal::TextureUses::COPY_DST,
from: wgpu_types::TextureUses::UNINITIALIZED,
to: wgpu_types::TextureUses::COPY_DST,
},
};
let texture_barrier2 = hal::TextureBarrier {
texture: &texture,
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::COPY_DST,
to: hal::TextureUses::RESOURCE,
from: wgpu_types::TextureUses::COPY_DST,
to: wgpu_types::TextureUses::RESOURCE,
},
};
let copy = hal::BufferTextureCopy {
@@ -405,7 +405,7 @@ impl<A: hal::Api> Example<A> {
let global_buffer_desc = hal::BufferDescriptor {
label: Some("global"),
size: size_of::<Globals>() as wgpu_types::BufferAddress,
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM,
usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::UNIFORM,
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
};
let global_buffer = unsafe {
@@ -431,7 +431,7 @@ impl<A: hal::Api> Example<A> {
label: Some("local"),
size: (MAX_BUNNIES as wgpu_types::BufferAddress)
* (local_alignment as wgpu_types::BufferAddress),
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM,
usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::UNIFORM,
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
};
let local_buffer = unsafe { device.create_buffer(&local_buffer_desc).unwrap() };
@@ -440,7 +440,7 @@ impl<A: hal::Api> Example<A> {
label: None,
format: texture_desc.format,
dimension: wgpu_types::TextureViewDimension::D2,
usage: hal::TextureUses::RESOURCE,
usage: wgpu_types::TextureUses::RESOURCE,
range: wgpu_types::ImageSubresourceRange::default(),
};
let texture_view = unsafe { device.create_texture_view(&texture, &view_desc).unwrap() };
@@ -453,7 +453,7 @@ impl<A: hal::Api> Example<A> {
};
let texture_binding = hal::TextureBinding {
view: &texture_view,
usage: hal::TextureUses::RESOURCE,
usage: wgpu_types::TextureUses::RESOURCE,
};
let global_group_desc = hal::BindGroupDescriptor {
label: Some("global"),
@@ -675,8 +675,8 @@ impl<A: hal::Api> Example<A> {
texture: surface_tex.borrow(),
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::UNINITIALIZED,
to: hal::TextureUses::COLOR_TARGET,
from: wgpu_types::TextureUses::UNINITIALIZED,
to: wgpu_types::TextureUses::COLOR_TARGET,
},
};
unsafe {
@@ -688,7 +688,7 @@ impl<A: hal::Api> Example<A> {
label: None,
format: self.surface_format,
dimension: wgpu_types::TextureViewDimension::D2,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgpu_types::TextureUses::COLOR_TARGET,
range: wgpu_types::ImageSubresourceRange::default(),
};
let surface_tex_view = unsafe {
@@ -707,7 +707,7 @@ impl<A: hal::Api> Example<A> {
color_attachments: &[Some(hal::ColorAttachment {
target: hal::Attachment {
view: &surface_tex_view,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgpu_types::TextureUses::COLOR_TARGET,
},
resolve_target: None,
ops: hal::AttachmentOps::STORE,
@@ -746,8 +746,8 @@ impl<A: hal::Api> Example<A> {
texture: surface_tex.borrow(),
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::COLOR_TARGET,
to: hal::TextureUses::PRESENT,
from: wgpu_types::TextureUses::COLOR_TARGET,
to: wgpu_types::TextureUses::PRESENT,
},
};
unsafe {
+2 -2
View File
@@ -293,7 +293,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter<hal::api::Gles>, width: u32, height
label: None,
format,
dimension: wgpu_types::TextureViewDimension::D2,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgpu_types::TextureUses::COLOR_TARGET,
range: wgpu_types::ImageSubresourceRange::default(),
},
)
@@ -321,7 +321,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter<hal::api::Gles>, width: u32, height
color_attachments: &[Some(hal::ColorAttachment {
target: hal::Attachment {
view: &view,
usage: hal::TextureUses::COLOR_TARGET,
usage: wgpu_types::TextureUses::COLOR_TARGET,
},
resolve_target: None,
ops: hal::AttachmentOps::STORE,
+28 -28
View File
@@ -304,7 +304,7 @@ impl<A: hal::Api> Example<A> {
height: window_size.1,
depth_or_array_layers: 1,
},
usage: hal::TextureUses::COLOR_TARGET | hal::TextureUses::COPY_DST,
usage: wgpu_types::TextureUses::COLOR_TARGET | wgpu_types::TextureUses::COPY_DST,
view_formats: vec![surface_format],
};
unsafe {
@@ -421,8 +421,8 @@ impl<A: hal::Api> Example<A> {
.create_buffer(&hal::BufferDescriptor {
label: Some("vertices buffer"),
size: vertices_size_in_bytes as u64,
usage: hal::BufferUses::MAP_WRITE
| hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage: wgpu_types::BufferUses::MAP_WRITE
| wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT,
})
.unwrap();
@@ -447,8 +447,8 @@ impl<A: hal::Api> Example<A> {
.create_buffer(&hal::BufferDescriptor {
label: Some("indices buffer"),
size: indices_size_in_bytes as u64,
usage: hal::BufferUses::MAP_WRITE
| hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage: wgpu_types::BufferUses::MAP_WRITE
| wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
memory_flags: hal::MemoryFlags::TRANSIENT
| hal::MemoryFlags::PREFER_COHERENT,
})
@@ -555,7 +555,7 @@ impl<A: hal::Api> Example<A> {
.create_buffer(&hal::BufferDescriptor {
label: Some("uniform buffer"),
size: uniforms_size as u64,
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM,
usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::UNIFORM,
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
})
.unwrap();
@@ -584,7 +584,7 @@ impl<A: hal::Api> Example<A> {
sample_count: 1,
dimension: wgpu_types::TextureDimension::D2,
format: wgpu_types::TextureFormat::Rgba8Unorm,
usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC,
usage: wgpu_types::TextureUses::STORAGE_READ_WRITE | wgpu_types::TextureUses::COPY_SRC,
memory_flags: hal::MemoryFlags::empty(),
view_formats: vec![wgpu_types::TextureFormat::Rgba8Unorm],
};
@@ -594,7 +594,7 @@ impl<A: hal::Api> Example<A> {
label: None,
format: texture_desc.format,
dimension: wgpu_types::TextureViewDimension::D2,
usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC,
usage: wgpu_types::TextureUses::STORAGE_READ_WRITE | wgpu_types::TextureUses::COPY_SRC,
range: wgpu_types::ImageSubresourceRange::default(),
};
let texture_view = unsafe { device.create_texture_view(&texture, &view_desc).unwrap() };
@@ -607,7 +607,7 @@ impl<A: hal::Api> Example<A> {
};
let texture_binding = hal::TextureBinding {
view: &texture_view,
usage: hal::TextureUses::STORAGE_READ_WRITE,
usage: wgpu_types::TextureUses::STORAGE_READ_WRITE,
};
let group_desc = hal::BindGroupDescriptor {
label: Some("bind group"),
@@ -644,7 +644,7 @@ impl<A: hal::Api> Example<A> {
size: blas_sizes
.build_scratch_size
.max(tlas_sizes.build_scratch_size),
usage: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
usage: wgpu_types::BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
memory_flags: hal::MemoryFlags::empty(),
})
.unwrap()
@@ -696,8 +696,8 @@ impl<A: hal::Api> Example<A> {
.create_buffer(&hal::BufferDescriptor {
label: Some("instances_buffer"),
size: instances_buffer_size as u64,
usage: hal::BufferUses::MAP_WRITE
| hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
usage: wgpu_types::BufferUses::MAP_WRITE
| wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT,
})
.unwrap();
@@ -756,8 +756,8 @@ impl<A: hal::Api> Example<A> {
let scratch_buffer_barrier = hal::BufferBarrier {
buffer: &scratch_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
from: wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
to: wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
},
};
cmd_encoder.transition_buffers(iter::once(scratch_buffer_barrier));
@@ -793,8 +793,8 @@ impl<A: hal::Api> Example<A> {
texture: &texture,
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::UNINITIALIZED,
to: hal::TextureUses::STORAGE_READ_WRITE,
from: wgpu_types::TextureUses::UNINITIALIZED,
to: wgpu_types::TextureUses::STORAGE_READ_WRITE,
},
};
@@ -867,8 +867,8 @@ impl<A: hal::Api> Example<A> {
texture: surface_tex.borrow(),
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::UNINITIALIZED,
to: hal::TextureUses::COPY_DST,
from: wgpu_types::TextureUses::UNINITIALIZED,
to: wgpu_types::TextureUses::COPY_DST,
},
};
@@ -937,8 +937,8 @@ impl<A: hal::Api> Example<A> {
let scratch_buffer_barrier = hal::BufferBarrier {
buffer: &self.scratch_buffer,
usage: hal::StateTransition {
from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
from: wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
to: wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
},
};
ctx.encoder
@@ -951,7 +951,7 @@ impl<A: hal::Api> Example<A> {
label: None,
format: self.surface_format,
dimension: wgpu_types::TextureViewDimension::D2,
usage: hal::TextureUses::COPY_DST,
usage: wgpu_types::TextureUses::COPY_DST,
range: wgpu_types::ImageSubresourceRange::default(),
};
let surface_tex_view = unsafe {
@@ -976,24 +976,24 @@ impl<A: hal::Api> Example<A> {
texture: surface_tex.borrow(),
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::COPY_DST,
to: hal::TextureUses::PRESENT,
from: wgpu_types::TextureUses::COPY_DST,
to: wgpu_types::TextureUses::PRESENT,
},
};
let target_barrier2 = hal::TextureBarrier {
texture: &self.texture,
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::STORAGE_READ_WRITE,
to: hal::TextureUses::COPY_SRC,
from: wgpu_types::TextureUses::STORAGE_READ_WRITE,
to: wgpu_types::TextureUses::COPY_SRC,
},
};
let target_barrier3 = hal::TextureBarrier {
texture: &self.texture,
range: wgpu_types::ImageSubresourceRange::default(),
usage: hal::StateTransition {
from: hal::TextureUses::COPY_SRC,
to: hal::TextureUses::STORAGE_READ_WRITE,
from: wgpu_types::TextureUses::COPY_SRC,
to: wgpu_types::TextureUses::STORAGE_READ_WRITE,
},
};
unsafe {
@@ -1001,7 +1001,7 @@ impl<A: hal::Api> Example<A> {
ctx.encoder.transition_textures(iter::once(target_barrier2));
ctx.encoder.copy_texture_to_texture(
&self.texture,
hal::TextureUses::COPY_SRC,
wgpu_types::TextureUses::COPY_SRC,
surface_tex.borrow(),
std::iter::once(hal::TextureCopy {
src_base: hal::TextureCopyBase {
+5 -5
View File
@@ -181,7 +181,7 @@ pub fn map_texture_format_for_copy(
pub fn map_texture_format_for_resource(
format: wgt::TextureFormat,
usage: crate::TextureUses,
usage: wgt::TextureUses,
has_view_formats: bool,
casting_fully_typed_format_supported: bool,
) -> Dxgi::Common::DXGI_FORMAT {
@@ -206,10 +206,10 @@ pub fn map_texture_format_for_resource(
// We might view this resource as SRV/UAV but also as DSV
} else if format.is_depth_stencil_format()
&& usage.intersects(
crate::TextureUses::RESOURCE
| crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::RESOURCE
| wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
)
{
match format {
+3 -3
View File
@@ -850,9 +850,9 @@ impl crate::Adapter for super::Adapter {
// See https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgidevice1-setmaximumframelatency
maximum_frame_latency: 1..=16,
current_extent,
usage: crate::TextureUses::COLOR_TARGET
| crate::TextureUses::COPY_SRC
| crate::TextureUses::COPY_DST,
usage: wgt::TextureUses::COLOR_TARGET
| wgt::TextureUses::COPY_SRC
| wgt::TextureUses::COPY_DST,
present_modes,
composite_alpha_modes: vec![wgt::CompositeAlphaMode::Opaque],
})
+5 -5
View File
@@ -383,7 +383,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
},
};
self.temp.barriers.push(raw);
} else if barrier.usage.from == crate::BufferUses::STORAGE_READ_WRITE {
} else if barrier.usage.from == wgt::BufferUses::STORAGE_READ_WRITE {
let raw = Direct3D12::D3D12_RESOURCE_BARRIER {
Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV,
Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE,
@@ -482,7 +482,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
}
}
}
} else if barrier.usage.from == crate::TextureUses::STORAGE_READ_WRITE {
} else if barrier.usage.from == wgt::TextureUses::STORAGE_READ_WRITE {
let raw = Direct3D12::D3D12_RESOURCE_BARRIER {
Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV,
Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE,
@@ -545,7 +545,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Texture,
regions: T,
) where
@@ -626,7 +626,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Buffer,
regions: T,
) where
@@ -735,7 +735,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
}
let ds_view = desc.depth_stencil_attachment.as_ref().map(|ds| {
if ds.target.usage == crate::TextureUses::DEPTH_STENCIL_WRITE {
if ds.target.usage == wgt::TextureUses::DEPTH_STENCIL_WRITE {
ds.target.view.handle_dsv_rw.as_ref().unwrap().raw
} else {
ds.target.view.handle_dsv_ro.as_ref().unwrap().raw
+16 -16
View File
@@ -1,10 +1,10 @@
use windows::Win32::Graphics::{Direct3D, Direct3D12};
pub fn map_buffer_usage_to_resource_flags(
usage: crate::BufferUses,
usage: wgt::BufferUses,
) -> Direct3D12::D3D12_RESOURCE_FLAGS {
let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE;
if usage.contains(crate::BufferUses::STORAGE_READ_WRITE) {
if usage.contains(wgt::BufferUses::STORAGE_READ_WRITE) {
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
}
flags
@@ -19,25 +19,25 @@ pub fn map_texture_dimension(dim: wgt::TextureDimension) -> Direct3D12::D3D12_RE
}
pub fn map_texture_usage_to_resource_flags(
usage: crate::TextureUses,
usage: wgt::TextureUses,
) -> Direct3D12::D3D12_RESOURCE_FLAGS {
let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE;
if usage.contains(crate::TextureUses::COLOR_TARGET) {
if usage.contains(wgt::TextureUses::COLOR_TARGET) {
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
}
if usage.intersects(
crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE,
) {
if usage
.intersects(wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE)
{
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
if !usage.contains(crate::TextureUses::RESOURCE) {
if !usage.contains(wgt::TextureUses::RESOURCE) {
flags |= Direct3D12::D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE;
}
}
if usage.intersects(
crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
) {
flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
}
@@ -116,8 +116,8 @@ pub fn map_binding_type(ty: &wgt::BindingType) -> Direct3D12::D3D12_DESCRIPTOR_R
}
}
pub fn map_buffer_usage_to_state(usage: crate::BufferUses) -> Direct3D12::D3D12_RESOURCE_STATES {
use crate::BufferUses as Bu;
pub fn map_buffer_usage_to_state(usage: wgt::BufferUses) -> Direct3D12::D3D12_RESOURCE_STATES {
use wgt::BufferUses as Bu;
let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON;
if usage.intersects(Bu::COPY_SRC) {
@@ -144,12 +144,12 @@ pub fn map_buffer_usage_to_state(usage: crate::BufferUses) -> Direct3D12::D3D12_
state
}
pub fn map_texture_usage_to_state(usage: crate::TextureUses) -> Direct3D12::D3D12_RESOURCE_STATES {
use crate::TextureUses as Tu;
pub fn map_texture_usage_to_state(usage: wgt::TextureUses) -> Direct3D12::D3D12_RESOURCE_STATES {
use wgt::TextureUses as Tu;
let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON;
//Note: `RESOLVE_SOURCE` and `RESOLVE_DEST` are not used here
//Note: `PRESENT` is the same as `COMMON`
if usage == crate::TextureUses::UNINITIALIZED {
if usage == wgt::TextureUses::UNINITIALIZED {
return state;
}
+9 -15
View File
@@ -399,7 +399,7 @@ impl crate::Device for super::Device {
desc: &crate::BufferDescriptor,
) -> Result<super::Buffer, crate::DeviceError> {
let mut size = desc.size;
if desc.usage.contains(crate::BufferUses::UNIFORM) {
if desc.usage.contains(wgt::BufferUses::UNIFORM) {
let align_mask = Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT as u64 - 1;
size = ((size - 1) | align_mask) + 1;
}
@@ -560,7 +560,7 @@ impl crate::Device for super::Device {
texture.resource.clone(),
texture.calc_subresource(desc.range.base_mip_level, desc.range.base_array_layer, 0),
),
handle_srv: if desc.usage.intersects(crate::TextureUses::RESOURCE) {
handle_srv: if desc.usage.intersects(wgt::TextureUses::RESOURCE) {
match unsafe { view_desc.to_srv() } {
Some(raw_desc) => {
let handle = self.srv_uav_pool.lock().alloc_handle()?;
@@ -579,9 +579,9 @@ impl crate::Device for super::Device {
None
},
handle_uav: if desc.usage.intersects(
crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
) {
match unsafe { view_desc.to_uav() } {
Some(raw_desc) => {
@@ -601,7 +601,7 @@ impl crate::Device for super::Device {
} else {
None
},
handle_rtv: if desc.usage.intersects(crate::TextureUses::COLOR_TARGET) {
handle_rtv: if desc.usage.intersects(wgt::TextureUses::COLOR_TARGET) {
let raw_desc = unsafe { view_desc.to_rtv() };
let handle = self.rtv_pool.lock().alloc_handle()?;
unsafe {
@@ -612,10 +612,7 @@ impl crate::Device for super::Device {
} else {
None
},
handle_dsv_ro: if desc
.usage
.intersects(crate::TextureUses::DEPTH_STENCIL_READ)
{
handle_dsv_ro: if desc.usage.intersects(wgt::TextureUses::DEPTH_STENCIL_READ) {
let raw_desc = unsafe { view_desc.to_dsv(true) };
let handle = self.dsv_pool.lock().alloc_handle()?;
unsafe {
@@ -626,10 +623,7 @@ impl crate::Device for super::Device {
} else {
None
},
handle_dsv_rw: if desc
.usage
.intersects(crate::TextureUses::DEPTH_STENCIL_WRITE)
{
handle_dsv_rw: if desc.usage.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE) {
let raw_desc = unsafe { view_desc.to_dsv(false) };
let handle = self.dsv_pool.lock().alloc_handle()?;
unsafe {
@@ -1556,7 +1550,7 @@ impl crate::Device for super::Device {
let buffer_desc = crate::BufferDescriptor {
label: None,
size: buffer_size,
usage: crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::MAP_WRITE,
usage: wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::MAP_WRITE,
// D3D12 backend doesn't care about the memory flags
memory_flags: crate::MemoryFlags::empty(),
};
+4 -4
View File
@@ -53,8 +53,8 @@ pub(crate) fn create_buffer_resource(
desc: &crate::BufferDescriptor,
raw_desc: Direct3D12::D3D12_RESOURCE_DESC,
) -> Result<(Direct3D12::ID3D12Resource, Option<AllocationWrapper>), crate::DeviceError> {
let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE);
let is_cpu_read = desc.usage.contains(wgt::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE);
// Workaround for Intel Xe drivers
if !device.private_caps.suballocation_supported {
@@ -289,8 +289,8 @@ pub(crate) fn create_committed_buffer_resource(
desc: &crate::BufferDescriptor,
raw_desc: Direct3D12::D3D12_RESOURCE_DESC,
) -> Result<Direct3D12::ID3D12Resource, crate::DeviceError> {
let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE);
let is_cpu_read = desc.usage.contains(wgt::BufferUses::MAP_READ);
let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE);
let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES {
Type: Direct3D12::D3D12_HEAP_TYPE_CUSTOM,
+5 -5
View File
@@ -4,7 +4,7 @@ use crate::{
AccelerationStructureBarrier, Api, Attachment, BufferBarrier, BufferBinding, BufferCopy,
BufferTextureCopy, BuildAccelerationStructureDescriptor, ColorAttachment, CommandEncoder,
ComputePassDescriptor, DepthStencilAttachment, DeviceError, Label, MemoryRange,
PassTimestampWrites, Rect, RenderPassDescriptor, TextureBarrier, TextureCopy, TextureUses,
PassTimestampWrites, Rect, RenderPassDescriptor, TextureBarrier, TextureCopy,
};
use super::{
@@ -37,7 +37,7 @@ pub trait DynCommandEncoder: DynResource + std::fmt::Debug {
unsafe fn copy_texture_to_texture(
&mut self,
src: &dyn DynTexture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &dyn DynTexture,
regions: &[TextureCopy],
);
@@ -52,7 +52,7 @@ pub trait DynCommandEncoder: DynResource + std::fmt::Debug {
unsafe fn copy_texture_to_buffer(
&mut self,
src: &dyn DynTexture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &dyn DynBuffer,
regions: &[BufferTextureCopy],
);
@@ -240,7 +240,7 @@ impl<C: CommandEncoder + DynResource> DynCommandEncoder for C {
unsafe fn copy_texture_to_texture(
&mut self,
src: &dyn DynTexture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &dyn DynTexture,
regions: &[TextureCopy],
) {
@@ -267,7 +267,7 @@ impl<C: CommandEncoder + DynResource> DynCommandEncoder for C {
unsafe fn copy_texture_to_buffer(
&mut self,
src: &dyn DynTexture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &dyn DynBuffer,
regions: &[BufferTextureCopy],
) {
+2 -2
View File
@@ -358,7 +358,7 @@ impl crate::CommandEncoder for Encoder {
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &Resource,
src_usage: crate::TextureUses,
src_usage: wgt::TextureUses,
dst: &Resource,
regions: T,
) {
@@ -369,7 +369,7 @@ impl crate::CommandEncoder for Encoder {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &Resource,
src_usage: crate::TextureUses,
src_usage: wgt::TextureUses,
dst: &Resource,
regions: T,
) {
+1 -1
View File
@@ -1213,7 +1213,7 @@ impl crate::Adapter for super::Adapter {
composite_alpha_modes: vec![wgt::CompositeAlphaMode::Opaque], //TODO
maximum_frame_latency: 2..=2, //TODO, unused currently
current_extent: None,
usage: crate::TextureUses::COLOR_TARGET,
usage: wgt::TextureUses::COLOR_TARGET,
})
} else {
None
+5 -9
View File
@@ -287,11 +287,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
}
for bar in barriers {
// GLES only synchronizes storage -> anything explicitly
if !bar
.usage
.from
.contains(crate::BufferUses::STORAGE_READ_WRITE)
{
if !bar.usage.from.contains(wgt::BufferUses::STORAGE_READ_WRITE) {
continue;
}
self.cmd_buffer
@@ -311,13 +307,13 @@ impl crate::CommandEncoder for super::CommandEncoder {
return;
}
let mut combined_usage = crate::TextureUses::empty();
let mut combined_usage = wgt::TextureUses::empty();
for bar in barriers {
// GLES only synchronizes storage -> anything explicitly
if !bar
.usage
.from
.contains(crate::TextureUses::STORAGE_READ_WRITE)
.contains(wgt::TextureUses::STORAGE_READ_WRITE)
{
continue;
}
@@ -393,7 +389,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Texture,
regions: T,
) where
@@ -439,7 +435,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Buffer,
regions: T,
) where
+13 -13
View File
@@ -505,7 +505,7 @@ impl crate::Device for super::Device {
&self,
desc: &crate::BufferDescriptor,
) -> Result<super::Buffer, crate::DeviceError> {
let target = if desc.usage.contains(crate::BufferUses::INDEX) {
let target = if desc.usage.contains(wgt::BufferUses::INDEX) {
glow::ELEMENT_ARRAY_BUFFER
} else {
glow::ARRAY_BUFFER
@@ -520,7 +520,7 @@ impl crate::Device for super::Device {
.private_caps
.contains(PrivateCapabilities::BUFFER_ALLOCATION);
if emulate_map && desc.usage.intersects(crate::BufferUses::MAP_WRITE) {
if emulate_map && desc.usage.intersects(wgt::BufferUses::MAP_WRITE) {
return Ok(super::Buffer {
raw: None,
target,
@@ -533,7 +533,7 @@ impl crate::Device for super::Device {
let gl = &self.shared.context.lock();
let target = if desc.usage.contains(crate::BufferUses::INDEX) {
let target = if desc.usage.contains(wgt::BufferUses::INDEX) {
glow::ELEMENT_ARRAY_BUFFER
} else {
glow::ARRAY_BUFFER
@@ -541,16 +541,16 @@ impl crate::Device for super::Device {
let is_host_visible = desc
.usage
.intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE);
.intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE);
let is_coherent = desc
.memory_flags
.contains(crate::MemoryFlags::PREFER_COHERENT);
let mut map_flags = 0;
if desc.usage.contains(crate::BufferUses::MAP_READ) {
if desc.usage.contains(wgt::BufferUses::MAP_READ) {
map_flags |= glow::MAP_READ_BIT;
}
if desc.usage.contains(crate::BufferUses::MAP_WRITE) {
if desc.usage.contains(wgt::BufferUses::MAP_WRITE) {
map_flags |= glow::MAP_WRITE_BIT;
}
@@ -573,14 +573,14 @@ impl crate::Device for super::Device {
}
}
// TODO: may also be required for other calls involving `buffer_sub_data_u8_slice` (e.g. copy buffer to buffer and clear buffer)
if desc.usage.intersects(crate::BufferUses::QUERY_RESOLVE) {
if desc.usage.intersects(wgt::BufferUses::QUERY_RESOLVE) {
map_flags |= glow::DYNAMIC_STORAGE_BIT;
}
unsafe { gl.buffer_storage(target, raw_size, None, map_flags) };
} else {
assert!(!is_coherent);
let usage = if is_host_visible {
if desc.usage.contains(crate::BufferUses::MAP_READ) {
if desc.usage.contains(wgt::BufferUses::MAP_READ) {
glow::STREAM_READ
} else {
glow::DYNAMIC_DRAW
@@ -596,7 +596,7 @@ impl crate::Device for super::Device {
unsafe { gl.bind_buffer(target, None) };
if !is_coherent && desc.usage.contains(crate::BufferUses::MAP_WRITE) {
if !is_coherent && desc.usage.contains(wgt::BufferUses::MAP_WRITE) {
map_flags |= glow::MAP_FLUSH_EXPLICIT_BIT;
}
//TODO: do we need `glow::MAP_UNSYNCHRONIZED_BIT`?
@@ -613,7 +613,7 @@ impl crate::Device for super::Device {
}
}
let data = if emulate_map && desc.usage.contains(crate::BufferUses::MAP_READ) {
let data = if emulate_map && desc.usage.contains(wgt::BufferUses::MAP_READ) {
Some(Arc::new(Mutex::new(vec![0; desc.size as usize])))
} else {
None
@@ -727,9 +727,9 @@ impl crate::Device for super::Device {
) -> Result<super::Texture, crate::DeviceError> {
let gl = &self.shared.context.lock();
let render_usage = crate::TextureUses::COLOR_TARGET
| crate::TextureUses::DEPTH_STENCIL_WRITE
| crate::TextureUses::DEPTH_STENCIL_READ;
let render_usage = wgt::TextureUses::COLOR_TARGET
| wgt::TextureUses::DEPTH_STENCIL_WRITE
| wgt::TextureUses::DEPTH_STENCIL_READ;
let format_desc = self.shared.describe_texture_format(desc.format);
let inner = if render_usage.contains(desc.usage)
+2 -2
View File
@@ -922,8 +922,8 @@ enum Command {
// It is also more efficient to emit a single command instead of two for
// this.
ClearDepthAndStencil(f32, u32),
BufferBarrier(glow::Buffer, crate::BufferUses),
TextureBarrier(crate::TextureUses),
BufferBarrier(glow::Buffer, wgt::BufferUses),
TextureBarrier(wgt::TextureUses),
SetViewport {
rect: crate::Rect<i32>,
depth: Range<f32>,
+16 -16
View File
@@ -1197,35 +1197,35 @@ impl super::Queue {
}
C::BufferBarrier(raw, usage) => {
let mut flags = 0;
if usage.contains(crate::BufferUses::VERTEX) {
if usage.contains(wgt::BufferUses::VERTEX) {
flags |= glow::VERTEX_ATTRIB_ARRAY_BARRIER_BIT;
unsafe { gl.bind_buffer(glow::ARRAY_BUFFER, Some(raw)) };
unsafe { gl.vertex_attrib_pointer_f32(0, 1, glow::BYTE, true, 0, 0) };
}
if usage.contains(crate::BufferUses::INDEX) {
if usage.contains(wgt::BufferUses::INDEX) {
flags |= glow::ELEMENT_ARRAY_BARRIER_BIT;
unsafe { gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(raw)) };
}
if usage.contains(crate::BufferUses::UNIFORM) {
if usage.contains(wgt::BufferUses::UNIFORM) {
flags |= glow::UNIFORM_BARRIER_BIT;
}
if usage.contains(crate::BufferUses::INDIRECT) {
if usage.contains(wgt::BufferUses::INDIRECT) {
flags |= glow::COMMAND_BARRIER_BIT;
unsafe { gl.bind_buffer(glow::DRAW_INDIRECT_BUFFER, Some(raw)) };
}
if usage.contains(crate::BufferUses::COPY_SRC) {
if usage.contains(wgt::BufferUses::COPY_SRC) {
flags |= glow::PIXEL_BUFFER_BARRIER_BIT;
unsafe { gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, Some(raw)) };
}
if usage.contains(crate::BufferUses::COPY_DST) {
if usage.contains(wgt::BufferUses::COPY_DST) {
flags |= glow::PIXEL_BUFFER_BARRIER_BIT;
unsafe { gl.bind_buffer(glow::PIXEL_PACK_BUFFER, Some(raw)) };
}
if usage.intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE) {
if usage.intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE) {
flags |= glow::BUFFER_UPDATE_BARRIER_BIT;
}
if usage.intersects(
crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::STORAGE_READ_WRITE,
wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE,
) {
flags |= glow::SHADER_STORAGE_BARRIER_BIT;
}
@@ -1233,23 +1233,23 @@ impl super::Queue {
}
C::TextureBarrier(usage) => {
let mut flags = 0;
if usage.contains(crate::TextureUses::RESOURCE) {
if usage.contains(wgt::TextureUses::RESOURCE) {
flags |= glow::TEXTURE_FETCH_BARRIER_BIT;
}
if usage.intersects(
crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
) {
flags |= glow::SHADER_IMAGE_ACCESS_BARRIER_BIT;
}
if usage.contains(crate::TextureUses::COPY_DST) {
if usage.contains(wgt::TextureUses::COPY_DST) {
flags |= glow::TEXTURE_UPDATE_BARRIER_BIT;
}
if usage.intersects(
crate::TextureUses::COLOR_TARGET
| crate::TextureUses::DEPTH_STENCIL_READ
| crate::TextureUses::DEPTH_STENCIL_WRITE,
wgt::TextureUses::COLOR_TARGET
| wgt::TextureUses::DEPTH_STENCIL_READ
| wgt::TextureUses::DEPTH_STENCIL_WRITE,
) {
flags |= glow::FRAMEBUFFER_BARRIER_BIT;
}
+19 -106
View File
@@ -710,7 +710,7 @@ pub trait Device: WasmNotSendSync {
/// Creates a new buffer.
///
/// The initial usage is `BufferUses::empty()`.
/// The initial usage is `wgt::BufferUses::empty()`.
unsafe fn create_buffer(
&self,
desc: &BufferDescriptor,
@@ -776,8 +776,8 @@ pub trait Device: WasmNotSendSync {
/// - The returned [`BufferMapping::ptr`] must not be used after a call to
/// [`Device::unmap_buffer`].
///
/// [`MAP_READ`]: BufferUses::MAP_READ
/// [`MAP_WRITE`]: BufferUses::MAP_WRITE
/// [`MAP_READ`]: wgt::BufferUses::MAP_READ
/// [`MAP_WRITE`]: wgt::BufferUses::MAP_WRITE
unsafe fn map_buffer(
&self,
buffer: &<Self::A as Api>::Buffer,
@@ -815,7 +815,7 @@ pub trait Device: WasmNotSendSync {
/// Creates a new texture.
///
/// The initial usage for all subresources is `TextureUses::UNINITIALIZED`.
/// The initial usage for all subresources is `wgt::TextureUses::UNINITIALIZED`.
unsafe fn create_texture(
&self,
desc: &TextureDescriptor,
@@ -1200,7 +1200,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
/// Copy from an external image to an internal texture.
/// Works with a single array layer.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`.
/// Note: the copy extent is in physical size (rounded to the block size)
#[cfg(webgl)]
unsafe fn copy_external_image_to_texture<T>(
@@ -1214,12 +1214,12 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
/// Copy from one texture to another.
/// Works with a single array layer.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`.
/// Note: the copy extent is in physical size (rounded to the block size)
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &<Self::A as Api>::Texture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &<Self::A as Api>::Texture,
regions: T,
) where
@@ -1227,7 +1227,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
/// Copy from buffer to texture.
/// Works with a single array layer.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`.
/// Note: the copy extent is in physical size (rounded to the block size)
unsafe fn copy_buffer_to_texture<T>(
&mut self,
@@ -1243,7 +1243,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &<Self::A as Api>::Texture,
src_usage: TextureUses,
src_usage: wgt::TextureUses,
dst: &<Self::A as Api>::Buffer,
regions: T,
) where
@@ -1662,93 +1662,6 @@ bitflags!(
}
);
bitflags::bitflags! {
/// Similar to `wgt::BufferUsages` but for internal use.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct BufferUses: u16 {
/// The argument to a read-only mapping.
const MAP_READ = 1 << 0;
/// The argument to a write-only mapping.
const MAP_WRITE = 1 << 1;
/// The source of a hardware copy.
const COPY_SRC = 1 << 2;
/// The destination of a hardware copy.
const COPY_DST = 1 << 3;
/// The index buffer used for drawing.
const INDEX = 1 << 4;
/// A vertex buffer used for drawing.
const VERTEX = 1 << 5;
/// A uniform buffer bound in a bind group.
const UNIFORM = 1 << 6;
/// A read-only storage buffer used in a bind group.
const STORAGE_READ_ONLY = 1 << 7;
/// A read-write buffer used in a bind group.
const STORAGE_READ_WRITE = 1 << 8;
/// The indirect or count buffer in a indirect draw or dispatch.
const INDIRECT = 1 << 9;
/// A buffer used to store query results.
const QUERY_RESOLVE = 1 << 10;
const ACCELERATION_STRUCTURE_SCRATCH = 1 << 11;
const BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 12;
const TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 13;
/// The combination of states that a buffer may be in _at the same time_.
const INCLUSIVE = Self::MAP_READ.bits() | Self::COPY_SRC.bits() |
Self::INDEX.bits() | Self::VERTEX.bits() | Self::UNIFORM.bits() |
Self::STORAGE_READ_ONLY.bits() | Self::INDIRECT.bits() | Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits() | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits();
/// The combination of states that a buffer must exclusively be in.
const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits() | Self::ACCELERATION_STRUCTURE_SCRATCH.bits();
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is ordered, then if the buffer state doesn't change between draw calls, there
/// are no barriers needed for synchronization.
const ORDERED = Self::INCLUSIVE.bits() | Self::MAP_WRITE.bits();
}
}
bitflags::bitflags! {
/// Similar to `wgt::TextureUsages` but for internal use.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TextureUses: u16 {
/// The texture is in unknown state.
const UNINITIALIZED = 1 << 0;
/// Ready to present image to the surface.
const PRESENT = 1 << 1;
/// The source of a hardware copy.
const COPY_SRC = 1 << 2;
/// The destination of a hardware copy.
const COPY_DST = 1 << 3;
/// Read-only sampled or fetched resource.
const RESOURCE = 1 << 4;
/// The color target of a renderpass.
const COLOR_TARGET = 1 << 5;
/// Read-only depth stencil usage.
const DEPTH_STENCIL_READ = 1 << 6;
/// Read-write depth stencil usage
const DEPTH_STENCIL_WRITE = 1 << 7;
/// Read-only storage texture usage. Corresponds to a UAV in d3d, so is exclusive, despite being read only.
const STORAGE_READ_ONLY = 1 << 8;
/// Write-only storage texture usage.
const STORAGE_WRITE_ONLY = 1 << 9;
/// Read-write storage texture usage.
const STORAGE_READ_WRITE = 1 << 10;
/// Image atomic enabled storage
const STORAGE_ATOMIC = 1 << 11;
/// The combination of states that a texture may be in _at the same time_.
const INCLUSIVE = Self::COPY_SRC.bits() | Self::RESOURCE.bits() | Self::DEPTH_STENCIL_READ.bits();
/// The combination of states that a texture must exclusively be in.
const EXCLUSIVE = Self::COPY_DST.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits() | Self::STORAGE_WRITE_ONLY.bits() | Self::STORAGE_READ_WRITE.bits() | Self::STORAGE_ATOMIC.bits() | Self::PRESENT.bits();
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is ordered, then if the texture state doesn't change between draw calls, there
/// are no barriers needed for synchronization.
const ORDERED = Self::INCLUSIVE.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits();
/// Flag used by the wgpu-core texture tracker to say a texture is in different states for every sub-resource
const COMPLEX = 1 << 12;
/// Flag used by the wgpu-core texture tracker to say that the tracker does not know the state of the sub-resource.
/// This is different from UNINITIALIZED as that says the tracker does know, but the texture has not been initialized.
const UNKNOWN = 1 << 13;
}
}
#[derive(Clone, Debug)]
pub struct InstanceDescriptor<'a> {
pub name: &'a str,
@@ -1827,8 +1740,8 @@ pub struct SurfaceCapabilities {
/// Supported texture usage flags.
///
/// Must have at least `TextureUses::COLOR_TARGET`
pub usage: TextureUses,
/// Must have at least `wgt::TextureUses::COLOR_TARGET`
pub usage: wgt::TextureUses,
/// List of supported V-sync modes.
///
@@ -1866,7 +1779,7 @@ pub struct BufferMapping {
pub struct BufferDescriptor<'a> {
pub label: Label<'a>,
pub size: wgt::BufferAddress,
pub usage: BufferUses,
pub usage: wgt::BufferUses,
pub memory_flags: MemoryFlags,
}
@@ -1878,7 +1791,7 @@ pub struct TextureDescriptor<'a> {
pub sample_count: u32,
pub dimension: wgt::TextureDimension,
pub format: wgt::TextureFormat,
pub usage: TextureUses,
pub usage: wgt::TextureUses,
pub memory_flags: MemoryFlags,
/// Allows views of this texture to have a different format
/// than the texture does.
@@ -1917,7 +1830,7 @@ pub struct TextureViewDescriptor<'a> {
pub label: Label<'a>,
pub format: wgt::TextureFormat,
pub dimension: wgt::TextureViewDimension,
pub usage: TextureUses,
pub usage: wgt::TextureUses,
pub range: wgt::ImageSubresourceRange,
}
@@ -2029,7 +1942,7 @@ impl<'a, T: DynBuffer + ?Sized> Clone for BufferBinding<'a, T> {
#[derive(Debug)]
pub struct TextureBinding<'a, T: DynTextureView + ?Sized> {
pub view: &'a T,
pub usage: TextureUses,
pub usage: wgt::TextureUses,
}
impl<'a, T: DynTextureView + ?Sized> Clone for TextureBinding<'a, T> {
@@ -2231,7 +2144,7 @@ pub struct SurfaceConfiguration {
/// `SurfaceCapabilities::extents` range.
pub extent: wgt::Extent3d,
/// Allowed usage of surface textures,
pub usage: TextureUses,
pub usage: wgt::TextureUses,
/// Allows views of swapchain texture to have a different format
/// than the texture does.
pub view_formats: Vec<wgt::TextureFormat>,
@@ -2254,14 +2167,14 @@ pub struct StateTransition<T> {
#[derive(Debug, Clone)]
pub struct BufferBarrier<'a, B: DynBuffer + ?Sized> {
pub buffer: &'a B,
pub usage: StateTransition<BufferUses>,
pub usage: StateTransition<wgt::BufferUses>,
}
#[derive(Debug, Clone)]
pub struct TextureBarrier<'a, T: DynTexture + ?Sized> {
pub texture: &'a T,
pub range: wgt::ImageSubresourceRange,
pub usage: StateTransition<TextureUses>,
pub usage: StateTransition<wgt::TextureUses>,
}
#[derive(Clone, Copy, Debug)]
@@ -2307,7 +2220,7 @@ pub struct Attachment<'a, T: DynTextureView + ?Sized> {
pub view: &'a T,
/// Contains either a single mutating usage as a target,
/// or a valid combination of read-only usages.
pub usage: TextureUses,
pub usage: wgt::TextureUses,
}
#[derive(Clone, Debug)]
+6 -6
View File
@@ -377,12 +377,12 @@ impl crate::Adapter for super::Adapter {
],
current_extent,
usage: crate::TextureUses::COLOR_TARGET
| crate::TextureUses::COPY_SRC
| crate::TextureUses::COPY_DST
| crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE,
usage: wgt::TextureUses::COLOR_TARGET
| wgt::TextureUses::COPY_SRC
| wgt::TextureUses::COPY_DST
| wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE,
})
}
+2 -2
View File
@@ -279,7 +279,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Texture,
regions: T,
) where
@@ -358,7 +358,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &super::Texture,
_src_usage: crate::TextureUses,
_src_usage: wgt::TextureUses,
dst: &super::Buffer,
regions: T,
) where
+2 -2
View File
@@ -1,8 +1,8 @@
pub fn map_texture_usage(
format: wgt::TextureFormat,
usage: crate::TextureUses,
usage: wgt::TextureUses,
) -> metal::MTLTextureUsage {
use crate::TextureUses as Tu;
use wgt::TextureUses as Tu;
let mut mtl_usage = metal::MTLTextureUsage::Unknown;
+2 -2
View File
@@ -340,8 +340,8 @@ impl crate::Device for super::Device {
type A = super::Api;
unsafe fn create_buffer(&self, desc: &crate::BufferDescriptor) -> DeviceResult<super::Buffer> {
let map_read = desc.usage.contains(crate::BufferUses::MAP_READ);
let map_write = desc.usage.contains(crate::BufferUses::MAP_WRITE);
let map_read = desc.usage.contains(wgt::BufferUses::MAP_READ);
let map_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE);
let mut options = metal::MTLResourceOptions::empty();
options |= if map_read || map_write {
+1 -1
View File
@@ -289,7 +289,7 @@ impl crate::Surface for super::Surface {
*self.extent.write() = config.extent;
let render_layer = self.render_layer.lock();
let framebuffer_only = config.usage == crate::TextureUses::COLOR_TARGET;
let framebuffer_only = config.usage == wgt::TextureUses::COLOR_TARGET;
let display_sync = match config.present_mode {
wgt::PresentMode::Fifo => true,
wgt::PresentMode::Immediate => false,
+3 -3
View File
@@ -285,7 +285,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &super::Texture,
src_usage: crate::TextureUses,
src_usage: wgt::TextureUses,
dst: &super::Texture,
regions: T,
) where
@@ -345,7 +345,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &super::Texture,
src_usage: crate::TextureUses,
src_usage: wgt::TextureUses,
dst: &super::Buffer,
regions: T,
) where
@@ -1157,7 +1157,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
#[test]
fn check_dst_image_layout() {
assert_eq!(
conv::derive_image_layout(crate::TextureUses::COPY_DST, wgt::TextureFormat::Rgba8Unorm),
conv::derive_image_layout(wgt::TextureUses::COPY_DST, wgt::TextureFormat::Rgba8Unorm),
DST_IMAGE_LAYOUT
);
}
+70 -77
View File
@@ -218,23 +218,18 @@ impl crate::ColorAttachment<'_, super::TextureView> {
}
}
pub fn derive_image_layout(
usage: crate::TextureUses,
format: wgt::TextureFormat,
) -> vk::ImageLayout {
pub fn derive_image_layout(usage: wgt::TextureUses, format: wgt::TextureFormat) -> vk::ImageLayout {
// Note: depth textures are always sampled with RODS layout
let is_color = !format.is_depth_stencil_format();
match usage {
crate::TextureUses::UNINITIALIZED => vk::ImageLayout::UNDEFINED,
crate::TextureUses::COPY_SRC => vk::ImageLayout::TRANSFER_SRC_OPTIMAL,
crate::TextureUses::COPY_DST => vk::ImageLayout::TRANSFER_DST_OPTIMAL,
crate::TextureUses::RESOURCE if is_color => vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
crate::TextureUses::COLOR_TARGET => vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
crate::TextureUses::DEPTH_STENCIL_WRITE => {
vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL
}
wgt::TextureUses::UNINITIALIZED => vk::ImageLayout::UNDEFINED,
wgt::TextureUses::COPY_SRC => vk::ImageLayout::TRANSFER_SRC_OPTIMAL,
wgt::TextureUses::COPY_DST => vk::ImageLayout::TRANSFER_DST_OPTIMAL,
wgt::TextureUses::RESOURCE if is_color => vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
wgt::TextureUses::COLOR_TARGET => vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
wgt::TextureUses::DEPTH_STENCIL_WRITE => vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
_ => {
if usage == crate::TextureUses::PRESENT {
if usage == wgt::TextureUses::PRESENT {
vk::ImageLayout::PRESENT_SRC_KHR
} else if is_color {
vk::ImageLayout::GENERAL
@@ -245,30 +240,30 @@ pub fn derive_image_layout(
}
}
pub fn map_texture_usage(usage: crate::TextureUses) -> vk::ImageUsageFlags {
pub fn map_texture_usage(usage: wgt::TextureUses) -> vk::ImageUsageFlags {
let mut flags = vk::ImageUsageFlags::empty();
if usage.contains(crate::TextureUses::COPY_SRC) {
if usage.contains(wgt::TextureUses::COPY_SRC) {
flags |= vk::ImageUsageFlags::TRANSFER_SRC;
}
if usage.contains(crate::TextureUses::COPY_DST) {
if usage.contains(wgt::TextureUses::COPY_DST) {
flags |= vk::ImageUsageFlags::TRANSFER_DST;
}
if usage.contains(crate::TextureUses::RESOURCE) {
if usage.contains(wgt::TextureUses::RESOURCE) {
flags |= vk::ImageUsageFlags::SAMPLED;
}
if usage.contains(crate::TextureUses::COLOR_TARGET) {
if usage.contains(wgt::TextureUses::COLOR_TARGET) {
flags |= vk::ImageUsageFlags::COLOR_ATTACHMENT;
}
if usage.intersects(
crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE,
) {
if usage
.intersects(wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE)
{
flags |= vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT;
}
if usage.intersects(
crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE
| crate::TextureUses::STORAGE_ATOMIC,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE
| wgt::TextureUses::STORAGE_ATOMIC,
) {
flags |= vk::ImageUsageFlags::STORAGE;
}
@@ -276,7 +271,7 @@ pub fn map_texture_usage(usage: crate::TextureUses) -> vk::ImageUsageFlags {
}
pub fn map_texture_usage_to_barrier(
usage: crate::TextureUses,
usage: wgt::TextureUses,
) -> (vk::PipelineStageFlags, vk::AccessFlags) {
let mut stages = vk::PipelineStageFlags::empty();
let mut access = vk::AccessFlags::empty();
@@ -284,51 +279,51 @@ pub fn map_texture_usage_to_barrier(
| vk::PipelineStageFlags::FRAGMENT_SHADER
| vk::PipelineStageFlags::COMPUTE_SHADER;
if usage.contains(crate::TextureUses::COPY_SRC) {
if usage.contains(wgt::TextureUses::COPY_SRC) {
stages |= vk::PipelineStageFlags::TRANSFER;
access |= vk::AccessFlags::TRANSFER_READ;
}
if usage.contains(crate::TextureUses::COPY_DST) {
if usage.contains(wgt::TextureUses::COPY_DST) {
stages |= vk::PipelineStageFlags::TRANSFER;
access |= vk::AccessFlags::TRANSFER_WRITE;
}
if usage.contains(crate::TextureUses::RESOURCE) {
if usage.contains(wgt::TextureUses::RESOURCE) {
stages |= shader_stages;
access |= vk::AccessFlags::SHADER_READ;
}
if usage.contains(crate::TextureUses::COLOR_TARGET) {
if usage.contains(wgt::TextureUses::COLOR_TARGET) {
stages |= vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT;
access |= vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE;
}
if usage.intersects(crate::TextureUses::DEPTH_STENCIL_READ) {
if usage.intersects(wgt::TextureUses::DEPTH_STENCIL_READ) {
stages |= vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS
| vk::PipelineStageFlags::LATE_FRAGMENT_TESTS;
access |= vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ;
}
if usage.intersects(crate::TextureUses::DEPTH_STENCIL_WRITE) {
if usage.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE) {
stages |= vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS
| vk::PipelineStageFlags::LATE_FRAGMENT_TESTS;
access |= vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ
| vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE;
}
if usage.intersects(
crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_READ_WRITE
| crate::TextureUses::STORAGE_ATOMIC,
wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE
| wgt::TextureUses::STORAGE_ATOMIC,
) {
stages |= shader_stages;
access |= vk::AccessFlags::SHADER_READ;
}
if usage.intersects(
crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE
| crate::TextureUses::STORAGE_ATOMIC,
wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE
| wgt::TextureUses::STORAGE_ATOMIC,
) {
stages |= shader_stages;
access |= vk::AccessFlags::SHADER_WRITE;
}
if usage == crate::TextureUses::UNINITIALIZED || usage == crate::TextureUses::PRESENT {
if usage == wgt::TextureUses::UNINITIALIZED || usage == wgt::TextureUses::PRESENT {
(
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::AccessFlags::empty(),
@@ -338,28 +333,28 @@ pub fn map_texture_usage_to_barrier(
}
}
pub fn map_vk_image_usage(usage: vk::ImageUsageFlags) -> crate::TextureUses {
let mut bits = crate::TextureUses::empty();
pub fn map_vk_image_usage(usage: vk::ImageUsageFlags) -> wgt::TextureUses {
let mut bits = wgt::TextureUses::empty();
if usage.contains(vk::ImageUsageFlags::TRANSFER_SRC) {
bits |= crate::TextureUses::COPY_SRC;
bits |= wgt::TextureUses::COPY_SRC;
}
if usage.contains(vk::ImageUsageFlags::TRANSFER_DST) {
bits |= crate::TextureUses::COPY_DST;
bits |= wgt::TextureUses::COPY_DST;
}
if usage.contains(vk::ImageUsageFlags::SAMPLED) {
bits |= crate::TextureUses::RESOURCE;
bits |= wgt::TextureUses::RESOURCE;
}
if usage.contains(vk::ImageUsageFlags::COLOR_ATTACHMENT) {
bits |= crate::TextureUses::COLOR_TARGET;
bits |= wgt::TextureUses::COLOR_TARGET;
}
if usage.contains(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT) {
bits |= crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE;
bits |= wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE;
}
if usage.contains(vk::ImageUsageFlags::STORAGE) {
bits |= crate::TextureUses::STORAGE_READ_ONLY
| crate::TextureUses::STORAGE_WRITE_ONLY
| crate::TextureUses::STORAGE_READ_WRITE
| crate::TextureUses::STORAGE_ATOMIC;
bits |= wgt::TextureUses::STORAGE_READ_ONLY
| wgt::TextureUses::STORAGE_WRITE_ONLY
| wgt::TextureUses::STORAGE_READ_WRITE
| wgt::TextureUses::STORAGE_ATOMIC;
}
bits
}
@@ -523,37 +518,35 @@ pub fn map_vk_composite_alpha(flags: vk::CompositeAlphaFlagsKHR) -> Vec<wgt::Com
modes
}
pub fn map_buffer_usage(usage: crate::BufferUses) -> vk::BufferUsageFlags {
pub fn map_buffer_usage(usage: wgt::BufferUses) -> vk::BufferUsageFlags {
let mut flags = vk::BufferUsageFlags::empty();
if usage.contains(crate::BufferUses::COPY_SRC) {
if usage.contains(wgt::BufferUses::COPY_SRC) {
flags |= vk::BufferUsageFlags::TRANSFER_SRC;
}
if usage.contains(crate::BufferUses::COPY_DST) {
if usage.contains(wgt::BufferUses::COPY_DST) {
flags |= vk::BufferUsageFlags::TRANSFER_DST;
}
if usage.contains(crate::BufferUses::UNIFORM) {
if usage.contains(wgt::BufferUses::UNIFORM) {
flags |= vk::BufferUsageFlags::UNIFORM_BUFFER;
}
if usage
.intersects(crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::STORAGE_READ_WRITE)
{
if usage.intersects(wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE) {
flags |= vk::BufferUsageFlags::STORAGE_BUFFER;
}
if usage.contains(crate::BufferUses::INDEX) {
if usage.contains(wgt::BufferUses::INDEX) {
flags |= vk::BufferUsageFlags::INDEX_BUFFER;
}
if usage.contains(crate::BufferUses::VERTEX) {
if usage.contains(wgt::BufferUses::VERTEX) {
flags |= vk::BufferUsageFlags::VERTEX_BUFFER;
}
if usage.contains(crate::BufferUses::INDIRECT) {
if usage.contains(wgt::BufferUses::INDIRECT) {
flags |= vk::BufferUsageFlags::INDIRECT_BUFFER;
}
if usage.contains(crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH) {
if usage.contains(wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH) {
flags |= vk::BufferUsageFlags::STORAGE_BUFFER | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS;
}
if usage.intersects(
crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT
| crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT
| wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
) {
flags |= vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS;
@@ -562,7 +555,7 @@ pub fn map_buffer_usage(usage: crate::BufferUses) -> vk::BufferUsageFlags {
}
pub fn map_buffer_usage_to_barrier(
usage: crate::BufferUses,
usage: wgt::BufferUses,
) -> (vk::PipelineStageFlags, vk::AccessFlags) {
let mut stages = vk::PipelineStageFlags::empty();
let mut access = vk::AccessFlags::empty();
@@ -570,50 +563,50 @@ pub fn map_buffer_usage_to_barrier(
| vk::PipelineStageFlags::FRAGMENT_SHADER
| vk::PipelineStageFlags::COMPUTE_SHADER;
if usage.contains(crate::BufferUses::MAP_READ) {
if usage.contains(wgt::BufferUses::MAP_READ) {
stages |= vk::PipelineStageFlags::HOST;
access |= vk::AccessFlags::HOST_READ;
}
if usage.contains(crate::BufferUses::MAP_WRITE) {
if usage.contains(wgt::BufferUses::MAP_WRITE) {
stages |= vk::PipelineStageFlags::HOST;
access |= vk::AccessFlags::HOST_WRITE;
}
if usage.contains(crate::BufferUses::COPY_SRC) {
if usage.contains(wgt::BufferUses::COPY_SRC) {
stages |= vk::PipelineStageFlags::TRANSFER;
access |= vk::AccessFlags::TRANSFER_READ;
}
if usage.contains(crate::BufferUses::COPY_DST) {
if usage.contains(wgt::BufferUses::COPY_DST) {
stages |= vk::PipelineStageFlags::TRANSFER;
access |= vk::AccessFlags::TRANSFER_WRITE;
}
if usage.contains(crate::BufferUses::UNIFORM) {
if usage.contains(wgt::BufferUses::UNIFORM) {
stages |= shader_stages;
access |= vk::AccessFlags::UNIFORM_READ;
}
if usage.intersects(crate::BufferUses::STORAGE_READ_ONLY) {
if usage.intersects(wgt::BufferUses::STORAGE_READ_ONLY) {
stages |= shader_stages;
access |= vk::AccessFlags::SHADER_READ;
}
if usage.intersects(crate::BufferUses::STORAGE_READ_WRITE) {
if usage.intersects(wgt::BufferUses::STORAGE_READ_WRITE) {
stages |= shader_stages;
access |= vk::AccessFlags::SHADER_READ | vk::AccessFlags::SHADER_WRITE;
}
if usage.contains(crate::BufferUses::INDEX) {
if usage.contains(wgt::BufferUses::INDEX) {
stages |= vk::PipelineStageFlags::VERTEX_INPUT;
access |= vk::AccessFlags::INDEX_READ;
}
if usage.contains(crate::BufferUses::VERTEX) {
if usage.contains(wgt::BufferUses::VERTEX) {
stages |= vk::PipelineStageFlags::VERTEX_INPUT;
access |= vk::AccessFlags::VERTEX_ATTRIBUTE_READ;
}
if usage.contains(crate::BufferUses::INDIRECT) {
if usage.contains(wgt::BufferUses::INDIRECT) {
stages |= vk::PipelineStageFlags::DRAW_INDIRECT;
access |= vk::AccessFlags::INDIRECT_COMMAND_READ;
}
if usage.intersects(
crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT
| crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT
| crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT
| wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT
| wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
) {
stages |= vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR;
access |= vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR
+3 -3
View File
@@ -1040,17 +1040,17 @@ impl crate::Device for super::Device {
let mut alloc_usage = if desc
.usage
.intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE)
.intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE)
{
let mut flags = gpu_alloc::UsageFlags::HOST_ACCESS;
//TODO: find a way to use `crate::MemoryFlags::PREFER_COHERENT`
flags.set(
gpu_alloc::UsageFlags::DOWNLOAD,
desc.usage.contains(crate::BufferUses::MAP_READ),
desc.usage.contains(wgt::BufferUses::MAP_READ),
);
flags.set(
gpu_alloc::UsageFlags::UPLOAD,
desc.usage.contains(crate::BufferUses::MAP_WRITE),
desc.usage.contains(wgt::BufferUses::MAP_WRITE),
);
flags
} else {
+2 -2
View File
@@ -618,7 +618,7 @@ struct FramebufferAttachment {
/// Can be NULL if the framebuffer is image-less
raw: vk::ImageView,
raw_image_flags: vk::ImageCreateFlags,
view_usage: crate::TextureUses,
view_usage: wgt::TextureUses,
view_format: wgt::TextureFormat,
raw_view_formats: Vec<vk::Format>,
}
@@ -798,7 +798,7 @@ pub struct Texture {
drop_guard: Option<crate::DropGuard>,
external_memory: Option<vk::DeviceMemory>,
block: Option<gpu_alloc::MemoryBlock<vk::DeviceMemory>>,
usage: crate::TextureUses,
usage: wgt::TextureUses,
format: wgt::TextureFormat,
raw_flags: vk::ImageCreateFlags,
copy_size: crate::CopyExtent,
+121
View File
@@ -5522,6 +5522,60 @@ bitflags::bitflags! {
}
}
bitflags::bitflags! {
/// Similar to `BufferUsages`, but used only for `CommandEncoder::transition_resources`.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct BufferUses: u16 {
/// The argument to a read-only mapping.
const MAP_READ = 1 << 0;
/// The argument to a write-only mapping.
const MAP_WRITE = 1 << 1;
/// The source of a hardware copy.
const COPY_SRC = 1 << 2;
/// The destination of a hardware copy.
const COPY_DST = 1 << 3;
/// The index buffer used for drawing.
const INDEX = 1 << 4;
/// A vertex buffer used for drawing.
const VERTEX = 1 << 5;
/// A uniform buffer bound in a bind group.
const UNIFORM = 1 << 6;
/// A read-only storage buffer used in a bind group.
const STORAGE_READ_ONLY = 1 << 7;
/// A read-write buffer used in a bind group.
const STORAGE_READ_WRITE = 1 << 8;
/// The indirect or count buffer in a indirect draw or dispatch.
const INDIRECT = 1 << 9;
/// A buffer used to store query results.
const QUERY_RESOLVE = 1 << 10;
/// Buffer used for acceleration structure building.
const ACCELERATION_STRUCTURE_SCRATCH = 1 << 11;
/// Buffer used for bottom level acceleration structure building.
const BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 12;
/// Buffer used for top level acceleration structure building.
const TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 13;
/// The combination of states that a buffer may be in _at the same time_.
const INCLUSIVE = Self::MAP_READ.bits() | Self::COPY_SRC.bits() |
Self::INDEX.bits() | Self::VERTEX.bits() | Self::UNIFORM.bits() |
Self::STORAGE_READ_ONLY.bits() | Self::INDIRECT.bits() | Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits() | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits();
/// The combination of states that a buffer must exclusively be in.
const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits() | Self::ACCELERATION_STRUCTURE_SCRATCH.bits();
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is ordered, then if the buffer state doesn't change between draw calls, there
/// are no barriers needed for synchronization.
const ORDERED = Self::INCLUSIVE.bits() | Self::MAP_WRITE.bits();
}
}
/// A buffer transition for use with `CommandEncoder::transition_resources`.
#[derive(Debug)]
pub struct BufferTransition<T> {
/// The buffer to transition.
pub buffer: T,
/// The new state to transition to.
pub state: BufferUses,
}
/// Describes a [`Buffer`](../wgpu/struct.Buffer.html).
///
/// Corresponds to [WebGPU `GPUBufferDescriptor`](
@@ -5736,6 +5790,73 @@ bitflags::bitflags! {
}
}
bitflags::bitflags! {
/// Similar to `TextureUsages`, but used only for `CommandEncoder::transition_resources`.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TextureUses: u16 {
/// The texture is in unknown state.
const UNINITIALIZED = 1 << 0;
/// Ready to present image to the surface.
const PRESENT = 1 << 1;
/// The source of a hardware copy.
const COPY_SRC = 1 << 2;
/// The destination of a hardware copy.
const COPY_DST = 1 << 3;
/// Read-only sampled or fetched resource.
const RESOURCE = 1 << 4;
/// The color target of a renderpass.
const COLOR_TARGET = 1 << 5;
/// Read-only depth stencil usage.
const DEPTH_STENCIL_READ = 1 << 6;
/// Read-write depth stencil usage
const DEPTH_STENCIL_WRITE = 1 << 7;
/// Read-only storage texture usage. Corresponds to a UAV in d3d, so is exclusive, despite being read only.
const STORAGE_READ_ONLY = 1 << 8;
/// Write-only storage texture usage.
const STORAGE_WRITE_ONLY = 1 << 9;
/// Read-write storage texture usage.
const STORAGE_READ_WRITE = 1 << 10;
/// Image atomic enabled storage.
const STORAGE_ATOMIC = 1 << 11;
/// The combination of states that a texture may be in _at the same time_.
const INCLUSIVE = Self::COPY_SRC.bits() | Self::RESOURCE.bits() | Self::DEPTH_STENCIL_READ.bits();
/// The combination of states that a texture must exclusively be in.
const EXCLUSIVE = Self::COPY_DST.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits() | Self::STORAGE_WRITE_ONLY.bits() | Self::STORAGE_READ_WRITE.bits() | Self::STORAGE_ATOMIC.bits() | Self::PRESENT.bits();
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is ordered, then if the texture state doesn't change between draw calls, there
/// are no barriers needed for synchronization.
const ORDERED = Self::INCLUSIVE.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits();
/// Flag used by the wgpu-core texture tracker to say a texture is in different states for every sub-resource
const COMPLEX = 1 << 12;
/// Flag used by the wgpu-core texture tracker to say that the tracker does not know the state of the sub-resource.
/// This is different from UNINITIALIZED as that says the tracker does know, but the texture has not been initialized.
const UNKNOWN = 1 << 13;
}
}
/// A texture transition for use with `CommandEncoder::transition_resources`.
#[derive(Debug)]
pub struct TextureTransition<T> {
/// The texture to transition.
pub texture: T,
/// An optional selector to transition only part of the texture.
///
/// If None, the entire texture will be transitioned.
pub selector: Option<TextureSelector>,
/// The new state to transition to.
pub state: TextureUses,
}
/// Specifies a particular set of subresources in a texture.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TextureSelector {
/// Range of mips to use.
pub mips: Range<u32>,
/// Range of layers to use.
pub layers: Range<u32>,
}
/// Defines the capabilities of a given surface and adapter.
#[derive(Debug)]
pub struct SurfaceCapabilities {
+65
View File
@@ -344,4 +344,69 @@ impl CommandEncoder {
&mut tlas.into_iter(),
);
}
/// Transition resources to an underlying hal resource state.
///
/// This is an advanced, native-only API (no-op on web) that has two main use cases:
///
/// # Batching Barriers
///
/// Wgpu does not have a global view of the frame when recording command buffers. When you submit multiple command buffers in a single queue submission, wgpu may need to record and
/// insert new command buffers (holding 1 or more barrier commands) in between the user-supplied command buffers in order to ensure that resources are transitioned to the correct state
/// for the start of the next user-supplied command buffer.
///
/// Wgpu does not currently attempt to batch multiple of these generated command buffers/barriers together, which may lead to suboptimal barrier placement.
///
/// Consider the following scenario, where the user does `queue.submit(&[a, b, c])`:
/// * CommandBuffer A: Use resource X as a render pass attachment
/// * CommandBuffer B: Use resource Y as a render pass attachment
/// * CommandBuffer C: Use resources X and Y in a bind group
///
/// At submission time, wgpu will record and insert some new command buffers, resulting in a submission that looks like `queue.submit(&[0, a, 1, b, 2, c])`:
/// * CommandBuffer 0: Barrier to transition resource X from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET
/// * CommandBuffer A: Use resource X as a render pass attachment
/// * CommandBuffer 1: Barrier to transition resource Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET
/// * CommandBuffer B: Use resource Y as a render pass attachment
/// * CommandBuffer 2: Barrier to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE
/// * CommandBuffer C: Use resources X and Y in a bind group
///
/// To prevent this, after profiling their app, an advanced user might choose to instead do `queue.submit(&[a, b, c])`:
/// * CommandBuffer A:
/// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET
/// * Use resource X as a render pass attachment
/// * CommandBuffer B: Use resource Y as a render pass attachment
/// * CommandBuffer C:
/// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE
/// * Use resources X and Y in a bind group
///
/// At submission time, wgpu will record and insert some new command buffers, resulting in a submission that looks like `queue.submit(&[0, a, b, 1, c])`:
/// * CommandBuffer 0: Barrier to transition resources X and Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET
/// * CommandBuffer A: Use resource X as a render pass attachment
/// * CommandBuffer B: Use resource Y as a render pass attachment
/// * CommandBuffer 1: Barrier to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE
/// * CommandBuffer C: Use resources X and Y in a bind group
///
/// Which eliminates the extra command buffer and barrier between command buffers A and B.
///
/// # Native Interoperability
///
/// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and
/// the native API commands, for synchronization and resource state transition purposes.
pub fn transition_resources<'a>(
&mut self,
buffer_transitions: impl Iterator<Item = wgt::BufferTransition<&'a Buffer>>,
texture_transitions: impl Iterator<Item = wgt::TextureTransition<&'a Texture>>,
) {
self.inner.transition_resources(
&mut buffer_transitions.map(|t| wgt::BufferTransition {
buffer: &t.buffer.inner,
state: t.state,
}),
&mut texture_transitions.map(|t| wgt::TextureTransition {
texture: &t.texture.inner,
selector: t.selector,
state: t.state,
}),
);
}
}
+12
View File
@@ -3103,6 +3103,18 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder {
) {
unimplemented!("Raytracing not implemented for web");
}
fn transition_resources<'a>(
&mut self,
_buffer_transitions: &mut dyn Iterator<
Item = wgt::BufferTransition<&'a dispatch::DispatchBuffer>,
>,
_texture_transitions: &mut dyn Iterator<
Item = wgt::TextureTransition<&'a dispatch::DispatchTexture>,
>,
) {
// no-op
}
}
impl Drop for WebCommandEncoder {
fn drop(&mut self) {
+31
View File
@@ -2545,6 +2545,37 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder {
);
}
}
fn transition_resources<'a>(
&mut self,
buffer_transitions: &mut dyn Iterator<
Item = wgt::BufferTransition<&'a dispatch::DispatchBuffer>,
>,
texture_transitions: &mut dyn Iterator<
Item = wgt::TextureTransition<&'a dispatch::DispatchTexture>,
>,
) {
let result = self.context.0.command_encoder_transition_resources(
self.id,
buffer_transitions.map(|t| wgt::BufferTransition {
buffer: t.buffer.as_core().id,
state: t.state,
}),
texture_transitions.map(|t| wgt::TextureTransition {
texture: t.texture.as_core().id,
selector: t.selector.clone(),
state: t.state,
}),
);
if let Err(cause) = result {
self.context.handle_error_nolabel(
&self.error_sink,
cause,
"CommandEncoder::transition_resources",
);
}
}
}
impl Drop for CoreCommandEncoder {
+6
View File
@@ -350,6 +350,12 @@ pub trait CommandEncoderInterface: CommonTraits {
blas: &mut dyn Iterator<Item = &'a crate::BlasBuildEntry<'a>>,
tlas: &mut dyn Iterator<Item = &'a crate::TlasPackage>,
);
fn transition_resources<'a>(
&mut self,
buffer_transitions: &mut dyn Iterator<Item = wgt::BufferTransition<&'a DispatchBuffer>>,
texture_transitions: &mut dyn Iterator<Item = wgt::TextureTransition<&'a DispatchTexture>>,
);
}
pub trait ComputePassInterface: CommonTraits {
fn set_pipeline(&mut self, pipeline: &DispatchComputePipeline);
+18 -18
View File
@@ -60,24 +60,24 @@ pub use api::*;
pub use wgt::{
AdapterInfo, AddressMode, AstcBlock, AstcChannel, Backend, BackendOptions, Backends,
BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState,
BufferAddress, BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState,
ColorWrites, CommandBufferDescriptor, CompareFunction, CompositeAlphaMode,
CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState, DeviceLostReason,
DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits, Dx12BackendOptions,
Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, GlBackendOptions,
Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor,
InstanceFlags, InternalCounters, Limits, MaintainResult, MemoryHints, MultisampleState,
Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference,
PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor,
ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, StencilFaceState,
StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, SurfaceStatus,
TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureUsages,
TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend,
WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES,
QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
BufferAddress, BufferBindingType, BufferSize, BufferTransition, BufferUsages, BufferUses,
Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction,
CompositeAlphaMode, CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState,
DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits,
Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode,
FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters, ImageSubresourceRange,
IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters, Limits, MaintainResult,
MemoryHints, MultisampleState, Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode,
PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState,
PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType,
SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages,
StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities,
SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition,
TextureUsages, TextureUses, TextureViewDimension, VertexAttribute, VertexFormat,
VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT,
COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
};
#[expect(deprecated)]
pub use wgt::{ImageCopyBuffer, ImageCopyTexture, ImageCopyTextureTagged, ImageDataLayout};
+1 -1
View File
@@ -9,7 +9,7 @@ pub struct BufferInitDescriptor<'a> {
pub contents: &'a [u8],
/// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation
/// will panic.
pub usage: crate::BufferUsages,
pub usage: wgt::BufferUsages,
}
/// Utility methods not meant to be in the main API.