Skip to content

Commit

Permalink
deps: wgpu -> 0.15
Browse files Browse the repository at this point in the history
This might help with #3032
  • Loading branch information
wez committed Feb 6, 2023
1 parent 44e162a commit 74dc74b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 38 deletions.
103 changes: 79 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wezterm-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ wezterm-mux-server-impl = { path = "../wezterm-mux-server-impl" }
wezterm-ssh = { path = "../wezterm-ssh" }
wezterm-term = { path = "../term", features=["use_serde"] }
wezterm-toast-notification = { path = "../wezterm-toast-notification" }
wgpu = "0.14"
wgpu = "0.15"
window = { path = "../window" }
window-funcs = { path = "../lua-api-crates/window-funcs" }

Expand Down
5 changes: 4 additions & 1 deletion wezterm-gui/src/scripting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> {
"enumerate_gpus",
lua.create_function(|_, _: ()| {
let backends = wgpu::Backends::all();
let instance = wgpu::Instance::new(backends);
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
..Default::default()
});
let gpus: Vec<GpuInfo> = instance
.enumerate_adapters(backends)
.map(|adapter| {
Expand Down
10 changes: 5 additions & 5 deletions wezterm-gui/src/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ struct VertexOutput {
};

// a regular monochrome text glyph
let IS_GLYPH: f32 = 0.0;
const IS_GLYPH: f32 = 0.0;

// a color emoji glyph
let IS_COLOR_EMOJI: f32 = 1.0;
const IS_COLOR_EMOJI: f32 = 1.0;

// a full color texture attached as the
// background image of the window
let IS_BG_IMAGE: f32 = 2.0;
const IS_BG_IMAGE: f32 = 2.0;

// like 2.0, except that instead of an
// image, we use the solid bg color
let IS_SOLID_COLOR: f32 = 3.0;
const IS_SOLID_COLOR: f32 = 3.0;

// Grayscale poly quad for non-aa text render layers
let IS_GRAY_SCALE: f32 = 4.0;
const IS_GRAY_SCALE: f32 = 4.0;

struct ShaderUniform {
foreground_text_hsb: vec3<f32>,
Expand Down
26 changes: 19 additions & 7 deletions wezterm-gui/src/termwindow/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl Texture2d for WebGpuTexture {

impl WebGpuTexture {
pub fn new(width: u32, height: u32, state: &WebGpuState) -> Self {
let format = wgpu::TextureFormat::Rgba8UnormSrgb;
let texture = state.device.create_texture(&wgpu::TextureDescriptor {
size: wgpu::Extent3d {
width,
Expand All @@ -129,9 +130,10 @@ impl WebGpuTexture {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
label: Some("Texture Atlas"),
view_formats: &[format, format.remove_srgb_suffix()],
});
Self {
texture,
Expand Down Expand Up @@ -197,8 +199,11 @@ impl WebGpuState {
config: &ConfigHandle,
) -> anyhow::Result<Self> {
let backends = wgpu::Backends::all();
let instance = wgpu::Instance::new(backends);
let surface = unsafe { instance.create_surface(&handle) };
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
..Default::default()
});
let surface = unsafe { instance.create_surface(&handle)? };

let mut adapter: Option<wgpu::Adapter> = None;

Expand Down Expand Up @@ -280,8 +285,8 @@ impl WebGpuState {

let adapter_info = adapter.get_info();
log::trace!("Using adapter: {adapter_info:?}");
let alpha_modes = surface.get_supported_alpha_modes(&adapter);
log::trace!("alpha modes: {alpha_modes:?}");
let caps = surface.get_capabilities(&adapter);
log::trace!("caps: {caps:?}");

let (device, queue) = adapter
.request_device(
Expand All @@ -302,17 +307,24 @@ impl WebGpuState {

let queue = Arc::new(queue);

// Explicitly request an SRGB format, if available
let format = caps.formats[0].add_srgb_suffix();

let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_supported_formats(&adapter)[0],
format,
width: dimensions.pixel_width as u32,
height: dimensions.pixel_height as u32,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: if alpha_modes.contains(&wgpu::CompositeAlphaMode::PostMultiplied) {
alpha_mode: if caps
.alpha_modes
.contains(&wgpu::CompositeAlphaMode::PostMultiplied)
{
wgpu::CompositeAlphaMode::PostMultiplied
} else {
wgpu::CompositeAlphaMode::Auto
},
view_formats: vec![format, format.remove_srgb_suffix()],
};
surface.configure(&device, &config);

Expand Down

0 comments on commit 74dc74b

Please sign in to comment.