diff options
author | Tor Arne Vestbø <[email protected]> | 2024-03-18 21:55:12 +0100 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2024-03-19 14:52:48 +0100 |
commit | 14ec2ab89fa3347f95170d6980a6c793b7f37424 (patch) | |
tree | 88686ff27beffaa7f98a0639777a51ab36cbd05e | |
parent | e8e029e2a5573eecd7358cd5ed66afa89debb306 (diff) |
Add configure feature for Metal
Simplifies maintenance of code paths that rely on Metal.
Change-Id: I1d1f705fffc14dbafde346eeb555b43be6d5be54
Reviewed-by: Alexandru Croitor <[email protected]>
23 files changed, 39 insertions, 34 deletions
diff --git a/examples/gui/rhiwindow/main.cpp b/examples/gui/rhiwindow/main.cpp index 6ca38e7b542..37977e3a34d 100644 --- a/examples/gui/rhiwindow/main.cpp +++ b/examples/gui/rhiwindow/main.cpp @@ -14,7 +14,7 @@ int main(int argc, char **argv) // Use platform-specific defaults when no command-line arguments given. #if defined(Q_OS_WIN) graphicsApi = QRhi::D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = QRhi::Metal; #elif QT_CONFIG(vulkan) graphicsApi = QRhi::Vulkan; diff --git a/examples/gui/rhiwindow/rhiwindow.cpp b/examples/gui/rhiwindow/rhiwindow.cpp index 5022244b863..345286b6358 100644 --- a/examples/gui/rhiwindow/rhiwindow.cpp +++ b/examples/gui/rhiwindow/rhiwindow.cpp @@ -146,7 +146,7 @@ void RhiWindow::init() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (m_graphicsApi == QRhi::Metal) { QRhiMetalInitParams params; m_rhi.reset(QRhi::create(QRhi::Metal, ¶ms)); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 4f1a4742f54..2df1baf3cd1 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1006,7 +1006,7 @@ qt_internal_extend_target(Gui CONDITION QT_FEATURE_xkbcommon AND UNIX XKB::XKB ) -qt_internal_extend_target(Gui CONDITION IOS OR MACOS +qt_internal_extend_target(Gui CONDITION QT_FEATURE_metal SOURCES rhi/qrhimetal.mm rhi/qrhimetal_p.h PUBLIC_LIBRARIES diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 754ca8d761d..ddb0af35b61 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -811,6 +811,10 @@ qt_feature("vulkan" PUBLIC LABEL "Vulkan" CONDITION QT_FEATURE_library AND QT_FEATURE_vkgen AND WrapVulkanHeaders_FOUND ) +qt_feature("metal" PUBLIC + LABEL "Metal" + CONDITION MACOS OR IOS +) qt_feature("vkkhrdisplay" PRIVATE SECTION "Platform plugins" LABEL "VK_KHR_display" @@ -1288,6 +1292,7 @@ qt_configure_add_summary_entry(ARGS "opengles31") qt_configure_add_summary_entry(ARGS "opengles32") qt_configure_end_summary_section() # end of "OpenGL" section qt_configure_add_summary_entry(ARGS "vulkan") +qt_configure_add_summary_entry(ARGS "metal") qt_configure_add_summary_entry(ARGS "graphicsframecapture") qt_configure_add_summary_entry(ARGS "sessionmanager") qt_configure_end_summary_section() # end of "Qt Gui" section diff --git a/src/gui/doc/snippets/rhioffscreen/main.cpp b/src/gui/doc/snippets/rhioffscreen/main.cpp index 1db1a8f59ab..c2c6f74dc1b 100644 --- a/src/gui/doc/snippets/rhioffscreen/main.cpp +++ b/src/gui/doc/snippets/rhioffscreen/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char **argv) #if defined(Q_OS_WIN) QRhiD3D12InitParams params; rhi.reset(QRhi::create(QRhi::D3D12, ¶ms)); -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) QRhiMetalInitParams params; rhi.reset(QRhi::create(QRhi::Metal, ¶ms)); #elif QT_CONFIG(vulkan) diff --git a/src/gui/painting/qbackingstorerhisupport.cpp b/src/gui/painting/qbackingstorerhisupport.cpp index e068f1880d9..630134e564d 100644 --- a/src/gui/painting/qbackingstorerhisupport.cpp +++ b/src/gui/painting/qbackingstorerhisupport.cpp @@ -107,7 +107,7 @@ bool QBackingStoreRhiSupport::create() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (!rhi && m_config.api() == QPlatformBackingStoreRhiConfig::Metal) { QRhiMetalInitParams params; // For parity with Qt Quick, fall back to OpenGL when there is no Metal (f.ex. in macOS virtual machines). @@ -271,7 +271,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC if (config.isEnabled()) { #if defined(Q_OS_WIN) config.setApi(QPlatformBackingStoreRhiConfig::D3D11); -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) config.setApi(QPlatformBackingStoreRhiConfig::Metal); #elif QT_CONFIG(opengl) config.setApi(QPlatformBackingStoreRhiConfig::OpenGL); @@ -291,7 +291,7 @@ bool QBackingStoreRhiSupport::checkForceRhi(QPlatformBackingStoreRhiConfig *outC if (backend == QStringLiteral("d3d12")) config.setApi(QPlatformBackingStoreRhiConfig::D3D12); #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (backend == QStringLiteral("metal")) config.setApi(QPlatformBackingStoreRhiConfig::Metal); #endif diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 874484b5181..25df9c60031 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -16,7 +16,7 @@ #include "qrhid3d11_p.h" #include "qrhid3d12_p.h" #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) #include "qrhimetal_p.h" #endif @@ -8477,7 +8477,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh break; #endif case Metal: -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) r->d = new QRhiMetal(static_cast<QRhiMetalInitParams *>(params), static_cast<QRhiMetalNativeHandles *>(importDevice)); break; @@ -8536,7 +8536,7 @@ bool QRhi::probe(QRhi::Implementation impl, QRhiInitParams *params) // create() and then drop the result. if (impl == Metal) { -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) ok = QRhiMetal::probe(static_cast<QRhiMetalInitParams *>(params)); #endif } else { @@ -8587,7 +8587,7 @@ bool QRhi::probe(QRhi::Implementation impl, QRhiInitParams *params) */ QRhiSwapChainProxyData QRhi::updateSwapChainProxyData(QRhi::Implementation impl, QWindow *window) { -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (impl == Metal) return QRhiMetal::updateSwapChainProxyData(window); #else diff --git a/src/gui/rhi/qrhi_platform.h b/src/gui/rhi/qrhi_platform.h index 0268cc6e49c..e7be522c529 100644 --- a/src/gui/rhi/qrhi_platform.h +++ b/src/gui/rhi/qrhi_platform.h @@ -23,7 +23,7 @@ #include <QtGui/qvulkaninstance.h> #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_QDOC) +#if QT_CONFIG(metal) || defined(Q_QDOC) Q_FORWARD_DECLARE_OBJC_CLASS(MTLDevice); Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandQueue); Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandBuffer); @@ -150,7 +150,7 @@ struct Q_GUI_EXPORT QRhiD3D12CommandBufferNativeHandles : public QRhiNativeHandl #endif // WIN/QDOC -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_QDOC) +#if QT_CONFIG(metal) || defined(Q_QDOC) struct Q_GUI_EXPORT QRhiMetalInitParams : public QRhiInitParams { diff --git a/src/gui/util/qgraphicsframecapture.cpp b/src/gui/util/qgraphicsframecapture.cpp index 131d2ae6e2e..e49fb83008a 100644 --- a/src/gui/util/qgraphicsframecapture.cpp +++ b/src/gui/util/qgraphicsframecapture.cpp @@ -4,7 +4,7 @@ #include "qgraphicsframecapture_p.h" #if (defined (Q_OS_WIN) || defined(Q_OS_LINUX)) && QT_CONFIG(library) #include "qgraphicsframecapturerenderdoc_p_p.h" -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) #include "qgraphicsframecapturemetal_p_p.h" #else #include "qgraphicsframecapture_p_p.h" @@ -28,7 +28,7 @@ QGraphicsFrameCapture::QGraphicsFrameCapture() { #if (defined (Q_OS_WIN) || defined(Q_OS_LINUX)) && QT_CONFIG(library) d.reset(new QGraphicsFrameCaptureRenderDoc); -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) d.reset(new QGraphicsFrameCaptureMetal); #endif } diff --git a/src/gui/util/qgraphicsframecapturerenderdoc.cpp b/src/gui/util/qgraphicsframecapturerenderdoc.cpp index 983506c4b18..88ba9d839fb 100644 --- a/src/gui/util/qgraphicsframecapturerenderdoc.cpp +++ b/src/gui/util/qgraphicsframecapturerenderdoc.cpp @@ -41,7 +41,7 @@ static void *glNativeContext(QOpenGLContext *context) { #endif #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) nctx = context->nativeInterface<QNativeInterface::QCocoaGLContext>()->nativeContext(); #endif } diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 5dc17a15ea2..cdbf247fceb 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -31,7 +31,7 @@ # define TST_D3D12 #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) # define TST_MTL #endif diff --git a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp index 9f56c776377..7c57e77eb38 100644 --- a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp +++ b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp @@ -84,7 +84,7 @@ void tst_QRhiWidget::testData() #endif #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) QRhiMetalInitParams metalInitParams; if (QRhi::probe(QRhi::Metal, &metalInitParams)) QTest::newRow("Metal") << QRhiWidget::Api::Metal; diff --git a/tests/manual/embeddedwindows/main.cpp b/tests/manual/embeddedwindows/main.cpp index 77d7ac3643d..e34c7206eaa 100644 --- a/tests/manual/embeddedwindows/main.cpp +++ b/tests/manual/embeddedwindows/main.cpp @@ -3,7 +3,7 @@ #include <QtGui> -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_OS_WIN) || QT_CONFIG(xcb) || defined(ANDROID) +#if QT_CONFIG(metal) || defined(Q_OS_WIN) || QT_CONFIG(xcb) || defined(ANDROID) #include "../../shared/nativewindow.h" #define HAVE_NATIVE_WINDOW #endif diff --git a/tests/manual/graphicsframecapture/main.cpp b/tests/manual/graphicsframecapture/main.cpp index ef199a85b91..b13f2f4184f 100644 --- a/tests/manual/graphicsframecapture/main.cpp +++ b/tests/manual/graphicsframecapture/main.cpp @@ -84,7 +84,7 @@ QRhi::Implementation graphicsApiFromCmd(const QGuiApplication &app) { QRhi::Implementation graphicsApi; #if defined(Q_OS_WIN) graphicsApi = QRhi::D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = QRhi::Metal; #elif QT_CONFIG(vulkan) graphicsApi = QRhi::Vulkan; diff --git a/tests/manual/graphicsframecapture/window.cpp b/tests/manual/graphicsframecapture/window.cpp index 84e2a0a824b..92a5483634f 100644 --- a/tests/manual/graphicsframecapture/window.cpp +++ b/tests/manual/graphicsframecapture/window.cpp @@ -9,7 +9,7 @@ Window::Window(QRhi::Implementation graphicsApi) : m_graphicsApi(graphicsApi) { m_capturer.reset(new QGraphicsFrameCapture); -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) qDebug("This example uses Metal Capture Manager In App API to capture frames. Press F9 to capture a frame and F10 to open it for analysis"); #else qDebug("This example uses RenderDoc In App API to capture frames. Press F9 to capture a frame and F10 to open it for analysis"); @@ -142,7 +142,7 @@ void Window::init() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (m_graphicsApi == QRhi::Metal) { QRhiMetalInitParams params; m_rhi.reset(QRhi::create(QRhi::Metal, ¶ms, rhiFlags)); diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp index 47fea36d439..89926c19cc9 100644 --- a/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp +++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char **argv) QRhi::Implementation graphicsApi; #if defined(Q_OS_WIN) graphicsApi = QRhi::D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = QRhi::Metal; #elif QT_CONFIG(vulkan) graphicsApi = QRhi::Vulkan; diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp index b4fa6e23f61..edbd048c637 100644 --- a/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp +++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp @@ -120,7 +120,7 @@ void Window::init() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (m_graphicsApi == QRhi::Metal) { QRhiMetalInitParams params; m_rhi.reset(QRhi::create(QRhi::Metal, ¶ms, rhiFlags)); diff --git a/tests/manual/rhi/multiwindow/multiwindow.cpp b/tests/manual/rhi/multiwindow/multiwindow.cpp index 4b0e4ff2548..bea4af2d480 100644 --- a/tests/manual/rhi/multiwindow/multiwindow.cpp +++ b/tests/manual/rhi/multiwindow/multiwindow.cpp @@ -91,7 +91,7 @@ void createRhi() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { QRhiMetalInitParams params; r.r = QRhi::create(QRhi::Metal, ¶ms); @@ -469,7 +469,7 @@ int main(int argc, char **argv) #if defined(Q_OS_WIN) graphicsApi = D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = Metal; #elif QT_CONFIG(vulkan) graphicsApi = Vulkan; diff --git a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp index 177492b9b2a..634caebd8d2 100644 --- a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp +++ b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp @@ -321,7 +321,7 @@ void Renderer::createRhi() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { QRhiMetalInitParams params; r = QRhi::create(QRhi::Metal, ¶ms, rhiFlags); @@ -654,7 +654,7 @@ int main(int argc, char **argv) #if defined(Q_OS_WIN) graphicsApi = D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = Metal; #elif QT_CONFIG(vulkan) graphicsApi = Vulkan; diff --git a/tests/manual/rhi/offscreen/offscreen.cpp b/tests/manual/rhi/offscreen/offscreen.cpp index c9b3f6ecb70..86bf5ad5a9e 100644 --- a/tests/manual/rhi/offscreen/offscreen.cpp +++ b/tests/manual/rhi/offscreen/offscreen.cpp @@ -68,7 +68,7 @@ int main(int argc, char **argv) #if defined(Q_OS_WIN) graphicsApi = D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = Metal; #elif QT_CONFIG(vulkan) graphicsApi = Vulkan; @@ -154,7 +154,7 @@ int main(int argc, char **argv) } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { QRhiMetalInitParams params; r = QRhi::create(QRhi::Metal, ¶ms, rhiFlags); diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 35a95b81577..f2ca57341c6 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -261,7 +261,7 @@ void Window::init() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { QRhiMetalInitParams params; m_r = QRhi::create(QRhi::Metal, ¶ms, rhiFlags); @@ -426,7 +426,7 @@ int main(int argc, char **argv) // Defaults. #if defined(Q_OS_WIN) graphicsApi = D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = Metal; #elif QT_CONFIG(vulkan) graphicsApi = Vulkan; diff --git a/tests/manual/rhi/texuploads/texuploads.cpp b/tests/manual/rhi/texuploads/texuploads.cpp index 69bad50a6bd..5723d19be92 100644 --- a/tests/manual/rhi/texuploads/texuploads.cpp +++ b/tests/manual/rhi/texuploads/texuploads.cpp @@ -192,7 +192,7 @@ void Window::customRender() if (d.testStage == 6) { const QRhiTexture::NativeTexture nativeTexture = d.tex->nativeTexture(); if (nativeTexture.object) { -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { qDebug() << "Metal texture: " << nativeTexture.object; // Now could cast to id<MTLTexture> and do something with diff --git a/tests/shared/nativewindow.h b/tests/shared/nativewindow.h index 7ec25d1e9fc..51d211704ec 100644 --- a/tests/shared/nativewindow.h +++ b/tests/shared/nativewindow.h @@ -53,7 +53,7 @@ private: Handle m_handle = {}; }; -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) @interface View : VIEW_BASE @end |