Skip to content

Commit

Permalink
Bug 1772004: Update wgpu to 32af4f56 (2022-5-31) r=jgilbert
Browse files Browse the repository at this point in the history
Minor changes are needed to the `mapAsync` implementation due to:
gfx-rs/wgpu#2698

Differential Revision: https://phabricator.services.mozilla.com/D147805
  • Loading branch information
jimblandy committed Jun 5, 2022
1 parent 5eb93f9 commit fcf498e
Show file tree
Hide file tree
Showing 102 changed files with 6,485 additions and 2,775 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ rev = "3484d3e3ebdc8931493aa5df4d7ee9360a90e76b"
[source."https://github.com/gfx-rs/wgpu"]
git = "https://github.com/gfx-rs/wgpu"
replace-with = "vendored-sources"
rev = "b51fd851"
rev = "32af4f56"

[source."https://github.com/gfx-rs/naga"]
git = "https://github.com/gfx-rs/naga"
replace-with = "vendored-sources"
rev = "1aa91549"
rev = "571302e"

[source."https://github.com/gfx-rs/metal-rs"]
git = "https://github.com/gfx-rs/metal-rs"
Expand Down
11 changes: 6 additions & 5 deletions Cargo.lock

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

15 changes: 7 additions & 8 deletions dom/webgpu/ipc/WebGPUParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ ipc::IPCResult WebGPUParent::RecvBufferMap(RawId aSelfId,

auto* request = new MapRequest(mContext.get(), aSelfId, aHostMap, aOffset,
std::move(shmem), std::move(aResolver));
ffi::WGPUBufferMapOperation mapOperation = {
aHostMap, &MapCallback, reinterpret_cast<uint8_t*>(request)};
ffi::wgpu_server_buffer_map(mContext.get(), aSelfId, aOffset, aSize,
mapOperation);
ffi::WGPUBufferMapCallbackC callback = {&MapCallback,
reinterpret_cast<uint8_t*>(request)};
ffi::wgpu_server_buffer_map(mContext.get(), aSelfId, aOffset, aSize, aHostMap,
callback);
return IPC_OK();
}

Expand Down Expand Up @@ -823,11 +823,10 @@ ipc::IPCResult WebGPUParent::RecvSwapChainPresent(
data,
};

ffi::WGPUBufferMapOperation mapOperation = {
ffi::WGPUHostMap_Read, &PresentCallback,
reinterpret_cast<uint8_t*>(presentRequest)};
ffi::WGPUBufferMapCallbackC callback = {
&PresentCallback, reinterpret_cast<uint8_t*>(presentRequest)};
ffi::wgpu_server_buffer_map(mContext.get(), bufferId, 0, bufferSize,
mapOperation);
ffi::WGPUHostMap_Read, callback);

return IPC_OK();
}
Expand Down
6 changes: 3 additions & 3 deletions gfx/wgpu_bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ default = []
[dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "b51fd851"
rev = "32af4f56"
#Note: "replay" shouldn't ideally be needed,
# but it allows us to serialize everything across IPC.
features = ["replay", "trace", "serial-pass"]

[dependencies.wgt]
package = "wgpu-types"
git = "https://github.com/gfx-rs/wgpu"
rev = "b51fd851"
rev = "32af4f56"

[dependencies.wgh]
package = "wgpu-hal"
git = "https://github.com/gfx-rs/wgpu"
rev = "b51fd851"
rev = "32af4f56"

[dependencies]
bincode = "1"
Expand Down
4 changes: 2 additions & 2 deletions gfx/wgpu_bindings/moz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ origin:

# Human-readable identifier for this version/release
# Generally "version NNN", "tag SSS", "bookmark SSS"
release: commit 0b61a191
release: commit 32af4f56

# Revision to pull in
# Must be a long or short commit SHA (long preferred)
revision: 0b61a191
revision: 32af4f56

license: ['MIT', 'Apache-2.0']

Expand Down
13 changes: 11 additions & 2 deletions gfx/wgpu_bindings/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,23 @@ pub extern "C" fn wgpu_server_device_create_buffer(
}
}

/// # Safety
///
/// Callers are responsible for ensuring `callback` is well-formed.
#[no_mangle]
pub extern "C" fn wgpu_server_buffer_map(
pub unsafe extern "C" fn wgpu_server_buffer_map(
global: &Global,
buffer_id: id::BufferId,
start: wgt::BufferAddress,
size: wgt::BufferAddress,
operation: wgc::resource::BufferMapOperation,
map_mode: wgc::device::HostMap,
callback: wgc::resource::BufferMapCallbackC,
) {
let callback = wgc::resource::BufferMapCallback::from_c(callback);
let operation = wgc::resource::BufferMapOperation {
host: map_mode,
callback
};
gfx_select!(buffer_id => global.buffer_map_async(
buffer_id,
start .. start + size,
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/naga/.cargo-checksum.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions third_party/rust/naga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ serde = { version = "1.0.103", features = ["derive"], optional = true }
petgraph = { version ="0.6", optional = true }
pp-rs = { version = "0.2.1", optional = true }
hexf-parse = { version = "0.2.1", optional = true }
# update unicode-xid to the next version since it has been updated to unicode v14
# (but has no release that includes it yet)
# https://github.com/unicode-rs/unicode-xid/pull/27
unicode-xid = { version = "0.2.2", optional = true }
unicode-xid = { version = "0.2.3", optional = true }

[dev-dependencies]
bincode = "1"
Expand Down
33 changes: 25 additions & 8 deletions third_party/rust/naga/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
![MSRV](https://img.shields.io/badge/rustc-1.56+-blue.svg)
[![codecov.io](https://codecov.io/gh/gfx-rs/naga/branch/master/graph/badge.svg?token=9VOKYO8BM2)](https://codecov.io/gh/gfx-rs/naga)

The shader translation library for the needs of [wgpu](https://github.com/gfx-rs/wgpu) and [gfx-rs](https://github.com/gfx-rs/gfx) projects.
The shader translation library for the needs of [wgpu](https://github.com/gfx-rs/wgpu).

## Supported end-points

Everything is still work-in-progress, but some end-points are usable:

Front-end | Status | Feature | Notes |
--------------- | ------------------ | ------- | ----- |
SPIR-V (binary) | :white_check_mark: | spv-in | |
Expand All @@ -35,12 +33,31 @@ DOT (GraphViz) | :ok: | dot-out | Not a shading language |

## Conversion tool

Naga includes a default binary target, which allows to test the conversion of different code paths.
Naga can be used as a CLI, which allows to test the conversion of different code paths.

First, install `naga-cli` from crates.io or directly from GitHub.

```bash
# release version
cargo install naga-cli

# development version
cargo install naga-cli --git https://github.com/gfx-rs/naga.git
```

Then, you can run `naga` command.

```bash
naga my_shader.wgsl # validate only
naga my_shader.spv my_shader.txt # dump the IR module into a file
naga my_shader.spv my_shader.metal --flow-dir flow-dir # convert the SPV to Metal, also dump the SPIR-V flow graph to `flow-dir`
naga my_shader.wgsl my_shader.vert --profile es310 # convert the WGSL to GLSL vertex stage under ES 3.20 profile
```

As naga includes a default binary target, you can also use `cargo run` without installation. This is useful when you develop naga itself, or investigate the behavior of naga at a specific commit (e.g. [wgpu](https://github.com/gfx-rs/wgpu) might pin a different version of naga than the `HEAD` of this repository).

```bash
cargo run my_shader.wgsl # validate only
cargo run my_shader.spv my_shader.txt # dump the IR module into a file
cargo run my_shader.spv my_shader.metal --flow-dir flow-dir # convert the SPV to Metal, also dump the SPIR-V flow graph to `flow-dir`
cargo run my_shader.wgsl my_shader.vert --profile es310 # convert the WGSL to GLSL vertex stage under ES 3.20 profile
cargo run my_shader.wgsl
```

## Development workflow
Expand Down
4 changes: 2 additions & 2 deletions third_party/rust/naga/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<T> hash::Hash for Handle<T> {
impl<T> Handle<T> {
#[cfg(test)]
pub const DUMMY: Self = Handle {
index: unsafe { NonZeroU32::new_unchecked(!0) },
index: unsafe { NonZeroU32::new_unchecked(u32::MAX) },
marker: PhantomData,
};

Expand All @@ -101,7 +101,7 @@ impl<T> Handle<T> {
let handle_index = u32::try_from(index + 1)
.ok()
.and_then(Index::new)
.expect("Failed to insert into UniqueArena. Handle overflows");
.expect("Failed to insert into arena. Handle overflows");
Handle::new(handle_index)
}

Expand Down
55 changes: 35 additions & 20 deletions third_party/rust/naga/src/back/glsl/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bitflags::bitflags! {
const MULTI_VIEW = 1 << 17;
/// Fused multiply-add.
const FMA = 1 << 18;
/// Texture samples query
const TEXTURE_SAMPLES = 1 << 19;
}
}

Expand Down Expand Up @@ -101,7 +103,10 @@ impl FeaturesManager {
check_feature!(SAMPLE_VARIABLES, 400, 300);
check_feature!(DYNAMIC_ARRAY_SIZE, 430, 310);
check_feature!(MULTI_VIEW, 140, 310);
check_feature!(FMA, 400, 310);
// Only available on glsl core, this means that opengl es can't query the number
// of samples in a image and neither do bound checks on the sample argument
// of texelFecth
check_feature!(TEXTURE_SAMPLES, 150);

// Return an error if there are missing features
if missing.is_empty() {
Expand Down Expand Up @@ -205,11 +210,19 @@ impl FeaturesManager {
writeln!(out, "#extension GL_EXT_multiview : require")?;
}

if self.0.contains(Features::FMA) && version.is_es() {
if self.0.contains(Features::FMA) && version >= Version::Embedded(310) {
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_gpu_shader5.txt
writeln!(out, "#extension GL_EXT_gpu_shader5 : require")?;
}

if self.0.contains(Features::TEXTURE_SAMPLES) {
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_texture_image_samples.txt
writeln!(
out,
"#extension GL_ARB_shader_texture_image_samples : require"
)?;
}

Ok(())
}
}
Expand Down Expand Up @@ -363,24 +376,26 @@ impl<'a, W> Writer<'a, W> {
}
}

if self.options.version.supports_fma_function() {
let has_fma = self
.module
.functions
.iter()
.flat_map(|(_, f)| f.expressions.iter())
.chain(
self.module
.entry_points
.iter()
.flat_map(|e| e.function.expressions.iter()),
)
.any(|(_, e)| match *e {
Expression::Math { fun, .. } if fun == MathFunction::Fma => true,
_ => false,
});
if has_fma {
self.features.request(Features::FMA);
// Loop trough all expressions in both functions and entry points
// to check for needed features
for (_, expr) in self
.module
.functions
.iter()
.flat_map(|(_, f)| f.expressions.iter())
.chain(self.entry_point.function.expressions.iter())
{
match *expr {
// Check for fused multiply add use
Expression::Math { fun, .. } if fun == MathFunction::Fma => {
self.features.request(Features::FMA)
}
// Check for samples query
Expression::ImageQuery {
query: crate::ImageQuery::NumSamples,
..
} => self.features.request(Features::TEXTURE_SAMPLES),
_ => {}
}
}

Expand Down
Loading

0 comments on commit fcf498e

Please sign in to comment.