Hyprland icon indicating copy to clipboard operation
Hyprland copied to clipboard

reduce a lot of glcalls and cache various states

Open gulafaran opened this issue 5 months ago • 4 comments

reading nvidia docs they say this.

All relevant GL state should be initialized during application initialization and not in the main render loop. For instance, 
occasionally glClearDepthf, glColorMask, or glViewport finds its way into the application render loop even though the 
values passed to these functions are always constant. Other times they are set unconditionally in the loop, just in case 
their values have changed per frame. Only call these functions when the values actually do need to change.

gluniform calls are also cached per program, and unless the value has changed it does not need to be called yet again.

this reduced gl* calls in apitrace by a large amount. moving a lot of driver churn to small cpu churn. but needs some testing from others that this doesnt make it now use a lot more cpu then needed. locally it doesnt.

the perfect way would be to really spend weeks into the code and appropiatly only call these uniforms/viewports/scissor when actually needed. but the easy way out is wrapping and caching the values.

i also havent tried HDR, since i dont have a HDR monitor. needs to be tested so it didnt break.

gulafaran avatar Jun 16 '25 09:06 gulafaran

@UjinT34 i need hdr testing! :heart:

gulafaran avatar Jun 16 '25 09:06 gulafaran

Might be tricky to test because these changes don't prevent HDR activation and some incorrect/outdated shader values might not be obvious. I guess it's time to choose/create some tool to use as a reference for CM testing. SImageDescription supports faster == comparison when id is set. CHyprOpenGLImpl::passCMUniforms uses it for color conversion matrix caching. Can be used in a similar way to return early and avoid all the new setUniform stuff and checks.

UjinT34 avatar Jun 16 '25 10:06 UjinT34

I think this is ready no?

vaxerski avatar Jun 18 '25 08:06 vaxerski

I think this is ready no?

sure ready for review and testing.

gulafaran avatar Jun 18 '25 09:06 gulafaran

I rebased this on the main. Without HDR enabled, HDR displays

monitorv2 {
    output = eDP-1
    mode = 1920x1080@144
    position = 0x0
    scale = 1
    # bitdepth = 10
    cm = srgb
    sdrbrightness = 2.20
    sdrsaturation = 1.07
    supports_wide_color = 1
    supports_hdr = 0
    sdr_min_luminance = 0.005
    sdr_max_luminance = 200
    min_luminance = 0
    max_luminance = 1000
    max_avg_luminance = 200
}

20250621_22h55m55s_grim

monitorv2 {
    output = eDP-1
    mode = 1920x1080@144
    position = 0x0
    scale = 1
    # bitdepth = 10
    cm = srgb
    sdrbrightness = 2.20
    sdrsaturation = 1.07
    supports_wide_color = 1
    supports_hdr = 0
    sdr_min_luminance = 0.005
    sdr_max_luminance = 200
    # min_luminance = 0
    # max_luminance = 1000
    # max_avg_luminance = 200
}

20250621_22h56m25s_grim

Black screen with:

monitorv2 {
    output = eDP-1
    mode = 1920x1080@144
    position = 0x0
    scale = 1
    # bitdepth = 10
    cm = srgb
    sdrbrightness = 2.20
    sdrsaturation = 1.07
    supports_wide_color = 1
    supports_hdr = 0
    sdr_min_luminance = 0.005
    sdr_max_luminance = 200
    # min_luminance = 0
    # max_luminance = 1000
    max_avg_luminance = 200
}

I just want to test this. Not sure if my config is wrong or not, but hope this helps

Zebra2711 avatar Jun 21 '25 16:06 Zebra2711

CM shader values aren't passed correctly. With cm = srgb the CM is skipped in most cases. Anything that triggers CM will result in a red tint. cm = edid should be enough for testing (might need to force wide color gamut and use cm = wide if EDID primaries are not set or equal to sRGB).

UjinT34 avatar Jun 22 '25 10:06 UjinT34

@Zebra2711 should work now

UjinT34 avatar Jun 22 '25 16:06 UjinT34

@Zebra2711 should work now

Yep, no more red tint when cm=edid (or wide,...) is set

Zebra2711 avatar Jun 22 '25 16:06 Zebra2711

https://github.com/user-attachments/assets/8e52bd37-28c2-4e65-bdfb-5b92ba5189fb

systeminfo.txt

there's something messed up, with animations/borders? best visible on bright wallpaper on special workspace this is with this patch applied on top of cf7e3aa (main), without it, i don't see these artifacts

Skidamek avatar Jun 23 '25 13:06 Skidamek

2025-06-23.15-09-48.mp4

systeminfo.txt

there's something messed up, with animations/borders? best visible on bright wallpaper on special workspace this is with this patch applied on top of cf7e3aa (main), without it, i don't see these artifacts

that looks bad indeed, but whats up with all your env vars in your config. LIBGL_ALWAYS_SOFTWARE, __NV_PRIME_RENDER_OFFLOAD , __VK_LAYER_NV_optimus etc

gulafaran avatar Jun 23 '25 14:06 gulafaran

2025-06-23.15-09-48.mp4 systeminfo.txt there's something messed up, with animations/borders? best visible on bright wallpaper on special workspace this is with this patch applied on top of cf7e3aa (main), without it, i don't see these artifacts

that looks bad indeed, but whats up with all your env vars in your config. LIBGL_ALWAYS_SOFTWARE, __NV_PRIME_RENDER_OFFLOAD , __VK_LAYER_NV_optimus etc

there is like 3 different places you set decoration blur/shadow too xD

gulafaran avatar Jun 23 '25 14:06 gulafaran

that looks bad indeed, but whats up with all your env vars in your config. LIBGL_ALWAYS_SOFTWARE, __NV_PRIME_RENDER_OFFLOAD , __VK_LAYER_NV_optimus etc

idk, i had them long time lol - they dont seem to affect that

there is like 3 different places you set decoration blur/shadow too xD

true, i need to clean it up sometime, axshell replaces them tho, i just checked that its reproducible with just axshell

Skidamek avatar Jun 23 '25 14:06 Skidamek

true, i need to clean it up sometime, axshell replaces them tho, i just checked that its reproducible with just axshell

That's because some functions changed and axshell used old functions like GL.glTexParameteri https://github.com/Axenide/Ax-Shell/blob/2ac60548ea449041ba4819ef26197161484486a4/modules/shader.py#L324

Zebra2711 avatar Jun 23 '25 14:06 Zebra2711

true, i need to clean it up sometime, axshell replaces them tho, i just checked that its reproducible with just axshell

That's because some functions changed and axshell used old functions like GL.glTexParameteri https://github.com/Axenide/Ax-Shell/blob/2ac60548ea449041ba4819ef26197161484486a4/modules/shader.py#L324

technically i dont think that should break, it merely will call it uncached

gulafaran avatar Jun 23 '25 15:06 gulafaran

true, i need to clean it up sometime, axshell replaces them tho, i just checked that its reproducible with just axshell

That's because some functions changed and axshell used old functions like GL.glTexParameteri https://github.com/Axenide/Ax-Shell/blob/2ac60548ea449041ba4819ef26197161484486a4/modules/shader.py#L324

technically i dont think that should break, it merely will call it uncached

Uncached calls won't update the cache and later cached calls might get skipped instead of updating values and cache.

UjinT34 avatar Jun 23 '25 17:06 UjinT34

isn't that a separate process though? I'd assume it's not hyprland as it's written in python.

vaxerski avatar Jun 23 '25 17:06 vaxerski

true, i need to clean it up sometime, axshell replaces them tho, i just checked that its reproducible with just axshell

That's because some functions changed and axshell used old functions like GL.glTexParameteri https://github.com/Axenide/Ax-Shell/blob/2ac60548ea449041ba4819ef26197161484486a4/modules/shader.py#L324

technically i dont think that should break, it merely will call it uncached

Uncached calls won't update the cache and later cached calls might get skipped instead of updating values and cache.

oOh yes -_-. we set whatever to 2. module sets it to 0, later we try to set it to 2 again, only now its cached as 2 but the module changed it, mismatch and 0xb00b

gulafaran avatar Jun 23 '25 17:06 gulafaran

oOh yes -_-. we set whatever to 2. module sets it to 0, later we try to set it to 2 again, only now its cached as 2 but the module changed it, mismatch and 0xb00b

if that python code is a plugin (runs as part of hl) then it's the plugin's job to update itself as hyprland changes. If it's just a client process, it has nothing to do with us.

vaxerski avatar Jun 23 '25 17:06 vaxerski

@Skidamek and @Zebra2711 reverted a change that broke contrast/blur and stuff. so it should be a lot happier now.

and as always, big thanks for testing things so they dont end up merged and causing havoc on -git :heart:

gulafaran avatar Jun 24 '25 12:06 gulafaran

Seems to work perfectly fine now, thanks

Skidamek avatar Jun 24 '25 13:06 Skidamek

@vaxerski yeah think we ruled out the issues, its good to go from here on, from my end.

gulafaran avatar Jun 24 '25 18:06 gulafaran