mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Update web-sys 0.3.51 to 0.3.53 (#1844)
* Update web-sys to work with newer ff nightly
* Update wgpu for web-sys 0.3.53
* Implement get_current_texture for web backend
* Set access for GpuStorageTextureBindingLayout
* Move inline mapping to use existing mapping fn
* Implement SPV to WGSL Conversion
Error handling is not completed yet.
* Update spv to wgsl conversion to match existing
Move to using spv::Parser struct
Remove need for unsafe block
Copied from f3c9f412f6/wgpu/src/backend/direct.rs (L971-L978)
* Add spirv-web feature
For spir-v --> wgsl conversion in the web backend
* Update README to include spirv-web
This commit is contained in:
28
Cargo.lock
generated
28
Cargo.lock
generated
@@ -801,9 +801,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.51"
|
||||
version = "0.3.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062"
|
||||
checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
@@ -1623,9 +1623,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
|
||||
checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"wasm-bindgen-macro",
|
||||
@@ -1633,9 +1633,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
|
||||
checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
@@ -1660,9 +1660,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
|
||||
checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1670,9 +1670,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
|
||||
checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1683,9 +1683,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.74"
|
||||
version = "0.2.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
|
||||
checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29"
|
||||
|
||||
[[package]]
|
||||
name = "wayland-client"
|
||||
@@ -1762,9 +1762,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.51"
|
||||
version = "0.3.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582"
|
||||
checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
|
||||
@@ -33,6 +33,7 @@ path = "tests/root.rs"
|
||||
[features]
|
||||
default = []
|
||||
spirv = ["naga/spv-in"]
|
||||
spirv-web = ["spirv", "naga/wgsl-out"]
|
||||
trace = ["serde", "wgc/trace"]
|
||||
replay = ["serde", "wgc/replay"]
|
||||
webgl = ["wgc"]
|
||||
@@ -146,16 +147,14 @@ name="water"
|
||||
test = true
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wasm-bindgen = "0.2.73" # remember to change version in wiki as well
|
||||
web-sys = { version = "=0.3.51", features = [
|
||||
wasm-bindgen = "0.2.76" # remember to change version in wiki as well
|
||||
web-sys = { version = "0.3.53", features = [
|
||||
"Document",
|
||||
"Navigator",
|
||||
"Node",
|
||||
"NodeList",
|
||||
"Gpu",
|
||||
"GpuAdapter",
|
||||
"GpuAdapterFeatures",
|
||||
"GpuAdapterLimits",
|
||||
"GpuAddressMode",
|
||||
"GpuBindGroup",
|
||||
"GpuBindGroupDescriptor",
|
||||
@@ -174,6 +173,7 @@ web-sys = { version = "=0.3.51", features = [
|
||||
"GpuBufferDescriptor",
|
||||
"GpuBufferUsage",
|
||||
"GpuCanvasContext",
|
||||
"GpuCanvasConfiguration",
|
||||
"GpuColorDict",
|
||||
"GpuColorTargetState",
|
||||
"GpuColorWrite",
|
||||
@@ -202,11 +202,9 @@ web-sys = { version = "=0.3.51", features = [
|
||||
"GpuFragmentState",
|
||||
"GpuFrontFace",
|
||||
"GpuImageCopyBuffer",
|
||||
"GpuImageCopyImageBitmap",
|
||||
"GpuImageCopyTexture",
|
||||
"GpuImageDataLayout",
|
||||
"GpuIndexFormat",
|
||||
"GpuInputStepMode",
|
||||
"GpuLoadOp",
|
||||
"GpuMapMode",
|
||||
"GpuMultisampleState",
|
||||
@@ -249,8 +247,8 @@ web-sys = { version = "=0.3.51", features = [
|
||||
"GpuStorageTextureAccess",
|
||||
"GpuStorageTextureBindingLayout",
|
||||
"GpuStoreOp",
|
||||
"GpuSwapChain",
|
||||
"GpuSwapChainDescriptor",
|
||||
"GpuSupportedFeatures",
|
||||
"GpuSupportedLimits",
|
||||
"GpuTexture",
|
||||
"GpuTextureAspect",
|
||||
"GpuTextureBindingLayout",
|
||||
@@ -269,6 +267,7 @@ web-sys = { version = "=0.3.51", features = [
|
||||
"GpuVertexBufferLayout",
|
||||
"GpuVertexFormat",
|
||||
"GpuVertexState",
|
||||
"GpuVertexStepMode",
|
||||
"HtmlCanvasElement",
|
||||
"Window",
|
||||
]}
|
||||
|
||||
@@ -56,4 +56,4 @@ Users can run the [naga](https://github.com/gfx-rs/naga) binary in the following
|
||||
cargo run -- <input.spv> <output.wgsl>
|
||||
```
|
||||
|
||||
In addition, SPIR-V can be used by enabling the `spirv` feature, and the cost of slightly increased build times.
|
||||
In addition, SPIR-V can be used by enabling the `spirv` feature, or the `spirv-web` feature for wasm targets, at the cost of slightly increased build times.
|
||||
|
||||
@@ -398,7 +398,7 @@ impl crate::RenderInner<Context> for RenderBundleEncoder {
|
||||
impl crate::RenderPassInner<Context> for RenderPass {
|
||||
fn set_blend_constant(&mut self, color: wgt::Color) {
|
||||
self.0
|
||||
.set_blend_color_with_gpu_color_dict(&map_color(color));
|
||||
.set_blend_constant_with_gpu_color_dict(&map_color(color));
|
||||
}
|
||||
fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) {
|
||||
self.0.set_scissor_rect(x, y, width, height);
|
||||
@@ -676,17 +676,17 @@ fn map_blend_factor(factor: wgt::BlendFactor) -> web_sys::GpuBlendFactor {
|
||||
match factor {
|
||||
BlendFactor::Zero => bf::Zero,
|
||||
BlendFactor::One => bf::One,
|
||||
BlendFactor::Src => bf::SrcColor,
|
||||
BlendFactor::OneMinusSrc => bf::OneMinusSrcColor,
|
||||
BlendFactor::Src => bf::Src,
|
||||
BlendFactor::OneMinusSrc => bf::OneMinusSrc,
|
||||
BlendFactor::SrcAlpha => bf::SrcAlpha,
|
||||
BlendFactor::OneMinusSrcAlpha => bf::OneMinusSrcAlpha,
|
||||
BlendFactor::Dst => bf::DstColor,
|
||||
BlendFactor::OneMinusDst => bf::OneMinusDstColor,
|
||||
BlendFactor::Dst => bf::Dst,
|
||||
BlendFactor::OneMinusDst => bf::OneMinusDst,
|
||||
BlendFactor::DstAlpha => bf::DstAlpha,
|
||||
BlendFactor::OneMinusDstAlpha => bf::OneMinusDstAlpha,
|
||||
BlendFactor::SrcAlphaSaturated => bf::SrcAlphaSaturated,
|
||||
BlendFactor::Constant => bf::BlendColor,
|
||||
BlendFactor::OneMinusConstant => bf::OneMinusBlendColor,
|
||||
BlendFactor::Constant => bf::Constant,
|
||||
BlendFactor::OneMinusConstant => bf::OneMinusConstant,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,8 +754,8 @@ fn map_vertex_format(format: wgt::VertexFormat) -> web_sys::GpuVertexFormat {
|
||||
}
|
||||
}
|
||||
|
||||
fn map_input_step_mode(mode: wgt::VertexStepMode) -> web_sys::GpuInputStepMode {
|
||||
use web_sys::GpuInputStepMode as sm;
|
||||
fn map_vertex_step_mode(mode: wgt::VertexStepMode) -> web_sys::GpuVertexStepMode {
|
||||
use web_sys::GpuVertexStepMode as sm;
|
||||
use wgt::VertexStepMode;
|
||||
match mode {
|
||||
VertexStepMode::Vertex => sm::Vertex,
|
||||
@@ -851,7 +851,7 @@ fn map_store_op(store: bool) -> web_sys::GpuStoreOp {
|
||||
if store {
|
||||
web_sys::GpuStoreOp::Store
|
||||
} else {
|
||||
web_sys::GpuStoreOp::Clear
|
||||
web_sys::GpuStoreOp::Discard
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1019,7 +1019,7 @@ impl crate::Context for Context {
|
||||
),
|
||||
(wgt::Features::TIMESTAMP_QUERY, Gfn::TimestampQuery),
|
||||
];
|
||||
let non_guaranteed_features = possible_features
|
||||
let required_features = possible_features
|
||||
.iter()
|
||||
.copied()
|
||||
.flat_map(|(flag, value)| {
|
||||
@@ -1030,7 +1030,7 @@ impl crate::Context for Context {
|
||||
}
|
||||
})
|
||||
.collect::<js_sys::Array>();
|
||||
mapped_desc.non_guaranteed_features(&non_guaranteed_features);
|
||||
mapped_desc.required_features(&required_features);
|
||||
|
||||
if let Some(label) = desc.label {
|
||||
mapped_desc.label(label);
|
||||
@@ -1067,8 +1067,8 @@ impl crate::Context for Context {
|
||||
max_storage_buffers_per_shader_stage: limits.max_storage_buffers_per_shader_stage(),
|
||||
max_storage_textures_per_shader_stage: limits.max_storage_textures_per_shader_stage(),
|
||||
max_uniform_buffers_per_shader_stage: limits.max_uniform_buffers_per_shader_stage(),
|
||||
max_uniform_buffer_binding_size: limits.max_uniform_buffer_binding_size(),
|
||||
max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size(),
|
||||
max_uniform_buffer_binding_size: limits.max_uniform_buffer_binding_size() as u32,
|
||||
max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size() as u32,
|
||||
max_vertex_buffers: limits.max_vertex_buffers(),
|
||||
max_vertex_attributes: limits.max_vertex_attributes(),
|
||||
max_vertex_buffer_array_stride: limits.max_vertex_buffer_array_stride(),
|
||||
@@ -1108,8 +1108,7 @@ impl crate::Context for Context {
|
||||
surface: &Self::SurfaceId,
|
||||
adapter: &Self::AdapterId,
|
||||
) -> Option<wgt::TextureFormat> {
|
||||
let format =
|
||||
map_texture_format_from_web_sys(surface.0.get_swap_chain_preferred_format(&adapter.0));
|
||||
let format = map_texture_format_from_web_sys(surface.0.get_preferred_format(&adapter.0));
|
||||
Some(format)
|
||||
}
|
||||
|
||||
@@ -1120,21 +1119,21 @@ impl crate::Context for Context {
|
||||
config: &wgt::SurfaceConfiguration,
|
||||
) {
|
||||
let mut mapped =
|
||||
web_sys::GpuSwapChainDescriptor::new(&device.0, map_texture_format(config.format));
|
||||
web_sys::GpuCanvasConfiguration::new(&device.0, map_texture_format(config.format));
|
||||
mapped.usage(config.usage.bits());
|
||||
surface.0.configure_swap_chain(&mapped);
|
||||
surface.0.configure(&mapped);
|
||||
}
|
||||
|
||||
fn surface_get_current_texture(
|
||||
&self,
|
||||
_surface: &Self::SurfaceId,
|
||||
surface: &Self::SurfaceId,
|
||||
) -> (
|
||||
Option<Self::TextureId>,
|
||||
wgt::SurfaceStatus,
|
||||
Self::SurfaceOutputDetail,
|
||||
) {
|
||||
(
|
||||
None, //TODO: surface.0.get_current_texture(),
|
||||
Some(Sendable(surface.0.get_current_texture())),
|
||||
wgt::SurfaceStatus::Good,
|
||||
(),
|
||||
)
|
||||
@@ -1165,13 +1164,28 @@ impl crate::Context for Context {
|
||||
desc: &crate::ShaderModuleDescriptor,
|
||||
) -> Self::ShaderModuleId {
|
||||
let mut descriptor = match desc.source {
|
||||
#[cfg(feature = "spirv")]
|
||||
#[cfg(feature = "spirv-web")]
|
||||
crate::ShaderSource::SpirV(ref spv) => {
|
||||
web_sys::GpuShaderModuleDescriptor::new(&js_sys::Uint32Array::from(&**spv))
|
||||
}
|
||||
crate::ShaderSource::Wgsl(ref code) => {
|
||||
web_sys::GpuShaderModuleDescriptor::new(&js_sys::JsString::from(&**code))
|
||||
use naga::{back, front, valid};
|
||||
|
||||
let options = naga::front::spv::Options {
|
||||
adjust_coordinate_space: false,
|
||||
strict_capabilities: true,
|
||||
flow_graph_dump_prefix: None,
|
||||
};
|
||||
let spv_parser = front::spv::Parser::new(spv.iter().cloned(), &options);
|
||||
let spv_module = spv_parser.parse().unwrap();
|
||||
|
||||
let mut validator = valid::Validator::new(
|
||||
valid::ValidationFlags::all(),
|
||||
valid::Capabilities::all(),
|
||||
);
|
||||
let spv_module_info = validator.validate(&spv_module).unwrap();
|
||||
|
||||
let wgsl_text = back::wgsl::write_string(&spv_module, &spv_module_info).unwrap();
|
||||
web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str())
|
||||
}
|
||||
crate::ShaderSource::Wgsl(ref code) => web_sys::GpuShaderModuleDescriptor::new(code),
|
||||
};
|
||||
if let Some(label) = desc.label {
|
||||
descriptor.label(label);
|
||||
@@ -1255,9 +1269,9 @@ impl crate::Context for Context {
|
||||
}
|
||||
};
|
||||
let mut storage_texture = web_sys::GpuStorageTextureBindingLayout::new(
|
||||
mapped_access,
|
||||
map_texture_format(format),
|
||||
);
|
||||
storage_texture.access(mapped_access);
|
||||
storage_texture.view_dimension(map_texture_view_dimension(view_dimension));
|
||||
mapped_entry.storage_texture(&storage_texture);
|
||||
}
|
||||
@@ -1375,7 +1389,7 @@ impl crate::Context for Context {
|
||||
vbuf.array_stride as f64,
|
||||
&mapped_attributes,
|
||||
);
|
||||
mapped_vbuf.step_mode(map_input_step_mode(vbuf.step_mode));
|
||||
mapped_vbuf.step_mode(map_vertex_step_mode(vbuf.step_mode));
|
||||
mapped_vbuf
|
||||
})
|
||||
.collect::<js_sys::Array>();
|
||||
@@ -1811,8 +1825,11 @@ impl crate::Context for Context {
|
||||
crate::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
};
|
||||
|
||||
let mut mapped_color_attachment =
|
||||
web_sys::GpuRenderPassColorAttachment::new(&load_value, &ca.view.id.0);
|
||||
let mut mapped_color_attachment = web_sys::GpuRenderPassColorAttachment::new(
|
||||
&load_value,
|
||||
map_store_op(ca.ops.store),
|
||||
&ca.view.id.0,
|
||||
);
|
||||
|
||||
if let Some(rt) = ca.resolve_target {
|
||||
mapped_color_attachment.resolve_target(&rt.id.0);
|
||||
|
||||
Reference in New Issue
Block a user