summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhimetal.mm
Commit message (Collapse)AuthorAgeFilesLines
* rhi: Replace deprecated MTLRenderPipelineDescriptor.sampleCountTor Arne Vestbø4 days1-1/+1
| | | | | Change-Id: I47c64416e9ba089c2f23dcebf63a26988bb1d0a7 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: metal: Reduce staging copy size for full-width texture uploadsLaszlo Agocs8 days1-6/+7
| | | | | | | Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-120565 Change-Id: I3f11796e0cfd7261885cec04695665b2266082f8 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: metal: Handle multiview with depth attachment onlyLaszlo Agocs9 days1-2/+8
| | | | | | | | | | Copy the approach added for Vulkan. (no color attachments, but depth texture array is present -> assume this means multiview rendering and use the array size as view count) Change-Id: Ie523b54e8eec6fdd4fe5f203d1ea97b366f8ac00 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* metal: Tie drawable's MTLTexture lifetime to MTLCommandBufferTor Arne Vestbø2024-04-261-0/+10
| | | | | | | | | | | | | | By default we define QRHI_METAL_COMMAND_BUFFERS_WITH_UNRETAINED_REFERENCES, which means we create MTLCommandBuffer via commandBufferWithUnretainedReferences. In this case, if Metal API validation diagnostics is enabled in Xcode, the texture is released before the command buffer is done with it, so we manually ensure the lifetime of the texture extends until the command buffer is complete. Pick-to: 6.7 Change-Id: I9b9efa96b4a004f43e0b72144aafc4b440c7fbb4 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Add preliminary support for Qt for visionOSTor Arne Vestbø2024-04-181-5/+5
| | | | | | | | | | | | | | | | | | | | | | Qt already runs on Vision Pro as "Designed for iPad", using Qt for iOS. This change enables building Qt for visionOS directly, which opens the door to visionOS specific APIs and use-cases such as volumes and immersive spaces. The platform removes some APIs we depend on, notably UIScreen, so some code paths have been disabled or mocked to get something up and running. As our current window management approach on UIKit platforms depends on UIWindow and UIScreen there is currently no way to bring up QWindows. This will improve once we refactor our window management to use window scenes. To configure for visionOS, pass -platform macx-visionos-clang, and optionally add -sdk xrsimulator to build for the simulator. Change-Id: I4eda55fc3fd06e12d30a188928487cf68940ee07 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* rhi: d3d: metal: Improve docs for importing existing resourcesLaszlo Agocs2024-04-111-0/+5
| | | | | | | | | The struct members were not described. Add something for each in the docs. Pick-to: 6.7 Change-Id: I75d0a5a6efee4d7b4a415b5282a9e44950ed3894 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Add support for resolving depth-stencilLaszlo Agocs2024-04-031-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* rhi: vulkan: metal: Ensure ms color data is written out on PreserveColorLaszlo Agocs2024-03-141-3/+11
| | | | | | | | 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/+1
| | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Synchronize read buffers on non-Apple Silicon in RHIPhilip Schuchardt2024-02-141-9/+16
| | | | | | | | | | | | | | Read buffers are not automatically synchronized when the buffer uses MTLResourceStorageModeManaged. This commit adds GPU to CPU synchronization for managed buffers, ensuring proper data transfer for reading operations on non-Apple Silicon devices. Fixes: QTBUG-119447 Pick-to: 6.6 6.7 Change-Id: I6398f4f27d00950c7dceae918b04e0054d4b5647 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QMetalRhi: Reset proxyData when swapChain is destroyedDoris Verria2024-01-161-0/+1
| | | | | | | | | | | | | | | | | | | When the swap chain is destroyed, we reset the swapchain’s layer (set it to nullptr). However we were not resetting the proxyData which would still point to the window’s (NSView) layer. This starts to become a problem in the cases where the swapchain’s associated QWindow is closed (NSView gets destroyed) and reopened (a new NSView will be created) because when the swap chain is recreated again, since the proxyData already exists and points to the invalid old layer, QRhi::updateSwapChainProxyData is never called. This led to an invalid value being assigned to the swap chain’s layer. To fix the issue, make sure to reset the swapchain’s proxy data when destroy() is called. Task-number: QTBUG-113498 Pick-to: 6.5 6.6 6.7 Change-Id: I02996ecf69ad9d183cac31c9188717ec36742531 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* rhi: Make sample count selection logic be closer to Qt 5Laszlo Agocs2023-12-061-11/+0
| | | | | | | | 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: Guard wantsExtendedDynamicRangeContent with iOS 16.0 checkTor Arne Vestbø2023-08-181-1/+1
| | | | | Change-Id: I3e3ae413a444f9da2f6c5859357ad47004116475 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: add a way to test Display P3 with the manual testLaszlo Agocs2023-08-151-1/+11
| | | | | | | | | | | Extended linear Display P3 + FP16 is likely the thing to use on platforms such as VisionOS and iOS (and optionally on macOS) and perhaps iOS). Enable testing this on macOS with the hdr manual test. Change-Id: I67f0bdbadae8c7ebccae7de008f12fd8d9135529 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* rhi: Enhance the hdr info struct and add a manual testLaszlo Agocs2023-08-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ...while sharing the related code between the d3d backends. The isHardCodedDefaults flag is not used in practice and is now removed. Add the luminance behavior and SDR white level (for Windows) to help creating portable 2D/3D renderers that composite SDR and HDR content. (sadly the Windows HDR and Apple EDR behavior is different, as usual) The new test application is expected to run with the command-line argument "scrgb" or "sdr". It allows seeing SDR content correction (on Windows) in action, and has some simple HDR 3D content with a basic, optional tonemapper. Also shows the platform-dependent HDR-related screen info. With some helpful tooltips even. Additionally, it needs a .hdr file after the 'file' argument. The usual -d, -D, -v, etc. arguments apply to select the 3D API. For example, to run with D3D12 in HDR mode: hdr -D scrgb file image.hdr The same in non-HDR mode: hdr -D sdr file image.hdr Change-Id: I7fdfc7054cc0352bc99398fc1c7b1e2f0874421f Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* rhi: metal: Centralize command buffer creationLaszlo Agocs2023-07-311-7/+22
| | | | | | | | ...and add a single toggle that can be used to switch between regular (auto-retaining) and unretaining command buffers. Change-Id: I9ef4b149f172415733e590e8320165358e29fa16 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: metal: Disable MTLBinaryArchive usage regardless of OS versionLaszlo Agocs2023-07-301-27/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Ironically enough when the old macOS 13 problem is no longer occurring (at least on an M1 Mini with 13.2.1), so the OS version based differentiation could likely be removed, there are now reports about problems with old Intel hardware and earlier OS versions. Therefore, get rid of the OS version based logic, and rather add a global flag that is enabled unconditionally for now, which disables MTLBinaryArchive usage altogether. How much we lose is not very clear anyway. The OS performs its own persistent caching (most likely), hidden from applications. Thus what we lose really is the fine grained control over the data (e.g. specifying a custom storage file via QQuickGraphicsConfiguration), with the possibility of pre-seeding for the first run. As the performance of subsequent runs is less likely to change in any significant way, this is seen as not a big deal for Apple hardware in general so we might just live with this. (and on macOS 13+ this was already crippled anyway due to the OS version logic) Pick-to: 6.6 6.5 Fixes: QTBUG-114338 Task-number: QTBUG-108216 Change-Id: If7b908baea2093f6882674ebfbdc18e770d6503e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* rhi: metal: Remove out of date / unneeded commentLaszlo Agocs2023-07-121-7/+0
| | | | | | | | | | | E.g. the view.layer thread checker problems are eliminated for some time now. The other mentioned XCode warning is likely not there anymore with newer XCode. Whereas the rest (that we pass validation) should be obvious. Pick-to: 6.6 6.5 Change-Id: I9754077aa6e178ee2b866b64538991412af5bb5a Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: metal: Fix external MTLDevice importLaszlo Agocs2023-07-051-1/+1
| | | | | | | | Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-115002 Change-Id: I57c12685f8451420c30c65a1a25064607b52e31c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: gl: metal: Enable depth-stencil correctly with multiviewLaszlo Agocs2023-06-281-1/+1
| | | | | | | | | | | | | | | After fixing the data type for D24S8, we can now implement attaching depth and stencil (with the same texture). For Metal we need to set a stencil flag correctly. This allows using D24S8 in the manual test, which is likely the format that is going to be commonly used when setting up multiview with Qt Quick. Fixes: QTBUG-114904 Change-Id: Ife425c6cb3e09bfe40092c841b78f7a93bb6a4cd Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: metal: Add support for multiview renderingLaszlo Agocs2023-06-271-23/+96
| | | | | | | | | | | | | | Some shortcomings and unexpected problems are not unlikely. The basic feature, with 2 views going to a texture array's 0 and 1 elements, seems to be working with macOS, also with MSAA. Instanced drawing has not been verified. (relevant because layered rendering works via instancing in Metal and the QRhi backend has to adjust the instance count in every draw call) Fixes: QTBUG-114774 Change-Id: I3655e0d2c658b88c4cd6b52a32f94134324e4ac9 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 doc: Fix a repeating typoLaszlo Agocs2023-06-161-3/+3
| | | | | | Pick-to: 6.6 Change-Id: I2025d559be357a6825cdcae4cb0f0931a89864ab Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: metal: Fix a leftover version checkLaszlo Agocs2023-06-131-4/+4
| | | | | | | Pick-to: 6.6 Change-Id: I907d4d312f03658d6f04a626a7df96f7e2b4955a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Don't check m_format in QRhiSwapChain::hdrInfo()Tor Arne Vestbø2023-06-111-13/+1
| | | | | | | | | | | | The HDR info is independent of the current format anyways. Removing the format check allows code to use hdrInfo() as a signal for whether to set a HDR format, instead of having to set the format, then query hdrInfo(), and then setting SDR again if needed. Pick-to: 6.6 Change-Id: I99b57335003d06af227f2a7078560c2a483b049b Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Only report HDR as supported if maxPotentialColorComponentValue > 1Tor Arne Vestbø2023-06-111-2/+14
| | | | | | Pick-to: 6.6 Change-Id: I4c951e8c651b2bee41aba8ff69f481a08d6a3561 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Add QRhiSwapChainHdrInfo::maxPotentialColorComponentValueTor Arne Vestbø2023-06-111-1/+5
| | | | | | | | | | | Knowing the maximum potential component value can be useful to potentially (sic) opt out of an HDR code path if the maximum color component value will be too low to make the additional processing overhead worth it. Pick-to: 6.6 Change-Id: Ib1e1b7a745b236e1d137a1e7daf1248f1572e184 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Pick up HDR maxColorComponentValue from UIScreen if availableTor Arne Vestbø2023-06-111-12/+14
| | | | | | | | | | | | | | | | | | Although QRhiSwapChainHdrInfo uses 'max' for this value, it's used by Qt Multimedia's QVideoWindowPrivate::render() as the current maximum, so we need to reflect UIScreen's currentEDRHeadroom rather than potentialEDRHeadroom (the absolute max), the same way we reflect maximumExtendedDynamicRangeColorComponentValue and not maximumPotentialExtendedDynamicRangeColorComponentValue from NSScreen. As we don't support HDRExtendedSrgbLinear on < iOS 16 there is no point in providing a heuristic fallback based on the iPhone 12 spec. Pick-to: 6.5 6.6 Change-Id: If071bb64f269ce16886206df05eb9f27d260bf15 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Enable HDRExtendedSrgbLinear for iOSTor Arne Vestbø2023-06-091-8/+11
| | | | | | Pick-to: 6.5 6.6 Change-Id: Iaff3c0d18c07cc0cd4ed57a8e6fa7fb07b130a58 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: metal: Fix a swapchain debug print crashLaszlo Agocs2023-06-071-1/+2
| | | | | | | | | | | | | | | When enabling the logs, printing hdrInfo() to qDebug in Qt Quick is something that is done before calling createOrResize() on the swapchain. (logically since this is still at the point of configuring the swapchain settings) Thus the correct thing to do is to only access m_window, not the backend data's window. Pick-to: 6.6 6.5 Change-Id: I3004b0c4a4fdb09cb07a9c0e3c503f79c699c562 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: avoid backends modifying the frontend depth and arraySizeLaszlo Agocs2023-05-301-5/+4
| | | | | | | | | | | | | | | 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: Make it a QPA-style private but semi-public APILaszlo Agocs2023-05-211-6/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* rhi: Replace the temporary GPU time query API with a saner oneLaszlo Agocs2023-04-181-9/+29
| | | | | | | | | | | | | | | | | | | | | | | 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 it safe to always call deleteLater on a resourceLaszlo Agocs2023-04-181-10/+30
| | | | | | | | | | | | | | | | | | | ...even when the QRhi is already gone. This should not happen in well-written applications and libraries, but we handle this gracefully in the regular dtor and destroy() for resources that register themselves to their creator QRhi, so by registering everything we can offer this to all QRhiResource subclasses. We still want to differentiate between native resource owning QRhiResources and others (that do not create native graphics objects), so do this via a flag passed to registerResource(). This way the behavior with QT_RHI_LEAK_CHECK=1 does not change. Pick-to: 6.5 Fixes: QTBUG-112914 Change-Id: I9bafc81ef7a4ae76f356fc5f6248628d1f8791e0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Strømme <christian.stromme@qt.io>
* rhi: Remove readback result type aliasLaszlo Agocs2023-04-121-1/+1
| | | | | | Change-Id: I1b14d3230ab4011506892c64ea03d5431d82a90d Reviewed-by: Christian Strømme <christian.stromme@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* rhi: metal: macOS: Set presentsWithTransaction during resizeLaszlo Agocs2023-03-231-25/+60
| | | | | | | | | | | | | | | | | | | ...when presenting from the main thread. Make resizing nice and smooth in application that render and present on the main thread. This includes Qt Quick applications when ran with QSG_RENDER_LOOP=basic, as well as QQuickWidget-based widget apps and anything using the QRhi-based backingstore flushing, and plain QWindow apps that use QRhi on the main thread. Allow opting out with an environment variable (QT_MTL_NO_TRANSACTION), following the existing patterns of some of the other backends (such as QT_D3D_NO_xxxx). This can be handy in case it turns out setting presentsWithTransaction is not desired in some very specific case. Task-number: QTBUG-107198 Change-Id: Id0f4e5a509076dd24c03d243c4f098ddb139d7af Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* rhi: metal: Share semaphore code within the backendLaszlo Agocs2023-03-211-25/+33
| | | | | | Change-Id: I5b52cb8ccac303c4532651553101f381568eba2d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: metal: Fix offscreen frame command completion waitLaszlo Agocs2023-03-211-9/+7
| | | | | | | | | | | Does what 711c55b63226c30532b39ec8d5191330512eb2e0 did for Vulkan, i.e. removes the there-is-more-than-one-swapchain condition. Fixes: QTBUG-109971 Pick-to: 6.5 6.4 6.2 Change-Id: If631748c50482389a3ef894823a1aaf1ebb38bee Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* rhi: Make non-critical pipeline cache warnings qCDebug insteadLaszlo Agocs2023-03-161-13/+14
| | | | | | | | | | | | | | | | 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: Metal tessellation shader input output interface blocksBen Fletcher2023-03-091-127/+321
| | | | | | | | | | | | | | | | | | | | | | | | | Add support for shader input output interface blocks in Metal tessellation pipelines. This feature is builtin to other rhi supported tessellation backends (OpenGL/Vulkan). Metal tessellation is implemented as compute pipelines for vert and tesc, and a render pipeline for tese and frag. The shader conversion from GLSL is handled by SPIRV-Cross, which has a particular way of doing things. Rhi must setup the vertex inputs for the tese - frag render pipeline to read from buffers written by the tesc compute pipeline, following SPIRV-Cross conventions. This includes ensuring correct memory alignment per MSL Specification. In order to enable input output interface blocks, reflection of struct members of QShaderDescription::InOutVariable is required. Reflection of QShaderDescription::BuiltinVariable array dimensions is also required to support variable size tese builtin input gl_ClipDistance. An acompanying patch to QtShaderTools is required. Change-Id: Id94e86caef211485afc187bb79fe3d0619d02cf0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Laszlo Agocs <laszlo.agocs@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: Remove QRhiSrb data gettersLaszlo Agocs2023-02-201-15/+6
| | | | | | | | | | | | | | | | 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-3/+2
| | | | | | | | 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: Metal SPIRV-Cross buffer size buffersBen Fletcher2023-02-141-1/+200
| | | | | | | | | | | | | When SPIRV-Cross encounters a GLSL storage buffer runtime sized array, it generates MSL code which expects a "buffer size buffer" containing a list of storage buffer sizes to be bound. This patch adds RHI backend support for Metal "buffer size buffers" on compute and graphics (including tessellation) pipelines. Includes unit tests. An accompanying patch to qtshadertools is required. Change-Id: I9392bfb21803e1a868d7de420fedc097a8452429 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Allow Metal shaders written in MSL versions greater than 2.0Ben Fletcher2023-02-141-11/+36
| | | | | | | | | | | The current rhi implementation only supports shaders written in MSL 1.2 or 2.0. The QtShaderTools/qsb tooling supports generation of shaders in newer MSL versions. This patch determines the platform's supported MSL versions at runtime, then selects the MSL shader with the highest supported version number from the available baked shaders. Change-Id: I5e3c0429179d1a5532a81df9ccbfe4db8c99c77a Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* rhi: Remove manual release of autoreleased NSStringTor Arne Vestbø2023-01-261-4/+1
| | | | | | | | | | The [NSString stringWithUTF8String:] function returns an autoreleased object, so we don't need to manually release it. Doing so results in a crash when the surrounding autorelease pool is drained. Pick-to: 6.5 6.4 6.2 Change-Id: I3dca01e2771d4010e582c2bf770f3d2281343dc3 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* RHI: Metal tessellation fixesBen Fletcher2023-01-111-111/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes four issues with Metal tessellation. a) Shader resource binding The Metal tessellation implementation assumes identical SPIRV-Cross native Metal resource binding mapping for vertex, tessellation control, and tessellation evaluation shaders. These mappings are independently generated by SPIRV-Cross for each shader stage, and may not always be identical. This patch allows for different resource bindings for each of the vert/tesc/tese stages. b) Tessellation evaluation vertex descriptors The Metal tessellation evaluation render pipeline vertex descriptor generation code contains a bug where attribute offsets and built in variable locations could be calculated incorrectly if the tessellation control shader output variables are not provided in ascending location order. This patch fixes this by sorting the variables by location before processing. c) Render pass descriptor Metal tessellation draw ends the current render pass encoder to perform tessellation compute tasks on a compute pass encoder. When the compute pass is completed, a new render pass encoder is created to continue rendering. A bug exists where the new render pass encoder uses a render pass descriptor that clears the color, depth and stencil attachements. This patch fixes this bug by changing the render pass descriptor color, depth and stencil attachment load actions to MTLLoadActionLoad when appropriate. d) drawIndexed A bug exists where when drawIndexed is called, the Metal tessellation vertex as compute stage input descriptor buffer layout step function gets set to MTLStepFunctionThreadPositionInGridX rather than the indexed version MTLStepFunctionThreadPositionInGridXIndexed. This patch fixes this by selecting the appropriate step function. Pick-to: 6.5 Change-Id: I122c67394719ad6b4801cd7643043839fd186bf2 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>