Skip to content

Fix wgpu dpi scaling #42

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Fix wgpu dpi scaling #42

wants to merge 2 commits into from

Conversation

hazeycode
Copy link
Member

@hazeycode hazeycode commented May 5, 2025

Let the upstream Dear imgui backends do the DPI scaling and delete our mouse position hacks.

This fixes DPI scaling for glfw_wgpu backend (#3) but exposes a bug in Dawn's vulkan backend. We work around this by ensuring the viewport size is clamped. However, there remains a validation error that results in a crash if the window size is increased; this appears to be a bug in the imgui wgpu backend, where the render target is not resized before the viewport is set.

error: [zgpu] Validation: Viewport bounds (x: 0.000000, y: 0.000000, width: 1927.000000, height: 1206.000000) are not contained in the render target dimensions (1920 x 1200).
 - While encoding [RenderPassEncoder].SetViewport(0.000000, 0.000000, 1927.000000, 1206.000000, 0.000000, 1.000000).

This ought to be fixed or worked-around before this is merged.

Note: We're going to have to bring Dawn up to a newer version at some point but it's no small feat.

To test these changes, check out zig-gamedev/zig-gamedev#755 and run zig build triangle_wgpu-run.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes DPI scaling issues in the glfw_wgpu backend while also working around a Dawn/Vulkan viewport bug. Key changes include updating the viewport clamping in the wgpu backend, removing redundant mouse position hacks, and adjusting DPI scaling handling in the GLFW implementation.

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

File Description
libs/imgui/backends/imgui_impl_wgpu.h Removed superfluous macros and wrapped declarations in extern "C".
libs/imgui/backends/imgui_impl_wgpu.cpp Updated viewport calculation with integer clamping as a workaround for Dawn/Vulkan bug.
libs/imgui/backends/imgui_impl_glfw.h Added extern "C" block and updated comments regarding known issues.
libs/imgui/backends/imgui_impl_glfw.cpp Removed DPI scaling multiplications from mouse event callbacks and mouse data updates.
Files not reviewed (2)
  • build.zig: Language not supported
  • src/backend_glfw_wgpu.zig: Language not supported

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant