1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Update wgpu to 0.13 (#1670)

* Update the wgsl syntax used in egui-wgpu

* Updates for the latest version of wgpu

* Update the wgpu version

* get_preffered_format -> get_supported_formats

* Just use an array access for compatible formats

* Use the naga cli to validate the egui demo app custom wgpu shader

* Run cargo check on the custom3d wgpu app

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Ashley
2022-07-03 15:43:39 +02:00
committed by GitHub
parent 433719717a
commit 9739009f20
8 changed files with 92 additions and 74 deletions

View File

@@ -40,7 +40,7 @@ egui = { version = "0.18.1", path = "../egui", default-features = false, feature
bytemuck = "1.7"
tracing = "0.1"
type-map = "0.5.0"
wgpu = "0.12"
wgpu = "0.13"
#! ### Optional dependencies
## Enable this when generating docs.

View File

@@ -1,15 +1,18 @@
// Vertex shader bindings
struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[location(1)]] color: vec4<f32>;
[[builtin(position)]] position: vec4<f32>;
@location(0) tex_coord: vec2<f32>,
@location(1) color: vec4<f32>,
@builtin(position) position: vec4<f32>,
};
struct Locals {
screen_size: vec2<f32>;
screen_size: vec2<f32>,
// Uniform buffers need to be at least 16 bytes in WebGL.
// See https://github.com/gfx-rs/wgpu/issues/2072
_padding: vec2<u32>,
};
[[group(0), binding(0)]] var<uniform> r_locals: Locals;
@group(0) @binding(0) var<uniform> r_locals: Locals;
// 0-1 from 0-255
fn linear_from_srgb(srgb: vec3<f32>) -> vec3<f32> {
@@ -38,11 +41,11 @@ fn position_from_screen(screen_pos: vec2<f32>) -> vec4<f32> {
);
}
[[stage(vertex)]]
@vertex
fn vs_main(
[[location(0)]] a_pos: vec2<f32>,
[[location(1)]] a_tex_coord: vec2<f32>,
[[location(2)]] a_color: u32,
@location(0) a_pos: vec2<f32>,
@location(1) a_tex_coord: vec2<f32>,
@location(2) a_color: u32,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = a_tex_coord;
@@ -52,11 +55,11 @@ fn vs_main(
return out;
}
[[stage(vertex)]]
@vertex
fn vs_conv_main(
[[location(0)]] a_pos: vec2<f32>,
[[location(1)]] a_tex_coord: vec2<f32>,
[[location(2)]] a_color: u32,
@location(0) a_pos: vec2<f32>,
@location(1) a_tex_coord: vec2<f32>,
@location(2) a_color: u32,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = a_tex_coord;
@@ -68,10 +71,10 @@ fn vs_conv_main(
// Fragment shader bindings
[[group(1), binding(0)]] var r_tex_color: texture_2d<f32>;
[[group(1), binding(1)]] var r_tex_sampler: sampler;
@group(1) @binding(0) var r_tex_color: texture_2d<f32>;
@group(1) @binding(1) var r_tex_sampler: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color * textureSample(r_tex_color, r_tex_sampler, in.tex_coord);
}

View File

@@ -148,7 +148,7 @@ impl RenderPass {
label: Some("egui_shader"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("egui.wgsl"))),
};
let module = device.create_shader_module(&shader);
let module = device.create_shader_module(shader);
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("egui_uniform_buffer"),
@@ -258,7 +258,7 @@ impl RenderPass {
fragment: Some(wgpu::FragmentState {
module: &module,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: output_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
@@ -273,7 +273,7 @@ impl RenderPass {
},
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
multiview: None,
});
@@ -307,14 +307,14 @@ impl RenderPass {
};
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: color_attachment,
resolve_target: None,
ops: wgpu::Operations {
load: load_operation,
store: true,
},
}],
})],
depth_stencil_attachment: None,
label: Some("egui main render pass"),
});

View File

@@ -114,7 +114,7 @@ impl<'a> Painter<'a> {
if self.render_state.is_none() {
let adapter = self.adapter.as_ref().unwrap();
let swapchain_format = surface.get_preferred_format(adapter).unwrap();
let swapchain_format = surface.get_supported_formats(adapter)[0];
let rs = pollster::block_on(self.init_render_state(adapter, swapchain_format));
self.render_state = Some(rs);