GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — WebGPU sampler set to WGPUAddressMode_Repeat causes image rendering issues · Issue #7511 · ocornut/imgui

WebGPU sampler set to WGPUAddressMode_Repeat causes image rendering issues #7511

New issue
Copy link
New issue
Copy link
Closed
Closed
WebGPU sampler set to WGPUAddressMode_Repeat causes image rendering issues#7511
Copy link
Labels
backendswebemscripten, wgpu etc.

Description

@ypujante
ypujante
opened on Apr 19, 2024
Issue body actions

Version/Branch of Dear ImGui:

master

Back-ends:

imgui_impl_wgpu.cpp

Compiler, OS:

macOS 13.6.6

Full config/build information:

Dear ImGui 1.90.4 (19040)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: __APPLE__
define: __GNUC__=4
define: __clang_version__=15.0.0 (clang-1500.0.40.1)
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_webgpu
io.ConfigFlags: 0x00000000
io.ConfigMacOSXBehaviors
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1400.00,900.00
io.DisplayFramebufferScale: 2.00,2.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

I was working on porting my ImGui desktop application to webgpu (Dawn) and I noticed this issue. See screenshot attached.

I have an image that I render like this:

      // kAudioJack is a texture loaded in webgpu and I keep a record of its size
      ImGui::SliderFloat("scale", &kScale, 0.1f, 2.0f);
      ImGui::Image(kAudioJack->getAsImTextureID(), {kAudioJack->fSize.x * kScale, kAudioJack->fSize.y * kScale});

As I move the scale slider, there are instances where the left of the image bleeds on the right side as can be seen on the screenshot (you can see a grey vertical line corresponding to the left edge of the image). In the ImGui demo, you can see that the bottom of the triangle bleeds on the top... The issue comes from this section in the code where the sampler is defined:

// imgui_impl_wgpu.cpp line 535
        WGPUSamplerDescriptor sampler_desc = {};
        sampler_desc.minFilter = WGPUFilterMode_Linear;
        sampler_desc.magFilter = WGPUFilterMode_Linear;
        sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
        sampler_desc.addressModeU = WGPUAddressMode_Repeat;
        sampler_desc.addressModeV = WGPUAddressMode_Repeat;
        sampler_desc.addressModeW = WGPUAddressMode_Repeat;
        sampler_desc.maxAnisotropy = 1;
        bd->renderResources.Sampler = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);

Using WGPUAddressMode_ClampToEdge instead of WGPUAddressMode_Repeat fixes this issue entirely.

In other backends, for example OpenGL, because it is completely statefull it is easy to change this kind of parameter outside of ImGui. But with WebGPU, because it is stateless, there is no way to change it besides changing the (ImGui) code.

I can think of 2 ways to address the issue:

a) change the code in ImGui directly to use WGPUAddressMode_ClampToEdge instead of WGPUAddressMode_Repeat
b) add a define for this value that the user can override in imgui_config.h

I think a) is the right approach because I feel like this is an issue (= a bug) with ImGui: any texture that has data on any side will simply get repeated if the texture is scaled. It is not due to my code or my texture.

Screenshots/Video:

From my personal testing:
Screenshot 2024-04-19 at 10 30 36

From code example:
Screenshot 2024-04-19 at 11 01 26

Actually it is visible in the demo window. It is just harder to see because the image has a border, but it is there (I circled it in red)
Screenshot 2024-04-19 at 11 04 44

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
    static float kScale = 1.0f;
    ImGui::SliderFloat("scale", &kScale, 0.1f, 2.0f);
    auto &io = ImGui::GetIO();
    ImTextureID my_tex_id = io.Fonts->TexID;
    float my_tex_w = (float)io.Fonts->TexWidth;
    float my_tex_h = (float)io.Fonts->TexHeight;
    ImGui::Image(my_tex_id, {my_tex_w * kScale, my_tex_h * kScale});

Activity

  1. ypujante commented on Apr 20, 2024

    @ypujante
    ypujante
    on Apr 20, 2024
    ContributorAuthor
    More actions

    I actually realized that I have an example that I built a while ago (for the PR that I closed pending some changes that I will re-issue later on) and that also demonstrates the problem:

    https://pongasoft.github.io/imgui/pr-7151/

    This is a emscripten/wgpu example

    Simply go to the Widgets/Images example and you can clearly see the artifacts of not clamping to edge...

    Screenshot 2024-04-20 at 07 47 00
  2. ypujante commented on Apr 20, 2024

    @ypujante
    ypujante
    on Apr 20, 2024
    ContributorAuthor
    More actions

    This PR #7468 by @JulesFouchy is the fix for this issue

  3. ocornut
    added
    backends
    webemscripten, wgpu etc.
    on Apr 22, 2024
  4. ocornut
    changed the title [-]Webgpu sampler set to WGPUAddressMode_Repeat causes image rendering issues[/-] [+]WebGPU sampler set to WGPUAddressMode_Repeat causes image rendering issues[/+] on May 3, 2024
  5. ocornut
    added a commit that references this issue on Oct 7, 2024

    Backends: DX9, DX10, DX11, DX12, OpenGL, Vulkan, WGPU: Changed defaul…

    42206b3
  6. ocornut commented on Oct 7, 2024

    @ocornut
    ocornut
    on Oct 7, 2024
    Owner
    More actions

    I have pushed a wider change 42206b3
    See #7230 (comment) for more details.

  7. ocornut
    closed this as completedon Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendswebemscripten, wgpu etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.