From a677265e1733f0d9e2365892ba16dd8e1d67ad30 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 25 Feb 2021 09:43:52 -0500 Subject: [PATCH 1/6] Expose the queue module --- CHANGELOG.md | 3 +++ wgpu-core/src/device/life.rs | 4 ++-- wgpu-core/src/device/mod.rs | 2 +- wgpu-core/src/device/queue.rs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 448641476..e35ee1bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## v0.7.1 (2021-02-25) + - Expose `wgc::device::queue` sub-module in publis + ## v0.7 (2021-01-31) - Major API changes: - `RenderPipelineDescriptor` diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index f30fe89b6..8aef40e15 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -249,7 +249,7 @@ impl LifetimeTracker { } } - pub fn track_submission( + pub(super) fn track_submission( &mut self, index: SubmissionIndex, fence: B::Fence, @@ -356,7 +356,7 @@ impl LifetimeTracker { } } - pub fn schedule_resource_destruction( + pub(super) fn schedule_resource_destruction( &mut self, temp_resource: TempResource, memory: alloc::MemoryBlock, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 1a2fcc733..153d5b82b 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -42,7 +42,7 @@ use std::{ pub mod alloc; pub mod descriptor; mod life; -mod queue; +pub mod queue; #[cfg(any(feature = "trace", feature = "replay"))] pub mod trace; diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index dbc53f28a..89e199155 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -29,13 +29,13 @@ struct StagingData { } #[derive(Debug)] -pub enum TempResource { +pub(super) enum TempResource { Buffer(B::Buffer), Image(B::Image), } #[derive(Debug)] -pub(crate) struct PendingWrites { +pub(super) struct PendingWrites { pub command_buffer: Option, pub temp_resources: Vec<(TempResource, alloc::MemoryBlock)>, pub dst_buffers: FastHashSet, From ed86e7ff05a6e4d4e6eb21f67b21dff36616362d Mon Sep 17 00:00:00 2001 From: Daniel Tang Date: Mon, 1 Feb 2021 02:15:06 -0500 Subject: [PATCH 2/6] Improve docs language --- wgpu-types/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 61574e574..2474456b4 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -847,9 +847,9 @@ impl Default for CullMode { pub enum PolygonMode { /// Polygons are filled Fill = 0, - /// Polygons are draw as line segments + /// Polygons are drawn as line segments Line = 1, - /// Polygons are draw as points + /// Polygons are drawn as points Point = 2, } @@ -873,7 +873,7 @@ pub struct PrimitiveState { /// The face to consider the front for the purpose of culling and stencil operations. #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] pub front_face: FrontFace, - /// The fact culling mode. + /// The face culling mode. #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] pub cull_mode: CullMode, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` From d66809d18b8ed3d6894ef85a0acf20ac19083aca Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 5 Feb 2021 00:57:13 -0500 Subject: [PATCH 3/6] Fix command allocator race condition with maintenance --- wgpu-core/src/command/allocator.rs | 42 +++++++++++++++++------------- wgpu-core/src/device/mod.rs | 3 +-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index f00c5d9ed..9d85d814a 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -98,26 +98,32 @@ impl CommandAllocator { let mut inner = self.inner.lock(); use std::collections::hash_map::Entry; - if let Entry::Vacant(e) = inner.pools.entry(thread_id) { - tracing::info!("Starting on thread {:?}", thread_id); - let raw = unsafe { - device - .create_command_pool( - self.queue_family, - hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL, - ) - .or(Err(DeviceError::OutOfMemory))? - }; - e.insert(CommandPool { - raw, - total: 0, - available: Vec::new(), - pending: Vec::new(), - }); - } + let pool = match inner.pools.entry(thread_id) { + Entry::Vacant(e) => { + tracing::info!("Starting on thread {:?}", thread_id); + let raw = unsafe { + device + .create_command_pool( + self.queue_family, + hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL, + ) + .or(Err(DeviceError::OutOfMemory))? + }; + e.insert(CommandPool { + raw, + total: 0, + available: Vec::new(), + pending: Vec::new(), + }) + } + Entry::Occupied(e) => e.into_mut(), + }; + + //Note: we have to allocate the first buffer right here, or otherwise + // the pool may be cleaned up by maintenance called from another thread. Ok(CommandBuffer { - raw: Vec::new(), + raw: vec![pool.allocate()], is_recording: true, recorded_thread_id: thread_id, device_id, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 153d5b82b..c2e2fad52 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -3549,14 +3549,13 @@ impl Global { Err(e) => break e, }; - let mut raw = device.cmd_allocator.extend(&command_buffer); + let mut raw = command_buffer.raw.first_mut().unwrap(); unsafe { if let Some(ref label) = desc.label { device.raw.set_command_buffer_name(&mut raw, label); } raw.begin_primary(hal::command::CommandBufferFlags::ONE_TIME_SUBMIT); } - command_buffer.raw.push(raw); let id = hub .command_buffers From 6181182f1f21fd5555fe645a9cb614310027a9e8 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Fri, 12 Feb 2021 13:56:51 +0100 Subject: [PATCH 4/6] fix rustdoc warnings --- wgpu-core/src/binding_model.rs | 2 +- wgpu-core/src/command/transfer.rs | 2 +- wgpu-core/src/resource.rs | 4 ++-- wgpu-types/src/lib.rs | 24 ++++++++++++------------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index da9f33200..8074d373c 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -440,7 +440,7 @@ pub struct PipelineLayoutDescriptor<'a> { /// must define the range in push constant memory that corresponds to its single `layout(push_constant)` /// uniform block. /// - /// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled. + /// If this array is non-empty, the [`Features::PUSH_CONSTANTS`](wgt::Features::PUSH_CONSTANTS) must be enabled. pub push_constant_ranges: Cow<'a, [wgt::PushConstantRange]>, } diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index e19fcd3a8..d73a1d1bf 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -220,7 +220,7 @@ pub(crate) fn validate_linear_texture_data( Ok(()) } -/// Function copied with minor modifications from webgpu standard https://gpuweb.github.io/gpuweb/#valid-texture-copy-range +/// Function copied with minor modifications from webgpu standard pub(crate) fn validate_texture_copy_range( texture_copy_view: &TextureCopyView, texture_format: wgt::TextureFormat, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 23aab5c86..109256444 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -273,7 +273,7 @@ pub struct TextureViewDescriptor<'a> { /// The dimension of the texture view. For 1D textures, this must be `1D`. For 2D textures it must be one of /// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `3D` pub dimension: Option, - /// Aspect of the texture. Color textures must be [`TextureAspect::All`]. + /// Aspect of the texture. Color textures must be [`TextureAspect::All`](wgt::TextureAspect::All). pub aspect: wgt::TextureAspect, /// Base mip level. pub base_mip_level: u32, @@ -393,7 +393,7 @@ pub struct SamplerDescriptor<'a> { pub compare: Option, /// Valid values: 1, 2, 4, 8, and 16. pub anisotropy_clamp: Option, - /// Border color to use when address_mode is [`AddressMode::ClampToBorder`] + /// Border color to use when address_mode is [`AddressMode::ClampToBorder`](wgt::AddressMode::ClampToBorder) pub border_color: Option, } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 2474456b4..8e42f6875 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -436,7 +436,7 @@ bitflags::bitflags! { /// implementation needs to support more than is needed. You should ideally only request exactly what /// you need. /// -/// See also: https://gpuweb.github.io/gpuweb/#dictdef-gpulimits +/// See also: #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] @@ -1368,7 +1368,7 @@ impl TextureFormat { let storage = basic | TextureUsage::STORAGE; let all_flags = TextureUsage::all(); - // See https://gpuweb.github.io/gpuweb/#texture-format-caps for reference + // See for reference let (required_features, sample_type, srgb, block_dimensions, block_size, allowed_usages) = match self { // Normal 8 bit textures @@ -2462,7 +2462,7 @@ pub struct TextureDataLayout { /// Specific type of a buffer binding. /// -/// WebGPU spec: https://gpuweb.github.io/gpuweb/#enumdef-gpubufferbindingtype +/// WebGPU spec: #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] @@ -2508,7 +2508,7 @@ impl Default for BufferBindingType { /// Specific type of a sample in a texture binding. /// -/// WebGPU spec: https://gpuweb.github.io/gpuweb/#enumdef-gputexturesampletype +/// WebGPU spec: #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] @@ -2559,7 +2559,7 @@ impl Default for TextureSampleType { /// Specific type of a sample in a texture binding. /// -/// WebGPU spec: https://gpuweb.github.io/gpuweb/#enumdef-gpustoragetextureaccess +/// WebGPU spec: #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] @@ -2579,7 +2579,7 @@ pub enum StorageTextureAccess { /// ``` WriteOnly, /// The texture can be both read and written in the shader. - /// [`Features::STORAGE_TEXTURE_ACCESS_READ_WRITE`] must be enabled to use this access mode. + /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] must be enabled to use this access mode. /// /// Example GLSL syntax: /// ```cpp,ignore @@ -2591,10 +2591,10 @@ pub enum StorageTextureAccess { /// Specific type of a binding. /// /// WebGPU spec: the enum of -/// - https://gpuweb.github.io/gpuweb/#dictdef-gpubufferbindinglayout -/// - https://gpuweb.github.io/gpuweb/#dictdef-gpusamplerbindinglayout -/// - https://gpuweb.github.io/gpuweb/#dictdef-gputexturebindinglayout -/// - https://gpuweb.github.io/gpuweb/#dictdef-gpustoragetexturebindinglayout +/// - +/// - +/// - +/// - #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] @@ -2628,7 +2628,7 @@ pub enum BindingType { /// A filtering sampler can only be used with a filterable texture. filtering: bool, /// Use as a comparison sampler instead of a normal sampler. - /// For more info take a look at the analogous functionality in OpenGL: https://www.khronos.org/opengl/wiki/Sampler_Object#Comparison_mode. + /// For more info take a look at the analogous functionality in OpenGL: . comparison: bool, }, /// A texture binding. @@ -2655,7 +2655,7 @@ pub enum BindingType { /// layout(set=0, binding=0, r32f) uniform image2D myStorageImage; /// ``` /// Note that the texture format must be specified in the shader as well. - /// A list of valid formats can be found in the specification here: https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.html#layout-qualifiers + /// A list of valid formats can be found in the specification here: StorageTexture { /// Allowed access to this texture. access: StorageTextureAccess, From c27517da97cc7926d784b09e910de86dba9607bb Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 6 Feb 2021 10:47:48 -0500 Subject: [PATCH 5/6] Don't check the index format for non-indexed calls --- wgpu-core/src/command/render.rs | 39 +++++++++++++++++++-------------- wgpu-types/src/lib.rs | 3 ++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index cf4292e7e..ec0366bf8 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -336,7 +336,7 @@ struct State { } impl State { - fn is_ready(&self) -> Result<(), DrawError> { + fn is_ready(&self, indexed: bool) -> Result<(), DrawError> { // Determine how many vertex buffers have already been bound let bound_buffers = self.vertex.inputs.iter().take_while(|v| v.bound).count() as u32; // Compare with the needed quantity @@ -359,17 +359,19 @@ impl State { if self.blend_color == OptionalState::Required { return Err(DrawError::MissingBlendColor); } - // Pipeline expects an index buffer - if let Some(pipeline_index_format) = self.index.pipeline_format { - // We have a buffer bound - let buffer_index_format = self.index.format.ok_or(DrawError::MissingIndexBuffer)?; + if indexed { + // Pipeline expects an index buffer + if let Some(pipeline_index_format) = self.index.pipeline_format { + // We have a buffer bound + let buffer_index_format = self.index.format.ok_or(DrawError::MissingIndexBuffer)?; - // The buffers are different formats - if pipeline_index_format != buffer_index_format { - return Err(DrawError::UnmatchedIndexFormats { - pipeline: pipeline_index_format, - buffer: buffer_index_format, - }); + // The buffers are different formats + if pipeline_index_format != buffer_index_format { + return Err(DrawError::UnmatchedIndexFormats { + pipeline: pipeline_index_format, + buffer: buffer_index_format, + }); + } } } Ok(()) @@ -1458,12 +1460,14 @@ impl Global { first_vertex, first_instance, } => { + let indexed = false; let scope = PassErrorScope::Draw { - indexed: false, + indexed, indirect: false, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; + let last_vertex = first_vertex + vertex_count; let vertex_limit = state.vertex.vertex_limit; if last_vertex > vertex_limit { @@ -1499,12 +1503,13 @@ impl Global { base_vertex, first_instance, } => { + let indexed = true; let scope = PassErrorScope::Draw { - indexed: true, + indexed, indirect: false, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; //TODO: validate that base_vertex + max_index() is within the provided range let last_index = first_index + index_count; @@ -1546,7 +1551,7 @@ impl Global { indirect: true, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; let stride = match indexed { false => mem::size_of::(), @@ -1620,7 +1625,7 @@ impl Global { indirect: true, pipeline: state.pipeline.last_state, }; - state.is_ready().map_pass_err(scope)?; + state.is_ready(indexed).map_pass_err(scope)?; let stride = match indexed { false => mem::size_of::(), diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 8e42f6875..10366d624 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -867,7 +867,8 @@ impl Default for PolygonMode { pub struct PrimitiveState { /// The primitive topology used to interpret vertices. pub topology: PrimitiveTopology, - /// The format of index buffers for strip topologies. Should be left `None` for non-strip. + /// When drawing strip topologies with indices, this is the required format for the index buffer. + /// This has no effect on non-indexed or non-strip draws. #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations. From 7294b6f0d5d5d7b3a9b8bbc74ef759ead18e9868 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 25 Feb 2021 09:45:34 -0500 Subject: [PATCH 6/6] Version bump to 0.7.1 --- CHANGELOG.md | 4 +++- Cargo.lock | 2 +- wgpu-core/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e35ee1bb2..e9cba576e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Change Log ## v0.7.1 (2021-02-25) - - Expose `wgc::device::queue` sub-module in publis + - expose `wgc::device::queue` sub-module in public + - fix the indexed buffer check + - fix command allocator race condition ## v0.7 (2021-01-31) - Major API changes: diff --git a/Cargo.lock b/Cargo.lock index fa78b2ed9..d1d845815 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1799,7 +1799,7 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "0.7.0" +version = "0.7.1" dependencies = [ "arrayvec", "bitflags", diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 77019eabd..d303a85f8 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wgpu-core" -version = "0.7.0" +version = "0.7.1" authors = ["wgpu developers"] edition = "2018" description = "WebGPU core logic on gfx-hal"