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
}
if (WMUtils::isRunningNvidiaProprietaryDriverX11() ||
!WMUtils::supportsDesktopGLWithEGL() ||
qEnvironmentVariableIntValue("FORCE_QT_GLES")) {
bool forceGles;
if (!Utils::getEnvironmentVariableOverride("FORCE_QT_GLES", &forceGles)) {
forceGles = WMUtils::isRunningNvidiaProprietaryDriverX11() ||
!WMUtils::supportsDesktopGLWithEGL();
}
if (forceGles) {
// 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
// OpenGL ES when running on Nvidia on X11.

View file

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

View file

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

View file

@ -4,7 +4,7 @@
#endif
#include "drm.h"
#include "string.h"
#include "utils.h"
extern "C" {
#include <libavutil/hwcontext_drm.h>
@ -80,6 +80,7 @@ struct dma_buf_sync {
#include <unistd.h>
#include <fcntl.h>
#include <string.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
// support raw YUV formats on the primary plane. Don't ever use primary
// planes on Spacemit hardware to avoid triggering this bug.
bool ok, allowPrimaryPlane = !!qEnvironmentVariableIntValue("DRM_ALLOW_PRIMARY_PLANE", &ok);
if (!ok) {
bool allowPrimaryPlane;
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;
}

View file

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

View file

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

View file

@ -1,5 +1,6 @@
#include <Limelight.h>
#include "ffmpeg.h"
#include "utils.h"
#include "streaming/session.h"
#include <h264_stream.h>
@ -109,10 +110,9 @@ bool FFmpegVideoDecoder::notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO info)
int FFmpegVideoDecoder::getDecoderCapabilities()
{
bool ok;
int capabilities;
int capabilities = qEnvironmentVariableIntValue("DECODER_CAPS", &ok);
if (ok) {
if (Utils::getEnvironmentVariableOverride("DECODER_CAPS", &capabilities)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Using decoder capability override: 0x%x",
capabilities);
@ -1080,8 +1080,9 @@ bool FFmpegVideoDecoder::isSeparateTestDecoderRequired(const AVCodec* decoder)
// 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
// opt-out all non-hwaccel decoders just to be safe.
if (qEnvironmentVariableIntValue("SEPARATE_TEST_DECODER")) {
return true;
bool value;
if (Utils::getEnvironmentVariableOverride("SEPARATE_TEST_DECODER", &value)) {
return value;
}
else if (getAVCodecCapabilities(decoder) & AV_CODEC_CAP_HARDWARE) {
return true;

View file

@ -14,3 +14,12 @@ namespace WMUtils {
bool isRunningDesktopEnvironment();
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()
{
if (qEnvironmentVariableIsSet("HAS_DESKTOP_ENVIRONMENT")) {
return qEnvironmentVariableIntValue("HAS_DESKTOP_ENVIRONMENT");
bool value;
if (Utils::getEnvironmentVariableOverride("HAS_DESKTOP_ENVIRONMENT", &value)) {
return value;
}
#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN)