Skip to content

Commit

Permalink
Update to wgpu 0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed May 7, 2024
1 parent 5e866c2 commit 623238a
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 404 deletions.
589 changes: 321 additions & 268 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[workspace]
resolver = "2"
members = ["simuverse", "run-wasm"]
default-members = ["simuverse"]
default-members = ["simuverse"]

[profile.wasm-release]
# Use release profile as default values
inherits = "release"
# Optimize with size in mind, also try "s", sometimes it is better.
# This doesn't increase compilation times compared to -O3, great improvements
opt-level = "z"
# Do a second optimization pass removing duplicate or unused code from dependencies.
# Slows compile times, marginal improvements
lto = "fat"
# When building crates, optimize larger chunks at a time
# Slows compile times, marginal improvements
codegen-units = 1
4 changes: 4 additions & 0 deletions build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ for i in target/wasm32-unknown-unknown/release/*.wasm;
do
wasm-bindgen --no-typescript --out-dir wasm --web "$i";
done

# 优化 wasm 包大小
# 2024/5/5, 4.6MB -> 3.2MB
wasm-opt -Oz --output wasm/optimized.wasm wasm/simuverse_bg.wasm
154 changes: 21 additions & 133 deletions simuverse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ edition = "2021"
rust-version = "1.76"

[dependencies]
app-surface = { version = "0.4.1" }
app-surface = { version = "0.4.2" }
# app-surface = { path = "../../idroid/wgpu-in-app/app-surface" }
egui = { git = "https://github.com/emilk/egui", rev = "5d0bc2b", default-features = false }
egui_extras = { git = "https://github.com/emilk/egui", package = "egui_extras", rev = "5d0bc2b" }
egui-wgpu = { git = "https://github.com/emilk/egui", package = "egui-wgpu", rev = "5d0bc2b" }
egui-winit = { git = "https://github.com/emilk/egui", package = "egui-winit", rev = "5d0bc2b", default-features = false }
egui = { git = "https://github.com/emilk/egui", rev = "ded8dbd", default-features = false }
egui_extras = { git = "https://github.com/emilk/egui", package = "egui_extras", rev = "ded8dbd" }
egui-wgpu = { git = "https://github.com/emilk/egui", package = "egui-wgpu", rev = "ded8dbd" }
egui-winit = { git = "https://github.com/emilk/egui", package = "egui-winit", rev = "ded8dbd", default-features = false }

webbrowser = { version = "0.8.3" }
webbrowser = { version = "1.0.1" }
# 需要 egui 先升级到 winit 0.30 后才能使用
winit = { version = "0.29.10" }
raw-window-handle = "0.6"
wgpu = "0.19.3"
# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "7c25c00f" }
# wgpu = { path = "../../forks/wgpu/wgpu" }

glam = "0.25"
wgpu = "0.20"
glam = "0.27"
# syntax_highlighting 需要 enum-map
enum-map = { version = "2", features = ["serde"] }
bytemuck = "1.14"
bytemuck = "1.15"
env_logger = "0.10"
log = "0.4"
rand = "0.8"
Expand All @@ -48,134 +46,24 @@ console_error_panic_hook = "0.1.7"
console_log = "1.0"
js-sys = "0.3.67"
reqwest = "0.11.15"
wasm-bindgen = "0.2.90"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.40"
web-sys = { version = "0.3.67", features = [
"Blob",
"Document",
"Navigator",
'Element',
'HtmlElement',
"Node",
"NodeList",
"Gpu",
"GpuAdapter",
"GpuAddressMode",
"GpuAutoLayoutMode",
"GpuBindGroup",
"GpuBindGroupDescriptor",
"GpuBindGroupEntry",
"GpuBindGroupLayout",
"GpuBindGroupLayoutDescriptor",
"GpuBindGroupLayoutEntry",
"GpuBlendComponent",
"GpuBlendFactor",
"GpuBlendOperation",
"GpuBlendState",
"GpuBuffer",
"GpuBufferBinding",
"GpuBufferBindingLayout",
"GpuBufferBindingType",
"GpuBufferDescriptor",
"GpuCanvasAlphaMode",
"GpuCanvasContext",
"GpuCanvasConfiguration",
"GpuColorDict",
"GpuColorTargetState",
"GpuCommandBuffer",
"GpuCommandBufferDescriptor",
"GpuCommandEncoder",
"GpuCommandEncoderDescriptor",
"GpuCompareFunction",
"GpuCompilationInfo",
"GpuCompilationMessage",
"GpuCompilationMessageType",
"GpuComputePassDescriptor",
"GpuComputePassEncoder",
"GpuComputePipeline",
"GpuComputePipelineDescriptor",
"GpuCullMode",
"GpuDepthStencilState",
"GpuDevice",
"GpuDeviceDescriptor",
"GpuDeviceLostInfo",
"GpuDeviceLostReason",
"GpuError",
"GpuErrorFilter",
"GpuExtent3dDict",
"GpuFeatureName",
"GpuFilterMode",
"GpuFragmentState",
"GpuFrontFace",
"GpuImageCopyBuffer",
"GpuImageCopyExternalImage",
"GpuImageCopyTexture",
"GpuImageCopyTextureTagged",
"GpuImageDataLayout",
"GpuIndexFormat",
"GpuLoadOp",
"gpu_map_mode",
"GpuMipmapFilterMode",
"GpuMultisampleState",
"GpuObjectDescriptorBase",
"GpuOrigin2dDict",
"GpuOrigin3dDict",
"GpuOutOfMemoryError",
"GpuPipelineDescriptorBase",
"GpuPipelineLayout",
"GpuPipelineLayoutDescriptor",
"GpuPowerPreference",
"GpuPrimitiveState",
"GpuPrimitiveTopology",
"GpuProgrammableStage",
"GpuQuerySet",
"GpuQuerySetDescriptor",
"GpuQueryType",
"GpuQueue",
"GpuRenderBundle",
"GpuRenderBundleDescriptor",
"GpuRenderBundleEncoder",
"GpuRenderBundleEncoderDescriptor",
"GpuRenderPassColorAttachment",
"GpuRenderPassDepthStencilAttachment",
"GpuRenderPassDescriptor",
"GpuRenderPassEncoder",
"GpuRenderPipeline",
"GpuRenderPipelineDescriptor",
"GpuRequestAdapterOptions",
"GpuSampler",
"GpuSamplerBindingLayout",
"GpuSamplerBindingType",
"GpuSamplerDescriptor",
"GpuShaderModule",
"GpuShaderModuleDescriptor",
"GpuStencilFaceState",
"GpuStencilOperation",
"GpuStorageTextureAccess",
"GpuStorageTextureBindingLayout",
"GpuStoreOp",
"GpuSupportedFeatures",
"GpuSupportedLimits",
"GpuTexture",
"GpuTextureAspect",
"GpuTextureBindingLayout",
"GpuTextureDescriptor",
"GpuTextureDimension",
"GpuTextureFormat",
"GpuTextureSampleType",
"GpuTextureView",
"GpuTextureViewDescriptor",
"GpuTextureViewDimension",
"GpuUncapturedErrorEvent",
"GpuUncapturedErrorEventInit",
"GpuValidationError",
"GpuVertexAttribute",
"GpuVertexBufferLayout",
"GpuVertexFormat",
"GpuVertexState",
"GpuVertexStepMode",
"HtmlCanvasElement",
"Response",
"OffscreenCanvas",
"ImageBitmap",
"ImageBitmapRenderingContext",
"Url",
"Window",
"WorkerGlobalScope",
"XmlHttpRequest",
"XmlHttpRequestResponseType",
] }
# Needed by webgpu_sys
"Event",
"EventTarget",
] }
2 changes: 1 addition & 1 deletion simuverse/src/egui_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl EguiLayer {
});
let clipped_primitives = self.ctx.tessellate(full_output.shapes, app.scale_factor);
let textures_delta = full_output.textures_delta;
let screen_descriptor = egui_wgpu::renderer::ScreenDescriptor {
let screen_descriptor = egui_wgpu::ScreenDescriptor {
size_in_pixels: [app.config.width, app.config.height],
pixels_per_point: app.scale_factor,
};
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/fluid/d2q9_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ impl D2Q9Node {
layout: Some(&pipeline_layout),
module: &collide_stream_shader,
entry_point: "cs_main",
compilation_options: Default::default(),
});
let boundary_pipeline =
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: Some("boundary_pipeline pipeline"),
layout: Some(&pipeline_layout),
module: &boundary_shader,
entry_point: "cs_main",
compilation_options: Default::default(),
});
setting_nodes.push(setting_node);
collide_stream_pipelines.push(collide_stream_pipeline);
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/fluid/particle_render_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ fn generate_pipeline(
module: shader,
entry_point: entry_points.0,
buffers: &buffers,
compilation_options: Default::default(),
},
fragment: Some(wgpu::FragmentState {
module: shader,
entry_point: entry_points.1,
targets: &targets,
compilation_options: Default::default(),
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/node/bufferless_fullscreen_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl BufferlessFullscreenNode {
module: shader_module,
entry_point: "vs_main",
buffers: &pipeline_vertex_buffers,
compilation_options: Default::default(),
},
fragment: Some(wgpu::FragmentState {
module: shader_module,
Expand All @@ -41,6 +42,7 @@ impl BufferlessFullscreenNode {
blend: blend_state,
write_mask: wgpu::ColorWrites::ALL,
})],
compilation_options: Default::default(),
}),
// the bufferless vertices are in clock-wise order
primitive: wgpu::PrimitiveState {
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/node/compute_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl ComputeNode {
layout: Some(&pipeline_layout),
module: shader_module,
entry_point: "cs_main",
compilation_options: Default::default(),
});

ComputeNode {
Expand Down Expand Up @@ -105,6 +106,7 @@ impl ComputeNode {
layout: Some(&pipeline_layout),
module: shader_module,
entry_point: "cs_main",
compilation_options: Default::default(),
});

ComputeNode {
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/node/view_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl ViewNode {
module: attributes.shader_module,
entry_point: "vs_main",
buffers: &vertex_buffer_layouts,
compilation_options: Default::default(),
},
fragment: Some(wgpu::FragmentState {
module: attributes.shader_module,
Expand All @@ -226,6 +227,7 @@ impl ViewNode {
blend: attributes.color_blend_state,
write_mask: wgpu::ColorWrites::ALL,
})],
compilation_options: Default::default(),
}),
primitive: wgpu::PrimitiveState {
topology: attributes.primitive_topology,
Expand Down
2 changes: 1 addition & 1 deletion simuverse/src/setting/control_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ControlPanel {
.resizable(false)
.collapsible(true)
.title_bar(true)
.scroll2([false, true])
.scroll([false, true])
.movable(false)
.fixed_size(self.window_size)
.frame(self.panel_frame)
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/truck/rendimpl/polygon_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl Rendered for PolygonInstance {
},
],
}],
compilation_options: Default::default(),
},
fragment: Some(FragmentState {
module: fragment_module,
Expand All @@ -159,6 +160,7 @@ impl Rendered for PolygonInstance {
blend,
write_mask: ColorWrites::ALL,
})],
compilation_options: Default::default(),
}),
primitive: PrimitiveState {
topology: PrimitiveTopology::TriangleList,
Expand Down
2 changes: 2 additions & 0 deletions simuverse/src/truck/rendimpl/wireframe_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl Rendered for WireFrameInstance {
shader_location: 0,
}],
}],
compilation_options: Default::default(),
},
fragment: Some(FragmentState {
module: &self.shaders.fragment_module,
Expand All @@ -114,6 +115,7 @@ impl Rendered for WireFrameInstance {
blend: Some(BlendState::REPLACE),
write_mask: ColorWrites::ALL,
})],
compilation_options: Default::default(),
}),
primitive: PrimitiveState {
topology: PrimitiveTopology::LineList,
Expand Down

0 comments on commit 623238a

Please sign in to comment.