Add configure feature for Metal
Simplifies maintenance of code paths that rely on Metal. Change-Id: I1d1f705fffc14dbafde346eeb555b43be6d5be54 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
e8e029e2a5
commit
14ec2ab89f
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user