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

Premultiply the alpha on the GPU #2190

Merged
merged 4 commits into from
May 24, 2023
Merged

Premultiply the alpha on the GPU #2190

merged 4 commits into from
May 24, 2023

Conversation

emilk
Copy link
Member

@emilk emilk commented May 23, 2023

What

Premultiplying on the GPU saves us A LOT of CPU time when loading e.g. a png. But texture filtering must happen AFTER premultiplying, which means we need to do texture filtering in software on the shader.

Checklist

PR Build Summary: https://build.rerun.io/pr/2190

Premultiplying on the GPU saves us A LOT of cpu.

But texture filtering must happen AFTER premultiplying, which means
we need to do texture filtering in software on the shader.
@emilk emilk added 🔺 re_renderer affects re_renderer itself 🚀 performance Optimization, memory use, etc labels May 23, 2023
@emilk emilk marked this pull request as ready for review May 23, 2023 21:13
@Wumpf Wumpf self-requested a review May 24, 2023 15:24
@@ -51,6 +50,9 @@ struct UniformBuffer {

minification_filter: u32,
magnification_filter: u32,

/// Boolean: decode 0-1 sRGB gamma to linear space before filtering?
decode_srgb: u32,
Copy link
Member

Choose a reason for hiding this comment

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

wgsl has a (32bit large) bool type, why not use that?

Copy link
Member

Choose a reason for hiding this comment

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

tried to find spec on when a bool is regarded as true, now not sure if it can be in a uniform buffer. Did you try?

Copy link
Member Author

Choose a reason for hiding this comment

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

NOPE

[2023-05-24T15:47:35Z ERROR re_renderer::error_tracker] WGPU error tick_nr=1 description=Validation Error
    
    Caused by:
        In Device::create_shader_module
        
    Shader validation error: 
       ┌─ :86:1
       │
    86 │ var<uniform> rect_info: UniformBuffer;
       │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ naga::GlobalVariable [1]
    
    
        Global variable [1] 'rect_info' is invalid
        Alignment requirements for address space Uniform are not met by [16]
        The type is not host-shareable
    

@emilk emilk merged commit 1606471 into main May 24, 2023
@emilk emilk deleted the emilk/premul-alpha-on-gpu branch May 24, 2023 15:48
emilk added a commit that referenced this pull request May 24, 2023
Regression from #2190
@emilk emilk mentioned this pull request May 24, 2023
1 task
Wumpf pushed a commit that referenced this pull request May 24, 2023
Regression from #2190
emilk added a commit that referenced this pull request May 25, 2023
* Premultiply the alpha on the GPU

Premultiplying on the GPU saves us A LOT of cpu.

But texture filtering must happen AFTER premultiplying, which means
we need to do texture filtering in software on the shader.

* Add a TODO

* Cleanup

* Docfix
emilk added a commit that referenced this pull request May 25, 2023
Regression from #2190
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 performance Optimization, memory use, etc 🔺 re_renderer affects re_renderer itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants