qt5base-lts/tests/manual/rhi
Laszlo Agocs 68a4c5da9a Compose render-to-texture widgets through QRhi
QPlatformTextureList holds a QRhiTexture instead of GLuint. A
QPlatformBackingStore now optionally can own a QRhi and a
QRhiSwapChain for the associated window.  Non-GL rendering must use
this QRhi everywhere, whereas GL (QOpenGLWidget) can choose to still
rely on resource sharing between contexts. A widget tells that it
wants QRhi and the desired configuration in a new virtual function in
QWidgetPrivate returning a QPlatformBackingStoreRhiConfig. This is
evaluated (among a top-level's all children) upon create() before
creating the repaint manager and the QWidgetWindow.

In QOpenGLWidget what do request is obvious: it will request an
OpenGL-based QRhi. QQuickWidget (or a potential future QRhiWidget)
will be more interesting: it needs to honor the standard Qt Quick
env.vars. and QQuickWindow APIs (or, in whatever way the user
configured the QRhiWidget), and so will set up the config struct
accordingly.

In addition, the rhiconfig and surface type is (re)evaluated when
(re)parenting a widget to a new tlw. If needed, this will now trigger
a destroy - create on the tlw. This should be be safe to do in
setParent. When multiple child widgets report an enabled rhiconfig,
the first one (the first child encountered) wins. So e.g. attempting
to have a QOpenGLWidget and a Vulkan-based QQuickWidget in the same
top-level window will fail one of the widgets (it likely won't
render).

RasterGLSurface is no longer used by widgets. Rather, the appropriate
surface type is chosen.

The rhi support in the backingstore is usable without widgets as well.
To make rhiFlush() functional, one needs to call setRhiConfig() after
creating the QBackingStore. (like QWidget does to top-level windows)

Most of the QT_NO_OPENGL ifdefs are eliminated all over the place.
Everything with QRhi is unconditional code at compile time, except the
actual initialization.

Having to plumb the widget tlw's shareContext (or, now, the QRhi)
through QWindowPrivate is no longer needed.  The old approach does not
scale: to implement composeAndFlush (now rhiFlush) we need more than
just a QRhi object, and this way we no longer pollute everything
starting from the widget level (QWidget's topextra -> QWidgetWindow ->
QWindowPrivate) just to send data around.

The BackingStoreOpenGLSupport interface and the QtGui - QtOpenGL split
is all gone. Instead, there is a QBackingStoreDefaultCompositor in
QtGui which is what the default implementations of composeAndFlush and
toTexture call. (overriding composeAndFlush and co. f.ex. in eglfs
should continue working mostly as-is, apart from adapting to the
texture list changes and getting the native OpenGL texture id out of
the QRhiTexture)

As QQuickWidget is way too complicated to just port as-is, an rhi
manual test (rhiwidget) is introduced as a first step, in ordewr to
exercise a simple, custom render-to-texture widget that does something
using a (not necessarily OpenGL-backed) QRhi and acts as fully
functional QWidget (modeled after QOpenGLWidget). This can also form
the foundation of a potential future QRhiWidget.

It is also possible to force the QRhi-based flushing always,
regardless of the presence of render-to-texture widgets. To exercise
this, set the env.var. QT_WIDGETS_RHI=1. This picks a
platform-specific default, and can be overridden with
QT_WIDGETS_RHI_BACKEND. (in sync with Qt Quick) This can eventually be
extended to query the platform plugin as well to check if the platform
plugin prefers to always do flushes with a 3D API.

QOpenGLWidget should work like before from the user's perspective, while
internally it has to do some things differently to play nice and prevent
regressions with the new rendering architecture. To exercise this
better, the qopenglwidget example gets a new tab-based view (that could
perhaps replace the example's main window later on?). The openglwidget
manual test is made compatible with Qt 6, and gets a counterpart in form
of the dockedopenglwidget manual test, which is a modified version of
the cube example that features dock widgets. This is relevant in
particular because render-to-texture widgets within a QDockWidget has
its own specific quirks, with logic taking this into account, hence
testing is essential.

For existing applications there are two important consequences with
this patch in place:

- Once the rhi-based composition is enabled, it stays active for the
lifetime of the top-level window.

- Dynamically creating and parenting the first render-to-texture
widget to an already created tlw will destroy and recreate the tlw
(and the underlying window). The visible effects of this depend on the
platform.  (e.g. the window may disappear and reappear on some,
whereas with other windowing systems it is not noticeable at all -
this is not really different from similar situtions with reparenting
or when moving windows between screens, so should be acceptable in
practice)

- On iOS raster windows are flushed with Metal (and rhi) from now on
(previously this was through OpenGL by making flush() call
composeAndFlush().

Change-Id: Id05bd0f7a26fa845f8b7ad8eedda3b0e78ab7a4e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-11 21:25:00 +01:00
..
compressedtexture_bc1 CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
compressedtexture_bc1_subupload CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
computebuffer CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
computeimage CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
cubemap rhi: vulkan: Fix mipmap generation for cubemaps 2020-09-25 09:24:25 +02:00
cubemap_render rhi: Regenerate shaders for some manual tests 2020-10-11 10:58:56 +02:00
cubemap_scissor CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
float16texture_with_compute rhi: Regenerate shaders for some manual tests 2020-10-11 10:58:56 +02:00
floattexture CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
geometryshader rhi: Add the basic infrastructure for geometry shader support 2022-01-31 08:53:37 -08:00
hellominimalcrossgfxtriangle rhi: manual tests: Switch to VK_LAYER_KHRONOS_validation 2021-05-31 17:16:45 +02:00
instancing rhi: Fix up vertex inputs with matrices 2020-10-14 22:35:19 +02:00
mrt CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
msaarenderbuffer CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
msaatexture CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
multiwindow rhi: manual tests: Switch to VK_LAYER_KHRONOS_validation 2021-05-31 17:16:45 +02:00
multiwindow_threaded rhi: Drop the profiler for now 2022-01-04 13:00:40 +01:00
noninstanced rhi: Make the new direct buffer update available for non-uniform buffers 2020-10-12 07:55:37 +02:00
offscreen rhi: manual tests: Switch to VK_LAYER_KHRONOS_validation 2021-05-31 17:16:45 +02:00
polygonmode rhi: Add support for polygon fill mode 2022-01-31 08:52:05 -08:00
rhiwidget Compose render-to-texture widgets through QRhi 2022-03-11 21:25:00 +01:00
shadowmap rhi: shadowmap manual test: use Nearest filtering 2021-01-04 17:30:26 +01:00
shared rhi: Drop the profiler for now 2022-01-04 13:00:40 +01:00
tessellation rhi: Add support for polygon fill mode 2022-01-31 08:52:05 -08:00
tex3d rhi: Add support for 3D textures 2021-05-31 17:16:57 +02:00
texturearray rhi: Add texture array support 2021-10-29 15:57:13 +02:00
texuploads CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
triquadcube rhi: Add queries for vertex input/output limits 2022-01-12 20:37:20 +01:00
CMakeLists.txt Compose render-to-texture widgets through QRhi 2022-03-11 21:25:00 +01:00
rhi.pro rhi: Add support for 3D textures 2021-05-31 17:16:57 +02:00