Skip to content

Conversation

@SergeyLebedkin
Copy link
Member

Fix sampler setings for un-premultiplied images by updating sampler for images

image

#4041

@SergeyLebedkin SergeyLebedkin self-assigned this Dec 18, 2025
Copilot AI review requested due to automatic review settings December 18, 2025 13:50
@SergeyLebedkin SergeyLebedkin added bug Something isn't working webgpu WebGPU render backend labels Dec 18, 2025
Copy link

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 PR fixes an alpha premultiplication bug in the WebGPU rendering engine by introducing a new sampler specifically configured for image rendering. The fix addresses issue #4041 where images were being rendered with incorrect alpha blending due to using a generic linear clamp sampler instead of a properly configured image sampler.

Key Changes:

  • Added a new samplerImages with different min/mag filter settings optimized for image rendering
  • Updated WgImageData to use the new image-specific sampler instead of the generic linear clamp sampler
  • Introduced a new overloaded createSampler method to support different min/mag filter configurations

Reviewed changes

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

File Description
tvgWgRenderData.cpp Updates bind group creation to use the new samplerImages instead of samplerLinearClamp
tvgWgCommon.h Declares the new samplerImages member and overloaded createSampler method
tvgWgCommon.cpp Implements initialization, cleanup, and creation logic for the new image sampler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SergeyLebedkin SergeyLebedkin force-pushed the sergii/webgpu_alpha_premultiplied_bug branch from 96529cc to 9777920 Compare December 18, 2025 13:52
Fix sampler setings for un-premultiplied images

#4041
@SergeyLebedkin SergeyLebedkin force-pushed the sergii/webgpu_alpha_premultiplied_bug branch from 9777920 to dffcc08 Compare December 18, 2025 13:57
Copilot AI review requested due to automatic review settings December 18, 2025 13:57
Copy link

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tinyjin
Copy link
Member

tinyjin commented Dec 19, 2025

CleanShot 2025-12-19 at 14 46 14@2x

Visual testing 👉 Rendering correctly in web.

@hermet
Copy link
Member

hermet commented Dec 19, 2025

Fix sampler setings for un-premultiplied images by updating sampler for images

image #4041

@SergeyLebedkin Please test on the thorvg viewer. Thanks.

@wenjieshen
Copy link
Collaborator

wenjieshen commented Dec 19, 2025

Hi @SergeyLebedkin,

Thank you for the PR. I tested it and noticed a regression when scaling the image to 4×.

To address this, I’d like to suggest pre-multiplying the alpha channel before storing the image into the drawing texture. Would you be open to handling this step with GPGPU via WebGPU in the PR? I think doing the premultiply as a lightweight compute pass (or equivalent) could keep the cost low and avoid CPU-side preprocessing.

Thanks again for taking a look.

image

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

Labels

bug Something isn't working webgpu WebGPU render backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants