Repository navigation
feat(opengl): texture caching - #6861
Conversation
|
To make reviewing simpler, I recommend viewing lv_draw_opengles.c as a diff of lv_draw_sdl.c Diff with git diff Diff in VS Code Todo:
|
|
The gray pixel artifact seems like black is blended with the opacity of the pixel (instead of the actual color) |
|
It's working, and I've created some benchmarks. It's faster in most of the cases but when a lot of recaching is required it's slower (e.g. in case of arc and multi texts). I don't know why the widget's demo is so much slower. Increasing the cache size 1000 (from 128) changed the render time to 11ms from 16ms. (SW is 8 ms) |
| #error("Unsupported color format") | ||
| #endif | ||
|
|
||
| glGenerateMipmap(GL_TEXTURE_2D); |
There was a problem hiding this comment.
I usually follow this call with:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL _mipMapLevel)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
Or nearest when chosing not to use interpolation.
The first call to lower the default index value of 1000 mipmaplevels to a value more in the range of 1-12.
The latter might apply more to 3d space where GL_LINEAR_MIPMAP_LINEAR gives the smoothest transition between mipmaps but I use it for 2D purposes as well.
There was a problem hiding this comment.
Thanks! 1000 is a lot of mipmap levels, especially considering the mipmap is unused since the textures are currently never being scaled relative to the pixels. I had been wondering if we could avoid generating the mipmap. I recall trying to remove it and something broke.
We could probably accelerate LVGL object/image transformations with OpenGL. That can be a future PR. I imagine the mipmap will be important to have for that. In the meantime I'll apply your suggestion to be well-prepared for forward compatibility.
There was a problem hiding this comment.
I tried linear but that gave some bleeding between labels and background due to interpolation. You want this in 3D space to resolve some artifacts in depth but it doesn't look as good in 2D. Setting To Nearest is better in this case.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 20);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
I don't have much time on my hand to look into this at the moment. I can take a deeper look somewhere later this week. Also on the performance difference mentioned above. That does strike me as quite strange. When all objects (and its vertices / indices) are set, rendering should be very fast. In my own project this flow goes like:
|
Note that OpenGL was slower only in the cases when it couldn't reuse the cached textures e.g. because the color of the labels in the "Multiple labels" text are changing randomly. Other than that the rendering times as usually 0ms. |
| dest_layer.buf_area = task->_real_area; | ||
| dest_layer._clip_area = task->_real_area; | ||
| dest_layer.phy_clip_area = task->_real_area; | ||
| lv_memzero(opengles_render_buf, lv_area_get_size(&dest_layer.buf_area) * 4 + 100); |
There was a problem hiding this comment.
magic number +100 bytes allocated for the render buffer?
There was a problem hiding this comment.
I think it's coming from the SDL renderer. Probably not required, just a leftover.
There was a problem hiding this comment.
Correct, it came from the SDL renderer. I was trying to leave working things untouched until the end.
| "uniform bool u_IsFill;\n" | ||
| "uniform vec3 u_FillColor;\n" | ||
| "\n" | ||
| "void main()\n" |
There was a problem hiding this comment.
I went over the shader as well and see that precision is set to mediump. That is fine for texture coordinates, but the use only seems to be limited to colors. you can use lowp. In large scenes using framents shaders with lowp, midiump or higp can have some influence on performance (but probably not really needed in this case)
|
@JWBverheesen all of your feedback has been addressed. Thank you.
I was about to take it out of draft but I see there is now clipping happening with the advanced usage. I will fix that, rebase, and then take it out of draft. |
|
Looks good from what I can see right now! as to the textures sometimes being flipped: Most image formats store there image data starting at top-left corner of the image. OpenGL starts bottom-left corner as origin. glTexCoord2f(0,0) = bottom-left and glTexCoord2f(1,1) = top-right corner. Kinda anoying but someting to keep in mind. |
|
A known issue I'm going to leave as-is for now is that there is flickering when advanced usage is used while |
kisvegabor
left a comment
There was a problem hiding this comment.
LGTM! Thank you Liam!
@XuNeo @FASTSHIFT could you also take look at it?
Co-authored-by: JWBverheesen <[email protected]>







Fixes #6017
Similar to LVGL's SDL texture caching. Reuse draw buffers by creating OpenGL textures for them and caching them. In theory, it should be faster because they do not have to be SW rendered again and they should blend faster than they would by software.
Notes
lv_conf_template.hrun lv_conf_internal_gen.py and update Kconfig.scripts/code-format.py(astyle v3.4.12needs to installed by runningcd scripts; ./install_astyle.sh) and follow the Code Conventions.