Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ serde = { version = "1.0.123", features = ["derive"], optional = true }
serde_json = { version = "1.0.61", optional = true }
serde_yaml2 = { version = "0.1.2", optional = true }
ron = { version = "0.12.0", package = "ron", optional = true }
toml = { version = "0.9.4", package = "toml", optional = true }
toml = { version = "1.1.2", package = "toml", optional = true }
raw-window-handle = "0.6.0"
async-global-executor = { version = "3.1.0", optional = true }
cfg-if = "1.0.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/kas-image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ webp = ["dep:image", "image/webp"]

[dependencies]
log = "0.4"
tiny-skia = { version = "0.11.0" }
resvg = { version = "0.46.0", optional = true }
usvg = { version = "0.46.0", optional = true }
tiny-skia = { version = "0.12.0" }
resvg = { version = "0.47.0", optional = true }
usvg = { version = "0.47.0", optional = true }
once_cell = "1.17.0"
thiserror = "2.0.3"
image = { version = "0.25.1", default-features = false, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-soft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bytemuck = "1.7.0"
futures-lite = "2.0"
log = "0.4"
thiserror = "2.0.3"
guillotiere = "0.6.0"
guillotiere = "0.7.0"
softbuffer = { version = "0.4.6", default-features = false }

[dependencies.kas]
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bytemuck = "1.7.0"
futures-lite = "2.0"
log = "0.4"
thiserror = "2.0.3"
guillotiere = "0.6.0"
guillotiere = "0.7.0"

[dependencies.kas]
# Rename package purely for convenience:
Expand All @@ -38,7 +38,7 @@ package = "kas-core"
path = "../kas-core"

[dependencies.wgpu]
version = "28.0.0"
version = "29.0.0"
default-features = false
features = ["spirv"]

Expand Down
15 changes: 9 additions & 6 deletions crates/kas-wgpu/src/draw/atlases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<I: bytemuck::Pod> Pipeline<I> {

let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("atlas pipeline layout"),
bind_group_layouts: &[bg_common, &bg_tex_layout],
bind_group_layouts: &[Some(bg_common), Some(&bg_tex_layout)],
immediate_size: 0,
});

Expand Down Expand Up @@ -363,16 +363,19 @@ impl<I: bytemuck::Pod> Window<I> {
mapped_at_creation: true,
});

let mut slice = buffer.slice(..byte_len.get()).get_mapped_range_mut();
copy_to_slice(&mut self.passes, &mut slice);
drop(slice);
let mut view = buffer.slice(..byte_len.get()).get_mapped_range_mut();
copy_to_slice(&mut self.passes, &mut view);
drop(view);

buffer.unmap();
self.buffer = Some(buffer);
self.buffer_size = buffer_size;
}

fn copy_to_slice<I: bytemuck::Pod>(passes: &mut [PassData<I>], slice: &mut [u8]) {
fn copy_to_slice<I: bytemuck::Pod>(
passes: &mut [PassData<I>],
view: &mut wgpu::BufferViewMut,
) {
let mut byte_offset = 0;
for pass in passes.iter_mut() {
let byte_start = byte_offset;
Expand All @@ -382,7 +385,7 @@ impl<I: bytemuck::Pod> Window<I> {
let byte_len = u64::from(len) * u64::conv(size_of::<I>());
let byte_end = byte_offset + byte_len;

slice[usize::conv(byte_offset)..usize::conv(byte_end)]
view.slice(usize::conv(byte_offset)..usize::conv(byte_end))
.copy_from_slice(bytemuck::cast_slice(&atlas.instances));

byte_offset = byte_end;
Expand Down
17 changes: 10 additions & 7 deletions crates/kas-wgpu/src/draw/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl<V: bytemuck::Pod> Window<V> {

if req_len <= self.buffer_size {
let buffer = self.buffer.as_ref().unwrap();
let mut slice = staging_belt.write_buffer(encoder, buffer, 0, byte_len);
copy_to_slice(&mut self.passes, &mut slice);
let mut view = staging_belt.write_buffer(encoder, buffer, 0, byte_len);
copy_to_slice(&mut self.passes, &mut view);
} else {
// Size must be a multiple of alignment
let mask = wgpu::COPY_BUFFER_ALIGNMENT - 1;
Expand All @@ -65,23 +65,26 @@ impl<V: bytemuck::Pod> Window<V> {
mapped_at_creation: true,
});

let mut slice = buffer.slice(..byte_len.get()).get_mapped_range_mut();
copy_to_slice(&mut self.passes, &mut slice);
drop(slice);
let mut view = buffer.slice(..byte_len.get()).get_mapped_range_mut();
copy_to_slice(&mut self.passes, &mut view);
drop(view);

buffer.unmap();
self.buffer = Some(buffer);
self.buffer_size = buffer_size;
}

fn copy_to_slice<V: bytemuck::Pod>(passes: &mut [PassData<V>], slice: &mut [u8]) {
fn copy_to_slice<V: bytemuck::Pod>(
passes: &mut [PassData<V>],
view: &mut wgpu::BufferViewMut,
) {
let mut byte_offset = 0;
for pass in passes.iter_mut() {
let len = u32::conv(pass.vertices.len());
let byte_len = u64::from(len) * u64::conv(size_of::<V>());
let byte_end = byte_offset + byte_len;

slice[usize::conv(byte_offset)..usize::conv(byte_end)]
view.slice(usize::conv(byte_offset)..usize::conv(byte_end))
.copy_from_slice(bytemuck::cast_slice(&pass.vertices));

pass.vertices.clear();
Expand Down
4 changes: 4 additions & 0 deletions crates/kas-wgpu/src/draw/draw_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl<C: CustomPipe> DrawPipe<C> {
let req = adapter.request_device(&desc);
let (device, queue) = block_on(req).map_err(|e| RunError::Graphics(Box::new(e)))?;

device.on_uncaptured_error(std::sync::Arc::new(|err| {
log::warn!("Uncaptured graphics device error: {err}")
}));

let shaders = ShaderManager::new(&device);

// Create staging belt and a local pool
Expand Down
2 changes: 1 addition & 1 deletion crates/kas-wgpu/src/draw/flat_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Pipeline {
) -> Self {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("FR pipeline_layout"),
bind_group_layouts: &[bgl_common],
bind_group_layouts: &[Some(bgl_common)],
immediate_size: 0,
});

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-wgpu/src/draw/round_2col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Pipeline {
) -> Self {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("R2C pipeline_layout"),
bind_group_layouts: &[bgl_common],
bind_group_layouts: &[Some(bgl_common)],
immediate_size: 0,
});

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-wgpu/src/draw/shaded_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Pipeline {
) -> Self {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("SR pipeline_layout"),
bind_group_layouts: &[bgl_common],
bind_group_layouts: &[Some(bgl_common)],
immediate_size: 0,
});

Expand Down
2 changes: 1 addition & 1 deletion crates/kas-wgpu/src/draw/shaded_square.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Pipeline {
) -> Self {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("SS pipeline_layout"),
bind_group_layouts: &[bgl_common],
bind_group_layouts: &[Some(bgl_common)],
immediate_size: 0,
});

Expand Down
7 changes: 5 additions & 2 deletions crates/kas-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ impl<CB: CustomPipeBuilder> Instance<CB> {
/// [`Options`] are typically default-constructed then
/// [loaded from enviroment variables](Options::load_from_env).
pub fn new(options: Options, custom: CB) -> Self {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: options.backend(),
..Default::default()
flags: Default::default(),
memory_budget_thresholds: Default::default(),
backend_options: Default::default(),
display: None,
});

Instance {
Expand Down
22 changes: 10 additions & 12 deletions crates/kas-wgpu/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kas::draw::{DrawIface, DrawSharedImpl, WindowCommon};
use kas::geom::Size;
use kas::runner::{HasDisplayAndWindowHandle, RunError, WindowSurface};
use std::time::Instant;
use wgpu::PresentMode;
use wgpu::{CurrentSurfaceTexture, PresentMode};

/// Per-window data
pub struct Surface<C: CustomPipe> {
Expand Down Expand Up @@ -113,22 +113,20 @@ impl<C: CustomPipe> WindowSurface for Surface<C> {

/// Return time at which render finishes
fn present(&mut self, shared: &mut Self::Shared, clear_color: Rgba) -> Instant {
// TODO: review error handling
let frame = match self.surface.get_current_texture() {
Ok(frame) => frame,
Err(e) => {
// This error has not been observed. Can it be fixed by
// re-configuring the surface? Does it ever occur anyway?
log::error!("WindowSurface::present: failed to get frame texture: {e}");
CurrentSurfaceTexture::Success(frame) | CurrentSurfaceTexture::Suboptimal(frame) => {
frame
}
CurrentSurfaceTexture::Timeout
| CurrentSurfaceTexture::Occluded
| CurrentSurfaceTexture::Outdated
| CurrentSurfaceTexture::Lost
| CurrentSurfaceTexture::Validation => {
return Instant::now();
}
};
Comment on lines 115 to 128
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inelegant but broadly equivalent to what we had before.


#[cfg(debug_assertions)]
if frame.suboptimal {
// Does this ever occur? Should we care?
log::warn!("WindowSurface::present: sub-optimal frame should be re-created");
}

let view = frame.texture.create_view(&Default::default());

let clear_color = to_wgpu_color(clear_color);
Expand Down
2 changes: 1 addition & 1 deletion examples/mandlebrot/mandlebrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl CustomPipeBuilder for PipeBuilder {

let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[bgl_common],
bind_group_layouts: &[Some(bgl_common)],
immediate_size: size_of::<PushConstants>().cast(),
});

Expand Down
Loading