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 9d44200
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 170 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
12 changes: 6 additions & 6 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 @@ -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
37 changes: 19 additions & 18 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand All @@ -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()
Expand Down

0 comments on commit 9d44200

Please sign in to comment.