mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Get boids working
This commit is contained in:
committed by
Josh Groves
parent
75ec7155f1
commit
9aedbed2eb
@@ -53,7 +53,7 @@ cgmath = "0.17"
|
||||
log = "0.4"
|
||||
png = "0.15"
|
||||
winit = { version = "0.22", features = ["web-sys"] }
|
||||
rand = "0.7.2"
|
||||
rand = { version = "0.7.2", features = ["wasm-bindgen"] }
|
||||
bytemuck = "1"
|
||||
futures = "0.3"
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#version 450
|
||||
|
||||
// this shader expects NUM_PARTICLES and PARTICLES_PER_GROUP
|
||||
// defines to be inserted by main.rs
|
||||
// These should match the Rust constants defined in main.rs
|
||||
#define NUM_PARTICLES 1500
|
||||
#define PARTICLES_PER_GROUP 64
|
||||
|
||||
layout(local_size_x = PARTICLES_PER_GROUP) in;
|
||||
|
||||
|
||||
BIN
wgpu/examples/boids/boids.comp.spv
Normal file
BIN
wgpu/examples/boids/boids.comp.spv
Normal file
Binary file not shown.
@@ -6,8 +6,6 @@ extern crate rand;
|
||||
#[path = "../framework.rs"]
|
||||
mod framework;
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
use wgpu::vertex_attr_array;
|
||||
|
||||
// number of boid particles to simulate
|
||||
@@ -35,34 +33,19 @@ impl framework::Example for Example {
|
||||
sc_desc: &wgpu::SwapChainDescriptor,
|
||||
device: &wgpu::Device,
|
||||
) -> (Self, Option<wgpu::CommandBuffer>) {
|
||||
// loads comp shader source and adds shared constants as defines to comp shader
|
||||
|
||||
const BOIDS_SOURCE: &str = include_str!("boids.comp");
|
||||
const HEADER: &str = "#version 450";
|
||||
assert_eq!(BOIDS_SOURCE.lines().next(), Some(HEADER));
|
||||
|
||||
let mut boids_source_str = String::from(HEADER);
|
||||
write!(
|
||||
boids_source_str,
|
||||
"\n#define NUM_PARTICLES {}\n#define PARTICLES_PER_GROUP {}",
|
||||
NUM_PARTICLES, PARTICLES_PER_GROUP
|
||||
)
|
||||
.unwrap();
|
||||
boids_source_str += &BOIDS_SOURCE[HEADER.len()..];
|
||||
|
||||
// load (and compile) shaders and create shader modules
|
||||
|
||||
let boids = framework::load_glsl(&boids_source_str, framework::ShaderStage::Compute);
|
||||
let boids_module = device.create_shader_module(&boids);
|
||||
let boids = include_bytes!("boids.comp.spv");
|
||||
let boids_module = device
|
||||
.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&boids[..])).unwrap());
|
||||
|
||||
let vs = framework::load_glsl(include_str!("shader.vert"), framework::ShaderStage::Vertex);
|
||||
let vs_module = device.create_shader_module(&vs);
|
||||
let vs = include_bytes!("shader.vert.spv");
|
||||
let vs_module =
|
||||
device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&vs[..])).unwrap());
|
||||
|
||||
let fs = framework::load_glsl(
|
||||
include_str!("shader.frag"),
|
||||
framework::ShaderStage::Fragment,
|
||||
);
|
||||
let fs_module = device.create_shader_module(&fs);
|
||||
let fs = include_bytes!("shader.frag.spv");
|
||||
let fs_module =
|
||||
device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&fs[..])).unwrap());
|
||||
|
||||
// create compute bind layout group and compute pipeline layout
|
||||
|
||||
|
||||
BIN
wgpu/examples/boids/shader.frag.spv
Normal file
BIN
wgpu/examples/boids/shader.frag.spv
Normal file
Binary file not shown.
BIN
wgpu/examples/boids/shader.vert.spv
Normal file
BIN
wgpu/examples/boids/shader.vert.spv
Normal file
Binary file not shown.
@@ -94,7 +94,8 @@ async fn run_async<E: Example>(event_loop: EventLoop<()>, window: Window) {
|
||||
*control_flow = if cfg!(feature = "metal-auto-capture") {
|
||||
ControlFlow::Exit
|
||||
} else {
|
||||
ControlFlow::Poll
|
||||
// TODO: ControlFlow::Poll
|
||||
ControlFlow::Wait
|
||||
};
|
||||
match event {
|
||||
event::Event::MainEventsCleared => window.request_redraw(),
|
||||
|
||||
Reference in New Issue
Block a user