Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Example for glfw/WebGPU doesn’t build on newest Dawn on MacOS #8191

Open
raddad772 opened this issue Nov 28, 2024 · 5 comments
Open

Example for glfw/WebGPU doesn’t build on newest Dawn on MacOS #8191

raddad772 opened this issue Nov 28, 2024 · 5 comments

Comments

@raddad772
Copy link

Version/Branch of Dear ImGui:

Latest master

Back-ends:

imgui_impl_glfw.cpp

Compiler, OS:

MacOS Clang

Full config/build information:

No response

Details:

My Issue/Question:

Latest version of Dawn dropped the WGPUSwapChain, after they were deprecated for a while. You’re supposed to configure a Surface I guess? I don’t know webGPU this is just what the errors say

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();

Literally just try to compile the example code with latest Dawn on MacOS

@ocornut
Copy link
Owner

ocornut commented Nov 29, 2024

You are not providing the errors. Please provide details so we don't have to guess.

@BrutPitt
Copy link

BrutPitt commented Dec 12, 2024

Hi, @ocornut
I guess the problem in the new dawn release lies in the fact that direct access to Swap Chain (now hided to end user) has been removed (and also all the references to it), so WGPUSwapChain (used in wgpu ImGui example) is "undefined".

And this not only on MacOS, but on all platforms: now the configuration of internal swap chain is done through wgpuSurfaceConfigure.
You can view these changes in dawn here:
https://issues.chromium.org/issues/42241264

Anyway this is the error (for better understanding), building for desktop (WebGPU-native) on Linux:

/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:38:8: error: ‘WGPUSwapChain’ does not name a type
   38 | static WGPUSwapChain     wgpu_swap_chain = nullptr;
      |        ^~~~~~~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp: In function ‘int main(int, char**)’:
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:226:69: error: ‘wgpu_swap_chain’ was not declared in this scope; did you mean ‘wgpu_swap_chain_width’?
  226 |         color_attachments.view = wgpuSwapChainGetCurrentTextureView(wgpu_swap_chain);
      |                                                                     ^~~~~~~~~~~~~~~
      |                                                                     wgpu_swap_chain_width
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:226:34: error: ‘wgpuSwapChainGetCurrentTextureView’ was not declared in this scope; did you mean ‘wgpuSurfaceGetCurrentTexture’?
  226 |         color_attachments.view = wgpuSwapChainGetCurrentTextureView(wgpu_swap_chain);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                  wgpuSurfaceGetCurrentTexture
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:246:9: error: ‘wgpuSwapChainPresent’ was not declared in this scope; did you mean ‘wgpuSurfacePresent’?
  246 |         wgpuSwapChainPresent(wgpu_swap_chain);
      |         ^~~~~~~~~~~~~~~~~~~~
      |         wgpuSurfacePresent
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp: In function ‘WGPUAdapterImpl* RequestAdapter(WGPUInstance)’:
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:280:51: error: invalid user-defined conversion from ‘RequestAdapter(WGPUInstance)::<lambda(WGPURequestAdapterStatus, WGPUAdapter, const char*, void*)>’ to ‘WGPURequestAdapterCallback’ {aka ‘void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl*, WGPUStringView, void*)’} [-fpermissive]
  280 |     wgpuInstanceRequestAdapter(instance, nullptr, onAdapterRequestEnded, (void*)&adapter);
      |                                                   ^~~~~~~~~~~~~~~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:272:34: note: candidate is: ‘constexpr RequestAdapter(WGPUInstance)::<lambda(WGPURequestAdapterStatus, WGPUAdapter, const char*, void*)>::operator void (*)(WGPURequestAdapterStatus, WGPUAdapter, const char*, void*)() const’ (near match)
  272 |     auto onAdapterRequestEnded = [](WGPURequestAdapterStatus status, WGPUAdapter adapter, const char* message, void* pUserData)
      |                                  ^
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:272:34: note:   no known conversion from ‘void (*)(WGPURequestAdapterStatus, WGPUAdapter, const char*, void*)’ {aka ‘void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl*, const char*, void*)’} to ‘WGPURequestAdapterCallback’ {aka ‘void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl*, WGPUStringView, void*)’}
In file included from /opt/dawn/include/webgpu/webgpu.h:31,
                 from /winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/../../backends/imgui_impl_wgpu.h:31,
                 from /winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:13:
/RamDisk/example_glfw_wgpu/debug/dawn/gen/include/dawn/webgpu.h:4098:152: note:   initializing argument 3 of ‘void wgpuInstanceRequestAdapter(WGPUInstance, const WGPURequestAdapterOptions*, WGPURequestAdapterCallback, void*)’
 4098 | WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE;
      |                                                                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp: In function ‘WGPUDeviceImpl* RequestDevice(WGPUAdapterImpl*&)’:
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:294:48: error: invalid user-defined conversion from ‘RequestDevice(WGPUAdapterImpl*&)::<lambda(WGPURequestDeviceStatus, WGPUDevice, const char*, void*)>’ to ‘WGPURequestDeviceCallback’ {aka ‘void (*)(WGPURequestDeviceStatus, WGPUDeviceImpl*, WGPUStringView, void*)’} [-fpermissive]
  294 |     wgpuAdapterRequestDevice(adapter, nullptr, onDeviceRequestEnded, (void*)&device);
      |                                                ^~~~~~~~~~~~~~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:286:33: note: candidate is: ‘constexpr RequestDevice(WGPUAdapterImpl*&)::<lambda(WGPURequestDeviceStatus, WGPUDevice, const char*, void*)>::operator void (*)(WGPURequestDeviceStatus, WGPUDevice, const char*, void*)() const’ (near match)
  286 |     auto onDeviceRequestEnded = [](WGPURequestDeviceStatus status, WGPUDevice device, const char* message, void* pUserData)
      |                                 ^
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:286:33: note:   no known conversion from ‘void (*)(WGPURequestDeviceStatus, WGPUDevice, const char*, void*)’ {aka ‘void (*)(WGPURequestDeviceStatus, WGPUDeviceImpl*, const char*, void*)’} to ‘WGPURequestDeviceCallback’ {aka ‘void (*)(WGPURequestDeviceStatus, WGPUDeviceImpl*, WGPUStringView, void*)’}
/RamDisk/example_glfw_wgpu/debug/dawn/gen/include/dawn/webgpu.h:3960:145: note:   initializing argument 3 of ‘void wgpuAdapterRequestDevice(WGPUAdapter, const WGPUDeviceDescriptor*, WGPURequestDeviceCallback, void*)’
 3960 | WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE;
      |                                                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp: In function ‘bool InitWGPU(GLFWwindow*)’:
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:333:5: error: ‘wgpuDeviceSetUncapturedErrorCallback’ was not declared in this scope; did you mean ‘WGPUUncapturedErrorCallback’?
  333 |     wgpuDeviceSetUncapturedErrorCallback(wgpu_device, wgpu_error_callback, nullptr);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     WGPUUncapturedErrorCallback
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp: In function ‘void CreateSwapChain(int, int)’:
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:340:9: error: ‘wgpu_swap_chain’ was not declared in this scope; did you mean ‘wgpu_swap_chain_width’?
  340 |     if (wgpu_swap_chain)
      |         ^~~~~~~~~~~~~~~
      |         wgpu_swap_chain_width
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:341:9: error: ‘wgpuSwapChainRelease’ was not declared in this scope; did you mean ‘wgpuSurfaceRelease’?
  341 |         wgpuSwapChainRelease(wgpu_swap_chain);
      |         ^~~~~~~~~~~~~~~~~~~~
      |         wgpuSurfaceRelease
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:344:5: error: ‘WGPUSwapChainDescriptor’ was not declared in this scope; did you mean ‘WGPUSurfaceDescriptor’?
  344 |     WGPUSwapChainDescriptor swap_chain_desc = {};
      |     ^~~~~~~~~~~~~~~~~~~~~~~
      |     WGPUSurfaceDescriptor
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:345:5: error: ‘swap_chain_desc’ was not declared in this scope
  345 |     swap_chain_desc.usage = WGPUTextureUsage_RenderAttachment;
      |     ^~~~~~~~~~~~~~~
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:350:5: error: ‘wgpu_swap_chain’ was not declared in this scope; did you mean ‘wgpu_swap_chain_width’?
  350 |     wgpu_swap_chain = wgpuDeviceCreateSwapChain(wgpu_device, wgpu_surface, &swap_chain_desc);
      |     ^~~~~~~~~~~~~~~
      |     wgpu_swap_chain_width
/winDW/-=DW=-/imgui-docking.1.91.5/examples/example_glfw_wgpu/main.cpp:350:23: error: ‘wgpuDeviceCreateSwapChain’ was not declared in this scope; did you mean ‘wgpuDeviceCreateSampler’?
  350 |     wgpu_swap_chain = wgpuDeviceCreateSwapChain(wgpu_device, wgpu_surface, &swap_chain_desc);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                       wgpuDeviceCreateSampler
[1089/1091] Building CXX object dawn/src/dawn/native/CMakeFiles/webgpu_dawn.dir/vulkan/VulkanBackend.cpp.o

@ocornut
Copy link
Owner

ocornut commented Feb 3, 2025

A PR for this would be great.

@BrutPitt
Copy link

BrutPitt commented Feb 6, 2025

Hi Omar.

I rewrite/correct the example and it works... ALMOST.

Let me explain better:
The application works (and should work) well, but I receive "sporadically" the following message from the callback of the Validation Layer

Validation error: Viewport bounds (x: 0.000000, y: 0.000000, width: 2393.000000, height: 1560.000000) are not contained in the render target dimensions (2381 x 1557).
 - While encoding [RenderPassEncoder (unlabeled)].SetViewport(0.000000, 0.000000, 2393.000000, 1560.000000, 0.000000, 1.000000).
 - While finishing [CommandEncoder (unlabeled)].

This comes from: imgui_impl_wgpu.cpp (wgpuRenderPassEncoderSetViewport)

The reason seems to be due to the discrepancy between ImGui::GetDrawData()->DisplaySize and the FrameBufferSize returned from glfwGetFramebufferSize (tried also with glfwGetWindowSize ).
As I said it does not always happen, only when I "enlarge" the window, and only occasionally.
It seems that the acquisition of the two dimensions takes place in different moments and (sometimes) with different sizes.
In fact, if changing the imgui_impl_wgpu file and inserting the same FrameBufferSize reported by "SAME" GLFW call in wgpuRenderPassEncoderSetViewport (and the surface size), the problem disappears.

(Obviously it also concerns wgpuRenderPassEncoderSetScissorRect in same file: same reasoning as before)
This does not happen when the window is reduced because the "previous" surface (before resizing) is always bigger than viewport.
And it happens (obviously) also in EMSCRIPTEN

In any case, it's like a WARNING in Debug mode (disappear in Release: missing ValidationLayer) even if it is a little frustrating in Emscripten, but I would like to learn more (before to make a PR).
For this reason I asked you had suggested where to investigate in ImGui or if I could show me where ImGui acquires the FrameBufferSize (I found where ImGui get FrameBufferSize: in ImGui_ImplGlfw_NewFrame).

P.S.
Currently tested in Linux and EMSCIPTEN, later test it also in Windows

About the example

I noticed that, in the old example during the initialization, was used the classes encapsulated by wgpu:: (to get Instance and create Surface), so given that have been also changed (from Google) the functions wgpuAdapterRequestDevice and wgpuInstanceRequestAdapter (has been eliminated the 4th parameter: user_data), I used these classes to initialize Adapter and Device (only in InitWGPU and only for Native)

@BrutPitt
Copy link

BrutPitt commented Feb 6, 2025

And I add:

In Windows the Validation Layer message don't appear.
Perhaps because (I noticed) the up/down-sizing mechanism is different (or it has been changed): the content of the window (current Surface) remains not modified (it's only "stretches") until the mouse is not released, while in Linux and EMSCRIPTEN the sizes change anytime while dragging window border.
But this also depends on the backend used (Vulkan, DX, etc.) by Dawn in current OS

Anyway, I have just update DAWN (from 23 Jan)... and the example have already trouble to compile :

  • struct WGPUVertexAttribute now have a new WGPUChainedStruct* nextInChain element, so in place initialization fails in imgui_impl_wgpu, and it's NOT present in WEB release (EMSCRIPTEN) ... for now.
  • enum WGPUErrorType_DeviceLost changes in WGPUErrorType_Internal for UncapturedError callback func
  • instanceDescriptor.features changes in instanceDescriptor.capabilities in WGPUInstanceDescriptor

So I imagine it also makes little sense to waste many time on something in constant evolution / change and still in the experimental phase.

Later check last things and this evening, or later tomorrow, I send the PR
... and (I hope) before that Google make other changes in Dawn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants