Skip to content

vello_gpu: Optimize full-sized texture sampling - #1964

Draft
laurenz-canva wants to merge 1 commit into
laurenz/fix_bilinear_imagefrom
laurenz/test_image_fast_path
Draft

laurenz-canva wants to merge 1 commit into
laurenz/fix_bilinear_imagefrom
laurenz/test_image_fast_path

Conversation

@laurenz-canva

@laurenz-canva laurenz-canva commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a fast path for images where we want to sample the whole texture. When this is the case, we can make use of WebGL sampler objects to define whether to use NN/bilinear sampling as well as which extend mode to use, without us having to reimplement these operations in software! This is much faster, see this video and compare to the FPS numbers from #1963 instead:

IMG_1298.MOV

The only two downsides are that

  1. It makes our shaders even bigger.
  2. We need to reject non-filterable textures, which I don't think is a big deal for now. In the future, we can refine this so non-filterable textures are accepted again, as long as the user only uses ImageQuality::Low.

Once this (and the preceding PR) have been approved, I will make sure to rerun tests on other devices to ensure we are not creating any regressions by making the shader bigger.

@laurenz-canva
laurenz-canva marked this pull request as draft September 29, 2026 14:58
@laurenz-canva
laurenz-canva added this pull request to stack #1965 September 29, 2026 14:59
@laurenz-canva
laurenz-canva force-pushed the laurenz/test_image_fast_path branch from 048b162 to 42ba050 Compare September 29, 2026 15:08
@LaurenzV
LaurenzV force-pushed the laurenz/test_image_fast_path branch from 42ba050 to bfec171 Compare September 30, 2026 06:18
@laurenz-canva
laurenz-canva force-pushed the laurenz/test_image_fast_path branch 2 times, most recently from 5b66f7a to 9eaef9e Compare September 30, 2026 07:09
@laurenz-canva
laurenz-canva force-pushed the laurenz/test_image_fast_path branch from 9eaef9e to c31e48a Compare September 30, 2026 07:47
@laurenz-canva
laurenz-canva force-pushed the laurenz/test_image_fast_path branch 2 times, most recently from fa12eb3 to 597aa52 Compare September 30, 2026 08:42
Comment thread vello_common/src/paint.rs
Comment on lines +83 to +90
/// **It is important that the provided width and height match the actual dimensions of the
/// texture, otherwise, rendering might be corrupted!**
Full {
/// Width of the bound texture view.
width: u16,
/// Height of the bound texture view.
height: u16,
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, we could derive that information ourselves using textureDimensions in the shader. However, I faintly remember this being a performance footgun. Hence why I think it's better to require that information to be passed along.

);
out.sample_xy = get_native_image_translate(image_texel1)
+ get_native_image_transform(image_texel0) * pos;
out.payload = get_native_image_opacity(image_texel1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit annoying to abuse the payload like this. 😅 But it avoids having to do another texture sample in the fragment shader, as all the metadata we need is passed directly.

@LaurenzV
LaurenzV marked this pull request as ready for review September 30, 2026 08:58
@LaurenzV
LaurenzV requested a review from grebmeg September 30, 2026 08:58
Comment thread vello_gpu_shaders/shaders/render.wesl Outdated
(paint_and_rect_flag >> EXTERNAL_TEXTURE_SLOT_SHIFT) & 0x3u;

if external_texture_slot == 0u {
final_color = paint_alpha * textureSampleLevel(external_texture_0, external_sampler_0, sample_xy, 0.0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Use textureSample?

@LaurenzV
LaurenzV removed the request for review from grebmeg October 1, 2026 09:29
@LaurenzV
LaurenzV marked this pull request as draft October 1, 2026 09:30
@laurenz-canva
laurenz-canva force-pushed the laurenz/test_image_fast_path branch from 597aa52 to 340a2ca Compare October 1, 2026 10:58
@laurenz-canva
laurenz-canva removed this pull request from stack #1965 October 1, 2026 10:59
@laurenz-canva
laurenz-canva added this pull request to stack #1969 October 1, 2026 11:00

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants