Add environment variable override helper function

This allows FORCE_QT_GLES and SEPARATE_TEST_DECODER to override both true and false.
This commit is contained in:
Cameron Gutman 2025-12-27 15:33:13 -06:00
commit 41ad3c0938
9 changed files with 68 additions and 60 deletions

View file

@ -550,9 +550,12 @@ int main(int argc, char *argv[])
#endif #endif
} }
if (WMUtils::isRunningNvidiaProprietaryDriverX11() || bool forceGles;
!WMUtils::supportsDesktopGLWithEGL() || if (!Utils::getEnvironmentVariableOverride("FORCE_QT_GLES", &forceGles)) {
qEnvironmentVariableIntValue("FORCE_QT_GLES")) { forceGles = WMUtils::isRunningNvidiaProprietaryDriverX11() ||
!WMUtils::supportsDesktopGLWithEGL();
}
if (forceGles) {
// The Nvidia proprietary driver causes Qt to render a black window when using // The Nvidia proprietary driver causes Qt to render a black window when using
// the default Desktop GL profile with EGL. AS a workaround, we default to // the default Desktop GL profile with EGL. AS a workaround, we default to
// OpenGL ES when running on Nvidia on X11. // OpenGL ES when running on Nvidia on X11.

View file

@ -533,28 +533,22 @@ bool Session::populateDecoderProperties(SDL_Window* window)
m_VideoCallbacks.submitDecodeUnit = drSubmitDecodeUnit; m_VideoCallbacks.submitDecodeUnit = drSubmitDecodeUnit;
} }
{ if (Utils::getEnvironmentVariableOverride("COLOR_SPACE_OVERRIDE", &m_StreamConfig.colorSpace)) {
bool ok; SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using colorspace override: %d",
m_StreamConfig.colorSpace);
}
else {
m_StreamConfig.colorSpace = decoder->getDecoderColorspace();
}
m_StreamConfig.colorSpace = qEnvironmentVariableIntValue("COLOR_SPACE_OVERRIDE", &ok); if (Utils::getEnvironmentVariableOverride("COLOR_RANGE_OVERRIDE", &m_StreamConfig.colorRange)) {
if (ok) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Using color range override: %d",
"Using colorspace override: %d", m_StreamConfig.colorRange);
m_StreamConfig.colorSpace); }
} else {
else { m_StreamConfig.colorRange = decoder->getDecoderColorRange();
m_StreamConfig.colorSpace = decoder->getDecoderColorspace();
}
m_StreamConfig.colorRange = qEnvironmentVariableIntValue("COLOR_RANGE_OVERRIDE", &ok);
if (ok) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using color range override: %d",
m_StreamConfig.colorRange);
}
else {
m_StreamConfig.colorRange = decoder->getDecoderColorRange();
}
} }
if (decoder->isAlwaysFullScreen()) { if (decoder->isAlwaysFullScreen()) {

View file

@ -4,6 +4,7 @@
#include "d3d11va.h" #include "d3d11va.h"
#include "dxutil.h" #include "dxutil.h"
#include "path.h" #include "path.h"
#include "utils.h"
#include "streaming/streamutils.h" #include "streaming/streamutils.h"
#include "streaming/session.h" #include "streaming/session.h"
@ -209,29 +210,26 @@ bool D3D11VARenderer::createDeviceByAdapterIndex(int adapterIndex, bool* adapter
goto Exit; goto Exit;
} }
bool ok; if (Utils::getEnvironmentVariableOverride("D3D11VA_FORCE_BIND", &m_BindDecoderOutputTextures)) {
m_BindDecoderOutputTextures = !!qEnvironmentVariableIntValue("D3D11VA_FORCE_BIND", &ok); SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
if (!ok) { "Using D3D11VA_FORCE_BIND to override default bind/copy logic");
}
else {
// Skip copying to our own internal texture on Intel GPUs due to // Skip copying to our own internal texture on Intel GPUs due to
// significant performance impact of the extra copy. See: // significant performance impact of the extra copy. See:
// https://github.com/moonlight-stream/moonlight-qt/issues/1304 // https://github.com/moonlight-stream/moonlight-qt/issues/1304
m_BindDecoderOutputTextures = adapterDesc.VendorId == 0x8086; m_BindDecoderOutputTextures = adapterDesc.VendorId == 0x8086;
} }
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using D3D11VA_FORCE_BIND to override default bind/copy logic");
}
m_UseFenceHack = !!qEnvironmentVariableIntValue("D3D11VA_FORCE_FENCE", &ok); if (Utils::getEnvironmentVariableOverride("D3D11VA_FORCE_FENCE", &m_UseFenceHack)) {
if (!ok) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using D3D11VA_FORCE_FENCE to override default fence workaround logic");
}
else {
// Old Intel GPUs (HD 4000) require a fence to properly synchronize // Old Intel GPUs (HD 4000) require a fence to properly synchronize
// the video engine with the 3D engine for texture sampling. // the video engine with the 3D engine for texture sampling.
m_UseFenceHack = adapterDesc.VendorId == 0x8086 && featureLevel < D3D_FEATURE_LEVEL_11_1; m_UseFenceHack = adapterDesc.VendorId == 0x8086 && featureLevel < D3D_FEATURE_LEVEL_11_1;
} }
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using D3D11VA_FORCE_FENCE to override default fence workaround logic");
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Decoder texture access: %s (fence: %s)", "Decoder texture access: %s (fence: %s)",

View file

@ -4,7 +4,7 @@
#endif #endif
#include "drm.h" #include "drm.h"
#include "string.h" #include "utils.h"
extern "C" { extern "C" {
#include <libavutil/hwcontext_drm.h> #include <libavutil/hwcontext_drm.h>
@ -80,6 +80,7 @@ struct dma_buf_sync {
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -576,8 +577,12 @@ bool DrmRenderer::initialize(PDECODER_PARAMETERS params)
// formats with the linear modifier on all planes, but doesn't actually // formats with the linear modifier on all planes, but doesn't actually
// support raw YUV formats on the primary plane. Don't ever use primary // support raw YUV formats on the primary plane. Don't ever use primary
// planes on Spacemit hardware to avoid triggering this bug. // planes on Spacemit hardware to avoid triggering this bug.
bool ok, allowPrimaryPlane = !!qEnvironmentVariableIntValue("DRM_ALLOW_PRIMARY_PLANE", &ok); bool allowPrimaryPlane;
if (!ok) { if (Utils::getEnvironmentVariableOverride("DRM_ALLOW_PRIMARY_PLANE", &allowPrimaryPlane)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using DRM_ALLOW_PRIMARY_PLANE to override default plane selection logic");
}
else {
allowPrimaryPlane = strcmp(m_Version->name, "spacemit") != 0; allowPrimaryPlane = strcmp(m_Version->name, "spacemit") != 0;
} }

View file

@ -5,6 +5,7 @@
#include <initguid.h> #include <initguid.h>
#include "dxva2.h" #include "dxva2.h"
#include "dxutil.h" #include "dxutil.h"
#include "utils.h"
#include "../ffmpeg.h" #include "../ffmpeg.h"
#include <streaming/streamutils.h> #include <streaming/streamutils.h>
#include <streaming/session.h> #include <streaming/session.h>
@ -390,16 +391,11 @@ bool DXVA2Renderer::initializeQuirksForAdapter(IDirect3D9Ex* d3d9ex, int adapter
SDL_assert(m_DeviceQuirks == 0); SDL_assert(m_DeviceQuirks == 0);
SDL_assert(!m_Device); SDL_assert(!m_Device);
{ if (Utils::getEnvironmentVariableOverride("DXVA2_QUIRK_FLAGS", &m_DeviceQuirks)) {
bool ok; SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using DXVA2 quirk override: 0x%x",
m_DeviceQuirks = qEnvironmentVariableIntValue("DXVA2_QUIRK_FLAGS", &ok); m_DeviceQuirks);
if (ok) { return true;
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using DXVA2 quirk override: 0x%x",
m_DeviceQuirks);
return true;
}
} }
UINT adapterCount = d3d9ex->GetAdapterCount(); UINT adapterCount = d3d9ex->GetAdapterCount();

View file

@ -1,4 +1,5 @@
#include "genhwaccel.h" #include "genhwaccel.h"
#include "utils.h"
GenericHwAccelRenderer::GenericHwAccelRenderer(AVHWDeviceType hwDeviceType) GenericHwAccelRenderer::GenericHwAccelRenderer(AVHWDeviceType hwDeviceType)
: IFFmpegRenderer(RendererType::Unknown), : IFFmpegRenderer(RendererType::Unknown),
@ -56,9 +57,9 @@ bool GenericHwAccelRenderer::isDirectRenderingSupported()
int GenericHwAccelRenderer::getDecoderCapabilities() int GenericHwAccelRenderer::getDecoderCapabilities()
{ {
bool ok; int caps;
int caps = qEnvironmentVariableIntValue("GENHWACCEL_CAPS", &ok);
if (ok) { if (Utils::getEnvironmentVariableOverride("GENHWACCEL_CAPS", &caps)) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Using GENHWACCEL_CAPS for decoder capabilities: %x", "Using GENHWACCEL_CAPS for decoder capabilities: %x",
caps); caps);

View file

@ -1,5 +1,6 @@
#include <Limelight.h> #include <Limelight.h>
#include "ffmpeg.h" #include "ffmpeg.h"
#include "utils.h"
#include "streaming/session.h" #include "streaming/session.h"
#include <h264_stream.h> #include <h264_stream.h>
@ -109,10 +110,9 @@ bool FFmpegVideoDecoder::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO info)
int FFmpegVideoDecoder::getDecoderCapabilities() int FFmpegVideoDecoder::getDecoderCapabilities()
{ {
bool ok; int capabilities;
int capabilities = qEnvironmentVariableIntValue("DECODER_CAPS", &ok); if (Utils::getEnvironmentVariableOverride("DECODER_CAPS", &capabilities)) {
if (ok) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using decoder capability override: 0x%x", "Using decoder capability override: 0x%x",
capabilities); capabilities);
@ -1080,8 +1080,9 @@ bool FFmpegVideoDecoder::isSeparateTestDecoderRequired(const AVCodec* decoder)
// the decoder can handle a change in surface sizes while streaming. // the decoder can handle a change in surface sizes while streaming.
// We know v4l2m2m can't handle this (see comment below), so let's just // We know v4l2m2m can't handle this (see comment below), so let's just
// opt-out all non-hwaccel decoders just to be safe. // opt-out all non-hwaccel decoders just to be safe.
if (qEnvironmentVariableIntValue("SEPARATE_TEST_DECODER")) { bool value;
return true; if (Utils::getEnvironmentVariableOverride("SEPARATE_TEST_DECODER", &value)) {
return value;
} }
else if (getAVCodecCapabilities(decoder) & AV_CODEC_CAP_HARDWARE) { else if (getAVCodecCapabilities(decoder) & AV_CODEC_CAP_HARDWARE) {
return true; return true;

View file

@ -14,3 +14,12 @@ namespace WMUtils {
bool isRunningDesktopEnvironment(); bool isRunningDesktopEnvironment();
QString getDrmCardOverride(); QString getDrmCardOverride();
} }
namespace Utils {
template <typename T>
bool getEnvironmentVariableOverride(const char* name, T* value) {
bool ok;
*value = (T)qEnvironmentVariableIntValue(name, &ok);
return ok;
}
}

View file

@ -176,8 +176,9 @@ bool WMUtils::isRunningWindowManager()
bool WMUtils::isRunningDesktopEnvironment() bool WMUtils::isRunningDesktopEnvironment()
{ {
if (qEnvironmentVariableIsSet("HAS_DESKTOP_ENVIRONMENT")) { bool value;
return qEnvironmentVariableIntValue("HAS_DESKTOP_ENVIRONMENT"); if (Utils::getEnvironmentVariableOverride("HAS_DESKTOP_ENVIRONMENT", &value)) {
return value;
} }
#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN) #if defined(Q_OS_WIN) || defined(Q_OS_DARWIN)