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

Dawn WebGPU Strings #8082

Open
nchavez324 opened this issue Oct 21, 2024 · 0 comments · May be fixed by #8083
Open

Dawn WebGPU Strings #8082

nchavez324 opened this issue Oct 21, 2024 · 0 comments · May be fixed by #8083

Comments

@nchavez324
Copy link

Version/Branch of Dear ImGui:

Version 1.91.4, Branch: master

Back-ends:

imgui_impl_wgpu.cpp + imgui_impl_glfw.cpp

Compiler, OS:

macOS 14.7 + Clang 15

Full config/build information:

No response

Details:

My Issue/Question:

When using Dawn for WebGPU at head (as of writing, this commit) with GLFW (also at head) on macOS targeting macOS with CMake, the following build errors are triggered:

[build] /Users/nickchavez/src/wgpu_imgui_bug/external/imgui/backends/imgui_impl_wgpu.cpp:281:27: error: no viable overloaded '='
[build]     stage_desc.entryPoint = "main";
[build]     ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~
[build] /Users/nickchavez/src/wgpu_imgui_bug/build/default/external/dawn/gen/include/dawn/webgpu.h:2384:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const char[5]' to 'const WGPUStringView' for 1st argument
[build] typedef struct WGPUStringView {
[build]                ^
[build] /Users/nickchavez/src/wgpu_imgui_bug/build/default/external/dawn/gen/include/dawn/webgpu.h:2384:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'const char[5]' to 'WGPUStringView' for 1st argument
[build] 1 error generated.

and the similar:

[build] /Users/nickchavez/src/wgpu_imgui_bug/external/imgui/backends/imgui_impl_wgpu.cpp:532:24: error: no viable overloaded '='
[build]         tex_desc.label = "Dear ImGui Font Texture";
[build]         ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
[build] /Users/nickchavez/src/wgpu_imgui_bug/build/default/external/dawn/gen/include/dawn/webgpu.h:2384:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const char[24]' to 'const WGPUStringView' for 1st argument
[build] typedef struct WGPUStringView {
[build]                ^
[build] /Users/nickchavez/src/wgpu_imgui_bug/build/default/external/dawn/gen/include/dawn/webgpu.h:2384:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'const char[24]' to 'WGPUStringView' for 1st argument
[build] 1 error generated.

It seems that for the Dawn backend, these lines need to be rewritten as such:

#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
    stage_desc.entryPoint = { "main", WGPU_STRLEN };
#else
    stage_desc.entryPoint = "main";
#endif
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
        tex_desc.label = { "Dear ImGui Font Texture", WGPU_STRLEN };
#else
        tex_desc.label = "Dear ImGui Font Texture";
#endif

Even when these are fixed however, the following runtime WGPU errors are produced:

Binding size (80) is larger than the size (0) of [Buffer "Dear ImGui Uniform buffer
Value 115200 is invalid for WGPUBufferUsage.
 - While calling [Device].CreateBuffer([BufferDescriptor ""Dear ImGui Vertex buffer

Value 22544 is invalid for WGPUBufferUsage.
 - While calling [Device].CreateBuffer([BufferDescriptor ""Dear ImGui Index buffer
 
[Invalid Buffer "Dear ImGui Vertex buffer
[Invalid Buffer "Dear ImGui Index buffer
Write range (bufferOffset: 0, size: 64) does not fit in [Buffer "Dear ImGui Uniform buffer
Write range (bufferOffset: 64, size: 4) does not fit in [Buffer "Dear ImGui Uniform buffer
[Invalid Buffer "Dear ImGui Vertex buffer
[Invalid CommandBuffer] is invalid.
 - While calling [Queue].Submit([[Invalid CommandBuffer]])

which point to the following lines, which likely should be corrected as:

  WGPUBufferDescriptor vb_desc =
  {
      nullptr,
      "Dear ImGui Vertex buffer", WGPU_STRLEN, // add WGPU_STRLEN here
      WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex,
      MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4),
      false
  };
  WGPUBufferDescriptor ib_desc =
  {
      nullptr,
      "Dear ImGui Index buffer", WGPU_STRLEN, // add WGPU_STRLEN here
      WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index,
      MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4),
      false
  };
  WGPUBufferDescriptor ub_desc =
  {
      nullptr,
      "Dear ImGui Uniform buffer", WGPU_STRLEN, // add WGPU_STRLEN here
      WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform,
      MEMALIGN(sizeof(Uniforms), 16),
      false
  };

Since WGPUBufferDescriptor's WGPU_BUFFER_DESCRIPTOR_INIT convenience initializer has a field label which has its own WGPU_STRING_VIEW_INIT convenience initializer which now takes 2 arguments, the label's value and its length.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Minimal code example: https://github.com/nchavez324/wgpu_imgui_bug/blob/main/main.cc

@nchavez324 nchavez324 linked a pull request Oct 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants