Fix Metal usage on iOS

Also enable the two Metal-specific scenegraph examples on iOS.

Change-Id: I0e1e6d527544ea4a5bfb0d08ca2d32c762d3c699
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Laszlo Agocs 2019-11-13 16:35:11 +01:00
parent f6e90ba533
commit df0cb0edac
7 changed files with 18 additions and 13 deletions

View File

@ -1,4 +1,4 @@
!macos: error("This example requires macOS")
!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
@ -6,7 +6,8 @@ HEADERS += metaltextureimport.h
SOURCES += metaltextureimport.mm main.cpp
RESOURCES += metaltextureimport.qrc
LIBS += -framework Metal -framework AppKit
LIBS += -framework Metal
macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metaltextureimport
INSTALLS += target

View File

@ -349,10 +349,13 @@ void SquircleRenderer::init(int framesInFlight)
rpDesc.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;
rpDesc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;
#ifdef Q_OS_MACOS
if (m_device.depth24Stencil8PixelFormatSupported) {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
} else {
} else
#endif
{
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}

View File

@ -1,4 +1,4 @@
!macos: error("This example requires macOS")
!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
@ -6,7 +6,8 @@ HEADERS += metalsquircle.h
SOURCES += metalsquircle.mm main.cpp
RESOURCES += metalunderqml.qrc
LIBS += -framework Metal -framework AppKit
LIBS += -framework Metal
macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metalunderqml
INSTALLS += target

View File

@ -16,7 +16,7 @@ SUBDIRS += \
rendernode \
threadedanimation
macos {
macos|ios {
SUBDIRS += \
metalunderqml \
metaltextureimport

View File

@ -159,7 +159,7 @@ void QSGRhiSupport::applySettings()
} else {
#if defined(Q_OS_WIN)
m_rhiBackend = QRhi::D3D11;
#elif defined(Q_OS_DARWIN)
#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
m_rhiBackend = QRhi::Metal;
#else
m_rhiBackend = QRhi::OpenGLES2;
@ -350,7 +350,7 @@ static const void *qsgrhi_d3d11_rifResource(QSGRendererInterface::Resource res,
}
#endif
#ifdef Q_OS_DARWIN
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
static const void *qsgrhi_mtl_rifResource(QSGRendererInterface::Resource res, const QRhiNativeHandles *nat,
const QRhiNativeHandles *cbNat)
{
@ -408,7 +408,7 @@ const void *QSGRhiSupport::rifResource(QSGRendererInterface::Resource res, const
case QRhi::D3D11:
return qsgrhi_d3d11_rifResource(res, nat);
#endif
#ifdef Q_OS_DARWIN
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
case QRhi::Metal:
{
QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer();
@ -507,7 +507,7 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf
rhi = QRhi::create(backend, &rhiParams, flags);
}
#endif
#ifdef Q_OS_DARWIN
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
if (backend == QRhi::Metal) {
QRhiMetalInitParams rhiParams;
rhi = QRhi::create(backend, &rhiParams, flags);

View File

@ -70,7 +70,7 @@
#include <QtGui/private/qrhid3d11_p.h>
#endif
#ifdef Q_OS_DARWIN
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
#include <QtGui/private/qrhimetal_p.h>
#endif

View File

@ -48,7 +48,7 @@ void QSGRhiNativeTextureImporter::buildWrapper(QRhi *rhi, QRhiTexture *t,
#if !QT_CONFIG(vulkan)
Q_UNUSED(nativeLayout);
#endif
#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) && !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN)
#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) && !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) && !defined(Q_OS_IOS)
Q_UNUSED(nativeObjectPtr);
#endif
@ -83,7 +83,7 @@ void QSGRhiNativeTextureImporter::buildWrapper(QRhi *rhi, QRhiTexture *t,
break;
case QRhi::Metal:
{
#ifdef Q_OS_DARWIN
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
QRhiMetalTextureNativeHandles h;
h.texture = *reinterpret_cast<void * const *>(nativeObjectPtr);
t->buildFrom(&h);