This commit is contained in:
2026-05-02 15:26:20 -04:00
parent bd0c8690b4
commit 2ad1bd2660
13 changed files with 1072 additions and 698 deletions
Generated
+1011 -623
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -5,8 +5,8 @@ edition = "2021"
[dependencies]
winit = "0.30.9"
pollster = "0.3.0"
pollster = "0.4.0"
bytemuck = "1.19.0"
num-traits = "0.2.19"
nalgebra = "0.33.2"
wgpu = "24.0.1"
nalgebra = "0.34.2"
wgpu = "29.0.3"
+5 -3
View File
@@ -36,7 +36,9 @@ impl Layout {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_SRC,
usage: wgpu::TextureUsages::STORAGE_BINDING
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
};
let output = Texture::init(
@@ -70,8 +72,8 @@ impl Layout {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Tile Pipeline Layout"),
bind_group_layouts: &[&bind_layout],
push_constant_ranges: &[],
bind_group_layouts: &[Some(&bind_layout)],
immediate_size: 0,
});
Self {
+18 -14
View File
@@ -37,9 +37,12 @@ impl Renderer<'_> {
pub fn new(window: Arc<Window>) -> Self {
let size = window.inner_size();
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
flags: Default::default(),
memory_budget_thresholds: Default::default(),
backend_options: Default::default(),
display: None,
});
let surface = instance
@@ -53,24 +56,21 @@ impl Renderer<'_> {
}))
.expect("Could not get adapter!");
let buf_size = (10f32.powi(9) * 1.5) as u32;
let (device, queue) = pollster::block_on(adapter.request_device(
&wgpu::DeviceDescriptor {
let buf_size = (10f32.powi(9) * 1.5) as u64;
let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
label: None,
required_features: wgpu::Features::PUSH_CONSTANTS
| wgpu::Features::TIMESTAMP_QUERY
required_features: wgpu::Features::TIMESTAMP_QUERY
| wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS
| wgpu::Features::TIMESTAMP_QUERY_INSIDE_PASSES,
required_limits: wgpu::Limits {
max_storage_buffer_binding_size: buf_size,
max_buffer_size: buf_size as u64,
max_push_constant_size: 4,
max_buffer_size: buf_size,
..Default::default()
},
memory_hints: wgpu::MemoryHints::default(),
},
None,
))
trace: wgpu::Trace::Off,
experimental_features: wgpu::ExperimentalFeatures::disabled(),
}))
.expect("Could not get device!");
let info = adapter.get_info();
@@ -97,7 +97,7 @@ impl Renderer<'_> {
};
surface.configure(&device, &config);
let staging_belt = wgpu::util::StagingBelt::new(1024);
let staging_belt = wgpu::util::StagingBelt::new(device.clone(), 1024);
let timer = GPUTimer::new(&device, queue.get_timestamp_period(), 1);
let len = 2;
@@ -143,7 +143,11 @@ impl Renderer<'_> {
);
let mut encoder = std::mem::replace(&mut self.encoder, Self::create_encoder(&self.device));
let output = self.surface.get_current_texture().unwrap();
let output = match self.surface.get_current_texture() {
wgpu::CurrentSurfaceTexture::Success(v) => v,
wgpu::CurrentSurfaceTexture::Suboptimal(v) => v,
_ => panic!("failed to get current surface texture"),
};
self.timer.start(&mut encoder, 0);
self.compute_pipeline.run(&mut encoder);
+4 -7
View File
@@ -17,10 +17,7 @@ pub struct Layout {
pub const LABEL: &str = file!();
impl Layout {
pub fn init(
device: &wgpu::Device,
config: &wgpu::SurfaceConfiguration,
) -> Self {
pub fn init(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> Self {
let view = Storage::init_with(device, "view", bytemuck::bytes_of(&WindowView::default()));
let texture_desc = wgpu::TextureDescriptor {
@@ -124,8 +121,8 @@ impl Layout {
let render_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some(LABEL),
bind_group_layouts: &[&render_bind_layout],
push_constant_ranges: &[],
bind_group_layouts: &[Some(&render_bind_layout)],
immediate_size: 0,
});
Self {
@@ -192,7 +189,7 @@ impl Layout {
mask: !0,
alpha_to_coverage_enabled: true,
},
multiview: None,
multiview_mask: None,
cache: None,
})
}
+2
View File
@@ -80,10 +80,12 @@ impl RenderPipeline {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});
render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, &self.bind_group, &[]);
+3 -9
View File
@@ -37,15 +37,9 @@ impl<T: bytemuck::Pod> ArrayBuffer<T> {
return resized;
}
if let Some(update) = self.update.take() {
let mut view = belt.write_buffer(
encoder,
&self.buffer,
0,
unsafe {
let mut view = belt.write_buffer(encoder, &self.buffer, 0, unsafe {
std::num::NonZeroU64::new_unchecked(std::mem::size_of_val(&update[..]) as u64)
},
device,
);
});
view.copy_from_slice(bytemuck::cast_slice(&update));
}
resized
@@ -122,7 +116,7 @@ impl<T: bytemuck::Pod> ArrayBuffer<T> {
}
}
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: self.buffer.as_entire_binding(),
+4 -4
View File
@@ -1,14 +1,14 @@
#![allow(unused_imports)]
#![allow(dead_code)]
mod array;
mod storage;
mod texture;
mod timer;
mod uniform;
mod array;
mod storage;
pub use array::*;
pub use storage::*;
pub use texture::*;
pub use timer::*;
pub use uniform::*;
pub use array::*;
pub use storage::*;
+4 -8
View File
@@ -45,13 +45,9 @@ impl Storage {
self.old_len = data.len();
true
} else {
let mut view = belt.write_buffer(
encoder,
&self.buffer,
0,
unsafe { std::num::NonZeroU64::new_unchecked(std::mem::size_of_val(data) as u64) },
device,
);
let mut view = belt.write_buffer(encoder, &self.buffer, 0, unsafe {
std::num::NonZeroU64::new_unchecked(std::mem::size_of_val(data) as u64)
});
view.copy_from_slice(data);
false
}
@@ -74,7 +70,7 @@ impl Storage {
count: None,
}
}
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: self.buffer.as_entire_binding(),
+4 -4
View File
@@ -40,7 +40,7 @@ impl Texture {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
compare: Some(wgpu::CompareFunction::LessEqual),
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
@@ -73,13 +73,13 @@ impl Texture {
self.texture = device.create_texture(&self.texture_desc);
self.view = self.texture.create_view(&self.view_desc);
}
pub fn view_bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn view_bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: wgpu::BindingResource::TextureView(&self.view),
}
}
pub fn sampler_bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn sampler_bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: wgpu::BindingResource::Sampler(&self.sampler),
@@ -118,7 +118,7 @@ impl ResizableTexture {
self.view = self.texture.create_view(&self.view_desc)
}
pub fn view_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn view_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: wgpu::BindingResource::TextureView(&self.view),
+1 -2
View File
@@ -57,7 +57,7 @@ impl GPUTimer {
.map_async(wgpu::MapMode::Read, move |v| {
s.send(v).expect("what");
});
device.poll(wgpu::Maintain::wait()).panic_on_timeout();
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
if let Ok(Ok(())) = r.recv() {
let data = self.map_buf.slice(..).get_mapped_range();
self.timestamps.copy_from_slice(bytemuck::cast_slice(&data));
@@ -86,4 +86,3 @@ impl GPUTimer {
pass.write_timestamp(&self.query_set, i * 2 + 1);
}
}
+3 -10
View File
@@ -33,21 +33,14 @@ impl<T: bytemuck::Pod> Uniform<T> {
}
pub fn update(
&mut self,
device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
belt: &mut wgpu::util::StagingBelt,
data: T,
) {
let slice = &[data];
let mut view = belt.write_buffer(
encoder,
&self.buffer,
0,
unsafe {
let mut view = belt.write_buffer(encoder, &self.buffer, 0, unsafe {
std::num::NonZeroU64::new_unchecked((slice.len() * std::mem::size_of::<T>()) as u64)
},
device,
);
});
view.copy_from_slice(bytemuck::cast_slice(slice));
}
}
@@ -67,7 +60,7 @@ impl<T> Uniform<T> {
count: None,
}
}
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry {
pub fn bind_group_entry(&self, binding: u32) -> wgpu::BindGroupEntry<'_> {
wgpu::BindGroupEntry {
binding,
resource: self.buffer.as_entire_binding(),
+1 -2
View File
@@ -1,6 +1,5 @@
#![feature(bigint_helper_methods)]
#![feature(widening_mul)]
#![feature(int_roundings)]
#![feature(let_chains)]
use client::ClientApp;