Page MenuHome

Fix T103398: Fix Icon sampler initialization in Metal backend.
Needs RevisionPublic

Authored by Jason Fielder (jason_apple) on Jan 3 2023, 2:45 PM.

Details

Summary

Resolves issue with nearest filtering on UI Icons. Note that as Metal does not support LOD bias as a parameter on a sampler object, the original code has been modified to perform LOD biasing at the shader level. As GPU_SAMPLER_ICON is not widely used, it is more efficient to apply directly to the affected shaders, rather than workaround passing in the sampler LOD bias as a separate value (e.g. uniform or push constant).

Authored by Apple: Michael Parkin-White

Ref T103398
Ref T96261

Diff Detail

Repository
rB Blender
Branch
viewport_commits/Fix_T103398
Build Status
Buildable 25199
Build 25199: arc lint + arc unit

Event Timeline

Jason Fielder (jason_apple) requested review of this revision.Jan 3 2023, 2:45 PM
Jason Fielder (jason_apple) created this revision.
Clément Foucault (fclem) requested changes to this revision.Jan 7 2023, 8:01 PM

Instead of modifying gpu_shader_image_varying_color_frag, I think it would be better to create another shader for the multi icon drawing similar to GPU_SHADER_ICON (maybe name it GPU_SHADER_ICON_MULTI). This variation does not need to be compatible with the corner masking, so move the sampling line at the top of main and #ifdef the rest.

This revision now requires changes to proceed.Jan 7 2023, 8:01 PM

Instead of modifying gpu_shader_image_varying_color_frag, I think it would be better to create another shader for the multi icon drawing similar to GPU_SHADER_ICON (maybe name it GPU_SHADER_ICON_MULTI). This variation does not need to be compatible with the corner masking, so move the sampling line at the top of main and #ifdef the rest.

Okay can do, so just to clarify my understanding, it appears that GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR (and by extension, gpu_shader_image_varying_color_frag) is currently only use for multiple icon drawing in one single place? Is this shader used elsewhere i.e. python GPU module?
Is your intent to have two separate shaders:

GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR (with an unmodified version of: gpu_shader_image_varying_color_frag.glsl - as is)
and
GPU_SHADER_ICON_MULTI (which is a similar variant of gpu_shader_icon_frag.glsl, but without the masking, such that it's similar to gpu_shader_image_varying_color_frag.glsl?)

And then use GPU_SHADER_ICON_MULTI inside icon_draw_cache_texture_flush_ex, such that it is more consistent with the single icon path in icon_draw_texture?
The only other difference with the 2d-image-multi-variant appears to be that it also does not have the outer circle dimming based on the text_width parameter. So effectively, it seems GPU_SHADER_ICON_MULTI would be nearly the same as GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, just with a physically separate fragment source shader, to avoid the ifdef USE_SAMPLER_LOD_BIAS check?
I guess at the moment, depending on whether icon caching is used or not, the results could be subtly different?

Apologies if this is incoherent, just a little unfamiliar with the icon rendering path!

Okay can do, so just to clarify my understanding, it appears that GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR is currently only use for multiple icon drawing in one single place?

That is correct.

The list of exposed shader through pyGPU is pygpu_shader_builtin_items.

Is your intent to have two separate shaders

I don't think there is a good case for keeping GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR. What I meant is to rename the shader to explicitely state that it is reserved for icon usage.

And then use GPU_SHADER_ICON_MULTI inside icon_draw_cache_texture_flush_ex, such that it is more consistent with the single icon path in icon_draw_texture?

Yes, more consistency.

The only other difference with the 2d-image-multi-variant appears to be that it also does not have the outer circle dimming based on the text_width parameter. So effectively, it seems GPU_SHADER_ICON_MULTI would be nearly the same as GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, just with a physically separate fragment source shader, to avoid the ifdef USE_SAMPLER_LOD_BIAS check?

Yes but like I said, I don't think keeping GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR is needed.

I guess at the moment, depending on whether icon caching is used or not, the results could be subtly different?

I guess you meant icon batching. Well, you should definitely add the bias in the non MULTI case too. The only difference will be the dot mask option that is unavailable in the multi version. But this is expected for now.

I hope this clears the questions.

Okay can do, so just to clarify my understanding, it appears that GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR is currently only use for multiple icon drawing in one single place?

That is correct.

The list of exposed shader through pyGPU is pygpu_shader_builtin_items.

Is your intent to have two separate shaders

I don't think there is a good case for keeping GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR. What I meant is to rename the shader to explicitely state that it is reserved for icon usage.

And then use GPU_SHADER_ICON_MULTI inside icon_draw_cache_texture_flush_ex, such that it is more consistent with the single icon path in icon_draw_texture?

Yes, more consistency.

The only other difference with the 2d-image-multi-variant appears to be that it also does not have the outer circle dimming based on the text_width parameter. So effectively, it seems GPU_SHADER_ICON_MULTI would be nearly the same as GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR, just with a physically separate fragment source shader, to avoid the ifdef USE_SAMPLER_LOD_BIAS check?

Yes but like I said, I don't think keeping GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR is needed.

I guess at the moment, depending on whether icon caching is used or not, the results could be subtly different?

I guess you meant icon batching. Well, you should definitely add the bias in the non MULTI case too. The only difference will be the dot mask option that is unavailable in the multi version. But this is expected for now.

I hope this clears the questions.

Yep this helps, thanks! Will put together an updated version :)