Running tst_qrhi -platform eglfs will pass on RPi4 / Mesa 22.
This does not test Vulkan of course since the platform plugin cannot
create a Vulkan instance.
Running tst_qrhi -platform vkkhrdisplay will enable Vulkan but will
still try OpenGL since the autotest does not query the platform
integration about OpenGL support. Make this nicer by skipping most of
the GL test if the platform integration we have cannot handle OpenGL
stuff anyway.
For some tests the data-driven approach has to be removed since doing
QFETCH without any rows will crash. These two OpenGL-specific tests
now check OpenGL support directly and QSKIP if needed.
While we are at it, fix up the Vulkan instance API version as well.
Pick-to: 6.4
Change-Id: I2891c04540bc2dfd0ccf475629bd23542bff15f5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.
Existing copyright statements remain intact
Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
...by removing the entire adjustedFormat() helper.
Qt Quick has never used this, which indicates it is not that
useful. Same goes for Qt Multimedia or Qt 3D. Ensuring depth and
stencil is requested is already solved by using
QSurfaceFormat::setDefaultFormat() or by adjusting the formats
everywhere as appropriate.
The helper function's usages are in the manual tests that use it as a
shortcut, and in the GL backend itself. Remove it and leave it up the
client to set the depth or stencil buffer size, typically in the
global default surface format. (which in fact many of the mentioned
manual tests already did, so some of calls to
window->setFormat(adjustedFormat()) were completely unnecessary)
By not having the built-in magic that tries to always force depth and
stencil, we avoid problems that arise then the helper cannot be easily
invoked (thinking of widgets and backingstores), and so one ends up
with unexpected stencil (or depth) in the context (where the GL
backend auto-adjusts), but not in the window (which is not under
QRhi's control).
It was in practice possible to trigger EGL_BAD_MATCH failures with the
new rhi-based widget composition on EGL-based systems. For example, if
an application with a QOpenGLWidget did not set both depth and stencil
(but only one, or none), it ended up failing due to the context -
surface EGLConfig mismatches. On other platforms this matters less due
to less strict config/pixelformat management.
Pick-to: 6.4
Change-Id: I28ae2de163de63ee91bee3ceae08b58e106e1380
Fixes: QTBUG-104951
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Some of the offsets are already quint32 in the API (vertex input
attributes, dynamic offsets, offsets in draw calls), matching the
reality of the underlying 3D APIs, but many buffer-related functions
use int as of now, simply because that used to be the default choice,
and the same goes for sizes (such as buffer or range sizes). This is
not quite consistent and should be cleaned up if for nothing else then
just to make the classes consistent, but also because no 3D API use a
signed type for offsets, sizes, and strides. (except OpenGL for some)
When it comes to strides (for vertex inputs and raw image texture
uploads), those are already all quint32s. This is straightforward
because most of the 3D APIs use 32-bit uints for these regardless of
the architecture.
Sizes and offsets are often architecture-dependent (Vulkan, Metal),
but there is at least one API where they are always 32-bit even on
64-bit Windows (UINT == unsigned int, D3D11). In addition, we do not
really care about buffer or texture data larger than 4 GB, at least
not without realistic use cases and real world testing, which are
quite unlikely to materialize for now (esp. since we still have the
width/height of 2D textures limited to 16 or 32K in many cases even on
desktops, whereas 2GB+ buffers are not guaranteed in practice even
when an API seemingly allows it).
In any case, the important change here is the signed->unsigned
switch. A number of casts can now be removed here and there in the
backends, because the offsets and sizes are now unsigned as well,
matching the underlying API reality. The size can be potentially
increased later on with minimal effort, if that becomes necessary for
some reason.
Change-Id: I404dbc365ac397eaeeb3bd2da9ce7eb98916da5f
Reviewed-by: Inho Lee <inho.lee@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Make our QRhiMemAllocStats struct a bit more generic, drop the memory
allocation part in the naming, and use the same getter and struct for
reporting some important timings. (we are free to rename for now, there
are no users in other modules yet)
The time spent in graphics (or compute) pipeline creation has a special
relevance in particular with the modern APIs (as it is the single
biggest potentially time consuming blocking operation), but also highly
interesting with others like D3D11 simply because that's where we do the
expensive source-to-intermediate compilation is HLSL source is provided.
In order to see the effects of the various caching mechanisms (of which
there can be confusingly many, on multiple levels), the ability to see
how much time we spent on pipeline creation e.g. until we render the
first view of an application can be pretty essential.
Task-number: QTBUG-103802
Change-Id: I85dd056a39db7e6b25fb1f9d02e4c94298d22b41
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
The goal is to make it possible to implement QSGRhiSupport::backendName()
in Qt Quick with just a single line:
return QString::fromUtf8(QRhi::backendName(m_rhiBackend));
instead of duplicating the strings and the logic.
Similarly, QBackingStoreRhiSupport can now drop its apiName() helper
entirely.
Change-Id: Ia8cbb1f1243539ed4d7a98e71dcc2ed56b017e40
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.
Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
swapchain->currentFrameRenderTarget()->renderPassDescriptor() is not
functional at the moment, it returns null. This is because no backend
ensures that the internal renderpass descriptor object is exposed via
that getter in a QRhiSwapChainRenderTarget. Whereas in a
QRhiTextureRenderTarget this would work by design because there the
setter must be called by the user.
Fix this up, providing better API symmetry, and also reducing the need
to pass along QRhiRenderPassDescriptor objects seprately alongside a
QRhiRenderTarget in some places, e.g. in Qt Quick.
Change-Id: I42c4e9aaee3202c1d23bd093d840af80c5f8cd0f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
It's one thing that this is not part of OpenGL ES, but it is optional
even with Vulkan, with some mobile GPUs not offering the feature at all.
Change-Id: I4e2c6642eccb0793e69074b4b6eeb2b7cef3516e
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
We want to enable gaining access to the underlying resource(s) by
inspecting a QRhiRenderTarget. This is not currently possible for
swapchains since there is nothing that references the actual
QRhiSwapChain. To clean this up, make an explicit, new
QRhiSwapChainRenderTarget subclass. Thus the logic already used in a
couple of places to examine the resources attached to a
QRhiTextureRenderTarget can now work with swapchain render targets too,
by branching based on the resourceType().
This eliminates the somewhat odd setup where a "RenderTarget" resource
is QRhiRenderTarget corresponding (but not exposing!) a swapchain,
whereas a "TextureRenderTarget" is a QRhiTextureRenderTarget which
is a subclass of QRhiRenderTarget. Now we correctly have an (abstract)
base and two subclasses, one for each type of render targets.
Besides, it allows us to clean up the oddly named
Q...ReferenceRenderTarget classes in the backends, which initially tried
to indicate that this "render target" merely references (or, in
practice, is) a swapchain. We can now have a nice and symmetrical
Q...SwapChainRenderTarget and Q...TextureRenderTarget naming scheme.
Change-Id: Ib07e9be99a316eec67b94de0860e08f5f4638959
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Only (straightforwardly) implementable with modern APIs, and
only really exists to handle special platform cases, such as
when a video framework gives us a D3D texture array with
D3D11_BIND_DECODER | D3D11_BIND_SHADER_RESOURCE
which is only possible to use as a shader resource if the SRV
selects a single array layer.
Has no effect on the normal usage of texture arrays, where all
array layers are exposed, and it is the shader that selects the
layer when sampling or loading via the sampler2DArray. That
continues to be the standard way to work with texture arrays.
Change-Id: I0a656b605da21f50239b38abb83067e0208c1dbe
Reviewed-by: Piotr Srebrny <piotr.srebrny@qt.io>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Multiple tests use qt_internal_add_resource that copies the
functionality that is already implemented inside the
qt_internal_add_test function. Simplify these test by replacing
the qt_internal_add_resource call with the new BUILTIN_TESTDATA
option.
Change-Id: I18475b817d6f87264f0de53817d6c26c5ccab4e2
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Raster pipeline is not supported on webOS OSE: trying to use it causes
an exit(1).
Fixes: QTBUG-100654
Pick-to: 6.3
Change-Id: I00325fc1330a2d0d4abfdee054343ecfac767309
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
There is a TODO for this in Qt Quick from the 6.0 times. To decide
upfront if Metal can be expected to function, or if a fallback to
OpenGL needs to be triggered (especially important with macOS virtual
machines, where, unlike any real macOS system, Metal may not be
present at all), the scenegraph calls create() and then drops the
result. The idea to make this less wasteful was back then to add a
dedicated probing function which can, possibly, perform the checks in
a more lightweight manner than full initialization. Implement this
now, focusing on Metal.
Brought to attention by QTBUG-100441: printing warnings about not
having an MTLDevice is confusing in a Metal-less macOS VM, because it
is not an actual error, only part of the probing at scenegraph
initialization. We can now avoid printing confusing warnings there.
Change-Id: Ie52c36af9224bedc3f5e4c23edb486d961c9f216
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This is an issue for QQuickWindow in practice, although it is not hit
by our current tests.
Pick-to: 6.3
Change-Id: Ia73704c1af6a82b2689ce7b844d3b0eb9a17ec18
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Mainly because we do have legacy code in the Qt 5 graphical effects that
tries to dynamically determine the max number of varyings. Make it
easier to port such code.
Change-Id: I846cab2c2fe7b4cd473b5ced0146ca36f1c8169b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Add some sort of autotest for both RGBA16F and the new RGB10A2. The
latter is introduced particularly because ideally we should have a
texture format that corresponds to the D3D/Vulkan swapchain color
buffer format with HDR10.
Change-Id: I1e1bbb7c7e32cb3db89275900811c0bcaeac39d6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
As these are QList and QHash. All existing usages are based on this
anyway, no value in being able to indicate "not available" - an empty
container fulfills the same role.
Change-Id: I8059025fa7a4acb6fc674cd98b16fcafa19ed85d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
For Direct 3D, Metal, and Vulkan this is natively supported. (and
makes no difference in particular for D3D and Metal because they do
not have the legacy combined image sampler concept anyways)
With OpenGL it will work too, but this relies on SPIR-Cross magic and
is still using a combined sampler (e.g. a sampler2D) in the GLSL
shader. The GL backend walks back and forth in the mapping tables from
the shader baker in order to make this work, which is presumably
slightly more expensive than combined image samplers.
Do note that combined image samplers (i.e. sampler2D in the shader and
QRhiShaderResourceBinding::sampledTexture() in code) continue to be
the primary, recommended way for any user of the rhi for the time
being.
Change-Id: I194721bc657b1ffbcc1bb79e6eadebe569a25087
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
The system we inherited from the original Qt 5.14 introduction of QRhi
is a text stream based solution where resource creation and frame
timings are sent in a comma-separated format to a QIODevice.
This, while useful to get insights about the number of resources at a
given time, is not actively helpful. The frameworks built on top (Qt
Quick, Qt Quick 3D) are expected to provide solutions for logging
timings in a different way (e.g. via the QML Profiler). Similarly,
tracking active resources and generating statistics from that is
better handled on a higher level.
The unique bits, such as the Vulkan memory allocator statistics and
the GPU frame timestamps, are converted into APIs in QRhi. This way a
user of QRhi can query it at any time and do whatever it sees fit with
the data.
When it comes to the GPU timestamps, that has a somewhat limited value
due to the heavy asynchronousness, hence the callback based
API. Nonetheless, this is still useful since it is the only means of
reporting some frame timing data (an approx. elapsed milliseconds for
a frame) from the GPU side.
Change-Id: I67cd58b81aaa7e343c11731f9aa5b4804c2a1823
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Adds the following in a QShader/QShaderDescription:
- a list of separate images
- a list of separate samplers
- a list of "combined_sampler_uniform_name" -> [
separate_texture_binding, separate_sampler_binding ] mappings
(relevant for GLSL only)
On the QShader (and qsb/QShaderBaker) level not having separate image
(texture) and sampler objects exposed in the reflection info is not
entirely future proof. Right now we benefit strongly from the fact
that Vulkan/SPIR-V supports both combined and separate
images/samplers, while for HLSL and MSL SPIRV-Cross translates
combined image samplers to separate texture and sampler objects, but
it is not given that relying on combined image samplers will always be
possible in the long run; it is mostly a legacy OpenGL thing that just
happens to be supported in Vulkan/SPIR-V due to some benefits with
certain implementations/hw, but is not something present in any newer
APIs.
In addition, before this patch, attempting to run a shader with
separate textures and samplers through qsb will just fail for GLSL,
even though SPIRV-Cross does have the ability to generate a "fake"
combined sampler for each separate texture+sampler combination. Take
this into use. This also involves generating and exposing a
combined_name->[separate_texture_binding,separate_sampler_binding]
mapping table for GLSL, not unlike we have the native binding map for
HLSL and MSL. A user (such as, the GL backend of QRhi) would then use
this table to recognize what user-provided texture+sampler binding
point numbers correspond to which auto-generated sampler2Ds in the GL
program.
Take the following example:
layout(binding = 1) uniform texture2D sepTex;
layout(binding = 2) uniform sampler sepSampler;
layout(binding = 3) uniform sampler sepSampler2;
Inn the reflection info (QShaderDescription) this (assuming a
corresponding qtshadertools patch in place) now gives one entry in
separateImages() and two in separateSamplers(). Assuming sepTex is
used both with sepSampler and sepSampler2, the GLSL output and mapping
table from QShaderBaker will have two auto-generated sampler2Ds (and
no 'texture2D' or 'sampler').
One immediate benefit is that it is now possible to create a shader
that relies only on separate images and samplers, feed it into qsb,
generate all the possible targets, and then also feed the SPIR-V
binary into a tool or library such as Tint (e.g. to generate WGSL)
that canot deal with combined image samplers.
Change-Id: I9b19847ea5854837b45d3a23edc788c48502aa15
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Unlike the shader resource binding lists that automatically recognize
in setShaderResources() when a referenced QRhiResource has been rebuilt
in the meantime (create() was called i.e. there may be completely
different native objects underneath), QRhiTextureRenderTarget has no
such thing. This leads to an asymmetric API and requires also rebuilding
the rt whenever an attachment is rebuilt:
rt = rhi->newTextureRenderTarget({ { texture } })
rt->create()
cb->beginPass(rt, ...)
texture->setPixelSize(...)
texture->create()
rt->create() // this should not be needed
cb->beginPass(rt, ...)
Avoid having to do that second rt->create().
Change-Id: If14eaa7aac3530950498bbdf834324d0741a7c4d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This time exercising series of buffer updates and texture uploads
within proper, on-screen frames. (particularly interesting for dynamic
buffers in case the double (or more) buffering and having multiple
frames in flight involves special bookkeeping for these - using
'offscreen' frames like in other test cases does not necessarily
exercise all of this)
Change-Id: Id470919d27037359a1f0346a50a2a0e3966f5cd2
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Arrays of textures have always been supported, but we will encounter
cases when we need to work with texture array objects as well.
Note that currently it is not possible to expose only a slice of the
array to the shader, because there is no dedicated API in the SRB,
and thus the same SRV/UAV (or equivalent) is used always, capturing
all elements in the array. Therefore in the shader the last component
of P in texture() is in range 0..array_size-1.
Change-Id: I5a032ed016aeefbbcd743d5bfb9fbc49ba00a1fa
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
QVLA itself is non-relocatable due to self references. (ptr pointing
to array[Prealloc] as long as capacity < Prealloc)
Seems we shot ourselves in the foot in multiple places with this.
Pick-to: 6.2 6.2.0
Fixes: QTBUG-96619
Change-Id: I57a2ce539b671326cd352dbe57a1f3d4c46a6456
Reviewed-by: Tobias Koenig <tobias.koenig@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
...when starting a render/compute pass.
This matches most other backends in fact, the Vulkan backend has
just certain historical differences, and is complicated due to the
fact that it has the option of using secondary command buffers for
passes that specify ExternalContents (to support the case of wanting
to issue direct Vulkan commands in a code block surrounded by calls
to beginExternal and endExternal).
Not resetting state such as the currently bound index buffer when
starting a pass quickly blows up when two consecutive render passes
use different settings, one targeting the primary while the other
the secondary command buffer. Instead of further complicating the
logic, just reset the relevant state in every begin(Compute)Pass.
Comes with an autotest that is crafted so that it manages to
downright crash when run with Vulkan without the fix to the backend.
Fixes: QTBUG-89765
Pick-to: 6.2
Change-Id: I8dc47bd179c17d45a0556ec31200dc90c4b67ca5
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Follow what has been done for QRhiShaderResourceBindings. Have a way
to retrieve an opaque blob (that just happens to be a list of integers)
so that a simple == comparison can be used to determine compatibility
even when the objects from which the blob was retrieved are no longer
alive.
The contract is the following:
bool a = rp1->isCompatible(rp2);
bool b = rp1->serializedFormat() == rp2->serializedFormat();
assert(a == b);
Pick-to: 6.2
Change-Id: I45e7d05eeb6dfa2b2de474da0a0644912aaf174a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Be idiomatic and return the output iterator one past the last element.
Otherwise passing in a plain pointer (as exercised by the autotest now)
fails to function because we write over the same 4 elements again and
again for each binding.
Pick-to: 6.2
Change-Id: If74463fa5140ffa2b1d5be97b71868848ad46614
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
...by the Qt Quick renderer, for example.
A typical Qt Quick material binding set serializes to 8 uints. This
would not demand a container like QVector. However, being implicitly
shared is essential here due to the intended usage (query the
serialized blob, put it into a cache key, hash it, compare it, all
without any copying and new allocs; we can afford an extra alloc
upon each srb construction, but don't want more afterwards in the
rendering engines)
Also make it clear in the pipeline docs that the optimization Qt Quick
is (soon going to be) doing is legal. (the srb ref in the pipeline can
be dead and dangling as long as every call to setShaderResources()
specifies a layout-compatible alternative)
Pick-to: 6.2
Change-Id: I97efbea1fa3516b10c9832adbab0a21b7bc0845d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
One is a bad application or library in this case, but nonetheless
we should handle this more gracefully then just crashing due to
the QRhi already having been destroyed. Mainly because in Qt 5 one
could get away with the same: releasing OpenGL objects underneath,
for example, a QSGPlainTexture with no (or wrong) GL context did
not generate any user visible fatal errors. So we should not crash
in Qt 6 either with these code bases.
In debug builds or when QT_RHI_LEAK_CHECK is set, one will get the
unreleased resources warning printed in Qt 6, which is a step
forward compared to Qt 5. So there is still some indication that
something is badly designed, even if the application survives.
Task-number: QTBUG-95394
Pick-to: 6.2
Change-Id: I944f4f425ff126e7363a82aff926b280ccf1dfc3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Supported on OpenGL (and ES) 3.0+ and everywhere else.
Can also be a render target, targeting a single slice at a time.
Can be mipmapped, cannot be multisample.
Reading back a given slice from a 3D texture is left as a future
exercise, for now it is documented to be not supported.
Upload is going to be limited to one slice in one upload entry,
just like we specify one face or one miplevel for cubemap and
mipmapped textures.
This also involves some welcome hardening of how texture subresources
are described internally: as we no longer can count on a layer index
between 0..5 (as is the case with cubemaps), simply arrays with
MAX_LAYER==6 are no longer sufficient. Switch to sufficiently dynamic
data structures where applicable.
On Vulkan rendering to a slice needs Vulkan 1.1 (and 1.1 enabled on the
VkInstance).
Task-number: QTBUG-89703
Change-Id: Ide6c20124ec9201d94ffc339dd479cd1ece777b0
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Normally we only allow creating wrappers for texture objects. These
can then be used with a QRhiTextureRenderTarget to allow rendering into
an externally created texture.
With OpenGL (ES), there are additional, special cases, especially on
embedded. Consider EGLImages for example. An EGLImageKHR can be bound to
a renderbuffer object (glEGLImageTargetRenderbufferStorageOES), which
can then be associated with a framebuffer object to allow rendering into
the external buffer represented by the EGLImage. To implement the same
via QRhi one needs a way to create a wrapping QRhiRenderBuffer for the
native OpenGL renderbuffer object.
Here we add a createFrom() to QRhiRenderBuffer, while providing a dummy,
default implementation. The only real implementation is in the OpenGL
backend, which simply takes a renderbuffer id, without taking ownership.
Task-number: QTBUG-92116
Change-Id: I4e68e665fb35a7d7803b7780db901c8bed5740e2
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Those tests don't fail anymore and show in CI as BPASS, so we
can safely, hopefully, unblock them
Task-number: QTBUG-87429
Fixes: QTBUG-68974
Fixes: QTBUG-69166
Fixes: QTBUG-87403
Fixes: QTBUG-87411
Fixes: QTBUG-69083
Fixes: QTBUG-69084
Fixes: QTBUG-87426
Pick-to: 6.1
Change-Id: I831b955116c0f465319b9c5fc726dd98804d1c00
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>