Skip to content

Commit

Permalink
Update to WGPU v24
Browse files Browse the repository at this point in the history
Had to manually use the defaults for some descriptors, because the type of the label couldn't be interfered.
  • Loading branch information
hasenbanck committed Jan 16, 2025
1 parent 48b7e9b commit 3392323
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 180 deletions.
304 changes: 185 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ syn = "2.0"
sys-locale = "0.3"
tokio = { version = "1.42", default-features = false }
walkdir = "2.5"
wgpu = "23.0"
wgpu = "24"
winit = "0.30"

[profile.dev.build-override]
Expand Down
2 changes: 1 addition & 1 deletion korangar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ serde = { workspace = true }
spin_sleep = { workspace = true }
sys-locale = { workspace = true }
walkdir = { workspace = true }
wgpu = { workspace = true }
wgpu = { workspace = true, features = ["static-dxc"] }
winit = { workspace = true }

[features]
Expand Down
10 changes: 5 additions & 5 deletions korangar/src/graphics/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use korangar_debug::logging::{print_debug, Colorize};
use korangar_debug::profile_block;
use wgpu::util::StagingBelt;
use wgpu::{
Adapter, CommandBuffer, CommandEncoder, CommandEncoderDescriptor, Device, Extent3d, ImageCopyBuffer, ImageCopyTexture, ImageDataLayout,
Instance, Maintain, Origin3d, Queue, SurfaceTexture, TextureAspect, TextureFormat, TextureViewDescriptor,
Adapter, CommandBuffer, CommandEncoder, CommandEncoderDescriptor, Device, Extent3d, Instance, Maintain, Origin3d, Queue,
SurfaceTexture, TexelCopyBufferInfo, TexelCopyBufferLayout, TexelCopyTextureInfo, TextureAspect, TextureFormat, TextureViewDescriptor,
};
use winit::dpi::PhysicalSize;
use winit::window::Window;
Expand Down Expand Up @@ -882,15 +882,15 @@ impl GraphicsEngine {
let y = (unpadded_texture_size.height - 1).min(instruction.picker_position.top as u32);

picker_encoder.copy_texture_to_buffer(
ImageCopyTexture {
TexelCopyTextureInfo {
texture: engine_context.global_context.picker_buffer_texture.get_texture(),
mip_level: 0,
origin: Origin3d { x, y, z: 0 },
aspect: TextureAspect::All,
},
ImageCopyBuffer {
TexelCopyBufferInfo {
buffer: engine_context.global_context.picker_value_buffer.get_buffer(),
layout: ImageDataLayout {
layout: TexelCopyBufferLayout {
offset: 0,
bytes_per_row,
rows_per_image: None,
Expand Down
15 changes: 8 additions & 7 deletions korangar/src/graphics/passes/interface/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: capabilities.get_max_texture_binding_array_count(),
count: None,
},
BindGroupLayoutEntry {
binding: 2,
Expand All @@ -106,7 +106,7 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: None,
count: capabilities.get_max_texture_binding_array_count(),
},
],
})
Expand Down Expand Up @@ -143,8 +143,8 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
device,
&bind_group_layout,
&instance_data_buffer,
&[global_context.solid_pixel_texture.get_texture_view()],
global_context.solid_pixel_texture.get_texture_view(),
&[global_context.solid_pixel_texture.get_texture_view()],
)
} else {
Self::create_bind_group(
Expand Down Expand Up @@ -384,8 +384,8 @@ impl Prepare for InterfaceRectangleDrawer {
device,
&self.bind_group_layout,
&self.instance_data_buffer,
&texture_views,
font_map_texture.get_texture_view(),
&texture_views,
);
} else {
for instruction in instructions.interface.iter() {
Expand Down Expand Up @@ -501,8 +501,9 @@ impl InterfaceRectangleDrawer {
device: &Device,
bind_group_layout: &BindGroupLayout,
instance_data_buffer: &Buffer<InstanceData>,
texture_views: &[&TextureView],

msdf_font_map: &TextureView,
texture_views: &[&TextureView],
) -> BindGroup {
device.create_bind_group(&BindGroupDescriptor {
label: Some(DRAWER_NAME),
Expand All @@ -514,11 +515,11 @@ impl InterfaceRectangleDrawer {
},
BindGroupEntry {
binding: 1,
resource: BindingResource::TextureViewArray(texture_views),
resource: BindingResource::TextureView(msdf_font_map),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(msdf_font_map),
resource: BindingResource::TextureViewArray(texture_views),
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct VertexOutput {
@group(0) @binding(1) var nearest_sampler: sampler;
@group(0) @binding(2) var linear_sampler: sampler;
@group(1) @binding(0) var<storage, read> instance_data: array<InstanceData>;
@group(1) @binding(1) var textures: binding_array<texture_2d<f32>>;
@group(1) @binding(2) var msdf_font_map: texture_2d<f32>;
@group(1) @binding(1) var msdf_font_map: texture_2d<f32>;
@group(1) @binding(2) var textures: binding_array<texture_2d<f32>>;

const BREATHING_ROOM = 0.5;
const BORDER_THRESHOLD = 2.0;
Expand Down
14 changes: 7 additions & 7 deletions korangar/src/graphics/passes/postprocessing/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: capabilities.get_max_texture_binding_array_count(),
count: None,
},
BindGroupLayoutEntry {
binding: 2,
Expand All @@ -123,7 +123,7 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: None,
count: capabilities.get_max_texture_binding_array_count(),
},
],
})
Expand Down Expand Up @@ -160,8 +160,8 @@ impl Drawer<{ BindGroupCount::One }, { ColorAttachmentCount::One }, { DepthAttac
device,
&bind_group_layout,
&instance_data_buffer,
&[global_context.solid_pixel_texture.get_texture_view()],
global_context.solid_pixel_texture.get_texture_view(),
&[global_context.solid_pixel_texture.get_texture_view()],
)
} else {
Self::create_bind_group(
Expand Down Expand Up @@ -412,8 +412,8 @@ impl Prepare for PostProcessingRectangleDrawer {
device,
&self.bind_group_layout,
&self.instance_data_buffer,
&texture_views,
font_map_texture.get_texture_view(),
&texture_views,
);
} else {
let mut offset = 0;
Expand Down Expand Up @@ -531,8 +531,8 @@ impl PostProcessingRectangleDrawer {
device: &Device,
bind_group_layout: &BindGroupLayout,
instance_data_buffer: &Buffer<InstanceData>,
texture_views: &[&TextureView],
msdf_font_map_view: &TextureView,
texture_views: &[&TextureView],
) -> BindGroup {
device.create_bind_group(&BindGroupDescriptor {
label: Some(DRAWER_NAME),
Expand All @@ -544,11 +544,11 @@ impl PostProcessingRectangleDrawer {
},
BindGroupEntry {
binding: 1,
resource: BindingResource::TextureViewArray(texture_views),
resource: BindingResource::TextureView(msdf_font_map_view),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(msdf_font_map_view),
resource: BindingResource::TextureViewArray(texture_views),
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ struct VertexOutput {
@group(0) @binding(1) var nearest_sampler: sampler;
@group(0) @binding(2) var linear_sampler: sampler;
@group(1) @binding(0) var<storage, read> instance_data: array<InstanceData>;
@group(1) @binding(1) var textures: binding_array<texture_2d<f32>>;
@group(1) @binding(2) var msdf_font_map: texture_2d<f32>;

@group(1) @binding(1) var msdf_font_map: texture_2d<f32>;
@group(1) @binding(2) var textures: binding_array<texture_2d<f32>>;

@vertex
fn vs_main(
Expand Down
34 changes: 30 additions & 4 deletions korangar/src/graphics/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,60 @@ pub(crate) fn create_new_sampler(
match sampler_type.into() {
SamplerType::TextureNearest => device.create_sampler(&SamplerDescriptor {
label: Some(label),
address_mode_u: AddressMode::default(),
address_mode_v: AddressMode::default(),
address_mode_w: AddressMode::default(),
mag_filter: FilterMode::Nearest,
min_filter: FilterMode::Nearest,
mipmap_filter: FilterMode::Nearest,
..Default::default()
lod_min_clamp: 0.0,
lod_max_clamp: 32.0,
compare: None,
anisotropy_clamp: 1,
border_color: None,
}),
SamplerType::TextureLinear => device.create_sampler(&SamplerDescriptor {
label: Some(label),
address_mode_u: AddressMode::default(),
address_mode_v: AddressMode::default(),
address_mode_w: AddressMode::default(),
mag_filter: FilterMode::Linear,
min_filter: FilterMode::Linear,
mipmap_filter: FilterMode::Linear,
..Default::default()
lod_min_clamp: 0.0,
lod_max_clamp: 32.0,
compare: None,
anisotropy_clamp: 1,
border_color: None,
}),
SamplerType::TextureAnisotropic(anisotropy_clamp) => device.create_sampler(&SamplerDescriptor {
label: Some(label),
address_mode_u: AddressMode::default(),
address_mode_v: AddressMode::default(),
address_mode_w: AddressMode::default(),
mag_filter: FilterMode::Linear,
min_filter: FilterMode::Linear,
mipmap_filter: FilterMode::Linear,
lod_min_clamp: 0.0,
lod_max_clamp: 32.0,
compare: None,
anisotropy_clamp,
..Default::default()
border_color: None,
}),
SamplerType::DepthCompare => {
let mut descriptor = SamplerDescriptor {
label: Some(label),
address_mode_u: AddressMode::default(),
address_mode_v: AddressMode::default(),
address_mode_w: AddressMode::default(),
mag_filter: FilterMode::Linear,
min_filter: FilterMode::Linear,
mipmap_filter: FilterMode::Linear,
lod_min_clamp: 0.0,
lod_max_clamp: 32.0,
compare: Some(CompareFunction::Greater),
..Default::default()
anisotropy_clamp: 1,
border_color: None,
};

if capabilities.supports_clamp_to_border() {
Expand Down
9 changes: 5 additions & 4 deletions korangar/src/graphics/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ impl Surface {
.get_current_texture()
.expect("Failed to acquire next surface texture!"),
Err(
// If the surface is outdated, or was lost, reconfigure it.
wgpu::SurfaceError::Outdated
| wgpu::SurfaceError::Lost
wgpu::SurfaceError::Lost
| wgpu::SurfaceError::Other
// If OutOfMemory happens, reconfiguring may not help, but we might as well try.
| wgpu::SurfaceError::OutOfMemory,
| wgpu::SurfaceError::OutOfMemory
// If the surface is outdated, or was lost, reconfigure it.
| wgpu::SurfaceError::Outdated
) => {
self.surface.configure(&self.device, &self.config);
self.surface
Expand Down
48 changes: 39 additions & 9 deletions korangar/src/graphics/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use hashbrown::HashMap;
use korangar_util::container::Cacheable;
use wgpu::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource,
BindingType, Device, Extent3d, ImageDataLayout, Queue, ShaderStages, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat,
TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension,
BindingType, Device, Extent3d, Queue, ShaderStages, TexelCopyBufferLayout, TextureAspect, TextureDescriptor, TextureDimension,
TextureFormat, TextureSampleType, TextureUsages, TextureView, TextureViewDescriptor, TextureViewDimension,
};

use crate::interface::layout::ScreenSize;
Expand Down Expand Up @@ -47,7 +47,14 @@ impl Texture {
let texture = device.create_texture(descriptor);
let texture_view = texture.create_view(&TextureViewDescriptor {
label: descriptor.label,
..Default::default()
format: None,
dimension: None,
usage: None,
aspect: TextureAspect::default(),
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: None,
});

let bind_group = device.create_bind_group(&BindGroupDescriptor {
Expand Down Expand Up @@ -84,7 +91,7 @@ impl Texture {
queue.write_texture(
texture.as_image_copy(),
image_data,
ImageDataLayout {
TexelCopyBufferLayout {
offset: 0,
bytes_per_row: Some(descriptor.size.width * block_size),
rows_per_image: Some(descriptor.size.height),
Expand All @@ -94,7 +101,14 @@ impl Texture {

let texture_view = texture.create_view(&TextureViewDescriptor {
label: descriptor.label,
..Default::default()
format: None,
dimension: None,
usage: None,
aspect: TextureAspect::default(),
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: None,
});

let bind_group = device.create_bind_group(&BindGroupDescriptor {
Expand Down Expand Up @@ -223,7 +237,8 @@ impl CubeArrayTexture {
label: Some("cube array face view"),
format: None,
dimension: Some(TextureViewDimension::D2),
aspect: wgpu::TextureAspect::All,
usage: None,
aspect: TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
base_array_layer: cube_index * 6 + face_index,
Expand All @@ -248,7 +263,8 @@ impl CubeArrayTexture {
label: Some("cube array view"),
format: None,
dimension: Some(TextureViewDimension::CubeArray),
aspect: wgpu::TextureAspect::All,
usage: None,
aspect: TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
Expand Down Expand Up @@ -326,7 +342,14 @@ impl AttachmentTexture {
let texture = device.create_texture(&descriptor);
let texture_view = texture.create_view(&TextureViewDescriptor {
label: descriptor.label,
..Default::default()
format: None,
dimension: None,
usage: None,
aspect: TextureAspect::default(),
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: None,
});

let sample_type = descriptor.format.sample_type(Some(TextureAspect::All), None).unwrap();
Expand Down Expand Up @@ -481,7 +504,14 @@ impl StorageTexture {
});
let texture_view = texture.create_view(&TextureViewDescriptor {
label: Some(label),
..Default::default()
format: None,
dimension: None,
usage: None,
aspect: TextureAspect::default(),
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: None,
});

Self {
Expand Down
1 change: 1 addition & 0 deletions korangar/src/loaders/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl TextureLoader {
label: Some(&format!("mip map level {level}")),
format: None,
dimension: Some(TextureViewDimension::D2),
usage: None,
aspect: TextureAspect::All,
base_mip_level: level,
mip_level_count: Some(1),
Expand Down
Loading

0 comments on commit 3392323

Please sign in to comment.