Skip to content

Commit

Permalink
Merge branch 'trunk' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 authored Jul 7, 2023
2 parents 7469572 + 234dea1 commit 91d872e
Show file tree
Hide file tree
Showing 30 changed files with 1,007 additions and 199 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ jobs:
set -e
# build for WebGPU
cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm
cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv
cargo doc --target ${{ matrix.target }} --no-deps --features glsl,spirv
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Bottom level categories:
#### Misc Breaking Changes

- Change `AdapterInfo::{device,vendor}` to be `u32` instead of `usize`. By @ameknite in [#3760](https://github.com/gfx-rs/wgpu/pull/3760)
- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904)
- Arcanization of wgpu core resources: Removed 'Token' and 'LifeTime' related management,
removed 'RefCount' and 'MultiRefCount' in favour of using only 'Arc' internal reference count, removing mut from resources and added instead internal members locks on demand or atomics operations, resources now implement Drop and destroy stuff when last 'Arc' resources is released, resources hold an 'Arc' in order to be able to implement Drop, resources have an utility to retrieve the id of the resource itself, removed all guards and just retrive the 'Arc' needed on-demand to unlock registry of resources asap removing locking from hot paths. By @gents83 in [#3626](https://github.com/gfx-rs/wgpu/pull/3626) and tnx also to @jimblandy

Expand All @@ -55,6 +56,7 @@ removed 'RefCount' and 'MultiRefCount' in favour of using only 'Arc' internal re
#### Vulkan

- Work around [Vulkan-ValidationLayers#5671](https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5671) by ignoring reports of violations of [VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912](https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912). By @jimblandy in [#3809](https://github.com/gfx-rs/wgpu/pull/3809).
- Implement depth-clip-control using depthClamp instead of VK_EXT_depth_clip_enable. By @AlbinBernhardssonARM [#3892](https://github.com/gfx-rs/wgpu/pull/3892).

### Added/New Features

Expand All @@ -63,17 +65,20 @@ removed 'RefCount' and 'MultiRefCount' in favour of using only 'Arc' internal re
### Documentation

- Better documentation for draw, draw_indexed, set_viewport and set_scissor_rect. By @genusistimelord in [#3860](https://github.com/gfx-rs/wgpu/pull/3860)
- Fix link to `GPUVertexBufferLayout`. By @fornwall in [#3906](https://github.com/gfx-rs/wgpu/pull/3906)

#### General

- Document feature requirements for `DEPTH32FLOAT_STENCIL8` by @ErichDonGubler in [#3734](https://github.com/gfx-rs/wgpu/pull/3734).
- Flesh out docs. for `AdapterInfo::{device,vendor}` by @ErichDonGubler in [#3763](https://github.com/gfx-rs/wgpu/pull/3763).
- Spell out which sizes are in bytes. By @jimblandy in [#3773](https://github.com/gfx-rs/wgpu/pull/3773).
- On Web, types don't implement `Send` or `Sync` anymore. By @daxpedda in [#3691](https://github.com/gfx-rs/wgpu/pull/3691)

### Bug Fixes

- Fix order of arguments to glPolygonOffset by @komadori in [#3783](https://github.com/gfx-rs/wgpu/pull/3783).
- Fix OpenGL/EGL backend not respecting non-sRGB texture formats in `SurfaceConfiguration`. by @liquidev in [#3817](https://github.com/gfx-rs/wgpu/pull/3817)
- Make write- and read-only marked buffers match non-readonly layouts. by @fornwall in [#3893](https://github.com/gfx-rs/wgpu/pull/3893)

#### Metal

Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ async fn setup<E: Example>(title: &str) -> Setup {

(size, surface)
};
let adapter =
wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, Some(&surface))
.await
.expect("No suitable GPU adapters found on the system!");
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface))
.await
.expect("No suitable GPU adapters found on the system!");

#[cfg(not(target_arch = "wasm32"))]
{
Expand Down
1 change: 0 additions & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) {
let compatible_surface: Option<&Surface> = compatible_surface.as_ref();
let adapter = pollster::block_on(wgpu::util::initialize_adapter_from_env_or_default(
&instance,
backends,
compatible_surface,
))
.expect("could not find suitable adapter on the system");
Expand Down
8 changes: 7 additions & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ targets = [
[lib]

[features]
default = []
default = ["link"]

# Backends, passed through to wgpu-hal
metal = ["hal/metal"]
Expand All @@ -31,6 +31,9 @@ gles = ["hal/gles"]
dx11 = ["hal/dx11"]
dx12 = ["hal/dx12"]

# Use static linking for libraries. Disale to manually link. Enabled by default.
link = ["hal/link"]

# Support the Renderdoc graphics debugger:
# https://renderdoc.org/
renderdoc = ["hal/renderdoc"]
Expand All @@ -48,6 +51,8 @@ serial-pass = ["serde", "wgt/serde", "arrayvec/serde"]
id32 = []
# Enable `ShaderModuleSource::Wgsl`
wgsl = ["naga/wgsl-in"]
# Implement `Send` and `Sync` on Wasm.
fragile-send-sync-non-atomic-wasm = ["hal/fragile-send-sync-non-atomic-wasm", "wgt/fragile-send-sync-non-atomic-wasm"]

[dependencies]
arrayvec = "0.7"
Expand Down Expand Up @@ -80,6 +85,7 @@ version = "0.16"
package = "wgpu-hal"
path = "../wgpu-hal"
version = "0.16"
default_features = false

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
web-sys = { version = "0.3.60", features = ["HtmlCanvasElement", "OffscreenCanvas"] }
14 changes: 14 additions & 0 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,21 @@ pub struct RenderBundle<A: HalApi> {
pub(crate) info: ResourceInfo<RenderBundleId>,
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Send for RenderBundle<A> {}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Sync for RenderBundle<A> {}

impl<A: HalApi> RenderBundle<A> {
Expand Down
34 changes: 27 additions & 7 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ pub struct SubmittedWorkDoneClosureC {
pub user_data: *mut u8,
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for SubmittedWorkDoneClosureC {}

pub struct SubmittedWorkDoneClosure {
Expand All @@ -52,17 +59,30 @@ pub struct SubmittedWorkDoneClosure {
inner: SubmittedWorkDoneClosureInner,
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
type SubmittedWorkDoneCallback = Box<dyn FnOnce() + Send + 'static>;
#[cfg(not(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
type SubmittedWorkDoneCallback = Box<dyn FnOnce() + 'static>;

enum SubmittedWorkDoneClosureInner {
Rust {
callback: Box<dyn FnOnce() + Send + 'static>,
},
C {
inner: SubmittedWorkDoneClosureC,
},
Rust { callback: SubmittedWorkDoneCallback },
C { inner: SubmittedWorkDoneClosureC },
}

impl SubmittedWorkDoneClosure {
pub fn from_rust(callback: Box<dyn FnOnce() + Send + 'static>) -> Self {
pub fn from_rust(callback: SubmittedWorkDoneCallback) -> Self {
Self {
inner: SubmittedWorkDoneClosureInner::Rust { callback },
}
Expand Down
15 changes: 15 additions & 0 deletions wgpu-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,22 @@ pub fn format_pretty_any(
#[derive(Debug)]
pub struct ContextError {
pub string: &'static str,
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
pub cause: Box<dyn Error + Send + Sync + 'static>,
#[cfg(not(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
pub cause: Box<dyn Error + 'static>,
pub label_key: &'static str,
pub label: String,
}
Expand Down
11 changes: 10 additions & 1 deletion wgpu-core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
}
}

#[cfg(test)]
#[cfg(all(
test,
any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)
))]
fn _test_send_sync(global: &Global<crate::identity::IdentityManagerFactory>) {
fn test_internal<T: Send + Sync>(_: T) {}
test_internal(global)
Expand Down
52 changes: 43 additions & 9 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,36 @@ pub(crate) enum BufferMapState<A: HalApi> {
Idle,
}

unsafe impl<A: HalApi> Send for BufferMapState<A> {}
unsafe impl<A: HalApi> Sync for BufferMapState<A> {}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: hal::Api> Send for BufferMapState<A> {}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: hal::Api> Sync for BufferMapState<A> {}

#[repr(C)]
pub struct BufferMapCallbackC {
pub callback: unsafe extern "C" fn(status: BufferMapAsyncStatus, user_data: *mut u8),
pub user_data: *mut u8,
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for BufferMapCallbackC {}

#[derive(Debug)]
Expand All @@ -200,13 +221,26 @@ pub struct BufferMapCallback {
inner: Option<BufferMapCallbackInner>,
}

#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + Send + 'static>;
#[cfg(not(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + 'static>;

enum BufferMapCallbackInner {
Rust {
callback: Box<dyn FnOnce(BufferAccessResult) + Send + 'static>,
},
C {
inner: BufferMapCallbackC,
},
Rust { callback: BufferMapCallbackCallback },
C { inner: BufferMapCallbackC },
}

impl Debug for BufferMapCallbackInner {
Expand All @@ -219,7 +253,7 @@ impl Debug for BufferMapCallbackInner {
}

impl BufferMapCallback {
pub fn from_rust(callback: Box<dyn FnOnce(BufferAccessResult) + Send + 'static>) -> Self {
pub fn from_rust(callback: BufferMapCallbackCallback) -> Self {
Self {
inner: Some(BufferMapCallbackInner::Rust { callback }),
}
Expand Down
71 changes: 70 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl Resource {
)
}
};
if self.class != class {
if !address_space_matches(self.class, class) {
return Err(BindingError::WrongAddressSpace {
binding: class,
shader: self.class,
Expand Down Expand Up @@ -1237,3 +1237,72 @@ impl Interface {
Ok(outputs)
}
}

fn address_space_matches(shader: naga::AddressSpace, binding: naga::AddressSpace) -> bool {
match (shader, binding) {
(
naga::AddressSpace::Storage {
access: access_shader,
},
naga::AddressSpace::Storage {
access: access_pipeline,
},
) => {
// Allow read- and write-only usages to match read-write layouts:
(access_shader & access_pipeline) == access_shader
}
(a, b) => a == b,
}
}

#[cfg(test)]
mod test {
use super::address_space_matches;

#[test]
fn address_space_matches_correctly() {
assert!(address_space_matches(
naga::AddressSpace::Uniform,
naga::AddressSpace::Uniform
));

assert!(!address_space_matches(
naga::AddressSpace::Uniform,
naga::AddressSpace::Storage {
access: naga::StorageAccess::LOAD
}
));

let test_cases = [
(naga::StorageAccess::LOAD, naga::StorageAccess::LOAD, true),
(naga::StorageAccess::STORE, naga::StorageAccess::LOAD, false),
(naga::StorageAccess::LOAD, naga::StorageAccess::STORE, false),
(naga::StorageAccess::STORE, naga::StorageAccess::STORE, true),
(
naga::StorageAccess::LOAD | naga::StorageAccess::STORE,
naga::StorageAccess::LOAD | naga::StorageAccess::STORE,
true,
),
(
naga::StorageAccess::STORE,
naga::StorageAccess::LOAD | naga::StorageAccess::STORE,
true,
),
(
naga::StorageAccess::LOAD,
naga::StorageAccess::LOAD | naga::StorageAccess::STORE,
true,
),
];

for (shader, binding, expect_match) in test_cases {
assert_eq!(
expect_match,
address_space_matches(
naga::AddressSpace::Storage { access: shader },
naga::AddressSpace::Storage { access: binding }
)
);
}
}
}
Loading

0 comments on commit 91d872e

Please sign in to comment.