diff options
Diffstat (limited to 'tests/manual/rhi/shared/examplefw.h')
-rw-r--r-- | tests/manual/rhi/shared/examplefw.h | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 1a29ef5f7e..d28bbea0a8 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -58,6 +58,7 @@ #include <QPlatformSurfaceEvent> #include <QElapsedTimer> #include <QTimer> +#include <QLoggingCategory> #include <QtGui/private/qshader_p.h> #include <QFile> @@ -70,7 +71,6 @@ #endif #if QT_CONFIG(vulkan) -#include <QLoggingCategory> #include <QtGui/private/qrhivulkan_p.h> #endif @@ -126,6 +126,8 @@ int sampleCount = 1; QRhiSwapChain::Flags scFlags = 0; QRhi::BeginFrameFlags beginFrameFlags = 0; QRhi::EndFrameFlags endFrameFlags = 0; +int framesUntilTdr = -1; +bool transparentBackground = false; class Window : public QWindow { @@ -166,6 +168,8 @@ protected: QOffscreenSurface *m_fallbackSurface = nullptr; #endif + QColor m_clearColor; + friend int main(int, char**); }; @@ -193,6 +197,8 @@ Window::Window() default: break; } + + m_clearColor = transparentBackground ? Qt::transparent : QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f); } Window::~Window() @@ -278,6 +284,10 @@ void Window::init() if (graphicsApi == D3D11) { QRhiD3D11InitParams params; params.enableDebugLayer = true; + if (framesUntilTdr > 0) { + params.framesUntilKillingDeviceViaTdr = framesUntilTdr; + params.repeatDeviceKill = true; + } m_r = QRhi::create(QRhi::D3D11, ¶ms, rhiFlags); } #endif @@ -297,7 +307,7 @@ void Window::init() m_sc = m_r->newSwapChain(); // allow depth-stencil, although we do not actually enable depth test/write for the triangle m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(), // no need to set the size yet + QSize(), // no need to set the size here, due to UsedWithSwapChainOnly sampleCount, QRhiRenderBuffer::UsedWithSwapChainOnly); m_sc->setWindow(this); @@ -334,16 +344,12 @@ void Window::releaseResources() void Window::resizeSwapChain() { - const QSize outputSize = m_sc->surfacePixelSize(); - - m_ds->setPixelSize(outputSize); - m_ds->build(); // == m_ds->release(); m_ds->build(); - - m_hasSwapChain = m_sc->buildOrResize(); + m_hasSwapChain = m_sc->buildOrResize(); // also handles m_ds m_frameCount = 0; m_timer.restart(); + const QSize outputSize = m_sc->currentPixelSize(); m_proj = m_r->clipSpaceCorrMatrix(); m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f); m_proj.translate(0, 0, -4); @@ -434,6 +440,8 @@ int main(int argc, char **argv) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + QLoggingCategory::setFilterRules(QLatin1String("qt.rhi.*=true")); + // Defaults. #if defined(Q_OS_WIN) graphicsApi = D3D11; @@ -461,8 +469,20 @@ int main(int argc, char **argv) // Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and // QCoreApplication::quit() (e.g. what a menu widget would do) is important. // Use this parameter for the latter. - QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self destruct after 5 seconds")); + QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds.")); cmdLineParser.addOption(sdOption); + // Attempt testing device lost situations on D3D at least. + QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. " + "(generate a device reset every <count> frames when on D3D11)"), + QLatin1String("count")); + cmdLineParser.addOption(tdrOption); + // Allow testing preferring the software adapter (D3D). + QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. " + "Only applicable with some APIs and platforms.")); + cmdLineParser.addOption(swOption); + // Allow testing having a semi-transparent window. + QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent")); + cmdLineParser.addOption(transparentOption); cmdLineParser.process(app); if (cmdLineParser.isSet(nullOption)) @@ -479,6 +499,11 @@ int main(int argc, char **argv) qDebug("Selected graphics API is %s", qPrintable(graphicsApiName())); qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText())); + if (cmdLineParser.isSet(transparentOption)) { + transparentBackground = true; + scFlags |= QRhiSwapChain::SurfaceHasPreMulAlpha; + } + #ifdef EXAMPLEFW_PREINIT void preInit(); preInit(); @@ -494,6 +519,9 @@ int main(int argc, char **argv) fmt.setSwapInterval(0); if (scFlags.testFlag(QRhiSwapChain::sRGB)) fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace); + // Exception: The alpha size is not necessarily OpenGL specific. + if (transparentBackground) + fmt.setAlphaBufferSize(8); QSurfaceFormat::setDefaultFormat(fmt); // Vulkan setup. @@ -521,6 +549,12 @@ int main(int argc, char **argv) } #endif + if (cmdLineParser.isSet(tdrOption)) + framesUntilTdr = cmdLineParser.value(tdrOption).toInt(); + + if (cmdLineParser.isSet(swOption)) + rhiFlags |= QRhi::PreferSoftwareRenderer; + // Create and show the window. Window w; #if QT_CONFIG(vulkan) |