rhi: Add a flag to suppress D3D11 smoke test warnings

Applicable to D3D11 only, although the flag is general enough that
other backends could use it if it made sense for them.

This allows Qt Quick to state that warnings about QRhi::create()
failures that lead to retrying with a different set of flags
(PreferSoftwareRenderer to get to use the WARP software rasterizer)
should be suppressed and turned to regular categorized debug prints.

Other users, e.g. an application directly working with QRhi may not
want this. A create() failure must be complemented by an unconditional
qWarning since normally that is pretty serious error. Hence the opt-in
flag.

Task-number: QTBUG-117926
Change-Id: I808bd1670b631e2068b566ab08589e1783f62ca5
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Laszlo Agocs 2023-10-09 16:10:07 +02:00
parent bbeff2a335
commit 92167f0119
3 changed files with 35 additions and 12 deletions

View File

@ -665,6 +665,17 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
mechanisms for shader/program binaries provided by Qt. Writing to those may
get disabled whenever this flag is set since storing program binaries to
multiple caches is not sensible.
\value SuppressSmokeTestWarnings Indicates that, with backends where this
is relevant, certain, non-fatal QRhi::create() failures should not
produce qWarning() calls. For example, with D3D11, passing this flag
makes a number of warning messages (that appear due to QRhi::create()
failing) to become categorized debug prints instead under the commonly used
\c{qt.rhi.general} logging category. This can be used by engines, such as
Qt Quick, that feature fallback logic, i.e. they retry calling create()
with a different set of flags (such as, \l PreferSoftwareRenderer), in order
to hide the unconditional warnings from the output that would be printed
when the first create() attempt had failed.
*/
/*!

View File

@ -1787,7 +1787,8 @@ public:
EnableDebugMarkers = 1 << 0,
PreferSoftwareRenderer = 1 << 1,
EnablePipelineCacheDataSave = 1 << 2,
EnableTimestamps = 1 << 3
EnableTimestamps = 1 << 3,
SuppressSmokeTestWarnings = 1 << 4
};
Q_DECLARE_FLAGS(Flags, Flag)

View File

@ -291,21 +291,24 @@ bool QRhiD3D11::create(QRhi::Flags flags)
return false;
}
const bool supports11_1 = SUCCEEDED(ctx->QueryInterface(__uuidof(ID3D11DeviceContext1), reinterpret_cast<void **>(&context)));
ctx->Release();
if (!supports11_1) {
qWarning("ID3D11DeviceContext1 not supported");
return false;
}
// Test if creating a Shader Model 5.0 vertex shader works; we want to
// fail already in create() if that's not the case.
ID3D11VertexShader *testShader = nullptr;
if (SUCCEEDED(dev->CreateVertexShader(g_testVertexShader, sizeof(g_testVertexShader), nullptr, &testShader))) {
testShader->Release();
} else {
qWarning("D3D11 smoke test failed (failed to create vertex shader)");
ctx->Release();
return false;
}
const bool supports11_1 = SUCCEEDED(ctx->QueryInterface(__uuidof(ID3D11DeviceContext1), reinterpret_cast<void **>(&context)));
ctx->Release();
if (!supports11_1) {
qWarning("ID3D11DeviceContext1 not supported");
static const char *msg = "D3D11 smoke test: Failed to create vertex shader";
if (flags.testFlag(QRhi::SuppressSmokeTestWarnings))
qCDebug(QRHI_LOG_INFO, "%s", msg);
else
qWarning("%s", msg);
return false;
}
@ -315,11 +318,19 @@ bool QRhiD3D11::create(QRhi::Flags flags)
// still not support this D3D_FEATURE_LEVEL_11_1 feature. (e.g.
// because it only does 11_0)
if (!features.ConstantBufferOffsetting) {
qWarning("Constant buffer offsetting is not supported by the driver");
static const char *msg = "D3D11 smoke test: Constant buffer offsetting is not supported by the driver";
if (flags.testFlag(QRhi::SuppressSmokeTestWarnings))
qCDebug(QRHI_LOG_INFO, "%s", msg);
else
qWarning("%s", msg);
return false;
}
} else {
qWarning("Failed to query D3D11_FEATURE_D3D11_OPTIONS");
static const char *msg = "D3D11 smoke test: Failed to query D3D11_FEATURE_D3D11_OPTIONS";
if (flags.testFlag(QRhi::SuppressSmokeTestWarnings))
qCDebug(QRHI_LOG_INFO, "%s", msg);
else
qWarning("%s", msg);
return false;
}
} else {