Skip to content

Commit

Permalink
Update to wgpu 0.15
Browse files Browse the repository at this point in the history
addresses AmbientRun#27
  • Loading branch information
kevzettler committed Apr 17, 2023
1 parent 6b97e56 commit 364bc81
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 225 deletions.
310 changes: 91 additions & 219 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.14.2"
wgpu = "0.15.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: 2 additions & 0 deletions crates/app/src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl UIRender {
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Snorm,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[]
},
));

Expand Down Expand Up @@ -298,6 +299,7 @@ impl UIRender {
dimension: wgpu::TextureDimension::D2,
format: DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_SRC,
view_formats: &[]
},
)
}
Expand Down
16 changes: 11 additions & 5 deletions crates/gpu/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use ambient_std::asset_cache::SyncAssetKey;
use bytemuck::{Pod, Zeroable};
use glam::{uvec2, UVec2, UVec3, UVec4, Vec2, Vec3, Vec4};
use wgpu::{PresentMode, TextureFormat};
use wgpu::{PresentMode, TextureFormat, InstanceDescriptor};
use winit::window::Window;

// #[cfg(debug_assertions)]
Expand Down Expand Up @@ -48,8 +48,13 @@ impl Gpu {
#[cfg(target_os = "unknown")]
let backend = wgpu::Backends::all();

let instance = wgpu::Instance::new(backend);
let surface = window.map(|window| unsafe { instance.create_surface(window) });
let instance = wgpu::Instance::new(InstanceDescriptor{
backends: backend,
// TODO upgrade to Dxc ?
// https://docs.rs/wgpu/latest/wgpu/enum.Dx12Compiler.html
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc
});
let surface = window.map(|window| unsafe { instance.create_surface(window).unwrap()});
#[cfg(not(target_os = "unknown"))]
{
tracing::debug!("Available adapters:");
Expand Down Expand Up @@ -99,9 +104,9 @@ impl Gpu {

tracing::info!("Device limits:\n{:#?}", device.limits());

let swapchain_format = surface.as_ref().map(|surface| surface.get_supported_formats(&adapter)[0]);
let swapchain_format = surface.as_ref().map(|surface| surface.get_capabilities(&adapter).formats[0]);
tracing::debug!("Swapchain format: {swapchain_format:?}");
let swapchain_mode = surface.as_ref().map(|surface| surface.get_supported_present_modes(&adapter)).as_ref().map(|modes| {
let swapchain_mode = surface.as_ref().map(|surface| surface.get_capabilities(&adapter).present_modes).as_ref().map(|modes| {
[PresentMode::Immediate, PresentMode::Fifo, PresentMode::Mailbox]
.into_iter()
.find(|pm| modes.contains(pm))
Expand Down Expand Up @@ -143,6 +148,7 @@ impl Gpu {
height: size.y,
present_mode,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![]
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/gpu/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl Texture {
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::RENDER_ATTACHMENT,
label,
view_formats: &[]
},
);
texture.write(image.as_raw());
Expand All @@ -147,6 +148,7 @@ impl Texture {
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label,
view_formats: &[]
},
&img.into_vec(),
)
Expand Down Expand Up @@ -177,6 +179,7 @@ impl Texture {
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::RENDER_ATTACHMENT,
label,
view_formats: &[]
},
);
for (layer, img) in data.into_iter().enumerate() {
Expand Down Expand Up @@ -224,6 +227,7 @@ impl Texture {
format: wgpu::TextureFormat::R32Float,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("texture"),
view_formats: &[]
},
bytemuck::cast_slice(data.as_slice().unwrap()),
)
Expand Down Expand Up @@ -282,6 +286,7 @@ impl Texture {
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Texture.new_single_color_texture"),
view_formats: &[]
},
bytemuck::cast_slice(&[color.x as u8, color.y as u8, color.z as u8, color.w as u8]),
)
Expand All @@ -298,6 +303,7 @@ impl Texture {
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("default_texture"),
view_formats: &[]
},
bytemuck::cast_slice(
&colors.into_iter().flat_map(|color| vec![color.x as u8, color.y as u8, color.z as u8, color.w as u8]).collect_vec(),
Expand Down
1 change: 1 addition & 0 deletions crates/renderer/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ fn create_dummy_shadow_texture(gpu: Arc<Gpu>) -> Arc<Texture> {
dimension: wgpu::TextureDimension::D2,
format: DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[]
},
))
}
Expand Down
1 change: 1 addition & 0 deletions crates/renderer/src/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl Outlines {
dimension: wgpu::TextureDimension::D2,
format: Self::FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[]
},
))
}
Expand Down
1 change: 1 addition & 0 deletions crates/renderer/src/shadow_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ShadowsRenderer {
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::COPY_DST,
view_formats: &[]
},
));

Expand Down
3 changes: 3 additions & 0 deletions crates/renderer/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl RenderTarget {
dimension: wgpu::TextureDimension::D2,
format: DEPTH_FORMAT,
usage,
view_formats: &[]
},
));
let color_buffer = Arc::new(Texture::new(
Expand All @@ -61,6 +62,7 @@ impl RenderTarget {
dimension: wgpu::TextureDimension::D2,
format: sc_desc.format,
usage,
view_formats: &[]
},
));
let normals_buffer = Arc::new(Texture::new(
Expand All @@ -73,6 +75,7 @@ impl RenderTarget {
dimension: wgpu::TextureDimension::D2,
format: to_linear_format(sc_desc.format),
usage,
view_formats: &[]
},
));
Self {
Expand Down
2 changes: 2 additions & 0 deletions crates/text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub fn systems(use_gpu: bool) -> SystemGroup {
format: wgpu::TextureFormat::R8Unorm,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Text.texture"),
view_formats: &[]
},
));
let texture_view = Arc::new(texture.create_view(&wgpu::TextureViewDescriptor::default()));
Expand Down Expand Up @@ -343,6 +344,7 @@ pub fn systems(use_gpu: bool) -> SystemGroup {
format: wgpu::TextureFormat::R8Unorm,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Text.texture"),
view_formats: &[]
},
));
glyph_brush.lock().resize_texture(suggested.0, suggested.1);
Expand Down

0 comments on commit 364bc81

Please sign in to comment.