Skip to content

Commit

Permalink
Fix expecting always Rgba8Unorm backbuffer on Web & Bgra8Unorm on nat…
Browse files Browse the repository at this point in the history
…ive (#1413)
  • Loading branch information
Wumpf authored Feb 27, 2023
1 parent 3f58921 commit 34123fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"cSpell.words": [
"andreas",
"bbox",
"framebuffer",
"hoverable",
"Keypoint",
"memoffset",
"nyud",
"objectron",
"Skybox",
"smallvec",
"swapchain",
"texcoords",
"Tonemapper",
"tonemapping",
Expand Down
22 changes: 15 additions & 7 deletions crates/re_renderer/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ struct Application<E> {
re_ctx: RenderContext,
}

// Same as egui_wgpu::preferred_framebuffer_format
fn preferred_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::TextureFormat {
for &format in formats {
if matches!(
format,
wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Bgra8Unorm
) {
return format;
}
}
formats[0] // take the first
}

impl<E: Example + 'static> Application<E> {
async fn new(event_loop: EventLoop<()>, window: Window) -> anyhow::Result<Self> {
let size = window.inner_size();
Expand Down Expand Up @@ -124,13 +137,8 @@ impl<E: Example + 'static> Application<E> {
let device = Arc::new(device);
let queue = Arc::new(queue);

// re_renderer is doing its own srgb conversion for each ViewBuilder for better egui compatibility.
let swapchain_format = if cfg!(target_arch = "wasm32") {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Bgra8Unorm
};

let swapchain_format =
preferred_framebuffer_format(&surface.get_capabilities(&adapter).formats);
let surface_config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: swapchain_format,
Expand Down
9 changes: 1 addition & 8 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,11 @@ pub(crate) fn customize_eframe(cc: &eframe::CreationContext<'_>) -> re_ui::ReUi

let paint_callback_resources = &mut render_state.renderer.write().paint_callback_resources;

// TODO(andreas): Query used surface format from eframe/renderer.
let output_format_color = if cfg!(target_arch = "wasm32") {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Bgra8Unorm
};

paint_callback_resources.insert(RenderContext::new(
render_state.device.clone(),
render_state.queue.clone(),
RenderContextConfig {
output_format_color,
output_format_color: render_state.target_format,
hardware_tier: crate::hardware_tier(),
},
));
Expand Down

1 comment on commit 34123fb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 34123fb Previous: 3f58921 Ratio
datastore/insert/batch/rects/insert 549163 ns/iter (± 2031) 555922 ns/iter (± 1478) 0.99
datastore/latest_at/batch/rects/query 1846 ns/iter (± 7) 1846 ns/iter (± 7) 1
datastore/latest_at/missing_components/primary 355 ns/iter (± 0) 355 ns/iter (± 1) 1
datastore/latest_at/missing_components/secondaries 423 ns/iter (± 3) 423 ns/iter (± 0) 1
datastore/range/batch/rects/query 152640 ns/iter (± 555) 155744 ns/iter (± 1574) 0.98
mono_points_arrow/generate_message_bundles 49140283 ns/iter (± 1710411) 50746760 ns/iter (± 855452) 0.97
mono_points_arrow/generate_messages 138227626 ns/iter (± 8448348) 138450113 ns/iter (± 1266860) 1.00
mono_points_arrow/encode_log_msg 164924427 ns/iter (± 2386829) 166405285 ns/iter (± 1714563) 0.99
mono_points_arrow/encode_total 355860002 ns/iter (± 2427617) 357795024 ns/iter (± 2316588) 0.99
mono_points_arrow/decode_log_msg 186595401 ns/iter (± 1287110) 186438444 ns/iter (± 1902222) 1.00
mono_points_arrow/decode_message_bundles 74760592 ns/iter (± 1537929) 75532242 ns/iter (± 1162133) 0.99
mono_points_arrow/decode_total 256120396 ns/iter (± 2077994) 256544353 ns/iter (± 1889458) 1.00
batch_points_arrow/generate_message_bundles 332919 ns/iter (± 2119) 334253 ns/iter (± 979) 1.00
batch_points_arrow/generate_messages 6210 ns/iter (± 53) 6199 ns/iter (± 21) 1.00
batch_points_arrow/encode_log_msg 370721 ns/iter (± 1954) 370015 ns/iter (± 2278) 1.00
batch_points_arrow/encode_total 726085 ns/iter (± 3905) 726272 ns/iter (± 3970) 1.00
batch_points_arrow/decode_log_msg 347020 ns/iter (± 1289) 348726 ns/iter (± 2051) 1.00
batch_points_arrow/decode_message_bundles 1985 ns/iter (± 15) 2035 ns/iter (± 10) 0.98
batch_points_arrow/decode_total 356050 ns/iter (± 1457) 354990 ns/iter (± 3195) 1.00
arrow_mono_points/insert 7141936290 ns/iter (± 18219870) 7018737013 ns/iter (± 21703766) 1.02
arrow_mono_points/query 1763477 ns/iter (± 12201) 1776141 ns/iter (± 19560) 0.99
arrow_batch_points/insert 2705162 ns/iter (± 21006) 2685442 ns/iter (± 32167) 1.01
arrow_batch_points/query 17519 ns/iter (± 139) 17434 ns/iter (± 479) 1.00
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.