Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to WGPU v24 #235

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
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
@@ -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]
2 changes: 1 addition & 1 deletion korangar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
10 changes: 5 additions & 5 deletions korangar/src/graphics/engine.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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,
15 changes: 8 additions & 7 deletions korangar/src/graphics/passes/interface/rectangle.rs
Original file line number Diff line number Diff line change
@@ -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,
@@ -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(),
},
],
})
@@ -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(
@@ -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() {
@@ -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),
@@ -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),
},
],
})
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 7 additions & 7 deletions korangar/src/graphics/passes/postprocessing/rectangle.rs
Original file line number Diff line number Diff line change
@@ -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,
@@ -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(),
},
],
})
@@ -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(
@@ -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;
@@ -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),
@@ -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),
},
],
})
Original file line number Diff line number Diff line change
@@ -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(
34 changes: 30 additions & 4 deletions korangar/src/graphics/sampler.rs
Original file line number Diff line number Diff line change
@@ -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() {
9 changes: 5 additions & 4 deletions korangar/src/graphics/surface.rs
Original file line number Diff line number Diff line change
@@ -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
48 changes: 39 additions & 9 deletions korangar/src/graphics/texture.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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 {
@@ -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),
@@ -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 {
@@ -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,
@@ -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,
@@ -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();
@@ -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 {
1 change: 1 addition & 0 deletions korangar/src/loaders/texture/mod.rs
Original file line number Diff line number Diff line change
@@ -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),
37 changes: 19 additions & 18 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
@@ -71,9 +71,13 @@ use ragnarok_packets::{
};
use renderer::InterfaceRenderer;
use settings::AudioSettings;
use wgpu::util::initialize_adapter_from_env_or_default;
use wgpu::{
BackendOptions, Backends, DeviceDescriptor, Dx12BackendOptions, Dx12Compiler, GlBackendOptions, Gles3MinorVersion, Instance,
InstanceDescriptor, InstanceFlags, MemoryHints,
};
#[cfg(feature = "debug")]
use wgpu::{Device, Queue};
use wgpu::{Dx12Compiler, Instance, InstanceFlags, MemoryHints};
use winit::application::ApplicationHandler;
use winit::dpi::{LogicalSize, PhysicalSize};
use winit::event::WindowEvent;
@@ -297,23 +301,20 @@ impl Client {
});

time_phase!("create adapter", {
let trace_dir = std::env::var("WGPU_TRACE");
let backends = wgpu::util::backend_bits_from_env().unwrap_or_default();
let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or(Dx12Compiler::Dxc {
dxil_path: None,
dxc_path: None,
});
let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();
let flags = InstanceFlags::from_build_config().with_env();

let instance = Instance::new(wgpu::InstanceDescriptor {
backends,
flags,
dx12_shader_compiler,
gles_minor_version,
let instance = Instance::new(&InstanceDescriptor {
backends: Backends::all().with_env(),
flags: InstanceFlags::from_build_config().with_env(),
backend_options: BackendOptions {
gl: GlBackendOptions {
gles_minor_version: Gles3MinorVersion::Automatic.with_env(),
},
dx12: Dx12BackendOptions {
shader_compiler: Dx12Compiler::StaticDxc.with_env(),
},
},
});

let adapter = pollster::block_on(async { wgpu::util::initialize_adapter_from_env_or_default(&instance, None).await.unwrap() });
let adapter = pollster::block_on(async { initialize_adapter_from_env_or_default(&instance, None).await.unwrap() });
let adapter = Arc::new(adapter);

#[cfg(feature = "debug")]
@@ -331,13 +332,13 @@ impl Client {
let (device, queue) = pollster::block_on(async {
adapter
.request_device(
&wgpu::DeviceDescriptor {
&DeviceDescriptor {
label: None,
required_features: capabilities.get_required_features(),
required_limits: capabilities.get_required_limits(),
memory_hints: MemoryHints::Performance,
},
trace_dir.ok().as_ref().map(std::path::Path::new),
std::env::var("WGPU_TRACE").ok().as_ref().map(std::path::Path::new),
)
.await
.unwrap()