summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhivulkan.cpp
Commit message (Collapse)AuthorAgeFilesLines
* rhi: vulkan: Fix multiview with depth attachment onlyLaszlo Agocs12 days1-4/+8
| | | | | | | | | | Also change a confusing argument naming (begin-end vs. first-last). Relevant in particular for the depth texture generation pass of Qt Quick 3D (XR) with multiview rendering enabled. Change-Id: I18746581cddfa96127de2d07853164b1c88b070b Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Reduce staging copy size for full-width texture uploadsLaszlo Agocs12 days1-6/+6
| | | | | | | Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-120565 Change-Id: I057f40ee410df35af87f27a0357252bc26234f04 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Add support for resolving depth-stencilLaszlo Agocs2024-04-031-14/+293
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add setDepthResolveTexture(). Should work similarly to the color attachments' resolveTexture, but for depth or depth-stencil. However, this is another fragmented feature. - D3D11/12: Not supported. AFAICS multisample resolve (ResolveSubresource) is just not supported for depth or depth-stencil formats. - Vulkan: Not supported with Vulkan 1.0. Supported with Vulkan 1.1 and the two extensions. (VK_KHR_depth_stencil_resolve which in turn requires VK_KHR_create_renderpass2 since the 1.0 structs are not extensible, so now need to use VkRenderPassCreateInfo2 and all the '2' structs) In Vulkan 1.2 the above are in core, without the KHR suffix, but we cannot just use that because our main target, the Quest 3 (Android) is Vulkan 1.1. So 1.2 and up is ignored for now and we always look for the 1.1 KHR extensions. The depth resolve filter is forced for SAMPLE_0. AVG seems to be supported on desktop (NVIDIA) at least, but that's not guaranteed, so would need physical device support checks. On the Quest 3 it does not seem to be supported. And in any case, other APIs such as Metal do not have an AVG filter mode at all, so just use SAMPLE_0 always. - OpenGL (not ES): Should work, both when the multisample data is a renderbuffer and a texture. Relies on glBlitFramebuffer with filter NEAREST. What it does internally, with regards to the depth/stencil resolve mode, is not under our control. - OpenGL ES: Should work when the multisample buffer is a texture. But it will not work when a multisample renderbuffer (setDepthStencilBuffer, not setDepthTexture) is used because the GLES-only multisample extensions (GL_EXT_multisampled_render_to_texture, GL_OVR_multiview_multisampled_render_to_texture, which we prefer over the explicit resolve-based approach) work with textures only. - Metal: Should work. Task-number: QTBUG-122292 Change-Id: Ifa7ca5e1be78227bd6bd7546dde3a62f7fdbc95e Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* QRhiVulkan: fix random values in pipelineCacheData() resultMarc Mutz2024-03-271-0/+1
| | | | | | | | | | | | | | | | | | The QVkPipelineCacheDataHeader::reserved field wasn't initializaed by the code, but then memcpy()ed with the struct into the result QByteArray. At best, this contains random data, at worst, it leaks information. Initialize it to zero. Found by Coverity. Amends df0e98d4080f50de7ecacdc4cae079ab31280481. Pick-to: 6.7 6.6 6.5 6.2 Coverity-Id: 444147 Change-Id: I398c9a1e99483f2f9887d768319b20ecc11e2c86 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* rhi: vulkan: metal: Ensure ms color data is written out on PreserveColorLaszlo Agocs2024-03-141-1/+1
| | | | | | | | Fixes: QTBUG-123211 Pick-to: 6.7 6.6 Change-Id: Id037f8c5a69c2b0ec18d92fe8bb5a34a0a2b0ea0 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* rhi: Make it possible to discard depth/stencil even when using a textureLaszlo Agocs2024-03-141-1/+3
| | | | | | | | | | Also implement this for OpenGL ES since it can be relevant with tiled architectures wrt performance. Task-number: QTBUG-122669 Change-Id: I90dcfe4f5f9edbb8dfb51189d46b89ef2c7a7c06 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Add basic support for specifying a view format for a textureLaszlo Agocs2024-03-121-10/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have to be able to strip the _SRGB nonsense from the render target view formats when rendering into textures that are provided from an external engine (e.g. OpenXR) and are forced onto us with formats such as VK_FORMAT_R8G8B8A8_SRGB. This highlights some limitation of the current system, which has very limited handling of sRGB stuff since proper renderers such as Qt Quick 3D have first class support for linearization and converting to sRGB at the end of their shading pipeline, so _SRGB format textures are never used in practice. OpenGL has an issue which is different from everything else, namely that we do not correctly do the glEnable/Disable on GL_FRAMEBUFFER_SRGB. The QOpenGLExtensions flag is not what we need. We need to know if the sRGB-conversion-on-write is supported or not, not that some framebuffer is sRGB-capable. So do our own query based on the desktop and the ES extension (GL_EXT_sRGB_write_control is something we never checked for, but that is the appropriate GLES extension, supported on the Quest 3 for instance) This is now corrected in the gl backend. This means that the colors will no longer be "too bright" with OpenGL ES and multiview on the Quest 3 for example. Unlike OpenGL, Vulkan and D3D automatically convert in shader reads and writes when the shader resource view or the render target view has a _SRGB format. (which we get by default since we pass on the texture format) Getting a second linear->sRGB conversion on the already sRGB data generated by e.g. Qt Quick 3D is just wrong. Allow solving this by a new function that can be optionally called to say we want (RGBA8, srgb=false), i.e. VK_FORMAT_R8G8B8A8_UNORM, for the views. Of course, reality is more complicated. D3D11 for instance does not allow "casting" a fully typed texture, we'd need to use a _TYPELESS format for that (possibly with other consequences), so skip D3D11. For D3D12 this should work from Windows 1703 on. Implementing for Metal is also left as a future exercise - it is neither needed at the moment within Qt, nor is it trivial, because view textures have to be created explicitly in Metal, normally we just work with the MTLTexture as-is, not with views. Task-number: QTBUG-122288 Task-number: QTBUG-122614 Change-Id: I8aea4e892b308d48f0bf18bdef481e460fbc9d47 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: add support for short and ushort vertex attributesAurélien Brooke2024-03-011-0/+16
| | | | | | | [ChangeLog][RHI] Add support for short and ushort vertex attributes Change-Id: I6111a02d442bbad2ec9667ac0336107dd3ab7b62 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* RHI: fix Vulkan layout for PreserveDepthStencilContents depth texturesAurélien Brooke2024-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Vulkan fails when we attach a depth texture to a render target with QRhiTextureRenderTarget::PreserveDepthStencilContents (we want to reuse the depth data from a depth pre-pass.) vkCreateRenderPass(): pCreateInfo->pAttachments[3] format is VK_FORMAT_D32_SFLOAT and loadOp is VK_ATTACHMENT_LOAD_OP_LOAD, but initialLayout is VK_IMAGE_LAYOUT_UNDEFINED. The Vulkan spec states: If format includes a color or depth component and loadOp is VK_ATTACHMENT_LOAD_OP_LOAD, then initialLayout must not be VK_IMAGE_LAYOUT_UNDEFINED (https://www.khronos.org/registry/vulkan/ specs/1.3-extensions/html/vkspec.html#VUID-VkAttachmentDescription- format-06699) To fix this, just do the same as color attachments: specify a VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL instead of VK_IMAGE_LAYOUT_UNDEFINED when the depth-stencil is preserved. [ChangeLog][RHI] QRhiTextureRenderTarget::PreserveDepthStencilContents now works properly on Vulkan Pick-to: 6.7 Change-Id: I0577bc8021b3598ddfdcea4af98aaef46e8a4519 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: vulkan: Query and enable multiview features when API is 1.1Laszlo Agocs2024-02-021-22/+71
| | | | | | | | Meaning a Vulkan implementation that is not 1.0, not 1.2, not 1.3, but 1.1. This does not have the 1.2+ versioning mechanisms. Change-Id: I9d9346d505162adc0e03aa04217930d41c72027f Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Make sample count selection logic be closer to Qt 5Laszlo Agocs2023-12-061-13/+7
| | | | | | | | Pick-to: 6.6 6.5 Fixes: QTBUG-119148 Change-Id: Ia119ab3ced9da08853c608aa256bde08a6fd8d4e Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* rhi: vulkan: Print vma statistics on out of device memoryLaszlo Agocs2023-09-261-2/+20
| | | | | | | | | | | | | | | | Following a vmaCreate* it makes sense to test for VK_ERROR_OUT_OF_DEVICE_MEMORY and print the allocator statistics in order to give an idea of the application's (video) memory usage. For instance when running on a Raspberry Pi 4, this helps to indicate that the application is just too big for the device, and is more informative then just a Failed to create image: -2 message. Pick-to: 6.6 6.5 Change-Id: I666e2358303894efab9d12d2b3a3d98f0bd3a5b6 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io>
* Add stereo support for DirectX12 and Vulkan backendsIlya Doroshenko2023-09-051-4/+104
| | | | | Change-Id: Id12723d6c392e25935ccb265c58af91aff968984 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: vulkan: Handle the Display P3 enum valueLaszlo Agocs2023-08-281-0/+3
| | | | | | | | | For parity with Metal. VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT is mapped to kCGColorSpaceExtendedLinearDisplayP3 by MoltenVK. Change-Id: Idba4ed56c029c1dea166e278ec6fc3f41e5ac471 Reviewed-by: Christian Strømme <christian.stromme@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: use the clamped api version for vmaLaszlo Agocs2023-07-311-6/+3
| | | | | | | | | | | | | caps.apiVersion is inst->apiVersion() limited by the version the physical device reports. Therefore, use caps.apiVersion when setting up the memory allocator, like it is done everywhere else. This is expected prevent vma init failures on lavapipe in some Linux distros. Pick-to: 6.6 6.5 Change-Id: I4e693820c95a5e0174846afb20e42aadd56034d6 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Fix cloned VkRenderPass wrt multiviewLaszlo Agocs2023-07-051-22/+42
| | | | | Change-Id: I2c97151d144a332fd078ec8940c063b30d3a6d7d Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Include multiViewCount in renderpass compatibilityLaszlo Agocs2023-07-051-7/+13
| | | | | Change-Id: I3185ce27c52c138053fee4805eccbe3575b9433a Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Fix multisample resolve with multiviewLaszlo Agocs2023-06-261-2/+7
| | | | | | Task-number: QTBUG-114790 Change-Id: I3afccc3f7ae2d05aa9aa0e0943aeadc080016f0e Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Implement multiview supportLaszlo Agocs2023-06-221-5/+45
| | | | | | Fixes: QTBUG-114771 Change-Id: I8408b84c5ce01df94d68167d557393af919864d3 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Introduce multiview starting with OpenGL (ES)Laszlo Agocs2023-06-221-0/+2
| | | | | | Fixes: QTBUG-114770 Change-Id: Ibb1ced7f19d15a5116c60e95fd3e6b86ace63155 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vulkan: Shuffle post-1.0 phys.dev.feature queriesLaszlo Agocs2023-06-211-33/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | Make it so that what we query with regards to 1.1, 1.2, and 1.3 features are stored for later use. This will be relevant for e.g. multiview where the multiview field will need to be checked when deciding if the feature is supported at run time. All this is only really compatible with Vulkan 1.2 and newer. Vulkan 1.1 does not have the 1.2 approach, i.e. there is no VkPhysicalDeviceVulkan11Features in Vulkan 1.1 (!). That is a struct added in Vulkan 1.2. In 1.1 one had the feature (extension) specific structs, such as VkPhysicalDeviceMultiviewFeatures in case of multiview. That we do not bother with at the moment. Then again that's nothing new. The existing code to enable all features with a few exceptions, that's already tied to the 1.2+ way of working with physical device features, and not quite compatible with a pure 1.1 (not 1.0, not 1.2+) implementation (which should be hopefully rare out there). Pick-to: 6.6 Change-Id: I661f2634651d28edd9b5feec66a423220920f894 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Do away with qrhivulkanext_p.hLaszlo Agocs2023-06-211-3/+11
| | | | | | | | | This is not scalable. Instead of putting parts of post-1.0 vulkan_core.h into this header, apply the appropriate ifdefs instead. Pick-to: 6.6 Change-Id: I21a9d6f7c51169efa7b66705545bae192ed30c14 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* rhi doc: Fix a repeating typoLaszlo Agocs2023-06-161-4/+4
| | | | | | Pick-to: 6.6 Change-Id: I2025d559be357a6825cdcae4cb0f0931a89864ab Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: vulkan: Fix swapchain format checkLaszlo Agocs2023-06-071-5/+3
| | | | | | | | | | | | | | Fix the treatment of the sRGB flag. That is independent from the value of format(), and should be checked regardless of wanting a HDR swapchain or not. On Android for instance Display P3 with RGBA8 or RGBA8_SRGB is one of the formats offered. While we do not support this right now, it is an example of a "HDR" format that still uses a color buffer format where a dedicated sRGB format is available and must be chosen according to the specified swapchain flags. Pick-to: 6.6 Change-Id: I2d97689fa5af7c08486702ae690f2230d06db469 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* Fix can't create rhi if VkInstance is not enable VK_KHR_surfaceJiDe Zhang2023-06-061-7/+8
| | | | | | | | | | | | | | The VK_KHR_surface is not need if we not using QRhiSwapChain, such as using QQuickRenderControl on QtQuick, it's using "beginOffscreenFrame" without QRhiSwapChain. It's useful if you using a custom VkInstance to QVulkanInstance, and the VkInstance is not create by other library and isn't enable the VK_KHR_surface extension. Pick-to: 6.6 6.5 Change-Id: I7623630adea9c933f38c180d4d73044b0e88f5b8 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: avoid backends modifying the frontend depth and arraySizeLaszlo Agocs2023-05-301-8/+6
| | | | | | | | | | | | | | | Buffer and texture sizes (size, pixelSize) may get increased, if needed, but those actual sizes calculated by the QRhi backends are not written back to the QRhiBuffer m_size or QRhiTexture m_pixelSize. In contrast, both m_depth and m_arraySize are clamped in QRhiTexture by most backends (to ensure a lower bound of 1 and 0, respectively). This is not great since it means the getters for depth() and arraySize() may return values different from what the user has provided. To avoid confusion, do not modify the m_* variables. Change-Id: I2cc5b9abf41ea108549ffd7f2403306e6e8ebba2 Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
* rhi: vulkan: expose the instance in the nativeHandles queryLaszlo Agocs2023-05-301-3/+11
| | | | | | | | | | | | | | | Mainly for completeness, but it has practical uses: someone retrieving a QRhi instance from somewhere should be able to tell the QVulkanInstance, and so the VkInstance, used by that QRhi without resorting to investigating other objects (e.g. retrieving the instance from the QWindow). This provides symmetry to other 3D APIs and QRhi backends where just a single QRhi instance is sufficient to get the MTLDevice, ID3D11Device/Context, etc. i.e. all that is needed to work with the 3D API directly. Change-Id: I5a8b9871a543ea648c76b868bf6ff7be5f2098f2 Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io> Reviewed-by: Hatem ElKharashy <hatem.elkharashy@qt.io>
* rhi: Make it a QPA-style private but semi-public APILaszlo Agocs2023-05-211-6/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qrhi.h, qshader.h, qshaderdescription.h (and qshaderbaker.h from shadertools; done separately) become "RHI APIs", following the concept of QPA APIs. Mirror completely what is done for QPA headers, but using the "rhi" prefix for the headers. This involves updating syncqt to handle the new category of headers. (a note on the regex: matching everything starting with "qrhi" is not acceptable due to incorrectly matching existing and future headers, hence specifying the four header names explicitly) There is going to be one difference to QPA: the documentation for everything RHI is going to be public and part of the regular docs, not hidden with \internal. In addition to the header renaming and adding the comments and documentation notes and warnings, there is one significant change here: there is no longer a need to do API-specific includes, such as qrhid3d11[_p].h, qrhivulkan[_p].h, etc. These are simply merged into a single header that is then included from qrhi.h. This means that users within Qt, and any future applications can just do #include <rhi/qrhi.h> (or rhi/qshader.h if the QRhi stuff is not relevant), no other headers are needed. There are no changes to functionality in this patch. Only the documentation is expanded, quite a lot, to eliminate all qdoc warnings and make the generated API docs complete. An example, with a quite extensive doc page is added as well. Task-number: QTBUG-113331 Change-Id: I91c749826348f14320cb335b1c83e9d1ea2b1d8b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Call into platform hooks for start and end framesDavid Edmundson2023-04-281-0/+7
| | | | | | | | This closely matches QPlatformOpenGLContext which in turn, where it can be used by backends to guard low level resources. Change-Id: Ia44cebced6cdf94497279c47d3c35c0e02e4cb0e Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Replace the temporary GPU time query API with a saner oneLaszlo Agocs2023-04-181-41/+101
| | | | | | | | | | | | | | | | | | | | | | | Modeled after Metal's cb.GPUStart/EndTime. Implemented with timestamp queries for other APIs. Implemented for Metal, D3D11, Vulkan for now. No more callback, just a getter on the command buffer which returns the latest known value, referring to some previous frame. This makes it a lot more usable than the original solution that is not really used anywhere at the moment. Now works for offscreen "frames" as well, this was not implemented before. Opt in with a new QRhi::create() flag because we cannot tell in advance if the getter will be called or not, and this way we can skip recording the timestamps by default. The cost is probably minimal, though. Qt Quick will set this automatically when running with QSG_RHI_PROFILE=1. Change-Id: I903779984a4e0bbf1d03806d04bf61571ce23d72 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Make non-critical pipeline cache warnings qCDebug insteadLaszlo Agocs2023-03-161-18/+18
| | | | | | | | | | | | | | | | It's not just that these are not fatal, but some "errors" are not actual errors, e.g. getting "Nothing to serialize" from Metal is not something we care about. Convert them from qWarning to qCDebug with our standard category, so they still all show up when running with QSG_INFO=1, but won't pollute the output for regular users. Even if a cache file cannot be used or written, that's not something typical users care about. Pick-to: 6.5 Fixes: QTBUG-110485 Change-Id: I63d815f7b95c4d6a4428497b7247811e860ebf04 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* rhi: Clean up 1D and 3D texture feature flagsLaszlo Agocs2023-03-071-0/+4
| | | | | | | | | | | | | | Separate 1D mipmap generation support from rendering into an 1D texture. Those are two independent features, so have a separate feature flag for both instead of using just one. This will then be symmetric with the 3D texture features, where now we have a new flag to report support for generating mipmap for 3D textures. (whereas 3D texture as a render target is already covered by RenderTo3DTextureSlice) Change-Id: Ie5e1f056a7d1c341d90cd7fc522877a3f2da3290 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Add support for half precision vertex atttributesBen Fletcher2023-02-271-0/+10
| | | | | | | | | | | | | | | | | | | Runtime support is indicated via QRhi::Feature::HalfAttributes. OpenGL support is available in OpenGL 3.0+, OpenGL ES 3.0+, and in implementations that support the extension GL_ARB_half_float_vertex. Other RHI backends (Vulkan, Metal, D3D11, and D3D12) all support this feature. Note that D3D does not support the half3 type. D3D backends pass half3 as half4. tst_qrhi auto unit test included. Change-Id: Ide05d7f62f6102ad5cae1b3681fdda98d52bca31 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Do some internal doc fixesLaszlo Agocs2023-02-211-1/+1
| | | | | Change-Id: Iefcf06ffc251d160e838ae12729314b29d4f36a1 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Remove QRhiSrb data gettersLaszlo Agocs2023-02-201-18/+9
| | | | | | | | | | | | | | | | This is for internal use, QRhiShaderResourceBinding does not need to have the data() getters. The backends can use any internal means to access this, no need to have the getters in the frontend just for that. Now, Qt Quick 3D has a special case of accessing this, hence keeping the two getters for now, to be removed in a follow up once that repo updates. While we are at it, share and reuse the sorting function. Change-Id: Ia2308af79863c72ca65024ce6c00531d0256a2cb Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: backends: Get color attachment count in a saner wayLaszlo Agocs2023-02-201-2/+1
| | | | | | | | Also bring all list-like data to the same level when it comes to the interface exposed in QRhi*. Change-Id: I90296a49ff1f52c1ce4e787167c99006fab3c4c3 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: vk: Fix up some legacy queue (family) index inconsistenciesLaszlo Agocs2022-12-161-25/+24
| | | | | | | | | | | | | | | Relevant mainly if we want to consistently expose these as the theoretically correct uint32_t/quint32 from Qt Quick's QSGRendererInterface. (not that int is not sufficient for indexing the typical 3-4 families and 2-16 queues per family) Some checks are not actually needed since the family index must always be valid after create(). Pick-to: 6.5 Task-number: QTBUG-108895 Change-Id: I474ccea51a81e7a096281604ff79b7db4cdd2484 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: vulkan: Flush before unmapLaszlo Agocs2022-12-021-4/+4
| | | | | | | | | | | To prevent validation errors with VUID-VkMappedMemoryRange-memory-00684 although I cannot actually trigger this on Windows. Based on the spec however the right thing seems to be to flush before unmap. Pick-to: 6.4 6.2 Fixes: QTBUG-109123 Change-Id: I34fedea22a6e6e2a14f9b95fea49af05985ec4cb Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* RHI: Add support for 1D texturesBen Fletcher2022-11-151-9/+36
| | | | | | | Support for 1D textures on Vulkan, OpenGL, Metal, and D3D. Change-Id: Ie74ec103da9cfcbf83fa78588cf8cfc1bd6e104f Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* rhi: vk: Switch to cheaper VMA statistics APILaszlo Agocs2022-10-201-7/+12
| | | | | | | | Now that we upgraded to 3.0.1 vmaCalculateStatistics can be replaced with a less-expensive call. Change-Id: Icb444354ce9e091cf69f82aff2e2f828b8302072 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* Update Vulkan memory allocatorLaszlo Agocs2022-10-201-98/+22
| | | | | | | Fixes: QTBUG-107715 Change-Id: I8ab0dc22cf4207e1ef6bc2a170dbd7c2cdd52ee4 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QRhi: Allow negative viewport originAntti Määttä2022-10-201-2/+3
| | | | | | | | | | | | Do not bound viewport rect to surface size, only scirror rect. Modifying the viewport will move the view origin changing the way the scene gets rendered. Pick-to: 6.4 Task-number: QTBUG-106082 Change-Id: I105516bd460af87727d0e73f580b8cf6b748d87f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* RHI: Align setViewport behavior on Metal/Vulkan with OpenGL/D3DBen Fletcher2022-10-181-1/+3
| | | | | | | Fixes to prevent crash on Metal/Vulkan when setViewport is called with no current graphics pipeline is set. This normalizes behavior across Metal/Vulkan/OpenGL/D3D. Change-Id: I8057e01005cfe89ea02a8415f06eaee0f27865fc Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-38/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-9/+9
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-78/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* vulkan: Re-enable VK_KHR_portability driversLaszlo Agocs2022-09-261-8/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Vulkan loader as of SDK 1.3.216 and MoltenVK decided that all existing applications need to stop working with non-conformant Vulkan implementations such as MoltenVK, unless they start specifying the right soup of instance flags, extensions, and device extensions. Set VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR in VkInstanceCreateInfo::flags. Automatically request VK_KHR_portability_enumeration, if supported, on the instance. This handles the instance side. On the device side we can add support in QRhi so Qt Quick continues to work with MoltenVK. This involves requesting VK_KHR_portability_subset on the device whenever the extension is reported as supported (not doing so would be an error) However, applications creating their own VkDevice will need to take care of this themselves. This device extension requires VK_KHR_get_physical_device_properties2 on the instance (which QRhi does not control). This is no problem with Qt Quick as that already does this automatically, but in the unlikely case of wrapping an existing VkInstance in QVulkanInstance it will be up to the creator of VkInstance to enable that as well. Pick-to: 6.4 6.3 6.2 Fixes: QTBUG-106912 Change-Id: Idaf277549b3ec982e99bfc49e4ad6a67976c141a Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* vulkan: Port to VK_EXT_debug_utilsLaszlo Agocs2022-08-101-57/+81
| | | | | | | Fixes: QTBUG-89762 Change-Id: Ie32043578968cbeda7c7f87990b98c10f5d06ff8 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* rhi: vulkan: Log instance extensionsLaszlo Agocs2022-08-101-3/+8
| | | | | Change-Id: I7968268c1c536a0ebcdea00f2f6ab7f5b008be18 Reviewed-by: Andy Nichols <andy.nichols@qt.io>