Dawn WebGPU Strings #8082

Closed
opened 2024-10-21 12:05:25 +00:00 by nchavez324 · 0 comments
nchavez324 commented 2024-10-21 12:05:25 +00:00 (Migrated from github.com)

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

### 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](https://dawn.googlesource.com/dawn/) for WebGPU at head (as of writing, [this commit](https://dawn.googlesource.com/dawn/+/ecf224df05e711fe7009fbd76840301fb82bde1a)) 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: ```cpp #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN stage_desc.entryPoint = { "main", WGPU_STRLEN }; #else stage_desc.entryPoint = "main"; #endif ``` ```cpp #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: ```cpp 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
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#8082
No description provided.