Skip to content

Commit

Permalink
Upgrade to wgpu 0.16.0
Browse files Browse the repository at this point in the history
fix braking changes
  • Loading branch information
kevzettler committed Apr 27, 2023
1 parent e9d1f3b commit 2089caa
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 224 deletions.
572 changes: 376 additions & 196 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 @@ -19,7 +19,7 @@ tracing = "0.1.35"
tracing-tree = { git = "https://github.com/TmLev/tracing-tree" }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
tracing-log = { version = "0.1" }
wgpu = "0.15.0"
wgpu = "0.16.0"
winit = { version = "0.28.1", features = ["serde"] }
futures = { version = "0.3", default-features = false, features = ["std"] }
tokio = { version = "1.20", features = ["parking_lot"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ExamplesRender {

tracing::debug!("Creating self");

let is_srgb = gpu.swapchain_format().describe().srgb;
let is_srgb = gpu.swapchain_format().is_srgb();
let gamma_correction = if !is_srgb {
tracing::info!("Output format is not in srgb colorspace. Applying manual gamma correction");
Some(2.2)
Expand Down
4 changes: 2 additions & 2 deletions crates/debugger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{num::NonZeroU32, sync::Arc};
use std::{sync::Arc};

use ambient_core::{
asset_cache,
Expand Down Expand Up @@ -188,7 +188,7 @@ fn ShadowMapViz(hooks: &mut Hooks, get_state: GetDebuggerState, cascade: u32) ->
tex = Some(renderer.shadows.as_ref().map(|x| {
Arc::new(x.shadow_texture.create_view(&wgpu::TextureViewDescriptor {
base_array_layer: cascade,
array_layer_count: NonZeroU32::new(1),
array_layer_count: Some(1),
dimension: Some(wgpu::TextureViewDimension::D2),
..Default::default()
}))
Expand Down
6 changes: 2 additions & 4 deletions crates/gpu/src/mipmap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::num::NonZeroU32;

use ambient_std::asset_cache::{AssetCache, SyncAssetKeyExt};

use super::blit::BlitterKey;
Expand All @@ -24,9 +22,9 @@ pub fn generate_mipmaps(
dimension: Some(wgpu::TextureViewDimension::D2),
aspect: wgpu::TextureAspect::All,
base_mip_level: mip,
mip_level_count: NonZeroU32::new(1),
mip_level_count: Some(1),
base_array_layer: layer,
array_layer_count: NonZeroU32::new(1),
array_layer_count: Some(1)
})
})
.collect::<Vec<_>>();
Expand Down
9 changes: 6 additions & 3 deletions crates/gpu/src/std_assets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{num::NonZeroU8, sync::Arc};
use std::{sync::Arc};

use ambient_std::asset_cache::{AssetCache, SyncAssetKey, SyncAssetKeyExt};
use glam::{uvec4, UVec4};
Expand All @@ -20,7 +20,10 @@ impl SyncAssetKey<Arc<wgpu::Sampler>> for DefaultSamplerKey {
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Linear,
anisotropy_clamp: NonZeroU8::new(16),
anisotropy_clamp: 1,
border_color: None,
compare: None,
label: None,
..Default::default()
}))
}
Expand Down Expand Up @@ -76,7 +79,7 @@ impl SyncAssetKey<Arc<wgpu::Sampler>> for DepthBufferSampler {
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
label: Some("depth buffer sampler"),
anisotropy_clamp: None,
anisotropy_clamp: 1,
border_color: None,
}))
}
Expand Down
23 changes: 11 additions & 12 deletions crates/gpu/src/texture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
io::Cursor,
num::NonZeroU32,
ops::Deref,
path::Path,
sync::{
Expand Down Expand Up @@ -54,7 +53,7 @@ impl Texture {

fn size_in_bytes_from_desc(descriptor: &wgpu::TextureDescriptor) -> u64 {
let mut mip_size = (descriptor.size.width as u64 * descriptor.size.height as u64 * descriptor.size.depth_or_array_layers as u64)
* descriptor.format.describe().block_size as u64;
* descriptor.format.block_size(None).unwrap() as u64;
let mut size_in_bytes = mip_size;
for _ in 1..descriptor.mip_level_count {
mip_size /= 2;
Expand Down Expand Up @@ -193,8 +192,8 @@ impl Texture {
&img.into_vec(),
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(texture.size.width * texture.format.describe().block_size as u32),
rows_per_image: NonZeroU32::new(texture.size.height),
bytes_per_row: Some(texture.size.width * texture.format.block_size(None).unwrap()),
rows_per_image: Some(texture.size.height),
},
wgpu::Extent3d { width: texture.size.width, height: texture.size.height, depth_or_array_layers: 1 },
);
Expand Down Expand Up @@ -240,8 +239,8 @@ impl Texture {
bytemuck::cast_slice(data.as_slice().unwrap()),
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(4 * size.width),
rows_per_image: NonZeroU32::new(size.height),
bytes_per_row: Some(4 * size.width),
rows_per_image: Some(size.height)
},
size,
);
Expand All @@ -256,8 +255,8 @@ impl Texture {
data,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(self.size.width * self.format.describe().block_size as u32),
rows_per_image: NonZeroU32::new(self.size.height),
bytes_per_row: Some(self.size.width * self.format.block_size(None).unwrap()),
rows_per_image: Some(self.size.height),
},
self.size,
);
Expand Down Expand Up @@ -363,7 +362,7 @@ pub struct TextureReader {
}
impl TextureReader {
pub fn new(gpu: Arc<Gpu>, base_size: wgpu::Extent3d, sample_count: u32, format: wgpu::TextureFormat) -> Self {
let block_size = format.describe().block_size as usize;
let block_size = format.block_size(None).unwrap() as usize;
let size = wgpu::Extent3d {
width: base_size.width * sample_count,
height: base_size.height * sample_count,
Expand Down Expand Up @@ -397,8 +396,8 @@ impl TextureReader {
buffer: &self.staging_output_buffer,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: Some(std::num::NonZeroU32::new(self.buffer_dimensions.padded_bytes_per_row as u32).unwrap()),
rows_per_image: Some(std::num::NonZeroU32::new(self.buffer_dimensions.size.height).unwrap()),
bytes_per_row: Some(self.buffer_dimensions.padded_bytes_per_row as u32),
rows_per_image: Some(self.buffer_dimensions.size.height),
},
},
self.base_size,
Expand All @@ -424,7 +423,7 @@ impl TextureReader {
self.size.width as usize
* self.size.height as usize
* self.size.depth_or_array_layers as usize
* self.format.describe().block_size as usize
* self.format.block_size(None).unwrap() as usize
];
for (i, chunk) in padded_buffer.chunks(self.buffer_dimensions.padded_bytes_per_row).enumerate() {
result[(i * self.buffer_dimensions.unpadded_bytes_per_row)..((i + 1) * self.buffer_dimensions.unpadded_bytes_per_row)]
Expand Down
4 changes: 2 additions & 2 deletions crates/renderer/src/shadow_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{num::NonZeroU32, sync::Arc};
use std::{sync::Arc};

use ambient_core::{camera::Camera, main_scene, player::local_user_id, transform::*};
use ambient_ecs::{ArchetypeFilter, World};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl ShadowsRenderer {
base_mip_level: 0,
mip_level_count: None,
base_array_layer: i,
array_layer_count: NonZeroU32::new(1),
array_layer_count: Some(1),
}),
globals: ShadowAndUIGlobals::new(assets.clone(), renderer_resources.globals_layout.clone()),
camera: Camera::default(),
Expand Down
6 changes: 3 additions & 3 deletions crates/text/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::fmt;
use std::{num::NonZeroU32, ops::Deref, str::FromStr, sync::Arc};
use std::{ops::Deref, str::FromStr, sync::Arc};

use ambient_core::{asset_cache, async_ecs::async_run, gpu, mesh, runtime, transform::*, window::window_scale_factor};
use ambient_ecs::{components, ensure_has_component, query, Debuggable, Entity, SystemGroup};
Expand Down Expand Up @@ -306,8 +306,8 @@ pub fn systems(use_gpu: bool) -> SystemGroup {
tex_data,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(rect.width()),
rows_per_image: NonZeroU32::new(rect.height()),
bytes_per_row: Some(rect.width()),
rows_per_image: Some(rect.height()),
},
wgpu::Extent3d { width: rect.width(), height: rect.height(), depth_or_array_layers: 1 },
);
Expand Down

0 comments on commit 2089caa

Please sign in to comment.