Skip to content

Commit

Permalink
WIP: Dependencies update, with very curious bug
Browse files Browse the repository at this point in the history
See: shaders/physics/compute.rs:110

GPU device dissapears when line 110 is not commented out. No other error
messages or backtrace
  • Loading branch information
tombh committed Sep 21, 2022
1 parent 65a98d5 commit 6eeea1b
Show file tree
Hide file tree
Showing 15 changed files with 629 additions and 582 deletions.
1,142 changes: 585 additions & 557 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Wrach

A game like Noita, but using the GPU

## Misc

Why do I have to do this?
```
rustup update
rustup override set nightly-2022-08-22
```
Even though it's set in `./rust-toolchain`
9 changes: 5 additions & 4 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl SquareVertex {
let fragment = wgpu::FragmentState {
module: shader_module,
entry_point: "main_fs",
targets: &[manager.config.format.into()],
targets: &[Some(manager.config.format.into())],
};

let pipeline_descriptor = wgpu::RenderPipelineDescriptor {
Expand All @@ -52,6 +52,7 @@ impl SquareVertex {
},
],
},
multiview: None,
fragment: Some(fragment),
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
Expand Down Expand Up @@ -90,18 +91,18 @@ impl SquareVertex {
command_encoder: &'a mut wgpu::CommandEncoder,
view: &'a wgpu::TextureView,
) -> wgpu::RenderPass<'a> {
let color_attachments = [wgpu::RenderPassColorAttachment {
let color_attachments = wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
},
}];
};

let render_pass_descriptor = wgpu::RenderPassDescriptor {
label: None,
color_attachments: &color_attachments,
color_attachments: &[Some(color_attachments)],
depth_stencil_attachment: None,
};

Expand Down
10 changes: 5 additions & 5 deletions runners/wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ edition = "2018"
wrach-physics-shaders = { path = "../../shaders/physics" }
rust-gpu-compiler = { path = "../../shaders/rust-gpu-compiler" }
futures = { version = "0.3", default-features = false, features = ["std", "executor"] }
wgpu = { version = "0.11.0", features = ["spirv"] }
wgpu-hal = "=0.11.2"
winit = { version = "0.25", features = ["web-sys"] }
wgpu = { version = "0.13.1", features = ["spirv", "vulkan-portability"] }
wgpu-hal = "0.13.2"
winit = { version = "0.27" }
bytemuck = "1.7.2"
crevice = { version = "0.8.0", features = ["glam"] }
rand = "0.7.2"
crevice = { version = "0.11.0", features = ["glam"] }
rand = "0.8.5"
cgmath = "0.18.0"
env_logger = "0.9.0"
async-executor = "1.4.1"
Expand Down
4 changes: 2 additions & 2 deletions runners/wgpu/src/event_looper/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<'instance, T: Renderer> EventLoop<'instance, T> {
cpass.set_pipeline(&self.manager.pipeline.compute_pipeline);

cpass.set_push_constants(0, bytemuck::bytes_of(&self.params.as_std140()));
cpass.dispatch(self.manager.pipeline.work_group_count, 1, 1);
cpass.dispatch_workgroups(self.manager.pipeline.work_group_count, 1, 1);
}

fn post_compute_pass_stage(&mut self, command_encoder: &mut wgpu::CommandEncoder) {
Expand All @@ -289,6 +289,6 @@ impl<'instance, T: Renderer> EventLoop<'instance, T> {
cpass.set_pipeline(&self.manager.pipeline.post_compute_pipeline);

cpass.set_push_constants(0, bytemuck::bytes_of(&self.params.as_std140()));
cpass.dispatch(self.manager.pipeline.work_group_count, 1, 1);
cpass.dispatch_workgroups(self.manager.pipeline.work_group_count, 1, 1);
}
}
6 changes: 3 additions & 3 deletions runners/wgpu/src/gpu_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl GPUManager {
);

let required_downlevel_capabilities = pipeline::Pipeline::required_downlevel_capabilities();
let downlevel_capabilities = adapter.get_downlevel_properties();
let downlevel_capabilities = adapter.get_downlevel_capabilities();
assert!(
downlevel_capabilities.shader_model >= required_downlevel_capabilities.shader_model,
"Adapter does not support the minimum shader model required to run this example: {:?}",
Expand Down Expand Up @@ -92,10 +92,10 @@ impl GPUManager {

let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::Fifo,
};

surface.configure(&device, &config);
Expand Down
6 changes: 3 additions & 3 deletions runners/wgpu/src/pipeliner/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a> Builder<'a> {
pub fn shader(device: &wgpu::Device, path: &str) -> ShaderModule {
let shader_binary = rust_gpu_compiler::build(path);
let spirv = wgpu::util::make_spirv(&shader_binary);
device.create_shader_module(&wgpu::ShaderModuleDescriptor {
device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some(path),
source: spirv,
})
Expand Down Expand Up @@ -182,8 +182,8 @@ impl<'a> Builder<'a> {
let position = vec2(x, y);
initial_position_data.push(position);
initial_velocity_data.push(vec2(
rng.gen_range(-jitter, jitter),
rng.gen_range(-jitter, jitter),
rng.gen_range(-jitter..jitter),
rng.gen_range(-jitter..jitter),
));
physics::neighbours::NeighbouringParticles::place_particle_in_pixel(
count as physics::particle::ParticleID,
Expand Down
2 changes: 1 addition & 1 deletion runners/wgpu/src/pipeliner/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Pipeline {
}

pub fn required_features() -> wgpu::Features {
wgpu::Features::CLEAR_COMMANDS | wgpu::Features::PUSH_CONSTANTS
wgpu::Features::PUSH_CONSTANTS
}

pub fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-04-11"
channel = "nightly-2022-08-22"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
4 changes: 2 additions & 2 deletions shaders/physics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = [ "g
cfg-if = "1.0.0"

[target.'cfg(not(target_arch = "spirv"))'.dependencies]
crevice = { version = "0.8.0", features = ["glam"] }
crevice = { version = "0.11.0", features = ["glam"] }
# We need the native version of glam for crevice/bytemuck support
glam = { version = "0.19.0", features = ["bytemuck"] }
glam = { version = "0.21.3", features = ["bytemuck"] }
2 changes: 1 addition & 1 deletion shaders/physics/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn entry(
});
particle = particle.propogate(neighbours);
positions_dst[id] = particle.position;
velocities_dst[id] = particle.velocity;
// velocities_dst[id] = particle.velocity;
neighbours::NeighbouringParticles::place_particle_in_pixel(
id as particle::ParticleID,
particle.position,
Expand Down
8 changes: 8 additions & 0 deletions shaders/physics/src/neighbours.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ impl NeighbouringParticles {
positions: &particle::ParticlePositions,
) {
let coord = Self::linear_pixel_coord(x, y);

// -------------------------------
// EXPENSIVE MEMORY ACESS
let mut neighbour_id = map[coord];
// -------------------------------

// Subtract 1 as all the IDs have been incremented to accomodate particle::NO_PARTICLE_ID
// TODO: can we use Option<T> instead of hacking ID 0?
Expand All @@ -198,7 +202,11 @@ impl NeighbouringParticles {

neighbour_id -= 1;

// ---------------------------------------------
// EXPENSIVE MEMORY ACESS
let position = positions[neighbour_id as usize];
// ---------------------------------------------

let length = position.distance(self.particle.position);
if length < (particle::INFLUENCE_FACTOR as f32 * particle::PARTICLE_RADIUS) {
self.note_neighbour_id(neighbour_id);
Expand Down
1 change: 1 addition & 0 deletions shaders/physics/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ cfg_if::cfg_if! {
}
}

#[allow(deprecated)]
pub const G: Vec2 = glam::const_vec2!([0.0, -10.0]);
4 changes: 2 additions & 2 deletions shaders/renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = [ "g
cfg-if = "1.0.0"

[target.'cfg(not(target_arch = "spirv"))'.dependencies]
crevice = { version = "0.8.0", features = ["glam"] }
crevice = { version = "0.11.0", features = ["glam"] }
# We need the native version of glam for crevice/bytemuck support
glam = { version = "0.19.0", features = ["bytemuck"] }
glam = { version = "0.21.3", features = ["bytemuck"] }

2 changes: 1 addition & 1 deletion shaders/rust-gpu-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ use-installed-tools = ["spirv-builder/use-installed-tools"]
use-compiled-tools = ["spirv-builder/use-compiled-tools"]

[dependencies]
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu", rev = "0866cf591a7fdbbd15bdb3468e192bb9b6189fd0", default-features = false }
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu", rev = "a9a233e", default-features = false }

0 comments on commit 6eeea1b

Please sign in to comment.