Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library upgrades and updates #940

Merged
merged 29 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9b83605
Convert to Tokio.
tychedelia Oct 7, 2023
3c7c832
Bump wgpu.
tychedelia Oct 8, 2023
67c531f
https://github.com/gfx-rs/wgpu/pull/2698.
tychedelia Oct 8, 2023
2c456d0
https://github.com/gfx-rs/wgpu/pull/2171
tychedelia Oct 8, 2023
2595135
https://github.com/gfx-rs/wgpu/pull/3610
tychedelia Oct 8, 2023
fc76e0f
More misc fixes.
tychedelia Oct 8, 2023
80185c7
More misc fixes.
tychedelia Oct 8, 2023
3713d27
More misc fixes.
tychedelia Oct 8, 2023
b76d778
More misc fixes. Update textures.
tychedelia Oct 8, 2023
fd2b1d8
More misc fixes. Update textures.
tychedelia Oct 8, 2023
7801016
More misc fixes. Update textures.
tychedelia Oct 10, 2023
ed80029
Fix font example.
tychedelia Oct 10, 2023
77d9a01
wgsl fixes.
tychedelia Oct 11, 2023
06b7b87
wgsl fixes.
tychedelia Oct 11, 2023
3dbf3cb
Fix wasm build.
tychedelia Oct 11, 2023
1648fd4
Fix wasm build.
tychedelia Oct 11, 2023
a92e343
Fix winit breaking changes; default to x11, add wayland feature.
tychedelia Oct 12, 2023
36a724e
Remove reframe and get demo app to render correctly.
tychedelia Jan 15, 2024
65bfc5f
Fix shaders from wgsl update.
tychedelia Jan 15, 2024
298efa8
fix: adjust texture sample type in certain scenarios
RobWalt Oct 16, 2023
5a4fc6f
Add missing futures dep to examples project.
tychedelia Jan 17, 2024
70eed1d
Rustfmt.
tychedelia Jan 17, 2024
c1d2e8c
Add tokio to examples.
tychedelia Jan 17, 2024
b7494fb
Address warnings in nannou_laser ffi module
mitchmindtree Jan 17, 2024
c7f0aff
Address remaining warnings throughout nannou crates
mitchmindtree Jan 17, 2024
69b3f19
fix minor syntax errors in wgpu example fragment shaders
mitchmindtree Jan 17, 2024
1fba132
fix wgpu_teapot_camera example panic when cursor grabbing unsupported
mitchmindtree Jan 17, 2024
b16af95
Remove epi vestige.
tychedelia Jan 17, 2024
2bb75d2
Rustfmt.
tychedelia Jan 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target/
**/*.rs.bk
Cargo.lock
.DS_Store
.idea/
7 changes: 6 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ homepage = "https://github.com/nannou-org/nannou"
edition = "2018"

[dev-dependencies]
async-std = "1.10.0"
audrey = "0.3"
hotglsl = { git = "https://github.com/nannou-org/hotglsl", branch = "master" }
hrtf = "0.2"
Expand All @@ -29,6 +28,12 @@ time_calc = { version= "0.13", features = ["serde"] }
walkdir = "2"
hound = "3.4.0"
ringbuf = "0.2.2"
futures = "0.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["full"]}
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1", features = ["rt"]}

# Audio
[[example]]
Expand Down
62 changes: 31 additions & 31 deletions examples/laser/laser_frame_stream_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use nannou::geom::Rect;
use nannou::prelude::*;
use nannou_egui::egui::FontId;
use nannou_egui::{self, egui, Egui};
use nannou_laser as laser;
use std::sync::{mpsc, Arc};
Expand Down Expand Up @@ -155,7 +156,6 @@ fn model(app: &App) -> Model {
// A user-interface to tweak the settings.
let window = app.window(w_id).unwrap();
let egui = Egui::from_window(&window);
egui.ctx().set_fonts(fonts());
egui.ctx().set_style(style());

Model {
Expand Down Expand Up @@ -278,7 +278,7 @@ fn raw_window_event(_app: &App, model: &mut Model, event: &nannou::winit::event:

fn update(_app: &App, model: &mut Model, update: Update) {
// First, check for new laser DACs.
for dac in model.dac_rx.try_recv() {
for dac in model.dac_rx.try_iter() {
println!("Detected DAC {:?}!", dac.id());
let stream = model
.laser_api
Expand Down Expand Up @@ -510,39 +510,16 @@ fn view(_app: &App, model: &Model, frame: Frame) {
// The following functions are some custom styling preferences in an attempt to improve on the
// default egui theming.

fn fonts() -> egui::FontDefinitions {
let mut fonts = egui::FontDefinitions::default();
let entries = [
(
egui::TextStyle::Small,
(egui::FontFamily::Proportional, 13.0),
),
(
egui::TextStyle::Body,
(egui::FontFamily::Proportional, 16.0),
),
(
egui::TextStyle::Button,
(egui::FontFamily::Proportional, 16.0),
),
(
egui::TextStyle::Heading,
(egui::FontFamily::Proportional, 20.0),
),
(
egui::TextStyle::Monospace,
(egui::FontFamily::Monospace, 14.0),
),
];
fonts.family_and_size.extend(entries.iter().cloned());
fonts
}

fn style() -> egui::Style {
let mut style = egui::Style::default();
style.spacing = egui::style::Spacing {
item_spacing: egui::Vec2::splat(8.0),
window_padding: egui::Vec2::new(6.0, 6.0),
window_margin: egui::Margin {
left: 6.0,
right: 6.0,
top: 6.0,
bottom: 6.0,
},
button_padding: egui::Vec2::new(4.0, 2.0),
interact_size: egui::Vec2::new(56.0, 24.0),
indent: 10.0,
Expand All @@ -556,5 +533,28 @@ fn style() -> egui::Style {
style.visuals.widgets.noninteractive.bg_fill = egui::Color32::from_gray(36);
style.visuals.widgets.noninteractive.bg_stroke.color = egui::Color32::BLACK;
style.visuals.widgets.noninteractive.fg_stroke.color = egui::Color32::WHITE;
style.text_styles = [
(
egui::TextStyle::Small,
FontId::new(13.0, egui::FontFamily::Proportional),
),
(
egui::TextStyle::Body,
FontId::new(16.0, egui::FontFamily::Proportional),
),
(
egui::TextStyle::Button,
FontId::new(16.0, egui::FontFamily::Proportional),
),
(
egui::TextStyle::Heading,
FontId::new(20.0, egui::FontFamily::Proportional),
),
(
egui::TextStyle::Monospace,
FontId::new(14.0, egui::FontFamily::Monospace),
),
]
.into();
style
}
2 changes: 1 addition & 1 deletion examples/ui/egui/tune_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn view(app: &App, model: &Model, frame: Frame) {
}

fn edit_hsv(ui: &mut egui::Ui, color: &mut Hsv) {
let mut egui_hsv = egui::color::Hsva::new(
let mut egui_hsv = egui::ecolor::Hsva::new(
color.hue.to_positive_radians() as f32 / (std::f32::consts::PI * 2.0),
color.saturation,
color.value,
Expand Down
18 changes: 8 additions & 10 deletions examples/wgpu/wgpu_compute_shader/shaders/cs.wgsl
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
[[block]]
struct Buffer {
data: [[stride(4)]] array<f32>;
data: array<f32>,
};

[[block]]
struct Uniforms {
time: f32;
freq: f32;
oscillator_count: u32;
time: f32,
freq: f32,
oscillator_count: u32,
};

[[group(0), binding(0)]]
@group(0) @binding(0)
var<storage, read_write> output: Buffer;
[[group(0), binding(1)]]
@group(0) @binding(1)
var<uniform> uniforms: Uniforms;

[[stage(compute), workgroup_size(1, 1, 1)]]
fn main([[builtin(global_invocation_id)]] id: vec3<u32>) {
@compute @workgroup_size(1, 1, 1)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
let index: u32 = id.x;
let phase: f32 = uniforms.time + f32(index) * uniforms.freq / f32(uniforms.oscillator_count);
output.data[index] = sin(phase) * 0.5 + 0.5;
Expand Down
12 changes: 8 additions & 4 deletions examples/wgpu/wgpu_compute_shader/wgpu_compute_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn model(app: &App) -> Model {

// Create the compute shader module.
let cs_desc = wgpu::include_wgsl!("shaders/cs.wgsl");
let cs_mod = device.create_shader_module(&cs_desc);
let cs_mod = device.create_shader_module(cs_desc);

// Create the buffer that will store the result of our compute operation.
let oscillator_buffer_size =
Expand Down Expand Up @@ -140,7 +140,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
let mut cpass = encoder.begin_compute_pass(&pass_desc);
cpass.set_pipeline(&compute.pipeline);
cpass.set_bind_group(0, &compute.bind_group, &[]);
cpass.dispatch(OSCILLATOR_COUNT as u32, 1, 1);
cpass.dispatch_workgroups(OSCILLATOR_COUNT as u32, 1, 1);
}
encoder.copy_buffer_to_buffer(
&compute.oscillator_buffer,
Expand All @@ -157,7 +157,11 @@ fn update(app: &App, model: &mut Model, _update: Update) {
let oscillators = model.oscillators.clone();
let future = async move {
let slice = read_buffer.slice(..);
if let Ok(_) = slice.map_async(wgpu::MapMode::Read).await {
let (tx, rx) = futures::channel::oneshot::channel();
slice.map_async(wgpu::MapMode::Read, |res| {
tx.send(res).expect("The channel was closed");
});
if let Ok(_) = rx.await {
if let Ok(mut oscillators) = oscillators.lock() {
let bytes = &slice.get_mapped_range()[..];
// "Cast" the slice of bytes to a slice of floats as required.
Expand All @@ -170,7 +174,7 @@ fn update(app: &App, model: &mut Model, _update: Update) {
}
}
};
async_std::task::spawn(future);
tokio::spawn(future);

// Check for resource cleanups and mapping callbacks.
//
Expand Down
10 changes: 5 additions & 5 deletions examples/wgpu/wgpu_image/shaders/fs.wgsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
struct FragmentOutput {
[[location(0)]] f_color: vec4<f32>;
@location(0) f_color: vec4<f32>,
};

[[group(0), binding(0)]]
@group(0) @binding(0)
var tex: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0) @binding(1)
var tex_sampler: sampler;

[[stage(fragment)]]
fn main([[location(0)]] tex_coords: vec2<f32>) -> FragmentOutput {
@fragment
fn main(@location(0) tex_coords: vec2<f32>) -> FragmentOutput {
let out_color: vec4<f32> = textureSample(tex, tex_sampler, tex_coords);
return FragmentOutput(out_color);
}
8 changes: 4 additions & 4 deletions examples/wgpu/wgpu_image/shaders/vs.wgsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
struct VertexOutput {
[[location(0)]] tex_coords: vec2<f32>;
[[builtin(position)]] out_pos: vec4<f32>;
@location(0) tex_coords: vec2<f32>,
@builtin(position) out_pos: vec4<f32>,
};

[[stage(vertex)]]
fn main([[location(0)]] pos: vec2<f32>) -> VertexOutput {
@vertex
fn main(@location(0) pos: vec2<f32>) -> VertexOutput {
let tex_coords: vec2<f32> = vec2<f32>(pos.x * 0.5 + 0.5, 1.0 - (pos.y * 0.5 + 0.5));
let out_pos: vec4<f32> = vec4<f32>(pos, 0.0, 1.0);
return VertexOutput(tex_coords, out_pos);
Expand Down
4 changes: 2 additions & 2 deletions examples/wgpu/wgpu_image/wgpu_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn model(app: &App) -> Model {

let vs_desc = wgpu::include_wgsl!("shaders/vs.wgsl");
let fs_desc = wgpu::include_wgsl!("shaders/fs.wgsl");
let vs_mod = device.create_shader_module(&vs_desc);
let fs_mod = device.create_shader_module(&fs_desc);
let vs_mod = device.create_shader_module(vs_desc);
let fs_mod = device.create_shader_module(fs_desc);

// Load the image as a texture.
let texture = wgpu::Texture::from_image(&window, &image);
Expand Down
10 changes: 5 additions & 5 deletions examples/wgpu/wgpu_image_sequence/shaders/fs.wgsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
struct FragmentOutput {
[[location(0)]] f_color: vec4<f32>;
@location(0) f_color: vec4<f32>,
};

[[group(0), binding(0)]]
@group(0) @binding(0)
var tex: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0) @binding(1)
var tex_sampler: sampler;

[[stage(fragment)]]
fn main([[location(0)]] tex_coords: vec2<f32>) -> FragmentOutput {
@fragment
fn main(@location(0) tex_coords: vec2<f32>) -> FragmentOutput {
let out_color: vec4<f32> = textureSample(tex, tex_sampler, tex_coords);
return FragmentOutput(out_color);
}
8 changes: 4 additions & 4 deletions examples/wgpu/wgpu_image_sequence/shaders/vs.wgsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
struct VertexOutput {
[[location(0)]] tex_coords: vec2<f32>;
[[builtin(position)]] out_pos: vec4<f32>;
@location(0) tex_coords: vec2<f32>,
@builtin(position) out_pos: vec4<f32>,
};

[[stage(vertex)]]
fn main([[location(0)]] pos: vec2<f32>) -> VertexOutput {
@vertex
fn main(@location(0) pos: vec2<f32>) -> VertexOutput {
let tex_coords: vec2<f32> = vec2<f32>(pos.x * 0.5 + 0.5, 1.0 - (pos.y * 0.5 + 0.5));
let out_pos: vec4<f32> = vec4<f32>(pos, 0.0, 1.0);
return VertexOutput(tex_coords, out_pos);
Expand Down
4 changes: 2 additions & 2 deletions examples/wgpu/wgpu_image_sequence/wgpu_image_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn model(app: &App) -> Model {

let vs_desc = wgpu::include_wgsl!("shaders/vs.wgsl");
let fs_desc = wgpu::include_wgsl!("shaders/fs.wgsl");
let vs_mod = device.create_shader_module(&vs_desc);
let fs_mod = device.create_shader_module(&fs_desc);
let vs_mod = device.create_shader_module(vs_desc);
let fs_mod = device.create_shader_module(fs_desc);

let texture_array = {
// The wgpu device queue used to load the image data.
Expand Down
8 changes: 4 additions & 4 deletions examples/wgpu/wgpu_instancing/shaders/fs.wgsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
struct FragmentOutput {
[[location(0)]] f_color: vec4<f32>;
@location(0) f_color: vec4<f32>,
};

[[stage(fragment)]]
@fragment
fn main(
[[location(0)]] normal: vec3<f32>,
[[location(1)]] color: vec3<f32>,
@location(0) normal: vec3<f32>,
@location(1) color: vec3<f32>,
) -> FragmentOutput {
let light: vec3<f32> = vec3<f32>(0.0, 0.0, 1.0);
let brightness: f32 = dot(normalize(normal), normalize(light));
Expand Down
31 changes: 15 additions & 16 deletions examples/wgpu/wgpu_instancing/shaders/vs.wgsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[[block]]
struct Data {
world: mat4x4<f32>;
view: mat4x4<f32>;
proj: mat4x4<f32>;
world: mat4x4<f32>,
view: mat4x4<f32>,
proj: mat4x4<f32>,
};

struct VertexOutput {
[[location(0)]] out_normal: vec3<f32>;
[[location(1)]] out_color: vec3<f32>;
[[builtin(position)]] out_pos: vec4<f32>;
@location(0) out_normal: vec3<f32>,
@location(1) out_color: vec3<f32>,
@builtin(position) out_pos: vec4<f32>,
};

[[group(0), binding(0)]]
@group(0) @binding(0)
var<uniform> uniforms: Data;

fn custom_inverse(m: mat3x3<f32>) -> mat3x3<f32> {
Expand All @@ -30,15 +29,15 @@ fn custom_inverse(m: mat3x3<f32>) -> mat3x3<f32> {
return minv;
}

[[stage(vertex)]]
@vertex
fn main(
[[location(0)]] pos: vec3<f32>,
[[location(1)]] normal: vec3<f32>,
[[location(2)]] mat0: vec4<f32>,
[[location(3)]] mat1: vec4<f32>,
[[location(4)]] mat2: vec4<f32>,
[[location(5)]] mat3: vec4<f32>,
[[location(6)]] color: vec3<f32>,
@location(0) pos: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) mat0: vec4<f32>,
@location(3) mat1: vec4<f32>,
@location(4) mat2: vec4<f32>,
@location(5) mat3: vec4<f32>,
@location(6) color: vec3<f32>,
) -> VertexOutput {
let instance_transform: mat4x4<f32> = mat4x4<f32>(mat0, mat1, mat2, mat3);
let worldview: mat4x4<f32> = uniforms.view * uniforms.world * instance_transform;
Expand Down
4 changes: 2 additions & 2 deletions examples/wgpu/wgpu_instancing/wgpu_instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ fn model(app: &App) -> Model {
// Load shader modules.
let vs_desc = wgpu::include_wgsl!("shaders/vs.wgsl");
let fs_desc = wgpu::include_wgsl!("shaders/fs.wgsl");
let vs_mod = device.create_shader_module(&vs_desc);
let fs_mod = device.create_shader_module(&fs_desc);
let vs_mod = device.create_shader_module(vs_desc);
let fs_mod = device.create_shader_module(fs_desc);

// Create the vertex, normal and index buffers.
let vertices_bytes = vertices_as_bytes(&data::VERTICES);
Expand Down
4 changes: 2 additions & 2 deletions examples/wgpu/wgpu_teapot/shaders/fs.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[stage(fragment)]]
fn main([[location(0)]] normal: vec3<f32>) -> [[location(0)]] vec4<f32> {
@fragment
fn main(@location(0) normal: vec3<f32>) -> @location(0) vec4<f32> {
let light: vec3<f32> = vec3<f32>(0.0, 0.0, 1.0);
let color: vec3<f32> = vec3<f32>(1.0);
let brightness: f32 = dot(normalize(normal), normalize(light));
Expand Down
Loading
Loading